Merge pull request #550 from bnnm/adp

adp
This commit is contained in:
bnnm 2020-01-13 21:55:42 +01:00 committed by GitHub
commit e58c73aab1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 281 additions and 273 deletions

View File

@ -20,7 +20,7 @@ void decode_wv6_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspa
void decode_alp_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
void decode_ffta2_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
void decode_blitz_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
void decode_mtf_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
void decode_mtf_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel, int is_stereo);
void decode_ms_ima(VGMSTREAM * vgmstream,VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do,int channel);
void decode_ref_ima(VGMSTREAM * vgmstream, VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do,int channel);

View File

@ -318,7 +318,7 @@ void decode_standard_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int chann
stream->adpcm_step_index = step_index;
}
void decode_mtf_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
void decode_mtf_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel, int is_stereo) {
int i, sample_count = 0;
int32_t hist1 = stream->adpcm_history1_32;
int step_index = stream->adpcm_step_index;
@ -331,8 +331,12 @@ void decode_mtf_ima(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspa
/* decode nibbles (layout: varies) */
for (i = first_sample; i < first_sample + samples_to_do; i++, sample_count += channelspacing) {
off_t byte_offset = stream->offset + i/2;
int nibble_shift = ((i&1) ? 0:4);
off_t byte_offset = is_stereo ?
stream->offset + i : /* stereo: one nibble per channel */
stream->offset + i/2; /* mono: consecutive nibbles */
int nibble_shift = is_stereo ?
((channel&1) ? 0:4) :
((i&1) ? 0:4);
mtf_ima_expand_nibble(stream, byte_offset,nibble_shift, &hist1, &step_index);
outbuf[sample_count] = clamp16(hist1 >> 4);

View File

@ -28,7 +28,7 @@ static void yamaha_adpcmb_expand_nibble(VGMSTREAMCHANNEL * stream, off_t byte_of
delta = -delta;
sample = *hist1 + delta;
sample = clamp16(sample); /* this may not be needed (not done in Aska) but no byte changes */
sample = clamp16(sample); /* not needed in Aska but seems others do */
*step_size = ((*step_size) * scale_step_adpcmb[code]) >> 6;
if (*step_size < 0x7f) *step_size = 0x7f;
@ -150,13 +150,14 @@ void decode_aska(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacin
}
/* Yamaha ADPCM with unknown expand variation (noisy), step size is double of normal Yamaha? */
/* NXAP ADPCM, Yamaha ADPCM-B with weird headered frames */
void decode_nxap(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
int i, sample_count = 0, num_frame;
int32_t hist1 = stream->adpcm_history1_32;
int step_size = stream->adpcm_step_index;
int16_t out_sample;
/* external interleave */
/* external interleave, mono */
int block_samples = (0x40 - 0x4) * 2;
num_frame = first_sample / block_samples;
first_sample = first_sample % block_samples;
@ -165,29 +166,20 @@ void decode_nxap(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacin
if (first_sample == 0) {
off_t header_offset = stream->offset + 0x40*num_frame;
hist1 = read_16bitLE(header_offset+0x00,stream->streamfile);
step_size = read_16bitLE(header_offset+0x02,stream->streamfile);
hist1 = read_s16le(header_offset+0x00,stream->streamfile);
step_size = read_u16le(header_offset+0x02,stream->streamfile) >> 1; /* remove lower bit, also note unsignedness */
if (step_size < 0x7f) step_size = 0x7f;
else if (step_size > 0x6000) step_size = 0x6000;
/* step's lower bit is hist1 sign (useless), and code doesn't seem to do anything useful with it? */
}
/* decode nibbles (layout: all nibbles from one channel) */
for (i = first_sample; i < first_sample + samples_to_do; i++) {
int code, delta, sample;
off_t byte_offset = (stream->offset + 0x40*num_frame + 0x04) + i/2;
int nibble_shift = (i&1?4:0); /* low nibble first? */
code = (read_8bit(byte_offset,stream->streamfile) >> nibble_shift)&0xf;
delta = (step_size * scale_delta[code]) / 8; //todo wrong
sample = hist1 + delta;
outbuf[sample_count] = clamp16(sample);
hist1 = outbuf[sample_count];
step_size = (step_size * scale_step_aica[code]) / 260.0; //todo wrong
if (step_size < 0x7f) step_size = 0x7f;
else if (step_size > 0x6000) step_size = 0x6000;
int nibble_shift = (i&1?0:4);
yamaha_adpcmb_expand_nibble(stream, byte_offset, nibble_shift, &hist1, &step_size, &out_sample);
outbuf[sample_count] = out_sample;
sample_count += channelspacing;
}

View File

@ -4,40 +4,51 @@
/* FWSE - Capcom's MT Framework V1.x sound file */
VGMSTREAM *init_vgmstream_fwse(STREAMFILE *streamFile) {
VGMSTREAM *vgmstream = NULL;
uint32_t version, /*file_size,*/ buffer_offset,
channel_count, sample_count, sample_rate;
uint32_t version, /*data_size,*/ buffer_offset;
int channel_count, loop_flag, sample_count, sample_rate, loop_start, loop_end;
/* checks*/
/* .fwse: header id, no apparent extension in bigfiles */
if (!check_extensions(streamFile,"fwse"))
goto fail;
if ((read_32bitLE(0x00,streamFile)) != 0x45535746)
if ((read_32bitBE(0x00,streamFile)) != 0x46575345) /* "FWSE" */
goto fail;
version = read_32bitLE(0x04,streamFile);
if (version != 2)
/* v2: Resident Evil 5 (PC)
* v3: Ace Attourney: Dual Destinies (Android) */
if (version != 2 && version != 3)
goto fail;
//file_size = read_32bitLE(0x08,streamFile);
//data_size = read_32bitLE(0x08,streamFile);
buffer_offset = read_32bitLE(0x0C,streamFile);
channel_count = read_32bitLE(0x10,streamFile);
if (channel_count > 1)
if (channel_count > 2)
goto fail;
sample_count = read_32bitLE(0x14,streamFile);
sample_rate = read_32bitLE(0x18,streamFile);
loop_start = read_32bitLE(0x20,streamFile);
loop_end = read_32bitLE(0x24,streamFile);
loop_flag = (loop_start != -1);
/* 0x28: some kind of setup? */
/* 0x40: some kind of seek table with ADPCM hist/steps? */
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, 0);
vgmstream = allocate_vgmstream(channel_count, loop_flag);
if (!vgmstream) goto fail;
vgmstream->meta_type = meta_FWSE;
vgmstream->sample_rate = sample_rate;
vgmstream->num_samples = sample_count;
vgmstream->loop_start_sample = loop_start;
vgmstream->loop_end_sample = loop_end;
vgmstream->coding_type = coding_MTF_IMA;
vgmstream->layout_type = channel_count == 1 ? layout_none : layout_interleave;
vgmstream->interleave_block_size = 1;
vgmstream->layout_type = layout_none;
if (!vgmstream_open_stream(vgmstream,streamFile,buffer_offset))

View File

@ -19,7 +19,7 @@ VGMSTREAM * init_vgmstream_nxap(STREAMFILE *streamFile) {
start_offset = read_32bitLE(0x04,streamFile);
channel_count = read_32bitLE(0x0c,streamFile);
loop_flag = 0; //(read_32bitLE(0x24,streamFile) > 0); //todo
loop_flag = (read_32bitLE(0x24,streamFile) > 0);
/* build the VGMSTREAM */
@ -29,10 +29,9 @@ VGMSTREAM * init_vgmstream_nxap(STREAMFILE *streamFile) {
vgmstream->sample_rate = read_32bitLE(0x10, streamFile);
vgmstream->num_samples = read_32bitLE(0x1c,streamFile) * (0x40-0x04)*2 / channel_count; /* number of frames */
/* unknown loop format, also 0x28/2c values seem related */
//vgmstream->loop_start_sample = read_32bitLE(0x20,streamFile) * (0x40-0x04)*2 / channel_count;
//vgmstream->loop_end_sample = read_32bitLE(0x24,streamFile) * (0x40-0x04)*2 / channel_count;
//vgmstream->loop_end_sample = vgmstream->loop_start_sample + vgmstream->loop_end_sample;
/* in channel blocks, also 0x28/2c values seem related */
vgmstream->loop_start_sample = read_32bitLE(0x20,streamFile) * (0x40-0x04)*2;
vgmstream->loop_end_sample = read_32bitLE(0x24,streamFile) * (0x40-0x04)*2;
vgmstream->meta_type = meta_NXAP;
vgmstream->coding_type = coding_NXAP;

View File

@ -1846,8 +1846,10 @@ void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to
break;
case coding_MTF_IMA:
for (ch = 0; ch < vgmstream->channels; ch++) {
int is_stereo = (vgmstream->channels > 1);
decode_mtf_ima(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
vgmstream->channels,vgmstream->samples_into_block,samples_to_do);
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch,
is_stereo);
}
break;
case coding_3DS_IMA: