Clean iadp and add missing .adp extension

This commit is contained in:
bnnm 2018-03-25 20:00:57 +02:00
parent a2acd045bf
commit 69da9d5f4d

View File

@ -159,8 +159,10 @@ VGMSTREAM * init_vgmstream_ngc_dsp_std(STREAMFILE *streamFile) {
int i;
/* check extension, case insensitive */
/* .dsp: standard, .adp: Dr. Muto (GC) mono files */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("dsp",filename_extension(filename))) goto fail;
if (strcasecmp("dsp",filename_extension(filename)) &&
strcasecmp("adp", filename_extension(filename))) goto fail;
if (read_dsp_header(&header, 0, streamFile)) goto fail;
@ -1832,119 +1834,60 @@ fail:
return NULL;
}
/* dual dsp header with additional "iadp" header, found in Dr. Muto (NGC) */
#define IADP_MAX_CHANNELS 2
/* iadp - custom header + interleaved dsp [Dr. Muto (GC)] */
VGMSTREAM * init_vgmstream_ngc_dsp_iadp(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[PATH_LIMIT];
struct dsp_header ch0_header,ch1_header;
off_t ch1_header_start, ch2_header_start, ch1_start, ch2_start;
off_t start_offset, header_offset;
size_t header_spacing, interleave;
int channel_count;
int i;
struct dsp_header ch_header[IADP_MAX_CHANNELS];
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("iadp",filename_extension(filename)))
/* checks */
/* .adp: actual extension, .iadp: header id */
if (!check_extensions(streamFile, "adp,iadp"))
goto fail;
if (read_32bitBE(0x00,streamFile) != 0x69616470) /* "iadp" */
goto fail;
/* check header */
if (read_32bitBE(0x0,streamFile) != 0x69616470) /* iadp */
goto fail;
channel_count = read_32bitBE(0x4,streamFile);
if (channel_count != 0x2)
goto fail;
channel_count = read_32bitBE(0x04,streamFile);
if (channel_count != IADP_MAX_CHANNELS) goto fail;
ch1_header_start = 0x20;
ch2_header_start = 0x80;
ch1_start = read_32bitBE(0x1C,streamFile);
ch2_start = ch1_start + read_32bitBE(0x8,streamFile);
header_offset = 0x20;
header_spacing = 0x60;
start_offset = read_32bitBE(0x1C,streamFile);
interleave = read_32bitBE(0x08,streamFile);
/* get DSP headers */
if (read_dsp_header(&ch0_header, ch1_header_start, streamFile)) goto fail;
if (read_dsp_header(&ch1_header, ch2_header_start, streamFile)) goto fail;
/* check initial predictor/scale */
if (ch0_header.initial_ps != (uint8_t)read_8bit(ch1_start, streamFile))
goto fail;
if (ch1_header.initial_ps != (uint8_t)read_8bit(ch2_start, streamFile))
goto fail;
/* check type==0 and gain==0 */
if (ch0_header.format || ch0_header.gain)
goto fail;
if (ch1_header.format || ch1_header.gain)
goto fail;
/* check for agreement */
if (
ch0_header.sample_count != ch1_header.sample_count ||
ch0_header.nibble_count != ch1_header.nibble_count ||
ch0_header.sample_rate != ch1_header.sample_rate ||
ch0_header.loop_flag != ch1_header.loop_flag ||
ch0_header.loop_start_offset != ch1_header.loop_start_offset ||
ch0_header.loop_end_offset != ch1_header.loop_end_offset
) goto fail;
if (ch0_header.loop_flag)
{
off_t loop_off;
/* check loop predictor/scale */
loop_off = ch0_header.loop_start_offset/16*8;
if (ch0_header.loop_ps != (uint8_t)read_8bit(ch1_start+loop_off,streamFile))
goto fail;
if (ch1_header.loop_ps != (uint8_t)read_8bit(ch2_start+loop_off,streamFile))
goto fail;
}
/* read dsp */
if (!dsp_load_header(ch_header, channel_count, streamFile,header_offset,header_spacing)) goto fail;
if (!check_dsp_format(ch_header, channel_count)) goto fail;
if (!check_dsp_samples(ch_header, channel_count)) goto fail;
if (!check_dsp_initial_ps(ch_header, channel_count, streamFile,start_offset,interleave)) goto fail;
if (!check_dsp_loop_ps(ch_header, channel_count, streamFile,start_offset,interleave)) goto fail;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,ch0_header.loop_flag);
vgmstream = allocate_vgmstream(channel_count,ch_header[0].loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
vgmstream->num_samples = ch0_header.sample_count;
vgmstream->sample_rate = ch0_header.sample_rate;
vgmstream->loop_start_sample = dsp_nibbles_to_samples(ch0_header.loop_start_offset);
vgmstream->loop_end_sample = dsp_nibbles_to_samples(ch0_header.loop_end_offset)+1;
vgmstream->sample_rate = ch_header[0].sample_rate;
vgmstream->num_samples = ch_header[0].sample_count;
vgmstream->loop_start_sample = dsp_nibbles_to_samples(ch_header[0].loop_start_offset);
vgmstream->loop_end_sample = dsp_nibbles_to_samples(ch_header[0].loop_end_offset)+1;
vgmstream->meta_type = meta_NGC_DSP_IADP;
vgmstream->coding_type = coding_NGC_DSP;
vgmstream->interleave_block_size = read_32bitBE(0x8,streamFile);
vgmstream->layout_type = layout_interleave;
vgmstream->meta_type = meta_NGC_DSP_IADP;
setup_vgmstream_dsp(vgmstream, ch_header);
/* coeffs */
for (i=0;i<16;i++) {
vgmstream->ch[0].adpcm_coef[i] = ch0_header.coef[i];
vgmstream->ch[1].adpcm_coef[i] = ch1_header.coef[i];
}
/* initial history */
/* always 0 that I've ever seen, but for completeness... */
vgmstream->ch[0].adpcm_history1_16 = ch0_header.initial_hist1;
vgmstream->ch[0].adpcm_history2_16 = ch0_header.initial_hist2;
vgmstream->ch[1].adpcm_history1_16 = ch1_header.initial_hist1;
vgmstream->ch[1].adpcm_history2_16 = ch1_header.initial_hist2;
/* open the file for reading */
vgmstream->ch[0].streamfile = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
if (!vgmstream->ch[0].streamfile)
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
goto fail;
vgmstream->ch[0].channel_start_offset = vgmstream->ch[0].offset=ch1_start;
vgmstream->ch[1].streamfile = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
if (!vgmstream->ch[1].streamfile)
goto fail;
vgmstream->ch[1].channel_start_offset = vgmstream->ch[1].offset=ch2_start;
return vgmstream;
fail:
/* clean up anything we may have opened */
if (vgmstream) close_vgmstream(vgmstream);
close_vgmstream(vgmstream);
return NULL;
}