]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/mpegaudiodec: Hardcode tables to save space
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Wed, 18 Nov 2020 01:19:53 +0000 (02:19 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Tue, 8 Dec 2020 16:51:47 +0000 (17:51 +0100)
The csa_tables (which always consist of 32 entries of four byte each,
but the type depends upon whether the decoder is fixed or
floating-point) are currently initialized once during decoder
initialization; yet it turns out that this is actually no benefit: The
code used to initialize these tables takes up 153 (fixed point) and 122
(floating point) bytes when compiled with GCC 9.3 with -O3 on x64, so it
is better to just hardcode these tables.

Essentially the same applies to the is_tables: They have a size of 128B
each and the code to initialize them occupies 149 (fixed point) resp.
140 (floating point) bytes. So hardcode them, too.

To make the origin of the tables clear, references to the code used to
create them have been added.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/mips/compute_antialias_fixed.h
libavcodec/mips/compute_antialias_float.h
libavcodec/mpegaudiodata.h
libavcodec/mpegaudiodec_common.c
libavcodec/mpegaudiodec_fixed.c
libavcodec/mpegaudiodec_float.c
libavcodec/mpegaudiodec_template.c

index a967f67de70cff6c697e817f851cccf29a99d78c..1f395d23027b3075317ead7d127eb5dc48827ae7 100644 (file)
@@ -59,7 +59,8 @@
 static void compute_antialias_mips_fixed(MPADecodeContext *s,
                                         GranuleDef *g)
 {
-    int32_t *ptr, *csa;
+    const int32_t *csa;
+    int32_t *ptr;
     int n, i;
     int MAX_lo = 0xffffffff;
 
index e2b4f29f4ab1de621993ded7fe0a432c70825aea..633eb9589d8ca214325c31e4e1e1958f66a256f6 100644 (file)
@@ -63,7 +63,7 @@ static void compute_antialias_mips_float(MPADecodeContext *s,
                                         GranuleDef *g)
 {
     float *ptr, *ptr_end;
-    float *csa = &csa_table[0][0];
+    const float *csa = &csa_table[0][0];
     /* temporary variables */
     float in1, in2, in3, in4, in5, in6, in7, in8;
     float out1, out2, out3, out4;
index ec969353f32a6097dc2b1c93d6fe7d96bd75622f..01b1f88cd00a6e3b56f6f6a6e8fe36b4dec1e053 100644 (file)
@@ -65,9 +65,6 @@ extern uint16_t ff_scale_factor_modshift[64];
 
 extern const uint8_t ff_mpa_pretab[2][22];
 
-/* table for alias reduction (XXX: store it as integer !) */
-extern const float ff_ci_table[8];
-
 /* Initialize tables shared between the fixed and
  * floating point MPEG audio decoders. */
 void ff_mpegaudiodec_common_init_static(void);
index 2ac9bb95bc772559ce7f547b66fbb6da37781f7c..4333746e9a6508a476347426a28079a225774e94 100644 (file)
@@ -396,10 +396,6 @@ const uint8_t ff_mpa_pretab[2][22] = {
     { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0 },
 };
 
-const float ff_ci_table[8] = {
-    -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037,
-};
-
 static av_cold void mpegaudiodec_common_init_static(void)
 {
     const uint8_t *huff_sym = mpa_huffsymbols, *huff_lens = mpa_hufflens;
index 6fe372b38f953c1dd2477bf18b3f0c9e74d4b74c..a3c8ddc21ed9bfdc22f144b241b08d0dd9e8b468 100644 (file)
 #define OUT_FMT   AV_SAMPLE_FMT_S16
 #define OUT_FMT_P AV_SAMPLE_FMT_S16P
 
+/* Intensity stereo table. See commit b91d46614df189e7905538e7f5c4ed9c7ed0d274
+ * (float based mp1/mp2/mp3 decoders.) for how they were created. */
+static const int32_t is_table[2][16] = {
+    { 0x000000, 0x1B0CB1, 0x2ED9EC, 0x400000, 0x512614, 0x64F34F, 0x800000 },
+    { 0x800000, 0x64F34F, 0x512614, 0x400000, 0x2ED9EC, 0x1B0CB1, 0x000000 }
+};
+
+/* Antialiasing table. See commit ce4a29c066cddfc180979ed86396812f24337985
+ * (optimize antialias) for how they were created. */
+static const int32_t csa_table[8][4] = {
+    { 0x36E129F8, 0xDF128056, 0x15F3AA4E, 0xA831565E },
+    { 0x386E75F2, 0xE1CF24A5, 0x1A3D9A97, 0xA960AEB3 },
+    { 0x3CC6B73A, 0xEBF19FA6, 0x28B856E0, 0xAF2AE86C },
+    { 0x3EEEA054, 0xF45B88BC, 0x334A2910, 0xB56CE868 },
+    { 0x3FB6905C, 0xF9F27F18, 0x39A90F74, 0xBA3BEEBC },
+    { 0x3FF23F20, 0xFD60D1E4, 0x3D531104, 0xBD6E92C4 },
+    { 0x3FFE5932, 0xFF175EE4, 0x3F15B816, 0xBF1905B2 },
+    { 0x3FFFE34A, 0xFFC3612F, 0x3FC34479, 0xBFC37DE5 }
+};
+
 #include "mpegaudiodec_template.c"
 
 #if CONFIG_MP1_DECODER
index cdee3374995383a409cefedebe08d4a1d37abe85..3ab7651d5b606eaa6c97e6d5bbc0296abd1f266b 100644 (file)
 #define OUT_FMT   AV_SAMPLE_FMT_FLT
 #define OUT_FMT_P AV_SAMPLE_FMT_FLTP
 
+/* Intensity stereo table. See commit b91d46614df189e7905538e7f5c4ed9c7ed0d274
+ * (float based mp1/mp2/mp3 decoders.) for how they were created. */
+static const float is_table[2][16] = {
+    { 0.000000000000000000e+00, 2.113248705863952637e-01, 3.660253882408142090e-01,
+      5.000000000000000000e-01, 6.339746117591857910e-01, 7.886751294136047363e-01,
+      1.000000000000000000e+00 },
+    { 1.000000000000000000e+00, 7.886751294136047363e-01, 6.339746117591857910e-01,
+      5.000000000000000000e-01, 3.660253882408142090e-01, 2.113248705863952637e-01,
+      0.000000000000000000e+00 }
+};
+
+/* Antialiasing table. See commit 6f1ec38ce2193d3d4cacd87edb452c6d7ba751ec
+ * (mpegaudio: clean up compute_antialias() definition) for how they were
+ * created. */
+static const float csa_table[8][4] = {
+    { 8.574929237365722656e-01, -5.144957900047302246e-01,
+      3.429971337318420410e-01, -1.371988654136657715e+00 },
+    { 8.817420005798339844e-01, -4.717319905757904053e-01,
+      4.100100100040435791e-01, -1.353474020957946777e+00 },
+    { 9.496286511421203613e-01, -3.133774697780609131e-01,
+      6.362511515617370605e-01, -1.263006091117858887e+00 },
+    { 9.833145737648010254e-01, -1.819131970405578613e-01,
+      8.014013767242431641e-01, -1.165227770805358887e+00 },
+    { 9.955177903175354004e-01, -9.457419067621231079e-02,
+      9.009436368942260742e-01, -1.090092062950134277e+00 },
+    { 9.991605877876281738e-01, -4.096558317542076111e-02,
+      9.581949710845947266e-01, -1.040126085281372070e+00 },
+    { 9.998992085456848145e-01, -1.419856864959001541e-02,
+      9.857006072998046875e-01, -1.014097809791564941e+00 },
+    { 9.999931454658508301e-01, -3.699974622577428818e-03,
+      9.962931871414184570e-01, -1.003693103790283203e+00 }
+};
+
 #include "mpegaudiodec_template.c"
 
 #if CONFIG_MP1FLOAT_DECODER
index fa75445036363e4f212a7d956cdcf38d2351f4b0..1e8fd6064f2d8374625dedf8b4c8fc198f4a057a 100644 (file)
@@ -99,9 +99,7 @@ typedef struct MPADecodeContext {
 
 #include "mpegaudio_tablegen.h"
 /* intensity stereo coef table */
-static INTFLOAT is_table[2][16];
 static INTFLOAT is_table_lsf[2][2][16];
-static INTFLOAT csa_table[8][4];
 
 /* [i][j]:  2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */
 static int32_t scale_factor_mult[15][3];
@@ -258,22 +256,6 @@ static av_cold void decode_init_static(void)
 
     mpegaudio_tableinit();
 
-    for (i = 0; i < 7; i++) {
-        float f;
-        INTFLOAT v;
-        if (i != 6) {
-            f = tan((double)i * M_PI / 12.0);
-            v = FIXR(f / (1.0 + f));
-        } else {
-            v = FIXR(1.0);
-        }
-        is_table[0][    i] = v;
-        is_table[1][6 - i] = v;
-    }
-    /* invalid values */
-    for (i = 7; i < 16; i++)
-        is_table[0][i] = is_table[1][i] = 0.0;
-
     for (i = 0; i < 16; i++) {
         double f;
         int e, k;
@@ -289,24 +271,6 @@ static av_cold void decode_init_static(void)
                     (float) is_table_lsf[j][1][i]);
         }
     }
-
-    for (i = 0; i < 8; i++) {
-        double ci, cs, ca;
-        ci = ff_ci_table[i];
-        cs = 1.0 / sqrt(1.0 + ci * ci);
-        ca = cs * ci;
-#if !USE_FLOATS
-        csa_table[i][0] = FIXHR(cs/4);
-        csa_table[i][1] = FIXHR(ca/4);
-        csa_table[i][2] = FIXHR(ca/4) + FIXHR(cs/4);
-        csa_table[i][3] = FIXHR(ca/4) - FIXHR(cs/4);
-#else
-        csa_table[i][0] = cs;
-        csa_table[i][1] = ca;
-        csa_table[i][2] = ca + cs;
-        csa_table[i][3] = ca - cs;
-#endif
-    }
     RENAME(ff_mpa_synth_init)();
     ff_mpegaudiodec_common_init_static();
 }
@@ -970,7 +934,8 @@ static void compute_stereo(MPADecodeContext *s, GranuleDef *g0, GranuleDef *g1)
 {
     int i, j, k, l;
     int sf_max, sf, len, non_zero_found;
-    INTFLOAT (*is_tab)[16], *tab0, *tab1, v1, v2;
+    INTFLOAT *tab0, *tab1, v1, v2;
+    const INTFLOAT (*is_tab)[16];
     SUINTFLOAT tmp0, tmp1;
     int non_zero_found_short[3];