annotate liba52/imdct.c @ 579:ba17f7dbe745 libavcodec

moved codebooks to svq1_cb.h
author al3x
date Mon, 22 Jul 2002 20:51:26 +0000
parents dd4f4c3d7171
children 68d0a38bd802
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
332
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
1 /*
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
2 * imdct.c
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
3 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
5 *
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
6 * The ifft algorithms in this file have been largely inspired by Dan
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
7 * Bernstein's work, djbfft, available at http://cr.yp.to/djbfft.html
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
8 *
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
9 * This file is part of a52dec, a free ATSC A-52 stream decoder.
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
10 * See http://liba52.sourceforge.net/ for updates.
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
11 *
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
12 * a52dec is free software; you can redistribute it and/or modify
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
13 * it under the terms of the GNU General Public License as published by
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
15 * (at your option) any later version.
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
16 *
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
17 * a52dec is distributed in the hope that it will be useful,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
20 * GNU General Public License for more details.
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
21 *
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
23 * along with this program; if not, write to the Free Software
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
25 */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
26
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
27 #include "a52.h"
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
28 #include "a52_internal.h"
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
29 #include "mm_accel.h"
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
30
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
31 typedef struct complex_s {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
32 sample_t real;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
33 sample_t imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
34 } complex_t;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
35
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
36 static complex_t buf[128];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
37
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
38 static uint8_t fftorder[] = {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
39 0,128, 64,192, 32,160,224, 96, 16,144, 80,208,240,112, 48,176,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
40 8,136, 72,200, 40,168,232,104,248,120, 56,184, 24,152,216, 88,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
41 4,132, 68,196, 36,164,228,100, 20,148, 84,212,244,116, 52,180,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
42 252,124, 60,188, 28,156,220, 92, 12,140, 76,204,236,108, 44,172,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
43 2,130, 66,194, 34,162,226, 98, 18,146, 82,210,242,114, 50,178,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
44 10,138, 74,202, 42,170,234,106,250,122, 58,186, 26,154,218, 90,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
45 254,126, 62,190, 30,158,222, 94, 14,142, 78,206,238,110, 46,174,
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
46 6,134, 70,198, 38,166,230,102,246,118, 54,182, 22,150,214, 86
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
47 };
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
48
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
49 /* Root values for IFFT */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
50 static sample_t roots16[3];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
51 static sample_t roots32[7];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
52 static sample_t roots64[15];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
53 static sample_t roots128[31];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
54
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
55 /* Twiddle factors for IMDCT */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
56 static complex_t pre1[128];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
57 static complex_t post1[64];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
58 static complex_t pre2[64];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
59 static complex_t post2[32];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
60
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
61 static sample_t a52_imdct_window[256];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
62
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
63 static void (* ifft128) (complex_t * buf);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
64 static void (* ifft64) (complex_t * buf);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
65
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
66 static inline void ifft2 (complex_t * buf)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
67 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
68 double r, i;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
69
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
70 r = buf[0].real;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
71 i = buf[0].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
72 buf[0].real += buf[1].real;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
73 buf[0].imag += buf[1].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
74 buf[1].real = r - buf[1].real;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
75 buf[1].imag = i - buf[1].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
76 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
77
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
78 static inline void ifft4 (complex_t * buf)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
79 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
80 double tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
81
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
82 tmp1 = buf[0].real + buf[1].real;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
83 tmp2 = buf[3].real + buf[2].real;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
84 tmp3 = buf[0].imag + buf[1].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
85 tmp4 = buf[2].imag + buf[3].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
86 tmp5 = buf[0].real - buf[1].real;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
87 tmp6 = buf[0].imag - buf[1].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
88 tmp7 = buf[2].imag - buf[3].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
89 tmp8 = buf[3].real - buf[2].real;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
90
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
91 buf[0].real = tmp1 + tmp2;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
92 buf[0].imag = tmp3 + tmp4;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
93 buf[2].real = tmp1 - tmp2;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
94 buf[2].imag = tmp3 - tmp4;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
95 buf[1].real = tmp5 + tmp7;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
96 buf[1].imag = tmp6 + tmp8;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
97 buf[3].real = tmp5 - tmp7;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
98 buf[3].imag = tmp6 - tmp8;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
99 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
100
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
101 /* the basic split-radix ifft butterfly */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
102
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
103 #define BUTTERFLY(a0,a1,a2,a3,wr,wi) do { \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
104 tmp5 = a2.real * wr + a2.imag * wi; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
105 tmp6 = a2.imag * wr - a2.real * wi; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
106 tmp7 = a3.real * wr - a3.imag * wi; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
107 tmp8 = a3.imag * wr + a3.real * wi; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
108 tmp1 = tmp5 + tmp7; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
109 tmp2 = tmp6 + tmp8; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
110 tmp3 = tmp6 - tmp8; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
111 tmp4 = tmp7 - tmp5; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
112 a2.real = a0.real - tmp1; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
113 a2.imag = a0.imag - tmp2; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
114 a3.real = a1.real - tmp3; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
115 a3.imag = a1.imag - tmp4; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
116 a0.real += tmp1; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
117 a0.imag += tmp2; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
118 a1.real += tmp3; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
119 a1.imag += tmp4; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
120 } while (0)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
121
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
122 /* split-radix ifft butterfly, specialized for wr=1 wi=0 */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
123
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
124 #define BUTTERFLY_ZERO(a0,a1,a2,a3) do { \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
125 tmp1 = a2.real + a3.real; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
126 tmp2 = a2.imag + a3.imag; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
127 tmp3 = a2.imag - a3.imag; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
128 tmp4 = a3.real - a2.real; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
129 a2.real = a0.real - tmp1; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
130 a2.imag = a0.imag - tmp2; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
131 a3.real = a1.real - tmp3; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
132 a3.imag = a1.imag - tmp4; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
133 a0.real += tmp1; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
134 a0.imag += tmp2; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
135 a1.real += tmp3; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
136 a1.imag += tmp4; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
137 } while (0)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
138
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
139 /* split-radix ifft butterfly, specialized for wr=wi */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
140
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
141 #define BUTTERFLY_HALF(a0,a1,a2,a3,w) do { \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
142 tmp5 = (a2.real + a2.imag) * w; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
143 tmp6 = (a2.imag - a2.real) * w; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
144 tmp7 = (a3.real - a3.imag) * w; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
145 tmp8 = (a3.imag + a3.real) * w; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
146 tmp1 = tmp5 + tmp7; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
147 tmp2 = tmp6 + tmp8; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
148 tmp3 = tmp6 - tmp8; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
149 tmp4 = tmp7 - tmp5; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
150 a2.real = a0.real - tmp1; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
151 a2.imag = a0.imag - tmp2; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
152 a3.real = a1.real - tmp3; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
153 a3.imag = a1.imag - tmp4; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
154 a0.real += tmp1; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
155 a0.imag += tmp2; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
156 a1.real += tmp3; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
157 a1.imag += tmp4; \
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
158 } while (0)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
159
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
160 static inline void ifft8 (complex_t * buf)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
161 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
162 double tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
163
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
164 ifft4 (buf);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
165 ifft2 (buf + 4);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
166 ifft2 (buf + 6);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
167 BUTTERFLY_ZERO (buf[0], buf[2], buf[4], buf[6]);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
168 BUTTERFLY_HALF (buf[1], buf[3], buf[5], buf[7], roots16[1]);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
169 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
170
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
171 static void ifft_pass (complex_t * buf, sample_t * weight, int n)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
172 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
173 complex_t * buf1;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
174 complex_t * buf2;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
175 complex_t * buf3;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
176 double tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
177 int i;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
178
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
179 buf++;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
180 buf1 = buf + n;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
181 buf2 = buf + 2 * n;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
182 buf3 = buf + 3 * n;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
183
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
184 BUTTERFLY_ZERO (buf[-1], buf1[-1], buf2[-1], buf3[-1]);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
185
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
186 i = n - 1;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
187
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
188 do {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
189 BUTTERFLY (buf[0], buf1[0], buf2[0], buf3[0], weight[n], weight[2*i]);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
190 buf++;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
191 buf1++;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
192 buf2++;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
193 buf3++;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
194 weight++;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
195 } while (--i);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
196 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
197
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
198 static void ifft16 (complex_t * buf)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
199 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
200 ifft8 (buf);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
201 ifft4 (buf + 8);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
202 ifft4 (buf + 12);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
203 ifft_pass (buf, roots16 - 4, 4);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
204 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
205
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
206 static void ifft32 (complex_t * buf)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
207 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
208 ifft16 (buf);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
209 ifft8 (buf + 16);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
210 ifft8 (buf + 24);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
211 ifft_pass (buf, roots32 - 8, 8);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
212 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
213
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
214 static void ifft64_c (complex_t * buf)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
215 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
216 ifft32 (buf);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
217 ifft16 (buf + 32);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
218 ifft16 (buf + 48);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
219 ifft_pass (buf, roots64 - 16, 16);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
220 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
221
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
222 static void ifft128_c (complex_t * buf)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
223 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
224 ifft32 (buf);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
225 ifft16 (buf + 32);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
226 ifft16 (buf + 48);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
227 ifft_pass (buf, roots64 - 16, 16);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
228
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
229 ifft32 (buf + 64);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
230 ifft32 (buf + 96);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
231 ifft_pass (buf, roots128 - 32, 32);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
232 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
233
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
234 void a52_imdct_512 (sample_t * data, sample_t * delay, sample_t bias)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
235 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
236 int i, k;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
237 sample_t t_r, t_i, a_r, a_i, b_r, b_i, w_1, w_2;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
238 const sample_t * window = a52_imdct_window;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
239
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
240 for (i = 0; i < 128; i++) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
241 k = fftorder[i];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
242 t_r = pre1[i].real;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
243 t_i = pre1[i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
244
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
245 buf[i].real = t_i * data[255-k] + t_r * data[k];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
246 buf[i].imag = t_r * data[255-k] - t_i * data[k];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
247 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
248
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
249 ifft128 (buf);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
250
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
251 /* Post IFFT complex multiply plus IFFT complex conjugate*/
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
252 /* Window and convert to real valued signal */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
253 for (i = 0; i < 64; i++) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
254 /* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
255 t_r = post1[i].real;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
256 t_i = post1[i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
257
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
258 a_r = t_r * buf[i].real + t_i * buf[i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
259 a_i = t_i * buf[i].real - t_r * buf[i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
260 b_r = t_i * buf[127-i].real + t_r * buf[127-i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
261 b_i = t_r * buf[127-i].real - t_i * buf[127-i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
262
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
263 w_1 = window[2*i];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
264 w_2 = window[255-2*i];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
265 data[2*i] = delay[2*i] * w_2 - a_r * w_1 + bias;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
266 data[255-2*i] = delay[2*i] * w_1 + a_r * w_2 + bias;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
267 delay[2*i] = a_i;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
268
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
269 w_1 = window[2*i+1];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
270 w_2 = window[254-2*i];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
271 data[2*i+1] = delay[2*i+1] * w_2 + b_r * w_1 + bias;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
272 data[254-2*i] = delay[2*i+1] * w_1 - b_r * w_2 + bias;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
273 delay[2*i+1] = b_i;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
274 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
275 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
276
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
277 void a52_imdct_256(sample_t data[],sample_t delay[],sample_t bias)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
278 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
279 int i, k;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
280 sample_t t_r, t_i, a_r, a_i, b_r, b_i, c_r, c_i, d_r, d_i, w_1, w_2;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
281 complex_t * buf1, * buf2;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
282 const sample_t * window = a52_imdct_window;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
283
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
284 buf1 = &buf[0];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
285 buf2 = &buf[64];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
286
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
287 /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
288 for (i = 0; i < 64; i++) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
289 k = fftorder[i];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
290 t_r = pre2[i].real;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
291 t_i = pre2[i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
292
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
293 buf1[i].real = t_i * data[254-k] + t_r * data[k];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
294 buf1[i].imag = t_r * data[254-k] - t_i * data[k];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
295
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
296 buf2[i].real = t_i * data[255-k] + t_r * data[k+1];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
297 buf2[i].imag = t_r * data[255-k] - t_i * data[k+1];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
298 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
299
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
300 ifft64 (buf1);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
301 ifft64 (buf2);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
302
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
303 /* Post IFFT complex multiply */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
304 /* Window and convert to real valued signal */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
305 for (i = 0; i < 32; i++) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
306 /* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
307 t_r = post2[i].real;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
308 t_i = post2[i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
309
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
310 a_r = t_r * buf1[i].real + t_i * buf1[i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
311 a_i = t_i * buf1[i].real - t_r * buf1[i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
312 b_r = t_i * buf1[63-i].real + t_r * buf1[63-i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
313 b_i = t_r * buf1[63-i].real - t_i * buf1[63-i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
314
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
315 c_r = t_r * buf2[i].real + t_i * buf2[i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
316 c_i = t_i * buf2[i].real - t_r * buf2[i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
317 d_r = t_i * buf2[63-i].real + t_r * buf2[63-i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
318 d_i = t_r * buf2[63-i].real - t_i * buf2[63-i].imag;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
319
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
320 w_1 = window[2*i];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
321 w_2 = window[255-2*i];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
322 data[2*i] = delay[2*i] * w_2 - a_r * w_1 + bias;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
323 data[255-2*i] = delay[2*i] * w_1 + a_r * w_2 + bias;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
324 delay[2*i] = c_i;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
325
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
326 w_1 = window[128+2*i];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
327 w_2 = window[127-2*i];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
328 data[128+2*i] = delay[127-2*i] * w_2 + a_i * w_1 + bias;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
329 data[127-2*i] = delay[127-2*i] * w_1 - a_i * w_2 + bias;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
330 delay[127-2*i] = c_r;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
331
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
332 w_1 = window[2*i+1];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
333 w_2 = window[254-2*i];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
334 data[2*i+1] = delay[2*i+1] * w_2 - b_i * w_1 + bias;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
335 data[254-2*i] = delay[2*i+1] * w_1 + b_i * w_2 + bias;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
336 delay[2*i+1] = d_r;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
337
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
338 w_1 = window[129+2*i];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
339 w_2 = window[126-2*i];
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
340 data[129+2*i] = delay[126-2*i] * w_2 + b_r * w_1 + bias;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
341 data[126-2*i] = delay[126-2*i] * w_1 - b_r * w_2 + bias;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
342 delay[126-2*i] = d_i;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
343 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
344 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
345
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
346 static double besselI0 (double x)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
347 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
348 double bessel = 1;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
349 int i = 100;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
350
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
351 do
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
352 bessel = bessel * x / (i * i) + 1;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
353 while (--i);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
354 return bessel;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
355 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
356
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
357 void a52_imdct_init (uint32_t mm_accel)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
358 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
359 int i, k;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
360 double sum;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
361
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
362 /* compute imdct window - kaiser-bessel derived window, alpha = 5.0 */
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
363 sum = 0;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
364 for (i = 0; i < 256; i++) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
365 sum += besselI0 (i * (256 - i) * (5 * M_PI / 256) * (5 * M_PI / 256));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
366 a52_imdct_window[i] = sum;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
367 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
368 sum++;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
369 for (i = 0; i < 256; i++)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
370 a52_imdct_window[i] = sqrt (a52_imdct_window[i] / sum);
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
371
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
372 for (i = 0; i < 3; i++)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
373 roots16[i] = cos ((M_PI / 8) * (i + 1));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
374
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
375 for (i = 0; i < 7; i++)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
376 roots32[i] = cos ((M_PI / 16) * (i + 1));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
377
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
378 for (i = 0; i < 15; i++)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
379 roots64[i] = cos ((M_PI / 32) * (i + 1));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
380
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
381 for (i = 0; i < 31; i++)
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
382 roots128[i] = cos ((M_PI / 64) * (i + 1));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
383
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
384 for (i = 0; i < 64; i++) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
385 k = fftorder[i] / 2 + 64;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
386 pre1[i].real = cos ((M_PI / 256) * (k - 0.25));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
387 pre1[i].imag = sin ((M_PI / 256) * (k - 0.25));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
388 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
389
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
390 for (i = 64; i < 128; i++) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
391 k = fftorder[i] / 2 + 64;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
392 pre1[i].real = -cos ((M_PI / 256) * (k - 0.25));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
393 pre1[i].imag = -sin ((M_PI / 256) * (k - 0.25));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
394 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
395
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
396 for (i = 0; i < 64; i++) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
397 post1[i].real = cos ((M_PI / 256) * (i + 0.5));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
398 post1[i].imag = sin ((M_PI / 256) * (i + 0.5));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
399 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
400
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
401 for (i = 0; i < 64; i++) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
402 k = fftorder[i] / 4;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
403 pre2[i].real = cos ((M_PI / 128) * (k - 0.25));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
404 pre2[i].imag = sin ((M_PI / 128) * (k - 0.25));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
405 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
406
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
407 for (i = 0; i < 32; i++) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
408 post2[i].real = cos ((M_PI / 128) * (i + 0.5));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
409 post2[i].imag = sin ((M_PI / 128) * (i + 0.5));
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
410 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
411
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
412 #ifdef LIBA52_DJBFFT
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
413 if (mm_accel & MM_ACCEL_DJBFFT) {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
414 fprintf (stderr, "Using djbfft for IMDCT transform\n");
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
415 ifft128 = (void (*) (complex_t *)) fftc4_un128;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
416 ifft64 = (void (*) (complex_t *)) fftc4_un64;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
417 } else
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
418 #endif
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
419 {
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
420 fprintf (stderr, "No accelerated IMDCT transform found\n");
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
421 ifft128 = ifft128_c;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
422 ifft64 = ifft64_c;
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
423 }
207cc56d18f8 * add support for liba52
kabi
parents:
diff changeset
424 }