This patch never got any replies on FFmpeg-devel.

-------- Original Message --------
Subject: [FFmpeg-devel] [PATCH] ac3enc: replace nb_coefs with
start_freq and  end_freq in AC3EncodeContext.
Date: Fri,  4 Mar 2011 19:12:51 -0500
From: Justin Ruggles <[email protected]>
Reply-To: FFmpeg development discussions and patches
<[email protected]>
To: [email protected]


Currently start_freq is always 0, but it will be non-zero for the coupling
channel after channel coupling is implemented.
---
 libavcodec/ac3enc.c |   74
+++++++++++++++++++++++++++++---------------------
 1 files changed, 43 insertions(+), 31 deletions(-)


diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 676bb5e..3602c04 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -114,7 +114,8 @@ typedef struct AC3EncodeContext {
 
     int cutoff;                             ///< user-specified cutoff frequency, in Hz
     int bandwidth_code[AC3_MAX_CHANNELS];   ///< bandwidth code (0 to 60)               (chbwcod)
-    int nb_coefs[AC3_MAX_CHANNELS];
+    int start_freq[AC3_MAX_CHANNELS];       ///< start frequency bin for each channel   (strtmant)
+    int end_freq[AC3_MAX_CHANNELS];         ///< end frequency bin for each channel     (endmant)
 
     int rematrixing;                        ///< determines how rematrixing strategy is calculated
     int num_rematrixing_bands;              ///< number of rematrixing bands
@@ -302,7 +303,7 @@ static void rematrixing_init(AC3EncodeContext *s)
  */
 static void compute_rematrixing_strategy(AC3EncodeContext *s)
 {
-    int nb_coefs;
+    int end_freq;
     int blk, bnd, i;
     AC3Block *block, *block0;
 
@@ -311,7 +312,7 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s)
     if (s->rematrixing & AC3_REMATRIXING_IS_STATIC)
         return;
 
-    nb_coefs = FFMIN(s->nb_coefs[0], s->nb_coefs[1]);
+    end_freq = FFMIN(s->end_freq[0], s->end_freq[1]);
 
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
         block = &s->blocks[blk];
@@ -319,7 +320,7 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s)
         for (bnd = 0; bnd < s->num_rematrixing_bands; bnd++) {
             /* calculate calculate sum of squared coeffs for one band in one block */
             int start = ff_ac3_rematrix_band_tab[bnd];
-            int end   = FFMIN(nb_coefs, ff_ac3_rematrix_band_tab[bnd+1]);
+            int end   = FFMIN(end_freq, ff_ac3_rematrix_band_tab[bnd+1]);
             CoefSumType sum[4] = {0,};
             for (i = start; i < end; i++) {
                 CoefType lt = block->mdct_coef[0][i];
@@ -354,7 +355,7 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s)
  */
 static void apply_rematrixing(AC3EncodeContext *s)
 {
-    int nb_coefs;
+    int end_freq;
     int blk, bnd, i;
     int start, end;
     uint8_t *flags;
@@ -362,7 +363,7 @@ static void apply_rematrixing(AC3EncodeContext *s)
     if (s->rematrixing == AC3_REMATRIXING_NONE)
         return;
 
-    nb_coefs = FFMIN(s->nb_coefs[0], s->nb_coefs[1]);
+    end_freq = FFMIN(s->end_freq[0], s->end_freq[1]);
 
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
         AC3Block *block = &s->blocks[blk];
@@ -371,7 +372,7 @@ static void apply_rematrixing(AC3EncodeContext *s)
         for (bnd = 0; bnd < s->num_rematrixing_bands; bnd++) {
             if (flags[bnd]) {
                 start = ff_ac3_rematrix_band_tab[bnd];
-                end   = FFMIN(nb_coefs, ff_ac3_rematrix_band_tab[bnd+1]);
+                end   = FFMIN(end_freq, ff_ac3_rematrix_band_tab[bnd+1]);
                 for (i = start; i < end; i++) {
                     int32_t lt = block->fixed_coef[0][i];
                     int32_t rt = block->fixed_coef[1][i];
@@ -577,12 +578,13 @@ static void encode_exponents(AC3EncodeContext *s)
 {
     int blk, blk1, ch;
     uint8_t *exp, *exp1, *exp_strategy;
-    int nb_coefs, num_reuse_blocks;
+    int start, nb_coefs, num_reuse_blocks;
 
     for (ch = 0; ch < s->channels; ch++) {
-        exp          = s->blocks[0].exp[ch];
+        start        = s->start_freq[ch];
+        exp          = &s->blocks[0].exp[ch][start];
         exp_strategy = s->exp_strategy[ch];
-        nb_coefs     = s->nb_coefs[ch];
+        nb_coefs     = s->end_freq[ch] - start;
 
         blk = 0;
         while (blk < AC3_MAX_BLOCKS) {
@@ -594,7 +596,7 @@ static void encode_exponents(AC3EncodeContext *s)
             num_reuse_blocks = blk1 - blk - 1;
 
             /* for the EXP_REUSE case we select the min of the exponents */
-            s->ac3dsp.ac3_exponent_min(exp, num_reuse_blocks, nb_coefs);
+            s->ac3dsp.ac3_exponent_min(exp-start, num_reuse_blocks, s->end_freq[ch]);
 
             encode_exponents_blk_ch(exp, nb_coefs, exp_strategy[blk]);
 
@@ -630,10 +632,11 @@ static void group_exponents(AC3EncodeContext *s)
         AC3Block *block = &s->blocks[blk];
         for (ch = 0; ch < s->channels; ch++) {
             int exp_strategy = s->exp_strategy[ch][blk];
+            int nb_coefs     = s->end_freq[ch] - s->start_freq[ch];
             if (exp_strategy == EXP_REUSE)
                 continue;
             group_size = exp_strategy + (exp_strategy == EXP_D45);
-            nb_groups = exponent_group_tab[exp_strategy-1][s->nb_coefs[ch]];
+            nb_groups = exponent_group_tab[exp_strategy-1][nb_coefs];
             bit_count += 4 + (nb_groups * 7);
             p = block->exp[ch];
 
@@ -803,12 +806,13 @@ static void count_frame_bits(AC3EncodeContext *s)
 /**
  * Calculate the number of bits needed to encode a set of mantissas.
  */
-static int compute_mantissa_size(int mant_cnt[5], uint8_t *bap, int nb_coefs)
+static int compute_mantissa_size(int mant_cnt[5], uint8_t *bap, int start,
+                                 int end)
 {
     int bits, b, i;
 
     bits = 0;
-    for (i = 0; i < nb_coefs; i++) {
+    for (i = start; i < end; i++) {
         b = bap[i];
         if (b <= 4) {
             // bap=1 to bap=4 will be counted in compute_mantissa_size_final
@@ -856,11 +860,11 @@ static void bit_alloc_masking(AC3EncodeContext *s)
                Since we currently do not calculate bap when exponent
                strategy is EXP_REUSE we do not need to calculate psd or mask. */
             if (s->exp_strategy[ch][blk] != EXP_REUSE) {
-                ff_ac3_bit_alloc_calc_psd(block->exp[ch], 0,
-                                          s->nb_coefs[ch],
+                ff_ac3_bit_alloc_calc_psd(block->exp[ch], s->start_freq[ch],
+                                          s->end_freq[ch],
                                           block->psd[ch], block->band_psd[ch]);
                 ff_ac3_bit_alloc_calc_mask(&s->bit_alloc, block->band_psd[ch],
-                                           0, s->nb_coefs[ch],
+                                           s->start_freq[ch], s->end_freq[ch],
                                            ff_ac3_fast_gain_tab[s->fast_gain_code[ch]],
                                            ch == s->lfe_channel,
                                            DBA_NONE, 0, NULL, NULL, NULL,
@@ -921,12 +925,14 @@ static int bit_alloc(AC3EncodeContext *s, int snr_offset)
             if (s->exp_strategy[ch][blk] == EXP_REUSE) {
                 memcpy(block->bap[ch], s->blocks[blk-1].bap[ch], AC3_MAX_COEFS);
             } else {
-                ff_ac3_bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0,
-                                          s->nb_coefs[ch], snr_offset,
-                                          s->bit_alloc.floor, ff_ac3_bap_tab,
-                                          block->bap[ch]);
+                ff_ac3_bit_alloc_calc_bap(block->mask[ch], block->psd[ch],
+                                          s->start_freq[ch], s->end_freq[ch],
+                                          snr_offset, s->bit_alloc.floor,
+                                          ff_ac3_bap_tab, block->bap[ch]);
             }
-            mantissa_bits += compute_mantissa_size(mant_cnt, block->bap[ch], s->nb_coefs[ch]);
+            mantissa_bits += compute_mantissa_size(mant_cnt, block->bap[ch],
+                                                   s->start_freq[ch],
+                                                   s->end_freq[ch]);
         }
         mantissa_bits += compute_mantissa_size_final(mant_cnt);
     }
@@ -1035,7 +1041,7 @@ static int reduce_bandwidth(AC3EncodeContext *s, int min_bw_code)
     if (s->bandwidth_code[0] > min_bw_code) {
         for (ch = 0; ch < s->fbw_channels; ch++) {
             s->bandwidth_code[ch]--;
-            s->nb_coefs[ch] = s->bandwidth_code[ch] * 3 + 73;
+            s->end_freq[ch] = s->bandwidth_code[ch] * 3 + 73;
         }
         return 0;
     }
@@ -1133,11 +1139,12 @@ static inline int asym_quant(int c, int e, int qbits)
  */
 static void quantize_mantissas_blk_ch(AC3EncodeContext *s, int32_t *fixed_coef,
                                       int8_t exp_shift, uint8_t *exp,
-                                      uint8_t *bap, uint16_t *qmant, int n)
+                                      uint8_t *bap, uint16_t *qmant, int start,
+                                      int end)
 {
     int i;
 
-    for (i = 0; i < n; i++) {
+    for (i = start; i < end; i++) {
         int v;
         int c = fixed_coef[i];
         int e = exp[i] - exp_shift;
@@ -1238,7 +1245,8 @@ static void quantize_mantissas(AC3EncodeContext *s)
         for (ch = 0; ch < s->channels; ch++) {
             quantize_mantissas_blk_ch(s, block->fixed_coef[ch], block->exp_shift[ch],
                                       block->exp[ch], block->bap[ch],
-                                      block->qmant[ch], s->nb_coefs[ch]);
+                                      block->qmant[ch], s->start_freq[ch],
+                                      s->end_freq[ch]);
         }
     }
 }
@@ -1327,6 +1335,7 @@ static void output_audio_block(AC3EncodeContext *s, int blk)
     /* exponents */
     for (ch = 0; ch < s->channels; ch++) {
         int nb_groups;
+        int nb_coefs = s->end_freq[ch] - s->start_freq[ch];
 
         if (s->exp_strategy[ch][blk] == EXP_REUSE)
             continue;
@@ -1335,7 +1344,7 @@ static void output_audio_block(AC3EncodeContext *s, int blk)
         put_bits(&s->pb, 4, block->grouped_exp[ch][0]);
 
         /* exponent groups */
-        nb_groups = exponent_group_tab[s->exp_strategy[ch][blk]-1][s->nb_coefs[ch]];
+        nb_groups = exponent_group_tab[s->exp_strategy[ch][blk]-1][nb_coefs];
         for (i = 1; i <= nb_groups; i++)
             put_bits(&s->pb, 7, block->grouped_exp[ch][i]);
 
@@ -1371,7 +1380,7 @@ static void output_audio_block(AC3EncodeContext *s, int blk)
     /* mantissas */
     for (ch = 0; ch < s->channels; ch++) {
         int b, q;
-        for (i = 0; i < s->nb_coefs[ch]; i++) {
+        for (i = s->start_freq[ch]; i < s->end_freq[ch]; i++) {
             q = block->qmant[ch][i];
             b = block->bap[ch][i];
             switch (b) {
@@ -1688,10 +1697,13 @@ static av_cold void set_bandwidth(AC3EncodeContext *s)
     /* 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;
+        s->start_freq[ch]     = 0;
+        s->end_freq[ch]       = bw_code * 3 + 73;
+    }
+    if (s->lfe_on) {
+        s->start_freq[s->lfe_channel] = 0;
+        s->end_freq[s->lfe_channel]   = 7; /* LFE channel always has 7 coefs */
     }
-    if (s->lfe_on)
-        s->nb_coefs[s->lfe_channel] = 7; /* LFE channel always has 7 coefs */
 }
 
 

_______________________________________________
ffmpeg-devel mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to