mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-19 00:04:04 +01:00
Microsoft IMA for riff and genh
git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@590 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
parent
b68b1803bd
commit
8963ee3eed
@ -18,6 +18,8 @@ void decode_eacs_ima(VGMSTREAM * stream, sample * outbuf, int channelspacing, in
|
||||
|
||||
void decode_ima(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);
|
||||
|
||||
void decode_ngc_afc(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
|
||||
void decode_ngc_dsp(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
|
@ -64,6 +64,65 @@ void decode_nds_ima(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspaci
|
||||
stream->adpcm_step_index = step_index;
|
||||
}
|
||||
|
||||
/* Xbox IMA is MS IMA, but I'll leave it alone for now (esp as it has > 2 channel support) */
|
||||
void decode_ms_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,stream->streamfile);
|
||||
step_index = read_16bitLE(offset+channel*4+2,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/8*4*vgmstream->channels) + (i%8)/2 + 4*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;
|
||||
|
@ -108,6 +108,9 @@ VGMSTREAM * init_vgmstream_genh(STREAMFILE *streamFile) {
|
||||
case 14:
|
||||
coding = coding_PSX_badflags;
|
||||
break;
|
||||
case 15:
|
||||
coding = coding_MS_IMA;
|
||||
break;
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
@ -184,6 +187,10 @@ VGMSTREAM * init_vgmstream_genh(STREAMFILE *streamFile) {
|
||||
vgmstream->layout_type = layout_none;
|
||||
}
|
||||
break;
|
||||
case coding_MS_IMA:
|
||||
vgmstream->interleave_block_size = interleave;
|
||||
vgmstream->layout_type = layout_none;
|
||||
break;
|
||||
case coding_MSADPCM:
|
||||
if (channel_count != 2) goto fail;
|
||||
vgmstream->interleave_block_size = interleave;
|
||||
@ -260,6 +267,7 @@ VGMSTREAM * init_vgmstream_genh(STREAMFILE *streamFile) {
|
||||
break;
|
||||
case coding_XBOX:
|
||||
case coding_MSADPCM:
|
||||
case coding_MS_IMA:
|
||||
/* xbox's "interleave" is a lie, all channels start at same
|
||||
* offset */
|
||||
chstreamfile =
|
||||
|
@ -88,6 +88,7 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
||||
off_t file_size = -1;
|
||||
int channel_count = 0;
|
||||
int sample_count = 0;
|
||||
int fact_sample_count = -1;
|
||||
int sample_rate = 0;
|
||||
int coding_type = -1;
|
||||
off_t start_offset = -1;
|
||||
@ -100,6 +101,7 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
||||
off_t loop_end_offset = -1;
|
||||
uint32_t riff_size;
|
||||
uint32_t data_size = 0;
|
||||
uint32_t block_size = 0;
|
||||
|
||||
int FormatChunkFound = 0;
|
||||
int DataChunkFound = 0;
|
||||
@ -151,6 +153,7 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
||||
|
||||
sample_rate = read_32bitLE(current_chunk+0x0c,streamFile);
|
||||
channel_count = read_16bitLE(current_chunk+0x0a,streamFile);
|
||||
block_size = read_16bitLE(current_chunk+0x14,streamFile);
|
||||
|
||||
switch (read_16bitLE(current_chunk+0x8,streamFile)) {
|
||||
case 1: /* PCM */
|
||||
@ -167,6 +170,13 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
case 0x11: /* MS IMA ADCM */
|
||||
/* ensure 4bps */
|
||||
if (read_16bitLE(current_chunk+0x16,streamFile)!=4)
|
||||
goto fail;
|
||||
coding_type = coding_MS_IMA;
|
||||
interleave = 0;
|
||||
break;
|
||||
case 0x555: /* Level-5 0x555 ADPCM */
|
||||
if (!mwv) goto fail;
|
||||
coding_type = coding_L5_555;
|
||||
@ -226,6 +236,10 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
||||
}
|
||||
mwv_ctrl_offset = current_chunk;
|
||||
break;
|
||||
case 0x66616374: /* fact */
|
||||
if (chunk_size != 4) break;
|
||||
fact_sample_count = read_32bitLE(current_chunk+8, streamFile);
|
||||
break;
|
||||
default:
|
||||
/* ignorance is bliss */
|
||||
break;
|
||||
@ -247,6 +261,10 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
||||
case coding_L5_555:
|
||||
sample_count = data_size/0x12/channel_count*32;
|
||||
break;
|
||||
case coding_MS_IMA:
|
||||
sample_count = (data_size / block_size) * (block_size - 4 * channel_count) * 2 / channel_count +
|
||||
((data_size % block_size) ? (data_size % block_size - 4 * channel_count) * 2 / channel_count : 0);
|
||||
break;
|
||||
}
|
||||
|
||||
/* build the VGMSTREAM */
|
||||
@ -259,12 +277,15 @@ VGMSTREAM * init_vgmstream_riff(STREAMFILE *streamFile) {
|
||||
vgmstream->sample_rate = sample_rate;
|
||||
|
||||
vgmstream->coding_type = coding_type;
|
||||
if (channel_count > 1 && coding_type != coding_PCM8_U_int)
|
||||
if (channel_count > 1 && coding_type != coding_PCM8_U_int && coding_type != coding_MS_IMA)
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
else
|
||||
vgmstream->layout_type = layout_none;
|
||||
vgmstream->interleave_block_size = interleave;
|
||||
|
||||
if (coding_type == coding_MS_IMA)
|
||||
vgmstream->interleave_block_size = block_size;
|
||||
|
||||
if (loop_flag) {
|
||||
if (loop_start_ms >= 0)
|
||||
{
|
||||
|
@ -680,6 +680,8 @@ int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream) {
|
||||
return vgmstream->ws_output_size;
|
||||
case coding_MSADPCM:
|
||||
return (vgmstream->interleave_block_size-(7-1)*vgmstream->channels)*2/vgmstream->channels;
|
||||
case coding_MS_IMA:
|
||||
return (vgmstream->interleave_block_size-4*vgmstream->channels)*2/vgmstream->channels;
|
||||
case coding_NDS_PROCYON:
|
||||
return 30;
|
||||
default:
|
||||
@ -721,6 +723,7 @@ int get_vgmstream_frame_size(VGMSTREAM * vgmstream) {
|
||||
case coding_NWA4:
|
||||
case coding_NWA5:
|
||||
return 1;
|
||||
case coding_MS_IMA:
|
||||
case coding_NDS_IMA:
|
||||
return vgmstream->interleave_block_size;
|
||||
case coding_NGC_DTK:
|
||||
@ -872,6 +875,13 @@ void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to
|
||||
vgmstream->channels,vgmstream->samples_into_block,
|
||||
samples_to_do,chan);
|
||||
}
|
||||
break;
|
||||
case coding_MS_IMA:
|
||||
for (chan=0;chan<vgmstream->channels;chan++) {
|
||||
decode_ms_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++) {
|
||||
@ -1319,6 +1329,9 @@ void describe_vgmstream(VGMSTREAM * vgmstream, char * desc, int length) {
|
||||
case coding_IMA:
|
||||
snprintf(temp,TEMPSIZE,"4-bit IMA ADPCM");
|
||||
break;
|
||||
case coding_MS_IMA:
|
||||
snprintf(temp,TEMPSIZE,"Microsoft 4-bit IMA ADPCM");
|
||||
break;
|
||||
case coding_WS:
|
||||
snprintf(temp,TEMPSIZE,"Westwood Studios DPCM");
|
||||
break;
|
||||
|
@ -70,6 +70,7 @@ typedef enum {
|
||||
coding_EACS_IMA,
|
||||
coding_IMA, /* bare IMA, low nibble first */
|
||||
coding_INT_IMA, /* */
|
||||
coding_MS_IMA, /* Microsoft IMA */
|
||||
coding_WS, /* Westwood Studios' custom VBR ADPCM */
|
||||
#ifdef VGM_USE_MPEG
|
||||
coding_fake_MPEG2_L2, /* MPEG-2 Layer 2 (AHX), with lying headers */
|
||||
|
Loading…
x
Reference in New Issue
Block a user