Originally committed as revision 22525 to svn://svn.ffmpeg.org/ffmpeg/trunk
Reimar Döffinger authored on 2010/03/15 04:30:25... | ... |
@@ -42,15 +42,12 @@ |
42 | 42 |
#include "mpegaudio.h" |
43 | 43 |
|
44 | 44 |
#include "qdm2data.h" |
45 |
+#include "qdm2_tablegen.h" |
|
45 | 46 |
|
46 | 47 |
#undef NDEBUG |
47 | 48 |
#include <assert.h> |
48 | 49 |
|
49 | 50 |
|
50 |
-#define SOFTCLIP_THRESHOLD 27600 |
|
51 |
-#define HARDCLIP_THRESHOLD 35716 |
|
52 |
- |
|
53 |
- |
|
54 | 51 |
#define QDM2_LIST_ADD(list, size, packet) \ |
55 | 52 |
do { \ |
56 | 53 |
if (size > 0) { \ |
... | ... |
@@ -214,69 +211,6 @@ static VLC vlc_tab_type30; |
214 | 214 |
static VLC vlc_tab_type34; |
215 | 215 |
static VLC vlc_tab_fft_tone_offset[5]; |
216 | 216 |
|
217 |
-static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1]; |
|
218 |
-static float noise_table[4096]; |
|
219 |
-static uint8_t random_dequant_index[256][5]; |
|
220 |
-static uint8_t random_dequant_type24[128][3]; |
|
221 |
-static float noise_samples[128]; |
|
222 |
- |
|
223 |
- |
|
224 |
-static av_cold void softclip_table_init(void) { |
|
225 |
- int i; |
|
226 |
- double dfl = SOFTCLIP_THRESHOLD - 32767; |
|
227 |
- float delta = 1.0 / -dfl; |
|
228 |
- for (i = 0; i < HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1; i++) |
|
229 |
- softclip_table[i] = SOFTCLIP_THRESHOLD - ((int)(sin((float)i * delta) * dfl) & 0x0000FFFF); |
|
230 |
-} |
|
231 |
- |
|
232 |
- |
|
233 |
-// random generated table |
|
234 |
-static av_cold void rnd_table_init(void) { |
|
235 |
- int i,j; |
|
236 |
- uint32_t ldw,hdw; |
|
237 |
- uint64_t tmp64_1; |
|
238 |
- uint64_t random_seed = 0; |
|
239 |
- float delta = 1.0 / 16384.0; |
|
240 |
- for(i = 0; i < 4096 ;i++) { |
|
241 |
- random_seed = random_seed * 214013 + 2531011; |
|
242 |
- noise_table[i] = (delta * (float)(((int32_t)random_seed >> 16) & 0x00007FFF)- 1.0) * 1.3; |
|
243 |
- } |
|
244 |
- |
|
245 |
- for (i = 0; i < 256 ;i++) { |
|
246 |
- random_seed = 81; |
|
247 |
- ldw = i; |
|
248 |
- for (j = 0; j < 5 ;j++) { |
|
249 |
- random_dequant_index[i][j] = (uint8_t)((ldw / random_seed) & 0xFF); |
|
250 |
- ldw = (uint32_t)ldw % (uint32_t)random_seed; |
|
251 |
- tmp64_1 = (random_seed * 0x55555556); |
|
252 |
- hdw = (uint32_t)(tmp64_1 >> 32); |
|
253 |
- random_seed = (uint64_t)(hdw + (ldw >> 31)); |
|
254 |
- } |
|
255 |
- } |
|
256 |
- for (i = 0; i < 128 ;i++) { |
|
257 |
- random_seed = 25; |
|
258 |
- ldw = i; |
|
259 |
- for (j = 0; j < 3 ;j++) { |
|
260 |
- random_dequant_type24[i][j] = (uint8_t)((ldw / random_seed) & 0xFF); |
|
261 |
- ldw = (uint32_t)ldw % (uint32_t)random_seed; |
|
262 |
- tmp64_1 = (random_seed * 0x66666667); |
|
263 |
- hdw = (uint32_t)(tmp64_1 >> 33); |
|
264 |
- random_seed = hdw + (ldw >> 31); |
|
265 |
- } |
|
266 |
- } |
|
267 |
-} |
|
268 |
- |
|
269 |
- |
|
270 |
-static av_cold void init_noise_samples(void) { |
|
271 |
- int i; |
|
272 |
- int random_seed = 0; |
|
273 |
- float delta = 1.0 / 16384.0; |
|
274 |
- for (i = 0; i < 128;i++) { |
|
275 |
- random_seed = random_seed * 214013 + 2531011; |
|
276 |
- noise_samples[i] = (delta * (float)((random_seed >> 16) & 0x00007fff) - 1.0); |
|
277 |
- } |
|
278 |
-} |
|
279 |
- |
|
280 | 217 |
static const uint16_t qdm2_vlc_offs[] = { |
281 | 218 |
0,260,566,598,894,1166,1230,1294,1678,1950,2214,2278,2310,2570,2834,3124,3448,3838, |
282 | 219 |
}; |
283 | 220 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,73 @@ |
0 |
+/* |
|
1 |
+ * Generate a header file for hardcoded QDM2 tables |
|
2 |
+ * |
|
3 |
+ * Copyright (c) 2010 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 av_cold |
|
24 |
+#define CONFIG_HARDCODED_TABLES 0 |
|
25 |
+#include "qdm2_tablegen.h" |
|
26 |
+#include "tableprint.h" |
|
27 |
+ |
|
28 |
+void tableinit(void) |
|
29 |
+{ |
|
30 |
+ softclip_table_init(); |
|
31 |
+ rnd_table_init(); |
|
32 |
+ init_noise_samples(); |
|
33 |
+} |
|
34 |
+ |
|
35 |
+const struct tabledef tables[] = { |
|
36 |
+ { |
|
37 |
+ "static const uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1]", |
|
38 |
+ write_uint16_array, |
|
39 |
+ softclip_table, |
|
40 |
+ HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1, |
|
41 |
+ 0 |
|
42 |
+ }, |
|
43 |
+ { |
|
44 |
+ "static const float noise_table[4096]", |
|
45 |
+ write_float_array, |
|
46 |
+ noise_table, |
|
47 |
+ 4096, |
|
48 |
+ 0 |
|
49 |
+ }, |
|
50 |
+ { |
|
51 |
+ "static const uint8_t random_dequant_index[256][5]", |
|
52 |
+ write_uint8_2d_array, |
|
53 |
+ random_dequant_index, |
|
54 |
+ 256, |
|
55 |
+ 5 |
|
56 |
+ }, |
|
57 |
+ { |
|
58 |
+ "static const uint8_t random_dequant_type24[128][3]", |
|
59 |
+ write_uint8_2d_array, |
|
60 |
+ random_dequant_type24, |
|
61 |
+ 128, |
|
62 |
+ 3 |
|
63 |
+ }, |
|
64 |
+ { |
|
65 |
+ "static const float noise_samples[128]", |
|
66 |
+ write_float_array, |
|
67 |
+ noise_samples, |
|
68 |
+ 128, |
|
69 |
+ 0 |
|
70 |
+ }, |
|
71 |
+ { NULL } |
|
72 |
+}; |
0 | 73 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,101 @@ |
0 |
+/* |
|
1 |
+ * Header file for hardcoded QDM2 tables |
|
2 |
+ * |
|
3 |
+ * Copyright (c) 2010 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 |
+#ifndef QDM2_TABLEGEN_H |
|
23 |
+#define QDM2_TABLEGEN_H |
|
24 |
+ |
|
25 |
+#include <stdint.h> |
|
26 |
+#include <math.h> |
|
27 |
+ |
|
28 |
+#define SOFTCLIP_THRESHOLD 27600 |
|
29 |
+#define HARDCLIP_THRESHOLD 35716 |
|
30 |
+ |
|
31 |
+#if CONFIG_HARDCODED_TABLES |
|
32 |
+#define softclip_table_init() |
|
33 |
+#define rnd_table_init() |
|
34 |
+#define init_noise_samples() |
|
35 |
+#include "libavcodec/qdm2_tables.h" |
|
36 |
+#else |
|
37 |
+static uint16_t softclip_table[HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1]; |
|
38 |
+static float noise_table[4096]; |
|
39 |
+static uint8_t random_dequant_index[256][5]; |
|
40 |
+static uint8_t random_dequant_type24[128][3]; |
|
41 |
+static float noise_samples[128]; |
|
42 |
+ |
|
43 |
+static av_cold void softclip_table_init(void) { |
|
44 |
+ int i; |
|
45 |
+ double dfl = SOFTCLIP_THRESHOLD - 32767; |
|
46 |
+ float delta = 1.0 / -dfl; |
|
47 |
+ for (i = 0; i < HARDCLIP_THRESHOLD - SOFTCLIP_THRESHOLD + 1; i++) |
|
48 |
+ softclip_table[i] = SOFTCLIP_THRESHOLD - ((int)(sin((float)i * delta) * dfl) & 0x0000FFFF); |
|
49 |
+} |
|
50 |
+ |
|
51 |
+ |
|
52 |
+// random generated table |
|
53 |
+static av_cold void rnd_table_init(void) { |
|
54 |
+ int i,j; |
|
55 |
+ uint32_t ldw,hdw; |
|
56 |
+ uint64_t tmp64_1; |
|
57 |
+ uint64_t random_seed = 0; |
|
58 |
+ float delta = 1.0 / 16384.0; |
|
59 |
+ for(i = 0; i < 4096 ;i++) { |
|
60 |
+ random_seed = random_seed * 214013 + 2531011; |
|
61 |
+ noise_table[i] = (delta * (float)(((int32_t)random_seed >> 16) & 0x00007FFF)- 1.0) * 1.3; |
|
62 |
+ } |
|
63 |
+ |
|
64 |
+ for (i = 0; i < 256 ;i++) { |
|
65 |
+ random_seed = 81; |
|
66 |
+ ldw = i; |
|
67 |
+ for (j = 0; j < 5 ;j++) { |
|
68 |
+ random_dequant_index[i][j] = (uint8_t)((ldw / random_seed) & 0xFF); |
|
69 |
+ ldw = (uint32_t)ldw % (uint32_t)random_seed; |
|
70 |
+ tmp64_1 = (random_seed * 0x55555556); |
|
71 |
+ hdw = (uint32_t)(tmp64_1 >> 32); |
|
72 |
+ random_seed = (uint64_t)(hdw + (ldw >> 31)); |
|
73 |
+ } |
|
74 |
+ } |
|
75 |
+ for (i = 0; i < 128 ;i++) { |
|
76 |
+ random_seed = 25; |
|
77 |
+ ldw = i; |
|
78 |
+ for (j = 0; j < 3 ;j++) { |
|
79 |
+ random_dequant_type24[i][j] = (uint8_t)((ldw / random_seed) & 0xFF); |
|
80 |
+ ldw = (uint32_t)ldw % (uint32_t)random_seed; |
|
81 |
+ tmp64_1 = (random_seed * 0x66666667); |
|
82 |
+ hdw = (uint32_t)(tmp64_1 >> 33); |
|
83 |
+ random_seed = hdw + (ldw >> 31); |
|
84 |
+ } |
|
85 |
+ } |
|
86 |
+} |
|
87 |
+ |
|
88 |
+ |
|
89 |
+static av_cold void init_noise_samples(void) { |
|
90 |
+ int i; |
|
91 |
+ int random_seed = 0; |
|
92 |
+ float delta = 1.0 / 16384.0; |
|
93 |
+ for (i = 0; i < 128;i++) { |
|
94 |
+ random_seed = random_seed * 214013 + 2531011; |
|
95 |
+ noise_samples[i] = (delta * (float)((random_seed >> 16) & 0x00007fff) - 1.0); |
|
96 |
+ } |
|
97 |
+} |
|
98 |
+#endif /* CONFIG_HARDCODED_TABLES */ |
|
99 |
+ |
|
100 |
+#endif /* QDM2_TABLEGEN_H */ |