Browse code

Add support for hard-coded MDCT-related ff_sine_windows tables.

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

Reimar Döffinger authored on 2010/01/09 22:28:04
Showing 14 changed files
... ...
@@ -697,6 +697,7 @@ $(SUBDIR)%_tables.h: $(SUBDIR)%_tablegen$(HOSTEXESUF)
697 697
 	./$< > $@
698 698
 
699 699
 ifdef CONFIG_HARDCODED_TABLES
700
+$(SUBDIR)mdct.o: $(SUBDIR)mdct_tables.h
700 701
 $(SUBDIR)mpegaudiodec.o: $(SUBDIR)mpegaudio_tables.h
701 702
 $(SUBDIR)motionpixels.o: $(SUBDIR)motionpixels_tables.h
702 703
 endif
... ...
@@ -552,8 +552,8 @@ static av_cold int aac_decode_init(AVCodecContext *avccontext)
552 552
     // window initialization
553 553
     ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
554 554
     ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
555
-    ff_sine_window_init(ff_sine_1024, 1024);
556
-    ff_sine_window_init(ff_sine_128, 128);
555
+    ff_init_ff_sine_windows(10);
556
+    ff_init_ff_sine_windows( 7);
557 557
 
558 558
     return 0;
559 559
 }
... ...
@@ -178,8 +178,8 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
178 178
     // window init
179 179
     ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
180 180
     ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
181
-    ff_sine_window_init(ff_sine_1024, 1024);
182
-    ff_sine_window_init(ff_sine_128, 128);
181
+    ff_init_ff_sine_windows(10);
182
+    ff_init_ff_sine_windows(7);
183 183
 
184 184
     s->samples            = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0]));
185 185
     s->cpe                = av_mallocz(sizeof(ChannelElement) * aac_chan_configs[avctx->channels-1][0]);
... ...
@@ -339,7 +339,7 @@ static av_cold int atrac1_decode_init(AVCodecContext *avctx)
339 339
     ff_mdct_init(&q->mdct_ctx[1], 8, 1, -1.0/ (1 << 15));
340 340
     ff_mdct_init(&q->mdct_ctx[2], 9, 1, -1.0/ (1 << 15));
341 341
 
342
-    ff_sine_window_init(ff_sine_32, 32);
342
+    ff_init_ff_sine_windows(5);
343 343
 
344 344
     atrac_generate_tables();
345 345
 
... ...
@@ -741,15 +741,19 @@ typedef struct FFTContext {
741 741
 #if CONFIG_HARDCODED_TABLES
742 742
 #define COSTABLE_CONST const
743 743
 #define SINTABLE_CONST const
744
+#define SINETABLE_CONST const
744 745
 #else
745 746
 #define COSTABLE_CONST
746 747
 #define SINTABLE_CONST
748
+#define SINETABLE_CONST
747 749
 #endif
748 750
 
749 751
 #define COSTABLE(size) \
750 752
     COSTABLE_CONST DECLARE_ALIGNED_16(FFTSample, ff_cos_##size[size/2])
751 753
 #define SINTABLE(size) \
752 754
     SINTABLE_CONST DECLARE_ALIGNED_16(FFTSample, ff_sin_##size[size/2])
755
+#define SINETABLE(size) \
756
+    SINETABLE_CONST DECLARE_ALIGNED_16(float, ff_sine_##size[size])
753 757
 extern COSTABLE(16);
754 758
 extern COSTABLE(32);
755 759
 extern COSTABLE(64);
... ...
@@ -846,15 +850,19 @@ void ff_kbd_window_init(float *window, float alpha, int n);
846 846
  * @param   n       size of half window
847 847
  */
848 848
 void ff_sine_window_init(float *window, int n);
849
-extern float ff_sine_32  [  32];
850
-extern float ff_sine_64  [  64];
851
-extern float ff_sine_128 [ 128];
852
-extern float ff_sine_256 [ 256];
853
-extern float ff_sine_512 [ 512];
854
-extern float ff_sine_1024[1024];
855
-extern float ff_sine_2048[2048];
856
-extern float ff_sine_4096[4096];
857
-extern float * const ff_sine_windows[13];
849
+/**
850
+ * initialize the specified entry of ff_sine_windows
851
+ */
852
+void ff_init_ff_sine_windows(int index);
853
+extern SINETABLE(  32);
854
+extern SINETABLE(  64);
855
+extern SINETABLE( 128);
856
+extern SINETABLE( 256);
857
+extern SINETABLE( 512);
858
+extern SINETABLE(1024);
859
+extern SINETABLE(2048);
860
+extern SINETABLE(4096);
861
+extern SINETABLE_CONST float * const ff_sine_windows[13];
858 862
 
859 863
 int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale);
860 864
 void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input);
... ...
@@ -48,26 +48,7 @@ av_cold void ff_kbd_window_init(float *window, float alpha, int n)
48 48
        window[i] = sqrt(local_window[i] / sum);
49 49
 }
50 50
 
51
-DECLARE_ALIGNED(16, float, ff_sine_32  [  32]);
52
-DECLARE_ALIGNED(16, float, ff_sine_64  [  64]);
53
-DECLARE_ALIGNED(16, float, ff_sine_128 [ 128]);
54
-DECLARE_ALIGNED(16, float, ff_sine_256 [ 256]);
55
-DECLARE_ALIGNED(16, float, ff_sine_512 [ 512]);
56
-DECLARE_ALIGNED(16, float, ff_sine_1024[1024]);
57
-DECLARE_ALIGNED(16, float, ff_sine_2048[2048]);
58
-DECLARE_ALIGNED(16, float, ff_sine_4096[4096]);
59
-float * const ff_sine_windows[] = {
60
-    NULL, NULL, NULL, NULL, NULL, // unused
61
-    ff_sine_32 , ff_sine_64 ,
62
-    ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096
63
-};
64
-
65
-// Generate a sine window.
66
-av_cold void ff_sine_window_init(float *window, int n) {
67
-    int i;
68
-    for(i = 0; i < n; i++)
69
-        window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n)));
70
-}
51
+#include "mdct_tablegen.h"
71 52
 
