support for mono sadb

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@574 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2009-02-04 01:05:20 +00:00
parent f2b83c7a5f
commit b1b0ca2f98

View File

@ -606,55 +606,60 @@ VGMSTREAM * init_vgmstream_sadb(STREAMFILE *streamFile) {
struct dsp_header ch0_header,ch1_header; struct dsp_header ch0_header,ch1_header;
int i; int i;
int channel_count;
/* check extension, case insensitive */ /* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename)); streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("sad",filename_extension(filename))) goto fail; if (strcasecmp("sad",filename_extension(filename))) goto fail;
if (read_dsp_header(&ch0_header, 0x80, streamFile)) goto fail;
if (read_dsp_header(&ch1_header, 0xe0, streamFile)) goto fail;
/* check header magic */ /* check header magic */
if (read_32bitBE(0x0,streamFile) != 0x73616462) goto fail; /* "sadb" */ if (read_32bitBE(0x0,streamFile) != 0x73616462) goto fail; /* "sadb" */
channel_count = read_8bit(0x32, streamFile);
if (channel_count != 1 && channel_count != 2) goto fail;
if (read_dsp_header(&ch0_header, 0x80, streamFile)) goto fail;
if (channel_count == 2 && read_dsp_header(&ch1_header, 0xe0, streamFile)) goto fail;
start_offset = read_32bitBE(0x48,streamFile); start_offset = read_32bitBE(0x48,streamFile);
interleave = 16; interleave = 16;
/* check initial predictor/scale */ /* check initial predictor/scale */
if (ch0_header.initial_ps != (uint8_t)read_8bit(start_offset,streamFile)) if (ch0_header.initial_ps != (uint8_t)read_8bit(start_offset,streamFile))
goto fail; goto fail;
if (ch1_header.initial_ps != (uint8_t)read_8bit(start_offset+interleave,streamFile)) if (channel_count == 2 && ch1_header.initial_ps != (uint8_t)read_8bit(start_offset+interleave,streamFile))
goto fail; goto fail;
/* check type==0 and gain==0 */ /* check type==0 and gain==0 */
if (ch0_header.format || ch0_header.gain || if (ch0_header.format || ch0_header.gain ||
ch1_header.format || ch1_header.gain) (channel_count == 2 &&(ch1_header.format || ch1_header.gain)))
goto fail; goto fail;
/* check for agreement */ /* check for agreement */
if ( if ( channel_count == 2 &&(
ch0_header.sample_count != ch1_header.sample_count || ch0_header.sample_count != ch1_header.sample_count ||
ch0_header.nibble_count != ch1_header.nibble_count || ch0_header.nibble_count != ch1_header.nibble_count ||
ch0_header.sample_rate != ch1_header.sample_rate || ch0_header.sample_rate != ch1_header.sample_rate ||
ch0_header.loop_flag != ch1_header.loop_flag || ch0_header.loop_flag != ch1_header.loop_flag ||
ch0_header.loop_start_offset != ch1_header.loop_start_offset || ch0_header.loop_start_offset != ch1_header.loop_start_offset ||
ch0_header.loop_end_offset != ch1_header.loop_end_offset ch0_header.loop_end_offset != ch1_header.loop_end_offset
) goto fail; )) goto fail;
if (ch0_header.loop_flag) { if (ch0_header.loop_flag) {
off_t loop_off; off_t loop_off;
/* check loop predictor/scale */ /* check loop predictor/scale */
loop_off = ch0_header.loop_start_offset/16*8; loop_off = ch0_header.loop_start_offset/8/channel_count*8;
loop_off = (loop_off/interleave*interleave*2) + (loop_off%interleave); loop_off = (loop_off/interleave*interleave*channel_count) + (loop_off%interleave);
if (ch0_header.loop_ps != (uint8_t)read_8bit(start_offset+loop_off,streamFile)) if (ch0_header.loop_ps != (uint8_t)read_8bit(start_offset+loop_off,streamFile))
goto fail; goto fail;
if (ch1_header.loop_ps != (uint8_t)read_8bit(start_offset+loop_off+interleave,streamFile)) if (channel_count == 2 &&
ch1_header.loop_ps != (uint8_t)read_8bit(start_offset+loop_off+interleave,streamFile))
goto fail; goto fail;
} }
/* build the VGMSTREAM */ /* build the VGMSTREAM */
vgmstream = allocate_vgmstream(2,ch0_header.loop_flag); vgmstream = allocate_vgmstream(channel_count,ch0_header.loop_flag);
if (!vgmstream) goto fail; if (!vgmstream) goto fail;
/* fill in the vital statistics */ /* fill in the vital statistics */
@ -668,29 +673,33 @@ VGMSTREAM * init_vgmstream_sadb(STREAMFILE *streamFile) {
ch0_header.loop_end_offset)+1; ch0_header.loop_end_offset)+1;
vgmstream->coding_type = coding_NGC_DSP; vgmstream->coding_type = coding_NGC_DSP;
vgmstream->layout_type = layout_interleave; vgmstream->layout_type = channel_count == 2 ? layout_interleave : layout_none;
vgmstream->interleave_block_size = interleave; vgmstream->interleave_block_size = interleave;
vgmstream->meta_type = meta_DSP_SADB; vgmstream->meta_type = meta_DSP_SADB;
/* coeffs */ /* coeffs */
for (i=0;i<16;i++) { for (i=0;i<16;i++) {
vgmstream->ch[0].adpcm_coef[i] = ch0_header.coef[i]; vgmstream->ch[0].adpcm_coef[i] = ch0_header.coef[i];
vgmstream->ch[1].adpcm_coef[i] = ch1_header.coef[i]; if (channel_count == 2)
vgmstream->ch[1].adpcm_coef[i] = ch1_header.coef[i];
} }
/* initial history */ /* initial history */
/* always 0 that I've ever seen, but for completeness... */ /* always 0 that I've ever seen, but for completeness... */
vgmstream->ch[0].adpcm_history1_16 = ch0_header.initial_hist1; vgmstream->ch[0].adpcm_history1_16 = ch0_header.initial_hist1;
vgmstream->ch[0].adpcm_history2_16 = ch0_header.initial_hist2; 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;
vgmstream->ch[0].streamfile = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE); vgmstream->ch[0].streamfile = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
vgmstream->ch[1].streamfile = vgmstream->ch[0].streamfile;
if (channel_count == 2) {
vgmstream->ch[1].adpcm_history1_16 = ch1_header.initial_hist1;
vgmstream->ch[1].adpcm_history2_16 = ch1_header.initial_hist2;
vgmstream->ch[1].streamfile = vgmstream->ch[0].streamfile;
}
if (!vgmstream->ch[0].streamfile) goto fail; if (!vgmstream->ch[0].streamfile) goto fail;
/* open the file for reading */ /* open the file for reading */
for (i=0;i<2;i++) { for (i=0;i<channel_count;i++) {
vgmstream->ch[i].channel_start_offset= vgmstream->ch[i].channel_start_offset=
vgmstream->ch[i].offset=start_offset+i*interleave; vgmstream->ch[i].offset=start_offset+i*interleave;
} }