annotate Input/aac/libfaad2/mdct.c @ 9:b6c614e106df trunk

[svn] Remove a stamp-po to fix a compile error.
author nenolod
date Mon, 24 Oct 2005 13:55:57 -0700
parents 6efb9e514224
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
1 /*
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
4 **
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
8 ** (at your option) any later version.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
9 **
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
13 ** GNU General Public License for more details.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
14 **
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
18 **
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
20 ** forbidden.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
21 **
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
24 **
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
25 ** $Id: mdct.c,v 1.34 2003/11/12 20:47:58 menno Exp $
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
26 **/
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
27
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
28 /*
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
29 * Fast (I)MDCT Implementation using (I)FFT ((Inverse) Fast Fourier Transform)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
30 * and consists of three steps: pre-(I)FFT complex multiplication, complex
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
31 * (I)FFT, post-(I)FFT complex multiplication,
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
32 *
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
33 * As described in:
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
34 * P. Duhamel, Y. Mahieux, and J.P. Petit, "A Fast Algorithm for the
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
35 * Implementation of Filter Banks Based on 'Time Domain Aliasing
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
36 * Cancellation’," IEEE Proc. on ICASSP‘91, 1991, pp. 2209-2212.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
37 *
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
38 *
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
39 * As of April 6th 2002 completely rewritten.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
40 * This (I)MDCT can now be used for any data size n, where n is divisible by 8.
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
41 *
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
42 */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
43
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
44 #include "common.h"
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
45 #include "structs.h"
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
46
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
47 #include <stdlib.h>
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
48 #ifdef _WIN32_WCE
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
49 #define assert(x)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
50 #else
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
51 #include <assert.h>
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
52 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
53
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
54 #include "cfft.h"
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
55 #include "mdct.h"
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
56
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
57 /* const_tab[]:
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
58 0: sqrt(2 / N)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
59 1: cos(2 * PI / N)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
60 2: sin(2 * PI / N)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
61 3: cos(2 * PI * (1/8) / N)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
62 4: sin(2 * PI * (1/8) / N)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
63 */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
64 #ifdef FIXED_POINT
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
65 real_t const_tab[][5] =
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
66 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
67 { /* 2048 */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
68 COEF_CONST(1),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
69 FRAC_CONST(0.99999529380957619),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
70 FRAC_CONST(0.0030679567629659761),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
71 FRAC_CONST(0.99999992646571789),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
72 FRAC_CONST(0.00038349518757139556)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
73 }, { /* 1920 */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
74 COEF_CONST(/* sqrt(1024/960) */ 1.0327955589886444),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
75 FRAC_CONST(0.99999464540169647),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
76 FRAC_CONST(0.0032724865065266251),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
77 FRAC_CONST(0.99999991633432805),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
78 FRAC_CONST(0.00040906153202803459)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
79 }, { /* 1024 */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
80 COEF_CONST(1),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
81 FRAC_CONST(0.99998117528260111),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
82 FRAC_CONST(0.0061358846491544753),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
83 FRAC_CONST(0.99999970586288223),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
84 FRAC_CONST(0.00076699031874270449)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
85 }, { /* 960 */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
86 COEF_CONST(/* sqrt(512/480) */ 1.0327955589886444),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
87 FRAC_CONST(0.99997858166412923),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
88 FRAC_CONST(0.0065449379673518581),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
89 FRAC_CONST(0.99999966533732598),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
90 FRAC_CONST(0.00081812299560725323)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
91 }, { /* 256 */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
92 COEF_CONST(1),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
93 FRAC_CONST(0.99969881869620425),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
94 FRAC_CONST(0.024541228522912288),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
95 FRAC_CONST(0.99999529380957619),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
96 FRAC_CONST(0.0030679567629659761)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
97 }, { /* 240 */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
98 COEF_CONST(/* sqrt(256/240) */ 1.0327955589886444),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
99 FRAC_CONST(0.99965732497555726),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
100 FRAC_CONST(0.026176948307873149),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
101 FRAC_CONST(0.99999464540169647),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
102 FRAC_CONST(0.0032724865065266251)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
103 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
104 #ifdef SSR_DEC
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
105 ,{ /* 512 */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
106 COEF_CONST(1),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
107 FRAC_CONST(0.9999247018391445),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
108 FRAC_CONST(0.012271538285719925),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
109 FRAC_CONST(0.99999882345170188),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
110 FRAC_CONST(0.0015339801862847655)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
111 }, { /* 64 */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
112 COEF_CONST(1),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
113 FRAC_CONST(0.99518472667219693),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
114 FRAC_CONST(0.098017140329560604),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
115 FRAC_CONST(0.9999247018391445),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
116 FRAC_CONST(0.012271538285719925)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
117 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
118 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
119 };
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
120 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
121
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
122 uint8_t map_N_to_idx(uint16_t N)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
123 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
124 /* gives an index into const_tab above */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
125 /* for normal AAC deocding (eg. no scalable profile) only */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
126 /* index 0 and 4 will be used */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
127 switch(N)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
128 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
129 case 2048: return 0;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
130 case 1920: return 1;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
131 case 1024: return 2;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
132 case 960: return 3;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
133 case 256: return 4;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
134 case 240: return 5;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
135 #ifdef SSR_DEC
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
136 case 512: return 6;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
137 case 64: return 7;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
138 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
139 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
140 return 0;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
141 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
142
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
143 mdct_info *faad_mdct_init(uint16_t N)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
144 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
145 uint16_t k;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
146 #ifdef FIXED_POINT
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
147 uint16_t N_idx;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
148 real_t cangle, sangle, c, s, cold;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
149 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
150 real_t scale;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
151
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
152 mdct_info *mdct = (mdct_info*)malloc(sizeof(mdct_info));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
153
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
154 assert(N % 8 == 0);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
155
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
156 mdct->N = N;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
157 mdct->sincos = (complex_t*)malloc(N/4*sizeof(complex_t));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
158
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
159 #ifdef FIXED_POINT
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
160 N_idx = map_N_to_idx(N);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
161
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
162 scale = const_tab[N_idx][0];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
163 cangle = const_tab[N_idx][1];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
164 sangle = const_tab[N_idx][2];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
165 c = const_tab[N_idx][3];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
166 s = const_tab[N_idx][4];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
167 #else
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
168 scale = (real_t)sqrt(2.0 / (real_t)N);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
169 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
170
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
171 /* (co)sine table build using recurrence relations */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
172 /* this can also be done using static table lookup or */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
173 /* some form of interpolation */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
174 for (k = 0; k < N/4; k++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
175 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
176 #ifdef FIXED_POINT
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
177 RE(mdct->sincos[k]) = c; //MUL_C_C(c,scale);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
178 IM(mdct->sincos[k]) = s; //MUL_C_C(s,scale);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
179
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
180 cold = c;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
181 c = MUL_F(c,cangle) - MUL_F(s,sangle);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
182 s = MUL_F(s,cangle) + MUL_F(cold,sangle);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
183 #else
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
184 /* no recurrence, just sines */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
185 RE(mdct->sincos[k]) = scale*(real_t)(cos(2.0*M_PI*(k+1./8.) / (real_t)N));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
186 IM(mdct->sincos[k]) = scale*(real_t)(sin(2.0*M_PI*(k+1./8.) / (real_t)N));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
187 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
188 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
189
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
190 /* initialise fft */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
191 mdct->cfft = cffti(N/4);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
192
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
193 return mdct;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
194 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
195
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
196 void faad_mdct_end(mdct_info *mdct)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
197 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
198 if (mdct != NULL)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
199 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
200 cfftu(mdct->cfft);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
201
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
202 if (mdct->sincos) free(mdct->sincos);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
203
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
204 free(mdct);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
205 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
206 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
207
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
208 void faad_imdct(mdct_info *mdct, real_t *X_in, real_t *X_out)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
209 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
210 uint16_t k;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
211
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
212 complex_t x;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
213 complex_t Z1[512];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
214 complex_t *sincos = mdct->sincos;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
215
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
216 uint16_t N = mdct->N;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
217 uint16_t N2 = N >> 1;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
218 uint16_t N4 = N >> 2;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
219 uint16_t N8 = N >> 3;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
220
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
221 /* pre-IFFT complex multiplication */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
222 for (k = 0; k < N4; k++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
223 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
224 ComplexMult(&IM(Z1[k]), &RE(Z1[k]),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
225 X_in[2*k], X_in[N2 - 1 - 2*k], RE(sincos[k]), IM(sincos[k]));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
226 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
227
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
228 /* complex IFFT, any non-scaling FFT can be used here */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
229 cfftb(mdct->cfft, Z1);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
230
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
231 /* post-IFFT complex multiplication */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
232 for (k = 0; k < N4; k++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
233 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
234 RE(x) = RE(Z1[k]);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
235 IM(x) = IM(Z1[k]);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
236 ComplexMult(&IM(Z1[k]), &RE(Z1[k]),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
237 IM(x), RE(x), RE(sincos[k]), IM(sincos[k]));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
238
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
239 #ifdef FIXED_POINT
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
240 #if (REAL_BITS == 16)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
241 if (abs(RE(Z1[k])) > REAL_CONST(16383.5))
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
242 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
243 if (RE(Z1[k]) > 0) RE(Z1[k]) = REAL_CONST(32767.0);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
244 else RE(Z1[k]) = REAL_CONST(-32767.0);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
245 } else {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
246 RE(Z1[k]) *= 2;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
247 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
248 if (abs(IM(Z1[k])) > REAL_CONST(16383.5))
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
249 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
250 if (IM(Z1[k]) > 0) IM(Z1[k]) = REAL_CONST(32767.0);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
251 else IM(Z1[k]) = REAL_CONST(-32767.0);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
252 } else {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
253 IM(Z1[k]) *= 2;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
254 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
255 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
256 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
257 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
258
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
259 /* reordering */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
260 for (k = 0; k < N8; k++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
261 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
262 X_out[ 2*k] = IM(Z1[N8 + k]);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
263 X_out[ 1 + 2*k] = -RE(Z1[N8 - 1 - k]);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
264 X_out[N4 + 2*k] = RE(Z1[ k]);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
265 X_out[N4 + 1 + 2*k] = -IM(Z1[N4 - 1 - k]);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
266 X_out[N2 + 2*k] = RE(Z1[N8 + k]);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
267 X_out[N2 + 1 + 2*k] = -IM(Z1[N8 - 1 - k]);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
268 X_out[N2 + N4 + 2*k] = -IM(Z1[ k]);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
269 X_out[N2 + N4 + 1 + 2*k] = RE(Z1[N4 - 1 - k]);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
270 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
271 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
272
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
273 #ifdef LTP_DEC
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
274 void faad_mdct(mdct_info *mdct, real_t *X_in, real_t *X_out)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
275 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
276 uint16_t k;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
277
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
278 complex_t x;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
279 complex_t Z1[512];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
280 complex_t *sincos = mdct->sincos;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
281
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
282 uint16_t N = mdct->N;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
283 uint16_t N2 = N >> 1;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
284 uint16_t N4 = N >> 2;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
285 uint16_t N8 = N >> 3;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
286
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
287 #ifndef FIXED_POINT
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
288 real_t scale = REAL_CONST(N);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
289 #else
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
290 real_t scale = REAL_CONST(4.0/N);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
291 #endif
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
292
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
293 /* pre-FFT complex multiplication */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
294 for (k = 0; k < N8; k++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
295 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
296 uint16_t n = k << 1;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
297 RE(x) = X_in[N - N4 - 1 - n] + X_in[N - N4 + n];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
298 IM(x) = X_in[ N4 + n] - X_in[ N4 - 1 - n];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
299
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
300 ComplexMult(&RE(Z1[k]), &IM(Z1[k]),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
301 RE(x), IM(x), RE(sincos[k]), IM(sincos[k]));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
302
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
303 RE(Z1[k]) = MUL_R(RE(Z1[k]), scale);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
304 IM(Z1[k]) = MUL_R(IM(Z1[k]), scale);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
305
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
306 RE(x) = X_in[N2 - 1 - n] - X_in[ n];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
307 IM(x) = X_in[N2 + n] + X_in[N - 1 - n];
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
308
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
309 ComplexMult(&RE(Z1[k + N8]), &IM(Z1[k + N8]),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
310 RE(x), IM(x), RE(sincos[k + N8]), IM(sincos[k + N8]));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
311
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
312 RE(Z1[k + N8]) = MUL_R(RE(Z1[k + N8]), scale);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
313 IM(Z1[k + N8]) = MUL_R(IM(Z1[k + N8]), scale);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
314 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
315
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
316 /* complex FFT, any non-scaling FFT can be used here */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
317 cfftf(mdct->cfft, Z1);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
318
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
319 /* post-FFT complex multiplication */
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
320 for (k = 0; k < N4; k++)
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
321 {
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
322 uint16_t n = k << 1;
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
323 ComplexMult(&RE(x), &IM(x),
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
324 RE(Z1[k]), IM(Z1[k]), RE(sincos[k]), IM(sincos[k]));
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
325
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
326 X_out[ n] = -RE(x);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
327 X_out[N2 - 1 - n] = IM(x);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
328 X_out[N2 + n] = -IM(x);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
329 X_out[N - 1 - n] = RE(x);
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
330 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
331 }
6efb9e514224 [svn] Import AAC stuff.
nenolod
parents:
diff changeset
332 #endif