1 /*****************************************************************************
2 * ac3_imdct_common.c: common ac3 DCT functions
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: ac3_imdct_common.c,v 1.3 2001/05/16 14:51:29 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 *****************************************************************************/
25 /* MODULE_NAME defined in Makefile together with -DBUILTIN */
27 # include "modules_inner.h"
29 # define _M( foo ) foo
32 /*****************************************************************************
34 *****************************************************************************/
37 #include <string.h> /* memcpy() */
47 #include "ac3_imdct.h"
48 #include "ac3_retables.h"
51 # define M_PI 3.14159265358979323846
54 void _M( fft_64p ) ( complex_t *x );
56 void _M( imdct_do_256 ) (imdct_t * p_imdct, float data[],float delay[])
68 complex_t *buf1, *buf2;
70 buf1 = &p_imdct->buf[0];
71 buf2 = &p_imdct->buf[64];
73 /* Pre IFFT complex multiply plus IFFT complex conjugate */
74 for (k=0; k<64; k++) {
82 /* Z1[k] = (X1[128-2*k-1] + j * X1[2*k]) * (xcos2[k] + j * xsin2[k]); */
83 buf1[k].real = data[p] * p_imdct->xcos2[j] - data[q] * p_imdct->xsin2[j];
84 buf1[k].imag = -1.0f*(data[q] * p_imdct->xcos2[j] + data[p] * p_imdct->xsin2[j]);
85 /* Z2[k] = (X2[128-2*k-1] + j * X2[2*k]) * (xcos2[k] + j * xsin2[k]); */
86 buf2[k].real = data[p + 1] * p_imdct->xcos2[j] - data[q + 1] * p_imdct->xsin2[j];
87 buf2[k].imag = -1.0f*(data[q + 1] * p_imdct->xcos2[j] + data[p + 1] * p_imdct->xsin2[j]);
90 _M( fft_64p ) ( &buf1[0] );
91 _M( fft_64p ) ( &buf2[0] );
93 /* Post IFFT complex multiply */
94 for( i=0; i < 64; i++) {
95 tmp_a_r = buf1[i].real;
96 tmp_a_i = -buf1[i].imag;
97 buf1[i].real = (tmp_a_r * p_imdct->xcos2[i]) - (tmp_a_i * p_imdct->xsin2[i]);
98 buf1[i].imag = (tmp_a_r * p_imdct->xsin2[i]) + (tmp_a_i * p_imdct->xcos2[i]);
99 tmp_a_r = buf2[i].real;
100 tmp_a_i = -buf2[i].imag;
101 buf2[i].real = (tmp_a_r * p_imdct->xcos2[i]) - (tmp_a_i * p_imdct->xsin2[i]);
102 buf2[i].imag = (tmp_a_r * p_imdct->xsin2[i]) + (tmp_a_i * p_imdct->xcos2[i]);
109 /* Window and convert to real valued signal */
110 for(i=0; i< 64; i++) {
111 *data_ptr++ = -buf1[i].imag * *window_ptr++ + *delay_ptr++;
112 *data_ptr++ = buf1[64-i-1].real * *window_ptr++ + *delay_ptr++;
115 for(i=0; i< 64; i++) {
116 *data_ptr++ = -buf1[i].real * *window_ptr++ + *delay_ptr++;
117 *data_ptr++ = buf1[64-i-1].imag * *window_ptr++ + *delay_ptr++;
122 for(i=0; i< 64; i++) {
123 *delay_ptr++ = -buf2[i].real * *--window_ptr;
124 *delay_ptr++ = buf2[64-i-1].imag * *--window_ptr;
127 for(i=0; i< 64; i++) {
128 *delay_ptr++ = buf2[i].imag * *--window_ptr;
129 *delay_ptr++ = -buf2[64-i-1].real * *--window_ptr;
134 void _M( imdct_do_256_nol ) (imdct_t * p_imdct, float data[], float delay[])
146 complex_t *buf1, *buf2;
148 buf1 = &p_imdct->buf[0];
149 buf2 = &p_imdct->buf[64];
151 /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
152 for(k=0; k<64; k++) {
154 * X2[k] = X[2*k+1] */
159 /* Z1[k] = (X1[128-2*k-1] + j * X1[2*k]) * (xcos2[k] + j * xsin2[k]); */
160 buf1[k].real = data[p] * p_imdct->xcos2[j] - data[q] * p_imdct->xsin2[j];
161 buf1[k].imag = -1.0f*(data[q] * p_imdct->xcos2[j] + data[p] * p_imdct->xsin2[j]);
162 /* Z2[k] = (X2[128-2*k-1] + j * X2[2*k]) * (xcos2[k] + j * xsin2[k]); */
163 buf2[k].real = data[p + 1] * p_imdct->xcos2[j] - data[q + 1] * p_imdct->xsin2[j];
164 buf2[k].imag = -1.0f*(data[q + 1] * p_imdct->xcos2[j] + data[p + 1] * p_imdct->xsin2[j]);
167 _M( fft_64p ) ( &buf1[0] );
168 _M( fft_64p ) ( &buf2[0] );
170 /* Post IFFT complex multiply */
171 for( i=0; i < 64; i++) {
172 /* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */
173 tmp_a_r = buf1[i].real;
174 tmp_a_i = -buf1[i].imag;
175 buf1[i].real =(tmp_a_r * p_imdct->xcos2[i]) - (tmp_a_i * p_imdct->xsin2[i]);
176 buf1[i].imag =(tmp_a_r * p_imdct->xsin2[i]) + (tmp_a_i * p_imdct->xcos2[i]);
177 /* y2[n] = z2[n] * (xcos2[n] + j * xsin2[n]) ; */
178 tmp_a_r = buf2[i].real;
179 tmp_a_i = -buf2[i].imag;
180 buf2[i].real =(tmp_a_r * p_imdct->xcos2[i]) - (tmp_a_i * p_imdct->xsin2[i]);
181 buf2[i].imag =(tmp_a_r * p_imdct->xsin2[i]) + (tmp_a_i * p_imdct->xcos2[i]);
188 /* Window and convert to real valued signal, no overlap */
189 for(i=0; i< 64; i++) {
190 *data_ptr++ = -buf1[i].imag * *window_ptr++;
191 *data_ptr++ = buf1[64-i-1].real * *window_ptr++;
194 for(i=0; i< 64; i++) {
195 *data_ptr++ = -buf1[i].real * *window_ptr++ + *delay_ptr++;
196 *data_ptr++ = buf1[64-i-1].imag * *window_ptr++ + *delay_ptr++;
201 for(i=0; i< 64; i++) {
202 *delay_ptr++ = -buf2[i].real * *--window_ptr;
203 *delay_ptr++ = buf2[64-i-1].imag * *--window_ptr;
206 for(i=0; i< 64; i++) {
207 *delay_ptr++ = buf2[i].imag * *--window_ptr;
208 *delay_ptr++ = -buf2[64-i-1].real * *--window_ptr;