mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-24 15:00:11 +01:00
IDSP as in SSB4 3DS
This commit is contained in:
parent
64bdd4c943
commit
0ebc29f236
@ -3,6 +3,8 @@
|
||||
|
||||
#include "../vgmstream.h"
|
||||
|
||||
VGMSTREAM * init_vgmstream_3ds_idsp(STREAMFILE *streamFile);
|
||||
|
||||
VGMSTREAM * init_vgmstream_adx(STREAMFILE *streamFile);
|
||||
|
||||
VGMSTREAM * init_vgmstream_afc(STREAMFILE *streamFile);
|
||||
|
@ -596,6 +596,124 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 3DS IDSP two standard DSP headers (SSB4) */
|
||||
VGMSTREAM * init_vgmstream_3ds_idsp(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
char filename[PATH_LIMIT];
|
||||
|
||||
off_t start_offset;
|
||||
off_t interleave;
|
||||
|
||||
struct dsp_header ch0_header,ch1_header;
|
||||
int i;
|
||||
int channel_count;
|
||||
|
||||
/* check extension, case insensitive */
|
||||
streamFile->get_name(streamFile,filename,sizeof(filename));
|
||||
if (strcasecmp("idsp",filename_extension(filename))) goto fail;
|
||||
|
||||
/* check header magic */
|
||||
if (read_32bitBE(0x0,streamFile) != 0x49445350) goto fail; /* "IDSP" */
|
||||
|
||||
channel_count = read_32bitBE(0x8, streamFile);
|
||||
if (channel_count != 2) goto fail;
|
||||
|
||||
if (read_dsp_header(&ch0_header, 0x40, streamFile)) goto fail;
|
||||
if (channel_count == 2 && read_dsp_header(&ch1_header, 0xa0, streamFile)) goto fail;
|
||||
|
||||
start_offset = read_32bitBE(0x28,streamFile);
|
||||
interleave = 16;
|
||||
|
||||
/* check initial predictor/scale */
|
||||
if (ch0_header.initial_ps != (uint8_t)read_8bit(start_offset,streamFile))
|
||||
goto fail;
|
||||
if (channel_count == 2 && ch1_header.initial_ps != (uint8_t)read_8bit(start_offset+interleave,streamFile))
|
||||
goto fail;
|
||||
|
||||
/* check type==0 and gain==0 */
|
||||
if (ch0_header.format || ch0_header.gain ||
|
||||
(channel_count == 2 &&(ch1_header.format || ch1_header.gain)))
|
||||
goto fail;
|
||||
|
||||
/* check for agreement */
|
||||
if ( channel_count == 2 &&(
|
||||
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.sample_rate != read_32bitBE(0xc, streamFile) ||
|
||||
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/8/channel_count*8;
|
||||
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))
|
||||
goto fail;
|
||||
if (channel_count == 2 &&
|
||||
ch1_header.loop_ps != (uint8_t)read_8bit(start_offset+loop_off+interleave,streamFile))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
|
||||
vgmstream = allocate_vgmstream(channel_count,ch0_header.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;
|
||||
|
||||
/* TODO: adjust for interleave? */
|
||||
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->coding_type = coding_NGC_DSP;
|
||||
vgmstream->layout_type = channel_count == 2 ? layout_interleave : layout_none;
|
||||
vgmstream->interleave_block_size = interleave;
|
||||
vgmstream->meta_type = meta_3DS_IDSP;
|
||||
|
||||
/* coeffs */
|
||||
for (i=0;i<16;i++) {
|
||||
vgmstream->ch[0].adpcm_coef[i] = ch0_header.coef[i];
|
||||
if (channel_count == 2)
|
||||
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[0].streamfile = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
||||
|
||||
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;
|
||||
/* open the file for reading */
|
||||
for (i=0;i<channel_count;i++) {
|
||||
vgmstream->ch[i].channel_start_offset=
|
||||
vgmstream->ch[i].offset=start_offset+i*interleave;
|
||||
}
|
||||
|
||||
return vgmstream;
|
||||
|
||||
fail:
|
||||
/* clean up anything we may have opened */
|
||||
if (vgmstream) close_vgmstream(vgmstream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* sadb - .SAD files, two standard DSP headers */
|
||||
VGMSTREAM * init_vgmstream_sadb(STREAMFILE *streamFile) {
|
||||
VGMSTREAM * vgmstream = NULL;
|
||||
|
@ -332,6 +332,7 @@ VGMSTREAM * (*init_vgmstream_fcns[])(STREAMFILE *streamFile) = {
|
||||
init_vgmstream_ps2_vbk,
|
||||
init_vgmstream_otm,
|
||||
init_vgmstream_bcstm,
|
||||
init_vgmstream_3ds_idsp,
|
||||
};
|
||||
|
||||
#define INIT_VGMSTREAM_FCNS (sizeof(init_vgmstream_fcns)/sizeof(init_vgmstream_fcns[0]))
|
||||
@ -3067,6 +3068,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
|
||||
case meta_CSTM:
|
||||
snprintf(temp,TEMPSIZE,"Nintendo 3DS CSTM Header");
|
||||
break;
|
||||
case meta_3DS_IDSP:
|
||||
snprintf(temp,TEMPSIZE,"Nintendo 3DS IDSP Header");
|
||||
break;
|
||||
default:
|
||||
snprintf(temp,TEMPSIZE,"THEY SHOULD HAVE SENT A POET");
|
||||
}
|
||||
|
@ -567,6 +567,7 @@ typedef enum {
|
||||
meta_PS2_VBK,
|
||||
meta_OTM, // Otomedius (Arcade)
|
||||
meta_CSTM, // Nintendo 3DS CSTM
|
||||
meta_3DS_IDSP, // Nintendo 3DS IDSP
|
||||
#ifdef VGM_USE_MP4V2
|
||||
meta_MP4,
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user