Fix tri-Ace Aska ADPCM .aac [Star Ocean Anamnesis (Mobile)]

This commit is contained in:
bnnm 2019-03-02 21:12:00 +01:00
parent 051cad9462
commit 0c39f4cf09
6 changed files with 30 additions and 24 deletions

View File

@ -129,9 +129,9 @@ void decode_msadpcm_ck(VGMSTREAM * vgmstream, sample * outbuf, int channelspacin
long msadpcm_bytes_to_samples(long bytes, int block_size, int channels); long msadpcm_bytes_to_samples(long bytes, int block_size, int channels);
/* yamaha_decoder */ /* yamaha_decoder */
void decode_aica(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel, int is_stereo); void decode_aica(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel, int is_stereo);
void decode_yamaha(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel); void decode_aska(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel);
void decode_yamaha_nxap(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do); void decode_yamaha_nxap(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
size_t aica_bytes_to_samples(size_t bytes, int channels); size_t aica_bytes_to_samples(size_t bytes, int channels);
size_t yamaha_bytes_to_samples(size_t bytes, int channels); size_t yamaha_bytes_to_samples(size_t bytes, int channels);

View File

@ -8,6 +8,11 @@ static const unsigned int scale_step[16] = {
230, 230, 230, 230, 307, 409, 512, 614 230, 230, 230, 230, 307, 409, 512, 614
}; };
/* actually implemented with if-else/switchs but that's too goofy */
static const int scale_step_aska[8] = {
57, 57, 57, 57, 77, 102, 128, 153,
};
/* expand an unsigned four bit delta to a wider signed range */ /* expand an unsigned four bit delta to a wider signed range */
static const int scale_delta[16] = { static const int scale_delta[16] = {
1, 3, 5, 7, 9, 11, 13, 15, 1, 3, 5, 7, 9, 11, 13, 15,
@ -16,7 +21,7 @@ static const int scale_delta[16] = {
/* raw Yamaha ADPCM a.k.a AICA as it's mainly used in Naomi/Dreamcast (also in RIFF and older arcade sound chips). */ /* raw Yamaha ADPCM a.k.a AICA as it's mainly used in Naomi/Dreamcast (also in RIFF and older arcade sound chips). */
void decode_aica(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel, int is_stereo) { void decode_aica(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; int i, sample_count;
int32_t hist1 = stream->adpcm_history1_16; int32_t hist1 = stream->adpcm_history1_16;
@ -52,9 +57,8 @@ void decode_aica(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing,
stream->adpcm_step_index = step_size; stream->adpcm_step_index = step_size;
} }
/* Yamaha ADPCM, in headered frames like MS-IMA. Possibly originated from Yamaha's SMAF tools /* tri-Ace Aska ADPCM, same-ish with modified step table (reversed from Android SO's .so) */
* (Windows ACM encoder/decoder was given in their site). Some info from Rockbox's yamaha_adpcm.c */ void decode_aska(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel) {
void decode_yamaha(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel) {
int i, sample_count, num_frame; int i, sample_count, num_frame;
int32_t hist1 = stream->adpcm_history1_32; int32_t hist1 = stream->adpcm_history1_32;
int step_size = stream->adpcm_step_index; int step_size = stream->adpcm_step_index;
@ -84,15 +88,15 @@ void decode_yamaha(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacin
(!(channel&1) ? 0:4) : (!(channel&1) ? 0:4) :
(!(i&1) ? 0:4); /* even = low, odd = high */ (!(i&1) ? 0:4); /* even = low, odd = high */
/* Yamaha/AICA expand, but same result as IMA's (((delta * 2 + 1) * step) >> 3) */ sample_nibble = (read_8bit(byte_offset,stream->streamfile) >> nibble_shift) & 0xf;
sample_nibble = (read_8bit(byte_offset,stream->streamfile) >> nibble_shift)&0xf; sample_delta = ((((sample_nibble & 0x7) * 2) | 1) * step_size) >> 3; /* like 'mul' IMA with 'or' */
sample_delta = (step_size * scale_delta[sample_nibble]) / 8; if (sample_nibble & 8) sample_delta = -sample_delta;
sample_decoded = hist1 + sample_delta; sample_decoded = hist1 + sample_delta;
outbuf[sample_count] = clamp16(sample_decoded); outbuf[sample_count] = sample_decoded; /* not clamped */
hist1 = outbuf[sample_count]; hist1 = outbuf[sample_count];
step_size = (step_size * scale_step[sample_nibble]) >> 8; step_size = (step_size * scale_step_aska[sample_nibble & 0x07]) >> 6;
if (step_size < 0x7f) step_size = 0x7f; if (step_size < 0x7f) step_size = 0x7f;
if (step_size > 0x6000) step_size = 0x6000; if (step_size > 0x6000) step_size = 0x6000;
} }
@ -102,7 +106,7 @@ void decode_yamaha(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacin
} }
/* Yamaha ADPCM with unknown expand variation (noisy), step size is double of normal Yamaha? */ /* Yamaha ADPCM with unknown expand variation (noisy), step size is double of normal Yamaha? */
void decode_yamaha_nxap(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) { void decode_yamaha_nxap(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do) {
int i, sample_count, num_frame; int i, sample_count, num_frame;
int32_t hist1 = stream->adpcm_history1_32; int32_t hist1 = stream->adpcm_history1_32;
int step_size = stream->adpcm_step_index; int step_size = stream->adpcm_step_index;

View File

@ -634,7 +634,7 @@ static const coding_info coding_info_list[] = {
{coding_WS, "Westwood Studios VBR ADPCM"}, {coding_WS, "Westwood Studios VBR ADPCM"},
{coding_AICA, "Yamaha 4-bit ADPCM"}, {coding_AICA, "Yamaha 4-bit ADPCM"},
{coding_AICA_int, "Yamaha 4-bit ADPCM (mono/interleave)"}, {coding_AICA_int, "Yamaha 4-bit ADPCM (mono/interleave)"},
{coding_YAMAHA, "Yamaha 4-bit ADPCM (framed)"}, {coding_ASKA, "tri-Ace Aska 4-bit ADPCM"},
{coding_YAMAHA_NXAP, "Yamaha NXAP 4-bit ADPCM"}, {coding_YAMAHA_NXAP, "Yamaha NXAP 4-bit ADPCM"},
{coding_NDS_PROCYON, "Procyon Studio Digital Sound Elements NDS 4-bit APDCM"}, {coding_NDS_PROCYON, "Procyon Studio Digital Sound Elements NDS 4-bit APDCM"},
{coding_L5_555, "Level-5 0x555 4-bit ADPCM"}, {coding_L5_555, "Level-5 0x555 4-bit ADPCM"},

View File

@ -1,7 +1,7 @@
#include "meta.h" #include "meta.h"
#include "../coding/coding.h" #include "../coding/coding.h"
/* AAC - Tri-Ace Audio Container */ /* AAC - tri-Ace (Aska engine) Audio Container */
/* Xbox 360 Variants (Star Ocean 4, End of Eternity, Infinite Undiscovery) */ /* Xbox 360 Variants (Star Ocean 4, End of Eternity, Infinite Undiscovery) */
VGMSTREAM * init_vgmstream_ta_aac_x360(STREAMFILE *streamFile) { VGMSTREAM * init_vgmstream_ta_aac_x360(STREAMFILE *streamFile) {
@ -297,7 +297,7 @@ VGMSTREAM * init_vgmstream_ta_aac_mobile(STREAMFILE *streamFile) {
if (read_32bitLE(0x148, streamFile) != (0x40-0x04*channel_count)*2 / channel_count) goto fail; /* frame samples */ if (read_32bitLE(0x148, streamFile) != (0x40-0x04*channel_count)*2 / channel_count) goto fail; /* frame samples */
if (channel_count > 2) goto fail; /* unknown data layout */ if (channel_count > 2) goto fail; /* unknown data layout */
vgmstream->coding_type = coding_YAMAHA; vgmstream->coding_type = coding_ASKA;
vgmstream->layout_type = layout_none; vgmstream->layout_type = layout_none;
vgmstream->num_samples = yamaha_bytes_to_samples(data_size, channel_count); vgmstream->num_samples = yamaha_bytes_to_samples(data_size, channel_count);

View File

@ -1218,7 +1218,7 @@ int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream) {
return 1; return 1;
case coding_AICA_int: case coding_AICA_int:
return 2; return 2;
case coding_YAMAHA: case coding_ASKA:
return (0x40-0x04*vgmstream->channels) * 2 / vgmstream->channels; return (0x40-0x04*vgmstream->channels) * 2 / vgmstream->channels;
case coding_YAMAHA_NXAP: case coding_YAMAHA_NXAP:
return (0x40-0x04) * 2; return (0x40-0x04) * 2;
@ -1405,7 +1405,7 @@ int get_vgmstream_frame_size(VGMSTREAM * vgmstream) {
case coding_AICA: case coding_AICA:
case coding_AICA_int: case coding_AICA_int:
return 0x01; return 0x01;
case coding_YAMAHA: case coding_ASKA:
case coding_YAMAHA_NXAP: case coding_YAMAHA_NXAP:
return 0x40; return 0x40;
case coding_NDS_PROCYON: case coding_NDS_PROCYON:
@ -2001,9 +2001,9 @@ void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to
is_stereo); is_stereo);
} }
break; break;
case coding_YAMAHA: case coding_ASKA:
for (ch = 0; ch < vgmstream->channels; ch++) { for (ch = 0; ch < vgmstream->channels; ch++) {
decode_yamaha(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch, decode_aska(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch); vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
} }
break; break;

View File

@ -148,10 +148,12 @@ typedef enum {
coding_MSADPCM_int, /* Microsoft ADPCM (mono) */ coding_MSADPCM_int, /* Microsoft ADPCM (mono) */
coding_MSADPCM_ck, /* Microsoft ADPCM (Cricket Audio variation) */ coding_MSADPCM_ck, /* Microsoft ADPCM (Cricket Audio variation) */
coding_WS, /* Westwood Studios VBR ADPCM */ coding_WS, /* Westwood Studios VBR ADPCM */
coding_AICA, /* Yamaha AICA ADPCM (stereo) */
coding_AICA_int, /* Yamaha AICA ADPCM (mono/interleave) */ coding_AICA, /* Yamaha ADPCM (stereo) */
coding_YAMAHA, /* Yamaha ADPCM */ coding_AICA_int, /* Yamaha ADPCM (mono/interleave) */
coding_YAMAHA_NXAP, /* Yamaha ADPCM (NXAP variation) */ coding_ASKA, /* Aska ADPCM */
coding_YAMAHA_NXAP, /* NXAP ADPCM */
coding_NDS_PROCYON, /* Procyon Studio ADPCM */ coding_NDS_PROCYON, /* Procyon Studio ADPCM */
coding_L5_555, /* Level-5 0x555 ADPCM */ coding_L5_555, /* Level-5 0x555 ADPCM */
coding_LSF, /* lsf ADPCM (Fastlane Street Racing iPhone)*/ coding_LSF, /* lsf ADPCM (Fastlane Street Racing iPhone)*/