[FFmpeg-cvslog] r25984 - trunk/libavcodec/ac3enc.c

jbr subversion
Tue Dec 14 15:52:40 CET 2010


Author: jbr
Date: Tue Dec 14 15:52:40 2010
New Revision: 25984

Log:
Split setting of bandwidth into a separate function.

Modified:
   trunk/libavcodec/ac3enc.c

Modified: trunk/libavcodec/ac3enc.c
==============================================================================
--- trunk/libavcodec/ac3enc.c	Tue Dec 14 15:52:37 2010	(r25983)
+++ trunk/libavcodec/ac3enc.c	Tue Dec 14 15:52:40 2010	(r25984)
@@ -1295,12 +1295,44 @@ static av_cold int validate_options(AVCo
 
 
 /**
+ * Set bandwidth for all channels.
+ * The user can optionally supply a cutoff frequency. Otherwise an appropriate
+ * default value will be used.
+ */
+static av_cold void set_bandwidth(AC3EncodeContext *s, int cutoff)
+{
+    int ch, bw_code;
+
+    if (cutoff) {
+        /* calculate bandwidth based on user-specified cutoff frequency */
+        int fbw_coeffs;
+        cutoff         = av_clip(cutoff, 1, s->sample_rate >> 1);
+        fbw_coeffs     = cutoff * 2 * AC3_MAX_COEFS / 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 annoying high frequency artifacts */
+        bw_code = 50;
+    }
+
+    /* set number of coefficients for each channel */
+    for (ch = 0; ch < s->fbw_channels; ch++) {
+        s->bandwidth_code[ch] = bw_code;
+        s->nb_coefs[ch]       = bw_code * 3 + 73;
+    }
+    if (s->lfe_on)
+        s->nb_coefs[s->lfe_channel] = 7; /* LFE channel always has 7 coefs */
+}
+
+
+/**
  * Initialize the encoder.
  */
 static av_cold int ac3_encode_init(AVCodecContext *avctx)
 {
     AC3EncodeContext *s = avctx->priv_data;
-    int ch, bw_code, ret;
+    int ret;
 
     avctx->frame_size = AC3_FRAME_SIZE;
 
@@ -1318,25 +1350,7 @@ static av_cold int ac3_encode_init(AVCod
     s->samples_written = 0;
     s->frame_size      = s->frame_size_min;
 
-    /* set bandwidth */
-    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 * 2 * AC3_MAX_COEFS / 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 annoying high frequency artifacts */
-        bw_code = 50;
-    }
-    for (ch = 0; ch < s->fbw_channels; ch++) {
-        /* bandwidth for each channel */
-        s->bandwidth_code[ch] = bw_code;
-        s->nb_coefs[ch]       = bw_code * 3 + 73;
-    }
-    if (s->lfe_on)
-        s->nb_coefs[s->lfe_channel] = 7; /* LFE channel always has 7 coefs */
+    set_bandwidth(s, avctx->cutoff);
 
     /* initial snr offset */
     s->coarse_snr_offset = 40;



More information about the ffmpeg-cvslog mailing list