RSD6RADP .rsd support, added "Radical ADPCM" decoder (IMA)

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@698 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2009-09-12 04:51:39 +00:00
parent 4d8e5ee8ae
commit cc6912b2d5
6 changed files with 142 additions and 0 deletions

View File

@ -21,6 +21,8 @@ void decode_ima(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing,
void decode_ms_ima(VGMSTREAM * vgmstream,VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do,int channel);
void decode_rad_ima(VGMSTREAM * vgmstream,VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do,int channel);
void decode_apple_ima4(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
void decode_ms_ima(VGMSTREAM * vgmstream,VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do,int channel);

View File

@ -123,6 +123,65 @@ void decode_ms_ima(VGMSTREAM * vgmstream,VGMSTREAMCHANNEL * stream, sample * out
stream->adpcm_step_index=step_index;
}
// "Radical ADPCM", essentially MS IMA
void decode_rad_ima(VGMSTREAM * vgmstream,VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do,int channel) {
int i=first_sample;
int sample_nibble;
int sample_decoded;
int delta;
int block_samples = (vgmstream->interleave_block_size - vgmstream->channels * 4) * 2 / vgmstream->channels;
int32_t sample_count=0;
int32_t hist1=stream->adpcm_history1_32;
int step_index = stream->adpcm_step_index;
off_t offset=stream->offset;
first_sample = first_sample % block_samples;
if (first_sample == 0) {
hist1 = read_16bitLE(offset+channel*4+2,stream->streamfile);
step_index = read_16bitLE(offset+channel*4,stream->streamfile);
if (step_index < 0) step_index=0;
if (step_index > 88) step_index=88;
}
for (i=first_sample,sample_count=0; i<first_sample+samples_to_do; i++,sample_count+=channelspacing) {
int step = ADPCMTable[step_index];
offset = stream->offset + 4*vgmstream->channels + (i/2*vgmstream->channels) + channel;
sample_nibble = (read_8bit(offset,stream->streamfile) >> (i&1?4:0))&0xf;
sample_decoded=hist1;
delta = step >> 3;
if (sample_nibble & 1) delta += step >> 2;
if (sample_nibble & 2) delta += step >> 1;
if (sample_nibble & 4) delta += step;
if (sample_nibble & 8)
sample_decoded -= delta;
else
sample_decoded += delta;
hist1=clamp16(sample_decoded);
step_index += IMA_IndexTable[sample_nibble];
if (step_index < 0) step_index=0;
if (step_index > 88) step_index=88;
outbuf[sample_count]=(short)(hist1);
}
// Only increment offset on complete frame
if (i == block_samples) stream->offset += vgmstream->interleave_block_size;
stream->adpcm_history1_32=hist1;
stream->adpcm_step_index=step_index;
}
void decode_xbox_ima(VGMSTREAM * vgmstream,VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do,int channel) {
int i=first_sample;
int sample_nibble;

View File

@ -283,6 +283,8 @@ VGMSTREAM * init_vgmstream_rsd6wadp(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_rsd6xadp(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_rsd6radp(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_dc_asd(STREAMFILE * streamFile);
VGMSTREAM * init_vgmstream_naomi_spsd(STREAMFILE * streamFile);

View File

@ -909,6 +909,67 @@ fail:
return NULL;
}
/* RSD6RADP */
VGMSTREAM * init_vgmstream_rsd6radp(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
char filename[260];
off_t start_offset;
int loop_flag;
int channel_count;
/* check extension, case insensitive */
streamFile->get_name(streamFile,filename,sizeof(filename));
if (strcasecmp("rsd",filename_extension(filename))) goto fail;
/* check header */
if (read_32bitBE(0x0,streamFile) != 0x52534436) /* RSD6 */
goto fail;
if (read_32bitBE(0x4,streamFile) != 0x52414450) /* RADP */
goto fail;
loop_flag = 0;
channel_count = read_32bitLE(0x8,streamFile);
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count,loop_flag);
if (!vgmstream) goto fail;
/* fill in the vital statistics */
start_offset = 0x800;
vgmstream->channels = channel_count;
vgmstream->sample_rate = read_32bitLE(0x10,streamFile);
vgmstream->coding_type = coding_RAD_IMA;
vgmstream->num_samples = (get_streamfile_size(streamFile)-start_offset)/0x14/channel_count*32;
if (loop_flag) {
vgmstream->loop_start_sample = loop_flag;
vgmstream->loop_end_sample = (get_streamfile_size(streamFile)-start_offset)*28/16/channel_count;
}
vgmstream->layout_type = layout_none;
vgmstream->interleave_block_size = 0x14*channel_count;
vgmstream->meta_type = meta_RSD6RADP;
/* open the file for reading */
{
int i;
STREAMFILE * file;
file = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
if (!file) goto fail;
for (i=0;i<channel_count;i++) {
vgmstream->ch[i].streamfile = file;
vgmstream->ch[i].offset=vgmstream->ch[i].channel_start_offset=start_offset;
}
}
return vgmstream;
fail:
/* clean up anything we may have opened */
if (vgmstream) close_vgmstream(vgmstream);
return NULL;
}
#if 0
/* RSD6XMA */

View File

@ -164,6 +164,7 @@ VGMSTREAM * (*init_vgmstream_fcns[])(STREAMFILE *streamFile) = {
init_vgmstream_rsd6vag,
init_vgmstream_rsd6wadp,
init_vgmstream_rsd6xadp,
init_vgmstream_rsd6radp,
init_vgmstream_bgw,
init_vgmstream_spw,
init_vgmstream_ps2_ass,
@ -727,6 +728,7 @@ int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream) {
case coding_APPLE_IMA4:
return 64;
case coding_MS_IMA:
case coding_RAD_IMA:
return (vgmstream->interleave_block_size-4*vgmstream->channels)*2/vgmstream->channels;
case coding_NDS_PROCYON:
return 30;
@ -772,6 +774,7 @@ int get_vgmstream_frame_size(VGMSTREAM * vgmstream) {
case coding_SASSC:
return 1;
case coding_MS_IMA:
case coding_RAD_IMA:
case coding_NDS_IMA:
return vgmstream->interleave_block_size;
case coding_NGC_DTK:
@ -950,6 +953,13 @@ void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to
samples_to_do,chan);
}
break;
case coding_RAD_IMA:
for (chan=0;chan<vgmstream->channels;chan++) {
decode_rad_ima(vgmstream,&vgmstream->ch[chan],buffer+samples_written*vgmstream->channels+chan,
vgmstream->channels,vgmstream->samples_into_block,
samples_to_do,chan);
}
break;
case coding_NGC_DTK:
for (chan=0;chan<vgmstream->channels;chan++) {
decode_ngc_dtk(&vgmstream->ch[chan],buffer+samples_written*vgmstream->channels+chan,
@ -1440,6 +1450,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
case coding_MS_IMA:
snprintf(temp,TEMPSIZE,"Microsoft 4-bit IMA ADPCM");
break;
case coding_RAD_IMA:
snprintf(temp,TEMPSIZE,"\"Radical\" 4-bit IMA ADPCM");
break;
case coding_APPLE_IMA4:
snprintf(temp,TEMPSIZE,"Apple Quicktime 4-bit IMA ADPCM");
break;
@ -2116,6 +2129,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
case meta_RSD6WADP:
snprintf(temp,TEMPSIZE,"RSD6/WADP Header");
break;
case meta_RSD6RADP:
snprintf(temp,TEMPSIZE,"RSD6/RADP Header");
break;
case meta_DC_ASD:
snprintf(temp,TEMPSIZE,"ASD Header");
break;

View File

@ -74,6 +74,7 @@ typedef enum {
coding_IMA, /* bare IMA, low nibble first */
coding_INT_IMA, /* */
coding_MS_IMA, /* Microsoft IMA */
coding_RAD_IMA, /* "Radical ADPCM" IMA */
coding_APPLE_IMA4, /* Apple Quicktime IMA4 */
coding_WS, /* Westwood Studios' custom VBR ADPCM */
#ifdef VGM_USE_MPEG
@ -315,6 +316,7 @@ typedef enum {
meta_RSD6VAG, /* RSD6VAG */
meta_RSD6WADP, /* RSD6WADP */
meta_RSD6XADP, /* RSD6XADP */
meta_RSD6RADP, /* RSD6RADP */
meta_PS2_ASS, /* ASS */
meta_PS2_SEG, /* Eragon */