Browse code

define AC3_CRITICAL_BANDS and use it in the AC-3 encoder and decoder.

Originally committed as revision 25967 to svn://svn.ffmpeg.org/ffmpeg/trunk

Justin Ruggles authored on 2010/12/14 23:51:40
Showing 4 changed files
... ...
@@ -33,7 +33,7 @@
33 33
 /**
34 34
  * Starting frequency coefficient bin for each critical band.
35 35
  */
36
-static const uint8_t band_start_tab[51] = {
36
+static const uint8_t band_start_tab[AC3_CRITICAL_BANDS+1] = {
37 37
       0,  1,   2,   3,   4,   5,   6,   7,   8,   9,
38 38
      10,  11, 12,  13,  14,  15,  16,  17,  18,  19,
39 39
      20,  21, 22,  23,  24,  25,  26,  27,  28,  31,
... ...
@@ -127,7 +127,7 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
127 127
                                uint8_t *dba_lengths, uint8_t *dba_values,
128 128
                                int16_t *mask)
129 129
 {
130
-    int16_t excite[50]; /* excitation */
130
+    int16_t excite[AC3_CRITICAL_BANDS]; /* excitation */
131 131
     int band;
132 132
     int band_start, band_end, begin, end1;
133 133
     int lowcomp, fastleak, slowleak;
... ...
@@ -198,7 +198,7 @@ int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,
198 198
         band = 0;
199 199
         for (seg = 0; seg < dba_nsegs; seg++) {
200 200
             band += dba_offsets[seg];
201
-            if (band >= 50 || dba_lengths[seg] > 50-band)
201
+            if (band >= AC3_CRITICAL_BANDS || dba_lengths[seg] > AC3_CRITICAL_BANDS-band)
202 202
                 return -1;
203 203
             if (dba_values[seg] >= 4) {
204 204
                 delta = (dba_values[seg] - 3) << 7;
... ...
@@ -247,8 +247,8 @@ void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap,
247 247
                                    uint8_t *dba_values)
248 248
 {
249 249
     int16_t psd[256];   /* scaled exponents */
250
-    int16_t band_psd[50]; /* interpolated exponents */
251
-    int16_t mask[50];   /* masking value */
250
+    int16_t band_psd[AC3_CRITICAL_BANDS]; /* interpolated exponents */
251
+    int16_t mask[AC3_CRITICAL_BANDS];   /* masking value */
252 252
 
253 253
     ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, band_psd);
254 254
 
... ...
@@ -270,12 +270,12 @@ av_cold void ac3_common_init(void)
270 270
 #if !CONFIG_HARDCODED_TABLES
271 271
     /* compute bndtab and masktab from bandsz */
272 272
     int bin = 0, band;
273
-    for (band = 0; band < 50; band++) {
273
+    for (band = 0; band < AC3_CRITICAL_BANDS; band++) {
274 274
         int band_end = bin + ff_ac3_critical_band_size_tab[band];
275 275
         band_start_tab[band] = bin;
276 276
         while (bin < band_end)
277 277
             bin_to_band_tab[bin++] = band;
278 278
     }
279
-    band_start_tab[50] = bin;
279
+    band_start_tab[AC3_CRITICAL_BANDS] = bin;
280 280
 #endif /* !CONFIG_HARDCODED_TABLES */
281 281
 }
... ...
@@ -37,6 +37,7 @@
37 37
 #define AC3_MAX_BLOCKS    6
38 38
 #define AC3_FRAME_SIZE (AC3_MAX_BLOCKS * 256)
39 39
 #define AC3_WINDOW_SIZE (AC3_BLOCK_SIZE * 2)
40
+#define AC3_CRITICAL_BANDS 50
40 41
 
41 42
 /* exponent encoding strategy */
42 43
 #define EXP_REUSE 0
... ...
@@ -168,8 +168,8 @@ typedef struct {
168 168
     int fast_gain[AC3_MAX_CHANNELS];                ///< fast gain values/SMR's         (fgain)
169 169
     uint8_t bap[AC3_MAX_CHANNELS][AC3_MAX_COEFS];   ///< bit allocation pointers
170 170
     int16_t psd[AC3_MAX_CHANNELS][AC3_MAX_COEFS];   ///< scaled exponents
171
-    int16_t band_psd[AC3_MAX_CHANNELS][50];         ///< interpolated exponents
172
-    int16_t mask[AC3_MAX_CHANNELS][50];             ///< masking curve values
171
+    int16_t band_psd[AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS]; ///< interpolated exponents
172
+    int16_t mask[AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS];     ///< masking curve values
173 173
     int dba_mode[AC3_MAX_CHANNELS];                 ///< delta bit allocation mode
174 174
     int dba_nsegs[AC3_MAX_CHANNELS];                ///< number of delta segments
175 175
     uint8_t dba_offsets[AC3_MAX_CHANNELS][8];       ///< delta segment offsets
... ...
@@ -506,16 +506,16 @@ static void bit_alloc_masking(AC3EncodeContext *s,
506 506
                               uint8_t encoded_exp[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
507 507
                               uint8_t exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS],
508 508
                               int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
509
-                              int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][50])
509
+                              int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS])
510 510
 {
511 511
     int blk, ch;
512
-    int16_t band_psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][50];
512
+    int16_t band_psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS];
513 513
 
514 514
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
515 515
         for (ch = 0; ch < s->channels; ch++) {
516 516
             if(exp_strategy[blk][ch] == EXP_REUSE) {
517 517
                 memcpy(psd[blk][ch],  psd[blk-1][ch],  AC3_MAX_COEFS*sizeof(psd[0][0][0]));
518
-                memcpy(mask[blk][ch], mask[blk-1][ch], 50*sizeof(mask[0][0][0]));
518
+                memcpy(mask[blk][ch], mask[blk-1][ch], AC3_CRITICAL_BANDS*sizeof(mask[0][0][0]));
519 519
             } else {
520 520
                 ff_ac3_bit_alloc_calc_psd(encoded_exp[blk][ch], 0,
521 521
                                           s->nb_coefs[ch],
... ...
@@ -540,7 +540,7 @@ static void bit_alloc_masking(AC3EncodeContext *s,
540 540
  *         SNR offset is used to quantize the mantissas.
541 541
  */
542 542
 static int bit_alloc(AC3EncodeContext *s,
543
-                     int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][50],
543
+                     int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS],
544 544
                      int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
545 545
                      uint8_t bap[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS],
546 546
                      int frame_bits, int coarse_snr_offset, int fine_snr_offset)
... ...
@@ -584,7 +584,7 @@ static int compute_bit_allocation(AC3EncodeContext *s,
584 584
     int coarse_snr_offset, fine_snr_offset;
585 585
     uint8_t bap1[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
586 586
     int16_t psd[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_MAX_COEFS];
587
-    int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][50];
587
+    int16_t mask[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][AC3_CRITICAL_BANDS];
588 588
     static const int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
589 589
 
590 590
     /* init default parameters */