1 /*____________________________________________________________________________
3 FreeAmp - The Free MP3 Player
5 MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
6 Corp. http://www.xingtech.com
8 Portions Copyright (C) 1998-1999 EMusic.com
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 ____________________________________________________________________________*/
27 /**** mdct.c ***************************************************
31 cos transform for n=18, n=6
33 computes c[k] = Sum( cos((pi/4*n)*(2*k+1)*(2*p+1))*f[p] )
34 k = 0, ...n-1, p = 0...n-1
39 ******************************************************************/
47 extern void imdct18_asm(float f[18]);
48 extern void imdct6_3_asm(float f[]);
51 /*------ 18 point xform -------*/
68 static IMDCT_INIT_BLOCK imdct_info_18 =
69 {mdct18w, mdct18w2, coef};
70 static IMDCT_INIT_BLOCK imdct_info_6 =
71 {mdct6_3v, mdct6_3v2, &coef87};
73 /*====================================================================*/
74 IMDCT_INIT_BLOCK *imdct_init_addr_18(void)
76 return &imdct_info_18;
78 IMDCT_INIT_BLOCK *imdct_init_addr_6(void)
82 /*--------------------------------------------------------------------*/
83 void imdct18(float f[18]) /* 18 point */
90 float ap, bp, a8p, b8p;
94 for (p = 0; p < 4; p++)
96 g1 = mdct18w[p] * f[p];
97 g2 = mdct18w[17 - p] * f[17 - p];
100 bp = mdct18w2[p] * (g1 - g2); // b[p]
102 g1 = mdct18w[8 - p] * f[8 - p];
103 g2 = mdct18w[9 + p] * f[9 + p];
104 a8p = g1 + g2; // a[8-p]
106 b8p = mdct18w2[8 - p] * (g1 - g2); // b[8-p]
113 g1 = mdct18w[p] * f[p];
114 g2 = mdct18w[17 - p] * f[17 - p];
116 b[p] = mdct18w2[p] * (g1 - g2);
119 f[0] = 0.5f * (a[0] + a[1] + a[2] + a[3] + a[4]);
120 f[1] = 0.5f * (b[0] + b[1] + b[2] + b[3] + b[4]);
122 f[2] = coef[1][0] * a[5] + coef[1][1] * a[6] + coef[1][2] * a[7]
124 f[3] = coef[1][0] * b[5] + coef[1][1] * b[6] + coef[1][2] * b[7]
125 + coef[1][3] * b[8] - f[1];
129 f[4] = coef[2][0] * a[0] + coef[2][1] * a[1] + coef[2][2] * a[2]
130 + coef[2][3] * a[3] - a[4];
131 f[5] = coef[2][0] * b[0] + coef[2][1] * b[1] + coef[2][2] * b[2]
132 + coef[2][3] * b[3] - b[4] - f[3];
136 f[6] = coef[3][0] * (a[5] - a[7] - a[8]);
137 f[7] = coef[3][0] * (b[5] - b[7] - b[8]) - f[5];
141 f[8] = coef[4][0] * a[0] + coef[4][1] * a[1] + coef[4][2] * a[2]
142 + coef[4][3] * a[3] + a[4];
143 f[9] = coef[4][0] * b[0] + coef[4][1] * b[1] + coef[4][2] * b[2]
144 + coef[4][3] * b[3] + b[4] - f[7];
148 f[10] = coef[5][0] * a[5] + coef[5][1] * a[6] + coef[5][2] * a[7]
150 f[11] = coef[5][0] * b[5] + coef[5][1] * b[6] + coef[5][2] * b[7]
151 + coef[5][3] * b[8] - f[9];
153 f[10] = f[10] - f[9];
155 f[12] = 0.5f * (a[0] + a[2] + a[3]) - a[1] - a[4];
156 f[13] = 0.5f * (b[0] + b[2] + b[3]) - b[1] - b[4] - f[11];
157 f[11] = f[11] - f[10];
158 f[12] = f[12] - f[11];
160 f[14] = coef[7][0] * a[5] + coef[7][1] * a[6] + coef[7][2] * a[7]
162 f[15] = coef[7][0] * b[5] + coef[7][1] * b[6] + coef[7][2] * b[7]
163 + coef[7][3] * b[8] - f[13];
164 f[13] = f[13] - f[12];
165 f[14] = f[14] - f[13];
167 f[16] = coef[8][0] * a[0] + coef[8][1] * a[1] + coef[8][2] * a[2]
168 + coef[8][3] * a[3] + a[4];
169 f[17] = coef[8][0] * b[0] + coef[8][1] * b[1] + coef[8][2] * b[2]
170 + coef[8][3] * b[3] + b[4] - f[15];
171 f[15] = f[15] - f[14];
172 f[16] = f[16] - f[15];
173 f[17] = f[17] - f[16];
179 /*--------------------------------------------------------------------*/
180 /* does 3, 6 pt dct. changes order from f[i][window] c[window][i] */
181 void imdct6_3(float f[]) /* 6 point */
188 float *a, *c; // b[i] = a[3+i]
195 for (w = 0; w < 3; w++)
197 g1 = mdct6_3v[0] * f[3 * 0];
198 g2 = mdct6_3v[5] * f[3 * 5];
200 a[3 + 0] = mdct6_3v2[0] * (g1 - g2);
202 g1 = mdct6_3v[1] * f[3 * 1];
203 g2 = mdct6_3v[4] * f[3 * 4];
205 a[3 + 1] = mdct6_3v2[1] * (g1 - g2);
207 g1 = mdct6_3v[2] * f[3 * 2];
208 g2 = mdct6_3v[3] * f[3 * 3];
210 a[3 + 2] = mdct6_3v2[2] * (g1 - g2);
217 for (w = 0; w < 3; w++)
220 b02 = (a[3 + 0] + a[3 + 2]);
222 c[1] = b02 + a[3 + 1];
223 c[2] = coef87 * (a[0] - a[2]);
224 c[3] = coef87 * (a[3 + 0] - a[3 + 2]) - c[1];
227 c[4] = a02 - a[1] - a[1];
228 c[5] = b02 - a[3 + 1] - a[3 + 1] - c[3];
239 /*--------------------------------------------------------------------*/