]> git.sesse.net Git - ffmpeg/commitdiff
use cutoff frequency to adjust bandwidth in ac3 encoder
authorJustin Ruggles <justin.ruggles@gmail.com>
Fri, 28 Dec 2007 06:13:55 +0000 (06:13 +0000)
committerJustin Ruggles <justin.ruggles@gmail.com>
Fri, 28 Dec 2007 06:13:55 +0000 (06:13 +0000)
Originally committed as revision 11338 to svn://svn.ffmpeg.org/ffmpeg/trunk

libavcodec/ac3enc.c
libavcodec/avcodec.h

index e84b220dc8e0d3cfd08cf499491d49eec508a6c6..4ed58e7e848dc449c39e8791f0f275c9e923a894 100644 (file)
@@ -632,6 +632,7 @@ static int AC3_encode_init(AVCodecContext *avctx)
     AC3EncodeContext *s = avctx->priv_data;
     int i, j, ch;
     float alpha;
+    int bw_code;
     static const uint8_t channel_mode_defs[6] = {
         0x01, /* C */
         0x02, /* L R */
@@ -683,12 +684,21 @@ static int AC3_encode_init(AVCodecContext *avctx)
     s->frame_size = s->frame_size_min;
 
     /* bit allocation init */
-    for(ch=0;ch<s->nb_channels;ch++) {
-        /* bandwidth for each channel */
+    if(avctx->cutoff) {
+        /* calculate bandwidth based on user-specified cutoff frequency */
+        int cutoff = av_clip(avctx->cutoff, 1, s->sample_rate >> 1);
+        int fbw_coeffs = cutoff * 512 / s->sample_rate;
+        bw_code = av_clip((fbw_coeffs - 73) / 3, 0, 60);
+    } else {
+        /* use default bandwidth setting */
         /* XXX: should compute the bandwidth according to the frame
            size, so that we avoid anoying high freq artefacts */
-        s->chbwcod[ch] = 50; /* sample bandwidth as mpeg audio layer 2 table 0 */
-        s->nb_coefs[ch] = ((s->chbwcod[ch] + 12) * 3) + 37;
+        bw_code = 50;
+    }
+    for(ch=0;ch<s->nb_channels;ch++) {
+        /* bandwidth for each channel */
+        s->chbwcod[ch] = bw_code;
+        s->nb_coefs[ch] = bw_code * 3 + 73;
     }
     if (s->lfe) {
         s->nb_coefs[s->lfe_channel] = 7; /* fixed */
index 95ed9e6b01a4910ddc304e190b061889bf8b53c7..3e6204e248e5957073ec810e45961df0b2f4ab95 100644 (file)
@@ -2072,7 +2072,7 @@ typedef struct AVCodecContext {
     int directpred;
 
     /**
-     * Audio cutoff bandwidth (0 means "automatic"), currently used only by FAAC.
+     * Audio cutoff bandwidth (0 means "automatic")
      * - encoding: Set by user.
      * - decoding: unused
      */