From 3612e492b43130be53464efbd26483b4ec86b768 Mon Sep 17 00:00:00 2001 From: Dima Date: Tue, 17 Sep 2019 13:28:31 +0300 Subject: [PATCH] aac-dec: save to 32-bit wav if aac: INT_PCM==LONG (SAMPLE_BITS==32) --- aac-dec.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/aac-dec.c b/aac-dec.c index 3da70a3..84b1715 100644 --- a/aac-dec.c +++ b/aac-dec.c @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) { void *wav = NULL; int output_size; uint8_t *output_buf; - int16_t *decode_buf; + INT_PCM *decode_buf; HANDLE_AACDECODER handle; int frame_size = 0; if (argc < 3) { @@ -46,9 +46,9 @@ int main(int argc, char *argv[]) { return 1; } - output_size = 8*2*2048; + output_size = 8*sizeof(INT_PCM)*2048; output_buf = (uint8_t*) malloc(output_size); - decode_buf = (int16_t*) malloc(output_size); + decode_buf = (INT_PCM*) malloc(output_size); while (1) { uint8_t packet[10240], *ptr = packet; @@ -89,18 +89,19 @@ int main(int argc, char *argv[]) { } frame_size = info->frameSize * info->numChannels; // Note, this probably doesn't return channels > 2 in the right order for wav - wav = wav_write_open(outfile, info->sampleRate, 16, info->numChannels); + wav = wav_write_open(outfile, info->sampleRate, sizeof(INT_PCM)*8, info->numChannels); if (!wav) { perror(outfile); break; } } for (i = 0; i < frame_size; i++) { - uint8_t* out = &output_buf[2*i]; - out[0] = decode_buf[i] & 0xff; - out[1] = decode_buf[i] >> 8; + uint8_t* out = &output_buf[sizeof(INT_PCM)*i]; + unsigned j; + for (j = 0; j < sizeof(INT_PCM); j++) + out[j] = (uint8_t)(decode_buf[i] >> (8*j)); } - wav_write_data(wav, output_buf, 2*frame_size); + wav_write_data(wav, output_buf, sizeof(INT_PCM)*frame_size); } free(output_buf); free(decode_buf);