annotate libfaad2/mdct.c @ 11527:f649a00416e5

Use SMC decoder from libavcodec
author rtognimp
date Wed, 26 Nov 2003 21:00:10 +0000
parents 3185f64f6350
children 4a370c80fe5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
4 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
8 ** (at your option) any later version.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
9 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
13 ** GNU General Public License for more details.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
14 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
18 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
20 ** forbidden.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
21 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
24 **
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
25 ** $Id: mdct.c,v 1.28 2003/09/30 12:43:05 menno Exp $
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
26 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
27
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29 * Fast (I)MDCT Implementation using (I)FFT ((Inverse) Fast Fourier Transform)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30 * and consists of three steps: pre-(I)FFT complex multiplication, complex
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31 * (I)FFT, post-(I)FFT complex multiplication,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33 * As described in:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34 * P. Duhamel, Y. Mahieux, and J.P. Petit, "A Fast Algorithm for the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 * Implementation of Filter Banks Based on 'Time Domain Aliasing
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 * Cancellation’," IEEE Proc. on ICASSP‘91, 1991, pp. 2209-2212.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39 * As of April 6th 2002 completely rewritten.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 * This (I)MDCT can now be used for any data size n, where n is divisible by 8.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 #include <stdlib.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 #ifdef _WIN32_WCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 #define assert(x)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 #include <assert.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54 #include "cfft.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 #include "mdct.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 /* const_tab[]:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 0: sqrt(2 / N)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 1: cos(2 * PI / N)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 2: sin(2 * PI / N)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 3: cos(2 * PI * (1/8) / N)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 4: sin(2 * PI * (1/8) / N)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64 #ifndef FIXED_POINT
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65 #ifdef _MSC_VER
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 #pragma warning(disable:4305)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67 #pragma warning(disable:4244)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 real_t const_tab[][5] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 { COEF_CONST(0.0312500000), COEF_CONST(0.9999952938), COEF_CONST(0.0030679568),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 COEF_CONST(0.9999999265), COEF_CONST(0.0003834952) }, /* 2048 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 { COEF_CONST(0.0322748612), COEF_CONST(0.9999946356), COEF_CONST(0.0032724866),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 COEF_CONST(0.9999999404), COEF_CONST(0.0004090615) }, /* 1920 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 { COEF_CONST(0.0441941738), COEF_CONST(0.9999811649), COEF_CONST(0.0061358847),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 COEF_CONST(0.9999997020), COEF_CONST(0.0007669903) }, /* 1024 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 { COEF_CONST(0.0456435465), COEF_CONST(0.9999786019), COEF_CONST(0.0065449383),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 COEF_CONST(0.9999996424), COEF_CONST(0.0008181230) }, /* 960 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 { COEF_CONST(0.0883883476), COEF_CONST(0.9996988177), COEF_CONST(0.0245412290),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 COEF_CONST(0.9999952912), COEF_CONST(0.0030679568) }, /* 256 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81 { COEF_CONST(0.0912870929), COEF_CONST(0.9996573329), COEF_CONST(0.0261769500),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 COEF_CONST(0.9999946356), COEF_CONST(0.0032724866) } /* 240 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 ,{ COEF_CONST(0.062500000), COEF_CONST(0.999924702), COEF_CONST(0.012271538),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 COEF_CONST(0.999998823), COEF_CONST(0.00153398) }, /* 512 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 { COEF_CONST(0.176776695), COEF_CONST(0.995184727), COEF_CONST(0.09801714),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 COEF_CONST(0.999924702), COEF_CONST(0.012271538) } /* 64 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91 real_t const_tab[][5] =
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 { COEF_CONST(1), COEF_CONST(0.9999952938), COEF_CONST(0.0030679568),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 COEF_CONST(0.9999999265), COEF_CONST(0.0003834952) }, /* 2048 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 { COEF_CONST(/* sqrt(1024/960) */ 1.03279556), COEF_CONST(0.9999946356), COEF_CONST(0.0032724866),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 COEF_CONST(0), COEF_CONST(0.0004090615) }, /* 1920 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97 { COEF_CONST(1), COEF_CONST(0.9999811649), COEF_CONST(0.0061358847),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 COEF_CONST(0.9999997020), COEF_CONST(0.0007669903) }, /* 1024 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 { COEF_CONST(/* sqrt(512/480) */ 1.03279556), COEF_CONST(0.9999786019), COEF_CONST(0.0065449383),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 COEF_CONST(0.9999996424), COEF_CONST(0.0008181230) }, /* 960 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 { COEF_CONST(1), COEF_CONST(0.9996988177), COEF_CONST(0.0245412290),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102 COEF_CONST(0.9999952912), COEF_CONST(0.0030679568) }, /* 256 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 { COEF_CONST(/* sqrt(256/240) */ 1.03279556), COEF_CONST(0.9996573329), COEF_CONST(0.0261769500),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 COEF_CONST(0.9999946356), COEF_CONST(0.0032724866) } /* 240 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 ,{ COEF_CONST(0), COEF_CONST(0.999924702), COEF_CONST(0.012271538),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 COEF_CONST(0.999998823), COEF_CONST(0.00153398) }, /* 512 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 { COEF_CONST(0), COEF_CONST(0.995184727), COEF_CONST(0.09801714),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 COEF_CONST(0.999924702), COEF_CONST(0.012271538) } /* 64 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 uint8_t map_N_to_idx(uint16_t N)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
116 /* gives an index into const_tab above */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
117 /* for normal AAC deocding (eg. no scalable profile) only */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
118 /* index 0 and 4 will be used */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 switch(N)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 case 2048: return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 case 1920: return 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 case 1024: return 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 case 960: return 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 case 256: return 4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 case 240: return 5;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 case 512: return 6;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 case 64: return 7;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 mdct_info *faad_mdct_init(uint16_t N)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 uint16_t k, N_idx;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 real_t cangle, sangle, c, s, cold;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 real_t scale;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 mdct_info *mdct = (mdct_info*)malloc(sizeof(mdct_info));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 assert(N % 8 == 0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145 mdct->N = N;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 mdct->sincos = (complex_t*)malloc(N/4*sizeof(complex_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 mdct->Z1 = (complex_t*)malloc(N/4*sizeof(complex_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 N_idx = map_N_to_idx(N);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 scale = const_tab[N_idx][0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 cangle = const_tab[N_idx][1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 sangle = const_tab[N_idx][2];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 c = const_tab[N_idx][3];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 s = const_tab[N_idx][4];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
157 /* (co)sine table build using recurrence relations */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
158 /* this can also be done using static table lookup or */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
159 /* some form of interpolation */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 for (k = 0; k < N/4; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
162 #if 1
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 RE(mdct->sincos[k]) = -1*MUL_C_C(c,scale);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 IM(mdct->sincos[k]) = -1*MUL_C_C(s,scale);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 cold = c;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 c = MUL_C_C(c,cangle) - MUL_C_C(s,sangle);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 s = MUL_C_C(s,cangle) + MUL_C_C(cold,sangle);
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
169 #else
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
170 /* no recurrence, just sines */
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
171 RE(mdct->sincos[k]) = -scale*cos(2.0*M_PI*(k+1./8.) / (float)N);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
172 IM(mdct->sincos[k]) = -scale*sin(2.0*M_PI*(k+1./8.) / (float)N);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
173 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
176 /* initialise fft */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177 mdct->cfft = cffti(N/4);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
178
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
179 return mdct;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182 void faad_mdct_end(mdct_info *mdct)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
183 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 if (mdct != NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186 cfftu(mdct->cfft);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188 if (mdct->Z1) free(mdct->Z1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 if (mdct->sincos) free(mdct->sincos);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 free(mdct);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 void faad_imdct(mdct_info *mdct, real_t *X_in, real_t *X_out)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 uint16_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 complex_t x;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 complex_t *Z1 = mdct->Z1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201 complex_t *sincos = mdct->sincos;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 uint16_t N = mdct->N;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204 uint16_t N2 = N >> 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205 uint16_t N4 = N >> 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 uint16_t N8 = N >> 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 /* pre-IFFT complex multiplication */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 for (k = 0; k < N4; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
211 RE(Z1[k]) = MUL_R_C(X_in[N2 - 1 - 2*k], RE(sincos[k])) - MUL_R_C(X_in[2*k], IM(sincos[k]));
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
212 IM(Z1[k]) = MUL_R_C(X_in[2*k], RE(sincos[k])) + MUL_R_C(X_in[N2 - 1 - 2*k], IM(sincos[k]));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
215 /* complex IFFT, any non-scaling FFT can be used here */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216 cfftb(mdct->cfft, Z1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218 /* post-IFFT complex multiplication */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 for (k = 0; k < N4; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 RE(x) = RE(Z1[k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 IM(x) = IM(Z1[k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 RE(Z1[k]) = MUL_R_C(RE(x), RE(sincos[k])) - MUL_R_C(IM(x), IM(sincos[k]));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 IM(Z1[k]) = MUL_R_C(IM(x), RE(sincos[k])) + MUL_R_C(RE(x), IM(sincos[k]));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 /* reordering */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 for (k = 0; k < N8; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
231 X_out[ 2*k] = IM(Z1[N8 + k]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
232 X_out[ 1 + 2*k] = -RE(Z1[N8 - 1 - k]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
233 X_out[N4 + 2*k] = RE(Z1[ k]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
234 X_out[N4 + 1 + 2*k] = -IM(Z1[N4 - 1 - k]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
235 X_out[N2 + 2*k] = RE(Z1[N8 + k]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
236 X_out[N2 + 1 + 2*k] = -IM(Z1[N8 - 1 - k]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
237 X_out[N2 + N4 + 2*k] = -IM(Z1[ k]);
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
238 X_out[N2 + N4 + 1 + 2*k] = RE(Z1[N4 - 1 - k]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242 #ifdef LTP_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243 void faad_mdct(mdct_info *mdct, real_t *X_in, real_t *X_out)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 uint16_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247 complex_t x;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248 complex_t *Z1 = mdct->Z1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 complex_t *sincos = mdct->sincos;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251 uint16_t N = mdct->N;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252 uint16_t N2 = N >> 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253 uint16_t N4 = N >> 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254 uint16_t N8 = N >> 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256 real_t scale = REAL_CONST(N);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 /* pre-FFT complex multiplication */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259 for (k = 0; k < N8; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 uint16_t n = k << 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262 RE(x) = X_in[N - N4 - 1 - n] + X_in[N - N4 + n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263 IM(x) = X_in[ N4 + n] - X_in[ N4 - 1 - n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265 RE(Z1[k]) = -MUL_R_C(RE(x), RE(sincos[k])) - MUL_R_C(IM(x), IM(sincos[k]));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266 IM(Z1[k]) = -MUL_R_C(IM(x), RE(sincos[k])) + MUL_R_C(RE(x), IM(sincos[k]));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
267
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
268 RE(x) = X_in[N2 - 1 - n] - X_in[ n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
269 IM(x) = X_in[N2 + n] + X_in[N - 1 - n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
270
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
271 RE(Z1[k + N8]) = -MUL_R_C(RE(x), RE(sincos[k + N8])) - MUL_R_C(IM(x), IM(sincos[k + N8]));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
272 IM(Z1[k + N8]) = -MUL_R_C(IM(x), RE(sincos[k + N8])) + MUL_R_C(RE(x), IM(sincos[k + N8]));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
275 /* complex FFT, any non-scaling FFT can be used here */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 cfftf(mdct->cfft, Z1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 /* post-FFT complex multiplication */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 for (k = 0; k < N4; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281 uint16_t n = k << 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
282 RE(x) = MUL(MUL_R_C(RE(Z1[k]), RE(sincos[k])) + MUL_R_C(IM(Z1[k]), IM(sincos[k])), scale);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283 IM(x) = MUL(MUL_R_C(IM(Z1[k]), RE(sincos[k])) - MUL_R_C(RE(Z1[k]), IM(sincos[k])), scale);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
285 X_out[ n] = RE(x);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
286 X_out[N2 - 1 - n] = -IM(x);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
287 X_out[N2 + n] = IM(x);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288 X_out[N - 1 - n] = -RE(x);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
291 #endif