[FFmpeg-cvslog] r15776 - in trunk/libavcodec: aac.c aac.h aactab.c

superdump subversion
Wed Nov 5 14:59:42 CET 2008


Author: superdump
Date: Wed Nov  5 14:59:42 2008
New Revision: 15776

Log:
Fix perceptual noise shaping scaling including an oversight of the offset for
the EIGHT_SHORT window type. Fixes issue 664.

Patch by Alex Converse (alex converse gmail com)


Modified:
   trunk/libavcodec/aac.c
   trunk/libavcodec/aac.h
   trunk/libavcodec/aactab.c

Modified: trunk/libavcodec/aac.c
==============================================================================
--- trunk/libavcodec/aac.c	(original)
+++ trunk/libavcodec/aac.c	Wed Nov  5 14:59:42 2008
@@ -399,7 +399,7 @@ static av_cold int aac_decode_init(AVCod
     }
 
 #ifndef CONFIG_HARDCODED_TABLES
-    for (i = 0; i < 316; i++)
+    for (i = 0; i < 428; i++)
         ff_aac_pow2sf_tab[i] = pow(2, (i - 200)/4.);
 #endif /* CONFIG_HARDCODED_TABLES */
 
@@ -573,7 +573,7 @@ static int decode_scalefactors(AACContex
                             "%s (%d) out of range.\n", sf_str[1], offset[1]);
                         return -1;
                     }
