annotate libfaad2/mdct.c @ 10875:a0d3ce3d87af

fixed " character
author nauj27
date Tue, 16 Sep 2003 15:45:58 +0000
parents e989150f8216
children 3185f64f6350
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 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
25 ** $Id: mdct.c,v 1.26 2003/07/29 08:20:12 menno Exp $
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 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 switch(N)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 case 2048: return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 case 1920: return 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 case 1024: return 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 case 960: return 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 case 256: return 4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 case 240: return 5;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 #ifdef SSR_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 case 512: return 6;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 case 64: return 7;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 mdct_info *faad_mdct_init(uint16_t N)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 uint16_t k, N_idx;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 real_t cangle, sangle, c, s, cold;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136 real_t scale;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 mdct_info *mdct = (mdct_info*)malloc(sizeof(mdct_info));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 assert(N % 8 == 0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 mdct->N = N;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 mdct->sincos = (complex_t*)malloc(N/4*sizeof(complex_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 mdct->Z1 = (complex_t*)malloc(N/4*sizeof(complex_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 N_idx = map_N_to_idx(N);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 scale = const_tab[N_idx][0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 cangle = const_tab[N_idx][1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 sangle = const_tab[N_idx][2];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 c = const_tab[N_idx][3];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 s = const_tab[N_idx][4];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 for (k = 0; k < N/4; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 RE(mdct->sincos[k]) = -1*MUL_C_C(c,scale);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 IM(mdct->sincos[k]) = -1*MUL_C_C(s,scale);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159 cold = c;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 c = MUL_C_C(c,cangle) - MUL_C_C(s,sangle);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 s = MUL_C_C(s,cangle) + MUL_C_C(cold,sangle);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 /* initialise fft */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 mdct->cfft = cffti(N/4);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 return mdct;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 void faad_mdct_end(mdct_info *mdct)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172 if (mdct != NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 cfftu(mdct->cfft);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
176 if (mdct->Z1) free(mdct->Z1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177 if (mdct->sincos) free(mdct->sincos);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
178
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
179 free(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
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
183 void faad_imdct(mdct_info *mdct, real_t *X_in, real_t *X_out)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185 uint16_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 complex_t x;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188 complex_t *Z1 = mdct->Z1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 complex_t *sincos = mdct->sincos;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 uint16_t N = mdct->N;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 uint16_t N2 = N >> 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 uint16_t N4 = N >> 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 uint16_t N8 = N >> 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 /* pre-IFFT complex multiplication */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 for (k = 0; k < N4; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 uint16_t n = k << 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 RE(x) = X_in[ n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201 IM(x) = X_in[N2 - 1 - n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 RE(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
203 IM(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
204 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 /* complex IFFT */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 cfftb(mdct->cfft, Z1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 /* post-IFFT complex multiplication */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210 for (k = 0; k < N4; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 uint16_t n = k << 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 RE(x) = RE(Z1[k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 IM(x) = IM(Z1[k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216 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
217 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
218 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220 /* reordering */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 for (k = 0; k < N8; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 uint16_t n = k << 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 X_out[ n] = IM(Z1[N8 + k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 X_out[ 1 + n] = -RE(Z1[N8 - 1 - k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 X_out[N4 + n] = RE(Z1[ k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227 X_out[N4 + 1 + n] = -IM(Z1[N4 - 1 - k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 X_out[N2 + n] = RE(Z1[N8 + k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 X_out[N2 + 1 + n] = -IM(Z1[N8 - 1 - k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 X_out[N2 + N4 + n] = -IM(Z1[ k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 X_out[N2 + N4 + 1 + n] = RE(Z1[N4 - 1 - k]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 #ifdef LTP_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 void faad_mdct(mdct_info *mdct, real_t *X_in, real_t *X_out)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238 uint16_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 complex_t x;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241 complex_t *Z1 = mdct->Z1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242 complex_t *sincos = mdct->sincos;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244 uint16_t N = mdct->N;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 uint16_t N2 = N >> 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246 uint16_t N4 = N >> 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247 uint16_t N8 = N >> 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 real_t scale = REAL_CONST(N);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251 /* pre-FFT complex multiplication */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252 for (k = 0; k < N8; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254 uint16_t n = k << 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255 RE(x) = X_in[N - N4 - 1 - n] + X_in[N - N4 + n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256 IM(x) = X_in[ N4 + n] - X_in[ N4 - 1 - n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 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
259 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
260
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 RE(x) = X_in[N2 - 1 - n] - X_in[ n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262 IM(x) = X_in[N2 + n] + X_in[N - 1 - n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264 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
265 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
266 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
267
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
268 /* complex FFT */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
269 cfftf(mdct->cfft, Z1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
270
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
271 /* post-FFT complex multiplication */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
272 for (k = 0; k < N4; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274 uint16_t n = k << 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275 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
276 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
277
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 X_out[ n] = RE(x);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 X_out[N2 - 1 - n] = -IM(x);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280 X_out[N2 + n] = IM(x);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281 X_out[N - 1 - n] = -RE(x);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
282 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284 #endif