opusenc: remove unused header entries and simplify normalization
authorRostislav Pehlivanov <atomnuker@gmail.com>
Mon, 3 Apr 2017 12:13:14 +0000 (13:13 +0100)
committerRostislav Pehlivanov <atomnuker@gmail.com>
Fri, 7 Apr 2017 23:27:33 +0000 (00:27 +0100)
Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
libavcodec/opus_celt.h
libavcodec/opusenc.c

index 23c2089..1ed57f3 100644 (file)
@@ -67,9 +67,6 @@ typedef struct CeltBlock {
 
     uint8_t collapse_masks[CELT_MAX_BANDS];
 
-    int band_bins[CELT_MAX_BANDS]; /* MDCT bins per band */
-    float *band_coeffs[CELT_MAX_BANDS];
-
     /* buffer for mdct output + postfilter */
     DECLARE_ALIGNED(32, float, buf)[2048];
     DECLARE_ALIGNED(32, float, coeffs)[CELT_MAX_FRAME_SIZE];
index cecc8f2..a84e51f 100644 (file)
@@ -255,24 +255,20 @@ static int celt_frame_map_norm_bands(OpusEncContext *s, CeltFrame *f)
 
     for (ch = 0; ch < f->channels; ch++) {
         CeltBlock *block = &f->block[ch];
-        float *start = block->coeffs;
         for (i = 0; i < CELT_MAX_BANDS; i++) {
             float ener = 0.0f;
+            int band_offset = ff_celt_freq_bands[i] << f->size;
+            int band_size   = ff_celt_freq_range[i] << f->size;
+            float *coeffs   = &block->coeffs[band_offset];
 
-            /* Calculate band bins */
-            block->band_bins[i] = ff_celt_freq_range[i] << f->size;
-            block->band_coeffs[i] = start;
-            start += block->band_bins[i];
-
-            /* Normalize band energy */
-            for (j = 0; j < block->band_bins[i]; j++)
-                ener += block->band_coeffs[i][j]*block->band_coeffs[i][j];
+            for (j = 0; j < band_size; j++)
+                ener += coeffs[j]*coeffs[j];
 
             block->lin_energy[i] = sqrtf(ener) + FLT_EPSILON;
             ener = 1.0f/block->lin_energy[i];
 
-            for (j = 0; j < block->band_bins[i]; j++)
-                block->band_coeffs[i][j] *= ener;
+            for (j = 0; j < band_size; j++)
+                coeffs[j] *= ener;
 
             block->energy[i] = log2f(block->lin_energy[i]) - ff_celt_mean_energy[i];