72 53
 /**
73 54
  * init MDCT or IMDCT computation.
74 55
new file mode 100644
... ...
@@ -0,0 +1,61 @@
0
+/*
1
+ * Generate a header file for hardcoded MDCT tables
2
+ *
3
+ * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
4
+ *
5
+ * This file is part of FFmpeg.
6
+ *
7
+ * FFmpeg is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * FFmpeg is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with FFmpeg; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+#include <stdlib.h>
23
+#define CONFIG_HARDCODED_TABLES 0
24
+#define av_cold
25
+#define SINETABLE_CONST
26
+#define SINETABLE(size) \
27
+    float ff_sine_##size[size]
28
+#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
29
+#ifndef M_PI
30
+#define M_PI 3.14159265358979323846
31
+#endif
32
+#include "mdct_tablegen.h"
33
+#include "tableprint.h"
34
+
35
+void tableinit(void)
36
+{
37
+    int i;
38
+    for (i = 5; i <= 12; i++)
39
+        ff_init_ff_sine_windows(i);
40
+}
41
+
42
+#define SINE_TABLE_DEF(size) \
43
+    { \
44
+        "SINETABLE("#size")", \
45
+        write_float_array, \
46
+        ff_sine_##size, \
47
+        size \
48
+    },
49
+
50
+const struct tabledef tables[] = {
51
+    SINE_TABLE_DEF(  32)
52
+    SINE_TABLE_DEF(  64)
53
+    SINE_TABLE_DEF( 128)
54
+    SINE_TABLE_DEF( 256)
55
+    SINE_TABLE_DEF( 512)
56
+    SINE_TABLE_DEF(1024)
57
+    SINE_TABLE_DEF(2048)
58
+    SINE_TABLE_DEF(4096)
59
+    { NULL }
60
+};
0 61
new file mode 100644
... ...
@@ -0,0 +1,59 @@
0
+/*
1
+ * Header file for hardcoded MDCT tables
2
+ *
3
+ * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
4
+ *
5
+ * This file is part of FFmpeg.
6
+ *
7
+ * FFmpeg is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * FFmpeg is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with FFmpeg; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+#include <assert.h>
23
+// do not use libavutil/mathematics.h since this is compiled both
24
+// for the host and the target and config.h is only valid for the target
25
+#include <math.h>
26
+
27
+#if !CONFIG_HARDCODED_TABLES
28
+SINETABLE(  32);
29
+SINETABLE(  64);
30
+SINETABLE( 128);
31
+SINETABLE( 256);
32
+SINETABLE( 512);
33
+SINETABLE(1024);
34
+SINETABLE(2048);
35
+SINETABLE(4096);
36
+#else
37
+#include "mdct_tables.h"
38
+#endif
39
+
40
+SINETABLE_CONST float * const ff_sine_windows[] = {
41
+    NULL, NULL, NULL, NULL, NULL, // unused
42
+    ff_sine_32 , ff_sine_64 ,
43
+    ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096
44
+};
45
+
46
+// Generate a sine window.
47
+av_cold void ff_sine_window_init(float *window, int n) {
48
+    int i;
49
+    for(i = 0; i < n; i++)
50
+        window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n)));
51
+}
52
+
53
+av_cold void ff_init_ff_sine_windows(int index) {
54
+    assert(index >= 0 && index < FF_ARRAY_ELEMS(ff_sine_windows));
55
+#if !CONFIG_HARDCODED_TABLES
56
+    ff_sine_window_init(ff_sine_windows[index], 1 << index);
57
+#endif
58
+}
... ...
@@ -144,7 +144,7 @@ static av_cold int decode_init(AVCodecContext * avctx) {
144 144
 
145 145
     /* Generate overlap window */