-                    sf[idx]  = -ff_aac_pow2sf_tab[ offset[1] + sf_offset];
+                    sf[idx]  = -ff_aac_pow2sf_tab[ offset[1] + sf_offset + 100];
                 }
             }else {
                 for(; i < run_end; i++, idx++) {
@@ -704,11 +704,17 @@ static int decode_spectrum_and_dequant(A
                     memset(coef + group * 128 + offsets[i], 0, (offsets[i+1] - offsets[i])*sizeof(float));
                 }
             }else if (cur_band_type == NOISE_BT) {
-                const float scale = sf[idx] / ((offsets[i+1] - offsets[i]) * PNS_MEAN_ENERGY);
                 for (group = 0; group < ics->group_len[g]; group++) {
+                    float scale;
+                    float band_energy = 0;
                     for (k = offsets[i]; k < offsets[i+1]; k++) {
                         ac->random_state  = lcg_random(ac->random_state);
-                        coef[group*128+k] = ac->random_state * scale;
+                        coef[group*128+k] = ac->random_state;
+                        band_energy += coef[group*128+k]*coef[group*128+k];
+                    }
+                    scale = sf[idx] / sqrtf(band_energy);
+                    for (k = offsets[i]; k < offsets[i+1]; k++) {
+                        coef[group*128+k] *= scale;
                     }
                 }
             }else if (cur_band_type != INTENSITY_BT2 && cur_band_type != INTENSITY_BT) {

Modified: trunk/libavcodec/aac.h
==============================================================================
--- trunk/libavcodec/aac.h	(original)
+++ trunk/libavcodec/aac.h	Wed Nov  5 14:59:42 2008
@@ -46,7 +46,6 @@
 #define MAX_ELEM_ID 16
 
 #define TNS_MAX_ORDER 20
-#define PNS_MEAN_ENERGY 3719550720.0f // sqrt(3.0) * 1<<31
 
 enum AudioObjectType {
     AOT_NULL,

Modified: trunk/libavcodec/aactab.c
==============================================================================
--- trunk/libavcodec/aactab.c	(original)
+++ trunk/libavcodec/aactab.c	Wed Nov  5 14:59:42 2008
@@ -904,7 +904,7 @@ const float * const ff_aac_codebook_vect
  * [60, 315] scale factor decoding when using SIMD dsp.float_to_int16
  * [45, 300] intensity stereo position decoding mapped in reverse order i.e. 0->300, 1->299, ..., 254->46, 255->45
  */
-const float ff_aac_pow2sf_tab[316] = {
+const float ff_aac_pow2sf_tab[428] = {
     8.88178420e-16, 1.05622810e-15, 1.25607397e-15, 1.49373210e-15,
     1.77635684e-15, 2.11245619e-15, 2.51214793e-15, 2.98746420e-15,
     3.55271368e-15, 4.22491238e-15, 5.02429587e-15, 5.97492839e-15,
@@ -984,10 +984,38 @@ const float ff_aac_pow2sf_tab[316] = {
     6.71088640e+07, 7.98063385e+07, 9.49062656e+07, 1.12863206e+08,
     1.34217728e+08, 1.59612677e+08, 1.89812531e+08, 2.25726413e+08,
     2.68435456e+08, 3.19225354e+08, 3.79625062e+08, 4.51452825e+08,
+    5.36870912e+08, 6.38450708e+08, 7.59250125e+08, 9.02905651e+08,
+    1.07374182e+09, 1.27690142e+09, 1.51850025e+09, 1.80581130e+09,
+    2.14748365e+09, 2.55380283e+09, 3.03700050e+09, 3.61162260e+09,
+    4.29496730e+09, 5.10760567e+09, 6.07400100e+09, 7.22324521e+09,
+    8.58993459e+09, 1.02152113e+10, 1.21480020e+10, 1.44464904e+10,
+    1.71798692e+10, 2.04304227e+10, 2.42960040e+10, 2.88929808e+10,
+    3.43597384e+10, 4.08608453e+10, 4.85920080e+10, 5.77859616e+10,
+    6.87194767e+10, 8.17216907e+10, 9.71840160e+10, 1.15571923e+11,
+    1.37438953e+11, 1.63443381e+11, 1.94368032e+11, 2.31143847e+11,
+    2.74877907e+11, 3.26886763e+11, 3.88736064e+11, 4.62287693e+11,
+    5.49755814e+11, 6.53773525e+11, 7.77472128e+11, 9.24575386e+11,
+    1.09951163e+12, 1.30754705e+12, 1.55494426e+12, 1.84915077e+12,
+    2.19902326e+12, 2.61509410e+12, 3.10988851e+12, 3.69830155e+12,
+    4.39804651e+12, 5.23018820e+12, 6.21977702e+12, 7.39660309e+12,
+    8.79609302e+12, 1.04603764e+13, 1.24395540e+13, 1.47932062e+13,
+    1.75921860e+13, 2.09207528e+13, 2.48791081e+13, 2.95864124e+13,
+    3.51843721e+13, 4.18415056e+13, 4.97582162e+13, 5.91728247e+13,
+    7.03687442e+13, 8.36830112e+13, 9.95164324e+13, 1.18345649e+14,
+    1.40737488e+14, 1.67366022e+14, 1.99032865e+14, 2.36691299e+14,
+    2.81474977e+14, 3.34732045e+14, 3.98065730e+14, 4.73382598e+14,
+    5.62949953e+14, 6.69464090e+14, 7.96131459e+14, 9.46765196e+14,
+    1.12589991e+15, 1.33892818e+15, 1.59226292e+15, 1.89353039e+15,
+    2.25179981e+15, 2.67785636e+15, 3.18452584e+15, 3.78706078e+15,
+    4.50359963e+15, 5.35571272e+15, 6.36905167e+15, 7.57412156e+15,
+    9.00719925e+15, 1.07114254e+16, 1.27381033e+16, 1.51482431e+16,
+    1.80143985e+16, 2.14228509e+16, 2.54762067e+16, 3.02964863e+16,
+    3.60287970e+16, 4.28457018e+16, 5.09524134e+16, 6.05929725e+16,
+    7.20575940e+16, 8.56914035e+16, 1.01904827e+17, 1.21185945e+17,
 };
 
 #else
 
-float ff_aac_pow2sf_tab[316];
+float ff_aac_pow2sf_tab[428];
 
 #endif /* CONFIG_HARDCODED_TABLES */




More information about the ffmpeg-cvslog mailing list