Mercurial > mplayer.hg
annotate liba52/imdct.c @ 8839:c932c17042bf
For solaris, sys/smedia.h header is not needed any more. Compilation was
failing on Solaris 7, where sys/smedia.h is not available.
author | jkeil |
---|---|
date | Wed, 08 Jan 2003 14:11:33 +0000 |
parents | fb88ccbc5ccc |
children | 01a9cf43074c |
rev | line source |
---|---|
3394 | 1 /* |
2 * imdct.c | |
3 * Copyright (C) 2000-2001 Michel Lespinasse <walken@zoy.org> | |
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | |
5 * | |
6 * This file is part of a52dec, a free ATSC A-52 stream decoder. | |
7 * See http://liba52.sourceforge.net/ for updates. | |
8 * | |
9 * a52dec is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * a52dec is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
3579 | 22 * |
23 * SSE optimizations from Michael Niedermayer (michaelni@gmx.at) | |
3884 | 24 * 3DNOW optimizations from Nick Kurshev <nickols_k@mail.ru> |
25 * michael did port them from libac3 (untested, perhaps totally broken) | |
3394 | 26 */ |
27 | |
28 #include "config.h" | |
29 | |
30 #include <math.h> | |
31 #include <stdio.h> | |
32 #ifndef M_PI | |
33 #define M_PI 3.1415926535897932384626433832795029 | |
34 #endif | |
35 #include <inttypes.h> | |
36 | |
37 #include "a52.h" | |
38 #include "a52_internal.h" | |
39 #include "mm_accel.h" | |
4247
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
40 #include "mangle.h" |
3394 | 41 |
3884 | 42 #ifdef RUNTIME_CPUDETECT |
43 #undef HAVE_3DNOWEX | |
44 #endif | |
45 | |
46 #define USE_AC3_C | |
47 | |
3394 | 48 void (* imdct_256) (sample_t data[], sample_t delay[], sample_t bias); |
49 void (* imdct_512) (sample_t data[], sample_t delay[], sample_t bias); | |
50 | |
51 typedef struct complex_s { | |
52 sample_t real; | |
53 sample_t imag; | |
54 } complex_t; | |
55 | |
3884 | 56 static void fft_128p(complex_t *a); |
57 | |
58 static const int pm128[128] __attribute__((aligned(16))) = | |
59 { | |
60 0, 16, 32, 48, 64, 80, 96, 112, 8, 40, 72, 104, 24, 56, 88, 120, | |
61 4, 20, 36, 52, 68, 84, 100, 116, 12, 28, 44, 60, 76, 92, 108, 124, | |
62 2, 18, 34, 50, 66, 82, 98, 114, 10, 42, 74, 106, 26, 58, 90, 122, | |
63 6, 22, 38, 54, 70, 86, 102, 118, 14, 46, 78, 110, 30, 62, 94, 126, | |
64 1, 17, 33, 49, 65, 81, 97, 113, 9, 41, 73, 105, 25, 57, 89, 121, | |
65 5, 21, 37, 53, 69, 85, 101, 117, 13, 29, 45, 61, 77, 93, 109, 125, | |
66 3, 19, 35, 51, 67, 83, 99, 115, 11, 43, 75, 107, 27, 59, 91, 123, | |
67 7, 23, 39, 55, 71, 87, 103, 119, 15, 31, 47, 63, 79, 95, 111, 127 | |
68 }; | |
3394 | 69 |
70 /* 128 point bit-reverse LUT */ | |
71 static uint8_t bit_reverse_512[] = { | |
72 0x00, 0x40, 0x20, 0x60, 0x10, 0x50, 0x30, 0x70, | |
73 0x08, 0x48, 0x28, 0x68, 0x18, 0x58, 0x38, 0x78, | |
74 0x04, 0x44, 0x24, 0x64, 0x14, 0x54, 0x34, 0x74, | |
75 0x0c, 0x4c, 0x2c, 0x6c, 0x1c, 0x5c, 0x3c, 0x7c, | |
76 0x02, 0x42, 0x22, 0x62, 0x12, 0x52, 0x32, 0x72, | |
77 0x0a, 0x4a, 0x2a, 0x6a, 0x1a, 0x5a, 0x3a, 0x7a, | |
78 0x06, 0x46, 0x26, 0x66, 0x16, 0x56, 0x36, 0x76, | |
79 0x0e, 0x4e, 0x2e, 0x6e, 0x1e, 0x5e, 0x3e, 0x7e, | |
80 0x01, 0x41, 0x21, 0x61, 0x11, 0x51, 0x31, 0x71, | |
81 0x09, 0x49, 0x29, 0x69, 0x19, 0x59, 0x39, 0x79, | |
82 0x05, 0x45, 0x25, 0x65, 0x15, 0x55, 0x35, 0x75, | |
83 0x0d, 0x4d, 0x2d, 0x6d, 0x1d, 0x5d, 0x3d, 0x7d, | |
84 0x03, 0x43, 0x23, 0x63, 0x13, 0x53, 0x33, 0x73, | |
85 0x0b, 0x4b, 0x2b, 0x6b, 0x1b, 0x5b, 0x3b, 0x7b, | |
86 0x07, 0x47, 0x27, 0x67, 0x17, 0x57, 0x37, 0x77, | |
87 0x0f, 0x4f, 0x2f, 0x6f, 0x1f, 0x5f, 0x3f, 0x7f}; | |
88 | |
89 static uint8_t bit_reverse_256[] = { | |
90 0x00, 0x20, 0x10, 0x30, 0x08, 0x28, 0x18, 0x38, | |
91 0x04, 0x24, 0x14, 0x34, 0x0c, 0x2c, 0x1c, 0x3c, | |
92 0x02, 0x22, 0x12, 0x32, 0x0a, 0x2a, 0x1a, 0x3a, | |
93 0x06, 0x26, 0x16, 0x36, 0x0e, 0x2e, 0x1e, 0x3e, | |
94 0x01, 0x21, 0x11, 0x31, 0x09, 0x29, 0x19, 0x39, | |
95 0x05, 0x25, 0x15, 0x35, 0x0d, 0x2d, 0x1d, 0x3d, | |
96 0x03, 0x23, 0x13, 0x33, 0x0b, 0x2b, 0x1b, 0x3b, | |
97 0x07, 0x27, 0x17, 0x37, 0x0f, 0x2f, 0x1f, 0x3f}; | |
98 | |
3579 | 99 #ifdef ARCH_X86 |
3508 | 100 // NOTE: SSE needs 16byte alignment or it will segfault |
3581 | 101 // |
3508 | 102 static complex_t __attribute__((aligned(16))) buf[128]; |
3581 | 103 static float __attribute__((aligned(16))) sseSinCos1c[256]; |
104 static float __attribute__((aligned(16))) sseSinCos1d[256]; | |
3512 | 105 static float __attribute__((aligned(16))) ps111_1[4]={1,1,1,-1}; |
3534 | 106 //static float __attribute__((aligned(16))) sseW0[4]; |
107 static float __attribute__((aligned(16))) sseW1[8]; | |
108 static float __attribute__((aligned(16))) sseW2[16]; | |
109 static float __attribute__((aligned(16))) sseW3[32]; | |
110 static float __attribute__((aligned(16))) sseW4[64]; | |
111 static float __attribute__((aligned(16))) sseW5[128]; | |
112 static float __attribute__((aligned(16))) sseW6[256]; | |
113 static float __attribute__((aligned(16))) *sseW[7]= | |
114 {NULL /*sseW0*/,sseW1,sseW2,sseW3,sseW4,sseW5,sseW6}; | |
3553 | 115 static float __attribute__((aligned(16))) sseWindow[512]; |
3508 | 116 #else |
3394 | 117 static complex_t buf[128]; |
3508 | 118 #endif |
3394 | 119 |
120 /* Twiddle factor LUT */ | |
121 static complex_t w_1[1]; | |
122 static complex_t w_2[2]; | |
123 static complex_t w_4[4]; | |
124 static complex_t w_8[8]; | |
125 static complex_t w_16[16]; | |
126 static complex_t w_32[32]; | |
127 static complex_t w_64[64]; | |
128 static complex_t * w[7] = {w_1, w_2, w_4, w_8, w_16, w_32, w_64}; | |
129 | |
130 /* Twiddle factors for IMDCT */ | |
131 static sample_t xcos1[128]; | |
132 static sample_t xsin1[128]; | |
133 static sample_t xcos2[64]; | |
134 static sample_t xsin2[64]; | |
135 | |
136 /* Windowing function for Modified DCT - Thank you acroread */ | |
137 sample_t imdct_window[] = { | |
138 0.00014, 0.00024, 0.00037, 0.00051, 0.00067, 0.00086, 0.00107, 0.00130, | |
139 0.00157, 0.00187, 0.00220, 0.00256, 0.00297, 0.00341, 0.00390, 0.00443, | |
140 0.00501, 0.00564, 0.00632, 0.00706, 0.00785, 0.00871, 0.00962, 0.01061, | |
141 0.01166, 0.01279, 0.01399, 0.01526, 0.01662, 0.01806, 0.01959, 0.02121, | |
142 0.02292, 0.02472, 0.02662, 0.02863, 0.03073, 0.03294, 0.03527, 0.03770, | |
143 0.04025, 0.04292, 0.04571, 0.04862, 0.05165, 0.05481, 0.05810, 0.06153, | |
144 0.06508, 0.06878, 0.07261, 0.07658, 0.08069, 0.08495, 0.08935, 0.09389, | |
145 0.09859, 0.10343, 0.10842, 0.11356, 0.11885, 0.12429, 0.12988, 0.13563, | |
146 0.14152, 0.14757, 0.15376, 0.16011, 0.16661, 0.17325, 0.18005, 0.18699, | |
147 0.19407, 0.20130, 0.20867, 0.21618, 0.22382, 0.23161, 0.23952, 0.24757, | |
148 0.25574, 0.26404, 0.27246, 0.28100, 0.28965, 0.29841, 0.30729, 0.31626, | |
149 0.32533, 0.33450, 0.34376, 0.35311, 0.36253, 0.37204, 0.38161, 0.39126, | |
150 0.40096, 0.41072, 0.42054, 0.43040, 0.44030, 0.45023, 0.46020, 0.47019, | |
151 0.48020, 0.49022, 0.50025, 0.51028, 0.52031, 0.53033, 0.54033, 0.55031, | |
152 0.56026, 0.57019, 0.58007, 0.58991, 0.59970, 0.60944, 0.61912, 0.62873, | |
153 0.63827, 0.64774, 0.65713, 0.66643, 0.67564, 0.68476, 0.69377, 0.70269, | |
154 0.71150, 0.72019, 0.72877, 0.73723, 0.74557, 0.75378, 0.76186, 0.76981, | |
155 0.77762, 0.78530, 0.79283, 0.80022, 0.80747, 0.81457, 0.82151, 0.82831, | |
156 0.83496, 0.84145, 0.84779, 0.85398, 0.86001, 0.86588, 0.87160, 0.87716, | |
157 0.88257, 0.88782, 0.89291, 0.89785, 0.90264, 0.90728, 0.91176, 0.91610, | |
158 0.92028, 0.92432, 0.92822, 0.93197, 0.93558, 0.93906, 0.94240, 0.94560, | |
159 0.94867, 0.95162, 0.95444, 0.95713, 0.95971, 0.96217, 0.96451, 0.96674, | |
160 0.96887, 0.97089, 0.97281, 0.97463, 0.97635, 0.97799, 0.97953, 0.98099, | |
161 0.98236, 0.98366, 0.98488, 0.98602, 0.98710, 0.98811, 0.98905, 0.98994, | |
162 0.99076, 0.99153, 0.99225, 0.99291, 0.99353, 0.99411, 0.99464, 0.99513, | |
163 0.99558, 0.99600, 0.99639, 0.99674, 0.99706, 0.99736, 0.99763, 0.99788, | |
164 0.99811, 0.99831, 0.99850, 0.99867, 0.99882, 0.99895, 0.99908, 0.99919, | |
165 0.99929, 0.99938, 0.99946, 0.99953, 0.99959, 0.99965, 0.99969, 0.99974, | |
166 0.99978, 0.99981, 0.99984, 0.99986, 0.99988, 0.99990, 0.99992, 0.99993, | |
167 0.99994, 0.99995, 0.99996, 0.99997, 0.99998, 0.99998, 0.99998, 0.99999, | |
168 0.99999, 0.99999, 0.99999, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, | |
169 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000 }; | |
170 | |
171 | |
172 static inline void swap_cmplx(complex_t *a, complex_t *b) | |
173 { | |
174 complex_t tmp; | |
175 | |
176 tmp = *a; | |
177 *a = *b; | |
178 *b = tmp; | |
179 } | |
180 | |
181 | |
182 | |
183 static inline complex_t cmplx_mult(complex_t a, complex_t b) | |
184 { | |
185 complex_t ret; | |
186 | |
187 ret.real = a.real * b.real - a.imag * b.imag; | |
188 ret.imag = a.real * b.imag + a.imag * b.real; | |
189 | |
190 return ret; | |
191 } | |
192 | |
193 void | |
194 imdct_do_512(sample_t data[],sample_t delay[], sample_t bias) | |
195 { | |
8254
772d6d27fd66
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michael
parents:
4497
diff
changeset
|
196 int i; |
772d6d27fd66
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michael
parents:
4497
diff
changeset
|
197 #ifndef USE_AC3_C |
772d6d27fd66
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michael
parents:
4497
diff
changeset
|
198 int k; |
3394 | 199 int p,q; |
200 int m; | |
201 int two_m; | |
202 int two_m_plus_one; | |
203 | |
8254
772d6d27fd66
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michael
parents:
4497
diff
changeset
|
204 sample_t tmp_b_i; |
772d6d27fd66
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michael
parents:
4497
diff
changeset
|
205 sample_t tmp_b_r; |
772d6d27fd66
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michael
parents:
4497
diff
changeset
|
206 #endif |
3394 | 207 sample_t tmp_a_i; |
208 sample_t tmp_a_r; | |
209 | |
210 sample_t *data_ptr; | |
211 sample_t *delay_ptr; | |
212 sample_t *window_ptr; | |
213 | |
214 /* 512 IMDCT with source and dest data in 'data' */ | |
215 | |
3884 | 216 /* Pre IFFT complex multiply plus IFFT cmplx conjugate & reordering*/ |
3394 | 217 for( i=0; i < 128; i++) { |
218 /* z[i] = (X[256-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) ; */ | |
3884 | 219 #ifdef USE_AC3_C |
220 int j= pm128[i]; | |
221 #else | |
222 int j= bit_reverse_512[i]; | |
223 #endif | |
224 buf[i].real = (data[256-2*j-1] * xcos1[j]) - (data[2*j] * xsin1[j]); | |
225 buf[i].imag = -1.0 * ((data[2*j] * xcos1[j]) + (data[256-2*j-1] * xsin1[j])); | |
3394 | 226 } |
227 | |
228 /* FFT Merge */ | |
3549 | 229 /* unoptimized variant |
230 for (m=1; m < 7; m++) { | |
231 if(m) | |
232 two_m = (1 << m); | |
233 else | |
234 two_m = 1; | |
235 | |
236 two_m_plus_one = (1 << (m+1)); | |
237 | |
238 for(i = 0; i < 128; i += two_m_plus_one) { | |
239 for(k = 0; k < two_m; k++) { | |
240 p = k + i; | |
241 q = p + two_m; | |
3508 | 242 tmp_a_r = buf[p].real; |
243 tmp_a_i = buf[p].imag; | |
3549 | 244 tmp_b_r = buf[q].real * w[m][k].real - buf[q].imag * w[m][k].imag; |
245 tmp_b_i = buf[q].imag * w[m][k].real + buf[q].real * w[m][k].imag; | |
3508 | 246 buf[p].real = tmp_a_r + tmp_b_r; |
247 buf[p].imag = tmp_a_i + tmp_b_i; | |
248 buf[q].real = tmp_a_r - tmp_b_r; | |
249 buf[q].imag = tmp_a_i - tmp_b_i; | |
3549 | 250 } |
251 } | |
252 } | |
253 */ | |
3884 | 254 #ifdef USE_AC3_C |
255 fft_128p (&buf[0]); | |
256 #else | |
257 | |
3623 | 258 /* 1. iteration */ |
3579 | 259 for(i = 0; i < 128; i += 2) { |
260 tmp_a_r = buf[i].real; | |
261 tmp_a_i = buf[i].imag; | |
262 tmp_b_r = buf[i+1].real; | |
263 tmp_b_i = buf[i+1].imag; | |
264 buf[i].real = tmp_a_r + tmp_b_r; | |
265 buf[i].imag = tmp_a_i + tmp_b_i; | |
266 buf[i+1].real = tmp_a_r - tmp_b_r; | |
267 buf[i+1].imag = tmp_a_i - tmp_b_i; | |
268 } | |
269 | |
3623 | 270 /* 2. iteration */ |
3579 | 271 // Note w[1]={{1,0}, {0,-1}} |
272 for(i = 0; i < 128; i += 4) { | |
273 tmp_a_r = buf[i].real; | |
274 tmp_a_i = buf[i].imag; | |
275 tmp_b_r = buf[i+2].real; | |
276 tmp_b_i = buf[i+2].imag; | |
277 buf[i].real = tmp_a_r + tmp_b_r; | |
278 buf[i].imag = tmp_a_i + tmp_b_i; | |
279 buf[i+2].real = tmp_a_r - tmp_b_r; | |
280 buf[i+2].imag = tmp_a_i - tmp_b_i; | |
281 tmp_a_r = buf[i+1].real; | |
282 tmp_a_i = buf[i+1].imag; | |
283 tmp_b_r = buf[i+3].imag; | |
284 tmp_b_i = buf[i+3].real; | |
285 buf[i+1].real = tmp_a_r + tmp_b_r; | |
286 buf[i+1].imag = tmp_a_i - tmp_b_i; | |
287 buf[i+3].real = tmp_a_r - tmp_b_r; | |
288 buf[i+3].imag = tmp_a_i + tmp_b_i; | |
289 } | |
290 | |
3623 | 291 /* 3. iteration */ |
3579 | 292 for(i = 0; i < 128; i += 8) { |
293 tmp_a_r = buf[i].real; | |
294 tmp_a_i = buf[i].imag; | |
295 tmp_b_r = buf[i+4].real; | |
296 tmp_b_i = buf[i+4].imag; | |
297 buf[i].real = tmp_a_r + tmp_b_r; | |
298 buf[i].imag = tmp_a_i + tmp_b_i; | |
299 buf[i+4].real = tmp_a_r - tmp_b_r; | |
300 buf[i+4].imag = tmp_a_i - tmp_b_i; | |
301 tmp_a_r = buf[1+i].real; | |
302 tmp_a_i = buf[1+i].imag; | |
303 tmp_b_r = (buf[i+5].real + buf[i+5].imag) * w[2][1].real; | |
304 tmp_b_i = (buf[i+5].imag - buf[i+5].real) * w[2][1].real; | |
305 buf[1+i].real = tmp_a_r + tmp_b_r; | |
306 buf[1+i].imag = tmp_a_i + tmp_b_i; | |
307 buf[i+5].real = tmp_a_r - tmp_b_r; | |
308 buf[i+5].imag = tmp_a_i - tmp_b_i; | |
309 tmp_a_r = buf[i+2].real; | |
310 tmp_a_i = buf[i+2].imag; | |
311 tmp_b_r = buf[i+6].imag; | |
312 tmp_b_i = - buf[i+6].real; | |
313 buf[i+2].real = tmp_a_r + tmp_b_r; | |
314 buf[i+2].imag = tmp_a_i + tmp_b_i; | |
315 buf[i+6].real = tmp_a_r - tmp_b_r; | |
316 buf[i+6].imag = tmp_a_i - tmp_b_i; | |
317 tmp_a_r = buf[i+3].real; | |
318 tmp_a_i = buf[i+3].imag; | |
319 tmp_b_r = (buf[i+7].real - buf[i+7].imag) * w[2][3].imag; | |
320 tmp_b_i = (buf[i+7].imag + buf[i+7].real) * w[2][3].imag; | |
321 buf[i+3].real = tmp_a_r + tmp_b_r; | |
322 buf[i+3].imag = tmp_a_i + tmp_b_i; | |
323 buf[i+7].real = tmp_a_r - tmp_b_r; | |
324 buf[i+7].imag = tmp_a_i - tmp_b_i; | |
325 } | |
326 | |
3623 | 327 /* 4-7. iterations */ |
3579 | 328 for (m=3; m < 7; m++) { |
329 two_m = (1 << m); | |
330 | |
331 two_m_plus_one = two_m<<1; | |
332 | |
333 for(i = 0; i < 128; i += two_m_plus_one) { | |
334 for(k = 0; k < two_m; k++) { | |
335 int p = k + i; | |
336 int q = p + two_m; | |
337 tmp_a_r = buf[p].real; | |
338 tmp_a_i = buf[p].imag; | |
339 tmp_b_r = buf[q].real * w[m][k].real - buf[q].imag * w[m][k].imag; | |
340 tmp_b_i = buf[q].imag * w[m][k].real + buf[q].real * w[m][k].imag; | |
341 buf[p].real = tmp_a_r + tmp_b_r; | |
342 buf[p].imag = tmp_a_i + tmp_b_i; | |
343 buf[q].real = tmp_a_r - tmp_b_r; | |
344 buf[q].imag = tmp_a_i - tmp_b_i; | |
345 } | |
346 } | |
347 } | |
3884 | 348 #endif |
3579 | 349 /* Post IFFT complex multiply plus IFFT complex conjugate*/ |
350 for( i=0; i < 128; i++) { | |
351 /* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */ | |
352 tmp_a_r = buf[i].real; | |
353 tmp_a_i = -1.0 * buf[i].imag; | |
354 buf[i].real =(tmp_a_r * xcos1[i]) - (tmp_a_i * xsin1[i]); | |
355 buf[i].imag =(tmp_a_r * xsin1[i]) + (tmp_a_i * xcos1[i]); | |
356 } | |
357 | |
358 data_ptr = data; | |
359 delay_ptr = delay; | |
360 window_ptr = imdct_window; | |
361 | |
362 /* Window and convert to real valued signal */ | |
363 for(i=0; i< 64; i++) { | |
364 *data_ptr++ = -buf[64+i].imag * *window_ptr++ + *delay_ptr++ + bias; | |
365 *data_ptr++ = buf[64-i-1].real * *window_ptr++ + *delay_ptr++ + bias; | |
366 } | |
367 | |
368 for(i=0; i< 64; i++) { | |
369 *data_ptr++ = -buf[i].real * *window_ptr++ + *delay_ptr++ + bias; | |
370 *data_ptr++ = buf[128-i-1].imag * *window_ptr++ + *delay_ptr++ + bias; | |
371 } | |
3884 | 372 |
3579 | 373 /* The trailing edge of the window goes into the delay line */ |
374 delay_ptr = delay; | |
375 | |
376 for(i=0; i< 64; i++) { | |
377 *delay_ptr++ = -buf[64+i].real * *--window_ptr; | |
378 *delay_ptr++ = buf[64-i-1].imag * *--window_ptr; | |
379 } | |
380 | |
381 for(i=0; i<64; i++) { | |
382 *delay_ptr++ = buf[i].imag * *--window_ptr; | |
383 *delay_ptr++ = -buf[128-i-1].real * *--window_ptr; | |
384 } | |
385 } | |
386 | |
4497 | 387 // Stuff below this line is borrowed from libac3 |
388 #include "srfftp.h" | |
3579 | 389 #ifdef ARCH_X86 |
4497 | 390 #ifndef HAVE_3DNOW |
391 #define HAVE_3DNOW 1 | |
392 #endif | |
3884 | 393 #include "srfftp_3dnow.h" |
394 | |
8451 | 395 const i_cmplx_t x_plus_minus_3dnow __attribute__ ((aligned (8))) = {{ 0x00000000UL, 0x80000000UL }}; |
396 const i_cmplx_t x_minus_plus_3dnow __attribute__ ((aligned (8))) = {{ 0x80000000UL, 0x00000000UL }}; | |
3884 | 397 const complex_t HSQRT2_3DNOW __attribute__ ((aligned (8))) = { 0.707106781188, 0.707106781188 }; |
398 | |
4497 | 399 #undef HAVE_3DNOWEX |
400 #include "imdct_3dnow.h" | |
401 #define HAVE_3DNOWEX | |
402 #include "imdct_3dnow.h" | |
3884 | 403 |
3579 | 404 void |
405 imdct_do_512_sse(sample_t data[],sample_t delay[], sample_t bias) | |
406 { | |
8254
772d6d27fd66
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michael
parents:
4497
diff
changeset
|
407 /* int i,k; |
772d6d27fd66
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michael
parents:
4497
diff
changeset
|
408 int p,q;*/ |
3579 | 409 int m; |
410 int two_m; | |
411 int two_m_plus_one; | |
412 | |
8254
772d6d27fd66
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michael
parents:
4497
diff
changeset
|
413 /* sample_t tmp_a_i; |
3579 | 414 sample_t tmp_a_r; |
415 sample_t tmp_b_i; | |
8254
772d6d27fd66
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michael
parents:
4497
diff
changeset
|
416 sample_t tmp_b_r;*/ |
3579 | 417 |
418 sample_t *data_ptr; | |
419 sample_t *delay_ptr; | |
420 sample_t *window_ptr; | |
421 | |
422 /* 512 IMDCT with source and dest data in 'data' */ | |
3623 | 423 /* see the c version (dct_do_512()), its allmost identical, just in C */ |
424 | |
3579 | 425 /* Pre IFFT complex multiply plus IFFT cmplx conjugate */ |
426 /* Bit reversed shuffling */ | |
427 asm volatile( | |
428 "xorl %%esi, %%esi \n\t" | |
4247
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
429 "leal "MANGLE(bit_reverse_512)", %%eax \n\t" |
3579 | 430 "movl $1008, %%edi \n\t" |
431 "pushl %%ebp \n\t" //use ebp without telling gcc | |
432 ".balign 16 \n\t" | |
433 "1: \n\t" | |
3584 | 434 "movlps (%0, %%esi), %%xmm0 \n\t" // XXXI |
435 "movhps 8(%0, %%edi), %%xmm0 \n\t" // RXXI | |
436 "movlps 8(%0, %%esi), %%xmm1 \n\t" // XXXi | |
437 "movhps (%0, %%edi), %%xmm1 \n\t" // rXXi | |
438 "shufps $0x33, %%xmm1, %%xmm0 \n\t" // irIR | |
4247
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
439 "movaps "MANGLE(sseSinCos1c)"(%%esi), %%xmm2\n\t" |
3584 | 440 "mulps %%xmm0, %%xmm2 \n\t" |
441 "shufps $0xB1, %%xmm0, %%xmm0 \n\t" // riRI | |
4247
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
442 "mulps "MANGLE(sseSinCos1d)"(%%esi), %%xmm0\n\t" |
3584 | 443 "subps %%xmm0, %%xmm2 \n\t" |
3579 | 444 "movzbl (%%eax), %%edx \n\t" |
445 "movzbl 1(%%eax), %%ebp \n\t" | |
3584 | 446 "movlps %%xmm2, (%1, %%edx,8) \n\t" |
447 "movhps %%xmm2, (%1, %%ebp,8) \n\t" | |
3579 | 448 "addl $16, %%esi \n\t" |
449 "addl $2, %%eax \n\t" // avoid complex addressing for P4 crap | |
450 "subl $16, %%edi \n\t" | |
451 " jnc 1b \n\t" | |
452 "popl %%ebp \n\t"//no we didnt touch ebp *g* | |
453 :: "b" (data), "c" (buf) | |
454 : "%esi", "%edi", "%eax", "%edx" | |
455 ); | |
456 | |
457 | |
458 /* FFT Merge */ | |
459 /* unoptimized variant | |
460 for (m=1; m < 7; m++) { | |
461 if(m) | |
462 two_m = (1 << m); | |
463 else | |
464 two_m = 1; | |
465 | |
466 two_m_plus_one = (1 << (m+1)); | |
467 | |
468 for(i = 0; i < 128; i += two_m_plus_one) { | |
469 for(k = 0; k < two_m; k++) { | |
470 p = k + i; | |
471 q = p + two_m; | |
472 tmp_a_r = buf[p].real; | |
473 tmp_a_i = buf[p].imag; | |
474 tmp_b_r = buf[q].real * w[m][k].real - buf[q].imag * w[m][k].imag; | |
475 tmp_b_i = buf[q].imag * w[m][k].real + buf[q].real * w[m][k].imag; | |
476 buf[p].real = tmp_a_r + tmp_b_r; | |
477 buf[p].imag = tmp_a_i + tmp_b_i; | |
478 buf[q].real = tmp_a_r - tmp_b_r; | |
479 buf[q].imag = tmp_a_i - tmp_b_i; | |
480 } | |
481 } | |
482 } | |
483 */ | |
484 | |
3623 | 485 /* 1. iteration */ |
3549 | 486 // Note w[0][0]={1,0} |
3508 | 487 asm volatile( |
488 "xorps %%xmm1, %%xmm1 \n\t" | |
489 "xorps %%xmm2, %%xmm2 \n\t" | |
490 "movl %0, %%esi \n\t" | |
3529 | 491 ".balign 16 \n\t" |
3508 | 492 "1: \n\t" |
493 "movlps (%%esi), %%xmm0 \n\t" //buf[p] | |
494 "movlps 8(%%esi), %%xmm1\n\t" //buf[q] | |
495 "movhps (%%esi), %%xmm0 \n\t" //buf[p] | |
496 "movhps 8(%%esi), %%xmm2\n\t" //buf[q] | |
497 "addps %%xmm1, %%xmm0 \n\t" | |
498 "subps %%xmm2, %%xmm0 \n\t" | |
499 "movaps %%xmm0, (%%esi) \n\t" | |
500 "addl $16, %%esi \n\t" | |
501 "cmpl %1, %%esi \n\t" | |
502 " jb 1b \n\t" | |
503 :: "g" (buf), "r" (buf + 128) | |
504 : "%esi" | |
505 ); | |
3549 | 506 |
3623 | 507 /* 2. iteration */ |
3512 | 508 // Note w[1]={{1,0}, {0,-1}} |
509 asm volatile( | |
4247
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
510 "movaps "MANGLE(ps111_1)", %%xmm7\n\t" // 1,1,1,-1 |
3512 | 511 "movl %0, %%esi \n\t" |
3529 | 512 ".balign 16 \n\t" |
3512 | 513 "1: \n\t" |
514 "movaps 16(%%esi), %%xmm2 \n\t" //r2,i2,r3,i3 | |
515 "shufps $0xB4, %%xmm2, %%xmm2 \n\t" //r2,i2,i3,r3 | |
516 "mulps %%xmm7, %%xmm2 \n\t" //r2,i2,i3,-r3 | |
517 "movaps (%%esi), %%xmm0 \n\t" //r0,i0,r1,i1 | |
518 "movaps (%%esi), %%xmm1 \n\t" //r0,i0,r1,i1 | |
519 "addps %%xmm2, %%xmm0 \n\t" | |
520 "subps %%xmm2, %%xmm1 \n\t" | |
521 "movaps %%xmm0, (%%esi) \n\t" | |
522 "movaps %%xmm1, 16(%%esi) \n\t" | |
523 "addl $32, %%esi \n\t" | |
524 "cmpl %1, %%esi \n\t" | |
525 " jb 1b \n\t" | |
526 :: "g" (buf), "r" (buf + 128) | |
527 : "%esi" | |
528 ); | |
3549 | 529 |
3623 | 530 /* 3. iteration */ |
3534 | 531 /* |
532 Note sseW2+0={1,1,sqrt(2),sqrt(2)) | |
533 Note sseW2+16={0,0,sqrt(2),-sqrt(2)) | |
534 Note sseW2+32={0,0,-sqrt(2),-sqrt(2)) | |
535 Note sseW2+48={1,-1,sqrt(2),-sqrt(2)) | |
536 */ | |
537 asm volatile( | |
4247
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
538 "movaps 48+"MANGLE(sseW2)", %%xmm6\n\t" |
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
539 "movaps 16+"MANGLE(sseW2)", %%xmm7\n\t" |
3534 | 540 "xorps %%xmm5, %%xmm5 \n\t" |
541 "xorps %%xmm2, %%xmm2 \n\t" | |
542 "movl %0, %%esi \n\t" | |
543 ".balign 16 \n\t" | |
544 "1: \n\t" | |
3537 | 545 "movaps 32(%%esi), %%xmm2 \n\t" //r4,i4,r5,i5 |
3534 | 546 "movaps 48(%%esi), %%xmm3 \n\t" //r6,i6,r7,i7 |
4247
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
547 "movaps "MANGLE(sseW2)", %%xmm4 \n\t" //r4,i4,r5,i5 |
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
548 "movaps 32+"MANGLE(sseW2)", %%xmm5\n\t" //r6,i6,r7,i7 |
3537 | 549 "mulps %%xmm2, %%xmm4 \n\t" |
550 "mulps %%xmm3, %%xmm5 \n\t" | |
3534 | 551 "shufps $0xB1, %%xmm2, %%xmm2 \n\t" //i4,r4,i5,r5 |
552 "shufps $0xB1, %%xmm3, %%xmm3 \n\t" //i6,r6,i7,r7 | |
3537 | 553 "mulps %%xmm6, %%xmm3 \n\t" |
3534 | 554 "mulps %%xmm7, %%xmm2 \n\t" |
555 "movaps (%%esi), %%xmm0 \n\t" //r0,i0,r1,i1 | |
556 "movaps 16(%%esi), %%xmm1 \n\t" //r2,i2,r3,i3 | |
557 "addps %%xmm4, %%xmm2 \n\t" | |
558 "addps %%xmm5, %%xmm3 \n\t" | |
559 "movaps %%xmm2, %%xmm4 \n\t" | |
560 "movaps %%xmm3, %%xmm5 \n\t" | |
561 "addps %%xmm0, %%xmm2 \n\t" | |
562 "addps %%xmm1, %%xmm3 \n\t" | |
563 "subps %%xmm4, %%xmm0 \n\t" | |
564 "subps %%xmm5, %%xmm1 \n\t" | |
565 "movaps %%xmm2, (%%esi) \n\t" | |
566 "movaps %%xmm3, 16(%%esi) \n\t" | |
567 "movaps %%xmm0, 32(%%esi) \n\t" | |
568 "movaps %%xmm1, 48(%%esi) \n\t" | |
569 "addl $64, %%esi \n\t" | |
570 "cmpl %1, %%esi \n\t" | |
571 " jb 1b \n\t" | |
572 :: "g" (buf), "r" (buf + 128) | |
573 : "%esi" | |
574 ); | |
3508 | 575 |
3623 | 576 /* 4-7. iterations */ |
3546 | 577 for (m=3; m < 7; m++) { |
578 two_m = (1 << m); | |
579 two_m_plus_one = two_m<<1; | |
580 asm volatile( | |
581 "movl %0, %%esi \n\t" | |
582 ".balign 16 \n\t" | |
583 "1: \n\t" | |
584 "xorl %%edi, %%edi \n\t" // k | |
585 "leal (%%esi, %3), %%edx \n\t" | |
586 "2: \n\t" | |
587 "movaps (%%edx, %%edi), %%xmm1 \n\t" | |
588 "movaps (%4, %%edi, 2), %%xmm2 \n\t" | |
589 "mulps %%xmm1, %%xmm2 \n\t" | |
590 "shufps $0xB1, %%xmm1, %%xmm1 \n\t" | |
591 "mulps 16(%4, %%edi, 2), %%xmm1 \n\t" | |
592 "movaps (%%esi, %%edi), %%xmm0 \n\t" | |
593 "addps %%xmm2, %%xmm1 \n\t" | |
594 "movaps %%xmm1, %%xmm2 \n\t" | |
595 "addps %%xmm0, %%xmm1 \n\t" | |
596 "subps %%xmm2, %%xmm0 \n\t" | |
597 "movaps %%xmm1, (%%esi, %%edi) \n\t" | |
598 "movaps %%xmm0, (%%edx, %%edi) \n\t" | |
599 "addl $16, %%edi \n\t" | |
600 "cmpl %3, %%edi \n\t" //FIXME (opt) count against 0 | |
601 " jb 2b \n\t" | |
602 "addl %2, %%esi \n\t" | |
603 "cmpl %1, %%esi \n\t" | |
604 " jb 1b \n\t" | |
605 :: "g" (buf), "m" (buf+128), "m" (two_m_plus_one<<3), "r" (two_m<<3), | |
606 "r" (sseW[m]) | |
607 : "%esi", "%edi", "%edx" | |
608 ); | |
609 } | |
610 | |
3623 | 611 /* Post IFFT complex multiply plus IFFT complex conjugate*/ |
3581 | 612 asm volatile( |
4247
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
613 "movl $-1024, %%esi \n\t" |
3581 | 614 ".balign 16 \n\t" |
615 "1: \n\t" | |
616 "movaps (%0, %%esi), %%xmm0 \n\t" | |
617 "movaps (%0, %%esi), %%xmm1 \n\t" | |
618 "shufps $0xB1, %%xmm0, %%xmm0 \n\t" | |
4247
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
619 "mulps 1024+"MANGLE(sseSinCos1c)"(%%esi), %%xmm1\n\t" |
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
620 "mulps 1024+"MANGLE(sseSinCos1d)"(%%esi), %%xmm0\n\t" |
3581 | 621 "addps %%xmm1, %%xmm0 \n\t" |
622 "movaps %%xmm0, (%0, %%esi) \n\t" | |
623 "addl $16, %%esi \n\t" | |
624 " jnz 1b \n\t" | |
625 :: "r" (buf+128) | |
626 : "%esi" | |
627 ); | |
628 | |
3394 | 629 |
630 data_ptr = data; | |
631 delay_ptr = delay; | |
632 window_ptr = imdct_window; | |
633 | |
634 /* Window and convert to real valued signal */ | |
3552 | 635 asm volatile( |
636 "xorl %%edi, %%edi \n\t" // 0 | |
637 "xorl %%esi, %%esi \n\t" // 0 | |
638 "movss %3, %%xmm2 \n\t" // bias | |
639 "shufps $0x00, %%xmm2, %%xmm2 \n\t" // bias, bias, ... | |
640 ".balign 16 \n\t" | |
641 "1: \n\t" | |
642 "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? A ? | |
643 "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? C ? | |
644 "movhps -16(%0, %%edi), %%xmm1 \n\t" // ? D C ? | |
645 "movhps -8(%0, %%edi), %%xmm0 \n\t" // ? B A ? | |
646 "shufps $0x99, %%xmm1, %%xmm0 \n\t" // D C B A | |
4247
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
647 "mulps "MANGLE(sseWindow)"(%%esi), %%xmm0\n\t" |
3552 | 648 "addps (%2, %%esi), %%xmm0 \n\t" |
649 "addps %%xmm2, %%xmm0 \n\t" | |
650 "movaps %%xmm0, (%1, %%esi) \n\t" | |
651 "addl $16, %%esi \n\t" | |
652 "subl $16, %%edi \n\t" | |
653 "cmpl $512, %%esi \n\t" | |
654 " jb 1b \n\t" | |
655 :: "r" (buf+64), "r" (data_ptr), "r" (delay_ptr), "m" (bias) | |
656 : "%esi", "%edi" | |
657 ); | |
658 data_ptr+=128; | |
659 delay_ptr+=128; | |
3553 | 660 // window_ptr+=128; |
3579 | 661 |
3552 | 662 asm volatile( |
663 "movl $1024, %%edi \n\t" // 512 | |
664 "xorl %%esi, %%esi \n\t" // 0 | |
665 "movss %3, %%xmm2 \n\t" // bias | |
666 "shufps $0x00, %%xmm2, %%xmm2 \n\t" // bias, bias, ... | |
667 ".balign 16 \n\t" | |
668 "1: \n\t" | |
669 "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? ? A | |
670 "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? ? C | |
671 "movhps -16(%0, %%edi), %%xmm1 \n\t" // D ? ? C | |
672 "movhps -8(%0, %%edi), %%xmm0 \n\t" // B ? ? A | |
673 "shufps $0xCC, %%xmm1, %%xmm0 \n\t" // D C B A | |
4247
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
674 "mulps 512+"MANGLE(sseWindow)"(%%esi), %%xmm0\n\t" |
3552 | 675 "addps (%2, %%esi), %%xmm0 \n\t" |
676 "addps %%xmm2, %%xmm0 \n\t" | |
677 "movaps %%xmm0, (%1, %%esi) \n\t" | |
678 "addl $16, %%esi \n\t" | |
679 "subl $16, %%edi \n\t" | |
680 "cmpl $512, %%esi \n\t" | |
681 " jb 1b \n\t" | |
682 :: "r" (buf), "r" (data_ptr), "r" (delay_ptr), "m" (bias) | |
683 : "%esi", "%edi" | |
684 ); | |
685 data_ptr+=128; | |
3553 | 686 // window_ptr+=128; |
3394 | 687 |
688 /* The trailing edge of the window goes into the delay line */ | |
689 delay_ptr = delay; | |
690 | |
3553 | 691 asm volatile( |
692 "xorl %%edi, %%edi \n\t" // 0 | |
693 "xorl %%esi, %%esi \n\t" // 0 | |
694 ".balign 16 \n\t" | |
695 "1: \n\t" | |
696 "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? ? A | |
697 "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? ? C | |
698 "movhps -16(%0, %%edi), %%xmm1 \n\t" // D ? ? C | |
699 "movhps -8(%0, %%edi), %%xmm0 \n\t" // B ? ? A | |
700 "shufps $0xCC, %%xmm1, %%xmm0 \n\t" // D C B A | |
4247
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
701 "mulps 1024+"MANGLE(sseWindow)"(%%esi), %%xmm0\n\t" |
3553 | 702 "movaps %%xmm0, (%1, %%esi) \n\t" |
703 "addl $16, %%esi \n\t" | |
704 "subl $16, %%edi \n\t" | |
705 "cmpl $512, %%esi \n\t" | |
706 " jb 1b \n\t" | |
707 :: "r" (buf+64), "r" (delay_ptr) | |
708 : "%esi", "%edi" | |
709 ); | |
710 delay_ptr+=128; | |
711 // window_ptr-=128; | |
3579 | 712 |
3553 | 713 asm volatile( |
714 "movl $1024, %%edi \n\t" // 1024 | |
715 "xorl %%esi, %%esi \n\t" // 0 | |
716 ".balign 16 \n\t" | |
717 "1: \n\t" | |
718 "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? A ? | |
719 "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? C ? | |
720 "movhps -16(%0, %%edi), %%xmm1 \n\t" // ? D C ? | |
721 "movhps -8(%0, %%edi), %%xmm0 \n\t" // ? B A ? | |
722 "shufps $0x99, %%xmm1, %%xmm0 \n\t" // D C B A | |
4247
2dbd637ffe05
mangle for win32 in liba52 (includes dummy mangle.h pointing to the one in main)
atmos4
parents:
3908
diff
changeset
|
723 "mulps 1536+"MANGLE(sseWindow)"(%%esi), %%xmm0\n\t" |
3553 | 724 "movaps %%xmm0, (%1, %%esi) \n\t" |
725 "addl $16, %%esi \n\t" | |
726 "subl $16, %%edi \n\t" | |
727 "cmpl $512, %%esi \n\t" | |
728 " jb 1b \n\t" | |
729 :: "r" (buf), "r" (delay_ptr) | |
730 : "%esi", "%edi" | |
731 ); | |
3394 | 732 } |
3579 | 733 #endif //arch_x86 |
3394 | 734 |
735 void | |
736 imdct_do_256(sample_t data[],sample_t delay[],sample_t bias) | |
737 { | |
738 int i,k; | |
739 int p,q; | |
740 int m; | |
741 int two_m; | |
742 int two_m_plus_one; | |
743 | |
744 sample_t tmp_a_i; | |
745 sample_t tmp_a_r; | |
746 sample_t tmp_b_i; | |
747 sample_t tmp_b_r; | |
748 | |
749 sample_t *data_ptr; | |
750 sample_t *delay_ptr; | |
751 sample_t *window_ptr; | |
752 | |
753 complex_t *buf_1, *buf_2; | |
754 | |
755 buf_1 = &buf[0]; | |
756 buf_2 = &buf[64]; | |
757 | |
758 /* Pre IFFT complex multiply plus IFFT cmplx conjugate */ | |
759 for(k=0; k<64; k++) { | |
760 /* X1[k] = X[2*k] */ | |
761 /* X2[k] = X[2*k+1] */ | |
762 | |
763 p = 2 * (128-2*k-1); | |
764 q = 2 * (2 * k); | |
765 | |
766 /* Z1[k] = (X1[128-2*k-1] + j * X1[2*k]) * (xcos2[k] + j * xsin2[k]); */ | |
767 buf_1[k].real = data[p] * xcos2[k] - data[q] * xsin2[k]; | |
768 buf_1[k].imag = -1.0f * (data[q] * xcos2[k] + data[p] * xsin2[k]); | |
769 /* Z2[k] = (X2[128-2*k-1] + j * X2[2*k]) * (xcos2[k] + j * xsin2[k]); */ | |
770 buf_2[k].real = data[p + 1] * xcos2[k] - data[q + 1] * xsin2[k]; | |
771 buf_2[k].imag = -1.0f * ( data[q + 1] * xcos2[k] + data[p + 1] * xsin2[k]); | |
772 } | |
773 | |
774 /* IFFT Bit reversed shuffling */ | |
775 for(i=0; i<64; i++) { | |
776 k = bit_reverse_256[i]; | |
777 if (k < i) { | |
778 swap_cmplx(&buf_1[i],&buf_1[k]); | |
779 swap_cmplx(&buf_2[i],&buf_2[k]); | |
780 } | |
781 } | |
782 | |
783 /* FFT Merge */ | |
784 for (m=0; m < 6; m++) { | |
785 two_m = (1 << m); | |
786 two_m_plus_one = (1 << (m+1)); | |
787 | |
788 /* FIXME */ | |
789 if(m) | |
790 two_m = (1 << m); | |
791 else | |
792 two_m = 1; | |
793 | |
794 for(k = 0; k < two_m; k++) { | |
795 for(i = 0; i < 64; i += two_m_plus_one) { | |
796 p = k + i; | |
797 q = p + two_m; | |
798 /* Do block 1 */ | |
799 tmp_a_r = buf_1[p].real; | |
800 tmp_a_i = buf_1[p].imag; | |
801 tmp_b_r = buf_1[q].real * w[m][k].real - buf_1[q].imag * w[m][k].imag; | |
802 tmp_b_i = buf_1[q].imag * w[m][k].real + buf_1[q].real * w[m][k].imag; | |
803 buf_1[p].real = tmp_a_r + tmp_b_r; | |
804 buf_1[p].imag = tmp_a_i + tmp_b_i; | |
805 buf_1[q].real = tmp_a_r - tmp_b_r; | |
806 buf_1[q].imag = tmp_a_i - tmp_b_i; | |
807 | |
808 /* Do block 2 */ | |
809 tmp_a_r = buf_2[p].real; | |
810 tmp_a_i = buf_2[p].imag; | |
811 tmp_b_r = buf_2[q].real * w[m][k].real - buf_2[q].imag * w[m][k].imag; | |
812 tmp_b_i = buf_2[q].imag * w[m][k].real + buf_2[q].real * w[m][k].imag; | |
813 buf_2[p].real = tmp_a_r + tmp_b_r; | |
814 buf_2[p].imag = tmp_a_i + tmp_b_i; | |
815 buf_2[q].real = tmp_a_r - tmp_b_r; | |
816 buf_2[q].imag = tmp_a_i - tmp_b_i; | |
817 } | |
818 } | |
819 } | |
820 | |
821 /* Post IFFT complex multiply */ | |
822 for( i=0; i < 64; i++) { | |
823 /* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */ | |
824 tmp_a_r = buf_1[i].real; | |
825 tmp_a_i = -buf_1[i].imag; | |
826 buf_1[i].real =(tmp_a_r * xcos2[i]) - (tmp_a_i * xsin2[i]); | |
827 buf_1[i].imag =(tmp_a_r * xsin2[i]) + (tmp_a_i * xcos2[i]); | |
828 /* y2[n] = z2[n] * (xcos2[n] + j * xsin2[n]) ; */ | |
829 tmp_a_r = buf_2[i].real; | |
830 tmp_a_i = -buf_2[i].imag; | |
831 buf_2[i].real =(tmp_a_r * xcos2[i]) - (tmp_a_i * xsin2[i]); | |
832 buf_2[i].imag =(tmp_a_r * xsin2[i]) + (tmp_a_i * xcos2[i]); | |
833 } | |
834 | |
835 data_ptr = data; | |
836 delay_ptr = delay; | |
837 window_ptr = imdct_window; | |
838 | |
839 /* Window and convert to real valued signal */ | |
840 for(i=0; i< 64; i++) { | |
841 *data_ptr++ = -buf_1[i].imag * *window_ptr++ + *delay_ptr++ + bias; | |
842 *data_ptr++ = buf_1[64-i-1].real * *window_ptr++ + *delay_ptr++ + bias; | |
843 } | |
844 | |
845 for(i=0; i< 64; i++) { | |
846 *data_ptr++ = -buf_1[i].real * *window_ptr++ + *delay_ptr++ + bias; | |
847 *data_ptr++ = buf_1[64-i-1].imag * *window_ptr++ + *delay_ptr++ + bias; | |
848 } | |
849 | |
850 delay_ptr = delay; | |
851 | |
852 for(i=0; i< 64; i++) { | |
853 *delay_ptr++ = -buf_2[i].real * *--window_ptr; | |
854 *delay_ptr++ = buf_2[64-i-1].imag * *--window_ptr; | |
855 } | |
856 | |
857 for(i=0; i< 64; i++) { | |
858 *delay_ptr++ = buf_2[i].imag * *--window_ptr; | |
859 *delay_ptr++ = -buf_2[64-i-1].real * *--window_ptr; | |
860 } | |
861 } | |
862 | |
863 void imdct_init (uint32_t mm_accel) | |
864 { | |
865 #ifdef LIBA52_MLIB | |
866 if (mm_accel & MM_ACCEL_MLIB) { | |
867 fprintf (stderr, "Using mlib for IMDCT transform\n"); | |
868 imdct_512 = imdct_do_512_mlib; | |
869 imdct_256 = imdct_do_256_mlib; | |
870 } else | |
871 #endif | |
872 { | |
873 int i, j, k; | |
874 | |
875 /* Twiddle factors to turn IFFT into IMDCT */ | |
876 for (i = 0; i < 128; i++) { | |
877 xcos1[i] = -cos ((M_PI / 2048) * (8 * i + 1)); | |
878 xsin1[i] = -sin ((M_PI / 2048) * (8 * i + 1)); | |
879 } | |
3579 | 880 #ifdef ARCH_X86 |
3527 | 881 for (i = 0; i < 128; i++) { |
3581 | 882 sseSinCos1c[2*i+0]= xcos1[i]; |
883 sseSinCos1c[2*i+1]= -xcos1[i]; | |
884 sseSinCos1d[2*i+0]= xsin1[i]; | |
885 sseSinCos1d[2*i+1]= xsin1[i]; | |
3527 | 886 } |
887 #endif | |
3394 | 888 |
889 /* More twiddle factors to turn IFFT into IMDCT */ | |
890 for (i = 0; i < 64; i++) { | |
891 xcos2[i] = -cos ((M_PI / 1024) * (8 * i + 1)); | |
892 xsin2[i] = -sin ((M_PI / 1024) * (8 * i + 1)); | |
893 } | |
894 | |
895 for (i = 0; i < 7; i++) { | |
896 j = 1 << i; | |
897 for (k = 0; k < j; k++) { | |
898 w[i][k].real = cos (-M_PI * k / j); | |
899 w[i][k].imag = sin (-M_PI * k / j); | |
900 } | |
901 } | |
3579 | 902 #ifdef ARCH_X86 |
3534 | 903 for (i = 1; i < 7; i++) { |
904 j = 1 << i; | |
905 for (k = 0; k < j; k+=2) { | |
906 | |
907 sseW[i][4*k + 0] = w[i][k+0].real; | |
908 sseW[i][4*k + 1] = w[i][k+0].real; | |
909 sseW[i][4*k + 2] = w[i][k+1].real; | |
910 sseW[i][4*k + 3] = w[i][k+1].real; | |
911 | |
912 sseW[i][4*k + 4] = -w[i][k+0].imag; | |
913 sseW[i][4*k + 5] = w[i][k+0].imag; | |
914 sseW[i][4*k + 6] = -w[i][k+1].imag; | |
915 sseW[i][4*k + 7] = w[i][k+1].imag; | |
916 | |
917 //we multiply more or less uninitalized numbers so we need to use exactly 0.0 | |
918 if(k==0) | |
919 { | |
920 // sseW[i][4*k + 0]= sseW[i][4*k + 1]= 1.0; | |
921 sseW[i][4*k + 4]= sseW[i][4*k + 5]= 0.0; | |
922 } | |
923 | |
924 if(2*k == j) | |
925 { | |
926 sseW[i][4*k + 0]= sseW[i][4*k + 1]= 0.0; | |
927 // sseW[i][4*k + 4]= -(sseW[i][4*k + 5]= -1.0); | |
928 } | |
929 } | |
930 } | |
3552 | 931 |
932 for(i=0; i<128; i++) | |
933 { | |
934 sseWindow[2*i+0]= -imdct_window[2*i+0]; | |
3553 | 935 sseWindow[2*i+1]= imdct_window[2*i+1]; |
3552 | 936 } |
3553 | 937 |
938 for(i=0; i<64; i++) | |
939 { | |
940 sseWindow[256 + 2*i+0]= -imdct_window[254 - 2*i+1]; | |
941 sseWindow[256 + 2*i+1]= imdct_window[254 - 2*i+0]; | |
942 sseWindow[384 + 2*i+0]= imdct_window[126 - 2*i+1]; | |
943 sseWindow[384 + 2*i+1]= -imdct_window[126 - 2*i+0]; | |
944 } | |
3579 | 945 #endif // arch_x86 |
946 | |
3720
120ac80f13c2
Fixed #ifdef discrepancy that was breaking compilation on PPC platform
melanson
parents:
3623
diff
changeset
|
947 imdct_512 = imdct_do_512; |
120ac80f13c2
Fixed #ifdef discrepancy that was breaking compilation on PPC platform
melanson
parents:
3623
diff
changeset
|
948 #ifdef ARCH_X86 |
4497 | 949 if(mm_accel & MM_ACCEL_X86_SSE) |
950 { | |
951 fprintf (stderr, "Using SSE optimized IMDCT transform\n"); | |
952 imdct_512 = imdct_do_512_sse; | |
953 } | |
954 else | |
955 if(mm_accel & MM_ACCEL_X86_3DNOWEXT) | |
956 { | |
957 fprintf (stderr, "Using 3DNowEx optimized IMDCT transform\n"); | |
958 imdct_512 = imdct_do_512_3dnowex; | |
959 } | |
960 else | |
961 if(mm_accel & MM_ACCEL_X86_3DNOW) | |
962 { | |
963 fprintf (stderr, "Using 3DNow optimized IMDCT transform\n"); | |
964 imdct_512 = imdct_do_512_3dnow; | |
965 } | |
966 else | |
3720
120ac80f13c2
Fixed #ifdef discrepancy that was breaking compilation on PPC platform
melanson
parents:
3623
diff
changeset
|
967 #endif // arch_x86 |
4497 | 968 fprintf (stderr, "No accelerated IMDCT transform found\n"); |
3394 | 969 imdct_256 = imdct_do_256; |
970 } | |
971 } | |
3884 | 972 |
973 static void fft_asmb(int k, complex_t *x, complex_t *wTB, | |
974 const complex_t *d, const complex_t *d_3) | |
975 { | |
976 register complex_t *x2k, *x3k, *x4k, *wB; | |
977 register float a_r, a_i, a1_r, a1_i, u_r, u_i, v_r, v_i; | |
978 | |
979 x2k = x + 2 * k; | |
980 x3k = x2k + 2 * k; | |
981 x4k = x3k + 2 * k; | |
982 wB = wTB + 2 * k; | |
983 | |
984 TRANSZERO(x[0],x2k[0],x3k[0],x4k[0]); | |
985 TRANS(x[1],x2k[1],x3k[1],x4k[1],wTB[1],wB[1],d[1],d_3[1]); | |
986 | |
987 --k; | |
988 for(;;) { | |
989 TRANS(x[2],x2k[2],x3k[2],x4k[2],wTB[2],wB[2],d[2],d_3[2]); | |
990 TRANS(x[3],x2k[3],x3k[3],x4k[3],wTB[3],wB[3],d[3],d_3[3]); | |
991 if (!--k) break; | |
992 x += 2; | |
993 x2k += 2; | |
994 x3k += 2; | |
995 x4k += 2; | |
996 d += 2; | |
997 d_3 += 2; | |
998 wTB += 2; | |
999 wB += 2; | |
1000 } | |
1001 | |
1002 } | |
1003 | |
1004 static void fft_asmb16(complex_t *x, complex_t *wTB) | |
1005 { | |
1006 register float a_r, a_i, a1_r, a1_i, u_r, u_i, v_r, v_i; | |
1007 int k = 2; | |
1008 | |
1009 /* transform x[0], x[8], x[4], x[12] */ | |
1010 TRANSZERO(x[0],x[4],x[8],x[12]); | |
1011 | |
1012 /* transform x[1], x[9], x[5], x[13] */ | |
1013 TRANS(x[1],x[5],x[9],x[13],wTB[1],wTB[5],delta16[1],delta16_3[1]); | |
1014 | |
1015 /* transform x[2], x[10], x[6], x[14] */ | |
1016 TRANSHALF_16(x[2],x[6],x[10],x[14]); | |
1017 | |
1018 /* transform x[3], x[11], x[7], x[15] */ | |
1019 TRANS(x[3],x[7],x[11],x[15],wTB[3],wTB[7],delta16[3],delta16_3[3]); | |
1020 | |
1021 } | |
1022 | |
1023 static void fft_4(complex_t *x) | |
1024 { | |
1025 /* delta_p = 1 here */ | |
1026 /* x[k] = sum_{i=0..3} x[i] * w^{i*k}, w=e^{-2*pi/4} | |
1027 */ | |
1028 | |
1029 register float yt_r, yt_i, yb_r, yb_i, u_r, u_i, vi_r, vi_i; | |
1030 | |
1031 yt_r = x[0].real; | |
1032 yb_r = yt_r - x[2].real; | |
1033 yt_r += x[2].real; | |
1034 | |
1035 u_r = x[1].real; | |
1036 vi_i = x[3].real - u_r; | |
1037 u_r += x[3].real; | |
1038 | |
1039 u_i = x[1].imag; | |
1040 vi_r = u_i - x[3].imag; | |
1041 u_i += x[3].imag; | |
1042 | |
1043 yt_i = yt_r; | |
1044 yt_i += u_r; | |
1045 x[0].real = yt_i; | |
1046 yt_r -= u_r; | |
1047 x[2].real = yt_r; | |
1048 yt_i = yb_r; | |
1049 yt_i += vi_r; | |
1050 x[1].real = yt_i; | |
1051 yb_r -= vi_r; | |
1052 x[3].real = yb_r; | |
1053 | |
1054 yt_i = x[0].imag; | |
1055 yb_i = yt_i - x[2].imag; | |
1056 yt_i += x[2].imag; | |
1057 | |
1058 yt_r = yt_i; | |
1059 yt_r += u_i; | |
1060 x[0].imag = yt_r; | |
1061 yt_i -= u_i; | |
1062 x[2].imag = yt_i; | |
1063 yt_r = yb_i; | |
1064 yt_r += vi_i; | |
1065 x[1].imag = yt_r; | |
1066 yb_i -= vi_i; | |
1067 x[3].imag = yb_i; | |
1068 } | |
1069 | |
1070 | |
1071 static void fft_8(complex_t *x) | |
1072 { | |
1073 /* delta_p = diag{1, sqrt(i)} here */ | |
1074 /* x[k] = sum_{i=0..7} x[i] * w^{i*k}, w=e^{-2*pi/8} | |
1075 */ | |
1076 register float wT1_r, wT1_i, wB1_r, wB1_i, wT2_r, wT2_i, wB2_r, wB2_i; | |
1077 | |
1078 wT1_r = x[1].real; | |
1079 wT1_i = x[1].imag; | |
1080 wB1_r = x[3].real; | |
1081 wB1_i = x[3].imag; | |
1082 | |
1083 x[1] = x[2]; | |
1084 x[2] = x[4]; | |
1085 x[3] = x[6]; | |
1086 fft_4(&x[0]); | |
1087 | |
1088 | |
1089 /* x[0] x[4] */ | |
1090 wT2_r = x[5].real; | |
1091 wT2_r += x[7].real; | |
1092 wT2_r += wT1_r; | |
1093 wT2_r += wB1_r; | |
1094 wT2_i = wT2_r; | |
1095 wT2_r += x[0].real; | |
1096 wT2_i = x[0].real - wT2_i; | |
1097 x[0].real = wT2_r; | |
1098 x[4].real = wT2_i; | |
1099 | |
1100 wT2_i = x[5].imag; | |
1101 wT2_i += x[7].imag; | |
1102 wT2_i += wT1_i; | |
1103 wT2_i += wB1_i; | |
1104 wT2_r = wT2_i; | |
1105 wT2_r += x[0].imag; | |
1106 wT2_i = x[0].imag - wT2_i; | |
1107 x[0].imag = wT2_r; | |
1108 x[4].imag = wT2_i; | |
1109 | |
1110 /* x[2] x[6] */ | |
1111 wT2_r = x[5].imag; | |
1112 wT2_r -= x[7].imag; | |
1113 wT2_r += wT1_i; | |
1114 wT2_r -= wB1_i; | |
1115 wT2_i = wT2_r; | |
1116 wT2_r += x[2].real; | |
1117 wT2_i = x[2].real - wT2_i; | |
1118 x[2].real = wT2_r; | |
1119 x[6].real = wT2_i; | |
1120 | |
1121 wT2_i = x[5].real; | |
1122 wT2_i -= x[7].real; | |
1123 wT2_i += wT1_r; | |
1124 wT2_i -= wB1_r; | |
1125 wT2_r = wT2_i; | |
1126 wT2_r += x[2].imag; | |
1127 wT2_i = x[2].imag - wT2_i; | |
1128 x[2].imag = wT2_i; | |
1129 x[6].imag = wT2_r; | |
1130 | |
1131 | |
1132 /* x[1] x[5] */ | |
1133 wT2_r = wT1_r; | |
1134 wT2_r += wB1_i; | |
1135 wT2_r -= x[5].real; | |
1136 wT2_r -= x[7].imag; | |
1137 wT2_i = wT1_i; | |
1138 wT2_i -= wB1_r; | |
1139 wT2_i -= x[5].imag; | |
1140 wT2_i += x[7].real; | |
1141 | |
1142 wB2_r = wT2_r; | |
1143 wB2_r += wT2_i; | |
1144 wT2_i -= wT2_r; | |
1145 wB2_r *= HSQRT2; | |
1146 wT2_i *= HSQRT2; | |
1147 wT2_r = wB2_r; | |
1148 wB2_r += x[1].real; | |
1149 wT2_r = x[1].real - wT2_r; | |
1150 | |
1151 wB2_i = x[5].real; | |
1152 x[1].real = wB2_r; | |
1153 x[5].real = wT2_r; | |
1154 | |
1155 wT2_r = wT2_i; | |
1156 wT2_r += x[1].imag; | |
1157 wT2_i = x[1].imag - wT2_i; | |
1158 wB2_r = x[5].imag; | |
1159 x[1].imag = wT2_r; | |
1160 x[5].imag = wT2_i; | |
1161 | |
1162 /* x[3] x[7] */ | |
1163 wT1_r -= wB1_i; | |
1164 wT1_i += wB1_r; | |
1165 wB1_r = wB2_i - x[7].imag; | |
1166 wB1_i = wB2_r + x[7].real; | |
1167 wT1_r -= wB1_r; | |
1168 wT1_i -= wB1_i; | |
1169 wB1_r = wT1_r + wT1_i; | |
1170 wB1_r *= HSQRT2; | |
1171 wT1_i -= wT1_r; | |
1172 wT1_i *= HSQRT2; | |
1173 wB2_r = x[3].real; | |
1174 wB2_i = wB2_r + wT1_i; | |
1175 wB2_r -= wT1_i; | |
1176 x[3].real = wB2_i; | |
1177 x[7].real = wB2_r; | |
1178 wB2_i = x[3].imag; | |
1179 wB2_r = wB2_i + wB1_r; | |
1180 wB2_i -= wB1_r; | |
1181 x[3].imag = wB2_i; | |
1182 x[7].imag = wB2_r; | |
1183 } | |
1184 | |
1185 | |
1186 static void fft_128p(complex_t *a) | |
1187 { | |
1188 fft_8(&a[0]); fft_4(&a[8]); fft_4(&a[12]); | |
1189 fft_asmb16(&a[0], &a[8]); | |
1190 | |
1191 fft_8(&a[16]), fft_8(&a[24]); | |
1192 fft_asmb(4, &a[0], &a[16],&delta32[0], &delta32_3[0]); | |
1193 | |
1194 fft_8(&a[32]); fft_4(&a[40]); fft_4(&a[44]); | |
1195 fft_asmb16(&a[32], &a[40]); | |
1196 | |
1197 fft_8(&a[48]); fft_4(&a[56]); fft_4(&a[60]); | |
1198 fft_asmb16(&a[48], &a[56]); | |
1199 | |
1200 fft_asmb(8, &a[0], &a[32],&delta64[0], &delta64_3[0]); | |
1201 | |
1202 fft_8(&a[64]); fft_4(&a[72]); fft_4(&a[76]); | |
1203 /* fft_16(&a[64]); */ | |
1204 fft_asmb16(&a[64], &a[72]); | |
1205 | |
1206 fft_8(&a[80]); fft_8(&a[88]); | |
1207 | |
1208 /* fft_32(&a[64]); */ | |
1209 fft_asmb(4, &a[64], &a[80],&delta32[0], &delta32_3[0]); | |
1210 | |
1211 fft_8(&a[96]); fft_4(&a[104]), fft_4(&a[108]); | |
1212 /* fft_16(&a[96]); */ | |
1213 fft_asmb16(&a[96], &a[104]); | |
1214 | |
1215 fft_8(&a[112]), fft_8(&a[120]); | |
1216 /* fft_32(&a[96]); */ | |
1217 fft_asmb(4, &a[96], &a[112], &delta32[0], &delta32_3[0]); | |
1218 | |
1219 /* fft_128(&a[0]); */ | |
1220 fft_asmb(16, &a[0], &a[64], &delta128[0], &delta128_3[0]); | |
1221 } | |
1222 | |
1223 | |
1224 |