Updated VGMStream to r1050-2834-gc40d364e
parent
f64a67941a
commit
9dd4f68049
|
@ -79,8 +79,8 @@ void decode_pcmfloat(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelsp
|
||||||
size_t pcm_bytes_to_samples(size_t bytes, int channels, int bits_per_sample);
|
size_t pcm_bytes_to_samples(size_t bytes, int channels, int bits_per_sample);
|
||||||
|
|
||||||
/* psx_decoder */
|
/* psx_decoder */
|
||||||
void decode_psx(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int is_badflags);
|
void decode_psx(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int is_badflags, int config);
|
||||||
void decode_psx_configurable(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int frame_size);
|
void decode_psx_configurable(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int frame_size, int config);
|
||||||
void decode_psx_pivotal(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int frame_size);
|
void decode_psx_pivotal(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int frame_size);
|
||||||
int ps_find_loop_offsets(STREAMFILE *streamFile, off_t start_offset, size_t data_size, int channels, size_t interleave, int32_t * out_loop_start, int32_t * out_loop_end);
|
int ps_find_loop_offsets(STREAMFILE *streamFile, off_t start_offset, size_t data_size, int channels, size_t interleave, int32_t * out_loop_start, int32_t * out_loop_end);
|
||||||
int ps_find_loop_offsets_full(STREAMFILE *streamFile, off_t start_offset, size_t data_size, int channels, size_t interleave, int32_t * out_loop_start, int32_t * out_loop_end);
|
int ps_find_loop_offsets_full(STREAMFILE *streamFile, off_t start_offset, size_t data_size, int channels, size_t interleave, int32_t * out_loop_start, int32_t * out_loop_end);
|
||||||
|
|
|
@ -1,423 +1,446 @@
|
||||||
#include "coding.h"
|
#include "coding.h"
|
||||||
|
|
||||||
|
|
||||||
/* PS-ADPCM table, defined as rational numbers (as in the spec) */
|
/* PS-ADPCM table, defined as rational numbers (as in the spec) */
|
||||||
static const float ps_adpcm_coefs_f[5][2] = {
|
static const float ps_adpcm_coefs_f[16][2] = {
|
||||||
{ 0.0 , 0.0 }, //{ 0.0 , 0.0 },
|
{ 0.0 , 0.0 }, //{ 0.0 , 0.0 },
|
||||||
{ 0.9375 , 0.0 }, //{ 60.0 / 64.0 , 0.0 },
|
{ 0.9375 , 0.0 }, //{ 60.0 / 64.0 , 0.0 },
|
||||||
{ 1.796875 , -0.8125 }, //{ 115.0 / 64.0 , -52.0 / 64.0 },
|
{ 1.796875 , -0.8125 }, //{ 115.0 / 64.0 , -52.0 / 64.0 },
|
||||||
{ 1.53125 , -0.859375 }, //{ 98.0 / 64.0 , -55.0 / 64.0 },
|
{ 1.53125 , -0.859375 }, //{ 98.0 / 64.0 , -55.0 / 64.0 },
|
||||||
{ 1.90625 , -0.9375 }, //{ 122.0 / 64.0 , -60.0 / 64.0 },
|
{ 1.90625 , -0.9375 }, //{ 122.0 / 64.0 , -60.0 / 64.0 },
|
||||||
};
|
/* extended table used in few PS3 games, found in ELFs */
|
||||||
|
{ 0.46875 , -0.0 }, //{ 30.0 / 64.0 , -0.0 / 64.0 },
|
||||||
/* PS-ADPCM table, defined as spec_coef*64 (for int implementations) */
|
{ 0.8984375 , -0.40625 }, //{ 57.5 / 64.0 , -26.0 / 64.0 },
|
||||||
static const int ps_adpcm_coefs_i[5][2] = {
|
{ 0.765625 , -0.4296875 }, //{ 49.0 / 64.0 , -27.5 / 64.0 },
|
||||||
{ 0 , 0 },
|
{ 0.953125 , -0.46875 }, //{ 61.0 / 64.0 , -30.0 / 64.0 },
|
||||||
{ 60 , 0 },
|
{ 0.234375 , -0.0 }, //{ 15.0 / 64.0 , -0.0 / 64.0 },
|
||||||
{ 115 , -52 },
|
{ 0.44921875, -0.203125 }, //{ 28.75/ 64.0 , -13.0 / 64.0 },
|
||||||
{ 98 , -55 },
|
{ 0.3828125 , -0.21484375}, //{ 24.5 / 64.0 , -13.75/ 64.0 },
|
||||||
{ 122 , -60 },
|
{ 0.4765625 , -0.234375 }, //{ 30.5 / 64.0 , -15.0 / 64.0 },
|
||||||
#if 0
|
{ 0.5 , -0.9375 }, //{ 32.0 / 64.0 , -60.0 / 64.0 },
|
||||||
/* extended table from PPSSPP (PSP emu), found by tests (unused?) */
|
{ 0.234375 , -0.9375 }, //{ 15.0 / 64.0 , -60.0 / 64.0 },
|
||||||
{ 0 , 0 },
|
{ 0.109375 , -0.9375 }, //{ 7.0 / 64.0 , -60.0 / 64.0 },
|
||||||
{ 0 , 0 },
|
};
|
||||||
{ 52 , 0 },
|
|
||||||
{ 55 , -2 },
|
/* PS-ADPCM table, defined as spec_coef*64 (for int implementations) */
|
||||||
{ 60 ,-125 },
|
static const int ps_adpcm_coefs_i[5][2] = {
|
||||||
{ 0 , 0 },
|
{ 0 , 0 },
|
||||||
{ 0 , -91 },
|
{ 60 , 0 },
|
||||||
{ 0 , 0 },
|
{ 115 , -52 },
|
||||||
{ 2 ,-216 },
|
{ 98 , -55 },
|
||||||
{ 125 , -6 },
|
{ 122 , -60 },
|
||||||
{ 0 ,-151 },
|
#if 0
|
||||||
#endif
|
/* extended table from PPSSPP (PSP emu), found by tests (unused?) */
|
||||||
};
|
{ 0 , 0 },
|
||||||
|
{ 0 , 0 },
|
||||||
|
{ 52 , 0 },
|
||||||
/* Decodes Sony's PS-ADPCM (sometimes called SPU-ADPCM or VAG, just "ADPCM" in the SDK docs).
|
{ 55 , -2 },
|
||||||
* Very similar to XA ADPCM (see xa_decoder for extended info).
|
{ 60 ,-125 },
|
||||||
*
|
{ 0 , 0 },
|
||||||
* Some official PC tools decode using float coefs (from the spec), as does this code, but
|
{ 0 , -91 },
|
||||||
* consoles/games/libs would vary (PS1 could do it in hardware using BRR/XA's logic, FMOD/PS3
|
{ 0 , 0 },
|
||||||
* may use int math in software, etc). There are inaudible rounding diffs between implementations.
|
{ 2 ,-216 },
|
||||||
*/
|
{ 125 , -6 },
|
||||||
|
{ 0 ,-151 },
|
||||||
/* standard PS-ADPCM (float math version) */
|
#endif
|
||||||
void decode_psx(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int is_badflags) {
|
};
|
||||||
uint8_t frame[0x10] = {0};
|
|
||||||
off_t frame_offset;
|
|
||||||
int i, frames_in, sample_count = 0;
|
/* Decodes Sony's PS-ADPCM (sometimes called SPU-ADPCM or VAG, just "ADPCM" in the SDK docs).
|
||||||
size_t bytes_per_frame, samples_per_frame;
|
* Very similar to XA ADPCM (see xa_decoder for extended info).
|
||||||
uint8_t coef_index, shift_factor, flag;
|
*
|
||||||
int32_t hist1 = stream->adpcm_history1_32;
|
* Some official PC tools decode using float coefs (from the spec), as does this code, but
|
||||||
int32_t hist2 = stream->adpcm_history2_32;
|
* consoles/games/libs would vary (PS1 could do it in hardware using BRR/XA's logic, FMOD may
|
||||||
|
* depend on platform, PS3 games use floats, etc). There are rounding diffs between implementations.
|
||||||
|
*/
|
||||||
/* external interleave (fixed size), mono */
|
|
||||||
bytes_per_frame = 0x10;
|
/* standard PS-ADPCM (float math version) */
|
||||||
samples_per_frame = (bytes_per_frame - 0x02) * 2; /* always 28 */
|
void decode_psx(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int is_badflags, int config) {
|
||||||
frames_in = first_sample / samples_per_frame;
|
uint8_t frame[0x10] = {0};
|
||||||
first_sample = first_sample % samples_per_frame;
|
off_t frame_offset;
|
||||||
|
int i, frames_in, sample_count = 0;
|
||||||
/* parse frame header */
|
size_t bytes_per_frame, samples_per_frame;
|
||||||
frame_offset = stream->offset + bytes_per_frame * frames_in;
|
uint8_t coef_index, shift_factor, flag;
|
||||||
read_streamfile(frame, frame_offset, bytes_per_frame, stream->streamfile); /* ignore EOF errors */
|
int32_t hist1 = stream->adpcm_history1_32;
|
||||||
coef_index = (frame[0] >> 4) & 0xf;
|
int32_t hist2 = stream->adpcm_history2_32;
|
||||||
shift_factor = (frame[0] >> 0) & 0xf;
|
int extended_mode = (config == 1);
|
||||||
flag = frame[1]; /* only lower nibble needed */
|
|
||||||
|
|
||||||
VGM_ASSERT_ONCE(coef_index > 5 || shift_factor > 12, "PS-ADPCM: incorrect coefs/shift at %x\n", (uint32_t)frame_offset);
|
/* external interleave (fixed size), mono */
|
||||||
if (coef_index > 5) /* needed by inFamous (PS3) (maybe it's supposed to use more filters?) */
|
bytes_per_frame = 0x10;
|
||||||
coef_index = 0; /* upper filters aren't used in PS1/PS2, maybe in PSP/PS3? */
|
samples_per_frame = (bytes_per_frame - 0x02) * 2; /* always 28 */
|
||||||
if (shift_factor > 12)
|
frames_in = first_sample / samples_per_frame;
|
||||||
shift_factor = 9; /* supposedly, from Nocash PSX docs */
|
first_sample = first_sample % samples_per_frame;
|
||||||
|
|
||||||
if (is_badflags) /* some games store garbage or extra internal logic in the flags, must be ignored */
|
/* parse frame header */
|
||||||
flag = 0;
|
frame_offset = stream->offset + bytes_per_frame * frames_in;
|
||||||
VGM_ASSERT_ONCE(flag > 7,"PS-ADPCM: unknown flag at %x\n", (uint32_t)frame_offset); /* meta should use PSX-badflags */
|
read_streamfile(frame, frame_offset, bytes_per_frame, stream->streamfile); /* ignore EOF errors */
|
||||||
|
coef_index = (frame[0] >> 4) & 0xf;
|
||||||
|
shift_factor = (frame[0] >> 0) & 0xf;
|
||||||
/* decode nibbles */
|
flag = frame[1]; /* only lower nibble needed */
|
||||||
for (i = first_sample; i < first_sample + samples_to_do; i++) {
|
|
||||||
int32_t sample = 0;
|
/* upper filters only used in few PS3 games, normally 0 */
|
||||||
|
if (!extended_mode) {
|
||||||
if (flag < 0x07) { /* with flag 0x07 decoded sample must be 0 */
|
VGM_ASSERT_ONCE(coef_index > 5 || shift_factor > 12, "PS-ADPCM: incorrect coefs/shift at %x\n", (uint32_t)frame_offset);
|
||||||
uint8_t nibbles = frame[0x02 + i/2];
|
if (coef_index > 5)
|
||||||
|
coef_index = 0;
|
||||||
sample = i&1 ? /* low nibble first */
|
if (shift_factor > 12)
|
||||||
(nibbles >> 4) & 0x0f :
|
shift_factor = 9; /* supposedly, from Nocash PSX docs */
|
||||||
(nibbles >> 0) & 0x0f;
|
}
|
||||||
sample = (int16_t)((sample << 12) & 0xf000) >> shift_factor; /* 16b sign extend + scale */
|
|
||||||
sample = (int32_t)(sample + ps_adpcm_coefs_f[coef_index][0]*hist1 + ps_adpcm_coefs_f[coef_index][1]*hist2);
|
if (is_badflags) /* some games store garbage or extra internal logic in the flags, must be ignored */
|
||||||
sample = clamp16(sample);
|
flag = 0;
|
||||||
}
|
VGM_ASSERT_ONCE(flag > 7,"PS-ADPCM: unknown flag at %x\n", (uint32_t)frame_offset); /* meta should use PSX-badflags */
|
||||||
|
|
||||||
outbuf[sample_count] = sample;
|
|
||||||
sample_count += channelspacing;
|
/* decode nibbles */
|
||||||
|
for (i = first_sample; i < first_sample + samples_to_do; i++) {
|
||||||
hist2 = hist1;
|
int32_t sample = 0;
|
||||||
hist1 = sample;
|
|
||||||
}
|
if (flag < 0x07) { /* with flag 0x07 decoded sample must be 0 */
|
||||||
|
uint8_t nibbles = frame[0x02 + i/2];
|
||||||
stream->adpcm_history1_32 = hist1;
|
|
||||||
stream->adpcm_history2_32 = hist2;
|
sample = i&1 ? /* low nibble first */
|
||||||
}
|
(nibbles >> 4) & 0x0f :
|
||||||
|
(nibbles >> 0) & 0x0f;
|
||||||
|
sample = (int16_t)((sample << 12) & 0xf000) >> shift_factor; /* 16b sign extend + scale */
|
||||||
/* PS-ADPCM with configurable frame size and no flag (int math version).
|
sample = (int32_t)(sample + ps_adpcm_coefs_f[coef_index][0]*hist1 + ps_adpcm_coefs_f[coef_index][1]*hist2);
|
||||||
* Found in some PC/PS3 games (FF XI in sizes 0x3/0x5/0x9/0x41, Afrika in size 0x4, Blur/James Bond in size 0x33, etc).
|
sample = clamp16(sample);
|
||||||
*
|
}
|
||||||
* Uses int math to decode, which seems more likely (based on FF XI PC's code in Moogle Toolbox). */
|
|
||||||
void decode_psx_configurable(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int frame_size) {
|
outbuf[sample_count] = sample;
|
||||||
uint8_t frame[0x50] = {0};
|
sample_count += channelspacing;
|
||||||
off_t frame_offset;
|
|
||||||
int i, frames_in, sample_count = 0;
|
hist2 = hist1;
|
||||||
size_t bytes_per_frame, samples_per_frame;
|
hist1 = sample;
|
||||||
uint8_t coef_index, shift_factor;
|
}
|
||||||
int32_t hist1 = stream->adpcm_history1_32;
|
|
||||||
int32_t hist2 = stream->adpcm_history2_32;
|
stream->adpcm_history1_32 = hist1;
|
||||||
|
stream->adpcm_history2_32 = hist2;
|
||||||
|
}
|
||||||
/* external interleave (variable size), mono */
|
|
||||||
bytes_per_frame = frame_size;
|
|
||||||
samples_per_frame = (bytes_per_frame - 0x01) * 2;
|
/* PS-ADPCM with configurable frame size and no flag (int math version).
|
||||||
frames_in = first_sample / samples_per_frame;
|
* Found in some PC/PS3 games (FF XI in sizes 0x3/0x5/0x9/0x41, Afrika in size 0x4, Blur/James Bond in size 0x33, etc).
|
||||||
first_sample = first_sample % samples_per_frame;
|
*
|
||||||
|
* Uses int/float math depending on config (PC/other code may be int, PS3 float). */
|
||||||
/* parse frame header */
|
void decode_psx_configurable(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int frame_size, int config) {
|
||||||
frame_offset = stream->offset + bytes_per_frame * frames_in;
|
uint8_t frame[0x50] = {0};
|
||||||
read_streamfile(frame, frame_offset, bytes_per_frame, stream->streamfile); /* ignore EOF errors */
|
off_t frame_offset;
|
||||||
coef_index = (frame[0] >> 4) & 0xf;
|
int i, frames_in, sample_count = 0;
|
||||||
shift_factor = (frame[0] >> 0) & 0xf;
|
size_t bytes_per_frame, samples_per_frame;
|
||||||
|
uint8_t coef_index, shift_factor;
|
||||||
VGM_ASSERT_ONCE(coef_index > 5 || shift_factor > 12, "PS-ADPCM: incorrect coefs/shift at %x\n", (uint32_t)frame_offset);
|
int32_t hist1 = stream->adpcm_history1_32;
|
||||||
if (coef_index > 5) /* needed by Afrika (PS3) (maybe it's supposed to use more filters?) */
|
int32_t hist2 = stream->adpcm_history2_32;
|
||||||
coef_index = 0; /* upper filters aren't used in PS1/PS2, maybe in PSP/PS3? */
|
int extended_mode = (config == 1);
|
||||||
if (shift_factor > 12)
|
int float_mode = (config == 1);
|
||||||
shift_factor = 9; /* supposedly, from Nocash PSX docs */
|
|
||||||
|
|
||||||
|
/* external interleave (variable size), mono */
|
||||||
/* decode nibbles */
|
bytes_per_frame = frame_size;
|
||||||
for (i = first_sample; i < first_sample + samples_to_do; i++) {
|
samples_per_frame = (bytes_per_frame - 0x01) * 2;
|
||||||
int32_t sample = 0;
|
frames_in = first_sample / samples_per_frame;
|
||||||
uint8_t nibbles = frame[0x01 + i/2];
|
first_sample = first_sample % samples_per_frame;
|
||||||
|
|
||||||
sample = i&1 ? /* low nibble first */
|
/* parse frame header */
|
||||||
(nibbles >> 4) & 0x0f :
|
frame_offset = stream->offset + bytes_per_frame * frames_in;
|
||||||
(nibbles >> 0) & 0x0f;
|
read_streamfile(frame, frame_offset, bytes_per_frame, stream->streamfile); /* ignore EOF errors */
|
||||||
sample = (int16_t)((sample << 12) & 0xf000) >> shift_factor; /* 16b sign extend + scale */
|
coef_index = (frame[0] >> 4) & 0xf;
|
||||||
sample = sample + ((ps_adpcm_coefs_i[coef_index][0]*hist1 + ps_adpcm_coefs_i[coef_index][1]*hist2) >> 6);
|
shift_factor = (frame[0] >> 0) & 0xf;
|
||||||
sample = clamp16(sample);
|
|
||||||
|
/* upper filters only used in few PS3 games, normally 0 */
|
||||||
outbuf[sample_count] = sample;
|
if (!extended_mode) {
|
||||||
sample_count += channelspacing;
|
VGM_ASSERT_ONCE(coef_index > 5 || shift_factor > 12, "PS-ADPCM: incorrect coefs/shift at %x\n", (uint32_t)frame_offset);
|
||||||
|
if (coef_index > 5)
|
||||||
hist2 = hist1;
|
coef_index = 0;
|
||||||
hist1 = sample;
|
if (shift_factor > 12)
|
||||||
}
|
shift_factor = 9; /* supposedly, from Nocash PSX docs */
|
||||||
|
}
|
||||||
stream->adpcm_history1_32 = hist1;
|
|
||||||
stream->adpcm_history2_32 = hist2;
|
|
||||||
}
|
/* decode nibbles */
|
||||||
|
for (i = first_sample; i < first_sample + samples_to_do; i++) {
|
||||||
/* PS-ADPCM from Pivotal games, exactly like psx_cfg but with float math (reverse engineered from the exe) */
|
int32_t sample = 0;
|
||||||
void decode_psx_pivotal(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int frame_size) {
|
uint8_t nibbles = frame[0x01 + i/2];
|
||||||
uint8_t frame[0x50] = {0};
|
|
||||||
off_t frame_offset;
|
sample = i&1 ? /* low nibble first */
|
||||||
int i, frames_in, sample_count = 0;
|
(nibbles >> 4) & 0x0f :
|
||||||
size_t bytes_per_frame, samples_per_frame;
|
(nibbles >> 0) & 0x0f;
|
||||||
uint8_t coef_index, shift_factor;
|
sample = (int16_t)((sample << 12) & 0xf000) >> shift_factor; /* 16b sign extend + scale */
|
||||||
int32_t hist1 = stream->adpcm_history1_32;
|
sample = float_mode ?
|
||||||
int32_t hist2 = stream->adpcm_history2_32;
|
(int32_t)(sample + ps_adpcm_coefs_f[coef_index][0]*hist1 + ps_adpcm_coefs_f[coef_index][1]*hist2) :
|
||||||
float scale;
|
sample + ((ps_adpcm_coefs_i[coef_index][0]*hist1 + ps_adpcm_coefs_i[coef_index][1]*hist2) >> 6);
|
||||||
|
sample = clamp16(sample);
|
||||||
|
|
||||||
/* external interleave (variable size), mono */
|
outbuf[sample_count] = sample;
|
||||||
bytes_per_frame = frame_size;
|
sample_count += channelspacing;
|
||||||
samples_per_frame = (bytes_per_frame - 0x01) * 2;
|
|
||||||
frames_in = first_sample / samples_per_frame;
|
hist2 = hist1;
|
||||||
first_sample = first_sample % samples_per_frame;
|
hist1 = sample;
|
||||||
|
}
|
||||||
/* parse frame header */
|
|
||||||
frame_offset = stream->offset + bytes_per_frame * frames_in;
|
stream->adpcm_history1_32 = hist1;
|
||||||
read_streamfile(frame, frame_offset, bytes_per_frame, stream->streamfile); /* ignore EOF errors */
|
stream->adpcm_history2_32 = hist2;
|
||||||
coef_index = (frame[0] >> 4) & 0xf;
|
}
|
||||||
shift_factor = (frame[0] >> 0) & 0xf;
|
|
||||||
|
/* PS-ADPCM from Pivotal games, exactly like psx_cfg but with float math (reverse engineered from the exe) */
|
||||||
VGM_ASSERT_ONCE(coef_index > 5 || shift_factor > 12, "PS-ADPCM-piv: incorrect coefs/shift\n");
|
void decode_psx_pivotal(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int frame_size) {
|
||||||
if (coef_index > 5) /* just in case */
|
uint8_t frame[0x50] = {0};
|
||||||
coef_index = 5;
|
off_t frame_offset;
|
||||||
if (shift_factor > 12) /* same */
|
int i, frames_in, sample_count = 0;
|
||||||
shift_factor = 12;
|
size_t bytes_per_frame, samples_per_frame;
|
||||||
|
uint8_t coef_index, shift_factor;
|
||||||
scale = (float)(1.0 / (double)(1 << shift_factor));
|
int32_t hist1 = stream->adpcm_history1_32;
|
||||||
|
int32_t hist2 = stream->adpcm_history2_32;
|
||||||
|
float scale;
|
||||||
/* decode nibbles */
|
|
||||||
for (i = first_sample; i < first_sample + samples_to_do; i++) {
|
|
||||||
int32_t sample = 0;
|
/* external interleave (variable size), mono */
|
||||||
uint8_t nibbles = frame[0x01 + i/2];
|
bytes_per_frame = frame_size;
|
||||||
|
samples_per_frame = (bytes_per_frame - 0x01) * 2;
|
||||||
sample = !(i&1) ? /* low nibble first */
|
frames_in = first_sample / samples_per_frame;
|
||||||
(nibbles >> 0) & 0x0f :
|
first_sample = first_sample % samples_per_frame;
|
||||||
(nibbles >> 4) & 0x0f;
|
|
||||||
sample = (int16_t)((sample << 12) & 0xf000); /* 16b sign extend + default scale */
|
/* parse frame header */
|
||||||
sample = sample*scale + ps_adpcm_coefs_f[coef_index][0]*hist1 + ps_adpcm_coefs_f[coef_index][1]*hist2; /* actually substracts negative coefs but whatevs */
|
frame_offset = stream->offset + bytes_per_frame * frames_in;
|
||||||
|
read_streamfile(frame, frame_offset, bytes_per_frame, stream->streamfile); /* ignore EOF errors */
|
||||||
outbuf[sample_count] = clamp16(sample);
|
coef_index = (frame[0] >> 4) & 0xf;
|
||||||
sample_count += channelspacing;
|
shift_factor = (frame[0] >> 0) & 0xf;
|
||||||
|
|
||||||
hist2 = hist1;
|
VGM_ASSERT_ONCE(coef_index > 5 || shift_factor > 12, "PS-ADPCM-piv: incorrect coefs/shift\n");
|
||||||
hist1 = sample; /* not clamped but no difference */
|
if (coef_index > 5) /* just in case */
|
||||||
}
|
coef_index = 5;
|
||||||
|
if (shift_factor > 12) /* same */
|
||||||
stream->adpcm_history1_32 = hist1;
|
shift_factor = 12;
|
||||||
stream->adpcm_history2_32 = hist2;
|
|
||||||
}
|
scale = (float)(1.0 / (double)(1 << shift_factor));
|
||||||
|
|
||||||
|
|
||||||
/* Find loop samples in PS-ADPCM data and return if the file loops.
|
/* decode nibbles */
|
||||||
*
|
for (i = first_sample; i < first_sample + samples_to_do; i++) {
|
||||||
* PS-ADPCM/VAG has optional bit flags that control looping in the SPU.
|
int32_t sample = 0;
|
||||||
* Possible combinations (as usually defined in Sony's docs):
|
uint8_t nibbles = frame[0x01 + i/2];
|
||||||
* - 0x0 (0000): Normal decode
|
|
||||||
* - 0x1 (0001): End marker (last frame)
|
sample = !(i&1) ? /* low nibble first */
|
||||||
* - 0x2 (0010): Loop region (marks files that *may* have loop flags somewhere)
|
(nibbles >> 0) & 0x0f :
|
||||||
* - 0x3 (0011): Loop end (jump to loop address)
|
(nibbles >> 4) & 0x0f;
|
||||||
* - 0x4 (0100): Start marker
|
sample = (int16_t)((sample << 12) & 0xf000); /* 16b sign extend + default scale */
|
||||||
* - 0x5 (0101): Same as 0x07? Extremely rare [Blood Omen: Legacy of Kain (PS1)]
|
sample = sample*scale + ps_adpcm_coefs_f[coef_index][0]*hist1 + ps_adpcm_coefs_f[coef_index][1]*hist2; /* actually substracts negative coefs but whatevs */
|
||||||
* - 0x6 (0110): Loop start (save loop address)
|
|
||||||
* - 0x7 (0111): End marker and don't decode
|
outbuf[sample_count] = clamp16(sample);
|
||||||
* - 0x8+(1NNN): Not valid
|
sample_count += channelspacing;
|
||||||
*/
|
|
||||||
static int ps_find_loop_offsets_internal(STREAMFILE *sf, off_t start_offset, size_t data_size, int channels, size_t interleave, int32_t * p_loop_start, int32_t * p_loop_end, int config) {
|
hist2 = hist1;
|
||||||
int num_samples = 0, loop_start = 0, loop_end = 0;
|
hist1 = sample; /* not clamped but no difference */
|
||||||
int loop_start_found = 0, loop_end_found = 0;
|
}
|
||||||
off_t offset = start_offset;
|
|
||||||
off_t max_offset = start_offset + data_size;
|
stream->adpcm_history1_32 = hist1;
|
||||||
size_t interleave_consumed = 0;
|
stream->adpcm_history2_32 = hist2;
|
||||||
int detect_full_loops = config & 1;
|
}
|
||||||
|
|
||||||
|
|
||||||
if (data_size == 0 || channels == 0 || (channels > 1 && interleave == 0))
|
/* Find loop samples in PS-ADPCM data and return if the file loops.
|
||||||
return 0;
|
*
|
||||||
|
* PS-ADPCM/VAG has optional bit flags that control looping in the SPU.
|
||||||
while (offset < max_offset) {
|
* Possible combinations (as usually defined in Sony's docs):
|
||||||
uint8_t flag = read_u8(offset+0x01, sf) & 0x0F; /* lower nibble only (for HEVAG) */
|
* - 0x0 (0000): Normal decode
|
||||||
|
* - 0x1 (0001): End marker (last frame)
|
||||||
/* theoretically possible and would use last 0x06 */
|
* - 0x2 (0010): Loop region (marks files that *may* have loop flags somewhere)
|
||||||
VGM_ASSERT_ONCE(loop_start_found && flag == 0x06, "PS LOOPS: multiple loop start found at %x\n", (uint32_t)offset);
|
* - 0x3 (0011): Loop end (jump to loop address)
|
||||||
|
* - 0x4 (0100): Start marker
|
||||||
if (flag == 0x06 && !loop_start_found) {
|
* - 0x5 (0101): Same as 0x07? Extremely rare [Blood Omen: Legacy of Kain (PS1)]
|
||||||
loop_start = num_samples; /* loop start before this frame */
|
* - 0x6 (0110): Loop start (save loop address)
|
||||||
loop_start_found = 1;
|
* - 0x7 (0111): End marker and don't decode
|
||||||
}
|
* - 0x8+(1NNN): Not valid
|
||||||
|
*/
|
||||||
if (flag == 0x03 && !loop_end) {
|
static int ps_find_loop_offsets_internal(STREAMFILE *sf, off_t start_offset, size_t data_size, int channels, size_t interleave, int32_t * p_loop_start, int32_t * p_loop_end, int config) {
|
||||||
loop_end = num_samples + 28; /* loop end after this frame */
|
int num_samples = 0, loop_start = 0, loop_end = 0;
|
||||||
loop_end_found = 1;
|
int loop_start_found = 0, loop_end_found = 0;
|
||||||
|
off_t offset = start_offset;
|
||||||
/* ignore strange case in Commandos (PS2), has many loop starts and ends */
|
off_t max_offset = start_offset + data_size;
|
||||||
if (channels == 1
|
size_t interleave_consumed = 0;
|
||||||
&& offset + 0x10 < max_offset
|
int detect_full_loops = config & 1;
|
||||||
&& (read_u8(offset + 0x11, sf) & 0x0F) == 0x06) {
|
|
||||||
loop_end = 0;
|
|
||||||
loop_end_found = 0;
|
if (data_size == 0 || channels == 0 || (channels > 1 && interleave == 0))
|
||||||
}
|
return 0;
|
||||||
|
|
||||||
if (loop_start_found && loop_end_found)
|
while (offset < max_offset) {
|
||||||
break;
|
uint8_t flag = read_u8(offset+0x01, sf) & 0x0F; /* lower nibble only (for HEVAG) */
|
||||||
}
|
|
||||||
|
/* theoretically possible and would use last 0x06 */
|
||||||
/* hack for some games that don't have loop points but do full loops,
|
VGM_ASSERT_ONCE(loop_start_found && flag == 0x06, "PS LOOPS: multiple loop start found at %x\n", (uint32_t)offset);
|
||||||
* if there is a "partial" 0x07 end flag pretend it wants to loop
|
|
||||||
* (sometimes this will loop non-looping tracks, and won't loop all repeating files)
|
if (flag == 0x06 && !loop_start_found) {
|
||||||
* seems only used in Ratchet & Clank series and Ecco the Dolphin */
|
loop_start = num_samples; /* loop start before this frame */
|
||||||
if (flag == 0x01 && detect_full_loops) {
|
loop_start_found = 1;
|
||||||
static const uint8_t eof[0x10] = {0xFF,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
|
}
|
||||||
uint8_t buf[0x10];
|
|
||||||
uint8_t hdr = read_u8(offset + 0x00, sf);
|
if (flag == 0x03 && !loop_end) {
|
||||||
|
loop_end = num_samples + 28; /* loop end after this frame */
|
||||||
int read = read_streamfile(buf, offset+0x10, sizeof(buf), sf);
|
loop_end_found = 1;
|
||||||
if (read > 0
|
|
||||||
&& buf[0] != 0x00 /* ignore blank frame */
|
/* ignore strange case in Commandos (PS2), has many loop starts and ends */
|
||||||
&& buf[0] != 0x0c /* ignore silent frame */
|
if (channels == 1
|
||||||
&& buf[0] != 0x3c /* ignore some L-R tracks with different end flags */
|
&& offset + 0x10 < max_offset
|
||||||
) {
|
&& (read_u8(offset + 0x11, sf) & 0x0F) == 0x06) {
|
||||||
|
loop_end = 0;
|
||||||
/* assume full loop with repeated frame header and null frame */
|
loop_end_found = 0;
|
||||||
if (hdr == buf[0] && memcmp(buf+1, eof+1, sizeof(buf) - 1) == 0) {
|
}
|
||||||
loop_start = 28; /* skip first frame as it's null in PS-ADPCM */
|
|
||||||
loop_end = num_samples + 28; /* loop end after this frame */
|
if (loop_start_found && loop_end_found)
|
||||||
loop_start_found = 1;
|
break;
|
||||||
loop_end_found = 1;
|
}
|
||||||
//;VGM_LOG("PS LOOPS: full loop found\n");
|
|
||||||
break;
|
/* hack for some games that don't have loop points but do full loops,
|
||||||
}
|
* if there is a "partial" 0x07 end flag pretend it wants to loop
|
||||||
}
|
* (sometimes this will loop non-looping tracks, and won't loop all repeating files)
|
||||||
}
|
* seems only used in Ratchet & Clank series and Ecco the Dolphin */
|
||||||
|
if (flag == 0x01 && detect_full_loops) {
|
||||||
|
static const uint8_t eof[0x10] = {0xFF,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
|
||||||
num_samples += 28;
|
uint8_t buf[0x10];
|
||||||
offset += 0x10;
|
uint8_t hdr = read_u8(offset + 0x00, sf);
|
||||||
|
|
||||||
/* skip other channels */
|
int read = read_streamfile(buf, offset+0x10, sizeof(buf), sf);
|
||||||
interleave_consumed += 0x10;
|
if (read > 0
|
||||||
if (interleave_consumed == interleave) {
|
&& buf[0] != 0x00 /* ignore blank frame */
|
||||||
interleave_consumed = 0;
|
&& buf[0] != 0x0c /* ignore silent frame */
|
||||||
offset += interleave*(channels - 1);
|
&& buf[0] != 0x3c /* ignore some L-R tracks with different end flags */
|
||||||
}
|
) {
|
||||||
}
|
|
||||||
|
/* assume full loop with repeated frame header and null frame */
|
||||||
VGM_ASSERT(loop_start_found && !loop_end_found, "PS LOOPS: found loop start but not loop end\n");
|
if (hdr == buf[0] && memcmp(buf+1, eof+1, sizeof(buf) - 1) == 0) {
|
||||||
VGM_ASSERT(loop_end_found && !loop_start_found, "PS LOOPS: found loop end but not loop start\n");
|
loop_start = 28; /* skip first frame as it's null in PS-ADPCM */
|
||||||
//;VGM_LOG("PS LOOPS: start=%i, end=%i\n", loop_start, loop_end);
|
loop_end = num_samples + 28; /* loop end after this frame */
|
||||||
|
loop_start_found = 1;
|
||||||
/* From Sony's docs: if only loop_end is set loop back to "phoneme region start", but in practice doesn't */
|
loop_end_found = 1;
|
||||||
if (loop_start_found && loop_end_found) {
|
//;VGM_LOG("PS LOOPS: full loop found\n");
|
||||||
*p_loop_start = loop_start;
|
break;
|
||||||
*p_loop_end = loop_end;
|
}
|
||||||
return 1;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0; /* no loop */
|
|
||||||
}
|
num_samples += 28;
|
||||||
|
offset += 0x10;
|
||||||
int ps_find_loop_offsets(STREAMFILE *sf, off_t start_offset, size_t data_size, int channels, size_t interleave, int32_t *p_loop_start, int32_t *p_loop_end) {
|
|
||||||
return ps_find_loop_offsets_internal(sf, start_offset, data_size, channels, interleave, p_loop_start, p_loop_end, 0);
|
/* skip other channels */
|
||||||
}
|
interleave_consumed += 0x10;
|
||||||
|
if (interleave_consumed == interleave) {
|
||||||
int ps_find_loop_offsets_full(STREAMFILE *sf, off_t start_offset, size_t data_size, int channels, size_t interleave, int32_t *p_loop_start, int32_t *p_loop_end) {
|
interleave_consumed = 0;
|
||||||
return ps_find_loop_offsets_internal(sf, start_offset, data_size, channels, interleave, p_loop_start, p_loop_end, 1);
|
offset += interleave*(channels - 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
size_t ps_find_padding(STREAMFILE *streamFile, off_t start_offset, size_t data_size, int channels, size_t interleave, int discard_empty) {
|
|
||||||
off_t min_offset, offset;
|
VGM_ASSERT(loop_start_found && !loop_end_found, "PS LOOPS: found loop start but not loop end\n");
|
||||||
size_t frame_size = 0x10;
|
VGM_ASSERT(loop_end_found && !loop_start_found, "PS LOOPS: found loop end but not loop start\n");
|
||||||
size_t padding_size = 0;
|
//;VGM_LOG("PS LOOPS: start=%i, end=%i\n", loop_start, loop_end);
|
||||||
size_t interleave_consumed = 0;
|
|
||||||
|
/* From Sony's docs: if only loop_end is set loop back to "phoneme region start", but in practice doesn't */
|
||||||
|
if (loop_start_found && loop_end_found) {
|
||||||
if (data_size == 0 || channels == 0 || (channels > 0 && interleave == 0))
|
*p_loop_start = loop_start;
|
||||||
return 0;
|
*p_loop_end = loop_end;
|
||||||
|
return 1;
|
||||||
offset = start_offset + data_size;
|
}
|
||||||
|
|
||||||
/* in rare cases (ex. Gitaroo Man) channels have inconsistent empty padding, use first as guide */
|
return 0; /* no loop */
|
||||||
offset = offset - interleave * (channels - 1);
|
}
|
||||||
|
|
||||||
/* some files have padding spanning multiple interleave blocks */
|
int ps_find_loop_offsets(STREAMFILE *sf, off_t start_offset, size_t data_size, int channels, size_t interleave, int32_t *p_loop_start, int32_t *p_loop_end) {
|
||||||
min_offset = start_offset; //offset - interleave;
|
return ps_find_loop_offsets_internal(sf, start_offset, data_size, channels, interleave, p_loop_start, p_loop_end, 0);
|
||||||
|
}
|
||||||
while (offset > min_offset) {
|
|
||||||
uint32_t f1,f2,f3,f4;
|
int ps_find_loop_offsets_full(STREAMFILE *sf, off_t start_offset, size_t data_size, int channels, size_t interleave, int32_t *p_loop_start, int32_t *p_loop_end) {
|
||||||
uint8_t flag;
|
return ps_find_loop_offsets_internal(sf, start_offset, data_size, channels, interleave, p_loop_start, p_loop_end, 1);
|
||||||
int is_empty = 0;
|
}
|
||||||
|
|
||||||
offset -= frame_size;
|
size_t ps_find_padding(STREAMFILE *streamFile, off_t start_offset, size_t data_size, int channels, size_t interleave, int discard_empty) {
|
||||||
|
off_t min_offset, offset;
|
||||||
f1 = read_32bitBE(offset+0x00,streamFile);
|
size_t frame_size = 0x10;
|
||||||
f2 = read_32bitBE(offset+0x04,streamFile);
|
size_t padding_size = 0;
|
||||||
f3 = read_32bitBE(offset+0x08,streamFile);
|
size_t interleave_consumed = 0;
|
||||||
f4 = read_32bitBE(offset+0x0c,streamFile);
|
|
||||||
flag = (f1 >> 16) & 0xFF;
|
|
||||||
|
if (data_size == 0 || channels == 0 || (channels > 0 && interleave == 0))
|
||||||
if (f1 == 0 && f2 == 0 && f3 == 0 && f4 == 0)
|
return 0;
|
||||||
is_empty = 1;
|
|
||||||
|
offset = start_offset + data_size;
|
||||||
if (!is_empty && discard_empty) {
|
|
||||||
if (flag == 0x07 || flag == 0x77)
|
/* in rare cases (ex. Gitaroo Man) channels have inconsistent empty padding, use first as guide */
|
||||||
is_empty = 1; /* 'discard frame' flag */
|
offset = offset - interleave * (channels - 1);
|
||||||
else if ((f1 & 0xFF00FFFF) == 0 && f2 == 0 && f3 == 0 && f4 == 0)
|
|
||||||
is_empty = 1; /* silent with flags (typical for looping files) */
|
/* some files have padding spanning multiple interleave blocks */
|
||||||
else if ((f1 & 0xFF00FFFF) == 0x0C000000 && f2 == 0 && f3 == 0 && f4 == 0)
|
min_offset = start_offset; //offset - interleave;
|
||||||
is_empty = 1; /* silent (maybe shouldn't ignore flag 0x03?) */
|
|
||||||
else if ((f1 & 0x0000FFFF) == 0x00007777 && f2 == 0x77777777 && f3 ==0x77777777 && f4 == 0x77777777)
|
while (offset > min_offset) {
|
||||||
is_empty = 1; /* silent-ish */
|
uint32_t f1,f2,f3,f4;
|
||||||
}
|
uint8_t flag;
|
||||||
|
int is_empty = 0;
|
||||||
if (!is_empty)
|
|
||||||
break;
|
offset -= frame_size;
|
||||||
|
|
||||||
padding_size += frame_size * channels;
|
f1 = read_32bitBE(offset+0x00,streamFile);
|
||||||
|
f2 = read_32bitBE(offset+0x04,streamFile);
|
||||||
/* skip other channels */
|
f3 = read_32bitBE(offset+0x08,streamFile);
|
||||||
interleave_consumed += 0x10;
|
f4 = read_32bitBE(offset+0x0c,streamFile);
|
||||||
if (interleave_consumed == interleave) {
|
flag = (f1 >> 16) & 0xFF;
|
||||||
interleave_consumed = 0;
|
|
||||||
offset -= interleave*(channels - 1);
|
if (f1 == 0 && f2 == 0 && f3 == 0 && f4 == 0)
|
||||||
}
|
is_empty = 1;
|
||||||
}
|
|
||||||
|
if (!is_empty && discard_empty) {
|
||||||
return padding_size;
|
if (flag == 0x07 || flag == 0x77)
|
||||||
}
|
is_empty = 1; /* 'discard frame' flag */
|
||||||
|
else if ((f1 & 0xFF00FFFF) == 0 && f2 == 0 && f3 == 0 && f4 == 0)
|
||||||
|
is_empty = 1; /* silent with flags (typical for looping files) */
|
||||||
size_t ps_bytes_to_samples(size_t bytes, int channels) {
|
else if ((f1 & 0xFF00FFFF) == 0x0C000000 && f2 == 0 && f3 == 0 && f4 == 0)
|
||||||
if (channels <= 0) return 0;
|
is_empty = 1; /* silent (maybe shouldn't ignore flag 0x03?) */
|
||||||
return bytes / channels / 0x10 * 28;
|
else if ((f1 & 0x0000FFFF) == 0x00007777 && f2 == 0x77777777 && f3 ==0x77777777 && f4 == 0x77777777)
|
||||||
}
|
is_empty = 1; /* silent-ish */
|
||||||
|
}
|
||||||
size_t ps_cfg_bytes_to_samples(size_t bytes, size_t frame_size, int channels) {
|
|
||||||
int samples_per_frame = (frame_size - 0x01) * 2;
|
if (!is_empty)
|
||||||
return bytes / channels / frame_size * samples_per_frame;
|
break;
|
||||||
}
|
|
||||||
|
padding_size += frame_size * channels;
|
||||||
/* test PS-ADPCM frames for correctness */
|
|
||||||
int ps_check_format(STREAMFILE *streamFile, off_t offset, size_t max) {
|
/* skip other channels */
|
||||||
off_t max_offset = offset + max;
|
interleave_consumed += 0x10;
|
||||||
if (max_offset > get_streamfile_size(streamFile))
|
if (interleave_consumed == interleave) {
|
||||||
max_offset = get_streamfile_size(streamFile);
|
interleave_consumed = 0;
|
||||||
|
offset -= interleave*(channels - 1);
|
||||||
while (offset < max_offset) {
|
}
|
||||||
uint8_t predictor = (read_8bit(offset+0x00,streamFile) >> 4) & 0x0f;
|
}
|
||||||
uint8_t flags = read_8bit(offset+0x01,streamFile);
|
|
||||||
|
return padding_size;
|
||||||
if (predictor > 5 || flags > 7) {
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
offset += 0x10;
|
size_t ps_bytes_to_samples(size_t bytes, int channels) {
|
||||||
}
|
if (channels <= 0) return 0;
|
||||||
|
return bytes / channels / 0x10 * 28;
|
||||||
return 1;
|
}
|
||||||
}
|
|
||||||
|
size_t ps_cfg_bytes_to_samples(size_t bytes, size_t frame_size, int channels) {
|
||||||
|
int samples_per_frame = (frame_size - 0x01) * 2;
|
||||||
|
return bytes / channels / frame_size * samples_per_frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* test PS-ADPCM frames for correctness */
|
||||||
|
int ps_check_format(STREAMFILE *streamFile, off_t offset, size_t max) {
|
||||||
|
off_t max_offset = offset + max;
|
||||||
|
if (max_offset > get_streamfile_size(streamFile))
|
||||||
|
max_offset = get_streamfile_size(streamFile);
|
||||||
|
|
||||||
|
while (offset < max_offset) {
|
||||||
|
uint8_t predictor = (read_8bit(offset+0x00,streamFile) >> 4) & 0x0f;
|
||||||
|
uint8_t flags = read_8bit(offset+0x01,streamFile);
|
||||||
|
|
||||||
|
if (predictor > 5 || flags > 7) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
offset += 0x10;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
|
@ -1,60 +1,75 @@
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
#include "../coding/coding.h"
|
#include "../coding/coding.h"
|
||||||
#include "../layout/layout.h"
|
#include "../layout/layout.h"
|
||||||
#include "../vgmstream.h"
|
#include "../vgmstream.h"
|
||||||
|
|
||||||
|
|
||||||
static size_t get_block_header_size(STREAMFILE *streamFile, off_t offset, int channels, int big_endian);
|
static size_t get_channel_header_size(STREAMFILE* sf, off_t offset, int channels, int big_endian);
|
||||||
|
static size_t get_block_header_size(STREAMFILE* sf, off_t offset, size_t channel_header_size, int channels, int big_endian);
|
||||||
/* AWC music chunks */
|
|
||||||
void block_update_awc(off_t block_offset, VGMSTREAM * vgmstream) {
|
/* AWC music chunks */
|
||||||
STREAMFILE* streamFile = vgmstream->ch[0].streamfile;
|
void block_update_awc(off_t block_offset, VGMSTREAM * vgmstream) {
|
||||||
int32_t (*read_32bit)(off_t,STREAMFILE*) = vgmstream->codec_endian ? read_32bitBE : read_32bitLE;
|
STREAMFILE* sf = vgmstream->ch[0].streamfile;
|
||||||
size_t header_size, entries, block_size, block_samples;
|
int32_t (*read_32bit)(off_t,STREAMFILE*) = vgmstream->codec_endian ? read_32bitBE : read_32bitLE;
|
||||||
int i;
|
size_t header_size, entries, block_size, block_samples;
|
||||||
|
size_t channel_header_size;
|
||||||
/* assumed only AWC_IMA enters here, MPEG/XMA2 need special parsing as blocked layout is too limited */
|
int i;
|
||||||
|
|
||||||
entries = read_32bit(block_offset + 0x18*0 + 0x04, streamFile); /* assumed same for all channels */
|
/* assumed only AWC_IMA enters here, MPEG/XMA2 need special parsing as blocked layout is too limited */
|
||||||
block_samples = entries * (0x800-4)*2;
|
entries = read_32bit(block_offset + 0x04, sf); /* se first channel, assume all are the same */
|
||||||
block_size = vgmstream->full_block_size;
|
//block_samples = entries * (0x800-4)*2; //todo use
|
||||||
|
block_samples = read_32bit(block_offset + 0x0c, sf);
|
||||||
vgmstream->current_block_offset = block_offset;
|
block_size = vgmstream->full_block_size;
|
||||||
vgmstream->next_block_offset = block_offset + block_size;
|
|
||||||
vgmstream->current_block_samples = block_samples;
|
vgmstream->current_block_offset = block_offset;
|
||||||
|
vgmstream->next_block_offset = block_offset + block_size;
|
||||||
/* starts with a header block */
|
vgmstream->current_block_samples = block_samples;
|
||||||
/* for each channel
|
|
||||||
* 0x00: start entry within channel (ie. entries * ch)
|
/* starts with a header block */
|
||||||
* 0x04: entries
|
/* for each channel
|
||||||
* 0x08: samples to discard in the beginning of this block (MPEG only?)
|
* 0x00: start entry within channel (ie. entries * ch) but may be off by +1/+2
|
||||||
* 0x0c: samples in channel (for MPEG/XMA2 can vary between channels)
|
* 0x04: entries
|
||||||
* 0x10: MPEG only: close to number of frames but varies a bit?
|
* 0x08: samples to discard in the beginning of this block (MPEG only?)
|
||||||
* 0x14: MPEG only: channel usable data size (not counting padding)
|
* 0x0c: samples in channel (for MPEG/XMA2 can vary between channels)
|
||||||
* for each channel
|
* (next fields don't exist in later versions for IMA)
|
||||||
* 32b * entries = global samples per frame in each block (for MPEG probably per full frame)
|
* 0x10: (MPEG only, empty otherwise) close to number of frames but varies a bit?
|
||||||
*/
|
* 0x14: (MPEG only, empty otherwise) channel usable data size (not counting padding)
|
||||||
|
* for each channel
|
||||||
header_size = get_block_header_size(streamFile, block_offset, vgmstream->channels, vgmstream->codec_endian);
|
* 32b * entries = global samples per frame in each block (for MPEG probably per full frame)
|
||||||
for (i = 0; i < vgmstream->channels; i++) {
|
*/
|
||||||
vgmstream->ch[i].offset = block_offset + header_size + 0x800*entries*i;
|
|
||||||
}
|
channel_header_size = get_channel_header_size(sf, block_offset, vgmstream->channels, vgmstream->codec_endian);
|
||||||
|
header_size = get_block_header_size(sf, block_offset, channel_header_size, vgmstream->channels, vgmstream->codec_endian);
|
||||||
}
|
for (i = 0; i < vgmstream->channels; i++) {
|
||||||
|
vgmstream->ch[i].offset = block_offset + header_size + 0x800*entries*i;
|
||||||
static size_t get_block_header_size(STREAMFILE *streamFile, off_t offset, int channels, int big_endian) {
|
VGM_ASSERT(entries != read_32bit(block_offset + channel_header_size*i + 0x04, sf), "AWC: variable number of entries found at %lx\n", block_offset);
|
||||||
size_t header_size = 0;
|
}
|
||||||
int i;
|
|
||||||
int entries = channels;
|
}
|
||||||
int32_t (*read_32bit)(off_t,STREAMFILE*) = big_endian ? read_32bitBE : read_32bitLE;
|
|
||||||
|
static size_t get_channel_header_size(STREAMFILE* sf, off_t offset, int channels, int big_endian) {
|
||||||
for (i = 0; i < entries; i++) {
|
int32_t (*read_32bit)(off_t,STREAMFILE*) = big_endian ? read_32bitBE : read_32bitLE;
|
||||||
header_size += 0x18;
|
|
||||||
header_size += read_32bit(offset + 0x18*i + 0x04, streamFile) * 0x04; /* entries in the table */
|
/* later games have an smaller channel header, try to detect using
|
||||||
}
|
* an empty field not in IMA */
|
||||||
|
if (read_32bit(offset + 0x14, sf) == 0x00)
|
||||||
if (header_size % 0x800) /* padded */
|
return 0x18;
|
||||||
header_size += 0x800 - (header_size % 0x800);
|
return 0x10;
|
||||||
|
}
|
||||||
return header_size;
|
|
||||||
}
|
static size_t get_block_header_size(STREAMFILE* sf, off_t offset, size_t channel_header_size, int channels, int big_endian) {
|
||||||
|
size_t header_size = 0;
|
||||||
|
int i;
|
||||||
|
int entries = channels;
|
||||||
|
int32_t (*read_32bit)(off_t,STREAMFILE*) = big_endian ? read_32bitBE : read_32bitLE;
|
||||||
|
|
||||||
|
for (i = 0; i < entries; i++) {
|
||||||
|
header_size += channel_header_size;
|
||||||
|
header_size += read_32bit(offset + channel_header_size*i + 0x04, sf) * 0x04; /* entries in the table */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (header_size % 0x800) /* padded */
|
||||||
|
header_size += 0x800 - (header_size % 0x800);
|
||||||
|
|
||||||
|
return header_size;
|
||||||
|
}
|
||||||
|
|
|
@ -209,6 +209,21 @@ static void load_awb_name(STREAMFILE *streamFile, STREAMFILE *acbFile, VGMSTREAM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* try (name)_(name)_R001.awb + (name).acb [Sengoku Basara Battle Party (Mobile)] */
|
||||||
|
if (!acbFile) {
|
||||||
|
char *cmp = "_R001";
|
||||||
|
get_streamfile_basename(streamFile, filename, sizeof(filename));
|
||||||
|
len_name = strlen(filename);
|
||||||
|
len_cmp = strlen(cmp);
|
||||||
|
|
||||||
|
if (len_name > len_cmp && strcmp(filename + len_name - len_cmp, cmp) == 0) {
|
||||||
|
filename[(len_name - len_cmp) / 2] = '\0';
|
||||||
|
strcat(filename, ".acb");
|
||||||
|
VGM_LOG("%s\n", filename);
|
||||||
|
acbFile = open_streamfile_by_filename(streamFile, filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* probably loaded */
|
/* probably loaded */
|
||||||
load_acb_wave_name(acbFile, vgmstream, waveid, is_memory);
|
load_acb_wave_name(acbFile, vgmstream, waveid, is_memory);
|
||||||
|
|
||||||
|
|
|
@ -1,349 +1,349 @@
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
#include "../coding/coding.h"
|
#include "../coding/coding.h"
|
||||||
#include "../layout/layout.h"
|
#include "../layout/layout.h"
|
||||||
#include "awc_xma_streamfile.h"
|
#include "awc_xma_streamfile.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int big_endian;
|
int big_endian;
|
||||||
int is_encrypted;
|
int is_encrypted;
|
||||||
int is_music;
|
int is_music;
|
||||||
|
|
||||||
int total_subsongs;
|
int total_subsongs;
|
||||||
|
|
||||||
int channel_count;
|
int channel_count;
|
||||||
int sample_rate;
|
int sample_rate;
|
||||||
int codec;
|
int codec;
|
||||||
int num_samples;
|
int num_samples;
|
||||||
|
|
||||||
int block_chunk;
|
int block_chunk;
|
||||||
|
|
||||||
off_t stream_offset;
|
off_t stream_offset;
|
||||||
size_t stream_size;
|
size_t stream_size;
|
||||||
|
|
||||||
} awc_header;
|
} awc_header;
|
||||||
|
|
||||||
static int parse_awc_header(STREAMFILE* streamFile, awc_header* awc);
|
static int parse_awc_header(STREAMFILE* streamFile, awc_header* awc);
|
||||||
|
|
||||||
|
|
||||||
/* AWC - from RAGE (Rockstar Advanced Game Engine) audio (Red Dead Redemption, Max Payne 3, GTA5) */
|
/* AWC - from RAGE (Rockstar Advanced Game Engine) audio (Red Dead Redemption, Max Payne 3, GTA5) */
|
||||||
VGMSTREAM * init_vgmstream_awc(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_awc(STREAMFILE *streamFile) {
|
||||||
VGMSTREAM * vgmstream = NULL;
|
VGMSTREAM * vgmstream = NULL;
|
||||||
awc_header awc = {0};
|
awc_header awc = {0};
|
||||||
|
|
||||||
/* check extension */
|
/* check extension */
|
||||||
if (!check_extensions(streamFile,"awc"))
|
if (!check_extensions(streamFile,"awc"))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
/* check header */
|
/* check header */
|
||||||
if (!parse_awc_header(streamFile, &awc))
|
if (!parse_awc_header(streamFile, &awc))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
|
||||||
/* build the VGMSTREAM */
|
/* build the VGMSTREAM */
|
||||||
vgmstream = allocate_vgmstream(awc.channel_count, 0);
|
vgmstream = allocate_vgmstream(awc.channel_count, 0);
|
||||||
if (!vgmstream) goto fail;
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
vgmstream->sample_rate = awc.sample_rate;
|
vgmstream->sample_rate = awc.sample_rate;
|
||||||
vgmstream->num_samples = awc.num_samples;
|
vgmstream->num_samples = awc.num_samples;
|
||||||
vgmstream->num_streams = awc.total_subsongs;
|
vgmstream->num_streams = awc.total_subsongs;
|
||||||
vgmstream->stream_size = awc.stream_size;
|
vgmstream->stream_size = awc.stream_size;
|
||||||
vgmstream->meta_type = meta_AWC;
|
vgmstream->meta_type = meta_AWC;
|
||||||
|
|
||||||
|
|
||||||
switch(awc.codec) {
|
switch(awc.codec) {
|
||||||
case 0x01: /* PCM (PC/PS3) [sfx, rarely] */
|
case 0x01: /* PCM (PC/PS3) [sfx, rarely] */
|
||||||
if (awc.is_music) goto fail; /* blocked_awc needs to be prepared */
|
if (awc.is_music) goto fail; /* blocked_awc needs to be prepared */
|
||||||
vgmstream->coding_type = awc.big_endian ? coding_PCM16BE : coding_PCM16LE;
|
vgmstream->coding_type = awc.big_endian ? coding_PCM16BE : coding_PCM16LE;
|
||||||
vgmstream->layout_type = layout_interleave;
|
vgmstream->layout_type = layout_interleave;
|
||||||
vgmstream->interleave_block_size = 0x02;
|
vgmstream->interleave_block_size = 0x02;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x04: /* IMA (PC) */
|
case 0x04: /* IMA (PC) */
|
||||||
vgmstream->coding_type = coding_AWC_IMA;
|
vgmstream->coding_type = coding_AWC_IMA;
|
||||||
vgmstream->layout_type = awc.is_music ? layout_blocked_awc : layout_none;
|
vgmstream->layout_type = awc.is_music ? layout_blocked_awc : layout_none;
|
||||||
vgmstream->full_block_size = awc.block_chunk;
|
vgmstream->full_block_size = awc.block_chunk;
|
||||||
vgmstream->codec_endian = awc.big_endian;
|
vgmstream->codec_endian = awc.big_endian;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef VGM_USE_FFMPEG
|
#ifdef VGM_USE_FFMPEG
|
||||||
case 0x05: { /* XMA2 (X360) */
|
case 0x05: { /* XMA2 (X360) */
|
||||||
uint8_t buf[0x100];
|
uint8_t buf[0x100];
|
||||||
size_t bytes, block_size, block_count, substream_size;
|
size_t bytes, block_size, block_count, substream_size;
|
||||||
off_t substream_offset;
|
off_t substream_offset;
|
||||||
|
|
||||||
if (awc.is_music) {
|
if (awc.is_music) {
|
||||||
/* 1ch XMAs in blocks, we'll use layered layout + custom IO to get multi-FFmpegs working */
|
/* 1ch XMAs in blocks, we'll use layered layout + custom IO to get multi-FFmpegs working */
|
||||||
int i;
|
int i;
|
||||||
layered_layout_data * data = NULL;
|
layered_layout_data * data = NULL;
|
||||||
|
|
||||||
/* init layout */
|
/* init layout */
|
||||||
data = init_layout_layered(awc.channel_count);
|
data = init_layout_layered(awc.channel_count);
|
||||||
if (!data) goto fail;
|
if (!data) goto fail;
|
||||||
vgmstream->layout_data = data;
|
vgmstream->layout_data = data;
|
||||||
vgmstream->layout_type = layout_layered;
|
vgmstream->layout_type = layout_layered;
|
||||||
vgmstream->coding_type = coding_FFmpeg;
|
vgmstream->coding_type = coding_FFmpeg;
|
||||||
|
|
||||||
/* open each layer subfile */
|
/* open each layer subfile */
|
||||||
for (i = 0; i < awc.channel_count; i++) {
|
for (i = 0; i < awc.channel_count; i++) {
|
||||||
STREAMFILE* temp_streamFile;
|
STREAMFILE* temp_streamFile;
|
||||||
int layer_channels = 1;
|
int layer_channels = 1;
|
||||||
|
|
||||||
/* build the layer VGMSTREAM */
|
/* build the layer VGMSTREAM */
|
||||||
data->layers[i] = allocate_vgmstream(layer_channels, 0);
|
data->layers[i] = allocate_vgmstream(layer_channels, 0);
|
||||||
if (!data->layers[i]) goto fail;
|
if (!data->layers[i]) goto fail;
|
||||||
|
|
||||||
data->layers[i]->sample_rate = awc.sample_rate;
|
data->layers[i]->sample_rate = awc.sample_rate;
|
||||||
data->layers[i]->meta_type = meta_AWC;
|
data->layers[i]->meta_type = meta_AWC;
|
||||||
data->layers[i]->coding_type = coding_FFmpeg;
|
data->layers[i]->coding_type = coding_FFmpeg;
|
||||||
data->layers[i]->layout_type = layout_none;
|
data->layers[i]->layout_type = layout_none;
|
||||||
data->layers[i]->num_samples = awc.num_samples;
|
data->layers[i]->num_samples = awc.num_samples;
|
||||||
|
|
||||||
/* setup custom IO streamfile, pass to FFmpeg and hope it's fooled */
|
/* setup custom IO streamfile, pass to FFmpeg and hope it's fooled */
|
||||||
temp_streamFile = setup_awc_xma_streamfile(streamFile, awc.stream_offset, awc.stream_size, awc.block_chunk, awc.channel_count, i);
|
temp_streamFile = setup_awc_xma_streamfile(streamFile, awc.stream_offset, awc.stream_size, awc.block_chunk, awc.channel_count, i);
|
||||||
if (!temp_streamFile) goto fail;
|
if (!temp_streamFile) goto fail;
|
||||||
|
|
||||||
substream_offset = 0; /* where FFmpeg thinks data starts, which our custom streamFile will clamp */
|
substream_offset = 0; /* where FFmpeg thinks data starts, which our custom streamFile will clamp */
|
||||||
substream_size = get_streamfile_size(temp_streamFile); /* data of one XMA substream without blocks */
|
substream_size = get_streamfile_size(temp_streamFile); /* data of one XMA substream without blocks */
|
||||||
block_size = 0x8000; /* no idea */
|
block_size = 0x8000; /* no idea */
|
||||||
block_count = substream_size / block_size; /* not accurate but not needed */
|
block_count = substream_size / block_size; /* not accurate but not needed */
|
||||||
|
|
||||||
bytes = ffmpeg_make_riff_xma2(buf, 0x100, awc.num_samples, substream_size, layer_channels, awc.sample_rate, block_count, block_size);
|
bytes = ffmpeg_make_riff_xma2(buf, 0x100, awc.num_samples, substream_size, layer_channels, awc.sample_rate, block_count, block_size);
|
||||||
data->layers[i]->codec_data = init_ffmpeg_header_offset(temp_streamFile, buf,bytes, substream_offset,substream_size);
|
data->layers[i]->codec_data = init_ffmpeg_header_offset(temp_streamFile, buf,bytes, substream_offset,substream_size);
|
||||||
|
|
||||||
xma_fix_raw_samples(data->layers[i], temp_streamFile, substream_offset,substream_size, 0, 0,0); /* samples are ok? */
|
xma_fix_raw_samples(data->layers[i], temp_streamFile, substream_offset,substream_size, 0, 0,0); /* samples are ok? */
|
||||||
|
|
||||||
close_streamfile(temp_streamFile);
|
close_streamfile(temp_streamFile);
|
||||||
if (!data->layers[i]->codec_data) goto fail;
|
if (!data->layers[i]->codec_data) goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* setup layered VGMSTREAMs */
|
/* setup layered VGMSTREAMs */
|
||||||
if (!setup_layout_layered(data))
|
if (!setup_layout_layered(data))
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* regular XMA for sfx */
|
/* regular XMA for sfx */
|
||||||
block_size = 0x8000; /* no idea */
|
block_size = 0x8000; /* no idea */
|
||||||
block_count = awc.stream_size / block_size; /* not accurate but not needed */
|
block_count = awc.stream_size / block_size; /* not accurate but not needed */
|
||||||
|
|
||||||
bytes = ffmpeg_make_riff_xma2(buf, 0x100, awc.num_samples, awc.stream_size, awc.channel_count, awc.sample_rate, block_count, block_size);
|
bytes = ffmpeg_make_riff_xma2(buf, 0x100, awc.num_samples, awc.stream_size, awc.channel_count, awc.sample_rate, block_count, block_size);
|
||||||
vgmstream->codec_data = init_ffmpeg_header_offset(streamFile, buf,bytes, awc.stream_offset,awc.stream_size);
|
vgmstream->codec_data = init_ffmpeg_header_offset(streamFile, buf,bytes, awc.stream_offset,awc.stream_size);
|
||||||
if (!vgmstream->codec_data) goto fail;
|
if (!vgmstream->codec_data) goto fail;
|
||||||
vgmstream->coding_type = coding_FFmpeg;
|
vgmstream->coding_type = coding_FFmpeg;
|
||||||
vgmstream->layout_type = layout_none;
|
vgmstream->layout_type = layout_none;
|
||||||
|
|
||||||
xma_fix_raw_samples(vgmstream, streamFile, awc.stream_offset,awc.stream_size, 0, 0,0); /* samples are ok? */
|
xma_fix_raw_samples(vgmstream, streamFile, awc.stream_offset,awc.stream_size, 0, 0,0); /* samples are ok? */
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef VGM_USE_MPEG
|
#ifdef VGM_USE_MPEG
|
||||||
case 0x07: { /* MPEG (PS3) */
|
case 0x07: { /* MPEG (PS3) */
|
||||||
mpeg_custom_config cfg = {0};
|
mpeg_custom_config cfg = {0};
|
||||||
|
|
||||||
cfg.chunk_size = awc.block_chunk;
|
cfg.chunk_size = awc.block_chunk;
|
||||||
cfg.big_endian = awc.big_endian;
|
cfg.big_endian = awc.big_endian;
|
||||||
|
|
||||||
vgmstream->codec_data = init_mpeg_custom(streamFile, awc.stream_offset, &vgmstream->coding_type, vgmstream->channels, MPEG_AWC, &cfg);
|
vgmstream->codec_data = init_mpeg_custom(streamFile, awc.stream_offset, &vgmstream->coding_type, vgmstream->channels, MPEG_AWC, &cfg);
|
||||||
if (!vgmstream->codec_data) goto fail;
|
if (!vgmstream->codec_data) goto fail;
|
||||||
vgmstream->layout_type = layout_none;
|
vgmstream->layout_type = layout_none;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
VGM_LOG("AWC: unknown codec 0x%02x\n", awc.codec);
|
VGM_LOG("AWC: unknown codec 0x%02x\n", awc.codec);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!vgmstream_open_stream(vgmstream,streamFile,awc.stream_offset))
|
if (!vgmstream_open_stream(vgmstream,streamFile,awc.stream_offset))
|
||||||
goto fail;
|
goto fail;
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Parse Rockstar's AWC header (much info from LibertyV: https://github.com/koolkdev/libertyv).
|
/* Parse Rockstar's AWC header (much info from LibertyV: https://github.com/koolkdev/libertyv).
|
||||||
* Made of entries for N streams, each with a number of tags pointing to chunks (header, data, events, etc). */
|
* Made of entries for N streams, each with a number of tags pointing to chunks (header, data, events, etc). */
|
||||||
static int parse_awc_header(STREAMFILE* streamFile, awc_header* awc) {
|
static int parse_awc_header(STREAMFILE* streamFile, awc_header* awc) {
|
||||||
int64_t (*read_64bit)(off_t,STREAMFILE*) = NULL;
|
int64_t (*read_64bit)(off_t,STREAMFILE*) = NULL;
|
||||||
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
|
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
|
||||||
int16_t (*read_16bit)(off_t,STREAMFILE*) = NULL;
|
int16_t (*read_16bit)(off_t,STREAMFILE*) = NULL;
|
||||||
int i, ch, entries;
|
int i, ch, entries;
|
||||||
uint32_t flags, info_header, tag_count = 0, tags_skip = 0;
|
uint32_t flags, info_header, tag_count = 0, tags_skip = 0;
|
||||||
off_t off;
|
off_t off;
|
||||||
int target_subsong = streamFile->stream_index;
|
int target_subsong = streamFile->stream_index;
|
||||||
|
|
||||||
|
|
||||||
/* check header */
|
/* check header */
|
||||||
if (read_32bitBE(0x00,streamFile) != 0x41444154 && /* "ADAT" (LE) */
|
if (read_32bitBE(0x00,streamFile) != 0x41444154 && /* "ADAT" (LE) */
|
||||||
read_32bitBE(0x00,streamFile) != 0x54414441) /* "TADA" (BE) */
|
read_32bitBE(0x00,streamFile) != 0x54414441) /* "TADA" (BE) */
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
awc->big_endian = read_32bitBE(0x00,streamFile) == 0x54414441;
|
awc->big_endian = read_32bitBE(0x00,streamFile) == 0x54414441;
|
||||||
if (awc->big_endian) {
|
if (awc->big_endian) {
|
||||||
read_64bit = read_64bitBE;
|
read_64bit = read_64bitBE;
|
||||||
read_32bit = read_32bitBE;
|
read_32bit = read_32bitBE;
|
||||||
read_16bit = read_16bitBE;
|
read_16bit = read_16bitBE;
|
||||||
} else {
|
} else {
|
||||||
read_64bit = read_64bitLE;
|
read_64bit = read_64bitLE;
|
||||||
read_32bit = read_32bitLE;
|
read_32bit = read_32bitLE;
|
||||||
read_16bit = read_16bitLE;
|
read_16bit = read_16bitLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
flags = read_32bit(0x04,streamFile);
|
flags = read_32bit(0x04,streamFile);
|
||||||
entries = read_32bit(0x08,streamFile);
|
entries = read_32bit(0x08,streamFile);
|
||||||
//header_size = read_32bit(0x0c,streamFile); /* after to stream id/tags, not including chunks */
|
//header_size = read_32bit(0x0c,streamFile); /* after to stream id/tags, not including chunks */
|
||||||
|
|
||||||
off = 0x10;
|
off = 0x10;
|
||||||
|
|
||||||
if ((flags & 0xFF00FFFF) != 0xFF000001 || (flags & 0x00F00000)) {
|
if ((flags & 0xFF00FFFF) != 0xFF000001 || (flags & 0x00F00000)) {
|
||||||
VGM_LOG("AWC: unknown flags 0x%08x\n", flags);
|
VGM_LOG("AWC: unknown flags 0x%08x\n", flags);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & 0x00010000) /* some kind of mini offset table */
|
if (flags & 0x00010000) /* some kind of mini offset table */
|
||||||
off += 0x2 * entries;
|
off += 0x2 * entries;
|
||||||
//if (flags % 0x00020000) /* seems to indicate chunks are not ordered (ie. header may go after data) */
|
//if (flags % 0x00020000) /* seems to indicate chunks are not ordered (ie. header may go after data) */
|
||||||
// ...
|
// ...
|
||||||
//if (flags % 0x00040000) /* music/multichannel flag? (GTA5, not seen in RDR) */
|
//if (flags % 0x00040000) /* music/multichannel flag? (GTA5, not seen in RDR) */
|
||||||
// awc->is_music = 1;
|
// awc->is_music = 1;
|
||||||
if (flags & 0x00080000) /* encrypted data chunk (most of GTA5 PC) */
|
if (flags & 0x00080000) /* encrypted data chunk (most of GTA5 PC) */
|
||||||
awc->is_encrypted = 1;
|
awc->is_encrypted = 1;
|
||||||
|
|
||||||
if (awc->is_encrypted) {
|
if (awc->is_encrypted) {
|
||||||
VGM_LOG("AWC: encrypted data found\n");
|
VGM_LOG("AWC: encrypted data found\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Music when the first id is 0 (base/fake entry with info for all channels), sfx pack otherwise.
|
/* Music when the first id is 0 (base/fake entry with info for all channels), sfx pack otherwise.
|
||||||
* sfx = N single streams, music = N-1 interleaved mono channels (even for MP3/XMA).
|
* sfx = N single streams, music = N-1 interleaved mono channels (even for MP3/XMA).
|
||||||
* Music seems layered (N-1/2 stereo pairs), maybe set with events? */
|
* Music seems layered (N-1/2 stereo pairs), maybe set with events? */
|
||||||
awc->is_music = (read_32bit(off + 0x00,streamFile) & 0x1FFFFFFF) == 0x00000000;
|
awc->is_music = (read_32bit(off + 0x00,streamFile) & 0x1FFFFFFF) == 0x00000000;
|
||||||
if (awc->is_music) { /* all streams except id 0 is a channel */
|
if (awc->is_music) { /* all streams except id 0 is a channel */
|
||||||
awc->total_subsongs = 1;
|
awc->total_subsongs = 1;
|
||||||
target_subsong = 1; /* we only need id 0, though channels may have its own tags/chunks */
|
target_subsong = 1; /* we only need id 0, though channels may have its own tags/chunks */
|
||||||
}
|
}
|
||||||
else { /* each stream is a single sound */
|
else { /* each stream is a single sound */
|
||||||
awc->total_subsongs = entries;
|
awc->total_subsongs = entries;
|
||||||
if (target_subsong == 0) target_subsong = 1;
|
if (target_subsong == 0) target_subsong = 1;
|
||||||
if (target_subsong < 0 || target_subsong > awc->total_subsongs || awc->total_subsongs < 1) goto fail;
|
if (target_subsong < 0 || target_subsong > awc->total_subsongs || awc->total_subsongs < 1) goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* get stream base info */
|
/* get stream base info */
|
||||||
for (i = 0; i < entries; i++) {
|
for (i = 0; i < entries; i++) {
|
||||||
info_header = read_32bit(off + 0x04*i, streamFile);
|
info_header = read_32bit(off + 0x04*i, streamFile);
|
||||||
tag_count = (info_header >> 29) & 0x7; /* 3b */
|
tag_count = (info_header >> 29) & 0x7; /* 3b */
|
||||||
//id = (info_header >> 0) & 0x1FFFFFFF; /* 29b */
|
//id = (info_header >> 0) & 0x1FFFFFFF; /* 29b */
|
||||||
if (target_subsong-1 == i)
|
if (target_subsong-1 == i)
|
||||||
break;
|
break;
|
||||||
tags_skip += tag_count; /* tags to skip to reach target's tags, in the next header */
|
tags_skip += tag_count; /* tags to skip to reach target's tags, in the next header */
|
||||||
}
|
}
|
||||||
off += 0x04*entries;
|
off += 0x04*entries;
|
||||||
off += 0x08*tags_skip;
|
off += 0x08*tags_skip;
|
||||||
|
|
||||||
/* get stream tags */
|
/* get stream tags */
|
||||||
for (i = 0; i < tag_count; i++) {
|
for (i = 0; i < tag_count; i++) {
|
||||||
uint64_t tag_header;
|
uint64_t tag_header;
|
||||||
uint8_t tag;
|
uint8_t tag;
|
||||||
size_t size;
|
size_t size;
|
||||||
off_t offset;
|
off_t offset;
|
||||||
|
|
||||||
tag_header = (uint64_t)read_64bit(off + 0x08*i,streamFile);
|
tag_header = (uint64_t)read_64bit(off + 0x08*i,streamFile);
|
||||||
tag = (uint8_t)((tag_header >> 56) & 0xFF); /* 8b */
|
tag = (uint8_t)((tag_header >> 56) & 0xFF); /* 8b */
|
||||||
size = (size_t)((tag_header >> 28) & 0x0FFFFFFF); /* 28b */
|
size = (size_t)((tag_header >> 28) & 0x0FFFFFFF); /* 28b */
|
||||||
offset = (off_t)((tag_header >> 0) & 0x0FFFFFFF); /* 28b */
|
offset = (off_t)((tag_header >> 0) & 0x0FFFFFFF); /* 28b */
|
||||||
|
|
||||||
/* Tags are apparently part of a hash derived from a word ("data", "format", etc).
|
/* Tags are apparently part of a hash derived from a word ("data", "format", etc).
|
||||||
* If music + 1ch, the header and data chunks can repeat for no reason (sometimes not even pointed). */
|
* If music + 1ch, the header and data chunks can repeat for no reason (sometimes not even pointed). */
|
||||||
switch(tag) {
|
switch(tag) {
|
||||||
case 0x55: /* data */
|
case 0x55: /* data */
|
||||||
awc->stream_offset = offset;
|
awc->stream_offset = offset;
|
||||||
awc->stream_size = size;
|
awc->stream_size = size;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x48: /* music header */
|
case 0x48: /* music header */
|
||||||
if (!awc->is_music) {
|
if (!awc->is_music) {
|
||||||
VGM_LOG("AWC: music header found in sfx\n");
|
VGM_LOG("AWC: music header found in sfx\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 0x00(32): unknown (some count?) */
|
/* 0x00(32): unknown (some count?) */
|
||||||
awc->block_chunk = read_32bit(offset + 0x04,streamFile);
|
awc->block_chunk = read_32bit(offset + 0x04,streamFile);
|
||||||
awc->channel_count = read_32bit(offset + 0x08,streamFile);
|
awc->channel_count = read_32bit(offset + 0x08,streamFile);
|
||||||
|
|
||||||
if (awc->channel_count != entries - 1) { /* not counting id-0 */
|
if (awc->channel_count != entries - 1) { /* not counting id-0 */
|
||||||
VGM_LOG("AWC: number of music channels doesn't match entries\n");
|
VGM_LOG("AWC: number of music channels doesn't match entries\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ch = 0; ch < awc->channel_count; ch++) {
|
for (ch = 0; ch < awc->channel_count; ch++) {
|
||||||
int num_samples, sample_rate, codec;
|
int num_samples, sample_rate, codec;
|
||||||
/* 0x00(32): stream id (not always in the header entries order) */
|
/* 0x00(32): stream id (not always in the header entries order) */
|
||||||
/* 0x08(16): headroom?, 0x0d(8): round size?, 0x0e(16): unknown (zero?) */
|
/* 0x08(16): headroom?, 0x0d(8): round size?, 0x0e(16): unknown (zero?) */
|
||||||
num_samples = read_32bit(offset + 0x0c + 0x10*ch + 0x04,streamFile);
|
num_samples = read_32bit(offset + 0x0c + 0x10*ch + 0x04,streamFile);
|
||||||
sample_rate = (uint16_t)read_16bit(offset + 0x0c + 0x10*ch + 0x0a,streamFile);
|
sample_rate = (uint16_t)read_16bit(offset + 0x0c + 0x10*ch + 0x0a,streamFile);
|
||||||
codec = read_8bit(offset + 0x0c + 0x10*ch + 0x0c, streamFile);
|
codec = read_8bit(offset + 0x0c + 0x10*ch + 0x0c, streamFile);
|
||||||
|
|
||||||
/* validate as all channels should repeat this (when channels is even and > 2 seems
|
/* validate as all channels should repeat this (when channels is even and > 2 seems
|
||||||
* it's stereo pairs, and num_samples can vary slightly but no matter) */
|
* it's stereo pairs, and num_samples can vary slightly but no matter) */
|
||||||
if ((awc->num_samples && !(awc->num_samples >= num_samples - 10 && awc->num_samples <= num_samples + 10)) ||
|
if ((awc->num_samples && !(awc->num_samples >= num_samples - 10 && awc->num_samples <= num_samples + 10)) ||
|
||||||
(awc->sample_rate && awc->sample_rate != sample_rate) ||
|
(awc->sample_rate && awc->sample_rate != sample_rate) ||
|
||||||
(awc->codec && awc->codec != codec)) {
|
(awc->codec && awc->codec != codec)) {
|
||||||
VGM_LOG("AWC: found header diffs in channel %i, ns=%i vs %i, sr=%i vs %i, c=%i vs %i\n",
|
VGM_LOG("AWC: found header diffs in channel %i, ns=%i vs %i, sr=%i vs %i, c=%i vs %i\n",
|
||||||
ch, awc->num_samples, num_samples, awc->sample_rate, sample_rate, awc->codec, codec);
|
ch, awc->num_samples, num_samples, awc->sample_rate, sample_rate, awc->codec, codec);
|
||||||
goto fail;
|
//goto fail; //todo some Max Payne 3 cutscene channels have huge sample diffs
|
||||||
}
|
}
|
||||||
|
|
||||||
awc->num_samples = num_samples;
|
awc->num_samples = num_samples;
|
||||||
awc->sample_rate = sample_rate;
|
awc->sample_rate = sample_rate;
|
||||||
awc->codec = codec;
|
awc->codec = codec;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xFA: /* sfx header */
|
case 0xFA: /* sfx header */
|
||||||
if (awc->is_music) {
|
if (awc->is_music) {
|
||||||
VGM_LOG("AWC: sfx header found in music\n");
|
VGM_LOG("AWC: sfx header found in music\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
/* 0x04(32): -1?, 0x0a(16x4): unknown x4, 0x12: null? */
|
/* 0x04(32): -1?, 0x0a(16x4): unknown x4, 0x12: null? */
|
||||||
awc->num_samples = read_32bit(offset + 0x00,streamFile);
|
awc->num_samples = read_32bit(offset + 0x00,streamFile);
|
||||||
awc->sample_rate = (uint16_t)read_16bit(offset + 0x08,streamFile);
|
awc->sample_rate = (uint16_t)read_16bit(offset + 0x08,streamFile);
|
||||||
awc->codec = read_8bit(offset + 0x13, streamFile);
|
awc->codec = read_8bit(offset + 0x13, streamFile);
|
||||||
awc->channel_count = 1;
|
awc->channel_count = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0xA3: /* block-to-sample table (32b x number of blocks w/ num_samples at the start of each block) */
|
case 0xA3: /* block-to-sample table (32b x number of blocks w/ num_samples at the start of each block) */
|
||||||
case 0xBD: /* events (32bx4): type_hash, params_hash, timestamp_ms, flags */
|
case 0xBD: /* events (32bx4): type_hash, params_hash, timestamp_ms, flags */
|
||||||
default: /* 0x5C=animation/RSC?, 0x68=midi?, 0x36/0x2B/0x5A/0xD9=? */
|
default: /* 0x5C=animation/RSC?, 0x68=midi?, 0x36/0x2B/0x5A/0xD9=? */
|
||||||
//VGM_LOG("AWC: ignoring unknown tag 0x%02x\n", tag);
|
//VGM_LOG("AWC: ignoring unknown tag 0x%02x\n", tag);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!awc->stream_offset) {
|
if (!awc->stream_offset) {
|
||||||
VGM_LOG("AWC: stream offset not found\n");
|
VGM_LOG("AWC: stream offset not found\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If music, data is divided into blocks of block_chunk size with padding.
|
/* If music, data is divided into blocks of block_chunk size with padding.
|
||||||
* Each block has a header/seek table and interleaved data for all channels */
|
* Each block has a header/seek table and interleaved data for all channels */
|
||||||
if (awc->is_music && read_32bit(awc->stream_offset, streamFile) != 0) {
|
if (awc->is_music && read_32bit(awc->stream_offset, streamFile) != 0) {
|
||||||
VGM_LOG("AWC: music found, but block doesn't start with seek table at %x\n", (uint32_t)awc->stream_offset);
|
VGM_LOG("AWC: music found, but block doesn't start with seek table at %x\n", (uint32_t)awc->stream_offset);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
fail:
|
fail:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -860,6 +860,7 @@ VGMSTREAM * init_vgmstream_nub_wav(STREAMFILE * streamFile);
|
||||||
VGMSTREAM * init_vgmstream_nub_vag(STREAMFILE* streamFile);
|
VGMSTREAM * init_vgmstream_nub_vag(STREAMFILE* streamFile);
|
||||||
VGMSTREAM * init_vgmstream_nub_at3(STREAMFILE * streamFile);
|
VGMSTREAM * init_vgmstream_nub_at3(STREAMFILE * streamFile);
|
||||||
VGMSTREAM * init_vgmstream_nub_xma(STREAMFILE *streamFile);
|
VGMSTREAM * init_vgmstream_nub_xma(STREAMFILE *streamFile);
|
||||||
|
VGMSTREAM * init_vgmstream_nub_dsp(STREAMFILE * streamFile);
|
||||||
VGMSTREAM * init_vgmstream_nub_idsp(STREAMFILE * streamFile);
|
VGMSTREAM * init_vgmstream_nub_idsp(STREAMFILE * streamFile);
|
||||||
VGMSTREAM * init_vgmstream_nub_is14(STREAMFILE * streamFile);
|
VGMSTREAM * init_vgmstream_nub_is14(STREAMFILE * streamFile);
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,11 @@ VGMSTREAM * init_vgmstream_nub(STREAMFILE *streamFile) {
|
||||||
init_vgmstream_function = init_vgmstream_nub_xma;
|
init_vgmstream_function = init_vgmstream_nub_xma;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 0x05: /* "dsp\0" */
|
||||||
|
fake_ext = "dsp";
|
||||||
|
init_vgmstream_function = init_vgmstream_nub_dsp;
|
||||||
|
break;
|
||||||
|
|
||||||
case 0x06: /* "idsp" */
|
case 0x06: /* "idsp" */
|
||||||
fake_ext = "idsp";
|
fake_ext = "idsp";
|
||||||
init_vgmstream_function = init_vgmstream_nub_idsp;
|
init_vgmstream_function = init_vgmstream_nub_idsp;
|
||||||
|
@ -130,7 +135,6 @@ VGMSTREAM * init_vgmstream_nub(STREAMFILE *streamFile) {
|
||||||
init_vgmstream_function = init_vgmstream_nub_is14;
|
init_vgmstream_function = init_vgmstream_nub_is14;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x05:
|
|
||||||
default:
|
default:
|
||||||
VGM_LOG("NUB: unknown codec %x\n", codec);
|
VGM_LOG("NUB: unknown codec %x\n", codec);
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -512,6 +516,40 @@ fail:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* .nub dsp - from Namco NUB archives [Taiko no Tatsujin Wii Chou Goukanban (Wii)] */
|
||||||
|
VGMSTREAM * init_vgmstream_nub_dsp(STREAMFILE *streamFile) {
|
||||||
|
VGMSTREAM *vgmstream = NULL;
|
||||||
|
STREAMFILE *temp_sf = NULL;
|
||||||
|
off_t header_offset, stream_offset;
|
||||||
|
size_t header_size, stream_size;
|
||||||
|
|
||||||
|
|
||||||
|
/* checks */
|
||||||
|
if (!check_extensions(streamFile,"dsp"))
|
||||||
|
goto fail;
|
||||||
|
if (read_32bitBE(0x00,streamFile) != 0x64737000) /* "dsp\0" */
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
/* paste header+data together and pass to meta, which has loop info too */
|
||||||
|
header_offset = 0xBC;
|
||||||
|
stream_size = read_32bitBE(0x14, streamFile);
|
||||||
|
header_size = read_32bitBE(0x1c, streamFile);
|
||||||
|
stream_offset = align_size_to_block(header_offset + header_size, 0x10);
|
||||||
|
|
||||||
|
temp_sf = setup_nub_streamfile(streamFile, header_offset, header_size, stream_offset, stream_size, "dsp");
|
||||||
|
if (!temp_sf) goto fail;
|
||||||
|
|
||||||
|
vgmstream = init_vgmstream_ngc_dsp_std(temp_sf);
|
||||||
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
|
close_streamfile(temp_sf);
|
||||||
|
return vgmstream;
|
||||||
|
fail:
|
||||||
|
close_streamfile(temp_sf);
|
||||||
|
close_vgmstream(vgmstream);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* .nub idsp - from Namco NUB archives [Soul Calibur Legends (Wii), Sky Crawlers: Innocent Aces (Wii)] */
|
/* .nub idsp - from Namco NUB archives [Soul Calibur Legends (Wii), Sky Crawlers: Innocent Aces (Wii)] */
|
||||||
VGMSTREAM * init_vgmstream_nub_idsp(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_nub_idsp(STREAMFILE *streamFile) {
|
||||||
VGMSTREAM *vgmstream = NULL;
|
VGMSTREAM *vgmstream = NULL;
|
||||||
|
|
|
@ -221,7 +221,7 @@ static int read_fmt(int big_endian, STREAMFILE * streamFile, off_t current_chunk
|
||||||
goto fail;
|
goto fail;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case 0x270: /* ATRAC3 */
|
case 0x0270: /* ATRAC3 */
|
||||||
#ifdef VGM_USE_FFMPEG
|
#ifdef VGM_USE_FFMPEG
|
||||||
fmt->coding_type = coding_FFmpeg;
|
fmt->coding_type = coding_FFmpeg;
|
||||||
fmt->is_at3 = 1;
|
fmt->is_at3 = 1;
|
||||||
|
@ -312,6 +312,7 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
||||||
int32_t loop_start_wsmp = -1, loop_end_wsmp = -1;
|
int32_t loop_start_wsmp = -1, loop_end_wsmp = -1;
|
||||||
int32_t loop_start_smpl = -1, loop_end_smpl = -1;
|
int32_t loop_start_smpl = -1, loop_end_smpl = -1;
|
||||||
int32_t loop_start_cue = -1;
|
int32_t loop_start_cue = -1;
|
||||||
|
int32_t loop_start_nxbf = -1;
|
||||||
|
|
||||||
int FormatChunkFound = 0, DataChunkFound = 0, JunkFound = 0;
|
int FormatChunkFound = 0, DataChunkFound = 0, JunkFound = 0;
|
||||||
|
|
||||||
|
@ -340,7 +341,7 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
||||||
* .wvx: Godzilla - Destroy All Monsters Melee (Xbox)
|
* .wvx: Godzilla - Destroy All Monsters Melee (Xbox)
|
||||||
* .str: Harry Potter and the Philosopher's Stone (Xbox)
|
* .str: Harry Potter and the Philosopher's Stone (Xbox)
|
||||||
* .at3: standard ATRAC3
|
* .at3: standard ATRAC3
|
||||||
* .rws: Climax games (Silent Hill Origins PSP, Oblivion PSP) ATRAC3
|
* .rws: Climax ATRAC3 [Silent Hill Origins (PSP), Oblivion (PSP)]
|
||||||
* .aud: EA Replay ATRAC3
|
* .aud: EA Replay ATRAC3
|
||||||
* .at9: standard ATRAC9
|
* .at9: standard ATRAC9
|
||||||
* .saf: Whacked! (Xbox)
|
* .saf: Whacked! (Xbox)
|
||||||
|
@ -377,6 +378,8 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
||||||
riff_size -= 0x04; /* [Halo 2 (PC)] (possibly bad extractor? 'Gravemind Tool') */
|
riff_size -= 0x04; /* [Halo 2 (PC)] (possibly bad extractor? 'Gravemind Tool') */
|
||||||
else if (riff_size == file_size && codec == 0x0300)
|
else if (riff_size == file_size && codec == 0x0300)
|
||||||
riff_size -= 0x08; /* [Chrono Ma:gia (Android)] */
|
riff_size -= 0x08; /* [Chrono Ma:gia (Android)] */
|
||||||
|
else if (riff_size >= file_size && read_32bitBE(0x24,streamFile) == 0x4E584246) /* "NXBF" */
|
||||||
|
riff_size = file_size - 0x08; /* [R:Racing Evolution (Xbox)] */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for truncated RIFF */
|
/* check for truncated RIFF */
|
||||||
|
@ -506,6 +509,23 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 0x4E584246: /* "NXBF" (Namco NUS v1) [R:Racing Evolution (Xbox)] */
|
||||||
|
/* 0x00: "NXBF" again */
|
||||||
|
/* 0x04: always 0x1000? */
|
||||||
|
/* 0x08: data size */
|
||||||
|
/* 0x0c: channels */
|
||||||
|
/* 0x10: null */
|
||||||
|
loop_start_nxbf = read_32bitLE(current_chunk + 0x08 + 0x14, streamFile);
|
||||||
|
/* 0x18: sample rate */
|
||||||
|
/* 0x1c: volume? */
|
||||||
|
/* 0x20: type/flags? */
|
||||||
|
/* 0x24: codec? */
|
||||||
|
/* 0x28: null */
|
||||||
|
/* 0x2c: null */
|
||||||
|
/* 0x30: type/flags? */
|
||||||
|
loop_flag = (loop_start_nxbf >= 0);
|
||||||
|
break;
|
||||||
|
|
||||||
case 0x4A554E4B: /* "JUNK" */
|
case 0x4A554E4B: /* "JUNK" */
|
||||||
JunkFound = 1;
|
JunkFound = 1;
|
||||||
break;
|
break;
|
||||||
|
@ -778,6 +798,14 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
||||||
vgmstream->loop_start_sample = loop_start_cue;
|
vgmstream->loop_start_sample = loop_start_cue;
|
||||||
vgmstream->loop_end_sample = vgmstream->num_samples;
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
||||||
}
|
}
|
||||||
|
else if (loop_start_nxbf != -1) {
|
||||||
|
switch (fmt.coding_type) {
|
||||||
|
case coding_PCM16LE:
|
||||||
|
vgmstream->loop_start_sample = pcm_bytes_to_samples(loop_start_nxbf, vgmstream->channels, 16);
|
||||||
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (mwv) {
|
if (mwv) {
|
||||||
vgmstream->meta_type = meta_RIFF_WAVE_MWV;
|
vgmstream->meta_type = meta_RIFF_WAVE_MWV;
|
||||||
|
|
|
@ -153,10 +153,11 @@ VGMSTREAM * init_vgmstream_sgxd(STREAMFILE *streamFile) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
case 0x05: /* Short PS-ADPCM [Afrika (PS3)] */
|
case 0x05: /* Short PS-ADPCM [Afrika (PS3), LocoRoco Cocoreccho! (PS3)] */
|
||||||
vgmstream->coding_type = coding_PSX_cfg;
|
vgmstream->coding_type = coding_PSX_cfg;
|
||||||
vgmstream->layout_type = layout_interleave;
|
vgmstream->layout_type = layout_interleave;
|
||||||
vgmstream->interleave_block_size = 0x4;
|
vgmstream->interleave_block_size = 0x4;
|
||||||
|
vgmstream->codec_config = 1; /* needs extended table */
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -1,373 +1,373 @@
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
#include "../coding/coding.h"
|
#include "../coding/coding.h"
|
||||||
|
|
||||||
/* AAC - tri-Ace (Aska engine) Audio Container */
|
/* AAC - tri-Ace (Aska engine) Audio Container */
|
||||||
|
|
||||||
/* Xbox 360 Variants (Star Ocean 4, End of Eternity, Infinite Undiscovery) */
|
/* Xbox 360 Variants (Star Ocean 4, End of Eternity, Infinite Undiscovery) */
|
||||||
VGMSTREAM * init_vgmstream_ta_aac_x360(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_ta_aac_x360(STREAMFILE *streamFile) {
|
||||||
VGMSTREAM * vgmstream = NULL;
|
VGMSTREAM * vgmstream = NULL;
|
||||||
off_t start_offset;
|
off_t start_offset;
|
||||||
int loop_flag, channel_count;
|
int loop_flag, channel_count;
|
||||||
size_t sampleRate, numSamples, startSample, dataSize, blockSize, blockCount; // A mess
|
size_t sampleRate, numSamples, startSample, dataSize, blockSize, blockCount; // A mess
|
||||||
|
|
||||||
/* check extension, case insensitive */
|
/* check extension, case insensitive */
|
||||||
/* .aac: expected, .laac/ace: for players to avoid hijacking MP4/AAC */
|
/* .aac: expected, .laac/ace: for players to avoid hijacking MP4/AAC */
|
||||||
if ( !check_extensions(streamFile,"aac,laac,ace"))
|
if ( !check_extensions(streamFile,"aac,laac,ace"))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (read_32bitBE(0x00,streamFile) != 0x41414320) /* "AAC " */
|
if (read_32bitBE(0x00,streamFile) != 0x41414320) /* "AAC " */
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
/* Ok, let's check what's behind door number 1 */
|
/* Ok, let's check what's behind door number 1 */
|
||||||
if (read_32bitBE(0x1000, streamFile) == 0x41534320) /* "ASC " */
|
if (read_32bitBE(0x1000, streamFile) == 0x41534320) /* "ASC " */
|
||||||
{
|
{
|
||||||
loop_flag = read_32bitBE(0x1118, streamFile);
|
loop_flag = read_32bitBE(0x1118, streamFile);
|
||||||
|
|
||||||
/*Funky Channel Count Checking */
|
/*Funky Channel Count Checking */
|
||||||
if (read_32bitBE(0x1184, streamFile) == 0x7374726D)
|
if (read_32bitBE(0x1184, streamFile) == 0x7374726D)
|
||||||
channel_count = 6;
|
channel_count = 6;
|
||||||
else if (read_32bitBE(0x1154, streamFile) == 0x7374726D)
|
else if (read_32bitBE(0x1154, streamFile) == 0x7374726D)
|
||||||
channel_count = 4;
|
channel_count = 4;
|
||||||
else
|
else
|
||||||
channel_count = read_8bit(0x1134, streamFile);
|
channel_count = read_8bit(0x1134, streamFile);
|
||||||
|
|
||||||
sampleRate = read_32bitBE(0x10F4, streamFile);
|
sampleRate = read_32bitBE(0x10F4, streamFile);
|
||||||
numSamples = read_32bitBE(0x10FC, streamFile);
|
numSamples = read_32bitBE(0x10FC, streamFile);
|
||||||
startSample = read_32bitBE(0x10F8, streamFile);
|
startSample = read_32bitBE(0x10F8, streamFile);
|
||||||
dataSize = read_32bitBE(0x10F0, streamFile);
|
dataSize = read_32bitBE(0x10F0, streamFile);
|
||||||
blockSize = read_32bitBE(0x1100, streamFile);
|
blockSize = read_32bitBE(0x1100, streamFile);
|
||||||
blockCount = read_32bitBE(0x110C, streamFile);
|
blockCount = read_32bitBE(0x110C, streamFile);
|
||||||
}
|
}
|
||||||
else if (read_32bitBE(0x1000, streamFile) == 0x57415645) /* "WAVE" */
|
else if (read_32bitBE(0x1000, streamFile) == 0x57415645) /* "WAVE" */
|
||||||
{
|
{
|
||||||
loop_flag = read_32bitBE(0x1048, streamFile);
|
loop_flag = read_32bitBE(0x1048, streamFile);
|
||||||
|
|
||||||
/*Funky Channel Count Checking */
|
/*Funky Channel Count Checking */
|
||||||
if (read_32bitBE(0x10B0, streamFile) == 0x7374726D)
|
if (read_32bitBE(0x10B0, streamFile) == 0x7374726D)
|
||||||
channel_count = 6;
|
channel_count = 6;
|
||||||
else if (read_32bitBE(0x1080, streamFile) == 0x7374726D)
|
else if (read_32bitBE(0x1080, streamFile) == 0x7374726D)
|
||||||
channel_count = 4;
|
channel_count = 4;
|
||||||
else
|
else
|
||||||
channel_count = read_8bit(0x1060, streamFile);
|
channel_count = read_8bit(0x1060, streamFile);
|
||||||
|
|
||||||
sampleRate = read_32bitBE(0x1024, streamFile);
|
sampleRate = read_32bitBE(0x1024, streamFile);
|
||||||
numSamples = read_32bitBE(0x102C, streamFile);
|
numSamples = read_32bitBE(0x102C, streamFile);
|
||||||
startSample = read_32bitBE(0x1028, streamFile);
|
startSample = read_32bitBE(0x1028, streamFile);
|
||||||
dataSize = read_32bitBE(0x1020, streamFile);
|
dataSize = read_32bitBE(0x1020, streamFile);
|
||||||
blockSize = read_32bitBE(0x1030, streamFile);
|
blockSize = read_32bitBE(0x1030, streamFile);
|
||||||
blockCount = read_32bitBE(0x103C, streamFile);
|
blockCount = read_32bitBE(0x103C, streamFile);
|
||||||
}
|
}
|
||||||
else if (read_32bitBE(0x1000, streamFile) == 0x00000000) /* some like to be special */
|
else if (read_32bitBE(0x1000, streamFile) == 0x00000000) /* some like to be special */
|
||||||
{
|
{
|
||||||
loop_flag = read_32bitBE(0x6048, streamFile);
|
loop_flag = read_32bitBE(0x6048, streamFile);
|
||||||
|
|
||||||
/*Funky Channel Count Checking */
|
/*Funky Channel Count Checking */
|
||||||
if (read_32bitBE(0x60B0, streamFile) == 0x7374726D)
|
if (read_32bitBE(0x60B0, streamFile) == 0x7374726D)
|
||||||
channel_count = 6;
|
channel_count = 6;
|
||||||
else if (read_32bitBE(0x6080, streamFile) == 0x7374726D)
|
else if (read_32bitBE(0x6080, streamFile) == 0x7374726D)
|
||||||
channel_count = 4;
|
channel_count = 4;
|
||||||
else
|
else
|
||||||
channel_count = read_8bit(0x6060, streamFile);
|
channel_count = read_8bit(0x6060, streamFile);
|
||||||
|
|
||||||
sampleRate = read_32bitBE(0x6024, streamFile);
|
sampleRate = read_32bitBE(0x6024, streamFile);
|
||||||
numSamples = read_32bitBE(0x602C, streamFile);
|
numSamples = read_32bitBE(0x602C, streamFile);
|
||||||
startSample = read_32bitBE(0x6028, streamFile);
|
startSample = read_32bitBE(0x6028, streamFile);
|
||||||
dataSize = read_32bitBE(0x6020, streamFile);
|
dataSize = read_32bitBE(0x6020, streamFile);
|
||||||
blockSize = read_32bitBE(0x6030, streamFile);
|
blockSize = read_32bitBE(0x6030, streamFile);
|
||||||
blockCount = read_32bitBE(0x603C, streamFile);
|
blockCount = read_32bitBE(0x603C, streamFile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
goto fail; //cuz I don't know if there are other variants
|
goto fail; //cuz I don't know if there are other variants
|
||||||
|
|
||||||
/* build the VGMSTREAM */
|
/* build the VGMSTREAM */
|
||||||
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
vgmstream = allocate_vgmstream(channel_count,loop_flag);
|
||||||
if (!vgmstream) goto fail;
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
if (read_32bitBE(0x1000, streamFile) == 0x00000000)
|
if (read_32bitBE(0x1000, streamFile) == 0x00000000)
|
||||||
start_offset = 0x7000;
|
start_offset = 0x7000;
|
||||||
else
|
else
|
||||||
start_offset = 0x2000;
|
start_offset = 0x2000;
|
||||||
|
|
||||||
vgmstream->sample_rate = sampleRate;
|
vgmstream->sample_rate = sampleRate;
|
||||||
vgmstream->channels = channel_count;
|
vgmstream->channels = channel_count;
|
||||||
vgmstream->num_samples = numSamples;
|
vgmstream->num_samples = numSamples;
|
||||||
if (loop_flag) {
|
if (loop_flag) {
|
||||||
vgmstream->loop_start_sample = startSample;
|
vgmstream->loop_start_sample = startSample;
|
||||||
vgmstream->loop_end_sample = vgmstream->num_samples;
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
||||||
}
|
}
|
||||||
vgmstream->meta_type = meta_TA_AAC_X360;
|
vgmstream->meta_type = meta_TA_AAC_X360;
|
||||||
|
|
||||||
#ifdef VGM_USE_FFMPEG
|
#ifdef VGM_USE_FFMPEG
|
||||||
{
|
{
|
||||||
ffmpeg_codec_data *ffmpeg_data = NULL;
|
ffmpeg_codec_data *ffmpeg_data = NULL;
|
||||||
uint8_t buf[100];
|
uint8_t buf[100];
|
||||||
size_t bytes, datasize, block_size, block_count;
|
size_t bytes, datasize, block_size, block_count;
|
||||||
|
|
||||||
block_count = blockCount;
|
block_count = blockCount;
|
||||||
block_size = blockSize;
|
block_size = blockSize;
|
||||||
datasize = dataSize;
|
datasize = dataSize;
|
||||||
|
|
||||||
bytes = ffmpeg_make_riff_xma2(buf,100, vgmstream->num_samples, datasize, vgmstream->channels, vgmstream->sample_rate, block_count, block_size);
|
bytes = ffmpeg_make_riff_xma2(buf,100, vgmstream->num_samples, datasize, vgmstream->channels, vgmstream->sample_rate, block_count, block_size);
|
||||||
ffmpeg_data = init_ffmpeg_header_offset(streamFile, buf,bytes, start_offset,datasize);
|
ffmpeg_data = init_ffmpeg_header_offset(streamFile, buf,bytes, start_offset,datasize);
|
||||||
if ( !ffmpeg_data ) goto fail;
|
if ( !ffmpeg_data ) goto fail;
|
||||||
vgmstream->codec_data = ffmpeg_data;
|
vgmstream->codec_data = ffmpeg_data;
|
||||||
vgmstream->coding_type = coding_FFmpeg;
|
vgmstream->coding_type = coding_FFmpeg;
|
||||||
vgmstream->layout_type = layout_none;
|
vgmstream->layout_type = layout_none;
|
||||||
|
|
||||||
xma_fix_raw_samples(vgmstream, streamFile, start_offset, datasize, 0, 1,1);
|
xma_fix_raw_samples(vgmstream, streamFile, start_offset, datasize, 0, 1,1);
|
||||||
if (loop_flag) { /* reapply adjusted samples */
|
if (loop_flag) { /* reapply adjusted samples */
|
||||||
vgmstream->loop_end_sample = vgmstream->num_samples;
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
goto fail;
|
goto fail;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* open the file for reading */
|
/* open the file for reading */
|
||||||
if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) )
|
if ( !vgmstream_open_stream(vgmstream, streamFile, start_offset) )
|
||||||
goto fail;
|
goto fail;
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PlayStation 3 Variants (Star Ocean International, Resonance of Fate) */
|
/* PlayStation 3 Variants (Star Ocean International, Resonance of Fate) */
|
||||||
VGMSTREAM * init_vgmstream_ta_aac_ps3(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_ta_aac_ps3(STREAMFILE *streamFile) {
|
||||||
VGMSTREAM * vgmstream = NULL;
|
VGMSTREAM * vgmstream = NULL;
|
||||||
off_t start_offset;
|
off_t start_offset;
|
||||||
int loop_flag, channel_count;
|
int loop_flag, channel_count;
|
||||||
uint32_t data_size, loop_start, loop_end, codec_id, asc_chunk;
|
uint32_t data_size, loop_start, loop_end, codec_id, asc_chunk;
|
||||||
|
|
||||||
/* check extension, case insensitive */
|
/* check extension, case insensitive */
|
||||||
/* .aac: expected, .laac/ace: for players to avoid hijacking MP4/AAC */
|
/* .aac: expected, .laac/ace: for players to avoid hijacking MP4/AAC */
|
||||||
if (!check_extensions(streamFile, "aac,laac,ace"))
|
if (!check_extensions(streamFile, "aac,laac,ace"))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (read_32bitBE(0x00, streamFile) != 0x41414320) /* "AAC " */
|
if (read_32bitBE(0x00, streamFile) != 0x41414320) /* "AAC " */
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
/* Find the ASC chunk, That's where the goodies are */
|
/* Find the ASC chunk, That's where the goodies are */
|
||||||
asc_chunk = read_32bitBE(0x40, streamFile);
|
asc_chunk = read_32bitBE(0x40, streamFile);
|
||||||
if (read_32bitBE(asc_chunk, streamFile) != 0x41534320) /* "ASC " */
|
if (read_32bitBE(asc_chunk, streamFile) != 0x41534320) /* "ASC " */
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (read_32bitBE(asc_chunk+0x104, streamFile) != 0xFFFFFFFF)
|
if (read_32bitBE(asc_chunk+0x104, streamFile) != 0xFFFFFFFF)
|
||||||
loop_flag = 1;
|
loop_flag = 1;
|
||||||
else
|
else
|
||||||
loop_flag = 0;
|
loop_flag = 0;
|
||||||
|
|
||||||
channel_count = read_32bitBE(asc_chunk + 0xF4, streamFile);
|
channel_count = read_32bitBE(asc_chunk + 0xF4, streamFile);
|
||||||
codec_id = read_32bitBE(asc_chunk + 0xF0, streamFile);
|
codec_id = read_32bitBE(asc_chunk + 0xF0, streamFile);
|
||||||
|
|
||||||
/* build the VGMSTREAM */
|
/* build the VGMSTREAM */
|
||||||
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
||||||
if (!vgmstream) goto fail;
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
/* ASC header */
|
/* ASC header */
|
||||||
start_offset = asc_chunk + 0x110;
|
start_offset = asc_chunk + 0x110;
|
||||||
vgmstream->sample_rate = read_32bitBE(asc_chunk + 0xFC, streamFile);
|
vgmstream->sample_rate = read_32bitBE(asc_chunk + 0xFC, streamFile);
|
||||||
vgmstream->channels = channel_count;
|
vgmstream->channels = channel_count;
|
||||||
vgmstream->meta_type = meta_TA_AAC_PS3;
|
vgmstream->meta_type = meta_TA_AAC_PS3;
|
||||||
data_size = read_32bitBE(asc_chunk + 0xF8, streamFile);
|
data_size = read_32bitBE(asc_chunk + 0xF8, streamFile);
|
||||||
loop_start = read_32bitBE(asc_chunk + 0x104, streamFile);
|
loop_start = read_32bitBE(asc_chunk + 0x104, streamFile);
|
||||||
loop_end = read_32bitBE(asc_chunk + 0x108, streamFile);
|
loop_end = read_32bitBE(asc_chunk + 0x108, streamFile);
|
||||||
|
|
||||||
#ifdef VGM_USE_FFMPEG
|
#ifdef VGM_USE_FFMPEG
|
||||||
{
|
{
|
||||||
int block_align, encoder_delay;
|
int block_align, encoder_delay;
|
||||||
|
|
||||||
block_align = (codec_id == 4 ? 0x60 : (codec_id == 5 ? 0x98 : 0xC0)) * vgmstream->channels;
|
block_align = (codec_id == 4 ? 0x60 : (codec_id == 5 ? 0x98 : 0xC0)) * vgmstream->channels;
|
||||||
encoder_delay = 1024 + 69; /* approximate, gets good loops */
|
encoder_delay = 1024 + 69; /* approximate, gets good loops */
|
||||||
vgmstream->num_samples = atrac3_bytes_to_samples(data_size, block_align) - encoder_delay;
|
vgmstream->num_samples = atrac3_bytes_to_samples(data_size, block_align) - encoder_delay;
|
||||||
|
|
||||||
vgmstream->codec_data = init_ffmpeg_atrac3_raw(streamFile, start_offset,data_size, vgmstream->num_samples,vgmstream->channels,vgmstream->sample_rate, block_align, encoder_delay);
|
vgmstream->codec_data = init_ffmpeg_atrac3_raw(streamFile, start_offset,data_size, vgmstream->num_samples,vgmstream->channels,vgmstream->sample_rate, block_align, encoder_delay);
|
||||||
if (!vgmstream->codec_data) goto fail;
|
if (!vgmstream->codec_data) goto fail;
|
||||||
vgmstream->coding_type = coding_FFmpeg;
|
vgmstream->coding_type = coding_FFmpeg;
|
||||||
vgmstream->layout_type = layout_none;
|
vgmstream->layout_type = layout_none;
|
||||||
|
|
||||||
/* set offset samples (offset 0 jumps to sample 0 > pre-applied delay, and offset end loops after sample end > adjusted delay) */
|
/* set offset samples (offset 0 jumps to sample 0 > pre-applied delay, and offset end loops after sample end > adjusted delay) */
|
||||||
vgmstream->loop_start_sample = atrac3_bytes_to_samples(loop_start, block_align); // - encoder_delay
|
vgmstream->loop_start_sample = atrac3_bytes_to_samples(loop_start, block_align); // - encoder_delay
|
||||||
vgmstream->loop_end_sample = atrac3_bytes_to_samples(loop_end, block_align) - encoder_delay;
|
vgmstream->loop_end_sample = atrac3_bytes_to_samples(loop_end, block_align) - encoder_delay;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* open the file for reading */
|
/* open the file for reading */
|
||||||
if (!vgmstream_open_stream(vgmstream, streamFile, start_offset))
|
if (!vgmstream_open_stream(vgmstream, streamFile, start_offset))
|
||||||
goto fail;
|
goto fail;
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Android/iOS Variants (Star Ocean Anamnesis (APK v1.9.2), Heaven x Inferno (iOS)) */
|
/* Android/iOS Variants (Star Ocean Anamnesis (APK v1.9.2), Heaven x Inferno (iOS)) */
|
||||||
VGMSTREAM * init_vgmstream_ta_aac_mobile_vorbis(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_ta_aac_mobile_vorbis(STREAMFILE *streamFile) {
|
||||||
#ifdef VGM_USE_VORBIS
|
#ifdef VGM_USE_VORBIS
|
||||||
off_t start_offset;
|
off_t start_offset;
|
||||||
int8_t codec_id;
|
int8_t codec_id;
|
||||||
|
|
||||||
/* check extension, case insensitive */
|
/* check extension, case insensitive */
|
||||||
/* .aac: expected, .laac/ace: for players to avoid hijacking MP4/AAC */
|
/* .aac: expected, .laac/ace: for players to avoid hijacking MP4/AAC */
|
||||||
if (!check_extensions(streamFile, "aac,laac,ace"))
|
if (!check_extensions(streamFile, "aac,laac,ace"))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (read_32bitLE(0x00, streamFile) != 0x41414320) /* "AAC " */
|
if (read_32bitLE(0x00, streamFile) != 0x41414320) /* "AAC " */
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (read_32bitLE(0xf0, streamFile) != 0x57415645) /* "WAVE" */
|
if (read_32bitLE(0xf0, streamFile) != 0x57415645) /* "WAVE" */
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
codec_id = read_8bit(0x104, streamFile);
|
codec_id = read_8bit(0x104, streamFile);
|
||||||
if (codec_id == 0xe) /* Vorbis */
|
if (codec_id == 0xe) /* Vorbis */
|
||||||
{
|
{
|
||||||
ogg_vorbis_meta_info_t ovmi = {0};
|
ogg_vorbis_meta_info_t ovmi = {0};
|
||||||
VGMSTREAM * result = NULL;
|
VGMSTREAM * result = NULL;
|
||||||
|
|
||||||
ovmi.meta_type = meta_TA_AAC_MOBILE;
|
ovmi.meta_type = meta_TA_AAC_MOBILE;
|
||||||
ovmi.loop_start = read_32bitLE(0x140, streamFile);
|
ovmi.loop_start = read_32bitLE(0x140, streamFile);
|
||||||
ovmi.loop_end = read_32bitLE(0x144, streamFile);
|
ovmi.loop_end = read_32bitLE(0x144, streamFile);
|
||||||
ovmi.loop_flag = ovmi.loop_end > ovmi.loop_start;
|
ovmi.loop_flag = ovmi.loop_end > ovmi.loop_start;
|
||||||
ovmi.loop_end_found = ovmi.loop_flag;
|
ovmi.loop_end_found = ovmi.loop_flag;
|
||||||
|
|
||||||
start_offset = read_32bitLE(0x120, streamFile);
|
start_offset = read_32bitLE(0x120, streamFile);
|
||||||
result = init_vgmstream_ogg_vorbis_callbacks(streamFile, NULL, start_offset, &ovmi);
|
result = init_vgmstream_ogg_vorbis_callbacks(streamFile, NULL, start_offset, &ovmi);
|
||||||
|
|
||||||
if (result != NULL) {
|
if (result != NULL) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
/* clean up anything we may have opened */
|
/* clean up anything we may have opened */
|
||||||
#endif
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Android/iOS Variants, before they switched to Vorbis (Star Ocean Anamnesis (Android), Heaven x Inferno (iOS)) */
|
/* Android/iOS Variants, before they switched to Vorbis (Star Ocean Anamnesis (Android), Heaven x Inferno (iOS)) */
|
||||||
VGMSTREAM * init_vgmstream_ta_aac_mobile(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_ta_aac_mobile(STREAMFILE *streamFile) {
|
||||||
VGMSTREAM * vgmstream = NULL;
|
VGMSTREAM * vgmstream = NULL;
|
||||||
off_t start_offset;
|
off_t start_offset;
|
||||||
int channel_count, loop_flag, codec;
|
int channel_count, loop_flag, codec;
|
||||||
size_t data_size;
|
size_t data_size;
|
||||||
|
|
||||||
|
|
||||||
/* check extension, case insensitive */
|
/* check extension, case insensitive */
|
||||||
/* .aac: expected, .laac: for players to avoid hijacking MP4/AAC */
|
/* .aac: expected, .laac: for players to avoid hijacking MP4/AAC */
|
||||||
if (!check_extensions(streamFile, "aac,laac"))
|
if (!check_extensions(streamFile, "aac,laac"))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (read_32bitLE(0x00, streamFile) != 0x41414320) /* "AAC " */
|
if (read_32bitLE(0x00, streamFile) != 0x41414320) /* "AAC " */
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (read_32bitLE(0xf0, streamFile) != 0x57415645) /* "WAVE" */
|
if (read_32bitLE(0xf0, streamFile) != 0x57415645) /* "WAVE" */
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
codec = read_8bit(0x104, streamFile);
|
codec = read_8bit(0x104, streamFile);
|
||||||
channel_count = read_8bit(0x105, streamFile);
|
channel_count = read_8bit(0x105, streamFile);
|
||||||
/* 0x106: 0x01?, 0x107: 0x10? */
|
/* 0x106: 0x01?, 0x107: 0x10? */
|
||||||
data_size = read_32bitLE(0x10c, streamFile); /* usable data only, cuts last frame */
|
data_size = read_32bitLE(0x10c, streamFile); /* usable data only, cuts last frame */
|
||||||
start_offset = read_32bitLE(0x120, streamFile);
|
start_offset = read_32bitLE(0x120, streamFile);
|
||||||
/* 0x124: full data size */
|
/* 0x124: full data size */
|
||||||
loop_flag = (read_32bitLE(0x134, streamFile) > 0);
|
loop_flag = (read_32bitLE(0x134, streamFile) > 0);
|
||||||
|
|
||||||
|
|
||||||
/* build the VGMSTREAM */
|
/* build the VGMSTREAM */
|
||||||
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
||||||
if (!vgmstream) goto fail;
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
vgmstream->sample_rate = read_32bitLE(0x108, streamFile);
|
vgmstream->sample_rate = read_32bitLE(0x108, streamFile);
|
||||||
vgmstream->meta_type = meta_TA_AAC_MOBILE;
|
vgmstream->meta_type = meta_TA_AAC_MOBILE;
|
||||||
|
|
||||||
switch(codec) {
|
switch(codec) {
|
||||||
case 0x0d:
|
case 0x0d:
|
||||||
if (read_32bitLE(0x144, streamFile) != 0x40) goto fail; /* frame size */
|
if (read_32bitLE(0x144, streamFile) != 0x40) goto fail; /* frame size */
|
||||||
if (read_32bitLE(0x148, streamFile) != (0x40-0x04*channel_count)*2 / channel_count) goto fail; /* frame samples */
|
/* 0x148 or 0x150 (later games): frame samples */
|
||||||
if (channel_count > 2) goto fail; /* unknown data layout */
|
if (channel_count > 2) goto fail; /* unknown data layout */
|
||||||
|
|
||||||
vgmstream->coding_type = coding_ASKA;
|
vgmstream->coding_type = coding_ASKA;
|
||||||
vgmstream->layout_type = layout_none;
|
vgmstream->layout_type = layout_none;
|
||||||
|
|
||||||
vgmstream->num_samples = aska_bytes_to_samples(data_size, channel_count);
|
vgmstream->num_samples = aska_bytes_to_samples(data_size, channel_count);
|
||||||
vgmstream->loop_start_sample = aska_bytes_to_samples(read_32bitLE(0x130, streamFile), channel_count);
|
vgmstream->loop_start_sample = aska_bytes_to_samples(read_32bitLE(0x130, streamFile), channel_count);
|
||||||
vgmstream->loop_end_sample = aska_bytes_to_samples(read_32bitLE(0x134, streamFile), channel_count);
|
vgmstream->loop_end_sample = aska_bytes_to_samples(read_32bitLE(0x134, streamFile), channel_count);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
||||||
goto fail;
|
goto fail;
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Vita variants [Judas Code (Vita)] */
|
/* Vita variants [Judas Code (Vita)] */
|
||||||
VGMSTREAM * init_vgmstream_ta_aac_vita(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_ta_aac_vita(STREAMFILE *streamFile) {
|
||||||
VGMSTREAM * vgmstream = NULL;
|
VGMSTREAM * vgmstream = NULL;
|
||||||
off_t start_offset;
|
off_t start_offset;
|
||||||
int channel_count, loop_flag;
|
int channel_count, loop_flag;
|
||||||
|
|
||||||
|
|
||||||
/* check extension, case insensitive */
|
/* check extension, case insensitive */
|
||||||
/* .aac: expected, .laac: for players to avoid hijacking MP4/AAC */
|
/* .aac: expected, .laac: for players to avoid hijacking MP4/AAC */
|
||||||
if (!check_extensions(streamFile, "aac,laac"))
|
if (!check_extensions(streamFile, "aac,laac"))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (read_32bitLE(0x00, streamFile) != 0x41414320) /* "AAC " */
|
if (read_32bitLE(0x00, streamFile) != 0x41414320) /* "AAC " */
|
||||||
goto fail;
|
goto fail;
|
||||||
if (read_32bitLE(0x14, streamFile) != 0x56495441) /* "VITA" */
|
if (read_32bitLE(0x14, streamFile) != 0x56495441) /* "VITA" */
|
||||||
goto fail;
|
goto fail;
|
||||||
if (read_32bitLE(0x10d0, streamFile) != 0x57415645) /* "WAVE" */
|
if (read_32bitLE(0x10d0, streamFile) != 0x57415645) /* "WAVE" */
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
/* there is a bunch of chunks but we simplify */
|
/* there is a bunch of chunks but we simplify */
|
||||||
|
|
||||||
/* 0x10E4: codec 0x08? */
|
/* 0x10E4: codec 0x08? */
|
||||||
channel_count = read_8bit(0x10E5, streamFile);
|
channel_count = read_8bit(0x10E5, streamFile);
|
||||||
start_offset = read_32bitLE(0x1100, streamFile);
|
start_offset = read_32bitLE(0x1100, streamFile);
|
||||||
loop_flag = (read_32bitLE(0x1114, streamFile) > 0);
|
loop_flag = (read_32bitLE(0x1114, streamFile) > 0);
|
||||||
|
|
||||||
|
|
||||||
/* build the VGMSTREAM */
|
/* build the VGMSTREAM */
|
||||||
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
||||||
if (!vgmstream) goto fail;
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
vgmstream->sample_rate = read_32bitLE(0x10e8, streamFile);
|
vgmstream->sample_rate = read_32bitLE(0x10e8, streamFile);
|
||||||
vgmstream->meta_type = meta_TA_AAC_VITA;
|
vgmstream->meta_type = meta_TA_AAC_VITA;
|
||||||
|
|
||||||
#ifdef VGM_USE_ATRAC9
|
#ifdef VGM_USE_ATRAC9
|
||||||
{
|
{
|
||||||
atrac9_config cfg = {0};
|
atrac9_config cfg = {0};
|
||||||
|
|
||||||
cfg.channels = vgmstream->channels;
|
cfg.channels = vgmstream->channels;
|
||||||
cfg.encoder_delay = read_32bitLE(0x1124,streamFile);
|
cfg.encoder_delay = read_32bitLE(0x1124,streamFile);
|
||||||
cfg.config_data = read_32bitBE(0x1128,streamFile);
|
cfg.config_data = read_32bitBE(0x1128,streamFile);
|
||||||
|
|
||||||
vgmstream->codec_data = init_atrac9(&cfg);
|
vgmstream->codec_data = init_atrac9(&cfg);
|
||||||
if (!vgmstream->codec_data) goto fail;
|
if (!vgmstream->codec_data) goto fail;
|
||||||
vgmstream->coding_type = coding_ATRAC9;
|
vgmstream->coding_type = coding_ATRAC9;
|
||||||
vgmstream->layout_type = layout_none;
|
vgmstream->layout_type = layout_none;
|
||||||
|
|
||||||
vgmstream->num_samples = atrac9_bytes_to_samples(read_32bitLE(0x10EC, streamFile), vgmstream->codec_data);
|
vgmstream->num_samples = atrac9_bytes_to_samples(read_32bitLE(0x10EC, streamFile), vgmstream->codec_data);
|
||||||
vgmstream->num_samples -= cfg.encoder_delay;
|
vgmstream->num_samples -= cfg.encoder_delay;
|
||||||
vgmstream->loop_start_sample = atrac9_bytes_to_samples(read_32bitLE(0x1110, streamFile), vgmstream->codec_data);
|
vgmstream->loop_start_sample = atrac9_bytes_to_samples(read_32bitLE(0x1110, streamFile), vgmstream->codec_data);
|
||||||
vgmstream->loop_end_sample = atrac9_bytes_to_samples(read_32bitLE(0x1114, streamFile), vgmstream->codec_data);
|
vgmstream->loop_end_sample = atrac9_bytes_to_samples(read_32bitLE(0x1114, streamFile), vgmstream->codec_data);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
||||||
goto fail;
|
goto fail;
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -622,7 +622,7 @@ static VGMSTREAM * init_vgmstream_ubi_hx_header(ubi_hx_header *hx, STREAMFILE *s
|
||||||
|
|
||||||
switch(hx->codec) {
|
switch(hx->codec) {
|
||||||
case PCM:
|
case PCM:
|
||||||
vgmstream->coding_type = coding_PCM16LE;
|
vgmstream->coding_type = hx->big_endian ? coding_PCM16BE : coding_PCM16LE;
|
||||||
vgmstream->layout_type = layout_interleave;
|
vgmstream->layout_type = layout_interleave;
|
||||||
vgmstream->interleave_block_size = 0x02;
|
vgmstream->interleave_block_size = 0x02;
|
||||||
|
|
||||||
|
|
|
@ -2966,12 +2966,14 @@ static int config_sb_version(ubi_sb_header * sb, STREAMFILE *streamFile) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TMNT (2007)(X360)-bank 0x00190002 */
|
/* TMNT (2007)(X360)-bank 0x00190002 */
|
||||||
|
/* My Word Coach (2007)(Wii)-bank 0x00190002 */
|
||||||
/* Prince of Persia: Rival Swords (2007)(Wii)-bank 0x00190003 */
|
/* Prince of Persia: Rival Swords (2007)(Wii)-bank 0x00190003 */
|
||||||
/* Rainbow Six Vegas (2007)(PS3)-bank 0x00190005 */
|
/* Rainbow Six Vegas (2007)(PS3)-bank 0x00190005 */
|
||||||
/* Surf's Up (2007)(PS3)-bank 0x00190005 */
|
/* Surf's Up (2007)(PS3)-bank 0x00190005 */
|
||||||
/* Surf's Up (2007)(X360)-bank 0x00190005 */
|
/* Surf's Up (2007)(X360)-bank 0x00190005 */
|
||||||
/* Splinter Cell: Double Agent (2007)(PS3)-map 0x00190005 */
|
/* Splinter Cell: Double Agent (2007)(PS3)-map 0x00190005 */
|
||||||
if ((sb->version == 0x00190002 && sb->platform == UBI_X360) ||
|
if ((sb->version == 0x00190002 && sb->platform == UBI_X360) ||
|
||||||
|
(sb->version == 0x00190002 && sb->platform == UBI_WII) ||
|
||||||
(sb->version == 0x00190003 && sb->platform == UBI_WII) ||
|
(sb->version == 0x00190003 && sb->platform == UBI_WII) ||
|
||||||
(sb->version == 0x00190005 && sb->platform == UBI_PS3) ||
|
(sb->version == 0x00190005 && sb->platform == UBI_PS3) ||
|
||||||
(sb->version == 0x00190005 && sb->platform == UBI_X360)) {
|
(sb->version == 0x00190005 && sb->platform == UBI_X360)) {
|
||||||
|
@ -3009,6 +3011,16 @@ static int config_sb_version(ubi_sb_header * sb, STREAMFILE *streamFile) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Cranium Kabookii (2007)(Wii)-bank 0x001a0003 */
|
||||||
|
if (sb->version == 0x001a0003 && sb->platform == UBI_WII) {
|
||||||
|
config_sb_entry(sb, 0x6c, 0x78);
|
||||||
|
|
||||||
|
config_sb_audio_fs(sb, 0x2c, 0x30, 0x34);
|
||||||
|
config_sb_audio_he(sb, 0x40, 0x44, 0x4c, 0x54, 0x5c, 0x60);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Rainbow Six Vegas 2 (2008)(PS3)-bank */
|
/* Rainbow Six Vegas 2 (2008)(PS3)-bank */
|
||||||
/* Rainbow Six Vegas 2 (2008)(X360)-bank */
|
/* Rainbow Six Vegas 2 (2008)(X360)-bank */
|
||||||
if ((sb->version == 0x001C0000 && sb->platform == UBI_PS3) ||
|
if ((sb->version == 0x001C0000 && sb->platform == UBI_PS3) ||
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,324 +1,326 @@
|
||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
#include "../coding/coding.h"
|
#include "../coding/coding.h"
|
||||||
#include "../layout/layout.h"
|
#include "../layout/layout.h"
|
||||||
#include "xvag_streamfile.h"
|
#include "xvag_streamfile.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int big_endian;
|
int big_endian;
|
||||||
int channels;
|
int channels;
|
||||||
int sample_rate;
|
int sample_rate;
|
||||||
int codec;
|
int codec;
|
||||||
|
|
||||||
int factor;
|
int factor;
|
||||||
|
|
||||||
int loop_flag;
|
int loop_flag;
|
||||||
int num_samples;
|
int num_samples;
|
||||||
int loop_start;
|
int loop_start;
|
||||||
int loop_end;
|
int loop_end;
|
||||||
|
|
||||||
int subsongs;
|
int subsongs;
|
||||||
int layers;
|
int layers;
|
||||||
|
|
||||||
size_t data_size;
|
size_t data_size;
|
||||||
off_t stream_offset;
|
off_t stream_offset;
|
||||||
} xvag_header;
|
} xvag_header;
|
||||||
|
|
||||||
static int init_xvag_atrac9(STREAMFILE *streamFile, VGMSTREAM* vgmstream, xvag_header * xvag, off_t chunk_offset);
|
static int init_xvag_atrac9(STREAMFILE *streamFile, VGMSTREAM* vgmstream, xvag_header * xvag, off_t chunk_offset);
|
||||||
static layered_layout_data* build_layered_xvag(STREAMFILE *streamFile, xvag_header * xvag, off_t chunk_offset, off_t start_offset);
|
static layered_layout_data* build_layered_xvag(STREAMFILE *streamFile, xvag_header * xvag, off_t chunk_offset, off_t start_offset);
|
||||||
|
|
||||||
/* XVAG - Sony's Scream Tool/Stream Creator format (God of War III, Ratchet & Clank Future, The Last of Us, Uncharted) */
|
/* XVAG - Sony's Scream Tool/Stream Creator format (God of War III, Ratchet & Clank Future, The Last of Us, Uncharted) */
|
||||||
VGMSTREAM * init_vgmstream_xvag(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_xvag(STREAMFILE *streamFile) {
|
||||||
VGMSTREAM * vgmstream = NULL;
|
VGMSTREAM * vgmstream = NULL;
|
||||||
STREAMFILE* temp_streamFile = NULL;
|
STREAMFILE* temp_streamFile = NULL;
|
||||||
xvag_header xvag = {0};
|
xvag_header xvag = {0};
|
||||||
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
|
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
|
||||||
off_t start_offset, chunk_offset, first_offset = 0x20;
|
off_t start_offset, chunk_offset, first_offset = 0x20;
|
||||||
size_t chunk_size;
|
size_t chunk_size;
|
||||||
int total_subsongs = 0, target_subsong = streamFile->stream_index;
|
int total_subsongs = 0, target_subsong = streamFile->stream_index;
|
||||||
|
|
||||||
|
|
||||||
/* checks */
|
/* checks */
|
||||||
/* .xvag: standard
|
/* .xvag: standard
|
||||||
* (extensionless): The Last Of Us (PS3) speech files */
|
* (extensionless): The Last Of Us (PS3) speech files */
|
||||||
if (!check_extensions(streamFile,"xvag,"))
|
if (!check_extensions(streamFile,"xvag,"))
|
||||||
goto fail;
|
goto fail;
|
||||||
if (read_32bitBE(0x00,streamFile) != 0x58564147) /* "XVAG" */
|
if (read_32bitBE(0x00,streamFile) != 0x58564147) /* "XVAG" */
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
/* endian flag (XVAGs of the same game can use BE or LE, usually when reusing from other platforms) */
|
/* endian flag (XVAGs of the same game can use BE or LE, usually when reusing from other platforms) */
|
||||||
xvag.big_endian = read_8bit(0x08,streamFile) & 0x01;
|
xvag.big_endian = read_8bit(0x08,streamFile) & 0x01;
|
||||||
if (xvag.big_endian) {
|
if (xvag.big_endian) {
|
||||||
read_32bit = read_32bitBE;
|
read_32bit = read_32bitBE;
|
||||||
} else {
|
} else {
|
||||||
read_32bit = read_32bitLE;
|
read_32bit = read_32bitLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
start_offset = read_32bit(0x04,streamFile);
|
start_offset = read_32bit(0x04,streamFile);
|
||||||
/* 0x08: flags? (&0x01=big endian, 0x02=?, 0x06=full RIFF AT9?)
|
/* 0x08: flags? (&0x01=big endian, 0x02=?, 0x06=full RIFF AT9?)
|
||||||
* 0x09: flags2? (0x00/0x01/0x04, speaker mode?)
|
* 0x09: flags2? (0x00/0x01/0x04, speaker mode?)
|
||||||
* 0x0a: always 0?
|
* 0x0a: always 0?
|
||||||
* 0x0b: version-flag? (0x5f/0x60/0x61/0x62/etc) */
|
* 0x0b: version-flag? (0x5f/0x60/0x61/0x62/etc) */
|
||||||
|
|
||||||
|
|
||||||
/* "fmat": base format (always first) */
|
/* "fmat": base format (always first) */
|
||||||
if (!find_chunk(streamFile, 0x666D6174,first_offset,0, &chunk_offset,&chunk_size, xvag.big_endian, 1)) /*"fmat"*/
|
if (!find_chunk(streamFile, 0x666D6174,first_offset,0, &chunk_offset,&chunk_size, xvag.big_endian, 1)) /*"fmat"*/
|
||||||
goto fail;
|
goto fail;
|
||||||
xvag.channels = read_32bit(chunk_offset+0x00,streamFile);
|
xvag.channels = read_32bit(chunk_offset+0x00,streamFile);
|
||||||
xvag.codec = read_32bit(chunk_offset+0x04,streamFile);
|
xvag.codec = read_32bit(chunk_offset+0x04,streamFile);
|
||||||
xvag.num_samples = read_32bit(chunk_offset+0x08,streamFile);
|
xvag.num_samples = read_32bit(chunk_offset+0x08,streamFile);
|
||||||
/* 0x0c: samples again? */
|
/* 0x0c: samples again? */
|
||||||
VGM_ASSERT(xvag.num_samples != read_32bit(chunk_offset+0x0c,streamFile), "XVAG: num_samples values don't match\n");
|
VGM_ASSERT(xvag.num_samples != read_32bit(chunk_offset+0x0c,streamFile), "XVAG: num_samples values don't match\n");
|
||||||
|
|
||||||
xvag.factor = read_32bit(chunk_offset+0x10,streamFile); /* for interleave */
|
xvag.factor = read_32bit(chunk_offset+0x10,streamFile); /* for interleave */
|
||||||
xvag.sample_rate = read_32bit(chunk_offset+0x14,streamFile);
|
xvag.sample_rate = read_32bit(chunk_offset+0x14,streamFile);
|
||||||
xvag.data_size = read_32bit(chunk_offset+0x18,streamFile); /* not always accurate */
|
xvag.data_size = read_32bit(chunk_offset+0x18,streamFile); /* not always accurate */
|
||||||
|
|
||||||
/* extra data, seen in versions 0x61+ */
|
/* extra data, seen in versions 0x61+ */
|
||||||
if (chunk_size > 0x1c) {
|
if (chunk_size > 0x1c) {
|
||||||
/* number of interleaved subsongs */
|
/* number of interleaved subsongs */
|
||||||
xvag.subsongs = read_32bit(chunk_offset+0x1c,streamFile);
|
xvag.subsongs = read_32bit(chunk_offset+0x1c,streamFile);
|
||||||
/* number of interleaved layers (layers * channels_per_layer = channels) */
|
/* number of interleaved layers (layers * channels_per_layer = channels) */
|
||||||
xvag.layers = read_32bit(chunk_offset+0x20,streamFile);
|
xvag.layers = read_32bit(chunk_offset+0x20,streamFile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
xvag.subsongs = 1;
|
xvag.subsongs = 1;
|
||||||
xvag.layers = 1;
|
xvag.layers = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
total_subsongs = xvag.subsongs;
|
total_subsongs = xvag.subsongs;
|
||||||
if (target_subsong == 0) target_subsong = 1;
|
if (target_subsong == 0) target_subsong = 1;
|
||||||
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
|
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
|
||||||
|
|
||||||
|
|
||||||
/* other chunks: */
|
/* other chunks: */
|
||||||
/* "cpan": pan/volume per channel */
|
/* "cpan": pan/volume per channel */
|
||||||
/* "cues": cue/labels (rare) */
|
/* "cues": cue/labels (rare) */
|
||||||
/* "md5 ": hash (rare) */
|
/* "md5 ": hash (rare) */
|
||||||
/* "0000": end chunk before start_offset */
|
/* "0000": end chunk before start_offset */
|
||||||
|
|
||||||
/* XVAG has no looping, but some PS3 PS-ADPCM seems to do full loops (without data flags) */
|
/* XVAG has no looping, but some PS3 PS-ADPCM seems to do full loops (without data flags) */
|
||||||
if (xvag.codec == 0x06 && xvag.subsongs == 1) {
|
if (xvag.codec == 0x06 && xvag.subsongs == 1) {
|
||||||
size_t file_size = get_streamfile_size(streamFile);
|
size_t file_size = get_streamfile_size(streamFile);
|
||||||
/* simply test if last frame is not empty = may loop */
|
/* simply test if last frame is not empty = may loop */
|
||||||
xvag.loop_flag = (read_8bit(file_size - 0x01, streamFile) != 0);
|
xvag.loop_flag = (read_8bit(file_size - 0x01, streamFile) != 0);
|
||||||
xvag.loop_start = 0;
|
xvag.loop_start = 0;
|
||||||
xvag.loop_end = ps_bytes_to_samples(file_size - start_offset, xvag.channels);
|
xvag.loop_end = ps_bytes_to_samples(file_size - start_offset, xvag.channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* May use 'MP3 Surround' for multichannel [Twisted Metal (PS3), The Last of Us (PS4) test file]
|
/* May use 'MP3 Surround' for multichannel [Twisted Metal (PS3), The Last of Us (PS4) test file]
|
||||||
* It's a mutant MP3 that decodes as 2ch but output can be routed to 6ch somehow, if manually
|
* It's a mutant MP3 that decodes as 2ch but output can be routed to 6ch somehow, if manually
|
||||||
* activated. Fraunhofer IIS's MP3sPlayer can do it, as can PS3 (fw v2.40+) but no others seems to.
|
* activated. Fraunhofer IIS's MP3sPlayer can do it, as can PS3 (fw v2.40+) but no others seems to.
|
||||||
* So simply play as 2ch, they sound ok with slightly wider feel. No XVAG/MP3 flag exists to detect,
|
* So simply play as 2ch, they sound ok with slightly wider feel. No XVAG/MP3 flag exists to detect,
|
||||||
* can be found in v0x60 (without layers/subsongs) and v0x61 (with them set as 1) */
|
* can be found in v0x60 (without layers/subsongs) and v0x61 (with them set as 1) */
|
||||||
if (xvag.codec == 0x08 && xvag.channels == 6 && xvag.layers == 1) {
|
if (xvag.codec == 0x08 && xvag.channels == 6 && xvag.layers == 1) {
|
||||||
xvag.channels = 2;
|
xvag.channels = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* build the VGMSTREAM */
|
/* build the VGMSTREAM */
|
||||||
vgmstream = allocate_vgmstream(xvag.channels,xvag.loop_flag);
|
vgmstream = allocate_vgmstream(xvag.channels,xvag.loop_flag);
|
||||||
if (!vgmstream) goto fail;
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
vgmstream->meta_type = meta_XVAG;
|
vgmstream->meta_type = meta_XVAG;
|
||||||
vgmstream->sample_rate = xvag.sample_rate;
|
vgmstream->sample_rate = xvag.sample_rate;
|
||||||
vgmstream->num_samples = xvag.num_samples;
|
vgmstream->num_samples = xvag.num_samples;
|
||||||
if (xvag.loop_flag) {
|
if (xvag.loop_flag) {
|
||||||
vgmstream->loop_start_sample = xvag.loop_start;
|
vgmstream->loop_start_sample = xvag.loop_start;
|
||||||
vgmstream->loop_end_sample = xvag.loop_end;
|
vgmstream->loop_end_sample = xvag.loop_end;
|
||||||
}
|
}
|
||||||
vgmstream->num_streams = total_subsongs;
|
vgmstream->num_streams = total_subsongs;
|
||||||
vgmstream->stream_size = (xvag.data_size / total_subsongs);
|
vgmstream->stream_size = (xvag.data_size / total_subsongs);
|
||||||
|
|
||||||
switch (xvag.codec) {
|
switch (xvag.codec) {
|
||||||
case 0x06: /* VAG (PS-ADPCM): God of War III (PS3), Uncharted 1/2 (PS3), Ratchet and Clank Future (PS3) */
|
case 0x06: /* VAG (PS-ADPCM): God of War III (PS3), Uncharted 1/2 (PS3), Ratchet and Clank Future (PS3) */
|
||||||
case 0x07: /* SVAG? (PS-ADPCM with extended table?): inFamous 1 (PS3) */
|
case 0x07: /* SVAG? (PS-ADPCM with extended table): inFamous 1 (PS3) */
|
||||||
if (xvag.subsongs > 1 && xvag.layers > 1) goto fail;
|
if (xvag.subsongs > 1 && xvag.layers > 1) goto fail;
|
||||||
if (xvag.layers > 1 && xvag.layers != xvag.channels) goto fail;
|
if (xvag.layers > 1 && xvag.layers != xvag.channels) goto fail;
|
||||||
if (xvag.subsongs > 1 && xvag.channels > 1) goto fail; /* unknown layout */
|
if (xvag.subsongs > 1 && xvag.channels > 1) goto fail; /* unknown layout */
|
||||||
|
|
||||||
vgmstream->coding_type = coding_PSX;
|
vgmstream->coding_type = coding_PSX;
|
||||||
|
if (xvag.codec == 0x07)
|
||||||
if (xvag.subsongs > 1) { /* God of War 3 (PS4) */
|
vgmstream->codec_config = 1; /* needs extended table */
|
||||||
vgmstream->layout_type = layout_blocked_xvag_subsong;
|
|
||||||
vgmstream->interleave_block_size = 0x10;
|
if (xvag.subsongs > 1) { /* God of War 3 (PS4) */
|
||||||
vgmstream->full_block_size = 0x10 * xvag.factor * xvag.subsongs;
|
vgmstream->layout_type = layout_blocked_xvag_subsong;
|
||||||
vgmstream->current_block_size = 0x10 * xvag.factor;
|
vgmstream->interleave_block_size = 0x10;
|
||||||
start_offset += vgmstream->current_block_size * (target_subsong-1);
|
vgmstream->full_block_size = 0x10 * xvag.factor * xvag.subsongs;
|
||||||
}
|
vgmstream->current_block_size = 0x10 * xvag.factor;
|
||||||
else {
|
start_offset += vgmstream->current_block_size * (target_subsong-1);
|
||||||
vgmstream->layout_type = layout_interleave;
|
}
|
||||||
vgmstream->interleave_block_size = 0x10 * xvag.factor; /* usually 1, bigger in GoW3 PS4 */
|
else {
|
||||||
}
|
vgmstream->layout_type = layout_interleave;
|
||||||
break;
|
vgmstream->interleave_block_size = 0x10 * xvag.factor; /* usually 1, bigger in GoW3 PS4 */
|
||||||
|
}
|
||||||
#ifdef VGM_USE_MPEG
|
break;
|
||||||
case 0x08: { /* MPEG: The Last of Us (PS3), Uncharted 3 (PS3), Medieval Moves (PS3) */
|
|
||||||
mpeg_custom_config cfg = {0};
|
#ifdef VGM_USE_MPEG
|
||||||
|
case 0x08: { /* MPEG: The Last of Us (PS3), Uncharted 3 (PS3), Medieval Moves (PS3) */
|
||||||
/* often 2ch per MPEG and rarely 1ch (GoW3 PS4) */
|
mpeg_custom_config cfg = {0};
|
||||||
if (xvag.layers > 1 && !(xvag.layers*1 == vgmstream->channels || xvag.layers*2 == vgmstream->channels)) goto fail;
|
|
||||||
|
/* often 2ch per MPEG and rarely 1ch (GoW3 PS4) */
|
||||||
/* "mpin": mpeg info */
|
if (xvag.layers > 1 && !(xvag.layers*1 == vgmstream->channels || xvag.layers*2 == vgmstream->channels)) goto fail;
|
||||||
if (!find_chunk(streamFile, 0x6D70696E,first_offset,0, &chunk_offset,NULL, xvag.big_endian, 1)) /*"mpin"*/
|
|
||||||
goto fail;
|
/* "mpin": mpeg info */
|
||||||
|
if (!find_chunk(streamFile, 0x6D70696E,first_offset,0, &chunk_offset,NULL, xvag.big_endian, 1)) /*"mpin"*/
|
||||||
/* all layers/subsongs share the same config; not very useful but for posterity:
|
goto fail;
|
||||||
* - 0x00: mpeg version
|
|
||||||
* - 0x04: mpeg layer
|
/* all layers/subsongs share the same config; not very useful but for posterity:
|
||||||
* - 0x08: bit rate
|
* - 0x00: mpeg version
|
||||||
* - 0x0c: sample rate
|
* - 0x04: mpeg layer
|
||||||
* - 0x10: some version? (0x01-0x03)?
|
* - 0x08: bit rate
|
||||||
* - 0x14: channels per stream?
|
* - 0x0c: sample rate
|
||||||
* - 0x18: channels per stream or total channels?
|
* - 0x10: some version? (0x01-0x03)?
|
||||||
* - 0x1c: fixed frame size (always CBR)
|
* - 0x14: channels per stream?
|
||||||
* - 0x20: encoder delay (usually but not always 1201)
|
* - 0x18: channels per stream or total channels?
|
||||||
* - 0x24: number of samples
|
* - 0x1c: fixed frame size (always CBR)
|
||||||
* - 0x28: some size?
|
* - 0x20: encoder delay (usually but not always 1201)
|
||||||
* - 0x2c: ? (0x02)
|
* - 0x24: number of samples
|
||||||
* - 0x30: ? (0x00, 0x80)
|
* - 0x28: some size?
|
||||||
* - 0x34: data size
|
* - 0x2c: ? (0x02)
|
||||||
* (rest is padding)
|
* - 0x30: ? (0x00, 0x80)
|
||||||
* */
|
* - 0x34: data size
|
||||||
cfg.chunk_size = read_32bit(chunk_offset+0x1c,streamFile);
|
* (rest is padding)
|
||||||
cfg.skip_samples = read_32bit(chunk_offset+0x20,streamFile);
|
* */
|
||||||
cfg.interleave = cfg.chunk_size * xvag.factor;
|
cfg.chunk_size = read_32bit(chunk_offset+0x1c,streamFile);
|
||||||
|
cfg.skip_samples = read_32bit(chunk_offset+0x20,streamFile);
|
||||||
vgmstream->codec_data = init_mpeg_custom(streamFile, start_offset, &vgmstream->coding_type, vgmstream->channels, MPEG_XVAG, &cfg);
|
cfg.interleave = cfg.chunk_size * xvag.factor;
|
||||||
if (!vgmstream->codec_data) goto fail;
|
|
||||||
vgmstream->layout_type = layout_none;
|
vgmstream->codec_data = init_mpeg_custom(streamFile, start_offset, &vgmstream->coding_type, vgmstream->channels, MPEG_XVAG, &cfg);
|
||||||
|
if (!vgmstream->codec_data) goto fail;
|
||||||
/* interleaved subsongs, rarely [Sly Cooper: Thieves in Time (PS3)] */
|
vgmstream->layout_type = layout_none;
|
||||||
if (xvag.subsongs > 1) {
|
|
||||||
temp_streamFile = setup_xvag_streamfile(streamFile, start_offset, cfg.interleave,cfg.chunk_size, (target_subsong-1), total_subsongs);
|
/* interleaved subsongs, rarely [Sly Cooper: Thieves in Time (PS3)] */
|
||||||
if (!temp_streamFile) goto fail;
|
if (xvag.subsongs > 1) {
|
||||||
start_offset = 0;
|
temp_streamFile = setup_xvag_streamfile(streamFile, start_offset, cfg.interleave,cfg.chunk_size, (target_subsong-1), total_subsongs);
|
||||||
}
|
if (!temp_streamFile) goto fail;
|
||||||
|
start_offset = 0;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
#endif
|
break;
|
||||||
|
}
|
||||||
#ifdef VGM_USE_ATRAC9
|
#endif
|
||||||
case 0x09: { /* ATRAC9: Sly Cooper and the Thievius Raccoonus (Vita), The Last of Us Remastered (PS4) */
|
|
||||||
if (xvag.subsongs > 1 && xvag.layers > 1) goto fail;
|
#ifdef VGM_USE_ATRAC9
|
||||||
|
case 0x09: { /* ATRAC9: Sly Cooper and the Thievius Raccoonus (Vita), The Last of Us Remastered (PS4) */
|
||||||
/* "a9in": ATRAC9 info */
|
if (xvag.subsongs > 1 && xvag.layers > 1) goto fail;
|
||||||
/* 0x00: frame size, 0x04: samples per frame, 0x0c: fact num_samples (no change), 0x10: encoder delay1 */
|
|
||||||
if (!find_chunk(streamFile, 0x6139696E,first_offset,0, &chunk_offset,NULL, xvag.big_endian, 1)) /*"a9in"*/
|
/* "a9in": ATRAC9 info */
|
||||||
goto fail;
|
/* 0x00: frame size, 0x04: samples per frame, 0x0c: fact num_samples (no change), 0x10: encoder delay1 */
|
||||||
|
if (!find_chunk(streamFile, 0x6139696E,first_offset,0, &chunk_offset,NULL, xvag.big_endian, 1)) /*"a9in"*/
|
||||||
if (xvag.layers > 1) {
|
goto fail;
|
||||||
/* some Vita/PS4 multichannel [flower (Vita), Uncharted Collection (PS4)]. PS4 ATRAC9 also
|
|
||||||
* does single-stream >2ch, but this can do configs ATRAC9 can't, like 5ch/14ch/etc */
|
if (xvag.layers > 1) {
|
||||||
vgmstream->layout_data = build_layered_xvag(streamFile, &xvag, chunk_offset, start_offset);
|
/* some Vita/PS4 multichannel [flower (Vita), Uncharted Collection (PS4)]. PS4 ATRAC9 also
|
||||||
if (!vgmstream->layout_data) goto fail;
|
* does single-stream >2ch, but this can do configs ATRAC9 can't, like 5ch/14ch/etc */
|
||||||
vgmstream->coding_type = coding_ATRAC9;
|
vgmstream->layout_data = build_layered_xvag(streamFile, &xvag, chunk_offset, start_offset);
|
||||||
vgmstream->layout_type = layout_layered;
|
if (!vgmstream->layout_data) goto fail;
|
||||||
|
vgmstream->coding_type = coding_ATRAC9;
|
||||||
break;
|
vgmstream->layout_type = layout_layered;
|
||||||
}
|
|
||||||
else {
|
break;
|
||||||
/* interleaved subsongs (section layers) */
|
}
|
||||||
size_t frame_size = read_32bit(chunk_offset+0x00,streamFile);
|
else {
|
||||||
|
/* interleaved subsongs (section layers) */
|
||||||
if (!init_xvag_atrac9(streamFile, vgmstream, &xvag, chunk_offset))
|
size_t frame_size = read_32bit(chunk_offset+0x00,streamFile);
|
||||||
goto fail;
|
|
||||||
temp_streamFile = setup_xvag_streamfile(streamFile, start_offset, frame_size*xvag.factor,frame_size, (target_subsong-1), total_subsongs);
|
if (!init_xvag_atrac9(streamFile, vgmstream, &xvag, chunk_offset))
|
||||||
if (!temp_streamFile) goto fail;
|
goto fail;
|
||||||
start_offset = 0;
|
temp_streamFile = setup_xvag_streamfile(streamFile, start_offset, frame_size*xvag.factor,frame_size, (target_subsong-1), total_subsongs);
|
||||||
}
|
if (!temp_streamFile) goto fail;
|
||||||
|
start_offset = 0;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
#endif
|
break;
|
||||||
|
}
|
||||||
default:
|
#endif
|
||||||
goto fail;
|
|
||||||
}
|
default:
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
if (!vgmstream_open_stream(vgmstream,temp_streamFile ? temp_streamFile : streamFile,start_offset))
|
|
||||||
goto fail;
|
|
||||||
close_streamfile(temp_streamFile);
|
if (!vgmstream_open_stream(vgmstream,temp_streamFile ? temp_streamFile : streamFile,start_offset))
|
||||||
return vgmstream;
|
goto fail;
|
||||||
|
close_streamfile(temp_streamFile);
|
||||||
fail:
|
return vgmstream;
|
||||||
close_streamfile(temp_streamFile);
|
|
||||||
close_vgmstream(vgmstream);
|
fail:
|
||||||
return NULL;
|
close_streamfile(temp_streamFile);
|
||||||
}
|
close_vgmstream(vgmstream);
|
||||||
|
return NULL;
|
||||||
#ifdef VGM_USE_ATRAC9
|
}
|
||||||
static int init_xvag_atrac9(STREAMFILE *streamFile, VGMSTREAM* vgmstream, xvag_header * xvag, off_t chunk_offset) {
|
|
||||||
int32_t (*read_32bit)(off_t,STREAMFILE*) = xvag->big_endian ? read_32bitBE : read_32bitLE;
|
#ifdef VGM_USE_ATRAC9
|
||||||
atrac9_config cfg = {0};
|
static int init_xvag_atrac9(STREAMFILE *streamFile, VGMSTREAM* vgmstream, xvag_header * xvag, off_t chunk_offset) {
|
||||||
|
int32_t (*read_32bit)(off_t,STREAMFILE*) = xvag->big_endian ? read_32bitBE : read_32bitLE;
|
||||||
cfg.channels = vgmstream->channels;
|
atrac9_config cfg = {0};
|
||||||
cfg.config_data = read_32bitBE(chunk_offset+0x08,streamFile);
|
|
||||||
cfg.encoder_delay = read_32bit(chunk_offset+0x14,streamFile);
|
cfg.channels = vgmstream->channels;
|
||||||
|
cfg.config_data = read_32bitBE(chunk_offset+0x08,streamFile);
|
||||||
vgmstream->codec_data = init_atrac9(&cfg);
|
cfg.encoder_delay = read_32bit(chunk_offset+0x14,streamFile);
|
||||||
if (!vgmstream->codec_data) goto fail;
|
|
||||||
vgmstream->coding_type = coding_ATRAC9;
|
vgmstream->codec_data = init_atrac9(&cfg);
|
||||||
vgmstream->layout_type = layout_none;
|
if (!vgmstream->codec_data) goto fail;
|
||||||
|
vgmstream->coding_type = coding_ATRAC9;
|
||||||
return 1;
|
vgmstream->layout_type = layout_none;
|
||||||
fail:
|
|
||||||
return 0;
|
return 1;
|
||||||
}
|
fail:
|
||||||
#endif
|
return 0;
|
||||||
|
}
|
||||||
static layered_layout_data* build_layered_xvag(STREAMFILE *streamFile, xvag_header * xvag, off_t chunk_offset, off_t start_offset) {
|
#endif
|
||||||
layered_layout_data* data = NULL;
|
|
||||||
STREAMFILE* temp_streamFile = NULL;
|
static layered_layout_data* build_layered_xvag(STREAMFILE *streamFile, xvag_header * xvag, off_t chunk_offset, off_t start_offset) {
|
||||||
int32_t (*read_32bit)(off_t,STREAMFILE*) = xvag->big_endian ? read_32bitBE : read_32bitLE;
|
layered_layout_data* data = NULL;
|
||||||
int i, layers = xvag->layers;
|
STREAMFILE* temp_streamFile = NULL;
|
||||||
|
int32_t (*read_32bit)(off_t,STREAMFILE*) = xvag->big_endian ? read_32bitBE : read_32bitLE;
|
||||||
|
int i, layers = xvag->layers;
|
||||||
/* init layout */
|
|
||||||
data = init_layout_layered(layers);
|
|
||||||
if (!data) goto fail;
|
/* init layout */
|
||||||
|
data = init_layout_layered(layers);
|
||||||
/* interleaves frames per substreams */
|
if (!data) goto fail;
|
||||||
for (i = 0; i < layers; i++) {
|
|
||||||
int layer_channels = xvag->channels / layers; /* all streams must be equal (XVAG limitation) */
|
/* interleaves frames per substreams */
|
||||||
|
for (i = 0; i < layers; i++) {
|
||||||
/* build the layer VGMSTREAM */
|
int layer_channels = xvag->channels / layers; /* all streams must be equal (XVAG limitation) */
|
||||||
data->layers[i] = allocate_vgmstream(layer_channels, xvag->loop_flag);
|
|
||||||
if (!data->layers[i]) goto fail;
|
/* build the layer VGMSTREAM */
|
||||||
|
data->layers[i] = allocate_vgmstream(layer_channels, xvag->loop_flag);
|
||||||
data->layers[i]->sample_rate = xvag->sample_rate;
|
if (!data->layers[i]) goto fail;
|
||||||
data->layers[i]->num_samples = xvag->num_samples;
|
|
||||||
|
data->layers[i]->sample_rate = xvag->sample_rate;
|
||||||
switch(xvag->codec) {
|
data->layers[i]->num_samples = xvag->num_samples;
|
||||||
#ifdef VGM_USE_ATRAC9
|
|
||||||
case 0x09: {
|
switch(xvag->codec) {
|
||||||
size_t frame_size = read_32bit(chunk_offset+0x00,streamFile);
|
#ifdef VGM_USE_ATRAC9
|
||||||
|
case 0x09: {
|
||||||
if (!init_xvag_atrac9(streamFile, data->layers[i], xvag, chunk_offset))
|
size_t frame_size = read_32bit(chunk_offset+0x00,streamFile);
|
||||||
goto fail;
|
|
||||||
temp_streamFile = setup_xvag_streamfile(streamFile, start_offset, frame_size*xvag->factor,frame_size, i, layers);
|
if (!init_xvag_atrac9(streamFile, data->layers[i], xvag, chunk_offset))
|
||||||
if (!temp_streamFile) goto fail;
|
goto fail;
|
||||||
break;
|
temp_streamFile = setup_xvag_streamfile(streamFile, start_offset, frame_size*xvag->factor,frame_size, i, layers);
|
||||||
}
|
if (!temp_streamFile) goto fail;
|
||||||
#endif
|
break;
|
||||||
default:
|
}
|
||||||
goto fail;
|
#endif
|
||||||
}
|
default:
|
||||||
|
goto fail;
|
||||||
if ( !vgmstream_open_stream(data->layers[i], temp_streamFile, 0x00) )
|
}
|
||||||
goto fail;
|
|
||||||
close_streamfile(temp_streamFile);
|
if ( !vgmstream_open_stream(data->layers[i], temp_streamFile, 0x00) )
|
||||||
}
|
goto fail;
|
||||||
|
close_streamfile(temp_streamFile);
|
||||||
/* setup layered VGMSTREAMs */
|
}
|
||||||
if (!setup_layout_layered(data))
|
|
||||||
goto fail;
|
/* setup layered VGMSTREAMs */
|
||||||
return data;
|
if (!setup_layout_layered(data))
|
||||||
|
goto fail;
|
||||||
fail:
|
return data;
|
||||||
close_streamfile(temp_streamFile);
|
|
||||||
free_layout_layered(data);
|
fail:
|
||||||
return NULL;
|
close_streamfile(temp_streamFile);
|
||||||
}
|
free_layout_layered(data);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
|
@ -1694,19 +1694,19 @@ void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to
|
||||||
case coding_PSX:
|
case coding_PSX:
|
||||||
for (ch = 0; ch < vgmstream->channels; ch++) {
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
||||||
decode_psx(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
decode_psx(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
||||||
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, 0);
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, 0, vgmstream->codec_config);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case coding_PSX_badflags:
|
case coding_PSX_badflags:
|
||||||
for (ch = 0; ch < vgmstream->channels; ch++) {
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
||||||
decode_psx(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
decode_psx(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
||||||
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, 1);
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, 1, vgmstream->codec_config);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case coding_PSX_cfg:
|
case coding_PSX_cfg:
|
||||||
for (ch = 0; ch < vgmstream->channels; ch++) {
|
for (ch = 0; ch < vgmstream->channels; ch++) {
|
||||||
decode_psx_configurable(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
decode_psx_configurable(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
||||||
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, vgmstream->interleave_block_size);
|
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, vgmstream->interleave_block_size, vgmstream->codec_config);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case coding_PSX_pivotal:
|
case coding_PSX_pivotal:
|
||||||
|
|
Loading…
Reference in New Issue