Fixed v5 header coef positions

This commit is contained in:
bnnm 2016-12-16 20:34:44 +01:00
parent 2a7b645d23
commit 27868be723

View File

@ -8,11 +8,11 @@ Capcom MADP format found in Capcom 3DS games.
VGMSTREAM * init_vgmstream_mca(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[PATH_LIMIT];
coding_t coding_type;
int channel_count;
int loop_flag;
off_t start_offset;
off_t coef_offset;
int version;
size_t head_size, data_size;
off_t start_offset, coef_offset, coef_start, coef_shift;
int i, j;
int coef_spacing;
@ -26,44 +26,60 @@ VGMSTREAM * init_vgmstream_mca(STREAMFILE *streamFile) {
if ((uint32_t)read_32bitBE(0, streamFile) != 0x4D414450) /* "MADP" */
goto fail;
start_offset = (get_streamfile_size(streamFile) - read_32bitLE(0x20, streamFile));
channel_count = read_8bit(0x8, streamFile);
if (read_32bitLE(0x18, streamFile) > 0)
loop_flag = 1;
else
loop_flag = 0;
coding_type = coding_NGC_DSP;
if (channel_count < 1) goto fail;
if (channel_count < 1) goto fail;
loop_flag = read_32bitLE(0x18, streamFile) > 0;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
vgmstream->interleave_block_size = read_16bitLE(0xa, streamFile); /* guessed, only seen 0x100 */
vgmstream->num_samples = read_32bitLE(0xc, streamFile);
vgmstream->sample_rate = (uint16_t)read_16bitLE(0x10, streamFile);
/* channels and loop flag are set by allocate_vgmstream */
vgmstream->loop_start_sample = read_32bitLE(0x14, streamFile);
vgmstream->loop_end_sample = read_32bitLE(0x18, streamFile);
vgmstream->coding_type = coding_type;
vgmstream->coding_type = coding_NGC_DSP;
if (channel_count == 1)
vgmstream->layout_type = layout_none;
else
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x100; // Constant for this format
vgmstream->meta_type = meta_MCA;
/* find data/coef offsets (guessed, formula may change with version) */
version = read_16bitLE(0x04, streamFile);
coef_spacing = 0x30;
data_size = read_32bitLE(0x20, streamFile);
if (version <= 0x3) { /* v3: Resident Evil Mercenaries 3D, Super Street Fighter IV 3D */
head_size = get_streamfile_size(streamFile) - data_size; /* probably 0x2c + 0x30*ch */
coef_shift = 0x0;
coef_start = head_size - coef_spacing * channel_count;
start_offset = head_size;
coef_offset = coef_start + coef_shift * 0x14;
} else if (version == 0x4) { /* v4: EX Troopers, Ace Attourney 5 */
head_size = read_16bitLE(0x1c, streamFile);
coef_shift = read_16bitLE(0x28, streamFile);
coef_start = head_size - coef_spacing * channel_count;
start_offset = head_size;
coef_offset = coef_start + coef_shift * 0x14;
} else { /* v5: Ace Attourney 6, Monster Hunter Generations, v6+? */
head_size = read_16bitLE(0x1c, streamFile); /* partial size */
coef_shift = read_16bitLE(0x28, streamFile);
coef_start = head_size - coef_spacing * channel_count;
start_offset = read_32bitLE(coef_start - 0x4, streamFile);
coef_offset = coef_start + coef_shift * 0x14;
}
coef_offset = start_offset - (vgmstream->channels * 0x30);
coef_spacing = 0x30;
/* set up ADPCM coefs */
for (j = 0; j<vgmstream->channels; j++) {
for (i = 0; i<16; i++) {
vgmstream->ch[j].adpcm_coef[i] = read_16bitLE(coef_offset + j*coef_spacing + i * 2, streamFile);