commit 8bbdd20a293eab2cfac9f332613ead02a4e3c0c2 Author: Claudio Freire Date: Sun May 12 09:38:40 2013 +0200 aacenc: Fix erasure of surround channels This was due to a miscomputation of s->cur_channel, which led to psy-based encoders using the psy coefficients for the wrong channel. Signed-off-by: Martin Storsjö diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index 60eca59..b2ad47b 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -597,7 +597,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, coeffs[ch] = cpe->ch[ch].coeffs; s->psy.model->analyze(&s->psy, start_ch, coeffs, wi); for (ch = 0; ch < chans; ch++) { - s->cur_channel = start_ch * 2 + ch; + s->cur_channel = start_ch + ch; s->coder->search_for_quantizers(avctx, s, &cpe->ch[ch], s->lambda); } cpe->common_window = 0; @@ -613,7 +613,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } } } - s->cur_channel = start_ch * 2; + s->cur_channel = start_ch; if (s->options.stereo_mode && cpe->common_window) { if (s->options.stereo_mode > 0) { IndividualChannelStream *ics = &cpe->ch[0].ics; commit f4d0a63b5b5c682c18df3bba730f97a9067408ba Author: Claudio Freire Date: Sat May 4 18:36:37 2013 -0300 aacenc: Fix target bitrate for twoloop quantiser search This fixes a case where multichannel bitrate isn't accurately targetted by psy model alone, never achieving the target bitrate. Signed-off-by: Martin Storsjö diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c index d65d8d9..35b98a9 100644 --- a/libavcodec/aaccoder.c +++ b/libavcodec/aaccoder.c @@ -710,7 +710,7 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx, const float lambda) { int start = 0, i, w, w2, g; - int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels; + int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels * (lambda / 120.f); float dists[128] = { 0 }, uplims[128]; float maxvals[128]; int fflag, minscaler; commit 7c71ada4cad3c6aab5fa24155c379465c41cfd76 Author: Claudio Freire Date: Sat May 4 18:35:49 2013 -0300 aacenc: Fix a rounding bug in aacpsy channel bitrate computation Signed-off-by: Martin Storsjö diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c index 6f1ac05..66cf6d5 100644 --- a/libavcodec/aacpsy.c +++ b/libavcodec/aacpsy.c @@ -312,7 +312,7 @@ static av_cold int psy_3gpp_init(FFPsyContext *ctx) { AacPsyCoeffs *coeffs = pctx->psy_coef[j]; const uint8_t *band_sizes = ctx->bands[j]; float line_to_frequency = ctx->avctx->sample_rate / (j ? 256.f : 2048.0f); - float avg_chan_bits = chan_bitrate / ctx->avctx->sample_rate * (j ? 128.0f : 1024.0f); + float avg_chan_bits = chan_bitrate * (j ? 128.0f : 1024.0f) / ctx->avctx->sample_rate; /* reference encoder uses 2.4% here instead of 60% like the spec says */ float bark_pe = 0.024f * PSY_3GPP_BITS_TO_PE(avg_chan_bits) / num_bark; float en_spread_low = j ? PSY_3GPP_EN_SPREAD_LOW_S : PSY_3GPP_EN_SPREAD_LOW_L;