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 /**** isbt.c ***************************************************
29 MPEG audio decoder, dct and window
30 portable C integer version of csbt.c
32 mods 11/15/95 for Layer I
36 ******************************************************************/
46 #pragma warning(disable: 4244)
47 #pragma warning(disable: 4056)
52 /* asm is quick only, c code does not need separate window for right */
53 /* full is opposite of quick */
55 #define i_window_dual_right i_window_dual
56 #define i_window16_dual_right i_window16_dual
57 #define i_window8_dual_right i_window8_dual
61 void i_dct32(SAMPLEINT * sample, WININT * vbuf);
62 void i_dct32_dual(SAMPLEINT * sample, WININT * vbuf);
63 void i_dct32_dual_mono(SAMPLEINT * sample, WININT * vbuf);
65 void i_dct16(SAMPLEINT * sample, WININT * vbuf);
66 void i_dct16_dual(SAMPLEINT * sample, WININT * vbuf);
67 void i_dct16_dual_mono(SAMPLEINT * sample, WININT * vbuf);
69 void i_dct8(SAMPLEINT * sample, WININT * vbuf);
70 void i_dct8_dual(SAMPLEINT * sample, WININT * vbuf);
71 void i_dct8_dual_mono(SAMPLEINT * sample, WININT * vbuf);
74 void i_window(WININT * vbuf, int vb_ptr, short *pcm);
75 void i_window_dual(WININT * vbuf, int vb_ptr, short *pcm);
76 void i_window_dual_right(WININT * vbuf, int vb_ptr, short *pcm);
78 void i_window16(WININT * vbuf, int vb_ptr, short *pcm);
79 void i_window16_dual(WININT * vbuf, int vb_ptr, short *pcm);
80 void i_window16_dual_right(WININT * vbuf, int vb_ptr, short *pcm);
82 void i_window8(WININT * vbuf, int vb_ptr, short *pcm);
83 void i_window8_dual(WININT * vbuf, int vb_ptr, short *pcm);
84 void i_window8_dual_right(WININT * vbuf, int vb_ptr, short *pcm);
86 /*--------------------------------------------------------------------*/
87 /*-- floating point window coefs ---*/
88 /*-- for integer-quick window, table used to generate integer coefs --*/
89 static float wincoef[264] =
94 /* circular window buffers */
95 /* extern windows because of asm */
96 static signed int vb_ptr;
98 // static WININT vbuf[512];
99 //static WININT vbuf2[512];
100 extern WININT vbuf[512];
101 extern WININT vbuf2[512];
103 DCTCOEF *i_dct_coef_addr(void);
105 /*======================================================================*/
106 static void gencoef(void) /* gen coef for N=32 */
112 coef32 = i_dct_coef_addr();
115 pi = 4.0 * atan(1.0);
118 for (i = 0; i < 5; i++, n = n / 2)
120 for (p = 0; p < n; p++, k++)
122 t = (pi / (4 * n)) * (2 * p + 1);
123 coef32[k] = (1 << DCTBITS) * (0.50 / cos(t)) + 0.5;
127 /*------------------------------------------------------------*/
128 WINCOEF *i_wincoef_addr(void);
129 static void genwincoef_q(void) /* gen int window coefs from floating table */
135 iwincoef = i_wincoef_addr();
138 /*--- coefs generated inline for quick window ---*/
139 /*-- quick uses only 116 coefs --*/
143 for (i = 0; i < 16; i++)
146 for (j = 0; j < 7; j++)
148 x = (1 << WINBITS) * wincoef[k++];
158 for (j = 0; j < 4; j++)
160 x = (1 << WINBITS) * wincoef[k++];
168 /*------------------------------------------------------------*/
169 static void genwincoef(void) /* gen int window coefs from floating table */
175 iwincoef = i_wincoef_addr();
177 for (i = 0; i < 264; i++)
179 x = (1 << WINBITS) * wincoef[i];
187 /*------------------------------------------------------------*/
188 void i_sbt_init(void)
191 static int first_pass = 1;
194 static int full_integer = 1;
197 static int full_integer = 0;
211 /* clear window vbuf */
212 for (i = 0; i < 512; i++)
213 vbuf[i] = vbuf2[i] = 0;
217 /*==============================================================*/
218 /*==============================================================*/
219 /*==============================================================*/
220 void i_sbt_mono(SAMPLEINT * sample, short *pcm, int n)
224 for (i = 0; i < n; i++)
226 i_dct32(sample, vbuf + vb_ptr);
227 i_window(vbuf, vb_ptr, pcm);
229 vb_ptr = (vb_ptr - 32) & 511;
234 /*------------------------------------------------------------*/
235 void i_sbt_dual(SAMPLEINT * sample, short *pcm, int n)
239 for (i = 0; i < n; i++)
241 i_dct32_dual(sample, vbuf + vb_ptr);
242 i_dct32_dual(sample + 1, vbuf2 + vb_ptr);
243 i_window_dual(vbuf, vb_ptr, pcm);
244 i_window_dual_right(vbuf2, vb_ptr, pcm + 1);
246 vb_ptr = (vb_ptr - 32) & 511;
250 /*------------------------------------------------------------*/
251 /* convert dual to mono */
252 void i_sbt_dual_mono(SAMPLEINT * sample, short *pcm, int n)
256 for (i = 0; i < n; i++)
258 i_dct32_dual_mono(sample, vbuf + vb_ptr);
259 i_window(vbuf, vb_ptr, pcm);
261 vb_ptr = (vb_ptr - 32) & 511;
265 /*------------------------------------------------------------*/
266 /* convert dual to left */
267 void i_sbt_dual_left(SAMPLEINT * sample, short *pcm, int n)
271 for (i = 0; i < n; i++)
273 i_dct32_dual(sample, vbuf + vb_ptr);
274 i_window(vbuf, vb_ptr, pcm);
276 vb_ptr = (vb_ptr - 32) & 511;
280 /*------------------------------------------------------------*/
281 /* convert dual to right */
282 void i_sbt_dual_right(SAMPLEINT * sample, short *pcm, int n)
286 sample++; /* point to right chan */
287 for (i = 0; i < n; i++)
289 i_dct32_dual(sample, vbuf + vb_ptr);
290 i_window(vbuf, vb_ptr, pcm);
292 vb_ptr = (vb_ptr - 32) & 511;
296 /*------------------------------------------------------------*/
297 /*---------------- 16 pt sbt's -------------------------------*/
298 /*------------------------------------------------------------*/
299 void i_sbt16_mono(SAMPLEINT * sample, short *pcm, int n)
303 for (i = 0; i < n; i++)
305 i_dct16(sample, vbuf + vb_ptr);
306 i_window16(vbuf, vb_ptr, pcm);
308 vb_ptr = (vb_ptr - 16) & 255;
313 /*------------------------------------------------------------*/
314 void i_sbt16_dual(SAMPLEINT * sample, short *pcm, int n)
318 for (i = 0; i < n; i++)
320 i_dct16_dual(sample, vbuf + vb_ptr);
321 i_dct16_dual(sample + 1, vbuf2 + vb_ptr);
322 i_window16_dual(vbuf, vb_ptr, pcm);
323 i_window16_dual_right(vbuf2, vb_ptr, pcm + 1);
325 vb_ptr = (vb_ptr - 16) & 255;
330 /*------------------------------------------------------------*/
331 void i_sbt16_dual_mono(SAMPLEINT * sample, short *pcm, int n)
335 for (i = 0; i < n; i++)
337 i_dct16_dual_mono(sample, vbuf + vb_ptr);
338 i_window16(vbuf, vb_ptr, pcm);
340 vb_ptr = (vb_ptr - 16) & 255;
344 /*------------------------------------------------------------*/
345 void i_sbt16_dual_left(SAMPLEINT * sample, short *pcm, int n)
349 for (i = 0; i < n; i++)
351 i_dct16_dual(sample, vbuf + vb_ptr);
352 i_window16(vbuf, vb_ptr, pcm);
354 vb_ptr = (vb_ptr - 16) & 255;
358 /*------------------------------------------------------------*/
359 void i_sbt16_dual_right(SAMPLEINT * sample, short *pcm, int n)
364 for (i = 0; i < n; i++)
366 i_dct16_dual(sample, vbuf + vb_ptr);
367 i_window16(vbuf, vb_ptr, pcm);
369 vb_ptr = (vb_ptr - 16) & 255;
373 /*------------------------------------------------------------*/
374 /*---------------- 8 pt sbt's -------------------------------*/
375 /*------------------------------------------------------------*/
376 void i_sbt8_mono(SAMPLEINT * sample, short *pcm, int n)
380 for (i = 0; i < n; i++)
382 i_dct8(sample, vbuf + vb_ptr);
383 i_window8(vbuf, vb_ptr, pcm);
385 vb_ptr = (vb_ptr - 8) & 127;
390 /*------------------------------------------------------------*/
391 void i_sbt8_dual(SAMPLEINT * sample, short *pcm, int n)
395 for (i = 0; i < n; i++)
397 i_dct8_dual(sample, vbuf + vb_ptr);
398 i_dct8_dual(sample + 1, vbuf2 + vb_ptr);
399 i_window8_dual(vbuf, vb_ptr, pcm);
400 i_window8_dual_right(vbuf2, vb_ptr, pcm + 1);
402 vb_ptr = (vb_ptr - 8) & 127;
406 /*------------------------------------------------------------*/
407 void i_sbt8_dual_mono(SAMPLEINT * sample, short *pcm, int n)
411 for (i = 0; i < n; i++)
413 i_dct8_dual_mono(sample, vbuf + vb_ptr);
414 i_window8(vbuf, vb_ptr, pcm);
416 vb_ptr = (vb_ptr - 8) & 127;
420 /*------------------------------------------------------------*/
421 void i_sbt8_dual_left(SAMPLEINT * sample, short *pcm, int n)
425 for (i = 0; i < n; i++)
427 i_dct8_dual(sample, vbuf + vb_ptr);
428 i_window8(vbuf, vb_ptr, pcm);
430 vb_ptr = (vb_ptr - 8) & 127;
434 /*------------------------------------------------------------*/
435 void i_sbt8_dual_right(SAMPLEINT * sample, short *pcm, int n)
440 for (i = 0; i < n; i++)
442 i_dct8_dual(sample, vbuf + vb_ptr);
443 i_window8(vbuf, vb_ptr, pcm);
445 vb_ptr = (vb_ptr - 8) & 127;
449 /*------------------------------------------------------------*/
450 /*--- 8 bit output ----------------*/
452 /*----------------------------------*/
455 #pragma warning(default: 4244)
456 #pragma warning(default: 4056)