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

jbr subversion
Tue Dec 14 15:53:44 CET 2010


Author: jbr
Date: Tue Dec 14 15:53:43 2010
New Revision: 26003

Log:
Split out setting of bit allocation parameters to a separate function.
Th new function only needs to be called at initialization because bit
allocation parameters currently do not change during encoding.

Modified:
   trunk/libavcodec/ac3enc.c

Modified: trunk/libavcodec/ac3enc.c
==============================================================================
--- trunk/libavcodec/ac3enc.c	Tue Dec 14 15:53:40 2010	(r26002)
+++ trunk/libavcodec/ac3enc.c	Tue Dec 14 15:53:43 2010	(r26003)
@@ -745,6 +745,37 @@ static int process_exponents(AC3EncodeCo
 
 
 /**
+ * Initialize bit allocation.
+ * Set default parameter codes and calculate parameter values.
+ */
+static void bit_alloc_init(AC3EncodeContext *s)
+{
+    int ch;
+
+    /* init default parameters */
+    s->slow_decay_code = 2;
+    s->fast_decay_code = 1;
+    s->slow_gain_code  = 1;
+    s->db_per_bit_code = 2;
+    s->floor_code      = 4;
+    for (ch = 0; ch < s->channels; ch++)
+        s->fast_gain_code[ch] = 4;
+
+    /* initial snr offset */
+    s->coarse_snr_offset = 40;
+
+    /* compute real values */
+    /* currently none of these values change during encoding, so we can just
+       set them once at initialization */
+    s->bit_alloc.slow_decay = ff_ac3_slow_decay_tab[s->slow_decay_code] >> s->bit_alloc.sr_shift;
+    s->bit_alloc.fast_decay = ff_ac3_fast_decay_tab[s->fast_decay_code] >> s->bit_alloc.sr_shift;
+    s->bit_alloc.slow_gain  = ff_ac3_slow_gain_tab[s->slow_gain_code];
+    s->bit_alloc.db_per_bit = ff_ac3_db_per_bit_tab[s->db_per_bit_code];
+    s->bit_alloc.floor      = ff_ac3_floor_tab[s->floor_code];
+}
+
+
+/**
  * Count the bits used to encode the frame, minus exponents and mantissas.
  * @return bit count
  */
@@ -936,22 +967,6 @@ static int compute_bit_allocation(AC3Enc
     int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
     int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS];
 
-    /* init default parameters */
-    s->slow_decay_code = 2;
-    s->fast_decay_code = 1;
-    s->slow_gain_code  = 1;
-    s->db_per_bit_code = 2;
-    s->floor_code      = 4;
-    for (ch = 0; ch < s->channels; ch++)
-        s->fast_gain_code[ch] = 4;
-
-    /* compute real values */
-    s->bit_alloc.slow_decay = ff_ac3_slow_decay_tab[s->slow_decay_code] >> s->bit_alloc.sr_shift;
-    s->bit_alloc.fast_decay = ff_ac3_fast_decay_tab[s->fast_decay_code] >> s->bit_alloc.sr_shift;
-    s->bit_alloc.slow_gain  = ff_ac3_slow_gain_tab[s->slow_gain_code];
-    s->bit_alloc.db_per_bit = ff_ac3_db_per_bit_tab[s->db_per_bit_code];
-    s->bit_alloc.floor      = ff_ac3_floor_tab[s->floor_code];
-
     /* count frame bits other than exponents and mantissas */
     frame_bits += count_frame_bits(s, exp_strategy);
 
@@ -1615,8 +1630,7 @@ static av_cold int ac3_encode_init(AVCod
 
     set_bandwidth(s, avctx->cutoff);
 
-    /* initial snr offset */
-    s->coarse_snr_offset = 40;
+    bit_alloc_init(s);
 
     mdct_init(9);
 



More information about the ffmpeg-cvslog mailing list