146 146
     if (!ff_sine_128[127])
147
-        ff_sine_window_init(ff_sine_128, 128);
147
+        ff_init_ff_sine_windows(7);
148 148
 
149 149
     avctx->sample_fmt = SAMPLE_FMT_S16;
150 150
     avctx->channel_layout = CH_LAYOUT_MONO;
... ...
@@ -39,6 +39,7 @@ void write_##name##_array(const void *arg, int len, int dummy)\
39 39
 
40 40
 WRITE_1D_FUNC(int8,   int8_t,   "%3"PRIi8, 15)
41 41
 WRITE_1D_FUNC(uint32, uint32_t, "0x%08"PRIx32, 7)
42
+WRITE_1D_FUNC(float,  float,    "%.18e", 3)
42 43
 
43 44
 #define WRITE_2D_FUNC(name, type)\
44 45
 void write_##name##_2d_array(const void *arg, int len, int len2)\
... ...
@@ -32,6 +32,7 @@
32 32
  */
33 33
 void write_int8_array     (const void *, int, int);
34 34
 void write_uint32_array   (const void *, int, int);
35
+void write_float_array    (const void *, int, int);
35 36
 void write_int8_2d_array  (const void *, int, int);
36 37
 void write_uint32_2d_array(const void *, int, int);
37 38
 /** \} */ // end of printfuncs group
... ...
@@ -893,9 +893,9 @@ static av_cold void init_mdct_win(TwinContext *tctx)
893 893
     }
894 894
 
895 895
 
896
-    ff_sine_window_init(ff_sine_windows[av_log2(size_m)    ], size_m  );
897
-    ff_sine_window_init(ff_sine_windows[av_log2(size_s/2)  ], size_s/2);
898
-    ff_sine_window_init(ff_sine_windows[av_log2(mtab->size)], mtab->size);
896
+    ff_init_ff_sine_windows(av_log2(size_m));
897
+    ff_init_ff_sine_windows(av_log2(size_s/2));
898
+    ff_init_ff_sine_windows(av_log2(mtab->size));
899 899
 }
900 900
 
901 901
 /**
... ...
@@ -343,9 +343,7 @@ int ff_wma_init(AVCodecContext *avctx, int flags2)
343 343
 
344 344
     /* init MDCT windows : simple sinus window */
345 345
     for (i = 0; i < s->nb_block_sizes; i++) {
346
-        int n;
347
-        n = 1 << (s->frame_len_bits - i);
348
-        ff_sine_window_init(ff_sine_windows[s->frame_len_bits - i], n);
346
+        ff_init_ff_sine_windows(s->frame_len_bits - i);
349 347
         s->windows[i] = ff_sine_windows[s->frame_len_bits - i];
350 348
     }
351 349
 
... ...
@@ -425,9 +425,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
425 425
 
426 426
     /** init MDCT windows: simple sinus window */
427 427
     for (i = 0; i < WMAPRO_BLOCK_SIZES; i++) {
428
-        const int n       = 1 << (WMAPRO_BLOCK_MAX_BITS - i);
429 428
         const int win_idx = WMAPRO_BLOCK_MAX_BITS - i;
430
-        ff_sine_window_init(ff_sine_windows[win_idx], n);
429
+        ff_init_ff_sine_windows(win_idx);
431 430
         s->windows[WMAPRO_BLOCK_SIZES - i - 1] = ff_sine_windows[win_idx];
432 431
     }
433 432