annotate libfaad2/mdct.c @ 14561:a226d301eec1

Handle missing palettes in the info part of VobSubs in Matroska files correctly by giving mplayer a NULL pointer. This way it will use a default palette instead of black only. Patch by Csillag Kristof (fenwick () freemail ! hu)
author mosu
date Fri, 21 Jan 2005 18:25:44 +0000
parents 6d50ef45a058
children 2ae5ab4331ca
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
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
10725
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 **
12625
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
26 ** $Id: mdct.c,v 1.4 2004/06/23 13:50:51 diego Exp $
12625
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31 * Fast (I)MDCT Implementation using (I)FFT ((Inverse) Fast Fourier Transform)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32 * and consists of three steps: pre-(I)FFT complex multiplication, complex
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33 * (I)FFT, post-(I)FFT complex multiplication,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 * As described in:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 * P. Duhamel, Y. Mahieux, and J.P. Petit, "A Fast Algorithm for the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 * Implementation of Filter Banks Based on 'Time Domain Aliasing
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 * Cancellation’," IEEE Proc. on ICASSP‘91, 1991, pp. 2209-2212.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 * As of April 6th 2002 completely rewritten.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42 * 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
43 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 #include <stdlib.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 #ifdef _WIN32_WCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 #define assert(x)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52 #else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53 #include <assert.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56 #include "cfft.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 #include "mdct.h"
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
58 #include "mdct_tab.h"
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 mdct_info *faad_mdct_init(uint16_t N)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
63 mdct_info *mdct = (mdct_info*)faad_malloc(sizeof(mdct_info));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65 assert(N % 8 == 0);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67 mdct->N = N;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
69 /* NOTE: For "small framelengths" in FIXED_POINT the coefficients need to be
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
70 * scaled by sqrt("(nearest power of 2) > N" / N) */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
72 /* RE(mdct->sincos[k]) = scale*(real_t)(cos(2.0*M_PI*(k+1./8.) / (real_t)N));
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
73 * IM(mdct->sincos[k]) = scale*(real_t)(sin(2.0*M_PI*(k+1./8.) / (real_t)N)); */
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
74 /* scale is 1 for fixed point, sqrt(N) for floating point */
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
75 switch (N)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76 {
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
77 case 2048: mdct->sincos = (complex_t*)mdct_tab_2048; break;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
78 case 256: mdct->sincos = (complex_t*)mdct_tab_256; break;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
79 #ifdef LD_DEC
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
80 case 1024: mdct->sincos = (complex_t*)mdct_tab_1024; break;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
81 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
82 #ifdef ALLOW_SMALL_FRAMELENGTH
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
83 case 1920: mdct->sincos = (complex_t*)mdct_tab_1920; break;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
84 case 240: mdct->sincos = (complex_t*)mdct_tab_240; break;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
85 #ifdef LD_DEC
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
86 case 960: mdct->sincos = (complex_t*)mdct_tab_960; break;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
87 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
88 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
89 #ifdef SSR_DEC
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
90 case 512: mdct->sincos = (complex_t*)mdct_tab_512; break;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
91 case 64: mdct->sincos = (complex_t*)mdct_tab_64; break;
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
92 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 /* initialise fft */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 mdct->cfft = cffti(N/4);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
98 #ifdef PROFILE
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
99 mdct->cycles = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
100 mdct->fft_cycles = 0;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
101 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
102
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 return mdct;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 void faad_mdct_end(mdct_info *mdct)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 if (mdct != NULL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
110 #ifdef PROFILE
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
111 printf("MDCT[%.4d]: %I64d cycles\n", mdct->N, mdct->cycles);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
112 printf("CFFT[%.4d]: %I64d cycles\n", mdct->N/4, mdct->fft_cycles);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
113 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
114
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 cfftu(mdct->cfft);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
117 faad_free(mdct);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 void faad_imdct(mdct_info *mdct, real_t *X_in, real_t *X_out)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 uint16_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 complex_t x;
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
126 #ifdef ALLOW_SMALL_FRAMELENGTH
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
127 #ifdef FIXED_POINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
128 real_t scale, b_scale = 0;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
129 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
130 #endif
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
131 ALIGN complex_t Z1[512];
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
132 complex_t *sincos = mdct->sincos;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
133
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
134 uint16_t N = mdct->N;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
135 uint16_t N2 = N >> 1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
136 uint16_t N4 = N >> 2;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
137 uint16_t N8 = N >> 3;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
138
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
139 #ifdef PROFILE
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
140 int64_t count1, count2 = faad_get_ts();
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
141 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
142
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
143 #ifdef ALLOW_SMALL_FRAMELENGTH
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
144 #ifdef FIXED_POINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
145 /* detect non-power of 2 */
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
146 if (N & (N-1))
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
147 {
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
148 /* adjust scale for non-power of 2 MDCT */
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
149 /* 2048/1920 */
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
150 b_scale = 1;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
151 scale = COEF_CONST(1.0666666666666667);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
152 }
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
153 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
154 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
155
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
156 /* pre-IFFT complex multiplication */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
157 for (k = 0; k < N4; k++)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
158 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
159 ComplexMult(&IM(Z1[k]), &RE(Z1[k]),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
160 X_in[2*k], X_in[N2 - 1 - 2*k], RE(sincos[k]), IM(sincos[k]));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
161 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
162
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
163 #ifdef PROFILE
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
164 count1 = faad_get_ts();
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
165 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
166
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
167 /* complex IFFT, any non-scaling FFT can be used here */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
168 cfftb(mdct->cfft, Z1);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
169
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
170 #ifdef PROFILE
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
171 count1 = faad_get_ts() - count1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
172 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
173
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
174 /* post-IFFT complex multiplication */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
175 for (k = 0; k < N4; k++)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
176 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
177 RE(x) = RE(Z1[k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
178 IM(x) = IM(Z1[k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
179 ComplexMult(&IM(Z1[k]), &RE(Z1[k]),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
180 IM(x), RE(x), RE(sincos[k]), IM(sincos[k]));
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
181
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
182 #ifdef ALLOW_SMALL_FRAMELENGTH
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
183 #ifdef FIXED_POINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
184 /* non-power of 2 MDCT scaling */
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
185 if (b_scale)
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
186 {
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
187 RE(Z1[k]) = MUL_C(RE(Z1[k]), scale);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
188 IM(Z1[k]) = MUL_C(IM(Z1[k]), scale);
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
189 }
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
190 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
191 #endif
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
192 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
193
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
194 /* reordering */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
195 for (k = 0; k < N8; k+=2)
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
196 {
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
197 X_out[ 2*k] = IM(Z1[N8 + k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
198 X_out[ 2 + 2*k] = IM(Z1[N8 + 1 + k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
199
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
200 X_out[ 1 + 2*k] = -RE(Z1[N8 - 1 - k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
201 X_out[ 3 + 2*k] = -RE(Z1[N8 - 2 - k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
202
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
203 X_out[N4 + 2*k] = RE(Z1[ k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
204 X_out[N4 + + 2 + 2*k] = RE(Z1[ 1 + k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
205
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
206 X_out[N4 + 1 + 2*k] = -IM(Z1[N4 - 1 - k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
207 X_out[N4 + 3 + 2*k] = -IM(Z1[N4 - 2 - k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
208
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
209 X_out[N2 + 2*k] = RE(Z1[N8 + k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
210 X_out[N2 + + 2 + 2*k] = RE(Z1[N8 + 1 + k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
211
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
212 X_out[N2 + 1 + 2*k] = -IM(Z1[N8 - 1 - k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
213 X_out[N2 + 3 + 2*k] = -IM(Z1[N8 - 2 - k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
214
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
215 X_out[N2 + N4 + 2*k] = -IM(Z1[ k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
216 X_out[N2 + N4 + 2 + 2*k] = -IM(Z1[ 1 + k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
217
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
218 X_out[N2 + N4 + 1 + 2*k] = RE(Z1[N4 - 1 - k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
219 X_out[N2 + N4 + 3 + 2*k] = RE(Z1[N4 - 2 - k]);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
220 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
221
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
222 #ifdef PROFILE
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
223 count2 = faad_get_ts() - count2;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
224 mdct->fft_cycles += count1;
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
225 mdct->cycles += (count2 - count1);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
226 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
227 }
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
228
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 #ifdef LTP_DEC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 void faad_mdct(mdct_info *mdct, real_t *X_in, real_t *X_out)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 uint16_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234 complex_t x;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
235 ALIGN complex_t Z1[512];
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 complex_t *sincos = mdct->sincos;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238 uint16_t N = mdct->N;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 uint16_t N2 = N >> 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 uint16_t N4 = N >> 2;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241 uint16_t N8 = N >> 3;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
243 #ifndef FIXED_POINT
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244 real_t scale = REAL_CONST(N);
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
245 #else
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
246 real_t scale = REAL_CONST(4.0/N);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
247 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
249 #ifdef ALLOW_SMALL_FRAMELENGTH
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
250 #ifdef FIXED_POINT
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
251 /* detect non-power of 2 */
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
252 if (N & (N-1))
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
253 {
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
254 /* adjust scale for non-power of 2 MDCT */
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
255 /* *= sqrt(2048/1920) */
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
256 scale = MUL_C(scale, COEF_CONST(1.0327955589886444));
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
257 }
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
258 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
259 #endif
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
260
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 /* pre-FFT complex multiplication */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262 for (k = 0; k < N8; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264 uint16_t n = k << 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265 RE(x) = X_in[N - N4 - 1 - n] + X_in[N - N4 + n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266 IM(x) = X_in[ N4 + n] - X_in[ N4 - 1 - n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
267
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
268 ComplexMult(&RE(Z1[k]), &IM(Z1[k]),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
269 RE(x), IM(x), RE(sincos[k]), IM(sincos[k]));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
270
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
271 RE(Z1[k]) = MUL_R(RE(Z1[k]), scale);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
272 IM(Z1[k]) = MUL_R(IM(Z1[k]), scale);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274 RE(x) = X_in[N2 - 1 - n] - X_in[ n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275 IM(x) = X_in[N2 + n] + X_in[N - 1 - n];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
277 ComplexMult(&RE(Z1[k + N8]), &IM(Z1[k + N8]),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
278 RE(x), IM(x), RE(sincos[k + N8]), IM(sincos[k + N8]));
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
279
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
280 RE(Z1[k + N8]) = MUL_R(RE(Z1[k + N8]), scale);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
281 IM(Z1[k + N8]) = MUL_R(IM(Z1[k + N8]), scale);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
282 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
284 /* complex FFT, any non-scaling FFT can be used here */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
285 cfftf(mdct->cfft, Z1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
286
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
287 /* post-FFT complex multiplication */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288 for (k = 0; k < N4; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290 uint16_t n = k << 1;
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
291 ComplexMult(&RE(x), &IM(x),
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
292 RE(Z1[k]), IM(Z1[k]), RE(sincos[k]), IM(sincos[k]));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
293
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
294 X_out[ n] = -RE(x);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
295 X_out[N2 - 1 - n] = IM(x);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
296 X_out[N2 + n] = -IM(x);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
297 X_out[N - 1 - n] = RE(x);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
298 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
299 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300 #endif