From c5eec1554942ef99bcf6b2065008fd3730121ec9 Mon Sep 17 00:00:00 2001 From: nu774 Date: Wed, 30 Oct 2013 01:32:52 +0900 Subject: [PATCH] prepend 1 sample zero padding in case of SBR and enc_delay is odd This is required because odd enc_delay cannot be exactly expressed in downsampled scale, and HE-AACv2 FDK encoder actually has odd enc_delay. --- src/main.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main.c b/src/main.c index d06c683..7d1a68f 100644 --- a/src/main.c +++ b/src/main.c @@ -823,6 +823,16 @@ int main(int argc, char **argv) m4af_set_priming_mode(m4af, params.gapless_mode + 1); m4af_begin_write(m4af); } + if (sbr_mode && (aacinfo.encoderDelay & 1)) { + /* + * Since odd delay cannot be exactly expressed in downsampled scale, + * we push one zero frame to the encoder here, to make delay even + */ + int16_t zero[8] = { 0 }; + aacenc_result_t obuf = { 0 }; + aac_encode_frame(encoder, sample_format, zero, 1, &obuf); + free(obuf.data); + } frame_count = encode(¶ms, reader, encoder, aacinfo.frameLength, m4af); if (frame_count < 0) goto END; -- 2.30.2