1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: ac3_srfft.c,v 1.4 2001/05/14 15:58:04 reno Exp $
7 * Authors: Renaud Dartus <reno@videolan.org>
8 * Aaron Holtzman <aholtzma@engr.uvic.ca>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
27 #include <string.h> /* memcpy() */
37 #include "stream_control.h"
38 #include "input_ext-dec.h"
40 #include "ac3_decoder.h"
41 #include "ac3_srfft.h"
43 static void fft_8 (complex_t *x);
45 static void fft_4(complex_t *x)
47 /* delta_p = 1 here */
48 /* x[k] = sum_{i=0..3} x[i] * w^{i*k}, w=e^{-2*pi/4}
51 register float yt_r, yt_i, yb_r, yb_i, u_r, u_i, vi_r, vi_i;
54 yb_r = yt_r - x[2].real;
58 vi_i = x[3].real - u_r;
62 vi_r = u_i - x[3].imag;
77 yb_i = yt_i - x[2].imag;
93 static void fft_8 (complex_t *x)
95 /* delta_p = diag{1, sqrt(i)} here */
96 /* x[k] = sum_{i=0..7} x[i] * w^{i*k}, w=e^{-2*pi/8}
98 register float wT1_r, wT1_i, wB1_r, wB1_i, wT2_r, wT2_i, wB2_r, wB2_i;
118 wT2_i = x[0].real - wT2_i;
128 wT2_i = x[0].imag - wT2_i;
139 wT2_i = x[2].real - wT2_i;
149 wT2_i = x[2].imag - wT2_i;
171 wT2_r = x[1].real - wT2_r;
179 wT2_i = x[1].imag - wT2_i;
187 wB1_r = wB2_i - x[7].imag;
188 wB1_i = wB2_r + x[7].real;
191 wB1_r = wT1_r + wT1_i;
196 wB2_i = wB2_r + wT1_i;
201 wB2_r = wB2_i + wB1_r;
208 static void fft_asmb(int k, complex_t *x, complex_t *wTB,
209 const complex_t *d, const complex_t *d_3)
211 register complex_t *x2k, *x3k, *x4k, *wB;
212 register float a_r, a_i, a1_r, a1_i, u_r, u_i, v_r, v_i;
219 TRANSZERO(x[0],x2k[0],x3k[0],x4k[0]);
220 TRANS(x[1],x2k[1],x3k[1],x4k[1],wTB[1],wB[1],d[1],d_3[1]);
224 TRANS(x[2],x2k[2],x3k[2],x4k[2],wTB[2],wB[2],d[2],d_3[2]);
225 TRANS(x[3],x2k[3],x3k[3],x4k[3],wTB[3],wB[3],d[3],d_3[3]);
239 static void fft_asmb16(complex_t *x, complex_t *wTB)
241 register float a_r, a_i, a1_r, a1_i, u_r, u_i, v_r, v_i;
244 /* transform x[0], x[8], x[4], x[12] */
245 TRANSZERO(x[0],x[4],x[8],x[12]);
247 /* transform x[1], x[9], x[5], x[13] */
248 TRANS(x[1],x[5],x[9],x[13],wTB[1],wTB[5],delta16[1],delta16_3[1]);
250 /* transform x[2], x[10], x[6], x[14] */
251 TRANSHALF_16(x[2],x[6],x[10],x[14]);
253 /* transform x[3], x[11], x[7], x[15] */
254 TRANS(x[3],x[7],x[11],x[15],wTB[3],wTB[7],delta16[3],delta16_3[3]);
259 void fft_64p_c (complex_t *a)
261 fft_8(&a[0]); fft_4(&a[8]); fft_4(&a[12]);
262 fft_asmb16(&a[0], &a[8]);
264 fft_8(&a[16]), fft_8(&a[24]);
265 fft_asmb(4, &a[0], &a[16],&delta32[0], &delta32_3[0]);
267 fft_8(&a[32]); fft_4(&a[40]); fft_4(&a[44]);
268 fft_asmb16(&a[32], &a[40]);
270 fft_8(&a[48]); fft_4(&a[56]); fft_4(&a[60]);
271 fft_asmb16(&a[48], &a[56]);
273 fft_asmb(8, &a[0], &a[32],&delta64[0], &delta64_3[0]);
277 void fft_128p_c (complex_t *a)
279 fft_8(&a[0]); fft_4(&a[8]); fft_4(&a[12]);
280 fft_asmb16(&a[0], &a[8]);
282 fft_8(&a[16]), fft_8(&a[24]);
283 fft_asmb(4, &a[0], &a[16],&delta32[0], &delta32_3[0]);
285 fft_8(&a[32]); fft_4(&a[40]); fft_4(&a[44]);
286 fft_asmb16(&a[32], &a[40]);
288 fft_8(&a[48]); fft_4(&a[56]); fft_4(&a[60]);
289 fft_asmb16(&a[48], &a[56]);
291 fft_asmb(8, &a[0], &a[32],&delta64[0], &delta64_3[0]);
293 fft_8(&a[64]); fft_4(&a[72]); fft_4(&a[76]);
294 /* fft_16(&a[64]); */
295 fft_asmb16(&a[64], &a[72]);
297 fft_8(&a[80]); fft_8(&a[88]);
299 /* fft_32(&a[64]); */
300 fft_asmb(4, &a[64], &a[80],&delta32[0], &delta32_3[0]);
302 fft_8(&a[96]); fft_4(&a[104]), fft_4(&a[108]);
303 /* fft_16(&a[96]); */
304 fft_asmb16(&a[96], &a[104]);
306 fft_8(&a[112]), fft_8(&a[120]);
307 /* fft_32(&a[96]); */
308 fft_asmb(4, &a[96], &a[112], &delta32[0], &delta32_3[0]);
310 /* fft_128(&a[0]); */
311 fft_asmb(16, &a[0], &a[64], &delta128[0], &delta128_3[0]);