Avoid global state.
---
 libavcodec/mpegaudiodec_template.c |   3 +-
 libavcodec/mpegaudiodsp.c          |   2 -
 libavcodec/mpegaudiodsp.h          |   7 +-
 libavcodec/mpegaudiodsp_template.c | 218 +++++++++++++++++++++++++++++--------
 libavcodec/x86/mpegaudiodsp.c      |  12 +-
 5 files changed, 183 insertions(+), 59 deletions(-)

diff --git a/libavcodec/mpegaudiodec_template.c 
b/libavcodec/mpegaudiodec_template.c
index e9ea65e..63df73e 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -1191,7 +1191,8 @@ static void compute_antialias(MPADecodeContext *s, 
GranuleDef *g)
 static void compute_imdct(MPADecodeContext *s, GranuleDef *g,
                           INTFLOAT *sb_samples, INTFLOAT *mdct_buf)
 {
-    INTFLOAT *win, *out_ptr, *ptr, *buf, *ptr1;
+    const INTFLOAT *win;
+    INTFLOAT *out_ptr, *ptr, *buf, *ptr1;
     INTFLOAT out2[12];
     int i, j, mdct_long_end, sblimit;
 
diff --git a/libavcodec/mpegaudiodsp.c b/libavcodec/mpegaudiodsp.c
index 58ea1d1..c66e816 100644
--- a/libavcodec/mpegaudiodsp.c
+++ b/libavcodec/mpegaudiodsp.c
@@ -29,8 +29,6 @@ av_cold void ff_mpadsp_init(MPADSPContext *s)
     DCTContext dct;
 
     ff_dct_init(&dct, 5, DCT_II);
-    ff_init_mpadsp_tabs_float();
-    ff_init_mpadsp_tabs_fixed();
 
     s->apply_window_float = ff_mpadsp_apply_window_float;
     s->apply_window_fixed = ff_mpadsp_apply_window_fixed;
diff --git a/libavcodec/mpegaudiodsp.h b/libavcodec/mpegaudiodsp.h
index e0e872f..fcf03cc 100644
--- a/libavcodec/mpegaudiodsp.h
+++ b/libavcodec/mpegaudiodsp.h
@@ -79,13 +79,10 @@ void ff_imdct36_blocks_float(float *out, float *buf, float 
*in,
 void ff_imdct36_blocks_fixed(int *out, int *buf, int *in,
                              int count, int switch_point, int block_type);
 
-void ff_init_mpadsp_tabs_float(void);
-void ff_init_mpadsp_tabs_fixed(void);
-
 /** For SSE implementation, MDCT_BUF_SIZE/2 should be 128-bit aligned */
 #define MDCT_BUF_SIZE FFALIGN(36, 2*4)
 
-extern int ff_mdct_win_fixed[8][MDCT_BUF_SIZE];
-extern float ff_mdct_win_float[8][MDCT_BUF_SIZE];
+extern const int   ff_mdct_win_fixed[8][MDCT_BUF_SIZE];
+extern const float ff_mdct_win_float[8][MDCT_BUF_SIZE];
 
 #endif /* AVCODEC_MPEGAUDIODSP_H */
diff --git a/libavcodec/mpegaudiodsp_template.c 
b/libavcodec/mpegaudiodsp_template.c
index b8836c9..48f922a 100644
--- a/libavcodec/mpegaudiodsp_template.c
+++ b/libavcodec/mpegaudiodsp_template.c
@@ -73,7 +73,177 @@ static inline int round_sample(int64_t *sum)
     [MDCT_BUF_SIZE/2, MDCT_BUF_SIZE/2 + 17] are actually used. The rest
     is just to preserve alignment for SIMD implementations.
 */
-DECLARE_ALIGNED(16, INTFLOAT, RENAME(ff_mdct_win))[8][MDCT_BUF_SIZE];
+// the tables are generated by the following code
+#if 0
+{
+    int i, j;
+    for (i = 0; i < 36; i++) {
+        for (j = 0; j < 4; j++) {
+            double d;
+
+            if (j == 2 && i % 3 != 1)
+                continue;
+
+            d = sin(M_PI * (i + 0.5) / 36.0);
+            if (j == 1) {
+                if      (i >= 30) d = 0;
+                else if (i >= 24) d = sin(M_PI * (i - 18 + 0.5) / 12.0);
+                else if (i >= 18) d = 1;
+            } else if (j == 3) {
+                if      (i <   6) d = 0;
+                else if (i <  12) d = sin(M_PI * (i -  6 + 0.5) / 12.0);
+                else if (i <  18) d = 1;
+            }
+            //merge last stage of imdct into the window coefficients
+            d *= 0.5 / cos(M_PI * (2 * i + 19) / 72);
+
+            if (j == 2)
+                RENAME(mdct_win)[j][i/3] = FIXHR((d / (1<<5)));
+            else {
+                int idx = i < 18 ? i : i + (MDCT_BUF_SIZE/2 - 18);
+                RENAME(mdct_win)[j][idx] = FIXHR((d / (1<<5)));
+            }
+        }
+    }
+
+    /* NOTE: we do frequency inversion adter the MDCT by changing
+        the sign of the right window coefs */
+    for (j = 0; j < 4; j++) {
+        for (i = 0; i < MDCT_BUF_SIZE; i += 2) {
+            RENAME(mdct_win)[j + 4][i    ] =  RENAME(mdct_win)[j][i    ];
+            RENAME(mdct_win)[j + 4][i + 1] = -RENAME(mdct_win)[j][i + 1];
+        }
+    }
+}
+#endif
+DECLARE_ALIGNED(16, const INTFLOAT, RENAME(ff_mdct_win))[8][MDCT_BUF_SIZE] = {
+#if CONFIG_FLOAT
+    {
+        0.00100882596, 0.00335019873, 0.00629419601,  0.0101755112,  0.015625,
+        0.0239929594,  0.0387882143,  0.0728734732,   0.242004707, 
-0.264101803,
+        -0.0949705616, -0.0608853027, -0.0460900478, -0.0377220884,
+        -0.0322725996, -0.028391283,  -0.0254472848, -0.0231059138, 0, 0,
+        -0.0211726688, -0.0195263885, -0.0180872418,  -0.0168000516, -0.015625,
+        -0.0145321358, -0.0134979468, -0.0125031117,  -0.011530933,
+        -0.0105661536, -0.0095939748, -0.00859914068, -0.0075649512,
+        -0.006472087,  -0.00529703591, -0.0040098452, -0.0025706978,
+        -0.00092441868,
+    },
+    {
+        0.00100882596, 0.00335019873,  0.00629419601,  0.0101755112, 0.015625,
+        0.0239929594,  0.0387882143,   0.0728734732,   0.242004707,
+        -0.264101803, -0.0949705616, -0.0608853027,  -0.0460900478,
+        -0.0377220884, -0.0322725996, -0.028391283,   -0.0254472848,
+        -0.0231059138, 0, 0, -0.0211928394, -0.0196948815,  -0.0185263921,
+        -0.0176153425, -0.0169123784, -0.0163832679,  -0.0158674475,
+        -0.0145601816, -0.0124079557, -0.00952095911, -0.00603102474,
+        -0.00208898913,
+    },
+    {
+        0.00335019873, 0.015625,      0.0728734732,  -0.0949705616,
+        -0.0377220884, -0.0254472848, -0.0195263885, -0.015625, -0.0125031117,
+        -0.0095939748, -0.006472087,  -0.0025706978,
+    },
+    {
+        0, 0, 0, 0, 0, 0, 0.00942282099,  0.0458101816,  0.218065813,
+        -0.284188896, -0.110595562,   -0.0715734288,  -0.0519610867,
+        -0.0408300944, -0.0338387601, -0.0290806089,  -0.0256668683,
+        -0.0231279247, 0, 0, -0.0211726688,  -0.0195263885,  -0.0180872418,
+        -0.0168000516, -0.015625, -0.0145321358,  -0.0134979468,  
-0.0125031117,
+        -0.011530933,  -0.0105661536, -0.0095939748,  -0.00859914068,
+        -0.0075649512, -0.006472087, -0.00529703591, -0.0040098452,
+        -0.0025706978,  -0.00092441868,
+    },
+    {
+        0.00100882596, -0.00335019873, 0.00629419601, -0.0101755112, 0.015625,
+        -0.0239929594, 0.0387882143, -0.0728734732, 0.242004707, 0.264101803,
+        -0.0949705616, 0.0608853027, -0.0460900478, 0.0377220884, 
-0.0322725996,
+        0.028391283, -0.0254472848, 0.0231059138, 0, 0, -0.0211726688,
+        0.0195263885, -0.0180872418, 0.0168000516, -0.015625, 0.0145321358,
+        -0.0134979468, 0.0125031117, -0.011530933, 0.0105661536, -0.0095939748,
+        0.00859914068, -0.0075649512, 0.006472087, -0.00529703591, 
0.0040098452,
+        -0.0025706978, 0.00092441868,
+    },
+    {
+        0.00100882596, -0.00335019873, 0.00629419601, -0.0101755112, 0.015625,
+        -0.0239929594, 0.0387882143, -0.0728734732, 0.242004707, 0.264101803,
+        -0.0949705616, 0.0608853027, -0.0460900478, 0.0377220884, 
-0.0322725996,
+        0.028391283, -0.0254472848, 0.0231059138, 0, 0, -0.0211928394,
+        0.0196948815, -0.0185263921, 0.0176153425, -0.0169123784, 0.0163832679,
+        -0.0158674475, 0.0145601816, -0.0124079557, 0.00952095911,
+        -0.00603102474, 0.00208898913,
+    },
+    {
+        0.00335019873, -0.015625, 0.0728734732, 0.0949705616, -0.0377220884,
+        0.0254472848, -0.0195263885, 0.015625, -0.0125031117, 0.0095939748,
+        -0.006472087, 0.0025706978,
+    },
+    {
+        0, 0, 0, 0, 0, 0, 0.00942282099, -0.0458101816, 0.218065813,
+        0.284188896, -0.110595562, 0.0715734288, -0.0519610867, 0.0408300944,
+        -0.0338387601, 0.0290806089, -0.0256668683, 0.0231279247, 0, -0,
+        -0.0211726688, 0.0195263885, -0.0180872418, 0.0168000516, -0.015625,
+        0.0145321358, -0.0134979468, 0.0125031117, -0.011530933, 0.0105661536,
+        -0.0095939748, 0.00859914068, -0.0075649512, 0.006472087,
+        -0.00529703591, 0.0040098452, -0.0025706978, 0.00092441868,
+    },
+#else
+    {
+        4332874, 14388994, 27033365, 43703487, 67108864, 103048977, 166594117,
+        312989196, 1039402296, -1134308560, -407895461, -261500382, -197955241,
+        -162015129, -138609752, -121939630, -109295259, -99239139, 0, 0,
+        -90935917, -83865201, -77684112, -72155669, -67108863, -62415047,
+        -57973238, -53700455, -49524980, -45381283, -41205808, -36933026,
+        -32491217, -27797401, -22750594, -17222152, -11041062, -3970347,
+    },
+    {
+        4332874, 14388994, 27033365, 43703487, 67108864, 103048977, 166594117,
+        312989196, 1039402296, -1134308560, -407895461, -261500382, -197955241,
+        -162015129, -138609752, -121939630, -109295259, -99239139, 0, 0,
+        -91022550, -84588871, -79570244, -75657321, -72638110, -70365597,
+        -68150168, -62535505, -53291762, -40892207, -25903054, -8972139,
+    },
+    {
+        14388994, 67108864, 312989196, -407895461, -162015129, -109295259,
+        -83865201, -67108863, -53700455, -41205808, -27797401, -11041062,
+    },
+    {
+        0, 0, 0, 0, 0, 0, 40470708, 196753234, 936585551, -1220582053,
+        -475004325, -307405548, -223171165, -175363912, -145336362, -124900265,
+        -110238363, -99333683, 0, 0, -90935917, -83865201, -77684112, 
-72155669,
+        -67108863, -62415047, -57973238, -53700455, -49524980, -45381283,
+        -41205808, -36933026, -32491217, -27797401, -22750594, -17222152,
+        -11041062, -3970347,
+    },
+    {
+        4332874, -14388994, 27033365, -43703487, 67108864, -103048977,
+        166594117, -312989196, 1039402296, 1134308560, -407895461, 261500382,
+        -197955241, 162015129, -138609752, 121939630, -109295259, 99239139, 0,
+        0, -90935917, 83865201, -77684112, 72155669, -67108863, 62415047,
+        -57973238, 53700455, -49524980, 45381283, -41205808, 36933026,
+        -32491217, 27797401, -22750594, 17222152, -11041062, 3970347,
+    },
+    {
+        4332874, -14388994, 27033365, -43703487, 67108864, -103048977,
+        166594117, -312989196, 1039402296, 1134308560, -407895461, 261500382,
+        -197955241, 162015129, -138609752, 121939630, -109295259, 99239139, 0,
+        0, -91022550, 84588871, -79570244, 75657321, -72638110, 70365597,
+        -68150168, 62535505, -53291762, 40892207, -25903054, 8972139,
+    },
+    {
+        14388994, -67108864, 312989196, 407895461, -162015129, 109295259,
+        -83865201, 67108863, -53700455, 41205808, -27797401, 11041062,
+    },
+    {
+        0, 0, 0, 0, 0, 0, 40470708, -196753234, 936585551, 1220582053,
+        -475004325, 307405548, -223171165, 175363912, -145336362, 124900265,
+        -110238363, 99333683, 0, 0, -90935917, 83865201, -77684112, 72155669,
+        -67108863, 62415047, -57973238, 53700455, -49524980, 45381283,
+        -41205808, 36933026, -32491217, 27797401, -22750594, 17222152,
+        -11041062, 3970347,
+    }
+#endif
+};
 
 DECLARE_ALIGNED(16, MPA_INT, RENAME(ff_mpa_synth_window))[512+256];
 
@@ -221,48 +391,6 @@ av_cold void RENAME(ff_mpa_synth_init)(MPA_INT *window)
             window[512+128+16*i+j] = window[64*i+48-j];
 }
 
-av_cold void RENAME(ff_init_mpadsp_tabs)(void)
-{
-    int i, j;
-    /* compute mdct windows */
-    for (i = 0; i < 36; i++) {
-        for (j = 0; j < 4; j++) {
-            double d;
-
-            if (j == 2 && i % 3 != 1)
-                continue;
-
-            d = sin(M_PI * (i + 0.5) / 36.0);
-            if (j == 1) {
-                if      (i >= 30) d = 0;
-                else if (i >= 24) d = sin(M_PI * (i - 18 + 0.5) / 12.0);
-                else if (i >= 18) d = 1;
-            } else if (j == 3) {
-                if      (i <   6) d = 0;
-                else if (i <  12) d = sin(M_PI * (i -  6 + 0.5) / 12.0);
-                else if (i <  18) d = 1;
-            }
-            //merge last stage of imdct into the window coefficients
-            d *= 0.5 / cos(M_PI * (2 * i + 19) / 72);
-
-            if (j == 2)
-                RENAME(ff_mdct_win)[j][i/3] = FIXHR((d / (1<<5)));
-            else {
-                int idx = i < 18 ? i : i + (MDCT_BUF_SIZE/2 - 18);
-                RENAME(ff_mdct_win)[j][idx] = FIXHR((d / (1<<5)));
-            }
-        }
-    }
-
-    /* NOTE: we do frequency inversion adter the MDCT by changing
-        the sign of the right window coefs */
-    for (j = 0; j < 4; j++) {
-        for (i = 0; i < MDCT_BUF_SIZE; i += 2) {
-            RENAME(ff_mdct_win)[j + 4][i    ] =  RENAME(ff_mdct_win)[j][i    ];
-            RENAME(ff_mdct_win)[j + 4][i + 1] = -RENAME(ff_mdct_win)[j][i + 1];
-        }
-    }
-}
 /* cos(pi*i/18) */
 #define C1 FIXHR(0.98480775301220805936/2)
 #define C2 FIXHR(0.93969262078590838405/2)
@@ -300,7 +428,7 @@ static const INTFLOAT icos36h[9] = {
 };
 
 /* using Lee like decomposition followed by hand coded 9 points DCT */
-static void imdct36(INTFLOAT *out, INTFLOAT *buf, INTFLOAT *in, INTFLOAT *win)
+static void imdct36(INTFLOAT *out, INTFLOAT *buf, INTFLOAT *in, const INTFLOAT 
*win)
 {
     int i, j;
     INTFLOAT t0, t1, t2, t3, s0, s1, s2, s3;
@@ -389,7 +517,7 @@ void RENAME(ff_imdct36_blocks)(INTFLOAT *out, INTFLOAT 
*buf, INTFLOAT *in,
 
         /* select window */
         int win_idx = (switch_point && j < 2) ? 0 : block_type;
-        INTFLOAT *win = RENAME(ff_mdct_win)[win_idx + (4 & -(j & 1))];
+        const INTFLOAT *win = RENAME(ff_mdct_win)[win_idx + (4 & -(j & 1))];
 
         imdct36(out, buf, in, win);
 
diff --git a/libavcodec/x86/mpegaudiodsp.c b/libavcodec/x86/mpegaudiodsp.c
index 591f527..73b783d 100644
--- a/libavcodec/x86/mpegaudiodsp.c
+++ b/libavcodec/x86/mpegaudiodsp.c
@@ -26,11 +26,11 @@
 #include "libavutil/x86/cpu.h"
 #include "libavcodec/mpegaudiodsp.h"
 
-void ff_imdct36_float_sse(float *out, float *buf, float *in, float *win);
-void ff_imdct36_float_sse2(float *out, float *buf, float *in, float *win);
-void ff_imdct36_float_sse3(float *out, float *buf, float *in, float *win);
-void ff_imdct36_float_ssse3(float *out, float *buf, float *in, float *win);
-void ff_imdct36_float_avx(float *out, float *buf, float *in, float *win);
+void ff_imdct36_float_sse  (float *out, float *buf, float *in, const float 
*win);
+void ff_imdct36_float_sse2 (float *out, float *buf, float *in, const float 
*win);
+void ff_imdct36_float_sse3 (float *out, float *buf, float *in, const float 
*win);
+void ff_imdct36_float_ssse3(float *out, float *buf, float *in, const float 
*win);
+void ff_imdct36_float_avx  (float *out, float *buf, float *in, const float 
*win);
 void ff_four_imdct36_float_sse(float *out, float *buf, float *in, float *win,
                                float *tmpbuf);
 void ff_four_imdct36_float_avx(float *out, float *buf, float *in, float *win,
@@ -207,7 +207,7 @@ static void imdct36_blocks_ ## CPU1(float *out, float *buf, 
float *in,      \
                                                                         \
         /* select window */                                             \
         int win_idx = (switch_point && j < 2) ? 0 : block_type;         \
-        float *win = ff_mdct_win_float[win_idx + (4 & -(j & 1))];       \
+        const float *win = ff_mdct_win_float[win_idx + (4 & -(j & 1))]; \
                                                                         \
         ff_imdct36_float_ ## CPU1(out, buf, in, win);                   \
                                                                         \
-- 
2.0.0

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

Reply via email to