aacenc: new default cutoff
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 29 Jul 2012 17:49:22 +0000 (19:49 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 29 Jul 2012 20:02:46 +0000 (22:02 +0200)
Improves subjective quality

Formula and testing by: kamedo2 <fujisakihir90@yahoo.co.jp>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/aacpsy.c
libavcodec/psymodel.c
libavcodec/psymodel.h

index 585a249..a9a8988 100644 (file)
@@ -292,7 +292,7 @@ static av_cold int psy_3gpp_init(FFPsyContext *ctx) {
     int i, j, g, start;
     float prev, minscale, minath, minsnr, pe_min;
     const int chan_bitrate = ctx->avctx->bit_rate / ctx->avctx->channels;
-    const int bandwidth    = ctx->avctx->cutoff ? ctx->avctx->cutoff : ctx->avctx->sample_rate / 2;
+    const int bandwidth    = ctx->avctx->cutoff ? ctx->avctx->cutoff : AAC_CUTOFF(ctx->avctx);
     const float num_bark   = calc_bark((float)bandwidth);
 
     ctx->model_priv_data = av_mallocz(sizeof(AacPsyContext));
index a17aecc..bdd2509 100644 (file)
@@ -100,6 +100,9 @@ av_cold struct FFPsyPreprocessContext* ff_psy_preprocess_init(AVCodecContext *av
     if (avctx->cutoff > 0)
         cutoff_coeff = 2.0 * avctx->cutoff / avctx->sample_rate;
 
+    if (!cutoff_coeff && avctx->codec_id == CODEC_ID_AAC)
+        cutoff_coeff = 2.0 * AAC_CUTOFF(avctx) / avctx->sample_rate;
+
     if (cutoff_coeff)
     ctx->fcoeffs = ff_iir_filter_init_coeffs(avctx, FF_FILTER_TYPE_BUTTERWORTH,
                                              FF_FILTER_MODE_LOWPASS, FILT_ORDER,
index 317974b..37c8191 100644 (file)
@@ -29,6 +29,8 @@
 /** maximum number of channels */
 #define PSY_MAX_CHANS 20
 
+#define AAC_CUTOFF(s) (s->bit_rate ? FFMIN3(4000 + s->bit_rate/8, 12000 + s->bit_rate/32, s->sample_rate / 2) : (s->sample_rate / 2))
+
 /**
  * single band psychoacoustic information
  */