diff --git a/src/coding/mp4_aac_decoder.c b/src/coding/mp4_aac_decoder.c index 4a3a6aff..983c865d 100644 --- a/src/coding/mp4_aac_decoder.c +++ b/src/coding/mp4_aac_decoder.c @@ -1,5 +1,15 @@ #include "../vgmstream.h" +static void convert_samples(INT_PCM * src, sample * dest, int32_t count) { + int32_t i; + for ( i = 0; i < count; i++ ) { + INT_PCM sample = *src++; + sample >>= SAMPLE_BITS - 16; + if ( ( sample + 0x8000 ) & 0xFFFF0000 ) sample = 0x7FFF ^ ( sample >> 31 ); + *dest++ = sample; + } +} + void decode_mp4_aac(mp4_aac_codec_data * data, sample * outbuf, int32_t samples_to_do, int channels) { int samples_done = 0; @@ -25,7 +35,7 @@ void decode_mp4_aac(mp4_aac_codec_data * data, sample * outbuf, int32_t samples_ if ( samples_remain > samples_to_do ) samples_remain = samples_to_do; - memcpy( outbuf, data->sample_buffer + data->sample_ptr * stream_info->numChannels, samples_remain * stream_info->numChannels * sizeof(short) ); + convert_samples( data->sample_buffer + data->sample_ptr * stream_info->numChannels, outbuf, samples_remain * stream_info->numChannels ); outbuf += samples_remain * stream_info->numChannels; @@ -61,7 +71,7 @@ void decode_mp4_aac(mp4_aac_codec_data * data, sample * outbuf, int32_t samples_ } } if ( samples_remain > samples_to_do - samples_done ) samples_remain = samples_to_do - samples_done; - memcpy( outbuf, data->sample_buffer + data->sample_ptr * stream_info->numChannels, samples_remain * stream_info->numChannels * sizeof(short) ); + convert_samples( data->sample_buffer + data->sample_ptr * stream_info->numChannels, outbuf, samples_remain * stream_info->numChannels ); samples_done += samples_remain; outbuf += samples_remain * stream_info->numChannels; data->sample_ptr = samples_remain;