annotate libac3/imdct.c @ 282:5c7fdbecfa97 libavcodec

more aspect stuff
author michaelni
date Fri, 22 Mar 2002 23:28:11 +0000
parents 5aa6292a1660
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
2 * imdct.c
986e461dc072 Initial revision
glantau
parents:
diff changeset
3 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
4 * Copyright (C) Aaron Holtzman - May 1999
986e461dc072 Initial revision
glantau
parents:
diff changeset
5 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
6 * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
986e461dc072 Initial revision
glantau
parents:
diff changeset
7 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
8 * ac3dec is free software; you can redistribute it and/or modify
986e461dc072 Initial revision
glantau
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
986e461dc072 Initial revision
glantau
parents:
diff changeset
10 * the Free Software Foundation; either version 2, or (at your option)
986e461dc072 Initial revision
glantau
parents:
diff changeset
11 * any later version.
986e461dc072 Initial revision
glantau
parents:
diff changeset
12 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
13 * ac3dec is distributed in the hope that it will be useful,
986e461dc072 Initial revision
glantau
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
986e461dc072 Initial revision
glantau
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
986e461dc072 Initial revision
glantau
parents:
diff changeset
16 * GNU General Public License for more details.
986e461dc072 Initial revision
glantau
parents:
diff changeset
17 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
986e461dc072 Initial revision
glantau
parents:
diff changeset
19 * along with GNU Make; see the file COPYING. If not, write to
986e461dc072 Initial revision
glantau
parents:
diff changeset
20 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
986e461dc072 Initial revision
glantau
parents:
diff changeset
21 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
22 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
23 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
24
64
5aa6292a1660 win32 fixes
glantau
parents: 0
diff changeset
25 #include "../common.h"
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
26 #include <math.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
27 #include "ac3.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
28 #include "ac3_internal.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
29
986e461dc072 Initial revision
glantau
parents:
diff changeset
30 void (* imdct_256) (float data[], float delay[]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
31 void (* imdct_512) (float data[], float delay[]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
32
986e461dc072 Initial revision
glantau
parents:
diff changeset
33 typedef struct complex_s
986e461dc072 Initial revision
glantau
parents:
diff changeset
34 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
35 float real;
986e461dc072 Initial revision
glantau
parents:
diff changeset
36 float imag;
986e461dc072 Initial revision
glantau
parents:
diff changeset
37 } complex_t;
986e461dc072 Initial revision
glantau
parents:
diff changeset
38
986e461dc072 Initial revision
glantau
parents:
diff changeset
39
986e461dc072 Initial revision
glantau
parents:
diff changeset
40 /* 128 point bit-reverse LUT */
986e461dc072 Initial revision
glantau
parents:
diff changeset
41 static uint8_t bit_reverse_512[] = {
986e461dc072 Initial revision
glantau
parents:
diff changeset
42 0x00, 0x40, 0x20, 0x60, 0x10, 0x50, 0x30, 0x70,
986e461dc072 Initial revision
glantau
parents:
diff changeset
43 0x08, 0x48, 0x28, 0x68, 0x18, 0x58, 0x38, 0x78,
986e461dc072 Initial revision
glantau
parents:
diff changeset
44 0x04, 0x44, 0x24, 0x64, 0x14, 0x54, 0x34, 0x74,
986e461dc072 Initial revision
glantau
parents:
diff changeset
45 0x0c, 0x4c, 0x2c, 0x6c, 0x1c, 0x5c, 0x3c, 0x7c,
986e461dc072 Initial revision
glantau
parents:
diff changeset
46 0x02, 0x42, 0x22, 0x62, 0x12, 0x52, 0x32, 0x72,
986e461dc072 Initial revision
glantau
parents:
diff changeset
47 0x0a, 0x4a, 0x2a, 0x6a, 0x1a, 0x5a, 0x3a, 0x7a,
986e461dc072 Initial revision
glantau
parents:
diff changeset
48 0x06, 0x46, 0x26, 0x66, 0x16, 0x56, 0x36, 0x76,
986e461dc072 Initial revision
glantau
parents:
diff changeset
49 0x0e, 0x4e, 0x2e, 0x6e, 0x1e, 0x5e, 0x3e, 0x7e,
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 0x01, 0x41, 0x21, 0x61, 0x11, 0x51, 0x31, 0x71,
986e461dc072 Initial revision
glantau
parents:
diff changeset
51 0x09, 0x49, 0x29, 0x69, 0x19, 0x59, 0x39, 0x79,
986e461dc072 Initial revision
glantau
parents:
diff changeset
52 0x05, 0x45, 0x25, 0x65, 0x15, 0x55, 0x35, 0x75,
986e461dc072 Initial revision
glantau
parents:
diff changeset
53 0x0d, 0x4d, 0x2d, 0x6d, 0x1d, 0x5d, 0x3d, 0x7d,
986e461dc072 Initial revision
glantau
parents:
diff changeset
54 0x03, 0x43, 0x23, 0x63, 0x13, 0x53, 0x33, 0x73,
986e461dc072 Initial revision
glantau
parents:
diff changeset
55 0x0b, 0x4b, 0x2b, 0x6b, 0x1b, 0x5b, 0x3b, 0x7b,
986e461dc072 Initial revision
glantau
parents:
diff changeset
56 0x07, 0x47, 0x27, 0x67, 0x17, 0x57, 0x37, 0x77,
986e461dc072 Initial revision
glantau
parents:
diff changeset
57 0x0f, 0x4f, 0x2f, 0x6f, 0x1f, 0x5f, 0x3f, 0x7f};
986e461dc072 Initial revision
glantau
parents:
diff changeset
58
986e461dc072 Initial revision
glantau
parents:
diff changeset
59 static uint8_t bit_reverse_256[] = {
986e461dc072 Initial revision
glantau
parents:
diff changeset
60 0x00, 0x20, 0x10, 0x30, 0x08, 0x28, 0x18, 0x38,
986e461dc072 Initial revision
glantau
parents:
diff changeset
61 0x04, 0x24, 0x14, 0x34, 0x0c, 0x2c, 0x1c, 0x3c,
986e461dc072 Initial revision
glantau
parents:
diff changeset
62 0x02, 0x22, 0x12, 0x32, 0x0a, 0x2a, 0x1a, 0x3a,
986e461dc072 Initial revision
glantau
parents:
diff changeset
63 0x06, 0x26, 0x16, 0x36, 0x0e, 0x2e, 0x1e, 0x3e,
986e461dc072 Initial revision
glantau
parents:
diff changeset
64 0x01, 0x21, 0x11, 0x31, 0x09, 0x29, 0x19, 0x39,
986e461dc072 Initial revision
glantau
parents:
diff changeset
65 0x05, 0x25, 0x15, 0x35, 0x0d, 0x2d, 0x1d, 0x3d,
986e461dc072 Initial revision
glantau
parents:
diff changeset
66 0x03, 0x23, 0x13, 0x33, 0x0b, 0x2b, 0x1b, 0x3b,
986e461dc072 Initial revision
glantau
parents:
diff changeset
67 0x07, 0x27, 0x17, 0x37, 0x0f, 0x2f, 0x1f, 0x3f};
986e461dc072 Initial revision
glantau
parents:
diff changeset
68
986e461dc072 Initial revision
glantau
parents:
diff changeset
69 static complex_t buf[128];
986e461dc072 Initial revision
glantau
parents:
diff changeset
70
986e461dc072 Initial revision
glantau
parents:
diff changeset
71 /* Twiddle factor LUT */
986e461dc072 Initial revision
glantau
parents:
diff changeset
72 static complex_t w_1[1];
986e461dc072 Initial revision
glantau
parents:
diff changeset
73 static complex_t w_2[2];
986e461dc072 Initial revision
glantau
parents:
diff changeset
74 static complex_t w_4[4];
986e461dc072 Initial revision
glantau
parents:
diff changeset
75 static complex_t w_8[8];
986e461dc072 Initial revision
glantau
parents:
diff changeset
76 static complex_t w_16[16];
986e461dc072 Initial revision
glantau
parents:
diff changeset
77 static complex_t w_32[32];
986e461dc072 Initial revision
glantau
parents:
diff changeset
78 static complex_t w_64[64];
986e461dc072 Initial revision
glantau
parents:
diff changeset
79 static complex_t * w[7] = {w_1, w_2, w_4, w_8, w_16, w_32, w_64};
986e461dc072 Initial revision
glantau
parents:
diff changeset
80
986e461dc072 Initial revision
glantau
parents:
diff changeset
81 /* Twiddle factors for IMDCT */
986e461dc072 Initial revision
glantau
parents:
diff changeset
82 static float xcos1[128];
986e461dc072 Initial revision
glantau
parents:
diff changeset
83 static float xsin1[128];
986e461dc072 Initial revision
glantau
parents:
diff changeset
84 static float xcos2[64];
986e461dc072 Initial revision
glantau
parents:
diff changeset
85 static float xsin2[64];
986e461dc072 Initial revision
glantau
parents:
diff changeset
86
986e461dc072 Initial revision
glantau
parents:
diff changeset
87 /* Windowing function for Modified DCT - Thank you acroread */
986e461dc072 Initial revision
glantau
parents:
diff changeset
88 float imdct_window[] = {
986e461dc072 Initial revision
glantau
parents:
diff changeset
89 0.00014, 0.00024, 0.00037, 0.00051, 0.00067, 0.00086, 0.00107, 0.00130,
986e461dc072 Initial revision
glantau
parents:
diff changeset
90 0.00157, 0.00187, 0.00220, 0.00256, 0.00297, 0.00341, 0.00390, 0.00443,
986e461dc072 Initial revision
glantau
parents:
diff changeset
91 0.00501, 0.00564, 0.00632, 0.00706, 0.00785, 0.00871, 0.00962, 0.01061,
986e461dc072 Initial revision
glantau
parents:
diff changeset
92 0.01166, 0.01279, 0.01399, 0.01526, 0.01662, 0.01806, 0.01959, 0.02121,
986e461dc072 Initial revision
glantau
parents:
diff changeset
93 0.02292, 0.02472, 0.02662, 0.02863, 0.03073, 0.03294, 0.03527, 0.03770,
986e461dc072 Initial revision
glantau
parents:
diff changeset
94 0.04025, 0.04292, 0.04571, 0.04862, 0.05165, 0.05481, 0.05810, 0.06153,
986e461dc072 Initial revision
glantau
parents:
diff changeset
95 0.06508, 0.06878, 0.07261, 0.07658, 0.08069, 0.08495, 0.08935, 0.09389,
986e461dc072 Initial revision
glantau
parents:
diff changeset
96 0.09859, 0.10343, 0.10842, 0.11356, 0.11885, 0.12429, 0.12988, 0.13563,
986e461dc072 Initial revision
glantau
parents:
diff changeset
97 0.14152, 0.14757, 0.15376, 0.16011, 0.16661, 0.17325, 0.18005, 0.18699,
986e461dc072 Initial revision
glantau
parents:
diff changeset
98 0.19407, 0.20130, 0.20867, 0.21618, 0.22382, 0.23161, 0.23952, 0.24757,
986e461dc072 Initial revision
glantau
parents:
diff changeset
99 0.25574, 0.26404, 0.27246, 0.28100, 0.28965, 0.29841, 0.30729, 0.31626,
986e461dc072 Initial revision
glantau
parents:
diff changeset
100 0.32533, 0.33450, 0.34376, 0.35311, 0.36253, 0.37204, 0.38161, 0.39126,
986e461dc072 Initial revision
glantau
parents:
diff changeset
101 0.40096, 0.41072, 0.42054, 0.43040, 0.44030, 0.45023, 0.46020, 0.47019,
986e461dc072 Initial revision
glantau
parents:
diff changeset
102 0.48020, 0.49022, 0.50025, 0.51028, 0.52031, 0.53033, 0.54033, 0.55031,
986e461dc072 Initial revision
glantau
parents:
diff changeset
103 0.56026, 0.57019, 0.58007, 0.58991, 0.59970, 0.60944, 0.61912, 0.62873,
986e461dc072 Initial revision
glantau
parents:
diff changeset
104 0.63827, 0.64774, 0.65713, 0.66643, 0.67564, 0.68476, 0.69377, 0.70269,
986e461dc072 Initial revision
glantau
parents:
diff changeset
105 0.71150, 0.72019, 0.72877, 0.73723, 0.74557, 0.75378, 0.76186, 0.76981,
986e461dc072 Initial revision
glantau
parents:
diff changeset
106 0.77762, 0.78530, 0.79283, 0.80022, 0.80747, 0.81457, 0.82151, 0.82831,
986e461dc072 Initial revision
glantau
parents:
diff changeset
107 0.83496, 0.84145, 0.84779, 0.85398, 0.86001, 0.86588, 0.87160, 0.87716,
986e461dc072 Initial revision
glantau
parents:
diff changeset
108 0.88257, 0.88782, 0.89291, 0.89785, 0.90264, 0.90728, 0.91176, 0.91610,
986e461dc072 Initial revision
glantau
parents:
diff changeset
109 0.92028, 0.92432, 0.92822, 0.93197, 0.93558, 0.93906, 0.94240, 0.94560,
986e461dc072 Initial revision
glantau
parents:
diff changeset
110 0.94867, 0.95162, 0.95444, 0.95713, 0.95971, 0.96217, 0.96451, 0.96674,
986e461dc072 Initial revision
glantau
parents:
diff changeset
111 0.96887, 0.97089, 0.97281, 0.97463, 0.97635, 0.97799, 0.97953, 0.98099,
986e461dc072 Initial revision
glantau
parents:
diff changeset
112 0.98236, 0.98366, 0.98488, 0.98602, 0.98710, 0.98811, 0.98905, 0.98994,
986e461dc072 Initial revision
glantau
parents:
diff changeset
113 0.99076, 0.99153, 0.99225, 0.99291, 0.99353, 0.99411, 0.99464, 0.99513,
986e461dc072 Initial revision
glantau
parents:
diff changeset
114 0.99558, 0.99600, 0.99639, 0.99674, 0.99706, 0.99736, 0.99763, 0.99788,
986e461dc072 Initial revision
glantau
parents:
diff changeset
115 0.99811, 0.99831, 0.99850, 0.99867, 0.99882, 0.99895, 0.99908, 0.99919,
986e461dc072 Initial revision
glantau
parents:
diff changeset
116 0.99929, 0.99938, 0.99946, 0.99953, 0.99959, 0.99965, 0.99969, 0.99974,
986e461dc072 Initial revision
glantau
parents:
diff changeset
117 0.99978, 0.99981, 0.99984, 0.99986, 0.99988, 0.99990, 0.99992, 0.99993,
986e461dc072 Initial revision
glantau
parents:
diff changeset
118 0.99994, 0.99995, 0.99996, 0.99997, 0.99998, 0.99998, 0.99998, 0.99999,
986e461dc072 Initial revision
glantau
parents:
diff changeset
119 0.99999, 0.99999, 0.99999, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000,
986e461dc072 Initial revision
glantau
parents:
diff changeset
120 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000 };
986e461dc072 Initial revision
glantau
parents:
diff changeset
121
986e461dc072 Initial revision
glantau
parents:
diff changeset
122
986e461dc072 Initial revision
glantau
parents:
diff changeset
123 static inline void swap_cmplx(complex_t *a, complex_t *b)
986e461dc072 Initial revision
glantau
parents:
diff changeset
124 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
125 complex_t tmp;
986e461dc072 Initial revision
glantau
parents:
diff changeset
126
986e461dc072 Initial revision
glantau
parents:
diff changeset
127 tmp = *a;
986e461dc072 Initial revision
glantau
parents:
diff changeset
128 *a = *b;
986e461dc072 Initial revision
glantau
parents:
diff changeset
129 *b = tmp;
986e461dc072 Initial revision
glantau
parents:
diff changeset
130 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
131
986e461dc072 Initial revision
glantau
parents:
diff changeset
132
986e461dc072 Initial revision
glantau
parents:
diff changeset
133
986e461dc072 Initial revision
glantau
parents:
diff changeset
134 static inline complex_t cmplx_mult(complex_t a, complex_t b)
986e461dc072 Initial revision
glantau
parents:
diff changeset
135 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
136 complex_t ret;
986e461dc072 Initial revision
glantau
parents:
diff changeset
137
986e461dc072 Initial revision
glantau
parents:
diff changeset
138 ret.real = a.real * b.real - a.imag * b.imag;
986e461dc072 Initial revision
glantau
parents:
diff changeset
139 ret.imag = a.real * b.imag + a.imag * b.real;
986e461dc072 Initial revision
glantau
parents:
diff changeset
140
986e461dc072 Initial revision
glantau
parents:
diff changeset
141 return ret;
986e461dc072 Initial revision
glantau
parents:
diff changeset
142 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
143
986e461dc072 Initial revision
glantau
parents:
diff changeset
144 void
986e461dc072 Initial revision
glantau
parents:
diff changeset
145 imdct_do_512(float data[],float delay[])
986e461dc072 Initial revision
glantau
parents:
diff changeset
146 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
147 int i,k;
986e461dc072 Initial revision
glantau
parents:
diff changeset
148 int p,q;
986e461dc072 Initial revision
glantau
parents:
diff changeset
149 int m;
986e461dc072 Initial revision
glantau
parents:
diff changeset
150 int two_m;
986e461dc072 Initial revision
glantau
parents:
diff changeset
151 int two_m_plus_one;
986e461dc072 Initial revision
glantau
parents:
diff changeset
152
986e461dc072 Initial revision
glantau
parents:
diff changeset
153 float tmp_a_i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
154 float tmp_a_r;
986e461dc072 Initial revision
glantau
parents:
diff changeset
155 float tmp_b_i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
156 float tmp_b_r;
986e461dc072 Initial revision
glantau
parents:
diff changeset
157
986e461dc072 Initial revision
glantau
parents:
diff changeset
158 float *data_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
159 float *delay_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
160 float *window_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
161
986e461dc072 Initial revision
glantau
parents:
diff changeset
162 //
986e461dc072 Initial revision
glantau
parents:
diff changeset
163 // 512 IMDCT with source and dest data in 'data'
986e461dc072 Initial revision
glantau
parents:
diff changeset
164 //
986e461dc072 Initial revision
glantau
parents:
diff changeset
165
986e461dc072 Initial revision
glantau
parents:
diff changeset
166 // Pre IFFT complex multiply plus IFFT cmplx conjugate
986e461dc072 Initial revision
glantau
parents:
diff changeset
167 for( i=0; i < 128; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
168 /* z[i] = (X[256-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) ; */
986e461dc072 Initial revision
glantau
parents:
diff changeset
169 buf[i].real = (data[256-2*i-1] * xcos1[i]) - (data[2*i] * xsin1[i]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
170 buf[i].imag = -1.0 * ((data[2*i] * xcos1[i]) + (data[256-2*i-1] * xsin1[i]));
986e461dc072 Initial revision
glantau
parents:
diff changeset
171 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
172
986e461dc072 Initial revision
glantau
parents:
diff changeset
173 //Bit reversed shuffling
986e461dc072 Initial revision
glantau
parents:
diff changeset
174 for(i=0; i<128; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
175 k = bit_reverse_512[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
176 if (k < i)
986e461dc072 Initial revision
glantau
parents:
diff changeset
177 swap_cmplx(&buf[i],&buf[k]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
178 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
179
986e461dc072 Initial revision
glantau
parents:
diff changeset
180 /* FFT Merge */
986e461dc072 Initial revision
glantau
parents:
diff changeset
181 for (m=0; m < 7; m++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
182 if(m)
986e461dc072 Initial revision
glantau
parents:
diff changeset
183 two_m = (1 << m);
986e461dc072 Initial revision
glantau
parents:
diff changeset
184 else
986e461dc072 Initial revision
glantau
parents:
diff changeset
185 two_m = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
186
986e461dc072 Initial revision
glantau
parents:
diff changeset
187 two_m_plus_one = (1 << (m+1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
188
986e461dc072 Initial revision
glantau
parents:
diff changeset
189 for(k = 0; k < two_m; k++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
190 for(i = 0; i < 128; i += two_m_plus_one) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
191 p = k + i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
192 q = p + two_m;
986e461dc072 Initial revision
glantau
parents:
diff changeset
193 tmp_a_r = buf[p].real;
986e461dc072 Initial revision
glantau
parents:
diff changeset
194 tmp_a_i = buf[p].imag;
986e461dc072 Initial revision
glantau
parents:
diff changeset
195 tmp_b_r = buf[q].real * w[m][k].real - buf[q].imag * w[m][k].imag;
986e461dc072 Initial revision
glantau
parents:
diff changeset
196 tmp_b_i = buf[q].imag * w[m][k].real + buf[q].real * w[m][k].imag;
986e461dc072 Initial revision
glantau
parents:
diff changeset
197 buf[p].real = tmp_a_r + tmp_b_r;
986e461dc072 Initial revision
glantau
parents:
diff changeset
198 buf[p].imag = tmp_a_i + tmp_b_i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
199 buf[q].real = tmp_a_r - tmp_b_r;
986e461dc072 Initial revision
glantau
parents:
diff changeset
200 buf[q].imag = tmp_a_i - tmp_b_i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
201 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
202 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
203 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
204
986e461dc072 Initial revision
glantau
parents:
diff changeset
205 /* Post IFFT complex multiply plus IFFT complex conjugate*/
986e461dc072 Initial revision
glantau
parents:
diff changeset
206 for( i=0; i < 128; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
207 /* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
986e461dc072 Initial revision
glantau
parents:
diff changeset
208 tmp_a_r = buf[i].real;
986e461dc072 Initial revision
glantau
parents:
diff changeset
209 tmp_a_i = -1.0 * buf[i].imag;
986e461dc072 Initial revision
glantau
parents:
diff changeset
210 buf[i].real =(tmp_a_r * xcos1[i]) - (tmp_a_i * xsin1[i]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
211 buf[i].imag =(tmp_a_r * xsin1[i]) + (tmp_a_i * xcos1[i]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
212 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
213
986e461dc072 Initial revision
glantau
parents:
diff changeset
214 data_ptr = data;
986e461dc072 Initial revision
glantau
parents:
diff changeset
215 delay_ptr = delay;
986e461dc072 Initial revision
glantau
parents:
diff changeset
216 window_ptr = imdct_window;
986e461dc072 Initial revision
glantau
parents:
diff changeset
217
986e461dc072 Initial revision
glantau
parents:
diff changeset
218 /* Window and convert to real valued signal */
986e461dc072 Initial revision
glantau
parents:
diff changeset
219 for(i=0; i< 64; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
220 *data_ptr++ = 2.0f * (-buf[64+i].imag * *window_ptr++ + *delay_ptr++);
986e461dc072 Initial revision
glantau
parents:
diff changeset
221 *data_ptr++ = 2.0f * ( buf[64-i-1].real * *window_ptr++ + *delay_ptr++);
986e461dc072 Initial revision
glantau
parents:
diff changeset
222 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
223
986e461dc072 Initial revision
glantau
parents:
diff changeset
224 for(i=0; i< 64; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
225 *data_ptr++ = 2.0f * (-buf[i].real * *window_ptr++ + *delay_ptr++);
986e461dc072 Initial revision
glantau
parents:
diff changeset
226 *data_ptr++ = 2.0f * ( buf[128-i-1].imag * *window_ptr++ + *delay_ptr++);
986e461dc072 Initial revision
glantau
parents:
diff changeset
227 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
228
986e461dc072 Initial revision
glantau
parents:
diff changeset
229 /* The trailing edge of the window goes into the delay line */
986e461dc072 Initial revision
glantau
parents:
diff changeset
230 delay_ptr = delay;
986e461dc072 Initial revision
glantau
parents:
diff changeset
231
986e461dc072 Initial revision
glantau
parents:
diff changeset
232 for(i=0; i< 64; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
233 *delay_ptr++ = -buf[64+i].real * *--window_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
234 *delay_ptr++ = buf[64-i-1].imag * *--window_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
235 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
236
986e461dc072 Initial revision
glantau
parents:
diff changeset
237 for(i=0; i<64; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
238 *delay_ptr++ = buf[i].imag * *--window_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
239 *delay_ptr++ = -buf[128-i-1].real * *--window_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
240 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
241 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
242
986e461dc072 Initial revision
glantau
parents:
diff changeset
243 void
986e461dc072 Initial revision
glantau
parents:
diff changeset
244 imdct_do_256(float data[],float delay[])
986e461dc072 Initial revision
glantau
parents:
diff changeset
245 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
246 int i,k;
986e461dc072 Initial revision
glantau
parents:
diff changeset
247 int p,q;
986e461dc072 Initial revision
glantau
parents:
diff changeset
248 int m;
986e461dc072 Initial revision
glantau
parents:
diff changeset
249 int two_m;
986e461dc072 Initial revision
glantau
parents:
diff changeset
250 int two_m_plus_one;
986e461dc072 Initial revision
glantau
parents:
diff changeset
251
986e461dc072 Initial revision
glantau
parents:
diff changeset
252 float tmp_a_i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
253 float tmp_a_r;
986e461dc072 Initial revision
glantau
parents:
diff changeset
254 float tmp_b_i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
255 float tmp_b_r;
986e461dc072 Initial revision
glantau
parents:
diff changeset
256
986e461dc072 Initial revision
glantau
parents:
diff changeset
257 float *data_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
258 float *delay_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
259 float *window_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
260
986e461dc072 Initial revision
glantau
parents:
diff changeset
261 complex_t *buf_1, *buf_2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
262
986e461dc072 Initial revision
glantau
parents:
diff changeset
263 buf_1 = &buf[0];
986e461dc072 Initial revision
glantau
parents:
diff changeset
264 buf_2 = &buf[64];
986e461dc072 Initial revision
glantau
parents:
diff changeset
265
986e461dc072 Initial revision
glantau
parents:
diff changeset
266 /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
986e461dc072 Initial revision
glantau
parents:
diff changeset
267 for(k=0; k<64; k++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
268 /* X1[k] = X[2*k] */
986e461dc072 Initial revision
glantau
parents:
diff changeset
269 /* X2[k] = X[2*k+1] */
986e461dc072 Initial revision
glantau
parents:
diff changeset
270
986e461dc072 Initial revision
glantau
parents:
diff changeset
271 p = 2 * (128-2*k-1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
272 q = 2 * (2 * k);
986e461dc072 Initial revision
glantau
parents:
diff changeset
273
986e461dc072 Initial revision
glantau
parents:
diff changeset
274 /* Z1[k] = (X1[128-2*k-1] + j * X1[2*k]) * (xcos2[k] + j * xsin2[k]); */
986e461dc072 Initial revision
glantau
parents:
diff changeset
275 buf_1[k].real = data[p] * xcos2[k] - data[q] * xsin2[k];
986e461dc072 Initial revision
glantau
parents:
diff changeset
276 buf_1[k].imag = -1.0f * (data[q] * xcos2[k] + data[p] * xsin2[k]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
277 /* Z2[k] = (X2[128-2*k-1] + j * X2[2*k]) * (xcos2[k] + j * xsin2[k]); */
986e461dc072 Initial revision
glantau
parents:
diff changeset
278 buf_2[k].real = data[p + 1] * xcos2[k] - data[q + 1] * xsin2[k];
986e461dc072 Initial revision
glantau
parents:
diff changeset
279 buf_2[k].imag = -1.0f * ( data[q + 1] * xcos2[k] + data[p + 1] * xsin2[k]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
280 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
281
986e461dc072 Initial revision
glantau
parents:
diff changeset
282 //IFFT Bit reversed shuffling
986e461dc072 Initial revision
glantau
parents:
diff changeset
283 for(i=0; i<64; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
284 k = bit_reverse_256[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
285 if (k < i) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
286 swap_cmplx(&buf_1[i],&buf_1[k]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
287 swap_cmplx(&buf_2[i],&buf_2[k]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
288 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
289 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
290
986e461dc072 Initial revision
glantau
parents:
diff changeset
291 /* FFT Merge */
986e461dc072 Initial revision
glantau
parents:
diff changeset
292 for (m=0; m < 6; m++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
293 two_m = (1 << m);
986e461dc072 Initial revision
glantau
parents:
diff changeset
294 two_m_plus_one = (1 << (m+1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
295
986e461dc072 Initial revision
glantau
parents:
diff changeset
296 //FIXME
986e461dc072 Initial revision
glantau
parents:
diff changeset
297 if(m)
986e461dc072 Initial revision
glantau
parents:
diff changeset
298 two_m = (1 << m);
986e461dc072 Initial revision
glantau
parents:
diff changeset
299 else
986e461dc072 Initial revision
glantau
parents:
diff changeset
300 two_m = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
301
986e461dc072 Initial revision
glantau
parents:
diff changeset
302 for(k = 0; k < two_m; k++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
303 for(i = 0; i < 64; i += two_m_plus_one) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
304 p = k + i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
305 q = p + two_m;
986e461dc072 Initial revision
glantau
parents:
diff changeset
306 //Do block 1
986e461dc072 Initial revision
glantau
parents:
diff changeset
307 tmp_a_r = buf_1[p].real;
986e461dc072 Initial revision
glantau
parents:
diff changeset
308 tmp_a_i = buf_1[p].imag;
986e461dc072 Initial revision
glantau
parents:
diff changeset
309 tmp_b_r = buf_1[q].real * w[m][k].real - buf_1[q].imag * w[m][k].imag;
986e461dc072 Initial revision
glantau
parents:
diff changeset
310 tmp_b_i = buf_1[q].imag * w[m][k].real + buf_1[q].real * w[m][k].imag;
986e461dc072 Initial revision
glantau
parents:
diff changeset
311 buf_1[p].real = tmp_a_r + tmp_b_r;
986e461dc072 Initial revision
glantau
parents:
diff changeset
312 buf_1[p].imag = tmp_a_i + tmp_b_i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
313 buf_1[q].real = tmp_a_r - tmp_b_r;
986e461dc072 Initial revision
glantau
parents:
diff changeset
314 buf_1[q].imag = tmp_a_i - tmp_b_i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
315
986e461dc072 Initial revision
glantau
parents:
diff changeset
316 //Do block 2
986e461dc072 Initial revision
glantau
parents:
diff changeset
317 tmp_a_r = buf_2[p].real;
986e461dc072 Initial revision
glantau
parents:
diff changeset
318 tmp_a_i = buf_2[p].imag;
986e461dc072 Initial revision
glantau
parents:
diff changeset
319 tmp_b_r = buf_2[q].real * w[m][k].real - buf_2[q].imag * w[m][k].imag;
986e461dc072 Initial revision
glantau
parents:
diff changeset
320 tmp_b_i = buf_2[q].imag * w[m][k].real + buf_2[q].real * w[m][k].imag;
986e461dc072 Initial revision
glantau
parents:
diff changeset
321 buf_2[p].real = tmp_a_r + tmp_b_r;
986e461dc072 Initial revision
glantau
parents:
diff changeset
322 buf_2[p].imag = tmp_a_i + tmp_b_i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
323 buf_2[q].real = tmp_a_r - tmp_b_r;
986e461dc072 Initial revision
glantau
parents:
diff changeset
324 buf_2[q].imag = tmp_a_i - tmp_b_i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
325 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
326 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
327 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
328
986e461dc072 Initial revision
glantau
parents:
diff changeset
329 /* Post IFFT complex multiply */
986e461dc072 Initial revision
glantau
parents:
diff changeset
330 for( i=0; i < 64; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
331 /* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */
986e461dc072 Initial revision
glantau
parents:
diff changeset
332 tmp_a_r = buf_1[i].real;
986e461dc072 Initial revision
glantau
parents:
diff changeset
333 tmp_a_i = -buf_1[i].imag;
986e461dc072 Initial revision
glantau
parents:
diff changeset
334 buf_1[i].real =(tmp_a_r * xcos2[i]) - (tmp_a_i * xsin2[i]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
335 buf_1[i].imag =(tmp_a_r * xsin2[i]) + (tmp_a_i * xcos2[i]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
336 /* y2[n] = z2[n] * (xcos2[n] + j * xsin2[n]) ; */
986e461dc072 Initial revision
glantau
parents:
diff changeset
337 tmp_a_r = buf_2[i].real;
986e461dc072 Initial revision
glantau
parents:
diff changeset
338 tmp_a_i = -buf_2[i].imag;
986e461dc072 Initial revision
glantau
parents:
diff changeset
339 buf_2[i].real =(tmp_a_r * xcos2[i]) - (tmp_a_i * xsin2[i]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
340 buf_2[i].imag =(tmp_a_r * xsin2[i]) + (tmp_a_i * xcos2[i]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
341 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
342
986e461dc072 Initial revision
glantau
parents:
diff changeset
343 data_ptr = data;
986e461dc072 Initial revision
glantau
parents:
diff changeset
344 delay_ptr = delay;
986e461dc072 Initial revision
glantau
parents:
diff changeset
345 window_ptr = imdct_window;
986e461dc072 Initial revision
glantau
parents:
diff changeset
346
986e461dc072 Initial revision
glantau
parents:
diff changeset
347 /* Window and convert to real valued signal */
986e461dc072 Initial revision
glantau
parents:
diff changeset
348 for(i=0; i< 64; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
349 *data_ptr++ = 2.0f * (-buf_1[i].imag * *window_ptr++ + *delay_ptr++);
986e461dc072 Initial revision
glantau
parents:
diff changeset
350 *data_ptr++ = 2.0f * ( buf_1[64-i-1].real * *window_ptr++ + *delay_ptr++);
986e461dc072 Initial revision
glantau
parents:
diff changeset
351 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
352
986e461dc072 Initial revision
glantau
parents:
diff changeset
353 for(i=0; i< 64; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
354 *data_ptr++ = 2.0f * (-buf_1[i].real * *window_ptr++ + *delay_ptr++);
986e461dc072 Initial revision
glantau
parents:
diff changeset
355 *data_ptr++ = 2.0f * ( buf_1[64-i-1].imag * *window_ptr++ + *delay_ptr++);
986e461dc072 Initial revision
glantau
parents:
diff changeset
356 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
357
986e461dc072 Initial revision
glantau
parents:
diff changeset
358 delay_ptr = delay;
986e461dc072 Initial revision
glantau
parents:
diff changeset
359
986e461dc072 Initial revision
glantau
parents:
diff changeset
360 for(i=0; i< 64; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
361 *delay_ptr++ = -buf_2[i].real * *--window_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
362 *delay_ptr++ = buf_2[64-i-1].imag * *--window_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
363 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
364
986e461dc072 Initial revision
glantau
parents:
diff changeset
365 for(i=0; i< 64; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
366 *delay_ptr++ = buf_2[i].imag * *--window_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
367 *delay_ptr++ = -buf_2[64-i-1].real * *--window_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
368 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
369 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
370
986e461dc072 Initial revision
glantau
parents:
diff changeset
371 void imdct_init (void)
986e461dc072 Initial revision
glantau
parents:
diff changeset
372 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
373 #ifdef LIBAC3_MLIB
986e461dc072 Initial revision
glantau
parents:
diff changeset
374 void imdct_do_256_mlib(float data[],float delay[]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
375 void imdct_do_512_mlib(float data[],float delay[]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
376
986e461dc072 Initial revision
glantau
parents:
diff changeset
377 imdct_512 = imdct_do_512_mlib;
986e461dc072 Initial revision
glantau
parents:
diff changeset
378 imdct_256 = imdct_do_256_mlib;
986e461dc072 Initial revision
glantau
parents:
diff changeset
379 #else
986e461dc072 Initial revision
glantau
parents:
diff changeset
380 int i, j, k;
986e461dc072 Initial revision
glantau
parents:
diff changeset
381
986e461dc072 Initial revision
glantau
parents:
diff changeset
382 /* Twiddle factors to turn IFFT into IMDCT */
986e461dc072 Initial revision
glantau
parents:
diff changeset
383 for (i = 0; i < 128; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
384 xcos1[i] = -cos ((M_PI / 2048) * (8 * i + 1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
385 xsin1[i] = -sin ((M_PI / 2048) * (8 * i + 1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
386 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
387
986e461dc072 Initial revision
glantau
parents:
diff changeset
388 /* More twiddle factors to turn IFFT into IMDCT */
986e461dc072 Initial revision
glantau
parents:
diff changeset
389 for (i = 0; i < 64; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
390 xcos2[i] = -cos ((M_PI / 1024) * (8 * i + 1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
391 xsin2[i] = -sin ((M_PI / 1024) * (8 * i + 1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
392 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
393
986e461dc072 Initial revision
glantau
parents:
diff changeset
394 for (i = 0; i < 7; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
395 j = 1 << i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
396 for (k = 0; k < j; k++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
397 w[i][k].real = cos (-M_PI * k / j);
986e461dc072 Initial revision
glantau
parents:
diff changeset
398 w[i][k].imag = sin (-M_PI * k / j);
986e461dc072 Initial revision
glantau
parents:
diff changeset
399 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
400 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
401 imdct_512 = imdct_do_512;
986e461dc072 Initial revision
glantau
parents:
diff changeset
402 imdct_256 = imdct_do_256;
986e461dc072 Initial revision
glantau
parents:
diff changeset
403 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
404 }