aboutsummaryrefslogtreecommitdiffstats
path: root/codecs/mp3/src
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>1999-12-07 05:45:48 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>1999-12-07 05:45:48 +0000
commit878dd470f235a2c945f2410927175a45f052b234 (patch)
tree4fc09f73bccf2e5017fd2dab7019e076351cab9b /codecs/mp3/src
parent070e10a75492938462eeac565c78c8c16a02fc74 (diff)
Version 0.1.1 from FTP
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@95 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'codecs/mp3/src')
-rwxr-xr-xcodecs/mp3/src/cdct.c349
-rwxr-xr-xcodecs/mp3/src/csbt.c345
-rwxr-xr-xcodecs/mp3/src/csbtL3.c316
-rwxr-xr-xcodecs/mp3/src/csbtb.c276
-rwxr-xr-xcodecs/mp3/src/cupini.c421
-rwxr-xr-xcodecs/mp3/src/cupl3.c1189
-rwxr-xr-xcodecs/mp3/src/cwin.c500
-rwxr-xr-xcodecs/mp3/src/cwinb.c496
-rwxr-xr-xcodecs/mp3/src/cwinm.c59
-rwxr-xr-xcodecs/mp3/src/dec8.c338
-rwxr-xr-xcodecs/mp3/src/hwin.c284
-rwxr-xr-xcodecs/mp3/src/icdct.c383
-rwxr-xr-xcodecs/mp3/src/isbt.c458
-rwxr-xr-xcodecs/mp3/src/isbtb.c288
-rwxr-xr-xcodecs/mp3/src/iup.c529
-rwxr-xr-xcodecs/mp3/src/iupL1.c330
-rwxr-xr-xcodecs/mp3/src/iupini.c389
-rwxr-xr-xcodecs/mp3/src/iwinQ.c712
-rwxr-xr-xcodecs/mp3/src/iwinbQ.c712
-rwxr-xr-xcodecs/mp3/src/iwinm.c64
-rwxr-xr-xcodecs/mp3/src/l3dq.c256
-rwxr-xr-xcodecs/mp3/src/l3init.c383
-rwxr-xr-xcodecs/mp3/src/mdct.c239
-rwxr-xr-xcodecs/mp3/src/mhead.c321
-rwxr-xr-xcodecs/mp3/src/msis.c300
-rwxr-xr-xcodecs/mp3/src/uph.c505
-rwxr-xr-xcodecs/mp3/src/upsf.c404
-rwxr-xr-xcodecs/mp3/src/wavep.c165
-rwxr-xr-xcodecs/mp3/src/wcvt.c92
-rwxr-xr-xcodecs/mp3/src/x86gas.s393
-rwxr-xr-xcodecs/mp3/src/x86intel.c437
31 files changed, 11933 insertions, 0 deletions
diff --git a/codecs/mp3/src/cdct.c b/codecs/mp3/src/cdct.c
new file mode 100755
index 000000000..f9ce28a7e
--- /dev/null
+++ b/codecs/mp3/src/cdct.c
@@ -0,0 +1,349 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** cdct.c ***************************************************
+
+mod 5/16/95 first stage in 8 pt dct does not drop last sb mono
+
+
+MPEG audio decoder, dct
+portable C
+
+******************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#include "L3.h"
+#include "mhead.h"
+
+#ifdef ASM_X86
+extern void fdct32_asm(float*a, float*b);
+extern void fdct32_dual_asm(float*a, float*b);
+#endif /* ASM_X86 */
+
+/*------------------------------------------------------------*/
+float *dct_coef_addr(MPEG *m)
+{
+ return m->cdct.coef32;
+}
+/*------------------------------------------------------------*/
+static void forward_bf(int m, int n, float x[], float f[], float coef[])
+{
+ int i, j, n2;
+ int p, q, p0, k;
+
+ p0 = 0;
+ n2 = n >> 1;
+ for (i = 0; i < m; i++, p0 += n)
+ {
+ k = 0;
+ p = p0;
+ q = p + n - 1;
+ for (j = 0; j < n2; j++, p++, q--, k++)
+ {
+ f[p] = x[p] + x[q];
+ f[n2 + p] = coef[k] * (x[p] - x[q]);
+ }
+ }
+}
+/*------------------------------------------------------------*/
+static void back_bf(int m, int n, float x[], float f[])
+{
+ int i, j, n2, n21;
+ int p, q, p0;
+
+ p0 = 0;
+ n2 = n >> 1;
+ n21 = n2 - 1;
+ for (i = 0; i < m; i++, p0 += n)
+ {
+ p = p0;
+ q = p0;
+ for (j = 0; j < n2; j++, p += 2, q++)
+ f[p] = x[q];
+ p = p0 + 1;
+ for (j = 0; j < n21; j++, p += 2, q++)
+ f[p] = x[q] + x[q + 1];
+ f[p] = x[q];
+ }
+}
+/*------------------------------------------------------------*/
+
+#ifdef _EQUALIZER_ENABLE_
+extern float equalizer[32];
+extern int enableEQ;
+#endif
+
+void fdct32(MPEG *m, float x[], float c[])
+{
+#if (!defined(ASM_X86) && !defined(ASM_X86_OLD) || defined(_EQUALIZER_ENABLE_))
+ float a[32]; /* ping pong buffers */
+ float b[32];
+ int p, q;
+#endif
+
+ float *src = x;
+
+#ifdef _EQUALIZER_ENABLE_
+ int i;
+ float b[32];
+ if (enableEQ) {
+ for(i=0; i<32; i++)
+ b[i] = x[i] * equalizer[i];
+ src = b;
+ }
+#endif /* _EQUALIZER_ENABLE_ */
+#undef _EQUALIZER_ENABLE_
+
+#ifdef ASM_X86
+ fdct32_asm(src, c);
+#elif defined(ASM_X86_OLD)
+ asm_fdct32(src, c);
+#else
+/* special first stage */
+ for (p = 0, q = 31; p < 16; p++, q--)
+ {
+ a[p] = src[p] + src[q];
+ a[16 + p] = m->cdct.coef32[p] * (src[p] - src[q]);
+ }
+ forward_bf(2, 16, a, b, m->cdct.coef32 + 16);
+ forward_bf(4, 8, b, a, m->cdct.coef32 + 16 + 8);
+ forward_bf(8, 4, a, b, m->cdct.coef32 + 16 + 8 + 4);
+ forward_bf(16, 2, b, a, m->cdct.coef32 + 16 + 8 + 4 + 2);
+ back_bf(8, 4, a, b);
+ back_bf(4, 8, b, a);
+ back_bf(2, 16, a, b);
+ back_bf(1, 32, b, c);
+#endif
+}
+/*------------------------------------------------------------*/
+void fdct32_dual(MPEG *m, float x[], float c[])
+{
+#ifdef ASM_X86
+ fdct32_dual_asm(x, c);
+#else
+ float a[32]; /* ping pong buffers */
+ float b[32];
+ int p, pp, qq;
+
+/* special first stage for dual chan (interleaved x) */
+ pp = 0;
+ qq = 2 * 31;
+ for (p = 0; p < 16; p++, pp += 2, qq -= 2)
+ {
+ a[p] = x[pp] + x[qq];
+ a[16 + p] = m->cdct.coef32[p] * (x[pp] - x[qq]);
+ }
+ forward_bf(2, 16, a, b, m->cdct.coef32 + 16);
+ forward_bf(4, 8, b, a, m->cdct.coef32 + 16 + 8);
+ forward_bf(8, 4, a, b, m->cdct.coef32 + 16 + 8 + 4);
+ forward_bf(16, 2, b, a, m->cdct.coef32 + 16 + 8 + 4 + 2);
+ back_bf(8, 4, a, b);
+ back_bf(4, 8, b, a);
+ back_bf(2, 16, a, b);
+ back_bf(1, 32, b, c);
+#endif
+}
+/*---------------convert dual to mono------------------------------*/
+void fdct32_dual_mono(MPEG *m, float x[], float c[])
+{
+ float a[32]; /* ping pong buffers */
+ float b[32];
+ float t1, t2;
+ int p, pp, qq;
+
+/* special first stage */
+ pp = 0;
+ qq = 2 * 31;
+ for (p = 0; p < 16; p++, pp += 2, qq -= 2)
+ {
+ t1 = 0.5F * (x[pp] + x[pp + 1]);
+ t2 = 0.5F * (x[qq] + x[qq + 1]);
+ a[p] = t1 + t2;
+ a[16 + p] = m->cdct.coef32[p] * (t1 - t2);
+ }
+ forward_bf(2, 16, a, b, m->cdct.coef32 + 16);
+ forward_bf(4, 8, b, a, m->cdct.coef32 + 16 + 8);
+ forward_bf(8, 4, a, b, m->cdct.coef32 + 16 + 8 + 4);
+ forward_bf(16, 2, b, a, m->cdct.coef32 + 16 + 8 + 4 + 2);
+ back_bf(8, 4, a, b);
+ back_bf(4, 8, b, a);
+ back_bf(2, 16, a, b);
+ back_bf(1, 32, b, c);
+}
+/*------------------------------------------------------------*/
+/*---------------- 16 pt fdct -------------------------------*/
+void fdct16(MPEG *m, float x[], float c[])
+{
+ float a[16]; /* ping pong buffers */
+ float b[16];
+ int p, q;
+
+/* special first stage (drop highest sb) */
+ a[0] = x[0];
+ a[8] = m->cdct.coef32[16] * x[0];
+ for (p = 1, q = 14; p < 8; p++, q--)
+ {
+ a[p] = x[p] + x[q];
+ a[8 + p] = m->cdct.coef32[16 + p] * (x[p] - x[q]);
+ }
+ forward_bf(2, 8, a, b, m->cdct.coef32 + 16 + 8);
+ forward_bf(4, 4, b, a, m->cdct.coef32 + 16 + 8 + 4);
+ forward_bf(8, 2, a, b, m->cdct.coef32 + 16 + 8 + 4 + 2);
+ back_bf(4, 4, b, a);
+ back_bf(2, 8, a, b);
+ back_bf(1, 16, b, c);
+}
+/*------------------------------------------------------------*/
+/*---------------- 16 pt fdct dual chan---------------------*/
+void fdct16_dual(MPEG *m, float x[], float c[])
+{
+ float a[16]; /* ping pong buffers */
+ float b[16];
+ int p, pp, qq;
+
+/* special first stage for interleaved input */
+ a[0] = x[0];
+ a[8] = m->cdct.coef32[16] * x[0];
+ pp = 2;
+ qq = 2 * 14;
+ for (p = 1; p < 8; p++, pp += 2, qq -= 2)
+ {
+ a[p] = x[pp] + x[qq];
+ a[8 + p] = m->cdct.coef32[16 + p] * (x[pp] - x[qq]);
+ }
+ forward_bf(2, 8, a, b, m->cdct.coef32 + 16 + 8);
+ forward_bf(4, 4, b, a, m->cdct.coef32 + 16 + 8 + 4);
+ forward_bf(8, 2, a, b, m->cdct.coef32 + 16 + 8 + 4 + 2);
+ back_bf(4, 4, b, a);
+ back_bf(2, 8, a, b);
+ back_bf(1, 16, b, c);
+}
+/*------------------------------------------------------------*/
+/*---------------- 16 pt fdct dual to mono-------------------*/
+void fdct16_dual_mono(MPEG *m, float x[], float c[])
+{
+ float a[16]; /* ping pong buffers */
+ float b[16];
+ float t1, t2;
+ int p, pp, qq;
+
+/* special first stage */
+ a[0] = 0.5F * (x[0] + x[1]);
+ a[8] = m->cdct.coef32[16] * a[0];
+ pp = 2;
+ qq = 2 * 14;
+ for (p = 1; p < 8; p++, pp += 2, qq -= 2)
+ {
+ t1 = 0.5F * (x[pp] + x[pp + 1]);
+ t2 = 0.5F * (x[qq] + x[qq + 1]);
+ a[p] = t1 + t2;
+ a[8 + p] = m->cdct.coef32[16 + p] * (t1 - t2);
+ }
+ forward_bf(2, 8, a, b, m->cdct.coef32 + 16 + 8);
+ forward_bf(4, 4, b, a, m->cdct.coef32 + 16 + 8 + 4);
+ forward_bf(8, 2, a, b, m->cdct.coef32 + 16 + 8 + 4 + 2);
+ back_bf(4, 4, b, a);
+ back_bf(2, 8, a, b);
+ back_bf(1, 16, b, c);
+}
+/*------------------------------------------------------------*/
+/*---------------- 8 pt fdct -------------------------------*/
+void fdct8(MPEG *m, float x[], float c[])
+{
+ float a[8]; /* ping pong buffers */
+ float b[8];
+ int p, q;
+
+/* special first stage */
+
+ b[0] = x[0] + x[7];
+ b[4] = m->cdct.coef32[16 + 8] * (x[0] - x[7]);
+ for (p = 1, q = 6; p < 4; p++, q--)
+ {
+ b[p] = x[p] + x[q];
+ b[4 + p] = m->cdct.coef32[16 + 8 + p] * (x[p] - x[q]);
+ }
+
+ forward_bf(2, 4, b, a, m->cdct.coef32 + 16 + 8 + 4);
+ forward_bf(4, 2, a, b, m->cdct.coef32 + 16 + 8 + 4 + 2);
+ back_bf(2, 4, b, a);
+ back_bf(1, 8, a, c);
+}
+/*------------------------------------------------------------*/
+/*---------------- 8 pt fdct dual chan---------------------*/
+void fdct8_dual(MPEG *m, float x[], float c[])
+{
+ float a[8]; /* ping pong buffers */
+ float b[8];
+ int p, pp, qq;
+
+/* special first stage for interleaved input */
+ b[0] = x[0] + x[14];
+ b[4] = m->cdct.coef32[16 + 8] * (x[0] - x[14]);
+ pp = 2;
+ qq = 2 * 6;
+ for (p = 1; p < 4; p++, pp += 2, qq -= 2)
+ {
+ b[p] = x[pp] + x[qq];
+ b[4 + p] = m->cdct.coef32[16 + 8 + p] * (x[pp] - x[qq]);
+ }
+ forward_bf(2, 4, b, a, m->cdct.coef32 + 16 + 8 + 4);
+ forward_bf(4, 2, a, b, m->cdct.coef32 + 16 + 8 + 4 + 2);
+ back_bf(2, 4, b, a);
+ back_bf(1, 8, a, c);
+}
+/*------------------------------------------------------------*/
+/*---------------- 8 pt fdct dual to mono---------------------*/
+void fdct8_dual_mono(MPEG *m, float x[], float c[])
+{
+ float a[8]; /* ping pong buffers */
+ float b[8];
+ float t1, t2;
+ int p, pp, qq;
+
+/* special first stage */
+ t1 = 0.5F * (x[0] + x[1]);
+ t2 = 0.5F * (x[14] + x[15]);
+ b[0] = t1 + t2;
+ b[4] = m->cdct.coef32[16 + 8] * (t1 - t2);
+ pp = 2;
+ qq = 2 * 6;
+ for (p = 1; p < 4; p++, pp += 2, qq -= 2)
+ {
+ t1 = 0.5F * (x[pp] + x[pp + 1]);
+ t2 = 0.5F * (x[qq] + x[qq + 1]);
+ b[p] = t1 + t2;
+ b[4 + p] = m->cdct.coef32[16 + 8 + p] * (t1 - t2);
+ }
+ forward_bf(2, 4, b, a, m->cdct.coef32 + 16 + 8 + 4);
+ forward_bf(4, 2, a, b, m->cdct.coef32 + 16 + 8 + 4 + 2);
+ back_bf(2, 4, b, a);
+ back_bf(1, 8, a, c);
+}
+/*------------------------------------------------------------*/
diff --git a/codecs/mp3/src/csbt.c b/codecs/mp3/src/csbt.c
new file mode 100755
index 000000000..bb9079526
--- /dev/null
+++ b/codecs/mp3/src/csbt.c
@@ -0,0 +1,345 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** csbt.c ***************************************************
+
+MPEG audio decoder, dct and window
+portable C
+
+1/7/96 mod for Layer III
+
+******************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#include "L3.h"
+#include "mhead.h"
+
+void fdct32(MPEG *m, float *, float *);
+void fdct32_dual(MPEG *m, float *, float *);
+void fdct32_dual_mono(MPEG *m, float *, float *);
+void fdct16(MPEG *m, float *, float *);
+void fdct16_dual(MPEG *m, float *, float *);
+void fdct16_dual_mono(MPEG *m, float *, float *);
+void fdct8(MPEG *m, float *, float *);
+void fdct8_dual(MPEG *m, float *, float *);
+void fdct8_dual_mono(MPEG *m, float *, float *);
+
+void window(float *, int , short *pcm);
+void window_dual(MPEG *m, float *, int , short *pcm);
+void window16(MPEG *m, float *, int , short *pcm);
+void window16_dual(MPEG *m, float *, int , short *pcm);
+void window8(MPEG *m, float *, int , short *pcm);
+void window8_dual(MPEG *m, float *, int , short *pcm);
+float *dct_coef_addr(MPEG *m);
+
+/*-------------------------------------------------------------------------*/
+/* circular window buffers */
+
+/*======================================================================*/
+static void gencoef(MPEG *m) /* gen coef for N=32 (31 coefs) */
+{
+ int p, n, i, k;
+ double t, pi;
+ float *coef32;
+
+ coef32 = dct_coef_addr(m);
+
+ pi = 4.0 * atan(1.0);
+ n = 16;
+ k = 0;
+ for (i = 0; i < 5; i++, n = n / 2)
+ {
+
+ for (p = 0; p < n; p++, k++)
+ {
+ t = (pi / (4 * n)) * (2 * p + 1);
+ coef32[k] = (float) (0.50 / cos(t));
+ }
+ }
+}
+/*------------------------------------------------------------*/
+void sbt_init(MPEG *m)
+{
+ int i;
+
+ if (m->csbt.first_pass)
+ {
+ gencoef(m);
+ m->csbt.first_pass = 0;
+ }
+
+/* clear window m->csbt.vbuf */
+ for (i = 0; i < 512; i++)
+ {
+ m->csbt.vbuf[i] = 0.0F;
+ m->csbt.vbuf2[i] = 0.0F;
+ }
+ m->csbt.vb2_ptr = m->csbt.vb_ptr = 0;
+
+}
+/*============================================================*/
+/*============================================================*/
+/*============================================================*/
+void sbt_mono(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct32(m, sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window(m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+
+}
+/*------------------------------------------------------------*/
+void sbt_dual(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct32_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ fdct32_dual(m,sample + 1, m->csbt.vbuf2 + m->csbt.vb_ptr);
+ window_dual(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ window_dual(m,m->csbt.vbuf2, m->csbt.vb_ptr, pcm + 1);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 32) & 511;
+ pcm += 64;
+ }
+
+
+}
+/*------------------------------------------------------------*/
+/* convert dual to mono */
+void sbt_dual_mono(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct32_dual_mono(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window(m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+
+}
+/*------------------------------------------------------------*/
+/* convert dual to left */
+void sbt_dual_left(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct32_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window(m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+}
+/*------------------------------------------------------------*/
+/* convert dual to right */
+void sbt_dual_right(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ sample++; /* point to right chan */
+ for (i = 0; i < n; i++)
+ {
+ fdct32_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window(m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+}
+/*------------------------------------------------------------*/
+/*---------------- 16 pt sbt's -------------------------------*/
+/*------------------------------------------------------------*/
+void sbt16_mono(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct16(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window16(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+
+
+}
+/*------------------------------------------------------------*/
+void sbt16_dual(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct16_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ fdct16_dual(m,sample + 1, m->csbt.vbuf2 + m->csbt.vb_ptr);
+ window16_dual(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ window16_dual(m,m->csbt.vbuf2, m->csbt.vb_ptr, pcm + 1);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 16) & 255;
+ pcm += 32;
+ }
+}
+/*------------------------------------------------------------*/
+void sbt16_dual_mono(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct16_dual_mono(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window16(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+void sbt16_dual_left(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct16_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window16(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+void sbt16_dual_right(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ sample++;
+ for (i = 0; i < n; i++)
+ {
+ fdct16_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window16(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+/*---------------- 8 pt sbt's -------------------------------*/
+/*------------------------------------------------------------*/
+void sbt8_mono(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct8(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window8(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+
+}
+/*------------------------------------------------------------*/
+void sbt8_dual(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct8_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ fdct8_dual(m,sample + 1, m->csbt.vbuf2 + m->csbt.vb_ptr);
+ window8_dual(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ window8_dual(m,m->csbt.vbuf2, m->csbt.vb_ptr, pcm + 1);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 8) & 127;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+void sbt8_dual_mono(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct8_dual_mono(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window8(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+}
+/*------------------------------------------------------------*/
+void sbt8_dual_left(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct8_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window8(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+}
+/*------------------------------------------------------------*/
+void sbt8_dual_right(MPEG *m, float *sample, short *pcm, int n)
+{
+ int i;
+
+ sample++;
+ for (i = 0; i < n; i++)
+ {
+ fdct8_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window8(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+}
+/*------------------------------------------------------------*/
+/*------------------------------------------------------------*/
+#include "csbtb.c" /* 8 bit output */
+#include "csbtL3.c" /* Layer III */
+/*------------------------------------------------------------*/
diff --git a/codecs/mp3/src/csbtL3.c b/codecs/mp3/src/csbtL3.c
new file mode 100755
index 000000000..85f9599b0
--- /dev/null
+++ b/codecs/mp3/src/csbtL3.c
@@ -0,0 +1,316 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** csbtL3.c ***************************************************
+
+layer III
+
+ include to csbt.c
+
+******************************************************************/
+/*============================================================*/
+/*============ Layer III =====================================*/
+/*============================================================*/
+void sbt_mono_L3(MPEG *m, float *sample, short *pcm, int ch)
+{
+ int i;
+
+ ch = 0;
+ for (i = 0; i < 18; i++)
+ {
+ fdct32(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window(m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 32;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+
+}
+/*------------------------------------------------------------*/
+void sbt_dual_L3(MPEG *m, float *sample, short *pcm, int ch)
+{
+ int i;
+
+ if (ch == 0)
+ for (i = 0; i < 18; i++)
+ {
+ fdct32(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window_dual(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 32;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 32) & 511;
+ pcm += 64;
+ }
+ else
+ for (i = 0; i < 18; i++)
+ {
+ fdct32(m,sample, m->csbt.vbuf2 + m->csbt.vb2_ptr);
+ window_dual(m,m->csbt.vbuf2, m->csbt.vb2_ptr, pcm + 1);
+ sample += 32;
+ m->csbt.vb2_ptr = (m->csbt.vb2_ptr - 32) & 511;
+ pcm += 64;
+ }
+
+
+}
+/*------------------------------------------------------------*/
+/*------------------------------------------------------------*/
+/*---------------- 16 pt sbt's -------------------------------*/
+/*------------------------------------------------------------*/
+void sbt16_mono_L3(MPEG *m, float *sample, short *pcm, int ch)
+{
+ int i;
+
+ ch = 0;
+ for (i = 0; i < 18; i++)
+ {
+ fdct16(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window16(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 32;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+
+
+}
+/*------------------------------------------------------------*/
+void sbt16_dual_L3(MPEG *m, float *sample, short *pcm, int ch)
+{
+ int i;
+
+
+ if (ch == 0)
+ {
+ for (i = 0; i < 18; i++)
+ {
+ fdct16(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window16_dual(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 32;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 16) & 255;
+ pcm += 32;
+ }
+ }
+ else
+ {
+ for (i = 0; i < 18; i++)
+ {
+ fdct16(m,sample, m->csbt.vbuf2 + m->csbt.vb2_ptr);
+ window16_dual(m,m->csbt.vbuf2, m->csbt.vb2_ptr, pcm + 1);
+ sample += 32;
+ m->csbt.vb2_ptr = (m->csbt.vb2_ptr - 16) & 255;
+ pcm += 32;
+ }
+ }
+
+}
+/*------------------------------------------------------------*/
+/*---------------- 8 pt sbt's -------------------------------*/
+/*------------------------------------------------------------*/
+void sbt8_mono_L3(MPEG *m, float *sample, short *pcm, int ch)
+{
+ int i;
+
+ ch = 0;
+ for (i = 0; i < 18; i++)
+ {
+ fdct8(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window8(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 32;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+
+}
+/*------------------------------------------------------------*/
+void sbt8_dual_L3(MPEG *m, float *sample, short *pcm, int ch)
+{
+ int i;
+
+ if (ch == 0)
+ {
+ for (i = 0; i < 18; i++)
+ {
+ fdct8(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ window8_dual(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 32;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 8) & 127;
+ pcm += 16;
+ }
+ }
+ else
+ {
+ for (i = 0; i < 18; i++)
+ {
+ fdct8(m,sample, m->csbt.vbuf2 + m->csbt.vb2_ptr);
+ window8_dual(m,m->csbt.vbuf2, m->csbt.vb2_ptr, pcm + 1);
+ sample += 32;
+ m->csbt.vb2_ptr = (m->csbt.vb2_ptr - 8) & 127;
+ pcm += 16;
+ }
+ }
+
+
+
+}
+/*------------------------------------------------------------*/
+/*------- 8 bit output ---------------------------------------*/
+/*------------------------------------------------------------*/
+void sbtB_mono_L3(MPEG *m, float *sample, unsigned char *pcm, int ch)
+{
+ int i;
+
+ ch = 0;
+ for (i = 0; i < 18; i++)
+ {
+ fdct32(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 32;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+
+}
+/*------------------------------------------------------------*/
+void sbtB_dual_L3(MPEG *m, float *sample, unsigned char *pcm, int ch)
+{
+ int i;
+
+ if (ch == 0)
+ for (i = 0; i < 18; i++)
+ {
+ fdct32(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB_dual(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 32;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 32) & 511;
+ pcm += 64;
+ }
+ else
+ for (i = 0; i < 18; i++)
+ {
+ fdct32(m,sample, m->csbt.vbuf2 + m->csbt.vb2_ptr);
+ windowB_dual(m,m->csbt.vbuf2, m->csbt.vb2_ptr, pcm + 1);
+ sample += 32;
+ m->csbt.vb2_ptr = (m->csbt.vb2_ptr - 32) & 511;
+ pcm += 64;
+ }
+
+}
+/*------------------------------------------------------------*/
+/*------------------------------------------------------------*/
+/*---------------- 16 pt sbtB's -------------------------------*/
+/*------------------------------------------------------------*/
+void sbtB16_mono_L3(MPEG *m, float *sample, unsigned char *pcm, int ch)
+{
+ int i;
+
+ ch = 0;
+ for (i = 0; i < 18; i++)
+ {
+ fdct16(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB16(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 32;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+
+
+}
+/*------------------------------------------------------------*/
+void sbtB16_dual_L3(MPEG *m, float *sample, unsigned char *pcm, int ch)
+{
+ int i;
+
+ if (ch == 0)
+ {
+ for (i = 0; i < 18; i++)
+ {
+ fdct16(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB16_dual(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 32;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 16) & 255;
+ pcm += 32;
+ }
+ }
+ else
+ {
+ for (i = 0; i < 18; i++)
+ {
+ fdct16(m,sample, m->csbt.vbuf2 + m->csbt.vb2_ptr);
+ windowB16_dual(m,m->csbt.vbuf2, m->csbt.vb2_ptr, pcm + 1);
+ sample += 32;
+ m->csbt.vb2_ptr = (m->csbt.vb2_ptr - 16) & 255;
+ pcm += 32;
+ }
+ }
+
+}
+/*------------------------------------------------------------*/
+/*---------------- 8 pt sbtB's -------------------------------*/
+/*------------------------------------------------------------*/
+void sbtB8_mono_L3(MPEG *m, float *sample, unsigned char *pcm, int ch)
+{
+ int i;
+
+ ch = 0;
+ for (i = 0; i < 18; i++)
+ {
+ fdct8(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB8(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 32;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+
+}
+/*------------------------------------------------------------*/
+void sbtB8_dual_L3(MPEG *m, float *sample, unsigned char *pcm, int ch)
+{
+ int i;
+
+ if (ch == 0)
+ {
+ for (i = 0; i < 18; i++)
+ {
+ fdct8(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB8_dual(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 32;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 8) & 127;
+ pcm += 16;
+ }
+ }
+ else
+ {
+ for (i = 0; i < 18; i++)
+ {
+ fdct8(m,sample, m->csbt.vbuf2 + m->csbt.vb2_ptr);
+ windowB8_dual(m,m->csbt.vbuf2, m->csbt.vb2_ptr, pcm + 1);
+ sample += 32;
+ m->csbt.vb2_ptr = (m->csbt.vb2_ptr - 8) & 127;
+ pcm += 16;
+ }
+ }
+
+}
+/*------------------------------------------------------------*/
diff --git a/codecs/mp3/src/csbtb.c b/codecs/mp3/src/csbtb.c
new file mode 100755
index 000000000..158c38151
--- /dev/null
+++ b/codecs/mp3/src/csbtb.c
@@ -0,0 +1,276 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** csbtb.c ***************************************************
+include to csbt.c
+
+MPEG audio decoder, dct and window - byte (8 pcm bit output)
+portable C
+
+******************************************************************/
+/*============================================================*/
+/*============================================================*/
+void windowB(MPEG *m, float *, int , unsigned char *pcm);
+void windowB_dual(MPEG *m, float *, int , unsigned char *pcm);
+void windowB16(MPEG *m, float *, int , unsigned char *pcm);
+void windowB16_dual(MPEG *m, float *, int , unsigned char *pcm);
+void windowB8(MPEG *m, float *, int , unsigned char *pcm);
+void windowB8_dual(MPEG *m, float *, int , unsigned char *pcm);
+
+/*============================================================*/
+void sbtB_mono(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct32(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+
+}
+/*------------------------------------------------------------*/
+void sbtB_dual(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct32_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ fdct32_dual(m,sample + 1, m->csbt.vbuf2 + m->csbt.vb_ptr);
+ windowB_dual(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ windowB_dual(m,m->csbt.vbuf2, m->csbt.vb_ptr, pcm + 1);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 32) & 511;
+ pcm += 64;
+ }
+
+
+}
+/*------------------------------------------------------------*/
+/* convert dual to mono */
+void sbtB_dual_mono(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct32_dual_mono(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+
+}
+/*------------------------------------------------------------*/
+/* convert dual to left */
+void sbtB_dual_left(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct32_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+}
+/*------------------------------------------------------------*/
+/* convert dual to right */
+void sbtB_dual_right(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ sample++; /* point to right chan */
+ for (i = 0; i < n; i++)
+ {
+ fdct32_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+}
+/*------------------------------------------------------------*/
+/*---------------- 16 pt sbt's -------------------------------*/
+/*------------------------------------------------------------*/
+void sbtB16_mono(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct16(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB16(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+
+
+}
+/*------------------------------------------------------------*/
+void sbtB16_dual(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct16_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ fdct16_dual(m,sample + 1, m->csbt.vbuf2 + m->csbt.vb_ptr);
+ windowB16_dual(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ windowB16_dual(m,m->csbt.vbuf2, m->csbt.vb_ptr, pcm + 1);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 16) & 255;
+ pcm += 32;
+ }
+}
+/*------------------------------------------------------------*/
+void sbtB16_dual_mono(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct16_dual_mono(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB16(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+void sbtB16_dual_left(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct16_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB16(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+void sbtB16_dual_right(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ sample++;
+ for (i = 0; i < n; i++)
+ {
+ fdct16_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB16(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+/*---------------- 8 pt sbt's -------------------------------*/
+/*------------------------------------------------------------*/
+void sbtB8_mono(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct8(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB8(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+
+}
+/*------------------------------------------------------------*/
+void sbtB8_dual(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct8_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ fdct8_dual(m,sample + 1, m->csbt.vbuf2 + m->csbt.vb_ptr);
+ windowB8_dual(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ windowB8_dual(m,m->csbt.vbuf2, m->csbt.vb_ptr, pcm + 1);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 8) & 127;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+void sbtB8_dual_mono(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct8_dual_mono(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB8(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+}
+/*------------------------------------------------------------*/
+void sbtB8_dual_left(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ fdct8_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB8(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+}
+/*------------------------------------------------------------*/
+void sbtB8_dual_right(MPEG *m, float *sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ sample++;
+ for (i = 0; i < n; i++)
+ {
+ fdct8_dual(m,sample, m->csbt.vbuf + m->csbt.vb_ptr);
+ windowB8(m,m->csbt.vbuf, m->csbt.vb_ptr, pcm);
+ sample += 64;
+ m->csbt.vb_ptr = (m->csbt.vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+}
+/*------------------------------------------------------------*/
diff --git a/codecs/mp3/src/cupini.c b/codecs/mp3/src/cupini.c
new file mode 100755
index 000000000..5775a86bd
--- /dev/null
+++ b/codecs/mp3/src/cupini.c
@@ -0,0 +1,421 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/*=========================================================
+ initialization for cup.c - include to cup.c
+ mpeg audio decoder portable "c"
+
+mod 8/6/96 add 8 bit output
+
+mod 5/10/95 add quick (low precision) window
+
+mod 5/16/95 sb limit for reduced samprate output
+ changed from 94% to 100% of Nyquist sb
+
+mod 11/15/95 for Layer I
+
+
+=========================================================*/
+/*-- compiler bug, floating constant overflow w/ansi --*/
+#ifdef _MSC_VER
+#pragma warning(disable:4056)
+#endif
+
+
+
+/* Read Only */
+static long steps[18] =
+{
+ 0, 3, 5, 7, 9, 15, 31, 63, 127,
+ 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535};
+
+
+/* ABCD_INDEX = lookqt[mode][sr_index][br_index] */
+/* -1 = invalid */
+/* Read Only */
+static signed char lookqt[4][3][16] =
+{
+ {{1, -1, -1, -1, 2, -1, 2, 0, 0, 0, 1, 1, 1, 1, 1, -1}, /* 44ks stereo */
+ {0, -1, -1, -1, 2, -1, 2, 0, 0, 0, 0, 0, 0, 0, 0, -1}, /* 48ks */
+ {1, -1, -1, -1, 3, -1, 3, 0, 0, 0, 1, 1, 1, 1, 1, -1}}, /* 32ks */
+ {{1, -1, -1, -1, 2, -1, 2, 0, 0, 0, 1, 1, 1, 1, 1, -1}, /* 44ks joint stereo */
+ {0, -1, -1, -1, 2, -1, 2, 0, 0, 0, 0, 0, 0, 0, 0, -1}, /* 48ks */
+ {1, -1, -1, -1, 3, -1, 3, 0, 0, 0, 1, 1, 1, 1, 1, -1}}, /* 32ks */
+ {{1, -1, -1, -1, 2, -1, 2, 0, 0, 0, 1, 1, 1, 1, 1, -1}, /* 44ks dual chan */
+ {0, -1, -1, -1, 2, -1, 2, 0, 0, 0, 0, 0, 0, 0, 0, -1}, /* 48ks */
+ {1, -1, -1, -1, 3, -1, 3, 0, 0, 0, 1, 1, 1, 1, 1, -1}}, /* 32ks */
+// mono extended beyond legal br index
+// 1,2,2,0,0,0,1,1,1,1,1,1,1,1,1,-1, /* 44ks single chan */
+// 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,-1, /* 48ks */
+// 1,3,3,0,0,0,1,1,1,1,1,1,1,1,1,-1, /* 32ks */
+// legal mono
+ {{1, 2, 2, 0, 0, 0, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1}, /* 44ks single chan */
+ {0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1}, /* 48ks */
+ {1, 3, 3, 0, 0, 0, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1}}, /* 32ks */
+};
+/* Read Only */
+static long sr_table[8] =
+{22050L, 24000L, 16000L, 1L,
+ 44100L, 48000L, 32000L, 1L};
+
+/* bit allocation table look up */
+/* table per mpeg spec tables 3b2a/b/c/d /e is mpeg2 */
+/* look_bat[abcd_index][4][16] */
+/* Read Only */
+static unsigned char look_bat[5][4][16] =
+{
+/* LOOK_BATA */
+ {{0, 1, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17},
+ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17},
+ {0, 1, 2, 3, 4, 5, 6, 17, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 1, 2, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+/* LOOK_BATB */
+ {{0, 1, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17},
+ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17},
+ {0, 1, 2, 3, 4, 5, 6, 17, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 1, 2, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+/* LOOK_BATC */
+ {{0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 1, 2, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+/* LOOK_BATD */
+ {{0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 1, 2, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+/* LOOK_BATE */
+ {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 1, 2, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+};
+
+/* look_nbat[abcd_index]][4] */
+/* Read Only */
+static unsigned char look_nbat[5][4] =
+{
+ {3, 8, 12, 4},
+ {3, 8, 12, 7},
+ {2, 0, 6, 0},
+ {2, 0, 10, 0},
+ {4, 0, 7, 19},
+};
+
+
+void sbt_mono(MPEG *m, float *sample, short *pcm, int n);
+void sbt_dual(MPEG *m, float *sample, short *pcm, int n);
+void sbt_dual_mono(MPEG *m, float *sample, short *pcm, int n);
+void sbt_dual_left(MPEG *m, float *sample, short *pcm, int n);
+void sbt_dual_right(MPEG *m, float *sample, short *pcm, int n);
+void sbt16_mono(MPEG *m, float *sample, short *pcm, int n);
+void sbt16_dual(MPEG *m, float *sample, short *pcm, int n);
+void sbt16_dual_mono(MPEG *m, float *sample, short *pcm, int n);
+void sbt16_dual_left(MPEG *m, float *sample, short *pcm, int n);
+void sbt16_dual_right(MPEG *m, float *sample, short *pcm, int n);
+void sbt8_mono(MPEG *m, float *sample, short *pcm, int n);
+void sbt8_dual(MPEG *m, float *sample, short *pcm, int n);
+void sbt8_dual_mono(MPEG *m, float *sample, short *pcm, int n);
+void sbt8_dual_left(MPEG *m, float *sample, short *pcm, int n);
+void sbt8_dual_right(MPEG *m, float *sample, short *pcm, int n);
+
+/*--- 8 bit output ---*/
+void sbtB_mono(MPEG *m, float *sample, unsigned char *pcm, int n);
+void sbtB_dual(MPEG *m, float *sample, unsigned char *pcm, int n);
+void sbtB_dual_mono(MPEG *m, float *sample, unsigned char *pcm, int n);
+void sbtB_dual_left(MPEG *m, float *sample, unsigned char *pcm, int n);
+void sbtB_dual_right(MPEG *m, float *sample, unsigned char *pcm, int n);
+void sbtB16_mono(MPEG *m, float *sample, unsigned char *pcm, int n);
+void sbtB16_dual(MPEG *m, float *sample, unsigned char *pcm, int n);
+void sbtB16_dual_mono(MPEG *m, float *sample, unsigned char *pcm, int n);
+void sbtB16_dual_left(MPEG *m, float *sample, unsigned char *pcm, int n);
+void sbtB16_dual_right(MPEG *m, float *sample, unsigned char *pcm, int n);
+void sbtB8_mono(MPEG *m, float *sample, unsigned char *pcm, int n);
+void sbtB8_dual(MPEG *m, float *sample, unsigned char *pcm, int n);
+void sbtB8_dual_mono(MPEG *m, float *sample, unsigned char *pcm, int n);
+void sbtB8_dual_left(MPEG *m, float *sample, unsigned char *pcm, int n);
+void sbtB8_dual_right(MPEG *m, float *sample, unsigned char *pcm, int n);
+
+
+static SBT_FUNCTION_F sbt_table[2][3][5] =
+{
+ {{sbt_mono, sbt_dual, sbt_dual_mono, sbt_dual_left, sbt_dual_right},
+ {sbt16_mono, sbt16_dual, sbt16_dual_mono, sbt16_dual_left, sbt16_dual_right},
+ {sbt8_mono, sbt8_dual, sbt8_dual_mono, sbt8_dual_left, sbt8_dual_right}},
+ {{(SBT_FUNCTION_F) sbtB_mono,
+ (SBT_FUNCTION_F) sbtB_dual,
+ (SBT_FUNCTION_F) sbtB_dual_mono,
+ (SBT_FUNCTION_F) sbtB_dual_left,
+ (SBT_FUNCTION_F) sbtB_dual_right},
+ {(SBT_FUNCTION_F) sbtB16_mono,
+ (SBT_FUNCTION_F) sbtB16_dual,
+ (SBT_FUNCTION_F) sbtB16_dual_mono,
+ (SBT_FUNCTION_F) sbtB16_dual_left,
+ (SBT_FUNCTION_F) sbtB16_dual_right},
+ {(SBT_FUNCTION_F) sbtB8_mono,
+ (SBT_FUNCTION_F) sbtB8_dual,
+ (SBT_FUNCTION_F) sbtB8_dual_mono,
+ (SBT_FUNCTION_F) sbtB8_dual_left,
+ (SBT_FUNCTION_F) sbtB8_dual_right}},
+};
+
+static int out_chans[5] =
+{1, 2, 1, 1, 1};
+
+
+int audio_decode_initL1(MPEG_HEAD * h, int framebytes_arg,
+ int reduction_code, int transform_code, int convert_code,
+ int freq_limit);
+void sbt_init();
+
+
+IN_OUT L1audio_decode(void *mv, unsigned char *bs, signed short *pcm);
+IN_OUT L2audio_decode(void *mv, unsigned char *bs, signed short *pcm);
+IN_OUT L3audio_decode(void *mv, unsigned char *bs, unsigned char *pcm);
+static AUDIO_DECODE_ROUTINE decode_routine_table[4] =
+{
+ L2audio_decode,
+ (AUDIO_DECODE_ROUTINE)L3audio_decode,
+ L2audio_decode,
+ L1audio_decode,};
+
+extern void cup3_init(MPEG *m);
+
+void mpeg_init(MPEG *m)
+{
+ memset(m, 0, sizeof(MPEG));
+ m->cup.nsb_limit = 6;
+ m->cup.nbat[0] = 3;
+ m->cup.nbat[1] = 8;
+ m->cup.nbat[3] = 12;
+ m->cup.nbat[4] = 7;
+ m->cup.sbt = sbt_mono;
+ m->cup.first_pass = 1;
+ m->cup.first_pass_L1 = 1;
+ m->cup.audio_decode_routine = L2audio_decode;
+ m->cup.cs_factorL1 = m->cup.cs_factor[0];
+ m->cup.nbatL1 = 32;
+ m->cupl.band_limit = 576;
+ m->cupl.band_limit21 = 567;
+ m->cupl.band_limit12 = 576;
+ m->cupl.band_limit_nsb = 32;
+ m->cupl.nsb_limit=32;
+ m->cup.sample = (float *)&m->cupl.sample;
+ m->csbt.first_pass = 1;
+ cup3_init(m);
+}
+
+/*---------------------------------------------------------*/
+static void table_init(MPEG *m)
+{
+ int i, j;
+ int code;
+
+/*-- c_values (dequant) --*/
+ for (i = 1; i < 18; i++)
+ m->cup.look_c_value[i] = 2.0F / steps[i];
+
+/*-- scale factor table, scale by 32768 for 16 pcm output --*/
+ for (i = 0; i < 64; i++)
+ m->cup.sf_table[i] = (float) (32768.0 * 2.0 * pow(2.0, -i / 3.0));
+
+/*-- grouped 3 level lookup table 5 bit token --*/
+ for (i = 0; i < 32; i++)
+ {
+ code = i;
+ for (j = 0; j < 3; j++)
+ {
+ m->cup.group3_table[i][j] = (char) ((code % 3) - 1);
+ code /= 3;
+ }
+ }
+/*-- grouped 5 level lookup table 7 bit token --*/
+ for (i = 0; i < 128; i++)
+ {
+ code = i;
+ for (j = 0; j < 3; j++)
+ {
+ m->cup.group5_table[i][j] = (char) ((code % 5) - 2);
+ code /= 5;
+ }
+ }
+/*-- grouped 9 level lookup table 10 bit token --*/
+ for (i = 0; i < 1024; i++)
+ {
+ code = i;
+ for (j = 0; j < 3; j++)
+ {
+ m->cup.group9_table[i][j] = (short) ((code % 9) - 4);
+ code /= 9;
+ }
+ }
+
+
+}
+/*---------------------------------------------------------*/
+int L1audio_decode_init(MPEG *m, MPEG_HEAD * h, int framebytes_arg,
+ int reduction_code, int transform_code, int convert_code,
+ int freq_limit);
+int L3audio_decode_init(MPEG *m, MPEG_HEAD * h, int framebytes_arg,
+ int reduction_code, int transform_code, int convert_code,
+ int freq_limit);
+
+/*---------------------------------------------------------*/
+/* mpeg_head defined in mhead.h frame bytes is without pad */
+int audio_decode_init(MPEG *m, MPEG_HEAD * h, int framebytes_arg,
+ int reduction_code, int transform_code, int convert_code,
+ int freq_limit)
+{
+ int i, j, k;
+ int abcd_index;
+ long samprate;
+ int limit;
+ int bit_code;
+
+ if (m->cup.first_pass)
+ {
+ table_init(m);
+ m->cup.first_pass = 0;
+ }
+
+/* select decoder routine Layer I,II,III */
+ m->cup.audio_decode_routine = decode_routine_table[h->option & 3];
+
+
+ if (h->option == 3) /* layer I */
+ return L1audio_decode_init(m, h, framebytes_arg,
+ reduction_code, transform_code, convert_code, freq_limit);
+
+ if (h->option == 1) /* layer III */
+ return L3audio_decode_init(m, h, framebytes_arg,
+ reduction_code, transform_code, convert_code, freq_limit);
+
+
+
+ transform_code = transform_code; /* not used, asm compatability */
+ bit_code = 0;
+ if (convert_code & 8)
+ bit_code = 1;
+ convert_code = convert_code & 3; /* higher bits used by dec8 freq cvt */
+ if (reduction_code < 0)
+ reduction_code = 0;
+ if (reduction_code > 2)
+ reduction_code = 2;
+ if (freq_limit < 1000)
+ freq_limit = 1000;
+
+
+ m->cup.framebytes = framebytes_arg;
+/* check if code handles */
+ if (h->option != 2)
+ return 0; /* layer II only */
+ if (h->sr_index == 3)
+ return 0; /* reserved */
+
+/* compute abcd index for bit allo table selection */
+ if (h->id) /* mpeg 1 */
+ abcd_index = lookqt[h->mode][h->sr_index][h->br_index];
+ else
+ abcd_index = 4; /* mpeg 2 */
+
+ if (abcd_index < 0)
+ return 0; // fail invalid Layer II bit rate index
+
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 16; j++)
+ m->cup.bat[i][j] = look_bat[abcd_index][i][j];
+ for (i = 0; i < 4; i++)
+ m->cup.nbat[i] = look_nbat[abcd_index][i];
+ m->cup.max_sb = m->cup.nbat[0] + m->cup.nbat[1] + m->cup.nbat[2] + m->cup.nbat[3];
+/*----- compute nsb_limit --------*/
+ samprate = sr_table[4 * h->id + h->sr_index];
+ m->cup.nsb_limit = (freq_limit * 64L + samprate / 2) / samprate;
+/*- caller limit -*/
+/*---- limit = 0.94*(32>>reduction_code); ----*/
+ limit = (32 >> reduction_code);
+ if (limit > 8)
+ limit--;
+ if (m->cup.nsb_limit > limit)
+ m->cup.nsb_limit = limit;
+ if (m->cup.nsb_limit > m->cup.max_sb)
+ m->cup.nsb_limit = m->cup.max_sb;
+
+ m->cup.outvalues = 1152 >> reduction_code;
+ if (h->mode != 3)
+ { /* adjust for 2 channel modes */
+ for (i = 0; i < 4; i++)
+ m->cup.nbat[i] *= 2;
+ m->cup.max_sb *= 2;
+ m->cup.nsb_limit *= 2;
+ }
+
+/* set sbt function */
+ k = 1 + convert_code;
+ if (h->mode == 3)
+ {
+ k = 0;
+ }
+ m->cup.sbt = sbt_table[bit_code][reduction_code][k];
+ m->cup.outvalues *= out_chans[k];
+ if (bit_code)
+ m->cup.outbytes = m->cup.outvalues;
+ else
+ m->cup.outbytes = sizeof(short) * m->cup.outvalues;
+
+ m->cup.decinfo.channels = out_chans[k];
+ m->cup.decinfo.outvalues = m->cup.outvalues;
+ m->cup.decinfo.samprate = samprate >> reduction_code;
+ if (bit_code)
+ m->cup.decinfo.bits = 8;
+ else
+ m->cup.decinfo.bits = sizeof(short) * 8;
+
+ m->cup.decinfo.framebytes = m->cup.framebytes;
+ m->cup.decinfo.type = 0;
+
+
+
+/* clear sample buffer, unused sub bands must be 0 */
+ for (i = 0; i < 2304; i++)
+ m->cup.sample[i] = 0.0F;
+
+
+/* init sub-band transform */
+ sbt_init();
+
+ return 1;
+}
+/*---------------------------------------------------------*/
+void audio_decode_info(MPEG *m, DEC_INFO * info)
+{
+ *info = m->cup.decinfo; /* info return, call after init */
+}
+/*---------------------------------------------------------*/
+void decode_table_init(MPEG *m)
+{
+/* dummy for asm version compatability */
+}
+/*---------------------------------------------------------*/
diff --git a/codecs/mp3/src/cupl3.c b/codecs/mp3/src/cupl3.c
new file mode 100755
index 000000000..7d387b65d
--- /dev/null
+++ b/codecs/mp3/src/cupl3.c
@@ -0,0 +1,1189 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** cupL3.c ***************************************************
+unpack Layer III
+
+
+mod 8/18/97 bugfix crc problem
+
+mod 10/9/97 add band_limit12 for short blocks
+
+mod 10/22/97 zero buf_ptrs in init
+
+mod 5/15/98 mpeg 2.5
+
+mod 8/19/98 decode 22 sf bands
+
+******************************************************************/
+
+/*---------------------------------------
+TO DO: Test mixed blocks (mixed long/short)
+ No mixed blocks in mpeg-1 test stream being used for development
+
+-----------------------------------------*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#include <memory.h>
+#include <string.h>
+#include <assert.h>
+#include "L3.h"
+#include "mhead.h" /* mpeg header structure */
+#include "jdw.h"
+#include "protos.h"
+
+
+/*====================================================================*/
+static int mp_sr20_table[2][4] =
+{{441, 480, 320, -999}, {882, 960, 640, -999}};
+static int mp_br_tableL3[2][16] =
+{{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0}, /* mpeg 2 */
+ {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0}};
+
+/*====================================================================*/
+
+/*-- global band tables */
+/*-- short portion is 3*x !! --*/
+
+/*====================================================================*/
+
+/*---------------------------------*/
+/*---------------------------------*/
+/*- sample union of int/float sample[ch][gr][576] */
+/* Sample is the same as cup.sample */
+
+void sbt_dual_L3(MPEG *m, float *sample, short *pcm, int n);
+
+IN_OUT L3audio_decode_MPEG1(void *mv, unsigned char *bs, unsigned char *pcm);
+IN_OUT L3audio_decode_MPEG2(void *mv, unsigned char *bs, unsigned char *pcm);
+/*
+static DECODE_FUNCTION decode_function = L3audio_decode_MPEG1;
+*/
+
+/*====================================================================*/
+/* get bits from bitstream in endian independent way */
+
+BITDAT bitdat; /* global for inline use by Huff */
+
+/*------------- initialize bit getter -------------*/
+static void bitget_init(unsigned char *buf)
+{
+ bitdat.bs_ptr0 = bitdat.bs_ptr = buf;
+ bitdat.bits = 0;
+ bitdat.bitbuf = 0;
+}
+/*------------- initialize bit getter -------------*/
+static void bitget_init_end(unsigned char *buf_end)
+{
+ bitdat.bs_ptr_end = buf_end;
+}
+/*------------- get n bits from bitstream -------------*/
+int bitget_bits_used()
+{
+ int n; /* compute bits used from last init call */
+
+ n = ((bitdat.bs_ptr - bitdat.bs_ptr0) << 3) - bitdat.bits;
+ return n;
+}
+/*------------- check for n bits in bitbuf -------------*/
+void bitget_check(int n)
+{
+ if (bitdat.bits < n)
+ {
+ while (bitdat.bits <= 24)
+ {
+ bitdat.bitbuf = (bitdat.bitbuf << 8) | *bitdat.bs_ptr++;
+ bitdat.bits += 8;
+ }
+ }
+}
+/*------------- get n bits from bitstream -------------*/
+unsigned int bitget(int n)
+{
+ unsigned int x;
+
+ if (bitdat.bits < n)
+ { /* refill bit buf if necessary */
+ while (bitdat.bits <= 24)
+ {
+ bitdat.bitbuf = (bitdat.bitbuf << 8) | *bitdat.bs_ptr++;
+ bitdat.bits += 8;
+ }
+ }
+ bitdat.bits -= n;
+ x = bitdat.bitbuf >> bitdat.bits;
+ bitdat.bitbuf -= x << bitdat.bits;
+ return x;
+}
+/*------------- get 1 bit from bitstream -------------*/
+unsigned int bitget_1bit()
+{
+ unsigned int x;
+
+ if (bitdat.bits <= 0)
+ { /* refill bit buf if necessary */
+ while (bitdat.bits <= 24)
+ {
+ bitdat.bitbuf = (bitdat.bitbuf << 8) | *bitdat.bs_ptr++;
+ bitdat.bits += 8;
+ }
+ }
+ bitdat.bits--;
+ x = bitdat.bitbuf >> bitdat.bits;
+ bitdat.bitbuf -= x << bitdat.bits;
+ return x;
+}
+/*====================================================================*/
+static void Xform_mono(void *mv, void *pcm, int igr)
+{
+ MPEG *m = mv;
+ int igr_prev, n1, n2;
+
+/*--- hybrid + sbt ---*/
+ n1 = n2 = m->cupl.nsamp[igr][0]; /* total number bands */
+ if (m->cupl.side_info.gr[igr][0].block_type == 2)
+ { /* long bands */
+ n1 = 0;
+ if (m->cupl.side_info.gr[igr][0].mixed_block_flag)
+ n1 = m->cupl.sfBandIndex[0][m->cupl.ncbl_mixed - 1];
+ }
+ if (n1 > m->cupl.band_limit)
+ n1 = m->cupl.band_limit;
+ if (n2 > m->cupl.band_limit)
+ n2 = m->cupl.band_limit;
+ igr_prev = igr ^ 1;
+
+ m->cupl.nsamp[igr][0] = hybrid(m,m->cupl.sample[0][igr], m->cupl.sample[0][igr_prev],
+ m->cupl.yout, m->cupl.side_info.gr[igr][0].block_type, n1, n2, m->cupl.nsamp[igr_prev][0]);
+ FreqInvert(m->cupl.yout, m->cupl.nsamp[igr][0]);
+ m->cupl.sbt_L3(m,m->cupl.yout, pcm, 0);
+
+}
+
+/*--------------------------------------------------------------------*/
+static void Xform_dual_right(void *mv, void *pcm, int igr)
+{
+ MPEG *m = mv;
+ int igr_prev, n1, n2;
+
+/*--- hybrid + sbt ---*/
+ n1 = n2 = m->cupl.nsamp[igr][1]; /* total number bands */
+ if (m->cupl.side_info.gr[igr][1].block_type == 2)
+ { /* long bands */
+ n1 = 0;
+ if (m->cupl.side_info.gr[igr][1].mixed_block_flag)
+ n1 = m->cupl.sfBandIndex[0][m->cupl.ncbl_mixed - 1];
+ }
+ if (n1 > m->cupl.band_limit)
+ n1 = m->cupl.band_limit;
+ if (n2 > m->cupl.band_limit)
+ n2 = m->cupl.band_limit;
+ igr_prev = igr ^ 1;
+ m->cupl.nsamp[igr][1] = hybrid(m,m->cupl.sample[1][igr], m->cupl.sample[1][igr_prev],
+ m->cupl.yout, m->cupl.side_info.gr[igr][1].block_type, n1, n2, m->cupl.nsamp[igr_prev][1]);
+ FreqInvert(m->cupl.yout, m->cupl.nsamp[igr][1]);
+ m->cupl.sbt_L3(m,m->cupl.yout, pcm, 0);
+
+}
+/*--------------------------------------------------------------------*/
+static void Xform_dual(void *mv, void *pcm, int igr)
+{
+ MPEG *m = mv;
+ int ch;
+ int igr_prev, n1, n2;
+
+/*--- hybrid + sbt ---*/
+ igr_prev = igr ^ 1;
+ for (ch = 0; ch < m->cupl.nchan; ch++)
+ {
+ n1 = n2 = m->cupl.nsamp[igr][ch]; /* total number bands */
+ if (m->cupl.side_info.gr[igr][ch].block_type == 2)
+ { /* long bands */
+ n1 = 0;
+ if (m->cupl.side_info.gr[igr][ch].mixed_block_flag)
+ n1 = m->cupl.sfBandIndex[0][m->cupl.ncbl_mixed - 1];
+ }
+ if (n1 > m->cupl.band_limit)
+ n1 = m->cupl.band_limit;
+ if (n2 > m->cupl.band_limit)
+ n2 = m->cupl.band_limit;
+ m->cupl.nsamp[igr][ch] = hybrid(m,m->cupl.sample[ch][igr], m->cupl.sample[ch][igr_prev],
+ m->cupl.yout, m->cupl.side_info.gr[igr][ch].block_type, n1, n2, m->cupl.nsamp[igr_prev][ch]);
+ FreqInvert(m->cupl.yout, m->cupl.nsamp[igr][ch]);
+ m->cupl.sbt_L3(m,m->cupl.yout, pcm, ch);
+ }
+
+}
+/*--------------------------------------------------------------------*/
+static void Xform_dual_mono(void *mv, void *pcm, int igr)
+{
+ MPEG *m = mv;
+ int igr_prev, n1, n2, n3;
+
+/*--- hybrid + sbt ---*/
+ igr_prev = igr ^ 1;
+ if ((m->cupl.side_info.gr[igr][0].block_type == m->cupl.side_info.gr[igr][1].block_type)
+ && (m->cupl.side_info.gr[igr][0].mixed_block_flag == 0)
+ && (m->cupl.side_info.gr[igr][1].mixed_block_flag == 0))
+ {
+
+ n2 = m->cupl.nsamp[igr][0]; /* total number bands max of L R */
+ if (n2 < m->cupl.nsamp[igr][1])
+ n2 = m->cupl.nsamp[igr][1];
+ if (n2 > m->cupl.band_limit)
+ n2 = m->cupl.band_limit;
+ n1 = n2; /* n1 = number long bands */
+ if (m->cupl.side_info.gr[igr][0].block_type == 2)
+ n1 = 0;
+ sum_f_bands(m->cupl.sample[0][igr], m->cupl.sample[1][igr], n2);
+ n3 = m->cupl.nsamp[igr][0] = hybrid(m,m->cupl.sample[0][igr], m->cupl.sample[0][igr_prev],
+ m->cupl.yout, m->cupl.side_info.gr[igr][0].block_type, n1, n2, m->cupl.nsamp[igr_prev][0]);
+ }
+ else
+ { /* transform and then sum (not tested - never happens in test) */
+/*-- left chan --*/
+ n1 = n2 = m->cupl.nsamp[igr][0]; /* total number bands */
+ if (m->cupl.side_info.gr[igr][0].block_type == 2)
+ {
+ n1 = 0; /* long bands */
+ if (m->cupl.side_info.gr[igr][0].mixed_block_flag)
+ n1 = m->cupl.sfBandIndex[0][m->cupl.ncbl_mixed - 1];
+ }
+ n3 = m->cupl.nsamp[igr][0] = hybrid(m,m->cupl.sample[0][igr], m->cupl.sample[0][igr_prev],
+ m->cupl.yout, m->cupl.side_info.gr[igr][0].block_type, n1, n2, m->cupl.nsamp[igr_prev][0]);
+/*-- right chan --*/
+ n1 = n2 = m->cupl.nsamp[igr][1]; /* total number bands */
+ if (m->cupl.side_info.gr[igr][1].block_type == 2)
+ {
+ n1 = 0; /* long bands */
+ if (m->cupl.side_info.gr[igr][1].mixed_block_flag)
+ n1 = m->cupl.sfBandIndex[0][m->cupl.ncbl_mixed - 1];
+ }
+ m->cupl.nsamp[igr][1] = hybrid_sum(m, m->cupl.sample[1][igr], m->cupl.sample[0][igr],
+ m->cupl.yout, m->cupl.side_info.gr[igr][1].block_type, n1, n2);
+ if (n3 < m->cupl.nsamp[igr][1])
+ n1 = m->cupl.nsamp[igr][1];
+ }
+
+/*--------*/
+ FreqInvert(m->cupl.yout, n3);
+ m->cupl.sbt_L3(m,m->cupl.yout, pcm, 0);
+
+}
+/*--------------------------------------------------------------------*/
+/*====================================================================*/
+static int unpack_side_MPEG1(MPEG *m)
+{
+ int prot;
+ int br_index;
+ int igr, ch;
+ int side_bytes;
+
+/* decode partial header plus initial side info */
+/* at entry bit getter points at id, sync skipped by caller */
+
+ m->cupl.id = bitget(1); /* id */
+ bitget(2); /* skip layer */
+ prot = bitget(1); /* bitget prot bit */
+ br_index = bitget(4);
+ m->cupl.sr_index = bitget(2);
+ m->cupl.pad = bitget(1);
+ bitget(1); /* skip to mode */
+ m->cupl.side_info.mode = bitget(2); /* mode */
+ m->cupl.side_info.mode_ext = bitget(2); /* mode ext */
+
+ if (m->cupl.side_info.mode != 1)
+ m->cupl.side_info.mode_ext = 0;
+
+/* adjust global gain in ms mode to avoid having to mult by 1/sqrt(2) */
+ m->cupl.ms_mode = m->cupl.side_info.mode_ext >> 1;
+ m->cupl.is_mode = m->cupl.side_info.mode_ext & 1;
+
+
+ m->cupl.crcbytes = 0;
+ if (prot)
+ bitget(4); /* skip to data */
+ else
+ {
+ bitget(20); /* skip crc */
+ m->cupl.crcbytes = 2;
+ }
+
+ if (br_index > 0) /* framebytes fixed for free format */
+ {
+ m->cupl.framebytes =
+ 2880 * mp_br_tableL3[m->cupl.id][br_index] / mp_sr20_table[m->cupl.id][m->cupl.sr_index];
+ }
+
+ m->cupl.side_info.main_data_begin = bitget(9);
+ if (m->cupl.side_info.mode == 3)
+ {
+ m->cupl.side_info.private_bits = bitget(5);
+ m->cupl.nchan = 1;
+ m->cupl.stereo_flag = 0;
+ side_bytes = (4 + 17);
+/*-- with header --*/
+ }
+ else
+ {
+ m->cupl.side_info.private_bits = bitget(3);
+ m->cupl.nchan = 2;
+ m->cupl.stereo_flag = 1;
+ side_bytes = (4 + 32);
+/*-- with header --*/
+ }
+ for (ch = 0; ch < m->cupl.nchan; ch++)
+ m->cupl.side_info.scfsi[ch] = bitget(4);
+/* this always 0 (both igr) for short blocks */
+
+ for (igr = 0; igr < 2; igr++)
+ {
+ for (ch = 0; ch < m->cupl.nchan; ch++)
+ {
+ m->cupl.side_info.gr[igr][ch].part2_3_length = bitget(12);
+ m->cupl.side_info.gr[igr][ch].big_values = bitget(9);
+ m->cupl.side_info.gr[igr][ch].global_gain = bitget(8) + m->cupl.gain_adjust;
+ if (m->cupl.ms_mode)
+ m->cupl.side_info.gr[igr][ch].global_gain -= 2;
+ m->cupl.side_info.gr[igr][ch].scalefac_compress = bitget(4);
+ m->cupl.side_info.gr[igr][ch].window_switching_flag = bitget(1);
+ if (m->cupl.side_info.gr[igr][ch].window_switching_flag)
+ {
+ m->cupl.side_info.gr[igr][ch].block_type = bitget(2);
+ m->cupl.side_info.gr[igr][ch].mixed_block_flag = bitget(1);
+ m->cupl.side_info.gr[igr][ch].table_select[0] = bitget(5);
+ m->cupl.side_info.gr[igr][ch].table_select[1] = bitget(5);
+ m->cupl.side_info.gr[igr][ch].subblock_gain[0] = bitget(3);
+ m->cupl.side_info.gr[igr][ch].subblock_gain[1] = bitget(3);
+ m->cupl.side_info.gr[igr][ch].subblock_gain[2] = bitget(3);
+ /* region count set in terms of long block cb's/bands */
+ /* r1 set so r0+r1+1 = 21 (lookup produces 576 bands ) */
+ /* if(window_switching_flag) always 36 samples in region0 */
+ m->cupl.side_info.gr[igr][ch].region0_count = (8 - 1); /* 36 samples */
+ m->cupl.side_info.gr[igr][ch].region1_count = 20 - (8 - 1);
+ }
+ else
+ {
+ m->cupl.side_info.gr[igr][ch].mixed_block_flag = 0;
+ m->cupl.side_info.gr[igr][ch].block_type = 0;
+ m->cupl.side_info.gr[igr][ch].table_select[0] = bitget(5);
+ m->cupl.side_info.gr[igr][ch].table_select[1] = bitget(5);
+ m->cupl.side_info.gr[igr][ch].table_select[2] = bitget(5);
+ m->cupl.side_info.gr[igr][ch].region0_count = bitget(4);
+ m->cupl.side_info.gr[igr][ch].region1_count = bitget(3);
+ }
+ m->cupl.side_info.gr[igr][ch].preflag = bitget(1);
+ m->cupl.side_info.gr[igr][ch].scalefac_scale = bitget(1);
+ m->cupl.side_info.gr[igr][ch].count1table_select = bitget(1);
+ }
+ }
+
+
+
+/* return bytes in header + side info */
+ return side_bytes;
+}
+/*====================================================================*/
+static int unpack_side_MPEG2(MPEG *m, int igr)
+{
+ int prot;
+ int br_index;
+ int ch;
+ int side_bytes;
+
+/* decode partial header plus initial side info */
+/* at entry bit getter points at id, sync skipped by caller */
+
+ m->cupl.id = bitget(1); /* id */
+ bitget(2); /* skip layer */
+ prot = bitget(1); /* bitget prot bit */
+ br_index = bitget(4);
+ m->cupl.sr_index = bitget(2);
+ m->cupl.pad = bitget(1);
+ bitget(1); /* skip to mode */
+ m->cupl.side_info.mode = bitget(2); /* mode */
+ m->cupl.side_info.mode_ext = bitget(2); /* mode ext */
+
+ if (m->cupl.side_info.mode != 1)
+ m->cupl.side_info.mode_ext = 0;
+
+/* adjust global gain in ms mode to avoid having to mult by 1/sqrt(2) */
+ m->cupl.ms_mode = m->cupl.side_info.mode_ext >> 1;
+ m->cupl.is_mode = m->cupl.side_info.mode_ext & 1;
+
+ m->cupl.crcbytes = 0;
+ if (prot)
+ bitget(4); /* skip to data */
+ else
+ {
+ bitget(20); /* skip crc */
+ m->cupl.crcbytes = 2;
+ }
+
+ if (br_index > 0)
+ { /* framebytes fixed for free format */
+ if (m->cupl.mpeg25_flag == 0)
+ {
+ m->cupl.framebytes =
+ 1440 * mp_br_tableL3[m->cupl.id][br_index] / mp_sr20_table[m->cupl.id][m->cupl.sr_index];
+ }
+ else
+ {
+ m->cupl.framebytes =
+ 2880 * mp_br_tableL3[m->cupl.id][br_index] / mp_sr20_table[m->cupl.id][m->cupl.sr_index];
+ //if( sr_index == 2 ) return 0; // fail mpeg25 8khz
+ }
+ }
+ m->cupl.side_info.main_data_begin = bitget(8);
+ if (m->cupl.side_info.mode == 3)
+ {
+ m->cupl.side_info.private_bits = bitget(1);
+ m->cupl.nchan = 1;
+ m->cupl.stereo_flag = 0;
+ side_bytes = (4 + 9);
+/*-- with header --*/
+ }
+ else
+ {
+ m->cupl.side_info.private_bits = bitget(2);
+ m->cupl.nchan = 2;
+ m->cupl.stereo_flag = 1;
+ side_bytes = (4 + 17);
+/*-- with header --*/
+ }
+ m->cupl.side_info.scfsi[1] = m->cupl.side_info.scfsi[0] = 0;
+
+
+ for (ch = 0; ch < m->cupl.nchan; ch++)
+ {
+ m->cupl.side_info.gr[igr][ch].part2_3_length = bitget(12);
+ m->cupl.side_info.gr[igr][ch].big_values = bitget(9);
+ m->cupl.side_info.gr[igr][ch].global_gain = bitget(8) + m->cupl.gain_adjust;
+ if (m->cupl.ms_mode)
+ m->cupl.side_info.gr[igr][ch].global_gain -= 2;
+ m->cupl.side_info.gr[igr][ch].scalefac_compress = bitget(9);
+ m->cupl.side_info.gr[igr][ch].window_switching_flag = bitget(1);
+ if (m->cupl.side_info.gr[igr][ch].window_switching_flag)
+ {
+ m->cupl.side_info.gr[igr][ch].block_type = bitget(2);
+ m->cupl.side_info.gr[igr][ch].mixed_block_flag = bitget(1);
+ m->cupl.side_info.gr[igr][ch].table_select[0] = bitget(5);
+ m->cupl.side_info.gr[igr][ch].table_select[1] = bitget(5);
+ m->cupl.side_info.gr[igr][ch].subblock_gain[0] = bitget(3);
+ m->cupl.side_info.gr[igr][ch].subblock_gain[1] = bitget(3);
+ m->cupl.side_info.gr[igr][ch].subblock_gain[2] = bitget(3);
+ /* region count set in terms of long block cb's/bands */
+ /* r1 set so r0+r1+1 = 21 (lookup produces 576 bands ) */
+ /* bt=1 or 3 54 samples */
+ /* bt=2 mixed=0 36 samples */
+ /* bt=2 mixed=1 54 (8 long sf) samples? or maybe 36 */
+ /* region0 discussion says 54 but this would mix long */
+ /* and short in region0 if scale factors switch */
+ /* at band 36 (6 long scale factors) */
+ if ((m->cupl.side_info.gr[igr][ch].block_type == 2))
+ {
+ m->cupl.side_info.gr[igr][ch].region0_count = (6 - 1); /* 36 samples */
+ m->cupl.side_info.gr[igr][ch].region1_count = 20 - (6 - 1);
+ }
+ else
+ { /* long block type 1 or 3 */
+ m->cupl.side_info.gr[igr][ch].region0_count = (8 - 1); /* 54 samples */
+ m->cupl.side_info.gr[igr][ch].region1_count = 20 - (8 - 1);
+ }
+ }
+ else
+ {
+ m->cupl.side_info.gr[igr][ch].mixed_block_flag = 0;
+ m->cupl.side_info.gr[igr][ch].block_type = 0;
+ m->cupl.side_info.gr[igr][ch].table_select[0] = bitget(5);
+ m->cupl.side_info.gr[igr][ch].table_select[1] = bitget(5);
+ m->cupl.side_info.gr[igr][ch].table_select[2] = bitget(5);
+ m->cupl.side_info.gr[igr][ch].region0_count = bitget(4);
+ m->cupl.side_info.gr[igr][ch].region1_count = bitget(3);
+ }
+ m->cupl.side_info.gr[igr][ch].preflag = 0;
+ m->cupl.side_info.gr[igr][ch].scalefac_scale = bitget(1);
+ m->cupl.side_info.gr[igr][ch].count1table_select = bitget(1);
+ }
+
+/* return bytes in header + side info */
+ return side_bytes;
+}
+/*-----------------------------------------------------------------*/
+static void unpack_main(MPEG *m, unsigned char *pcm, int igr)
+{
+ int ch;
+ int bit0;
+ int n1, n2, n3, n4, nn2, nn3;
+ int nn4;
+ int qbits;
+ int m0;
+
+
+ for (ch = 0; ch < m->cupl.nchan; ch++)
+ {
+ bitget_init(m->cupl.buf + (m->cupl.main_pos_bit >> 3));
+ bit0 = (m->cupl.main_pos_bit & 7);
+ if (bit0)
+ bitget(bit0);
+ m->cupl.main_pos_bit += m->cupl.side_info.gr[igr][ch].part2_3_length;
+ bitget_init_end(m->cupl.buf + ((m->cupl.main_pos_bit + 39) >> 3));
+/*-- scale factors --*/
+ if (m->cupl.id)
+ unpack_sf_sub_MPEG1(&m->cupl.sf[igr][ch],
+ &m->cupl.side_info.gr[igr][ch], m->cupl.side_info.scfsi[ch], igr);
+ else
+ unpack_sf_sub_MPEG2(&m->cupl.sf[igr][ch],
+ &m->cupl.side_info.gr[igr][ch], m->cupl.is_mode & ch, &m->cupl.is_sf_info);
+/*--- huff data ---*/
+ n1 = m->cupl.sfBandIndex[0][m->cupl.side_info.gr[igr][ch].region0_count];
+ n2 = m->cupl.sfBandIndex[0][m->cupl.side_info.gr[igr][ch].region0_count
+ + m->cupl.side_info.gr[igr][ch].region1_count + 1];
+ n3 = m->cupl.side_info.gr[igr][ch].big_values;
+ n3 = n3 + n3;
+
+
+ if (n3 > m->cupl.band_limit)
+ n3 = m->cupl.band_limit;
+ if (n2 > n3)
+ n2 = n3;
+ if (n1 > n3)
+ n1 = n3;
+ nn3 = n3 - n2;
+ nn2 = n2 - n1;
+ unpack_huff(m->cupl.sample[ch][igr], n1, m->cupl.side_info.gr[igr][ch].table_select[0]);
+ unpack_huff(m->cupl.sample[ch][igr] + n1, nn2, m->cupl.side_info.gr[igr][ch].table_select[1]);
+ unpack_huff(m->cupl.sample[ch][igr] + n2, nn3, m->cupl.side_info.gr[igr][ch].table_select[2]);
+ qbits = m->cupl.side_info.gr[igr][ch].part2_3_length - (bitget_bits_used() - bit0);
+ nn4 = unpack_huff_quad(m->cupl.sample[ch][igr] + n3, m->cupl.band_limit - n3, qbits,
+ m->cupl.side_info.gr[igr][ch].count1table_select);
+ n4 = n3 + nn4;
+ m->cupl.nsamp[igr][ch] = n4;
+ //limit n4 or allow deqaunt to sf band 22
+ if (m->cupl.side_info.gr[igr][ch].block_type == 2)
+ n4 = min(n4, m->cupl.band_limit12);
+ else
+ n4 = min(n4, m->cupl.band_limit21);
+ if (n4 < 576)
+ memset(m->cupl.sample[ch][igr] + n4, 0, sizeof(SAMPLE) * (576 - n4));
+ if (bitdat.bs_ptr > bitdat.bs_ptr_end)
+ { // bad data overrun
+
+ memset(m->cupl.sample[ch][igr], 0, sizeof(SAMPLE) * (576));
+ }
+ }
+
+
+
+/*--- dequant ---*/
+ for (ch = 0; ch < m->cupl.nchan; ch++)
+ {
+ dequant(m,m->cupl.sample[ch][igr],
+ &m->cupl.nsamp[igr][ch], /* nsamp updated for shorts */
+ &m->cupl.sf[igr][ch], &m->cupl.side_info.gr[igr][ch],
+ &m->cupl.cb_info[igr][ch], m->cupl.ncbl_mixed);
+ }
+
+/*--- ms stereo processing ---*/
+ if (m->cupl.ms_mode)
+ {
+ if (m->cupl.is_mode == 0)
+ {
+ m0 = m->cupl.nsamp[igr][0]; /* process to longer of left/right */
+ if (m0 < m->cupl.nsamp[igr][1])
+ m0 = m->cupl.nsamp[igr][1];
+ }
+ else
+ { /* process to last cb in right */
+ m0 = m->cupl.sfBandIndex[m->cupl.cb_info[igr][1].cbtype][m->cupl.cb_info[igr][1].cbmax];
+ }
+ ms_process(m->cupl.sample[0][igr], m0);
+ }
+
+/*--- is stereo processing ---*/
+ if (m->cupl.is_mode)
+ {
+ if (m->cupl.id)
+ is_process_MPEG1(m, m->cupl.sample[0][igr], &m->cupl.sf[igr][1],
+ m->cupl.cb_info[igr], m->cupl.nsamp[igr][0], m->cupl.ms_mode);
+ else
+ is_process_MPEG2(m,m->cupl.sample[0][igr], &m->cupl.sf[igr][1],
+ m->cupl.cb_info[igr], &m->cupl.is_sf_info,
+ m->cupl.nsamp[igr][0], m->cupl.ms_mode);
+ }
+
+/*-- adjust ms and is modes to max of left/right */
+ if (m->cupl.side_info.mode_ext)
+ {
+ if (m->cupl.nsamp[igr][0] < m->cupl.nsamp[igr][1])
+ m->cupl.nsamp[igr][0] = m->cupl.nsamp[igr][1];
+ else
+ m->cupl.nsamp[igr][1] = m->cupl.nsamp[igr][0];
+ }
+
+/*--- antialias ---*/
+ for (ch = 0; ch < m->cupl.nchan; ch++)
+ {
+ if (m->cupl.cb_info[igr][ch].ncbl == 0)
+ continue; /* have no long blocks */
+ if (m->cupl.side_info.gr[igr][ch].mixed_block_flag)
+ n1 = 1; /* 1 -> 36 samples */
+ else
+ n1 = (m->cupl.nsamp[igr][ch] + 7) / 18;
+ if (n1 > 31)
+ n1 = 31;
+ antialias(m, m->cupl.sample[ch][igr], n1);
+ n1 = 18 * n1 + 8; /* update number of samples */
+ if (n1 > m->cupl.nsamp[igr][ch])
+ m->cupl.nsamp[igr][ch] = n1;
+ }
+
+
+
+/*--- hybrid + sbt ---*/
+ m->cupl.Xform(m, pcm, igr);
+
+
+/*-- done --*/
+}
+/*--------------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
+IN_OUT L3audio_decode(void *mv, unsigned char *bs, unsigned char *pcm)
+{
+ MPEG *m = mv;
+ return m->cupl.decode_function((MPEG *)mv, bs, pcm);
+}
+
+/*--------------------------------------------------------------------*/
+IN_OUT L3audio_decode_MPEG1(void *mv, unsigned char *bs, unsigned char *pcm)
+{
+ MPEG *m = mv;
+ int sync;
+ IN_OUT in_out;
+ int side_bytes;
+ int nbytes;
+
+ m->cupl.iframe++;
+
+ bitget_init(bs); /* initialize bit getter */
+/* test sync */
+ in_out.in_bytes = 0; /* assume fail */
+ in_out.out_bytes = 0;
+ sync = bitget(12);
+
+ if (sync != 0xFFF)
+ return in_out; /* sync fail */
+/*-----------*/
+
+/*-- unpack side info --*/
+ side_bytes = unpack_side_MPEG1(m);
+ m->cupl.padframebytes = m->cupl.framebytes + m->cupl.pad;
+ in_out.in_bytes = m->cupl.padframebytes;
+
+/*-- load main data and update buf pointer --*/
+/*-------------------------------------------
+ if start point < 0, must just cycle decoder
+ if jumping into middle of stream,
+w---------------------------------------------*/
+ m->cupl.buf_ptr0 = m->cupl.buf_ptr1 - m->cupl.side_info.main_data_begin; /* decode start point */
+ if (m->cupl.buf_ptr1 > BUF_TRIGGER)
+ { /* shift buffer */
+ memmove(m->cupl.buf, m->cupl.buf + m->cupl.buf_ptr0, m->cupl.side_info.main_data_begin);
+ m->cupl.buf_ptr0 = 0;
+ m->cupl.buf_ptr1 = m->cupl.side_info.main_data_begin;
+ }
+ nbytes = m->cupl.padframebytes - side_bytes - m->cupl.crcbytes;
+
+ // RAK: This is no bueno. :-(
+ if (nbytes < 0 || nbytes > NBUF)
+ {
+ in_out.in_bytes = 0;
+ return in_out;
+ }
+
+ memmove(m->cupl.buf + m->cupl.buf_ptr1, bs + side_bytes + m->cupl.crcbytes, nbytes);
+ m->cupl.buf_ptr1 += nbytes;
+/*-----------------------*/
+
+ if (m->cupl.buf_ptr0 >= 0)
+ {
+// dump_frame(buf+buf_ptr0, 64);
+ m->cupl.main_pos_bit = m->cupl.buf_ptr0 << 3;
+ unpack_main(m,pcm, 0);
+ unpack_main(m,pcm + m->cupl.half_outbytes, 1);
+ in_out.out_bytes = m->cupl.outbytes;
+ }
+ else
+ {
+ memset(pcm, m->cupl.zero_level_pcm, m->cupl.outbytes); /* fill out skipped frames */
+ in_out.out_bytes = m->cupl.outbytes;
+/* iframe--; in_out.out_bytes = 0; // test test */
+ }
+
+ return in_out;
+}
+/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------*/
+IN_OUT L3audio_decode_MPEG2(void *mv, unsigned char *bs, unsigned char *pcm)
+{
+ MPEG *m = mv;
+ int sync;
+ IN_OUT in_out;
+ int side_bytes;
+ int nbytes;
+ static int igr = 0;
+
+ m->cupl.iframe++;
+
+
+ bitget_init(bs); /* initialize bit getter */
+/* test sync */
+ in_out.in_bytes = 0; /* assume fail */
+ in_out.out_bytes = 0;
+ sync = bitget(12);
+
+// if( sync != 0xFFF ) return in_out; /* sync fail */
+
+ m->cupl.mpeg25_flag = 0;
+ if (sync != 0xFFF)
+ {
+ m->cupl.mpeg25_flag = 1; /* mpeg 2.5 sync */
+ if (sync != 0xFFE)
+ return in_out; /* sync fail */
+ }
+/*-----------*/
+
+
+/*-- unpack side info --*/
+ side_bytes = unpack_side_MPEG2(m,igr);
+ m->cupl.padframebytes = m->cupl.framebytes + m->cupl.pad;
+ in_out.in_bytes = m->cupl.padframebytes;
+
+ m->cupl.buf_ptr0 = m->cupl.buf_ptr1 - m->cupl.side_info.main_data_begin; /* decode start point */
+ if (m->cupl.buf_ptr1 > BUF_TRIGGER)
+ { /* shift buffer */
+ memmove(m->cupl.buf, m->cupl.buf + m->cupl.buf_ptr0, m->cupl.side_info.main_data_begin);
+ m->cupl.buf_ptr0 = 0;
+ m->cupl.buf_ptr1 = m->cupl.side_info.main_data_begin;
+ }
+ nbytes = m->cupl.padframebytes - side_bytes - m->cupl.crcbytes;
+ // RAK: This is no bueno. :-(
+ if (nbytes < 0 || nbytes > NBUF)
+ {
+ in_out.in_bytes = 0;
+ return in_out;
+ }
+ memmove(m->cupl.buf + m->cupl.buf_ptr1, bs + side_bytes + m->cupl.crcbytes, nbytes);
+ m->cupl.buf_ptr1 += nbytes;
+/*-----------------------*/
+
+ if (m->cupl.buf_ptr0 >= 0)
+ {
+ m->cupl.main_pos_bit = m->cupl.buf_ptr0 << 3;
+ unpack_main(m,pcm, igr);
+ in_out.out_bytes = m->cupl.outbytes;
+ }
+ else
+ {
+ memset(pcm, m->cupl.zero_level_pcm, m->cupl.outbytes); /* fill out skipped frames */
+ in_out.out_bytes = m->cupl.outbytes;
+// iframe--; in_out.out_bytes = 0; return in_out;// test test */
+ }
+
+
+
+ igr = igr ^ 1;
+ return in_out;
+}
+/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------*/
+static int const sr_table[8] =
+{22050, 24000, 16000, 1,
+ 44100, 48000, 32000, 1};
+
+static const struct
+{
+ int l[23];
+ int s[14];
+}
+sfBandIndexTable[3][3] =
+{
+/* mpeg-2 */
+ {
+ {
+ {
+ 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576
+ }
+ ,
+ {
+ 0, 4, 8, 12, 18, 24, 32, 42, 56, 74, 100, 132, 174, 192
+ }
+ }
+ ,
+ {
+ {
+ 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 114, 136, 162, 194, 232, 278, 332, 394, 464, 540, 576
+ }
+ ,
+ {
+ 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 136, 180, 192
+ }
+ }
+ ,
+ {
+ {
+ 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576
+ }
+ ,
+ {
+ 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192
+ }
+ }
+ ,
+ }
+ ,
+/* mpeg-1 */
+ {
+ {
+ {
+ 0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, 74, 90, 110, 134, 162, 196, 238, 288, 342, 418, 576
+ }
+ ,
+ {
+ 0, 4, 8, 12, 16, 22, 30, 40, 52, 66, 84, 106, 136, 192
+ }
+ }
+ ,
+ {
+ {
+ 0, 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, 72, 88, 106, 128, 156, 190, 230, 276, 330, 384, 576
+ }
+ ,
+ {
+ 0, 4, 8, 12, 16, 22, 28, 38, 50, 64, 80, 100, 126, 192
+ }
+ }
+ ,
+ {
+ {
+ 0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, 82, 102, 126, 156, 194, 240, 296, 364, 448, 550, 576
+ }
+ ,
+ {
+ 0, 4, 8, 12, 16, 22, 30, 42, 58, 78, 104, 138, 180, 192
+ }
+ }
+ }
+ ,
+
+/* mpeg-2.5, 11 & 12 KHz seem ok, 8 ok */
+ {
+ {
+ {
+ 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576
+ }
+ ,
+ {
+ 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192
+ }
+ }
+ ,
+ {
+ {
+ 0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576
+ }
+ ,
+ {
+ 0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192
+ }
+ }
+ ,
+// this 8khz table, and only 8khz, from mpeg123)
+ {
+ {
+ 0, 12, 24, 36, 48, 60, 72, 88, 108, 132, 160, 192, 232, 280, 336, 400, 476, 566, 568, 570, 572, 574, 576
+ }
+ ,
+ {
+ 0, 8, 16, 24, 36, 52, 72, 96, 124, 160, 162, 164, 166, 192
+ }
+ }
+ ,
+ }
+ ,
+};
+
+
+void sbt_mono_L3(MPEG *m, float *sample, signed short *pcm, int ch);
+void sbt_dual_L3(MPEG *m, float *sample, signed short *pcm, int ch);
+void sbt16_mono_L3(MPEG *m, float *sample, signed short *pcm, int ch);
+void sbt16_dual_L3(MPEG *m, float *sample, signed short *pcm, int ch);
+void sbt8_mono_L3(MPEG *m, float *sample, signed short *pcm, int ch);
+void sbt8_dual_L3(MPEG *m, float *sample, signed short *pcm, int ch);
+
+void sbtB_mono_L3(MPEG *m, float *sample, unsigned char *pcm, int ch);
+void sbtB_dual_L3(MPEG *m, float *sample, unsigned char *pcm, int ch);
+void sbtB16_mono_L3(MPEG *m, float *sample, unsigned char *pcm, int ch);
+void sbtB16_dual_L3(MPEG *m, float *sample, unsigned char *pcm, int ch);
+void sbtB8_mono_L3(MPEG *m, float *sample, unsigned char *pcm, int ch);
+void sbtB8_dual_L3(MPEG *m, float *sample, unsigned char *pcm, int ch);
+
+
+
+static SBT_FUNCTION_F sbt_table[2][3][2] =
+{
+{{ (SBT_FUNCTION_F) sbt_mono_L3,
+ (SBT_FUNCTION_F) sbt_dual_L3 } ,
+ { (SBT_FUNCTION_F) sbt16_mono_L3,
+ (SBT_FUNCTION_F) sbt16_dual_L3 } ,
+ { (SBT_FUNCTION_F) sbt8_mono_L3,
+ (SBT_FUNCTION_F) sbt8_dual_L3 }} ,
+/*-- 8 bit output -*/
+{{ (SBT_FUNCTION_F) sbtB_mono_L3,
+ (SBT_FUNCTION_F) sbtB_dual_L3 },
+ { (SBT_FUNCTION_F) sbtB16_mono_L3,
+ (SBT_FUNCTION_F) sbtB16_dual_L3 },
+ { (SBT_FUNCTION_F) sbtB8_mono_L3,
+ (SBT_FUNCTION_F) sbtB8_dual_L3 }}
+};
+
+
+void Xform_mono(void *mv, void *pcm, int igr);
+void Xform_dual(void *mv, void *pcm, int igr);
+void Xform_dual_mono(void *mv, void *pcm, int igr);
+void Xform_dual_right(void *mv, void *pcm, int igr);
+
+static XFORM_FUNCTION xform_table[5] =
+{
+ Xform_mono,
+ Xform_dual,
+ Xform_dual_mono,
+ Xform_mono, /* left */
+ Xform_dual_right,
+};
+int L3table_init(MPEG *m);
+void msis_init(MPEG *m);
+void sbt_init(MPEG *m);
+#if 0
+typedef int iARRAY22[22];
+#endif
+iARRAY22 *quant_init_band_addr();
+iARRAY22 *msis_init_band_addr();
+
+/*---------------------------------------------------------*/
+/* mpeg_head defined in mhead.h frame bytes is without pad */
+int L3audio_decode_init(void *mv, MPEG_HEAD * h, int framebytes_arg,
+ int reduction_code, int transform_code, int convert_code,
+ int freq_limit)
+{
+ MPEG *m = mv;
+ int i, j, k;
+ // static int first_pass = 1;
+ int samprate;
+ int limit;
+ int bit_code;
+ int out_chans;
+
+ m->cupl.buf_ptr0 = 0;
+ m->cupl.buf_ptr1 = 0;
+
+/* check if code handles */
+ if (h->option != 1)
+ return 0; /* layer III only */
+
+ if (h->id)
+ m->cupl.ncbl_mixed = 8; /* mpeg-1 */
+ else
+ m->cupl.ncbl_mixed = 6; /* mpeg-2 */
+
+ m->cupl.framebytes = framebytes_arg;
+
+ transform_code = transform_code; /* not used, asm compatability */
+ bit_code = 0;
+ if (convert_code & 8)
+ bit_code = 1;
+ convert_code = convert_code & 3; /* higher bits used by dec8 freq cvt */
+ if (reduction_code < 0)
+ reduction_code = 0;
+ if (reduction_code > 2)
+ reduction_code = 2;
+ if (freq_limit < 1000)
+ freq_limit = 1000;
+
+
+ samprate = sr_table[4 * h->id + h->sr_index];
+ if ((h->sync & 1) == 0)
+ samprate = samprate / 2; // mpeg 2.5
+/*----- compute nsb_limit --------*/
+ m->cupl.nsb_limit = (freq_limit * 64L + samprate / 2) / samprate;
+/*- caller limit -*/
+ limit = (32 >> reduction_code);
+ if (limit > 8)
+ limit--;
+ if (m->cupl.nsb_limit > limit)
+ m->cupl.nsb_limit = limit;
+ limit = 18 * m->cupl.nsb_limit;
+
+ k = h->id;
+ if ((h->sync & 1) == 0)
+ k = 2; // mpeg 2.5
+
+ if (k == 1)
+ {
+ m->cupl.band_limit12 = 3 * sfBandIndexTable[k][h->sr_index].s[13];
+ m->cupl.band_limit = m->cupl.band_limit21 = sfBandIndexTable[k][h->sr_index].l[22];
+ }
+ else
+ {
+ m->cupl.band_limit12 = 3 * sfBandIndexTable[k][h->sr_index].s[12];
+ m->cupl.band_limit = m->cupl.band_limit21 = sfBandIndexTable[k][h->sr_index].l[21];
+ }
+ m->cupl.band_limit += 8; /* allow for antialias */
+ if (m->cupl.band_limit > limit)
+ m->cupl.band_limit = limit;
+
+ if (m->cupl.band_limit21 > m->cupl.band_limit)
+ m->cupl.band_limit21 = m->cupl.band_limit;
+ if (m->cupl.band_limit12 > m->cupl.band_limit)
+ m->cupl.band_limit12 = m->cupl.band_limit;
+
+
+ m->cupl.band_limit_nsb = (m->cupl.band_limit + 17) / 18; /* limit nsb's rounded up */
+/*----------------------------------------------*/
+ m->cupl.gain_adjust = 0; /* adjust gain e.g. cvt to mono sum channel */
+ if ((h->mode != 3) && (convert_code == 1))
+ m->cupl.gain_adjust = -4;
+
+ m->cupl.outvalues = 1152 >> reduction_code;
+ if (h->id == 0)
+ m->cupl.outvalues /= 2;
+
+ out_chans = 2;
+ if (h->mode == 3)
+ out_chans = 1;
+ if (convert_code)
+ out_chans = 1;
+
+ m->cupl.sbt_L3 = sbt_table[bit_code][reduction_code][out_chans - 1];
+ k = 1 + convert_code;
+ if (h->mode == 3)
+ k = 0;
+ m->cupl.Xform = xform_table[k];
+
+
+ m->cupl.outvalues *= out_chans;
+
+ if (bit_code)
+ m->cupl.outbytes = m->cupl.outvalues;
+ else
+ m->cupl.outbytes = sizeof(short) * m->cupl.outvalues;
+
+ if (bit_code)
+ m->cupl.zero_level_pcm = 128; /* 8 bit output */
+ else
+ m->cupl.zero_level_pcm = 0;
+
+
+ m->cup.decinfo.channels = out_chans;
+ m->cup.decinfo.outvalues = m->cupl.outvalues;
+ m->cup.decinfo.samprate = samprate >> reduction_code;
+ if (bit_code)
+ m->cup.decinfo.bits = 8;
+ else
+ m->cup.decinfo.bits = sizeof(short) * 8;
+
+ m->cup.decinfo.framebytes = m->cupl.framebytes;
+ m->cup.decinfo.type = 0;
+
+ m->cupl.half_outbytes = m->cupl.outbytes / 2;
+/*------------------------------------------*/
+
+/*- init band tables --*/
+
+
+ k = h->id;
+ if ((h->sync & 1) == 0)
+ k = 2; // mpeg 2.5
+
+ for (i = 0; i < 22; i++)
+ m->cupl.sfBandIndex[0][i] = sfBandIndexTable[k][h->sr_index].l[i + 1];
+ for (i = 0; i < 13; i++)
+ m->cupl.sfBandIndex[1][i] = 3 * sfBandIndexTable[k][h->sr_index].s[i + 1];
+ for (i = 0; i < 22; i++)
+ m->cupl.nBand[0][i] =
+ sfBandIndexTable[k][h->sr_index].l[i + 1]
+ - sfBandIndexTable[k][h->sr_index].l[i];
+ for (i = 0; i < 13; i++)
+ m->cupl.nBand[1][i] =
+ sfBandIndexTable[k][h->sr_index].s[i + 1]
+ - sfBandIndexTable[k][h->sr_index].s[i];
+
+
+/* init tables */
+ L3table_init(m);
+/* init ms and is stereo modes */
+ msis_init(m);
+
+/*----- init sbt ---*/
+ sbt_init(m);
+
+
+
+/*--- clear buffers --*/
+ for (i = 0; i < 576; i++)
+ m->cupl.yout[i] = 0.0f;
+ for (j = 0; j < 2; j++)
+ {
+ for (k = 0; k < 2; k++)
+ {
+ for (i = 0; i < 576; i++)
+ {
+ m->cupl.sample[j][k][i].x = 0.0f;
+ m->cupl.sample[j][k][i].s = 0;
+ }
+ }
+ }
+
+ if (h->id == 1)
+ m->cupl.decode_function = L3audio_decode_MPEG1;
+ else
+ m->cupl.decode_function = L3audio_decode_MPEG2;
+
+ return 1;
+}
+/*---------------------------------------------------------*/
+/*==========================================================*/
+void cup3_init(MPEG *m)
+{
+ m->cupl.sbt_L3 = sbt_dual_L3;
+ m->cupl.Xform = Xform_dual;
+ m->cupl.sbt_L3 = sbt_dual_L3;
+ m->cupl.decode_function = L3audio_decode_MPEG1;
+}
diff --git a/codecs/mp3/src/cwin.c b/codecs/mp3/src/cwin.c
new file mode 100755
index 000000000..5698d82bb
--- /dev/null
+++ b/codecs/mp3/src/cwin.c
@@ -0,0 +1,500 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** cwin.c ***************************************************
+
+include to cwinm.c
+
+MPEG audio decoder, float window routines
+portable C
+
+******************************************************************/
+
+#ifdef ASM_X86
+extern void window_mpg_asm(float *a, int b, short *c);
+extern void window_dual_asm(float *a, int b, short *c);
+extern void window16_asm(float *a, int b, short *c);
+extern void window16_dual_asm(float *a, int b, short *c);
+extern void window8_asm(float *a, int b, short *c);
+extern void window8_dual_asm(float *a, int b, short *c);
+#endif /* ASM_X86 */
+
+/*-------------------------------------------------------------------------*/
+void window(float *vbuf, int vb_ptr, short *pcm)
+{
+#ifdef ASM_X86
+ window_mpg_asm(vbuf, vb_ptr, pcm);
+#else
+ int i, j;
+ int si, bx;
+ float *coef;
+ float sum;
+ long tmp;
+
+ si = vb_ptr + 16;
+ bx = (si + 32) & 511;
+ coef = wincoef;
+
+/*-- first 16 --*/
+ for (i = 0; i < 16; i++)
+ {
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[si];
+ si = (si + 64) & 511;
+ sum -= (*coef++) * vbuf[bx];
+ bx = (bx + 64) & 511;
+ }
+ si++;
+ bx--;
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = tmp;
+ }
+/*-- special case --*/
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[bx];
+ bx = (bx + 64) & 511;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = tmp;
+/*-- last 15 --*/
+ coef = wincoef + 255; /* back pass through coefs */
+ for (i = 0; i < 15; i++)
+ {
+ si--;
+ bx++;
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef--) * vbuf[si];
+ si = (si + 64) & 511;
+ sum += (*coef--) * vbuf[bx];
+ bx = (bx + 64) & 511;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = tmp;
+ }
+#endif
+}
+
+
+
+/*------------------------------------------------------------*/
+#ifndef ASM_X86_OLD
+void window_dual(float *vbuf, int vb_ptr, short *pcm)
+{
+#ifdef ASM_X86
+ window_dual_asm(vbuf, vb_ptr, pcm);
+#else
+ int i, j; /* dual window interleaves output */
+ int si, bx;
+ float *coef;
+ float sum;
+ long tmp;
+
+ si = vb_ptr + 16;
+ bx = (si + 32) & 511;
+ coef = wincoef;
+
+/*-- first 16 --*/
+ for (i = 0; i < 16; i++)
+ {
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[si];
+ si = (si + 64) & 511;
+ sum -= (*coef++) * vbuf[bx];
+ bx = (bx + 64) & 511;
+ }
+ si++;
+ bx--;
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = tmp;
+ pcm += 2;
+ }
+/*-- special case --*/
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[bx];
+ bx = (bx + 64) & 511;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = tmp;
+ pcm += 2;
+/*-- last 15 --*/
+ coef = wincoef + 255; /* back pass through coefs */
+ for (i = 0; i < 15; i++)
+ {
+ si--;
+ bx++;
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef--) * vbuf[si];
+ si = (si + 64) & 511;
+ sum += (*coef--) * vbuf[bx];
+ bx = (bx + 64) & 511;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = tmp;
+ pcm += 2;
+ }
+#endif
+}
+#endif /* ndef ASM_X86_OLD */
+/*------------------------------------------------------------*/
+/*------------------- 16 pt window ------------------------------*/
+void window16(float *vbuf, int vb_ptr, short *pcm)
+{
+#ifdef ASM_X86
+ window16_asm(vbuf, vb_ptr, pcm);
+#else
+ int i, j;
+ unsigned char si, bx;
+ float *coef;
+ float sum;
+ long tmp;
+
+ si = vb_ptr + 8;
+ bx = si + 16;
+ coef = wincoef;
+
+/*-- first 8 --*/
+ for (i = 0; i < 8; i++)
+ {
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[si];
+ si += 32;
+ sum -= (*coef++) * vbuf[bx];
+ bx += 32;
+ }
+ si++;
+ bx--;
+ coef += 16;
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = tmp;
+ }
+/*-- special case --*/
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[bx];
+ bx += 32;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = tmp;
+/*-- last 7 --*/
+ coef = wincoef + 255; /* back pass through coefs */
+ for (i = 0; i < 7; i++)
+ {
+ coef -= 16;
+ si--;
+ bx++;
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef--) * vbuf[si];
+ si += 32;
+ sum += (*coef--) * vbuf[bx];
+ bx += 32;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = tmp;
+ }
+#endif
+}
+/*--------------- 16 pt dual window (interleaved output) -----------------*/
+void window16_dual(float *vbuf, int vb_ptr, short *pcm)
+{
+#ifdef ASM_X86
+ window16_dual_asm(vbuf, vb_ptr, pcm);
+#else
+ int i, j;
+ unsigned char si, bx;
+ float *coef;
+ float sum;
+ long tmp;
+
+ si = vb_ptr + 8;
+ bx = si + 16;
+ coef = wincoef;
+
+/*-- first 8 --*/
+ for (i = 0; i < 8; i++)
+ {
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[si];
+ si += 32;
+ sum -= (*coef++) * vbuf[bx];
+ bx += 32;
+ }
+ si++;
+ bx--;
+ coef += 16;
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = tmp;
+ pcm += 2;
+ }
+/*-- special case --*/
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[bx];
+ bx += 32;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = tmp;
+ pcm += 2;
+/*-- last 7 --*/
+ coef = wincoef + 255; /* back pass through coefs */
+ for (i = 0; i < 7; i++)
+ {
+ coef -= 16;
+ si--;
+ bx++;
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef--) * vbuf[si];
+ si += 32;
+ sum += (*coef--) * vbuf[bx];
+ bx += 32;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = tmp;
+ pcm += 2;
+ }
+#endif
+}
+/*------------------- 8 pt window ------------------------------*/
+void window8(float *vbuf, int vb_ptr, short *pcm)
+{
+#ifdef ASM_X86
+ window8_asm(vbuf, vb_ptr, pcm);
+#else
+ int i, j;
+ int si, bx;
+ float *coef;
+ float sum;
+ long tmp;
+
+ si = vb_ptr + 4;
+ bx = (si + 8) & 127;
+ coef = wincoef;
+
+/*-- first 4 --*/
+ for (i = 0; i < 4; i++)
+ {
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[si];
+ si = (si + 16) & 127;
+ sum -= (*coef++) * vbuf[bx];
+ bx = (bx + 16) & 127;
+ }
+ si++;
+ bx--;
+ coef += 48;
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = tmp;
+ }
+/*-- special case --*/
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[bx];
+ bx = (bx + 16) & 127;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = tmp;
+/*-- last 3 --*/
+ coef = wincoef + 255; /* back pass through coefs */
+ for (i = 0; i < 3; i++)
+ {
+ coef -= 48;
+ si--;
+ bx++;
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef--) * vbuf[si];
+ si = (si + 16) & 127;
+ sum += (*coef--) * vbuf[bx];
+ bx = (bx + 16) & 127;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = tmp;
+ }
+#endif
+}
+/*--------------- 8 pt dual window (interleaved output) -----------------*/
+void window8_dual(float *vbuf, int vb_ptr, short *pcm)
+{
+#ifdef ASM_X86
+ window8_dual_asm(vbuf, vb_ptr, pcm);
+#else
+ int i, j;
+ int si, bx;
+ float *coef;
+ float sum;
+ long tmp;
+
+ si = vb_ptr + 4;
+ bx = (si + 8) & 127;
+ coef = wincoef;
+
+/*-- first 4 --*/
+ for (i = 0; i < 4; i++)
+ {
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[si];
+ si = (si + 16) & 127;
+ sum -= (*coef++) * vbuf[bx];
+ bx = (bx + 16) & 127;
+ }
+ si++;
+ bx--;
+ coef += 48;
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = tmp;
+ pcm += 2;
+ }
+/*-- special case --*/
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[bx];
+ bx = (bx + 16) & 127;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = tmp;
+ pcm += 2;
+/*-- last 3 --*/
+ coef = wincoef + 255; /* back pass through coefs */
+ for (i = 0; i < 3; i++)
+ {
+ coef -= 48;
+ si--;
+ bx++;
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef--) * vbuf[si];
+ si = (si + 16) & 127;
+ sum += (*coef--) * vbuf[bx];
+ bx = (bx + 16) & 127;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = tmp;
+ pcm += 2;
+ }
+#endif
+}
+/*------------------------------------------------------------*/
diff --git a/codecs/mp3/src/cwinb.c b/codecs/mp3/src/cwinb.c
new file mode 100755
index 000000000..6b7212dda
--- /dev/null
+++ b/codecs/mp3/src/cwinb.c
@@ -0,0 +1,496 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** cwin.c ***************************************************
+
+include to cwinm.c
+
+MPEG audio decoder, float window routines - 8 bit output
+portable C
+
+******************************************************************/
+/*-------------------------------------------------------------------------*/
+
+
+#ifdef ASM_X86
+extern void windowB_asm(float *a, int b, unsigned char *c);
+extern void windowB_dual_asm(float *a, int b, unsigned char *c);
+extern void windowB16_asm(float *a, int b, unsigned char *c);
+extern void windowB16_dual_asm(float *a, int b, unsigned char *c);
+extern void windowB8_asm(float *a, int b, unsigned char *c);
+extern void windowB8_dual_asm(float *a, int b, unsigned char *c);
+#endif /* ASM_X86 */
+
+void windowB(float *vbuf, int vb_ptr, unsigned char *pcm)
+{
+#ifdef ASM_X86
+ windowB_asm(vbuf, vb_ptr, pcm);
+#else
+ int i, j;
+ int si, bx;
+ float *coef;
+ float sum;
+ long tmp;
+
+ si = vb_ptr + 16;
+ bx = (si + 32) & 511;
+ coef = wincoef;
+
+/*-- first 16 --*/
+ for (i = 0; i < 16; i++)
+ {
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[si];
+ si = (si + 64) & 511;
+ sum -= (*coef++) * vbuf[bx];
+ bx = (bx + 64) & 511;
+ }
+ si++;
+ bx--;
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ }
+/*-- special case --*/
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[bx];
+ bx = (bx + 64) & 511;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = ((unsigned char) (tmp >> 8)) ^ 0x80;
+/*-- last 15 --*/
+ coef = wincoef + 255; /* back pass through coefs */
+ for (i = 0; i < 15; i++)
+ {
+ si--;
+ bx++;
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef--) * vbuf[si];
+ si = (si + 64) & 511;
+ sum += (*coef--) * vbuf[bx];
+ bx = (bx + 64) & 511;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ }
+#endif
+}
+/*------------------------------------------------------------*/
+void windowB_dual(float *vbuf, int vb_ptr, unsigned char *pcm)
+{
+#ifdef ASM_X86
+ windowB_dual_asm(vbuf, vb_ptr, pcm);
+#else
+ int i, j; /* dual window interleaves output */
+ int si, bx;
+ float *coef;
+ float sum;
+ long tmp;
+
+ si = vb_ptr + 16;
+ bx = (si + 32) & 511;
+ coef = wincoef;
+
+/*-- first 16 --*/
+ for (i = 0; i < 16; i++)
+ {
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[si];
+ si = (si + 64) & 511;
+ sum -= (*coef++) * vbuf[bx];
+ bx = (bx + 64) & 511;
+ }
+ si++;
+ bx--;
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ pcm += 2;
+ }
+/*-- special case --*/
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[bx];
+ bx = (bx + 64) & 511;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ pcm += 2;
+/*-- last 15 --*/
+ coef = wincoef + 255; /* back pass through coefs */
+ for (i = 0; i < 15; i++)
+ {
+ si--;
+ bx++;
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef--) * vbuf[si];
+ si = (si + 64) & 511;
+ sum += (*coef--) * vbuf[bx];
+ bx = (bx + 64) & 511;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ pcm += 2;
+ }
+#endif
+}
+/*------------------------------------------------------------*/
+/*------------------- 16 pt window ------------------------------*/
+void windowB16(float *vbuf, int vb_ptr, unsigned char *pcm)
+{
+#ifdef ASM_X86
+ windowB16_asm(vbuf, vb_ptr, pcm);
+#else
+ int i, j;
+ unsigned char si, bx;
+ float *coef;
+ float sum;
+ long tmp;
+
+ si = vb_ptr + 8;
+ bx = si + 16;
+ coef = wincoef;
+
+/*-- first 8 --*/
+ for (i = 0; i < 8; i++)
+ {
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[si];
+ si += 32;
+ sum -= (*coef++) * vbuf[bx];
+ bx += 32;
+ }
+ si++;
+ bx--;
+ coef += 16;
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ }
+/*-- special case --*/
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[bx];
+ bx += 32;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = ((unsigned char) (tmp >> 8)) ^ 0x80;
+/*-- last 7 --*/
+ coef = wincoef + 255; /* back pass through coefs */
+ for (i = 0; i < 7; i++)
+ {
+ coef -= 16;
+ si--;
+ bx++;
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef--) * vbuf[si];
+ si += 32;
+ sum += (*coef--) * vbuf[bx];
+ bx += 32;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ }
+#endif
+}
+/*--------------- 16 pt dual window (interleaved output) -----------------*/
+void windowB16_dual(float *vbuf, int vb_ptr, unsigned char *pcm)
+{
+#ifdef ASM_X86
+ windowB16_dual_asm(vbuf, vb_ptr, pcm);
+#else
+ int i, j;
+ unsigned char si, bx;
+ float *coef;
+ float sum;
+ long tmp;
+
+ si = vb_ptr + 8;
+ bx = si + 16;
+ coef = wincoef;
+
+/*-- first 8 --*/
+ for (i = 0; i < 8; i++)
+ {
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[si];
+ si += 32;
+ sum -= (*coef++) * vbuf[bx];
+ bx += 32;
+ }
+ si++;
+ bx--;
+ coef += 16;
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ pcm += 2;
+ }
+/*-- special case --*/
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[bx];
+ bx += 32;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ pcm += 2;
+/*-- last 7 --*/
+ coef = wincoef + 255; /* back pass through coefs */
+ for (i = 0; i < 7; i++)
+ {
+ coef -= 16;
+ si--;
+ bx++;
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef--) * vbuf[si];
+ si += 32;
+ sum += (*coef--) * vbuf[bx];
+ bx += 32;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ pcm += 2;
+ }
+#endif
+}
+/*------------------- 8 pt window ------------------------------*/
+void windowB8(float *vbuf, int vb_ptr, unsigned char *pcm)
+{
+#ifdef ASM_X86
+ windowB8_asm(vbuf, vb_ptr, pcm);
+#else
+ int i, j;
+ int si, bx;
+ float *coef;
+ float sum;
+ long tmp;
+
+ si = vb_ptr + 4;
+ bx = (si + 8) & 127;
+ coef = wincoef;
+
+/*-- first 4 --*/
+ for (i = 0; i < 4; i++)
+ {
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[si];
+ si = (si + 16) & 127;
+ sum -= (*coef++) * vbuf[bx];
+ bx = (bx + 16) & 127;
+ }
+ si++;
+ bx--;
+ coef += 48;
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ }
+/*-- special case --*/
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[bx];
+ bx = (bx + 16) & 127;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = ((unsigned char) (tmp >> 8)) ^ 0x80;
+/*-- last 3 --*/
+ coef = wincoef + 255; /* back pass through coefs */
+ for (i = 0; i < 3; i++)
+ {
+ coef -= 48;
+ si--;
+ bx++;
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef--) * vbuf[si];
+ si = (si + 16) & 127;
+ sum += (*coef--) * vbuf[bx];
+ bx = (bx + 16) & 127;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm++ = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ }
+#endif
+}
+/*--------------- 8 pt dual window (interleaved output) -----------------*/
+void windowB8_dual(float *vbuf, int vb_ptr, unsigned char *pcm)
+{
+#ifdef ASM_X86
+ windowB8_dual_asm(vbuf, vb_ptr, pcm);
+#else
+ int i, j;
+ int si, bx;
+ float *coef;
+ float sum;
+ long tmp;
+
+ si = vb_ptr + 4;
+ bx = (si + 8) & 127;
+ coef = wincoef;
+
+/*-- first 4 --*/
+ for (i = 0; i < 4; i++)
+ {
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[si];
+ si = (si + 16) & 127;
+ sum -= (*coef++) * vbuf[bx];
+ bx = (bx + 16) & 127;
+ }
+ si++;
+ bx--;
+ coef += 48;
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ pcm += 2;
+ }
+/*-- special case --*/
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef++) * vbuf[bx];
+ bx = (bx + 16) & 127;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ pcm += 2;
+/*-- last 3 --*/
+ coef = wincoef + 255; /* back pass through coefs */
+ for (i = 0; i < 3; i++)
+ {
+ coef -= 48;
+ si--;
+ bx++;
+ sum = 0.0F;
+ for (j = 0; j < 8; j++)
+ {
+ sum += (*coef--) * vbuf[si];
+ si = (si + 16) & 127;
+ sum += (*coef--) * vbuf[bx];
+ bx = (bx + 16) & 127;
+ }
+ tmp = (long) sum;
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ *pcm = ((unsigned char) (tmp >> 8)) ^ 0x80;
+ pcm += 2;
+ }
+#endif
+}
+/*------------------------------------------------------------*/
diff --git a/codecs/mp3/src/cwinm.c b/codecs/mp3/src/cwinm.c
new file mode 100755
index 000000000..c462fcc9a
--- /dev/null
+++ b/codecs/mp3/src/cwinm.c
@@ -0,0 +1,59 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** cwinm.c ***************************************************
+
+MPEG audio decoder, window master routine
+portable C
+
+
+******************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+
+
+/* disable precision loss warning on type conversion */
+#ifdef _MSC_VER
+#pragma warning(disable:4244 4056)
+#endif
+
+float wincoef[264] =
+{ /* window coefs */
+#include "tableawd.h"
+};
+
+/*--------------------------------------------------------*/
+#ifdef QUICK_FLOAT
+#include "cwinq.c"
+#include "cwinbq.c"
+#else
+#include "cwin.c"
+#include "cwinb.c"
+#endif
+/*--------------------------------------------------------*/
diff --git a/codecs/mp3/src/dec8.c b/codecs/mp3/src/dec8.c
new file mode 100755
index 000000000..478bbf1df
--- /dev/null
+++ b/codecs/mp3/src/dec8.c
@@ -0,0 +1,338 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** dec8.c ***************************************************
+
+
+ANSI C
+MPEG audio decoder Layer II only mpeg1 and mpeg2
+output sample type and sample rate conversion
+ decode mpeg to 8000Ks mono
+ output 16 bit linear, 8 bit linear, or u-law
+
+
+mod 6/29/95 bugfix in u-law table
+
+mod 11/15/95 for Layer I
+
+mod 1/7/97 minor mods for warnings
+
+******************************************************************/
+/*****************************************************************
+
+ MPEG audio software decoder portable ANSI c.
+ Decodes all Layer II to 8000Ks mono pcm.
+ Output selectable: 16 bit linear, 8 bit linear, u-law.
+
+-------------------------------------
+int audio_decode8_init(MPEG_HEAD *h, int framebytes_arg,
+ int reduction_code, int transform_code, int convert_code,
+ int freq_limit)
+
+initilize decoder:
+ return 0 = fail, not 0 = success
+
+MPEG_HEAD *h input, mpeg header info (returned by call to head_info)
+framebytes input, mpeg frame size (returned by call to head_info)
+reduction_code input, ignored
+transform_code input, ignored
+convert_code input, set convert_code = 4*bit_code + chan_code
+ bit_code: 1 = 16 bit linear pcm
+ 2 = 8 bit (unsigned) linear pcm
+ 3 = u-law (8 bits unsigned)
+ chan_code: 0 = convert two chan to mono
+ 1 = convert two chan to mono
+ 2 = convert two chan to left chan
+ 3 = convert two chan to right chan
+freq_limit input, ignored
+
+
+---------------------------------
+void audio_decode8_info( DEC_INFO *info)
+
+information return:
+ Call after audio_decode8_init. See mhead.h for
+ information returned in DEC_INFO structure.
+
+
+---------------------------------
+IN_OUT audio_decode8(unsigned char *bs, void *pcmbuf)
+
+decode one mpeg audio frame:
+bs input, mpeg bitstream, must start with
+ sync word. Caution: may read up to 3 bytes
+ beyond end of frame.
+pcmbuf output, pcm samples.
+
+IN_OUT structure returns:
+ Number bytes conceptually removed from mpeg bitstream.
+ Returns 0 if sync loss.
+ Number bytes of pcm output. This may vary from frame
+ to frame.
+
+*****************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#include "L3.h"
+#include "mhead.h" /* mpeg header structure */
+
+
+
+
+
+/*------------------------------------------*/
+static int output_code;
+static int convert(void *mv, unsigned char *pcm);
+static int convert_8bit(void *mv, unsigned char *pcm);
+static int convert_u(void *mv, unsigned char *pcm);
+static CVT_FUNCTION_8 cvt_table[3] =
+{
+ convert,
+ convert_8bit,
+ convert_u,
+};
+
+void mpeg8_init(MPEG8 *m)
+{
+ memset(&m->dec, 0, sizeof(m->dec));
+ m->dec.ncnt = 8 * 288;
+ m->dec.ncnt1 = 8 * 287;
+ m->dec.nlast = 287;
+ m->dec.ndeci = 11;
+ m->dec.kdeci = 8 * 288;
+ m->dec.first_pass = 1;
+}
+
+/*====================================================================*/
+IN_OUT audio_decode8(MPEG8 *m, unsigned char *bs, signed short *pcmbuf)
+{
+ IN_OUT x;
+
+ x = audio_decode(&m->cupper, bs, m->dec.pcm);
+ if (x.in_bytes <= 0)
+ return x;
+ x.out_bytes = m->dec.convert_routine(m, (void *) pcmbuf);
+
+ return x;
+}
+/*--------------8Ks 16 bit pcm --------------------------------*/
+static int convert(void *mv, unsigned char y0[])
+{
+ MPEG8 *m = mv;
+ int i, k;
+ long alpha;
+ short *y;
+
+ y = (short *) y0;
+ k = 0;
+ if (m->dec.kdeci < m->dec.ncnt)
+ {
+ alpha = m->dec.kdeci & 7;
+ y[k++] = (short) (m->dec.xsave + ((alpha * (m->dec.pcm[0] - m->dec.xsave)) >> 3));
+ m->dec.kdeci += m->dec.ndeci;
+ }
+ m->dec.kdeci -= m->dec.ncnt;
+ for (; m->dec.kdeci < m->dec.ncnt1; m->dec.kdeci += m->dec.ndeci)
+ {
+ i = m->dec.kdeci >> 3;
+ alpha = m->dec.kdeci & 7;
+ y[k++] = (short) (m->dec.pcm[i] + ((alpha * (m->dec.pcm[i + 1] - m->dec.pcm[i])) >> 3));
+ }
+ m->dec.xsave = m->dec.pcm[m->dec.nlast];
+
+/* printf("\n k out = %4d", k); */
+
+ return sizeof(short) * k;
+}
+/*----------------8Ks 8 bit unsigned pcm ---------------------------*/
+static int convert_8bit(void *mv, unsigned char y[])
+{
+ MPEG8 *m = mv;
+ int i, k;
+ long alpha;
+
+ k = 0;
+ if (m->dec.kdeci < m->dec.ncnt)
+ {
+ alpha = m->dec.kdeci & 7;
+ y[k++] = (unsigned char) (((m->dec.xsave + ((alpha * (m->dec.pcm[0] - m->dec.xsave)) >> 3)) >> 8) + 128);
+ m->dec.kdeci += m->dec.ndeci;
+ }
+ m->dec.kdeci -= m->dec.ncnt;
+ for (; m->dec.kdeci < m->dec.ncnt1; m->dec.kdeci += m->dec.ndeci)
+ {
+ i = m->dec.kdeci >> 3;
+ alpha = m->dec.kdeci & 7;
+ y[k++] = (unsigned char) (((m->dec.pcm[i] + ((alpha * (m->dec.pcm[i + 1] - m->dec.pcm[i])) >> 3)) >> 8) + 128);
+ }
+ m->dec.xsave = m->dec.pcm[m->dec.nlast];
+
+/* printf("\n k out = %4d", k); */
+
+ return k;
+}
+/*--------------8Ks u-law --------------------------------*/
+static int convert_u(void *mv, unsigned char y[])
+{
+ MPEG8 *m = mv;
+ int i, k;
+ long alpha;
+ unsigned char *look;
+
+ look = m->dec.look_u + 4096;
+
+ k = 0;
+ if (m->dec.kdeci < m->dec.ncnt)
+ {
+ alpha = m->dec.kdeci & 7;
+ y[k++] = look[(m->dec.xsave + ((alpha * (m->dec.pcm[0] - m->dec.xsave)) >> 3)) >> 3];
+ m->dec.kdeci += m->dec.ndeci;
+ }
+ m->dec.kdeci -= m->dec.ncnt;
+ for (; m->dec.kdeci < m->dec.ncnt1; m->dec.kdeci += m->dec.ndeci)
+ {
+ i = m->dec.kdeci >> 3;
+ alpha = m->dec.kdeci & 7;
+ y[k++] = look[(m->dec.pcm[i] + ((alpha * (m->dec.pcm[i + 1] - m->dec.pcm[i])) >> 3)) >> 3];
+ }
+ m->dec.xsave = m->dec.pcm[m->dec.nlast];
+
+/* printf("\n k out = %4d", k); */
+
+ return k;
+}
+/*--------------------------------------------------------------------*/
+static int ucomp3(int x) /* re analog devices CCITT G.711 */
+{
+ int s, p, y, t, u, u0, sign;
+
+ sign = 0;
+ if (x < 0)
+ {
+ x = -x;
+ sign = 0x0080;
+ }
+ if (x > 8031)
+ x = 8031;
+ x += 33;
+ t = x;
+ for (s = 0; s < 15; s++)
+ {
+ if (t & 0x4000)
+ break;
+ t <<= 1;
+ }
+ y = x << s;
+ p = (y >> 10) & 0x0f; /* position */
+ s = 9 - s; /* segment */
+ u0 = (((s << 4) | p) & 0x7f) | sign;
+ u = u0 ^ 0xff;
+
+ return u;
+}
+/*------------------------------------------------------------------*/
+static void table_init(MPEG8 *m)
+{
+ int i;
+
+ for (i = -4096; i < 4096; i++)
+ m->dec.look_u[4096 + i] = (unsigned char) (ucomp3(2 * i));
+
+}
+/*-------------------------------------------------------------------*/
+int audio_decode8_init(MPEG8 *m, MPEG_HEAD * h, int framebytes_arg,
+ int reduction_code, int transform_code, int convert_code,
+ int freq_limit)
+{
+ int istat;
+ int outvals;
+ static int sr_table[2][4] =
+ {{22, 24, 16, 0}, {44, 48, 32, 0}};
+
+ if (m->dec.first_pass)
+ {
+ table_init(m);
+ m->dec.first_pass = 0;
+ }
+
+ if ((h->sync & 1) == 0)
+ return 0; // fail mpeg 2.5
+
+ output_code = convert_code >> 2;
+ if (output_code < 1)
+ output_code = 1; /* 1= 16bit 2 = 8bit 3 = u */
+ if (output_code > 3)
+ output_code = 3; /* 1= 16bit 2 = 8bit 3 = u */
+
+ convert_code = convert_code & 3;
+ if (convert_code <= 0)
+ convert_code = 1; /* always cvt to mono */
+
+ reduction_code = 1;
+ if (h->id)
+ reduction_code = 2;
+
+/* select convert routine */
+ m->dec.convert_routine = cvt_table[output_code - 1];
+
+/* init decimation/convert routine */
+/*-- MPEG-2 layer III --*/
+ if ((h->option == 1) && h->id == 0)
+ outvals = 576 >> reduction_code;
+ else if (h->option == 3)
+ outvals = 384 >> reduction_code;
+/*-- layer I --*/
+ else
+ outvals = 1152 >> reduction_code;
+ m->dec.ncnt = 8 * outvals;
+ m->dec.ncnt1 = 8 * (outvals - 1);
+ m->dec.nlast = outvals - 1;
+ m->dec.ndeci = sr_table[h->id][h->sr_index] >> reduction_code;
+ m->dec.kdeci = 8 * outvals;
+/* printf("\n outvals %d", outvals); */
+
+ freq_limit = 3200;
+ istat = audio_decode_init(&m->cupper, h, framebytes_arg,
+ reduction_code, transform_code, convert_code,
+ freq_limit);
+
+
+ return istat;
+}
+/*-----------------------------------------------------------------*/
+void audio_decode8_info(MPEG8 *m, DEC_INFO * info)
+{
+
+ audio_decode_info(&m->cupper, info);
+ info->samprate = 8000;
+ if (output_code != 1)
+ info->bits = 8;
+ if (output_code == 3)
+ info->type = 10;
+}
diff --git a/codecs/mp3/src/hwin.c b/codecs/mp3/src/hwin.c
new file mode 100755
index 000000000..2ba1106d7
--- /dev/null
+++ b/codecs/mp3/src/hwin.c
@@ -0,0 +1,284 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** hwin.c ***************************************************
+
+Layer III
+
+hybrid window/filter
+
+******************************************************************/
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#include "L3.h"
+#include "mhead.h"
+
+#ifdef ASM_X86
+extern int hybrid_asm(float xin[], float xprev[], float y[18][32],
+ int btype, int nlong, int ntot, int nprev);
+extern void FreqInvert_asm(float y[18][32], int n);
+#endif /* ASM_X86 */
+
+
+typedef float ARRAY36[36];
+
+/*====================================================================*/
+void imdct18(float f[]); /* 18 point */
+void imdct6_3(float f[]); /* 6 point */
+
+/*====================================================================*/
+ARRAY36 *hwin_init_addr(MPEG *m)
+{
+ return m->cupl.win;
+}
+
+#ifdef ASM_X86
+#ifdef _MSC_VER
+#pragma warning(disable: 4035)
+#endif /* _MSC_VER */
+#endif /* ASM_X86 */
+
+/*====================================================================*/
+int hybrid(MPEG *m, float xin[], float xprev[], float y[18][32],
+ int btype, int nlong, int ntot, int nprev)
+{
+#ifdef ASM_X86
+ hybrid_asm(xin, xprev, y, btype, nlong, ntot, nprev);
+#else
+ int i, j;
+ float *x, *x0;
+ float xa, xb;
+ int n;
+ int nout;
+
+
+
+ if (btype == 2)
+ btype = 0;
+ x = xin;
+ x0 = xprev;
+
+/*-- do long blocks (if any) --*/
+ n = (nlong + 17) / 18; /* number of dct's to do */
+ for (i = 0; i < n; i++)
+ {
+ imdct18(x);
+ for (j = 0; j < 9; j++)
+ {
+ y[j][i] = x0[j] + m->cupl.win[btype][j] * x[9 + j];
+ y[9 + j][i] = x0[9 + j] + m->cupl.win[btype][9 + j] * x[17 - j];
+ }
+ /* window x for next time x0 */
+ for (j = 0; j < 4; j++)
+ {
+ xa = x[j];
+ xb = x[8 - j];
+ x[j] = m->cupl.win[btype][18 + j] * xb;
+ x[8 - j] = m->cupl.win[btype][(18 + 8) - j] * xa;
+ x[9 + j] = m->cupl.win[btype][(18 + 9) + j] * xa;
+ x[17 - j] = m->cupl.win[btype][(18 + 17) - j] * xb;
+ }
+ xa = x[j];
+ x[j] = m->cupl.win[btype][18 + j] * xa;
+ x[9 + j] = m->cupl.win[btype][(18 + 9) + j] * xa;
+
+ x += 18;
+ x0 += 18;
+ }
+
+/*-- do short blocks (if any) --*/
+ n = (ntot + 17) / 18; /* number of 6 pt dct's triples to do */
+ for (; i < n; i++)
+ {
+ imdct6_3(x);
+ for (j = 0; j < 3; j++)
+ {
+ y[j][i] = x0[j];
+ y[3 + j][i] = x0[3 + j];
+
+ y[6 + j][i] = x0[6 + j] + m->cupl.win[2][j] * x[3 + j];
+ y[9 + j][i] = x0[9 + j] + m->cupl.win[2][3 + j] * x[5 - j];
+
+ y[12 + j][i] = x0[12 + j] + m->cupl.win[2][6 + j] * x[2 - j] + m->cupl.win[2][j] * x[(6 + 3) + j];
+ y[15 + j][i] = x0[15 + j] + m->cupl.win[2][9 + j] * x[j] + m->cupl.win[2][3 + j] * x[(6 + 5) - j];
+ }
+ /* window x for next time x0 */
+ for (j = 0; j < 3; j++)
+ {
+ x[j] = m->cupl.win[2][6 + j] * x[(6 + 2) - j] + m->cupl.win[2][j] * x[(12 + 3) + j];
+ x[3 + j] = m->cupl.win[2][9 + j] * x[6 + j] + m->cupl.win[2][3 + j] * x[(12 + 5) - j];
+ }
+ for (j = 0; j < 3; j++)
+ {
+ x[6 + j] = m->cupl.win[2][6 + j] * x[(12 + 2) - j];
+ x[9 + j] = m->cupl.win[2][9 + j] * x[12 + j];
+ }
+ for (j = 0; j < 3; j++)
+ {
+ x[12 + j] = 0.0f;
+ x[15 + j] = 0.0f;
+ }
+ x += 18;
+ x0 += 18;
+ }
+
+/*--- overlap prev if prev longer that current --*/
+ n = (nprev + 17) / 18;
+ for (; i < n; i++)
+ {
+ for (j = 0; j < 18; j++)
+ y[j][i] = x0[j];
+ x0 += 18;
+ }
+ nout = 18 * i;
+
+/*--- clear remaining only to band limit --*/
+ for (; i < m->cupl.band_limit_nsb; i++)
+ {
+ for (j = 0; j < 18; j++)
+ y[j][i] = 0.0f;
+ }
+
+ return nout;
+#endif
+}
+
+#ifdef ASM_X86
+#ifdef _MSC_VER
+#pragma warning(default: 4035)
+#endif /* _MSC_VER */
+#endif /* ASM_X86 */
+
+/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------*/
+/*-- convert to mono, add curr result to y,
+ window and add next time to current left */
+int hybrid_sum(MPEG *m, float xin[], float xin_left[], float y[18][32],
+ int btype, int nlong, int ntot)
+{
+ int i, j;
+ float *x, *x0;
+ float xa, xb;
+ int n;
+ int nout;
+
+
+
+ if (btype == 2)
+ btype = 0;
+ x = xin;
+ x0 = xin_left;
+
+/*-- do long blocks (if any) --*/
+ n = (nlong + 17) / 18; /* number of dct's to do */
+ for (i = 0; i < n; i++)
+ {
+ imdct18(x);
+ for (j = 0; j < 9; j++)
+ {
+ y[j][i] += m->cupl.win[btype][j] * x[9 + j];
+ y[9 + j][i] += m->cupl.win[btype][9 + j] * x[17 - j];
+ }
+ /* window x for next time x0 */
+ for (j = 0; j < 4; j++)
+ {
+ xa = x[j];
+ xb = x[8 - j];
+ x0[j] += m->cupl.win[btype][18 + j] * xb;
+ x0[8 - j] += m->cupl.win[btype][(18 + 8) - j] * xa;
+ x0[9 + j] += m->cupl.win[btype][(18 + 9) + j] * xa;
+ x0[17 - j] += m->cupl.win[btype][(18 + 17) - j] * xb;
+ }
+ xa = x[j];
+ x0[j] += m->cupl.win[btype][18 + j] * xa;
+ x0[9 + j] += m->cupl.win[btype][(18 + 9) + j] * xa;
+
+ x += 18;
+ x0 += 18;
+ }
+
+/*-- do short blocks (if any) --*/
+ n = (ntot + 17) / 18; /* number of 6 pt dct's triples to do */
+ for (; i < n; i++)
+ {
+ imdct6_3(x);
+ for (j = 0; j < 3; j++)
+ {
+ y[6 + j][i] += m->cupl.win[2][j] * x[3 + j];
+ y[9 + j][i] += m->cupl.win[2][3 + j] * x[5 - j];
+
+ y[12 + j][i] += m->cupl.win[2][6 + j] * x[2 - j] + m->cupl.win[2][j] * x[(6 + 3) + j];
+ y[15 + j][i] += m->cupl.win[2][9 + j] * x[j] + m->cupl.win[2][3 + j] * x[(6 + 5) - j];
+ }
+ /* window x for next time */
+ for (j = 0; j < 3; j++)
+ {
+ x0[j] += m->cupl.win[2][6 + j] * x[(6 + 2) - j] + m->cupl.win[2][j] * x[(12 + 3) + j];
+ x0[3 + j] += m->cupl.win[2][9 + j] * x[6 + j] + m->cupl.win[2][3 + j] * x[(12 + 5) - j];
+ }
+ for (j = 0; j < 3; j++)
+ {
+ x0[6 + j] += m->cupl.win[2][6 + j] * x[(12 + 2) - j];
+ x0[9 + j] += m->cupl.win[2][9 + j] * x[12 + j];
+ }
+ x += 18;
+ x0 += 18;
+ }
+
+ nout = 18 * i;
+
+ return nout;
+}
+/*--------------------------------------------------------------------*/
+void sum_f_bands(float a[], float b[], int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ a[i] += b[i];
+}
+/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------*/
+void FreqInvert(float y[18][32], int n)
+{
+#ifdef ASM_X86
+ FreqInvert_asm(y, n);
+#else
+ int i, j;
+
+ n = (n + 17) / 18;
+ for (j = 0; j < 18; j += 2)
+ {
+ for (i = 0; i < n; i += 2)
+ {
+ y[1 + j][1 + i] = -y[1 + j][1 + i];
+ }
+ }
+#endif
+}
+/*--------------------------------------------------------------------*/
diff --git a/codecs/mp3/src/icdct.c b/codecs/mp3/src/icdct.c
new file mode 100755
index 000000000..a38c401dd
--- /dev/null
+++ b/codecs/mp3/src/icdct.c
@@ -0,0 +1,383 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** icdct.c ***************************************************
+
+
+MPEG audio decoder, dct
+portable C integer dct
+
+mod 1/8/97 warnings
+
+******************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#include "itype.h"
+
+/*-------------------------------------------------------------------*/
+static DCTCOEF coef32[32]; /* 32 pt dct coefs */
+
+
+
+
+#define forward_bf idx_forward_bf
+/*--- #define forward_bf ptr_forward_bf ---*/
+/*------------------------------------------------------------*/
+DCTCOEF *i_dct_coef_addr()
+{
+ return coef32;
+}
+/*------------------------------------------------------------*/
+static void idx_forward_bf(int m, int n, INT32 x[], INT32 f[], DCTCOEF coef[])
+{
+ int i, j, n2;
+ int p, q, p0, k;
+
+ p0 = 0;
+ n2 = n >> 1;
+ for (i = 0; i < m; i++, p0 += n)
+ {
+ k = 0;
+ p = p0;
+ q = p + n - 1;
+ for (j = 0; j < n2; j++, p++, q--, k++)
+ {
+ f[p] = x[p] + x[q];
+ f[n2 + p] = ((x[p] - x[q]) * coef[k]) >> DCTBITS;
+ }
+ }
+}
+/*------------------------------------------------------------*/
+/*--
+static void ptr_forward_bf(int m, int n, INT32 x[], INT32 f[], DCTCOEF coef[])
+{
+int i, j, n2;
+DCTCOEF *c;
+INT32 *y;
+
+n2 = n >> 1;
+for(i=0; i<m; i++) {
+ c = coef;
+ y = x+n;
+ for(j=0; j<n2; j++) {
+ *f = *x + *--y;
+ *((f++)+n2) = ( (*x++ - *y) * (*c++) ) >> DCTBITS;
+ }
+ f+=n2;
+ x+=n2;
+}
+}
+---*/
+/*------------------------------------------------------------*/
+static void forward_bfm(int m, INT32 x[], INT32 f[])
+{
+ int i;
+ int p;
+
+/*--- special case last fwd stage ----*/
+ for (p = 0, i = 0; i < m; i++, p += 2)
+ {
+ f[p] = x[p] + x[p + 1];
+ f[p + 1] = ((x[p] - x[p + 1]) * coef32[30]) >> DCTBITS;
+ }
+}
+/*------------------------------------------------------------*/
+static void back_bf(int m, int n, INT32 x[], INT32 f[])
+{
+ int i, j, n2, n21;
+ int p, q, p0;
+
+ p0 = 0;
+ n2 = n >> 1;
+ n21 = n2 - 1;
+ for (i = 0; i < m; i++, p0 += n)
+ {
+ p = p0;
+ q = p0;
+ for (j = 0; j < n2; j++, p += 2, q++)
+ f[p] = x[q];
+ p = p0 + 1;
+ for (j = 0; j < n21; j++, p += 2, q++)
+ f[p] = x[q] + x[q + 1];
+ f[p] = x[q];
+ }
+}
+/*------------------------------------------------------------*/
+static void back_bf0(int n, INT32 x[], WININT f[])
+{
+ int p, q;
+
+ n--;
+#if DCTSATURATE
+ for (p = 0, q = 0; p < n; p += 2, q++)
+ {
+ tmp = x[q];
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ f[p] = tmp;
+ }
+ for (p = 1; q < n; p += 2, q++)
+ {
+ tmp = x[q] + x[q + 1];
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ f[p] = tmp;
+ }
+ tmp = x[q];
+ if (tmp > 32767)
+ tmp = 32767;
+ else if (tmp < -32768)
+ tmp = -32768;
+ f[p] = tmp;
+#else
+ for (p = 0, q = 0; p < n; p += 2, q++)
+ f[p] = x[q];
+ for (p = 1; q < n; p += 2, q++)
+ f[p] = x[q] + x[q + 1];
+ f[p] = x[q];
+#endif
+
+}
+/*------------------------------------------------------------*/
+void i_dct32(SAMPLEINT x[], WININT c[])
+{
+ INT32 a[32]; /* ping pong buffers */
+ INT32 b[32];
+ int p, q;
+
+/* special first stage */
+ for (p = 0, q = 31; p < 16; p++, q--)
+ {
+ a[p] = (INT32) x[p] + x[q];
+ a[16 + p] = (coef32[p] * ((INT32) x[p] - x[q])) >> DCTBITS;
+ }
+
+ forward_bf(2, 16, a, b, coef32 + 16);
+ forward_bf(4, 8, b, a, coef32 + 16 + 8);
+ forward_bf(8, 4, a, b, coef32 + 16 + 8 + 4);
+ forward_bfm(16, b, a);
+ back_bf(8, 4, a, b);
+ back_bf(4, 8, b, a);
+ back_bf(2, 16, a, b);
+ back_bf0(32, b, c);
+}
+/*------------------------------------------------------------*/
+void i_dct32_dual(SAMPLEINT x[], WININT c[])
+{
+ INT32 a[32]; /* ping pong buffers */
+ INT32 b[32];
+ int p, pp, qq;
+
+/* special first stage for dual chan (interleaved x) */
+ pp = 0;
+ qq = 2 * 31;
+ for (p = 0; p < 16; p++, pp += 2, qq -= 2)
+ {
+ a[p] = (INT32) x[pp] + x[qq];
+ a[16 + p] = (coef32[p] * ((INT32) x[pp] - x[qq])) >> DCTBITS;
+ }
+ forward_bf(2, 16, a, b, coef32 + 16);
+ forward_bf(4, 8, b, a, coef32 + 16 + 8);
+ forward_bf(8, 4, a, b, coef32 + 16 + 8 + 4);
+ forward_bfm(16, b, a);
+ back_bf(8, 4, a, b);
+ back_bf(4, 8, b, a);
+ back_bf(2, 16, a, b);
+ back_bf0(32, b, c);
+}
+/*---------------convert dual to mono------------------------------*/
+void i_dct32_dual_mono(SAMPLEINT x[], WININT c[])
+{
+ INT32 a[32]; /* ping pong buffers */
+ INT32 b[32];
+ INT32 t1, t2;
+ int p, pp, qq;
+
+/* special first stage */
+ pp = 0;
+ qq = 2 * 31;
+ for (p = 0; p < 16; p++, pp += 2, qq -= 2)
+ {
+ t1 = ((INT32) x[pp] + x[pp + 1]);
+ t2 = ((INT32) x[qq] + x[qq + 1]);
+ a[p] = (t1 + t2) >> 1;
+ a[16 + p] = coef32[p] * (t1 - t2) >> (DCTBITS + 1);
+ }
+ forward_bf(2, 16, a, b, coef32 + 16);
+ forward_bf(4, 8, b, a, coef32 + 16 + 8);
+ forward_bf(8, 4, a, b, coef32 + 16 + 8 + 4);
+ forward_bfm(16, b, a);
+ back_bf(8, 4, a, b);
+ back_bf(4, 8, b, a);
+ back_bf(2, 16, a, b);
+ back_bf0(32, b, c);
+}
+/*------------------------------------------------------------*/
+/*---------------- 16 pt dct -------------------------------*/
+void i_dct16(SAMPLEINT x[], WININT c[])
+{
+ INT32 a[16]; /* ping pong buffers */
+ INT32 b[16];
+ int p, q;
+
+/* special first stage (drop highest sb) */
+ a[0] = x[0];
+ a[8] = (a[0] * coef32[16]) >> DCTBITS;
+ for (p = 1, q = 14; p < 8; p++, q--)
+ {
+ a[p] = (INT32) x[p] + x[q];
+ a[8 + p] = (((INT32) x[p] - x[q]) * coef32[16 + p]) >> DCTBITS;
+ }
+ forward_bf(2, 8, a, b, coef32 + 16 + 8);
+ forward_bf(4, 4, b, a, coef32 + 16 + 8 + 4);
+ forward_bfm(8, a, b);
+ back_bf(4, 4, b, a);
+ back_bf(2, 8, a, b);
+ back_bf0(16, b, c);
+}
+/*------------------------------------------------------------*/
+/*---------------- 16 pt dct dual chan---------------------*/
+void i_dct16_dual(SAMPLEINT x[], WININT c[])
+{
+ int p, pp, qq;
+ INT32 a[16]; /* ping pong buffers */
+ INT32 b[16];
+
+/* special first stage for interleaved input */
+ a[0] = x[0];
+ a[8] = (coef32[16] * a[0]) >> DCTBITS;
+ pp = 2;
+ qq = 2 * 14;
+ for (p = 1; p < 8; p++, pp += 2, qq -= 2)
+ {
+ a[p] = (INT32) x[pp] + x[qq];
+ a[8 + p] = (coef32[16 + p] * ((INT32) x[pp] - x[qq])) >> DCTBITS;
+ }
+ forward_bf(2, 8, a, b, coef32 + 16 + 8);
+ forward_bf(4, 4, b, a, coef32 + 16 + 8 + 4);
+ forward_bfm(8, a, b);
+ back_bf(4, 4, b, a);
+ back_bf(2, 8, a, b);
+ back_bf0(16, b, c);
+}
+/*------------------------------------------------------------*/
+/*---------------- 16 pt dct dual to mono-------------------*/
+void i_dct16_dual_mono(SAMPLEINT x[], WININT c[])
+{
+ INT32 a[16]; /* ping pong buffers */
+ INT32 b[16];
+ INT32 t1, t2;
+ int p, pp, qq;
+
+/* special first stage */
+ a[0] = ((INT32) x[0] + x[1]) >> 1;
+ a[8] = (coef32[16] * a[0]) >> DCTBITS;
+ pp = 2;
+ qq = 2 * 14;
+ for (p = 1; p < 8; p++, pp += 2, qq -= 2)
+ {
+ t1 = (INT32) x[pp] + x[pp + 1];
+ t2 = (INT32) x[qq] + x[qq + 1];
+ a[p] = (t1 + t2) >> 1;
+ a[8 + p] = (coef32[16 + p] * (t1 - t2)) >> (DCTBITS + 1);
+ }
+ forward_bf(2, 8, a, b, coef32 + 16 + 8);
+ forward_bf(4, 4, b, a, coef32 + 16 + 8 + 4);
+ forward_bfm(8, a, b);
+ back_bf(4, 4, b, a);
+ back_bf(2, 8, a, b);
+ back_bf0(16, b, c);
+}
+/*------------------------------------------------------------*/
+/*---------------- 8 pt dct -------------------------------*/
+void i_dct8(SAMPLEINT x[], WININT c[])
+{
+ int p, q;
+ INT32 a[8]; /* ping pong buffers */
+ INT32 b[8];
+
+/* special first stage */
+
+ for (p = 0, q = 7; p < 4; p++, q--)
+ {
+ b[p] = (INT32) x[p] + x[q];
+ b[4 + p] = (coef32[16 + 8 + p] * ((INT32) x[p] - x[q])) >> DCTBITS;
+ }
+
+ forward_bf(2, 4, b, a, coef32 + 16 + 8 + 4);
+ forward_bfm(4, a, b);
+ back_bf(2, 4, b, a);
+ back_bf0(8, a, c);
+}
+/*------------------------------------------------------------*/
+/*---------------- 8 pt dct dual chan---------------------*/
+void i_dct8_dual(SAMPLEINT x[], WININT c[])
+{
+ int p, pp, qq;
+ INT32 a[8]; /* ping pong buffers */
+ INT32 b[8];
+
+/* special first stage for interleaved input */
+ for (p = 0, pp = 0, qq = 14; p < 4; p++, pp += 2, qq -= 2)
+ {
+ b[p] = (INT32) x[pp] + x[qq];
+ b[4 + p] = (coef32[16 + 8 + p] * ((INT32) x[pp] - x[qq])) >> DCTBITS;
+ }
+ forward_bf(2, 4, b, a, coef32 + 16 + 8 + 4);
+ forward_bfm(4, a, b);
+ back_bf(2, 4, b, a);
+ back_bf0(8, a, c);
+}
+/*------------------------------------------------------------*/
+/*---------------- 8 pt dct dual to mono---------------------*/
+void i_dct8_dual_mono(SAMPLEINT x[], WININT c[])
+{
+ int p, pp, qq;
+ INT32 a[8]; /* ping pong buffers */
+ INT32 b[8];
+ INT32 t1, t2;
+
+/* special first stage */
+ for (p = 0, pp = 0, qq = 14; p < 4; p++, pp += 2, qq -= 2)
+ {
+ t1 = (INT32) x[pp] + x[pp + 1];
+ t2 = (INT32) x[qq] + x[qq + 1];
+ b[p] = (t1 + t2) >> 1;
+ b[4 + p] = (coef32[16 + 8 + p] * (t1 - t2)) >> (DCTBITS + 1);
+ }
+ forward_bf(2, 4, b, a, coef32 + 16 + 8 + 4);
+ forward_bfm(4, a, b);
+ back_bf(2, 4, b, a);
+ back_bf0(8, a, c);
+}
+/*------------------------------------------------------------*/
diff --git a/codecs/mp3/src/isbt.c b/codecs/mp3/src/isbt.c
new file mode 100755
index 000000000..bc240bdb9
--- /dev/null
+++ b/codecs/mp3/src/isbt.c
@@ -0,0 +1,458 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** isbt.c ***************************************************
+
+MPEG audio decoder, dct and window
+portable C integer version of csbt.c
+
+mods 11/15/95 for Layer I
+
+mods 1/7/97 warnings
+
+******************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#include "itype.h"
+
+
+#ifdef _MSC_VER
+#pragma warning(disable: 4244)
+#pragma warning(disable: 4056)
+#endif
+
+
+
+/* asm is quick only, c code does not need separate window for right */
+/* full is opposite of quick */
+#ifdef FULL_INTEGER
+#define i_window_dual_right i_window_dual
+#define i_window16_dual_right i_window16_dual
+#define i_window8_dual_right i_window8_dual
+#endif
+
+
+void i_dct32(SAMPLEINT * sample, WININT * vbuf);
+void i_dct32_dual(SAMPLEINT * sample, WININT * vbuf);
+void i_dct32_dual_mono(SAMPLEINT * sample, WININT * vbuf);
+
+void i_dct16(SAMPLEINT * sample, WININT * vbuf);
+void i_dct16_dual(SAMPLEINT * sample, WININT * vbuf);
+void i_dct16_dual_mono(SAMPLEINT * sample, WININT * vbuf);
+
+void i_dct8(SAMPLEINT * sample, WININT * vbuf);
+void i_dct8_dual(SAMPLEINT * sample, WININT * vbuf);
+void i_dct8_dual_mono(SAMPLEINT * sample, WININT * vbuf);
+
+
+void i_window(WININT * vbuf, int vb_ptr, short *pcm);
+void i_window_dual(WININT * vbuf, int vb_ptr, short *pcm);
+void i_window_dual_right(WININT * vbuf, int vb_ptr, short *pcm);
+
+void i_window16(WININT * vbuf, int vb_ptr, short *pcm);
+void i_window16_dual(WININT * vbuf, int vb_ptr, short *pcm);
+void i_window16_dual_right(WININT * vbuf, int vb_ptr, short *pcm);
+
+void i_window8(WININT * vbuf, int vb_ptr, short *pcm);
+void i_window8_dual(WININT * vbuf, int vb_ptr, short *pcm);
+void i_window8_dual_right(WININT * vbuf, int vb_ptr, short *pcm);
+
+/*--------------------------------------------------------------------*/
+/*-- floating point window coefs ---*/
+/*-- for integer-quick window, table used to generate integer coefs --*/
+static float wincoef[264] =
+{
+#include "tableawd.h"
+};
+
+/* circular window buffers */
+/* extern windows because of asm */
+static signed int vb_ptr;
+
+// static WININT vbuf[512];
+//static WININT vbuf2[512];
+extern WININT vbuf[512];
+extern WININT vbuf2[512];
+
+DCTCOEF *i_dct_coef_addr();
+
+/*======================================================================*/
+static void gencoef() /* gen coef for N=32 */
+{
+ int p, n, i, k;
+ double t, pi;
+ DCTCOEF *coef32;
+
+ coef32 = i_dct_coef_addr();
+
+
+ pi = 4.0 * atan(1.0);
+ n = 16;
+ k = 0;
+ for (i = 0; i < 5; i++, n = n / 2)
+ {
+ for (p = 0; p < n; p++, k++)
+ {
+ t = (pi / (4 * n)) * (2 * p + 1);
+ coef32[k] = (1 << DCTBITS) * (0.50 / cos(t)) + 0.5;
+ }
+ }
+}
+/*------------------------------------------------------------*/
+WINCOEF *i_wincoef_addr();
+static void genwincoef_q() /* gen int window coefs from floating table */
+{
+ int i, j, k, m;
+ float x;
+ WINCOEF *iwincoef;
+
+ iwincoef = i_wincoef_addr();
+
+
+/*--- coefs generated inline for quick window ---*/
+/*-- quick uses only 116 coefs --*/
+
+ k = 0;
+ m = 0;
+ for (i = 0; i < 16; i++)
+ {
+ k += 5;
+ for (j = 0; j < 7; j++)
+ {
+ x = (1 << WINBITS) * wincoef[k++];
+ if (x > 0.0)
+ x += 0.5;
+ else
+ x -= 0.5;
+ iwincoef[m++] = x;
+ }
+ k += 4;
+ }
+ k++;
+ for (j = 0; j < 4; j++)
+ {
+ x = (1 << WINBITS) * wincoef[k++];
+ if (x > 0.0)
+ x += 0.5;
+ else
+ x -= 0.5;
+ iwincoef[m++] = x;
+ }
+}
+/*------------------------------------------------------------*/
+static void genwincoef() /* gen int window coefs from floating table */
+{
+ int i;
+ float x;
+ WINCOEF *iwincoef;
+ WINCOEF *i_wincoef_addr();
+
+ iwincoef = i_wincoef_addr();
+
+ for (i = 0; i < 264; i++)
+ {
+ x = (1 << WINBITS) * wincoef[i];
+ if (x > 0.0)
+ x += 0.5;
+ else
+ x -= 0.5;
+ iwincoef[i] = x;
+ }
+}
+/*------------------------------------------------------------*/
+void i_sbt_init()
+{
+ int i;
+ static int first_pass = 1;
+
+#ifdef FULL_INTEGER
+ static int full_integer = 1;
+
+#else
+ static int full_integer = 0;
+
+#endif
+
+ if (first_pass)
+ {
+ gencoef();
+ if (full_integer)
+ genwincoef();
+ else
+ genwincoef_q();
+ first_pass = 0;
+ }
+
+/* clear window vbuf */
+ for (i = 0; i < 512; i++)
+ vbuf[i] = vbuf2[i] = 0;
+ vb_ptr = 0;
+
+}
+/*==============================================================*/
+/*==============================================================*/
+/*==============================================================*/
+void i_sbt_mono(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct32(sample, vbuf + vb_ptr);
+ i_window(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+
+}
+/*------------------------------------------------------------*/
+void i_sbt_dual(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct32_dual(sample, vbuf + vb_ptr);
+ i_dct32_dual(sample + 1, vbuf2 + vb_ptr);
+ i_window_dual(vbuf, vb_ptr, pcm);
+ i_window_dual_right(vbuf2, vb_ptr, pcm + 1);
+ sample += 64;
+ vb_ptr = (vb_ptr - 32) & 511;
+ pcm += 64;
+ }
+}
+/*------------------------------------------------------------*/
+/* convert dual to mono */
+void i_sbt_dual_mono(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct32_dual_mono(sample, vbuf + vb_ptr);
+ i_window(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+}
+/*------------------------------------------------------------*/
+/* convert dual to left */
+void i_sbt_dual_left(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct32_dual(sample, vbuf + vb_ptr);
+ i_window(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+}
+/*------------------------------------------------------------*/
+/* convert dual to right */
+void i_sbt_dual_right(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ sample++; /* point to right chan */
+ for (i = 0; i < n; i++)
+ {
+ i_dct32_dual(sample, vbuf + vb_ptr);
+ i_window(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+}
+/*------------------------------------------------------------*/
+/*---------------- 16 pt sbt's -------------------------------*/
+/*------------------------------------------------------------*/
+void i_sbt16_mono(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct16(sample, vbuf + vb_ptr);
+ i_window16(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+
+}
+/*------------------------------------------------------------*/
+void i_sbt16_dual(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct16_dual(sample, vbuf + vb_ptr);
+ i_dct16_dual(sample + 1, vbuf2 + vb_ptr);
+ i_window16_dual(vbuf, vb_ptr, pcm);
+ i_window16_dual_right(vbuf2, vb_ptr, pcm + 1);
+ sample += 64;
+ vb_ptr = (vb_ptr - 16) & 255;
+ pcm += 32;
+ }
+
+}
+/*------------------------------------------------------------*/
+void i_sbt16_dual_mono(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct16_dual_mono(sample, vbuf + vb_ptr);
+ i_window16(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+void i_sbt16_dual_left(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct16_dual(sample, vbuf + vb_ptr);
+ i_window16(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+void i_sbt16_dual_right(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ sample++;
+ for (i = 0; i < n; i++)
+ {
+ i_dct16_dual(sample, vbuf + vb_ptr);
+ i_window16(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+/*---------------- 8 pt sbt's -------------------------------*/
+/*------------------------------------------------------------*/
+void i_sbt8_mono(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct8(sample, vbuf + vb_ptr);
+ i_window8(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+
+}
+/*------------------------------------------------------------*/
+void i_sbt8_dual(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct8_dual(sample, vbuf + vb_ptr);
+ i_dct8_dual(sample + 1, vbuf2 + vb_ptr);
+ i_window8_dual(vbuf, vb_ptr, pcm);
+ i_window8_dual_right(vbuf2, vb_ptr, pcm + 1);
+ sample += 64;
+ vb_ptr = (vb_ptr - 8) & 127;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+void i_sbt8_dual_mono(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct8_dual_mono(sample, vbuf + vb_ptr);
+ i_window8(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+}
+/*------------------------------------------------------------*/
+void i_sbt8_dual_left(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct8_dual(sample, vbuf + vb_ptr);
+ i_window8(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+}
+/*------------------------------------------------------------*/
+void i_sbt8_dual_right(SAMPLEINT * sample, short *pcm, int n)
+{
+ int i;
+
+ sample++;
+ for (i = 0; i < n; i++)
+ {
+ i_dct8_dual(sample, vbuf + vb_ptr);
+ i_window8(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+}
+/*------------------------------------------------------------*/
+/*--- 8 bit output ----------------*/
+#include "isbtb.c"
+/*----------------------------------*/
+
+#ifdef _MSC_VER
+#pragma warning(default: 4244)
+#pragma warning(default: 4056)
+#endif
diff --git a/codecs/mp3/src/isbtb.c b/codecs/mp3/src/isbtb.c
new file mode 100755
index 000000000..f59841975
--- /dev/null
+++ b/codecs/mp3/src/isbtb.c
@@ -0,0 +1,288 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** isbtb.c ***************************************************
+
+include to isbt.c
+
+
+MPEG audio decoder, integer dct and window, 8 bit output
+
+
+******************************************************************/
+/* asm is quick only, c code does not need separate window for right */
+/* full is opposite of quick */
+#ifdef FULL_INTEGER
+#define i_windowB_dual_right i_windowB_dual
+#define i_windowB16_dual_right i_windowB16_dual
+#define i_windowB8_dual_right i_windowB8_dual
+#endif
+
+void i_windowB(WININT * vbuf, int vb_ptr, unsigned char *pcm);
+void i_windowB_dual(WININT * vbuf, int vb_ptr, unsigned char *pcm);
+void i_windowB_dual_right(WININT * vbuf, int vb_ptr, unsigned char *pcm);
+void i_windowB16(WININT * vbuf, int vb_ptr, unsigned char *pcm);
+void i_windowB16_dual(WININT * vbuf, int vb_ptr, unsigned char *pcm);
+void i_windowB16_dual_right(WININT * vbuf, int vb_ptr, unsigned char *pcm);
+void i_windowB8(WININT * vbuf, int vb_ptr, unsigned char *pcm);
+void i_windowB8_dual(WININT * vbuf, int vb_ptr, unsigned char *pcm);
+void i_windowB8_dual_right(WININT * vbuf, int vb_ptr, unsigned char *pcm);
+
+
+
+/*==============================================================*/
+/*==============================================================*/
+/*==============================================================*/
+void i_sbtB_mono(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct32(sample, vbuf + vb_ptr);
+ i_windowB(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+
+}
+/*------------------------------------------------------------*/
+void i_sbtB_dual(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct32_dual(sample, vbuf + vb_ptr);
+ i_dct32_dual(sample + 1, vbuf2 + vb_ptr);
+ i_windowB_dual(vbuf, vb_ptr, pcm);
+ i_windowB_dual_right(vbuf2, vb_ptr, pcm + 1);
+ sample += 64;
+ vb_ptr = (vb_ptr - 32) & 511;
+ pcm += 64;
+ }
+}
+/*------------------------------------------------------------*/
+/* convert dual to mono */
+void i_sbtB_dual_mono(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct32_dual_mono(sample, vbuf + vb_ptr);
+ i_windowB(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+}
+/*------------------------------------------------------------*/
+/* convert dual to left */
+void i_sbtB_dual_left(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct32_dual(sample, vbuf + vb_ptr);
+ i_windowB(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+}
+/*------------------------------------------------------------*/
+/* convert dual to right */
+void i_sbtB_dual_right(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ sample++; /* point to right chan */
+ for (i = 0; i < n; i++)
+ {
+ i_dct32_dual(sample, vbuf + vb_ptr);
+ i_windowB(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 32) & 511;
+ pcm += 32;
+ }
+}
+/*------------------------------------------------------------*/
+/*---------------- 16 pt sbt's -------------------------------*/
+/*------------------------------------------------------------*/
+void i_sbtB16_mono(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct16(sample, vbuf + vb_ptr);
+ i_windowB16(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+
+}
+/*------------------------------------------------------------*/
+void i_sbtB16_dual(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct16_dual(sample, vbuf + vb_ptr);
+ i_dct16_dual(sample + 1, vbuf2 + vb_ptr);
+ i_windowB16_dual(vbuf, vb_ptr, pcm);
+ i_windowB16_dual_right(vbuf2, vb_ptr, pcm + 1);
+ sample += 64;
+ vb_ptr = (vb_ptr - 16) & 255;
+ pcm += 32;
+ }
+
+}
+/*------------------------------------------------------------*/
+void i_sbtB16_dual_mono(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct16_dual_mono(sample, vbuf + vb_ptr);
+ i_windowB16(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+void i_sbtB16_dual_left(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct16_dual(sample, vbuf + vb_ptr);
+ i_windowB16(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+void i_sbtB16_dual_right(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ sample++;
+ for (i = 0; i < n; i++)
+ {
+ i_dct16_dual(sample, vbuf + vb_ptr);
+ i_windowB16(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 16) & 255;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+/*---------------- 8 pt sbt's -------------------------------*/
+/*------------------------------------------------------------*/
+void i_sbtB8_mono(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct8(sample, vbuf + vb_ptr);
+ i_windowB8(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+
+}
+/*------------------------------------------------------------*/
+void i_sbtB8_dual(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct8_dual(sample, vbuf + vb_ptr);
+ i_dct8_dual(sample + 1, vbuf2 + vb_ptr);
+ i_windowB8_dual(vbuf, vb_ptr, pcm);
+ i_windowB8_dual_right(vbuf2, vb_ptr, pcm + 1);
+ sample += 64;
+ vb_ptr = (vb_ptr - 8) & 127;
+ pcm += 16;
+ }
+}
+/*------------------------------------------------------------*/
+void i_sbtB8_dual_mono(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct8_dual_mono(sample, vbuf + vb_ptr);
+ i_windowB8(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+}
+/*------------------------------------------------------------*/
+void i_sbtB8_dual_left(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ i_dct8_dual(sample, vbuf + vb_ptr);
+ i_windowB8(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+}
+/*------------------------------------------------------------*/
+void i_sbtB8_dual_right(SAMPLEINT * sample, unsigned char *pcm, int n)
+{
+ int i;
+
+ sample++;
+ for (i = 0; i < n; i++)
+ {
+ i_dct8_dual(sample, vbuf + vb_ptr);
+ i_windowB8(vbuf, vb_ptr, pcm);
+ sample += 64;
+ vb_ptr = (vb_ptr - 8) & 127;
+ pcm += 8;
+ }
+}
+/*------------------------------------------------------------*/
diff --git a/codecs/mp3/src/iup.c b/codecs/mp3/src/iup.c
new file mode 100755
index 000000000..8dd2fcc79
--- /dev/null
+++ b/codecs/mp3/src/iup.c
@@ -0,0 +1,529 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** iup.c ***************************************************
+
+MPEG audio decoder Layer I/II, mpeg1 and mpeg2
+should be portable ANSI C, should be endian independent
+
+icup integer version of cup.c
+
+
+
+mod 10/18/95 mod grouped sample unpack for:
+ Overflow possible in grouped if native int is 16 bit.
+ Rare occurance. 16x16-->32 mult needed.
+
+mods 11/15/95 for Layer I
+
+
+1/5/95 Quick fix, cs_factor can overflow int16 (why?). Typed to int32.
+
+mods 1/7/97 warnings
+
+******************************************************************/
+/******************************************************************
+
+ MPEG audio software decoder portable ANSI c.
+ Decodes all Layer II to 16 bit linear pcm.
+ Optional stereo to mono conversion. Optional
+ output sample rate conversion to half or quarter of
+ native mpeg rate.
+
+-------------------------------------
+int i_audio_decode_init(MPEG *m, MPEG_HEAD *h, int framebytes_arg,
+ int reduction_code, int transform_code, int convert_code,
+ int freq_limit)
+
+initilize decoder:
+ return 0 = fail, not 0 = success
+
+MPEG_HEAD *h input, mpeg header info (returned by call to head_info)
+framebytes input, mpeg frame size (returned by call to head_info)
+reduction_code input, sample rate reduction code
+ 0 = full rate
+ 1 = half rate
+ 0 = quarter rate
+
+transform_code input, ignored
+convert_code input, channel conversion
+ convert_code: 0 = two chan output
+ 1 = convert two chan to mono
+ 2 = convert two chan to left chan
+ 3 = convert two chan to right chan
+freq_limit input, limits bandwidth of pcm output to specified
+ frequency. Special use. Set to 24000 for normal use.
+
+
+---------------------------------
+void i_audio_decode_info( MPEG *m, DEC_INFO *info)
+
+information return:
+ Call after audio_decode_init. See mhead.h for
+ information returned in DEC_INFO structure.
+
+
+---------------------------------
+IN_OUT i_audio_decode(MPEG *m, unsigned char *bs, void *pcmbuf)
+
+decode one mpeg audio frame:
+bs input, mpeg bitstream, must start with
+ sync word. Caution: may read up to 3 bytes
+ beyond end of frame.
+pcmbuf output, pcm samples.
+
+IN_OUT structure returns:
+ Number bytes conceptually removed from mpeg bitstream.
+ Returns 0 if sync loss.
+ Number bytes of pcm output.
+
+*******************************************************************/
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#include "L3.h"
+#include "mhead.h" /* mpeg header structure */
+#include "jdw.h"
+
+/*-------------------------------------------------------
+NOTE: Decoder may read up to three bytes beyond end of
+frame. Calling application must ensure that this does
+not cause a memory access violation (protection fault)
+---------------------------------------------------------*/
+
+
+#ifdef _MSC_VER
+#pragma warning(disable: 4709)
+#endif
+
+
+/* Okay to be global -- is read/only */
+static int look_joint[16] =
+{ /* lookup stereo sb's by mode+ext */
+ 64, 64, 64, 64, /* stereo */
+ 2 * 4, 2 * 8, 2 * 12, 2 * 16, /* joint */
+ 64, 64, 64, 64, /* dual */
+ 32, 32, 32, 32, /* mono */
+};
+
+/* Okay to be global -- is read/only */
+static int bat_bit_master[] =
+{
+ 0, 5, 7, 9, 10, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48};
+
+void i_sbt_mono(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt_dual(SAMPLEINT * sample, short *pcm, int n);
+
+static void unpack();
+
+/*------------- initialize bit getter -------------*/
+static void load_init(MPEGI *m, unsigned char *buf)
+{
+ m->iup.bs_ptr = buf;
+ m->iup.bits = 0;
+ m->iup.bitbuf = 0;
+}
+/*------------- get n bits from bitstream -------------*/
+static INT32 load(MPEGI *m, int n)
+{
+ UINT32 x;
+
+ if (m->iup.bits < n)
+ { /* refill bit buf if necessary */
+ while (m->iup.bits <= 24)
+ {
+ m->iup.bitbuf = (m->iup.bitbuf << 8) | *m->iup.bs_ptr++;
+ m->iup.bits += 8;
+ }
+ }
+ m->iup.bits -= n;
+ x = m->iup.bitbuf >> m->iup.bits;
+ m->iup.bitbuf -= x << m->iup.bits;
+ return x;
+}
+/*------------- skip over n bits in bitstream -------------*/
+static void skip(MPEGI *m, int n)
+{
+ int k;
+
+ if (m->iup.bits < n)
+ {
+ n -= m->iup.bits;
+ k = n >> 3;
+/*--- bytes = n/8 --*/
+ m->iup.bs_ptr += k;
+ n -= k << 3;
+ m->iup.bitbuf = *m->iup.bs_ptr++;
+ m->iup.bits = 8;
+ }
+ m->iup.bits -= n;
+ m->iup.bitbuf -= (m->iup.bitbuf >> m->iup.bits) << m->iup.bits;
+}
+/*--------------------------------------------------------------*/
+#define mac_load_check(n) \
+ if( m->iup.bits < (n) ) { \
+ while( m->iup.bits <= 24 ) { \
+ m->iup.bitbuf = (m->iup.bitbuf << 8) | *m->iup.bs_ptr++; \
+ m->iup.bits += 8; \
+ } \
+ }
+/*--------------------------------------------------------------*/
+#define mac_load(n) \
+ ( m->iup.bits -= n, \
+ m->iup.bitval = m->iup.bitbuf >> m->iup.bits, \
+ m->iup.bitbuf -= m->iup.bitval << m->iup.bits, \
+ m->iup.bitval )
+/*======================================================================*/
+static void unpack_ba(MPEGI *m)
+{
+ int i, j, k;
+ static int nbit[4] =
+ {4, 4, 3, 2};
+ int nstereo;
+ int n;
+
+ m->iup.bit_skip = 0;
+ nstereo = m->iup.stereo_sb;
+ k = 0;
+ for (i = 0; i < 4; i++)
+ {
+ for (j = 0; j < m->iup.nbat[i]; j++, k++)
+ {
+ mac_load_check(4);
+ n = m->iup.ballo[k] = m->iup.samp_dispatch[k] = m->iup.bat[i][mac_load(nbit[i])];
+ if (k >= m->iup.nsb_limit)
+ m->iup.bit_skip += bat_bit_master[m->iup.samp_dispatch[k]];
+ m->iup.c_value[k] = m->iup.look_c_value[n];
+ m->iup.c_shift[k] = m->iup.look_c_shift[n];
+ if (--nstereo < 0)
+ {
+ m->iup.ballo[k + 1] = m->iup.ballo[k];
+ m->iup.samp_dispatch[k] += 18; /* flag as joint */
+ m->iup.samp_dispatch[k + 1] = m->iup.samp_dispatch[k]; /* flag for sf */
+ m->iup.c_value[k + 1] = m->iup.c_value[k];
+ m->iup.c_shift[k + 1] = m->iup.c_shift[k];
+ k++;
+ j++;
+ }
+ }
+ }
+ m->iup.samp_dispatch[m->iup.nsb_limit] = 37; /* terminate the dispatcher with skip */
+ m->iup.samp_dispatch[k] = 36; /* terminate the dispatcher */
+
+}
+/*-------------------------------------------------------------------------*/
+static void unpack_sfs(MPEGI *m) /* unpack scale factor selectors */
+{
+ int i;
+
+ for (i = 0; i < m->iup.max_sb; i++)
+ {
+ mac_load_check(2);
+ if (m->iup.ballo[i])
+ m->iup.sf_dispatch[i] = mac_load(2);
+ else
+ m->iup.sf_dispatch[i] = 4; /* no allo */
+ }
+ m->iup.sf_dispatch[i] = 5; /* terminate dispatcher */
+}
+/*-------------------------------------------------------------------------*/
+/*--- multiply note -------------------------------------------------------*/
+/*--- 16bit x 16bit mult --> 32bit >> 15 --> 16 bit or better -----------*/
+static void unpack_sf(MPEGI *m) /* unpack scale factor */
+{ /* combine dequant and scale factors */
+ int i, n;
+ INT32 tmp; /* only reason tmp is 32 bit is to get 32 bit mult result */
+
+ i = -1;
+ dispatch:switch (m->iup.sf_dispatch[++i])
+ {
+ case 0: /* 3 factors 012 */
+ mac_load_check(18);
+ tmp = m->iup.c_value[i];
+ n = m->iup.c_shift[i];
+ m->iup.cs_factor[0][i] = (tmp * m->iup.sf_table[mac_load(6)]) >> n;
+ m->iup.cs_factor[1][i] = (tmp * m->iup.sf_table[mac_load(6)]) >> n;
+ m->iup.cs_factor[2][i] = (tmp * m->iup.sf_table[mac_load(6)]) >> n;
+ goto dispatch;
+ case 1: /* 2 factors 002 */
+ mac_load_check(12);
+ tmp = m->iup.c_value[i];
+ n = m->iup.c_shift[i];
+ m->iup.cs_factor[1][i] = m->iup.cs_factor[0][i] =
+ (tmp * m->iup.sf_table[mac_load(6)]) >> n;
+ m->iup.cs_factor[2][i] = (tmp * m->iup.sf_table[mac_load(6)]) >> n;
+ goto dispatch;
+ case 2: /* 1 factor 000 */
+ mac_load_check(6);
+ tmp = m->iup.c_value[i];
+ n = m->iup.c_shift[i];
+ m->iup.cs_factor[2][i] = m->iup.cs_factor[1][i] = m->iup.cs_factor[0][i] =
+ (tmp * m->iup.sf_table[mac_load(6)]) >> n;
+ goto dispatch;
+ case 3: /* 2 factors 022 */
+ mac_load_check(12);
+ tmp = m->iup.c_value[i];
+ n = m->iup.c_shift[i];
+ m->iup.cs_factor[0][i] = (tmp * m->iup.sf_table[mac_load(6)]) >> n;
+ m->iup.cs_factor[2][i] = m->iup.cs_factor[1][i] =
+ (tmp * m->iup.sf_table[mac_load(6)]) >> n;
+ goto dispatch;
+ case 4: /* no allo */
+ goto dispatch;
+ case 5: /* all done */
+ ;
+ } /* end switch */
+}
+/*-------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------------*/
+/*--- unpack multiply note ------------------------------------------------*/
+/*--- 16bit x 16bit mult --> 32bit or better required---------------------*/
+#define UNPACK_N(n) \
+ s[k] = ((m->iup.cs_factor[i][k]*(load(m,n)-((1 << (n-1)) -1)))>>(n-1)); \
+ s[k+64] = ((m->iup.cs_factor[i][k]*(load(m,n)-((1 << (n-1)) -1)))>>(n-1)); \
+ s[k+128] = ((m->iup.cs_factor[i][k]*(load(m,n)-((1 << (n-1)) -1)))>>(n-1)); \
+ goto dispatch;
+#define UNPACK_N2(n) \
+ mac_load_check(3*n); \
+ s[k] = (m->iup.cs_factor[i][k]*(mac_load(n)-((1 << (n-1)) -1)))>>(n-1); \
+ s[k+64] = (m->iup.cs_factor[i][k]*(mac_load(n)-((1 << (n-1)) -1)))>>(n-1); \
+ s[k+128] = (m->iup.cs_factor[i][k]*(mac_load(n)-((1 << (n-1)) -1)))>>(n-1); \
+ goto dispatch;
+#define UNPACK_N3(n) \
+ mac_load_check(2*n); \
+ s[k] = (m->iup.cs_factor[i][k]*(mac_load(n)-((1 << (n-1)) -1)))>>(n-1); \
+ s[k+64] = (m->iup.cs_factor[i][k]*(mac_load(n)-((1 << (n-1)) -1)))>>(n-1); \
+ mac_load_check(n); \
+ s[k+128] = (m->iup.cs_factor[i][k]*(mac_load(n)-((1 << (n-1)) -1)))>>(n-1); \
+ goto dispatch;
+#define UNPACKJ_N(n) \
+ tmp = (load(m,n)-((1 << (n-1)) -1)); \
+ s[k] = (m->iup.cs_factor[i][k]*tmp)>>(n-1); \
+ s[k+1] = (m->iup.cs_factor[i][k+1]*tmp)>>(n-1); \
+ tmp = (load(m,n)-((1 << (n-1)) -1)); \
+ s[k+64] = (m->iup.cs_factor[i][k]*tmp)>>(n-1); \
+ s[k+64+1] = (m->iup.cs_factor[i][k+1]*tmp)>>(n-1); \
+ tmp = (load(m,n)-((1 << (n-1)) -1)); \
+ s[k+128] = (m->iup.cs_factor[i][k]*tmp)>>(n-1); \
+ s[k+128+1] = (m->iup.cs_factor[i][k+1]*tmp)>>(n-1); \
+ k++; /* skip right chan dispatch */ \
+ goto dispatch;
+/*-------------------------------------------------------------------------*/
+static void unpack_samp(MPEGI *m) /* unpack samples */
+{
+ int i, j, k;
+ SAMPLEINT *s;
+ int n;
+ INT32 tmp;
+
+ s = m->iup.sample;
+ for (i = 0; i < 3; i++)
+ { /* 3 groups of scale factors */
+ for (j = 0; j < 4; j++)
+ {
+ k = -1;
+ dispatch:switch (m->iup.samp_dispatch[++k])
+ {
+ case 0:
+ s[k + 128] = s[k + 64] = s[k] = 0;
+ goto dispatch;
+ case 1: /* 3 levels grouped 5 bits */
+ mac_load_check(5);
+ n = mac_load(5);
+ s[k] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group3_table[n][0]) >> 1;
+ s[k + 64] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group3_table[n][1]) >> 1;
+ s[k + 128] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group3_table[n][2]) >> 1;
+ goto dispatch;
+ case 2: /* 5 levels grouped 7 bits */
+ mac_load_check(7);
+ n = mac_load(7);
+ s[k] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group5_table[n][0]) >> 2;
+ s[k + 64] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group5_table[n][1]) >> 2;
+ s[k + 128] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group5_table[n][2]) >> 2;
+ goto dispatch;
+ case 3:
+ UNPACK_N2(3) /* 7 levels */
+ case 4: /* 9 levels grouped 10 bits */
+ mac_load_check(10);
+ n = mac_load(10);
+ s[k] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group9_table[n][0]) >> 3;
+ s[k + 64] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group9_table[n][1]) >> 3;
+ s[k + 128] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group9_table[n][2]) >> 3;
+ goto dispatch;
+ case 5:
+ UNPACK_N2(4) /* 15 levels */
+ case 6:
+ UNPACK_N2(5) /* 31 levels */
+ case 7:
+ UNPACK_N2(6) /* 63 levels */
+ case 8:
+ UNPACK_N2(7) /* 127 levels */
+ case 9:
+ UNPACK_N2(8) /* 255 levels */
+ case 10:
+ UNPACK_N3(9) /* 511 levels */
+ case 11:
+ UNPACK_N3(10) /* 1023 levels */
+ case 12:
+ UNPACK_N3(11) /* 2047 levels */
+ case 13:
+ UNPACK_N3(12) /* 4095 levels */
+ case 14:
+ UNPACK_N(13) /* 8191 levels */
+ case 15:
+ UNPACK_N(14) /* 16383 levels */
+ case 16:
+ UNPACK_N(15) /* 32767 levels */
+ case 17:
+ UNPACK_N(16) /* 65535 levels */
+/* -- joint ---- */
+ case 18 + 0:
+ s[k + 128 + 1] = s[k + 128] = s[k + 64 + 1] = s[k + 64] = s[k + 1] = s[k] = 0;
+ k++; /* skip right chan dispatch */
+ goto dispatch;
+ case 18 + 1: /* 3 levels grouped 5 bits */
+ n = load(m,5);
+ s[k] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group3_table[n][0]) >> 1;
+ s[k + 1] = ((INT32) m->iup.cs_factor[i][k + 1] * m->iup.group3_table[n][0]) >> 1;
+ s[k + 64] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group3_table[n][1]) >> 1;
+ s[k + 64 + 1] = ((INT32) m->iup.cs_factor[i][k + 1] * m->iup.group3_table[n][1]) >> 1;
+ s[k + 128] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group3_table[n][2]) >> 1;
+ s[k + 128 + 1] = ((INT32) m->iup.cs_factor[i][k + 1] * m->iup.group3_table[n][2]) >> 1;
+ k++; /* skip right chan dispatch */
+ goto dispatch;
+ case 18 + 2: /* 5 levels grouped 7 bits */
+ n = load(m,7);
+ s[k] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group5_table[n][0]) >> 2;
+ s[k + 1] = ((INT32) m->iup.cs_factor[i][k + 1] * m->iup.group5_table[n][0]) >> 2;
+ s[k + 64] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group5_table[n][1]) >> 2;
+ s[k + 64 + 1] = ((INT32) m->iup.cs_factor[i][k + 1] * m->iup.group5_table[n][1]) >> 2;
+ s[k + 128] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group5_table[n][2]) >> 2;
+ s[k + 128 + 1] = ((INT32) m->iup.cs_factor[i][k + 1] * m->iup.group5_table[n][2]) >> 2;
+ k++; /* skip right chan dispatch */
+ goto dispatch;
+ case 18 + 3:
+ UNPACKJ_N(3) /* 7 levels */
+ case 18 + 4: /* 9 levels grouped 10 bits */
+ n = load(m,10);
+ s[k] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group9_table[n][0]) >> 3;
+ s[k + 1] = ((INT32) m->iup.cs_factor[i][k + 1] * m->iup.group9_table[n][0]) >> 3;
+ s[k + 64] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group9_table[n][1]) >> 3;
+ s[k + 64 + 1] = ((INT32) m->iup.cs_factor[i][k + 1] * m->iup.group9_table[n][1]) >> 3;
+ s[k + 128] = ((INT32) m->iup.cs_factor[i][k] * m->iup.group9_table[n][2]) >> 3;
+ s[k + 128 + 1] = ((INT32) m->iup.cs_factor[i][k + 1] * m->iup.group9_table[n][2]) >> 3;
+ k++; /* skip right chan dispatch */
+ goto dispatch;
+ case 18 + 5:
+ UNPACKJ_N(4) /* 15 levels */
+ case 18 + 6:
+ UNPACKJ_N(5) /* 31 levels */
+ case 18 + 7:
+ UNPACKJ_N(6) /* 63 levels */
+ case 18 + 8:
+ UNPACKJ_N(7) /* 127 levels */
+ case 18 + 9:
+ UNPACKJ_N(8) /* 255 levels */
+ case 18 + 10:
+ UNPACKJ_N(9) /* 511 levels */
+ case 18 + 11:
+ UNPACKJ_N(10) /* 1023 levels */
+ case 18 + 12:
+ UNPACKJ_N(11) /* 2047 levels */
+ case 18 + 13:
+ UNPACKJ_N(12) /* 4095 levels */
+ case 18 + 14:
+ UNPACKJ_N(13) /* 8191 levels */
+ case 18 + 15:
+ UNPACKJ_N(14) /* 16383 levels */
+ case 18 + 16:
+ UNPACKJ_N(15) /* 32767 levels */
+ case 18 + 17:
+ UNPACKJ_N(16) /* 65535 levels */
+/* -- end of dispatch -- */
+ case 37:
+ skip(m, m->iup.bit_skip);
+ case 36:
+ s += 3 * 64;
+ } /* end switch */
+ } /* end j loop */
+ } /* end i loop */
+
+
+}
+/*-------------------------------------------------------------------------*/
+static void unpack(MPEGI *m)
+{
+ int prot;
+
+/* at entry bit getter points at id, sync skipped by caller */
+
+ load(m,3); /* skip id and option (checked by init) */
+ prot = load(m,1); /* load prot bit */
+ load(m,6); /* skip to pad */
+ m->iup.pad = load(m,1);
+ load(m,1); /* skip to mode */
+ m->iup.stereo_sb = look_joint[load(m,4)];
+ if (prot)
+ load(m,4); /* skip to data */
+ else
+ load(m,20); /* skip crc */
+
+ unpack_ba(m); /* unpack bit allocation */
+ unpack_sfs(m); /* unpack scale factor selectors */
+ unpack_sf(m); /* unpack scale factor */
+ unpack_samp(m); /* unpack samples */
+
+
+}
+/*-------------------------------------------------------------------------*/
+IN_OUT i_audio_decode(MPEGI *m, unsigned char *bs, signed short *pcm)
+{
+ int sync;
+ IN_OUT in_out;
+
+ load_init(m,bs); /* initialize bit getter */
+/* test sync */
+ in_out.in_bytes = 0; /* assume fail */
+ in_out.out_bytes = 0;
+ sync = load(m,12);
+
+ if (sync != 0xFFF)
+ return in_out; /* sync fail */
+/*-----------*/
+ m->iup.unpack_routine();
+
+
+ m->iup.sbt(m->iup.sample, pcm, m->iup.nsbt);
+/*-----------*/
+ in_out.in_bytes = m->iup.framebytes + m->iup.pad;
+ in_out.out_bytes = m->iup.outbytes;
+ return in_out;
+}
+/*-------------------------------------------------------------------------*/
+#include "iupini.c" /* initialization */
+#include "iupL1.c" /* Layer 1 */
+/*-------------------------------------------------------------------------*/
diff --git a/codecs/mp3/src/iupL1.c b/codecs/mp3/src/iupL1.c
new file mode 100755
index 000000000..041c2a00b
--- /dev/null
+++ b/codecs/mp3/src/iupL1.c
@@ -0,0 +1,330 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** iupL1.c ***************************************************
+
+MPEG audio decoder Layer I mpeg1 and mpeg2
+should be portable ANSI C, should be endian independent
+
+icupL1 integer version of cupL1.c
+
+******************************************************************/
+/*======================================================================*/
+/* Read Only */
+static int bat_bit_masterL1[] =
+{
+ 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
+
+/*======================================================================*/
+static void unpack_baL1(MPEGI *m)
+{
+ int k;
+ int nstereo;
+ int n;
+
+ m->iup.bit_skip = 0;
+ nstereo = m->iup.stereo_sb;
+ for (k = 0; k < m->iup.nbatL1; k++)
+ {
+ mac_load_check(4);
+ n = m->iup.ballo[k] = m->iup.samp_dispatch[k] = mac_load(4);
+ if (k >= m->iup.nsb_limit)
+ m->iup.bit_skip += bat_bit_masterL1[m->iup.samp_dispatch[k]];
+ m->iup.c_value[k] = m->iup.look_c_valueL1[n];
+ m->iup.c_shift[k] = m->iup.look_c_shiftL1[n];
+ if (--nstereo < 0)
+ {
+ m->iup.ballo[k + 1] = m->iup.ballo[k];
+ m->iup.samp_dispatch[k] += 15; /* flag as joint */
+ m->iup.samp_dispatch[k + 1] = m->iup.samp_dispatch[k]; /* flag for sf */
+ m->iup.c_value[k + 1] = m->iup.c_value[k];
+ m->iup.c_shift[k + 1] = m->iup.c_shift[k];
+ k++;
+ }
+ }
+ m->iup.samp_dispatch[m->iup.nsb_limit] = 31; /* terminate the dispatcher with skip */
+ m->iup.samp_dispatch[k] = 30; /* terminate the dispatcher */
+
+}
+/*-------------------------------------------------------------------------*/
+static void unpack_sfL1(MPEGI *m) /* unpack scale factor */
+{ /* combine dequant and scale factors */
+ int i, n;
+ INT32 tmp; /* only reason tmp is 32 bit is to get 32 bit mult result */
+
+ for (i = 0; i < m->iup.nbatL1; i++)
+ {
+ if (m->iup.ballo[i])
+ {
+ mac_load_check(6);
+ tmp = m->iup.c_value[i];
+ n = m->iup.c_shift[i];
+ m->iup.cs_factorL1[i] = (tmp * m->iup.sf_table[mac_load(6)]) >> n;
+ }
+ }
+
+/*-- done --*/
+}
+/*-------------------------------------------------------------------------*/
+#define UNPACKL1_N(n) s[k] = (m->iup.cs_factorL1[k]*(load(m,n)-((1 << (n-1)) -1)))>>(n-1); \
+ goto dispatch;
+#define UNPACKL1J_N(n) tmp = (load(m,n)-((1 << (n-1)) -1)); \
+ s[k] = (m->iup.cs_factorL1[k]*tmp)>>(n-1); \
+ s[k+1] = (m->iup.cs_factorL1[k+1]*tmp)>>(n-1); \
+ k++; /* skip right chan dispatch */ \
+ goto dispatch;
+/*-------------------------------------------------------------------------*/
+static void unpack_sampL1(MPEGI *m) /* unpack samples */
+{
+ int j, k;
+ SAMPLEINT *s;
+ INT32 tmp;
+
+ s = m->iup.sample;
+ for (j = 0; j < 12; j++)
+ {
+ k = -1;
+ dispatch:switch (m->iup.samp_dispatch[++k])
+ {
+ case 0:
+ s[k] = 0;
+ goto dispatch;
+ case 1:
+ UNPACKL1_N(2) /* 3 levels */
+ case 2:
+ UNPACKL1_N(3) /* 7 levels */
+ case 3:
+ UNPACKL1_N(4) /* 15 levels */
+ case 4:
+ UNPACKL1_N(5) /* 31 levels */
+ case 5:
+ UNPACKL1_N(6) /* 63 levels */
+ case 6:
+ UNPACKL1_N(7) /* 127 levels */
+ case 7:
+ UNPACKL1_N(8) /* 255 levels */
+ case 8:
+ UNPACKL1_N(9) /* 511 levels */
+ case 9:
+ UNPACKL1_N(10) /* 1023 levels */
+ case 10:
+ UNPACKL1_N(11) /* 2047 levels */
+ case 11:
+ UNPACKL1_N(12) /* 4095 levels */
+ case 12:
+ UNPACKL1_N(13) /* 8191 levels */
+ case 13:
+ UNPACKL1_N(14) /* 16383 levels */
+ case 14:
+ UNPACKL1_N(15) /* 32767 levels */
+/* -- joint ---- */
+ case 15 + 0:
+ s[k + 1] = s[k] = 0;
+ k++; /* skip right chan dispatch */
+ goto dispatch;
+/* -- joint ---- */
+ case 15 + 1:
+ UNPACKL1J_N(2) /* 3 levels */
+ case 15 + 2:
+ UNPACKL1J_N(3) /* 7 levels */
+ case 15 + 3:
+ UNPACKL1J_N(4) /* 15 levels */
+ case 15 + 4:
+ UNPACKL1J_N(5) /* 31 levels */
+ case 15 + 5:
+ UNPACKL1J_N(6) /* 63 levels */
+ case 15 + 6:
+ UNPACKL1J_N(7) /* 127 levels */
+ case 15 + 7:
+ UNPACKL1J_N(8) /* 255 levels */
+ case 15 + 8:
+ UNPACKL1J_N(9) /* 511 levels */
+ case 15 + 9:
+ UNPACKL1J_N(10) /* 1023 levels */
+ case 15 + 10:
+ UNPACKL1J_N(11) /* 2047 levels */
+ case 15 + 11:
+ UNPACKL1J_N(12) /* 4095 levels */
+ case 15 + 12:
+ UNPACKL1J_N(13) /* 8191 levels */
+ case 15 + 13:
+ UNPACKL1J_N(14) /* 16383 levels */
+ case 15 + 14:
+ UNPACKL1J_N(15) /* 32767 levels */
+
+/* -- end of dispatch -- */
+ case 31:
+ skip(m, m->iup.bit_skip);
+ case 30:
+ s += 64;
+ } /* end switch */
+ } /* end j loop */
+
+/*-- done --*/
+}
+/*-------------------------------------------------------------------------*/
+static void unpackL1(MPEGI *m)
+{
+ int prot;
+
+/* at entry bit getter points at id, sync skipped by caller */
+
+ load(m,3); /* skip id and option (checked by init) */
+ prot = load(m,1); /* load prot bit */
+ load(m,6); /* skip to pad */
+ m->iup.pad = load(m,1) << 2;
+ load(m,1); /* skip to mode */
+ m->iup.stereo_sb = look_joint[load(m,4)];
+ if (prot)
+ load(m,4); /* skip to data */
+ else
+ load(m,20); /* skip crc */
+
+ unpack_baL1(m); /* unpack bit allocation */
+ unpack_sfL1(m); /* unpack scale factor */
+ unpack_sampL1(m); /* unpack samples */
+
+
+}
+/*-------------------------------------------------------------------------*/
+
+#ifdef _MSC_VER
+#pragma warning(disable: 4056)
+#endif
+
+int i_audio_decode_initL1(MPEGI *m, MPEG_HEAD * h, int framebytes_arg,
+ int reduction_code, int transform_code, int convert_code,
+ int freq_limit)
+{
+ int i, k;
+ long samprate;
+ int limit;
+ int stepbit;
+ long step;
+ int bit_code;
+
+/*--- sf table built by Layer II init ---*/
+
+ if (m->iup.first_pass_L1)
+ {
+ stepbit = 2;
+ step = 4;
+ for (i = 1; i < 16; i++)
+ {
+ m->iup.look_c_valueL1[i] = (int) (32768.0 * 2.0 / (step - 1));
+ m->iup.look_c_shiftL1[i] = 16 - stepbit;
+ stepbit++;
+ step <<= 1;
+ }
+ m->iup.first_pass_L1 = 0;
+ }
+
+ m->iup.unpack_routine = unpackL1;
+
+
+ transform_code = transform_code; /* not used, asm compatability */
+ bit_code = 0;
+ if (convert_code & 8)
+ bit_code = 1;
+ convert_code = convert_code & 3; /* higher bits used by dec8 freq cvt */
+ if (reduction_code < 0)
+ reduction_code = 0;
+ if (reduction_code > 2)
+ reduction_code = 2;
+ if (freq_limit < 1000)
+ freq_limit = 1000;
+
+
+ m->iup.framebytes = framebytes_arg;
+/* check if code handles */
+ if (h->option != 3)
+ return 0; /* layer I only */
+
+ m->iup.nbatL1 = 32;
+ m->iup.max_sb = m->iup.nbatL1;
+/*----- compute nsb_limit --------*/
+ samprate = sr_table[4 * h->id + h->sr_index];
+ m->iup.nsb_limit = (freq_limit * 64L + samprate / 2) / samprate;
+/*- caller limit -*/
+/*---- limit = 0.94*(32>>reduction_code); ----*/
+ limit = (32 >> reduction_code);
+ if (limit > 8)
+ limit--;
+ if (m->iup.nsb_limit > limit)
+ m->iup.nsb_limit = limit;
+ if (m->iup.nsb_limit > m->iup.max_sb)
+ m->iup.nsb_limit = m->iup.max_sb;
+
+ m->iup.outvalues = 384 >> reduction_code;
+ if (h->mode != 3)
+ { /* adjust for 2 channel modes */
+ m->iup.nbatL1 *= 2;
+ m->iup.max_sb *= 2;
+ m->iup.nsb_limit *= 2;
+ }
+
+/* set sbt function */
+ m->iup.nsbt = 12;
+ k = 1 + convert_code;
+ if (h->mode == 3)
+ {
+ k = 0;
+ }
+ m->iup.sbt = sbt_table[bit_code][reduction_code][k];
+ m->iup.outvalues *= out_chans[k];
+ if (bit_code != 0)
+ m->iup.outbytes = m->iup.outvalues;
+ else
+ m->iup.outbytes = sizeof(short) * m->iup.outvalues;
+
+ m->iup.decinfo.channels = out_chans[k];
+ m->iup.decinfo.outvalues = m->iup.outvalues;
+ m->iup.decinfo.samprate = samprate >> reduction_code;
+ if (bit_code != 0)
+ m->iup.decinfo.bits = 8;
+ else
+ m->iup.decinfo.bits = sizeof(short) * 8;
+
+ m->iup.decinfo.framebytes = m->iup.framebytes;
+ m->iup.decinfo.type = 0;
+
+
+/* clear sample buffer, unused sub bands must be 0 */
+ for (i = 0; i < 768; i++)
+ m->iup.sample[i] = 0;
+
+
+/* init sub-band transform */
+ i_sbt_init();
+
+ return 1;
+}
+
+#ifdef _MSC_VER
+#pragma warning(default: 4056)
+#endif
+
+/*---------------------------------------------------------*/
diff --git a/codecs/mp3/src/iupini.c b/codecs/mp3/src/iupini.c
new file mode 100755
index 000000000..83d5793b4
--- /dev/null
+++ b/codecs/mp3/src/iupini.c
@@ -0,0 +1,389 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/*=========================================================
+ initialization for iup.c - include to iup.c
+ mpeg audio decoder portable "c" integer
+
+
+mods 11/15/95 for Layer I
+
+mods 1/8/97 warnings
+
+=========================================================*/
+#include <limits.h>
+
+/* Read only */
+static long steps[18] =
+{
+ 0, 3, 5, 7, 9, 15, 31, 63, 127,
+ 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535};
+
+/* Read only */
+static int stepbits[18] =
+{
+ 0, 2, 3, 3, 4, 4, 5, 6, 7,
+ 8, 9, 10, 11, 12, 13, 14, 15, 16};
+
+/* ABCD_INDEX = lookqt[mode][sr_index][br_index] */
+/* -1 = invalid */
+/* Read only */
+static signed char lookqt[4][3][16] =
+{
+ {{1, -1, -1, -1, 2, -1, 2, 0, 0, 0, 1, 1, 1, 1, 1, -1}, /* 44ks stereo */
+ {0, -1, -1, -1, 2, -1, 2, 0, 0, 0, 0, 0, 0, 0, 0, -1}, /* 48ks */
+ {1, -1, -1, -1, 3, -1, 3, 0, 0, 0, 1, 1, 1, 1, 1, -1}}, /* 32ks */
+ {{1, -1, -1, -1, 2, -1, 2, 0, 0, 0, 1, 1, 1, 1, 1, -1}, /* 44ks joint stereo */
+ {0, -1, -1, -1, 2, -1, 2, 0, 0, 0, 0, 0, 0, 0, 0, -1}, /* 48ks */
+ {1, -1, -1, -1, 3, -1, 3, 0, 0, 0, 1, 1, 1, 1, 1, -1}}, /* 32ks */
+ {{1, -1, -1, -1, 2, -1, 2, 0, 0, 0, 1, 1, 1, 1, 1, -1}, /* 44ks dual chan */
+ {0, -1, -1, -1, 2, -1, 2, 0, 0, 0, 0, 0, 0, 0, 0, -1}, /* 48ks */
+ {1, -1, -1, -1, 3, -1, 3, 0, 0, 0, 1, 1, 1, 1, 1, -1}}, /* 32ks */
+ {{1, 2, 2, 0, 0, 0, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1}, /* 44ks single chan */
+ {0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1}, /* 48ks */
+ {1, 3, 3, 0, 0, 0, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1}}, /* 32ks */
+};
+
+/* Read only */
+static long sr_table[8] =
+{22050L, 24000L, 16000L, 1L,
+ 44100L, 48000L, 32000L, 1L};
+
+/* bit allocation table look up */
+/* table per mpeg spec tables 3b2a/b/c/d /e is mpeg2 */
+/* look_bat[abcd_index][4][16] */
+/* Read only */
+static unsigned char look_bat[5][4][16] =
+{
+/* LOOK_BATA */
+ {{0, 1, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17},
+ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17},
+ {0, 1, 2, 3, 4, 5, 6, 17, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 1, 2, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+/* LOOK_BATB */
+ {{0, 1, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17},
+ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17},
+ {0, 1, 2, 3, 4, 5, 6, 17, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 1, 2, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+/* LOOK_BATC */
+ {{0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 1, 2, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+/* LOOK_BATD */
+ {{0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 1, 2, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+/* LOOK_BATE */
+ {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 1, 2, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
+};
+
+/* look_nbat[abcd_index]][4] */
+/* Read only */
+static unsigned char look_nbat[5][4] =
+{
+ {3, 8, 12, 4},
+ {3, 8, 12, 7},
+ {2, 0, 6, 0},
+ {2, 0, 10, 0},
+ {4, 0, 7, 19},
+};
+
+
+void i_sbt_mono(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt_dual(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt_dual_mono(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt_dual_left(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt_dual_right(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt16_mono(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt16_dual(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt16_dual_mono(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt16_dual_left(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt16_dual_right(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt8_mono(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt8_dual(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt8_dual_mono(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt8_dual_left(SAMPLEINT * sample, short *pcm, int n);
+void i_sbt8_dual_right(SAMPLEINT * sample, short *pcm, int n);
+
+/*--- 8 bit output ---*/
+void i_sbtB_mono(SAMPLEINT * sample, unsigned char *pcm, int n);
+void i_sbtB_dual(SAMPLEINT * sample, unsigned char *pcm, int n);
+void i_sbtB_dual_mono(SAMPLEINT * sample, unsigned char *pcm, int n);
+void i_sbtB_dual_left(SAMPLEINT * sample, unsigned char *pcm, int n);
+void i_sbtB_dual_right(SAMPLEINT * sample, unsigned char *pcm, int n);
+void i_sbtB16_mono(SAMPLEINT * sample, unsigned char *pcm, int n);
+void i_sbtB16_dual(SAMPLEINT * sample, unsigned char *pcm, int n);
+void i_sbtB16_dual_mono(SAMPLEINT * sample, unsigned char *pcm, int n);
+void i_sbtB16_dual_left(SAMPLEINT * sample, unsigned char *pcm, int n);
+void i_sbtB16_dual_right(SAMPLEINT * sample, unsigned char *pcm, int n);
+void i_sbtB8_mono(SAMPLEINT * sample, unsigned char *pcm, int n);
+void i_sbtB8_dual(SAMPLEINT * sample, unsigned char *pcm, int n);
+void i_sbtB8_dual_mono(SAMPLEINT * sample, unsigned char *pcm, int n);
+void i_sbtB8_dual_left(SAMPLEINT * sample, unsigned char *pcm, int n);
+void i_sbtB8_dual_right(SAMPLEINT * sample, unsigned char *pcm, int n);
+
+
+/* Read Only */
+static SBT_FUNCTION sbt_table[2][3][5] =
+{
+ {{i_sbt_mono, i_sbt_dual, i_sbt_dual_mono, i_sbt_dual_left, i_sbt_dual_right},
+ {i_sbt16_mono, i_sbt16_dual, i_sbt16_dual_mono, i_sbt16_dual_left, i_sbt16_dual_right},
+ {i_sbt8_mono, i_sbt8_dual, i_sbt8_dual_mono, i_sbt8_dual_left, i_sbt8_dual_right}},
+
+ {{(SBT_FUNCTION) i_sbtB_mono,
+ (SBT_FUNCTION) i_sbtB_dual,
+ (SBT_FUNCTION) i_sbtB_dual_mono,
+ (SBT_FUNCTION) i_sbtB_dual_left,
+ (SBT_FUNCTION) i_sbtB_dual_right},
+ {(SBT_FUNCTION) i_sbtB16_mono,
+ (SBT_FUNCTION) i_sbtB16_dual,
+ (SBT_FUNCTION) i_sbtB16_dual_mono,
+ (SBT_FUNCTION) i_sbtB16_dual_left,
+ (SBT_FUNCTION) i_sbtB16_dual_right},
+ {(SBT_FUNCTION) i_sbtB8_mono,
+ (SBT_FUNCTION) i_sbtB8_dual,
+ (SBT_FUNCTION) i_sbtB8_dual_mono,
+ (SBT_FUNCTION) i_sbtB8_dual_left,
+ (SBT_FUNCTION) i_sbtB8_dual_right}},
+};
+/* Read Only */
+static int out_chans[5] =
+{1, 2, 1, 1, 1};
+
+/*---------------------------------------------------------*/
+
+#ifdef _MSC_VER
+#pragma warning(disable: 4056)
+#endif
+
+void i_mpeg_init(MPEGI *m)
+{
+ memset(&m->iup, 0, sizeof(m->iup));
+ m->iup.nsb_limit = 6;
+ m->iup.nbat[0] = 3;
+ m->iup.nbat[1] = 8;
+ m->iup.nbat[3] = 12;
+ m->iup.nbat[4] = 7;
+ m->iup.nsbt = 36;
+ m->iup.sbt = i_sbt_mono;
+ m->iup.unpack_routine = unpack;
+ m->iup.first_pass = 1;
+ m->iup.first_pass_L1 = 1;
+ m->iup.nbatL1 = 32;
+ m->iup.cs_factorL1 = m->iup.cs_factor[0];
+}
+
+static void table_init(MPEGI *m)
+{
+ int i, j;
+ int code;
+ int bits;
+ long tmp, sfmax;
+
+/*-- c_values (dequant) --*/
+ for (i = 1; i < 18; i++)
+ m->iup.look_c_value[i] = (int) (32768.0 * 2.0 / steps[i]);
+ for (i = 1; i < 18; i++)
+ m->iup.look_c_shift[i] = 16 - stepbits[i];
+
+/*-- scale factor table, scale by 32768 for 16 pcm output --*/
+ bits = min(8 * sizeof(SAMPLEINT), 8 * sizeof(m->iup.sf_table[0]));
+ tmp = 1L << (bits - 2);
+ sfmax = tmp + (tmp - 1);
+ for (i = 0; i < 64; i++)
+ {
+ tmp = (long) (32768.0 * 2.0 * pow(2.0, -i / 3.0));
+ if (tmp > sfmax)
+ tmp = sfmax;
+ m->iup.sf_table[i] = tmp;
+ }
+/*-- grouped 3 level lookup table 5 bit token --*/
+ for (i = 0; i < 32; i++)
+ {
+ code = i;
+ for (j = 0; j < 3; j++)
+ {
+ m->iup.group3_table[i][j] = (char) ((code % 3) - 1);
+ code /= 3;
+ }
+ }
+/*-- grouped 5 level lookup table 7 bit token --*/
+ for (i = 0; i < 128; i++)
+ {
+ code = i;
+ for (j = 0; j < 3; j++)
+ {
+ m->iup.group5_table[i][j] = (char) ((code % 5) - 2);
+ code /= 5;
+ }
+ }
+/*-- grouped 9 level lookup table 10 bit token --*/
+ for (i = 0; i < 1024; i++)
+ {
+ code = i;
+ for (j = 0; j < 3; j++)
+ {
+ m->iup.group9_table[i][j] = (short) ((code % 9) - 4);
+ code /= 9;
+ }
+ }
+
+
+}
+
+#ifdef _MSC_VER
+#pragma warning(default: 4056)
+#endif
+
+/*---------------------------------------------------------*/
+int i_audio_decode_initL1(MPEGI *m, MPEG_HEAD * h, int framebytes_arg,
+ int reduction_code, int transform_code, int convert_code,
+ int freq_limit);
+void i_sbt_init();
+
+/*---------------------------------------------------------*/
+/* mpeg_head defined in mhead.h frame bytes is without pad */
+int i_audio_decode_init(MPEGI *m, MPEG_HEAD * h, int framebytes_arg,
+ int reduction_code, int transform_code, int convert_code,
+ int freq_limit)
+{
+ int i, j, k;
+ int abcd_index;
+ long samprate;
+ int limit;
+ int bit_code;
+
+ if (m->iup.first_pass)
+ {
+ table_init(m);
+ m->iup.first_pass = 0;
+ }
+
+/* check if code handles */
+ if (h->option == 3) /* layer I */
+ return i_audio_decode_initL1(m, h, framebytes_arg,
+ reduction_code, transform_code, convert_code, freq_limit);
+ if (h->option != 2)
+ return 0; /* layer II only */
+
+
+ m->iup.unpack_routine = unpack;
+
+ transform_code = transform_code; /* not used, asm compatability */
+ bit_code = 0;
+ if (convert_code & 8)
+ bit_code = 1;
+ convert_code = convert_code & 3; /* higher bits used by dec8 freq cvt */
+ if (reduction_code < 0)
+ reduction_code = 0;
+ if (reduction_code > 2)
+ reduction_code = 2;
+ if (freq_limit < 1000)
+ freq_limit = 1000;
+
+
+ m->iup.framebytes = framebytes_arg;
+
+/* compute abcd index for bit allo table selection */
+ if (h->id) /* mpeg 1 */
+ abcd_index = lookqt[h->mode][h->sr_index][h->br_index];
+ else
+ abcd_index = 4; /* mpeg 2 */
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 16; j++)
+ m->iup.bat[i][j] = look_bat[abcd_index][i][j];
+ for (i = 0; i < 4; i++)
+ m->iup.nbat[i] = look_nbat[abcd_index][i];
+ m->iup.max_sb = m->iup.nbat[0] + m->iup.nbat[1] + m->iup.nbat[2] + m->iup.nbat[3];
+/*----- compute nsb_limit --------*/
+ samprate = sr_table[4 * h->id + h->sr_index];
+ m->iup.nsb_limit = (freq_limit * 64L + samprate / 2) / samprate;
+/*- caller limit -*/
+/*---- limit = 0.94*(32>>reduction_code); ----*/
+ limit = (32 >> reduction_code);
+ if (limit > 8)
+ limit--;
+ if (m->iup.nsb_limit > limit)
+ m->iup.nsb_limit = limit;
+ if (m->iup.nsb_limit > m->iup.max_sb)
+ m->iup.nsb_limit = m->iup.max_sb;
+
+ m->iup.outvalues = 1152 >> reduction_code;
+ if (h->mode != 3)
+ { /* adjust for 2 channel modes */
+ for (i = 0; i < 4; i++)
+ m->iup.nbat[i] *= 2;
+ m->iup.max_sb *= 2;
+ m->iup.nsb_limit *= 2;
+ }
+
+/* set sbt function */
+ m->iup.nsbt = 36;
+ k = 1 + convert_code;
+ if (h->mode == 3)
+ {
+ k = 0;
+ }
+ m->iup.sbt = sbt_table[bit_code][reduction_code][k];
+ m->iup.outvalues *= out_chans[k];
+ if (bit_code != 0)
+ m->iup.outbytes = m->iup.outvalues;
+ else
+ m->iup.outbytes = sizeof(short) * m->iup.outvalues;
+
+ m->iup.decinfo.channels = out_chans[k];
+ m->iup.decinfo.outvalues = m->iup.outvalues;
+ m->iup.decinfo.samprate = samprate >> reduction_code;
+ if (bit_code != 0)
+ m->iup.decinfo.bits = 8;
+ else
+ m->iup.decinfo.bits = sizeof(short) * 8;
+
+ m->iup.decinfo.framebytes = m->iup.framebytes;
+ m->iup.decinfo.type = 0;
+
+
+/* clear sample buffer, unused sub bands must be 0 */
+ for (i = 0; i < 2304; i++)
+ m->iup.sample[i] = 0;
+
+
+/* init sub-band transform */
+ i_sbt_init();
+
+ return 1;
+}
+/*---------------------------------------------------------*/
+void i_audio_decode_info(MPEGI *m, DEC_INFO * info)
+{
+ *info = m->iup.decinfo; /* info return, call after init */
+}
+/*---------------------------------------------------------*/
diff --git a/codecs/mp3/src/iwinQ.c b/codecs/mp3/src/iwinQ.c
new file mode 100755
index 000000000..fae859b99
--- /dev/null
+++ b/codecs/mp3/src/iwinQ.c
@@ -0,0 +1,712 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998 Emusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/*----- iwinq.c ---------------------------------------------------
+
+portable c
+mpeg1/2 Layer II audio decode
+
+conditional include to iwinm.c
+
+quick integer window
+
+mods 1/8/97 warnings
+
+--------------------------------------------------------------*/
+/*--------------------------------------------------------------------*/
+void i_window(WININT * vbuf, int vb_ptr, short *pcm)
+{
+ int i, j;
+ unsigned int si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+/*-- first 16 --*/
+ si = (vb_ptr + (16 + 3 * 64)) & 511;
+ bx = (si + (32 + 512 - 3 * 64 + 2 * 64)) & 511;
+ coef = iwincoef;
+ for (i = 0; i < 16; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si = (si + 64) & 511;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si = (si + (5 * 64 + 1)) & 511;
+ bx = (bx + (64 + 4 * 64 - 1)) & 511;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (short) sum;
+ }
+/*-- special case --*/
+ bx = (bx + (512 - 64)) & 511;
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (short) sum;
+
+/*-- last 15 --*/
+ coef = iwincoef + 111; /* back pass through coefs */
+ si = (si + (512 - 3 * 64 + 2 * 64 - 1)) & 511;
+ bx = (bx + (64 + 3 * 64 + 2 * 64 + 1)) & 511;
+ for (i = 0; i < 15; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si = (si + 64) & 511;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si = (si + (64 - 1 + 4 * 64)) & 511;
+ bx = (bx + (5 * 64 + 1)) & 511;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (short) sum;
+ }
+}
+/*------------------------------------------------------------*/
+void i_window_dual(WININT * vbuf, int vb_ptr, short *pcm)
+{
+/* dual window interleaves output */
+ int i, j;
+ unsigned int si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+/*-- first 16 --*/
+ si = (vb_ptr + (16 + 3 * 64)) & 511;
+ bx = (si + (32 + 512 - 3 * 64 + 2 * 64)) & 511;
+ coef = iwincoef;
+ for (i = 0; i < 16; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si = (si + 64) & 511;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si = (si + (5 * 64 + 1)) & 511;
+ bx = (bx + (64 + 4 * 64 - 1)) & 511;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+ }
+/*-- special case --*/
+ bx = (bx + (512 - 64)) & 511;
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+
+/*-- last 15 --*/
+ coef = iwincoef + 111; /* back pass through coefs */
+ si = (si + (512 - 3 * 64 + 2 * 64 - 1)) & 511;
+ bx = (bx + (64 + 3 * 64 + 2 * 64 + 1)) & 511;
+ for (i = 0; i < 15; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si = (si + 64) & 511;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si = (si + (64 - 1 + 4 * 64)) & 511;
+ bx = (bx + (5 * 64 + 1)) & 511;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+ }
+}
+/*------------------------------------------------------------*/
+void i_window_dual_right(WININT * vbuf, int vb_ptr, short *pcm)
+{
+/* right identical to dual, for asm */
+/* dual window interleaves output */
+ int i, j;
+ unsigned int si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+/*-- first 16 --*/
+ si = (vb_ptr + (16 + 3 * 64)) & 511;
+ bx = (si + (32 + 512 - 3 * 64 + 2 * 64)) & 511;
+ coef = iwincoef;
+ for (i = 0; i < 16; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si = (si + 64) & 511;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si = (si + (5 * 64 + 1)) & 511;
+ bx = (bx + (64 + 4 * 64 - 1)) & 511;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+ }
+/*-- special case --*/
+ bx = (bx + (512 - 64)) & 511;
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+
+/*-- last 15 --*/
+ coef = iwincoef + 111; /* back pass through coefs */
+ si = (si + (512 - 3 * 64 + 2 * 64 - 1)) & 511;
+ bx = (bx + (64 + 3 * 64 + 2 * 64 + 1)) & 511;
+ for (i = 0; i < 15; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si = (si + 64) & 511;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si = (si + (64 - 1 + 4 * 64)) & 511;
+ bx = (bx + (5 * 64 + 1)) & 511;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+ }
+}
+/*------------------------------------------------------------*/
+/*------------------------------------------------------------*/
+/*------------------- 16 pt window ------------------------------*/
+void i_window16(WININT * vbuf, int vb_ptr, short *pcm)
+{
+ int i, j;
+ unsigned char si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+
+/*-- first 8 --*/
+ si = (unsigned char) (vb_ptr + 8 + 3 * 32);
+ bx = (unsigned char) (si + (16 + 256 - 3 * 32 + 2 * 32));
+ coef = iwincoef;
+ for (i = 0; i < 8; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx += 32;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si += 32;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si += (5 * 32 + 1);
+ bx += (32 + 4 * 32 - 1);
+ coef += 7;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (short) sum;
+ }
+/*-- special case --*/
+ bx += (256 - 32);
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx += 32;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (short) sum;
+
+/*-- last 7 --*/
+ coef = iwincoef + (111 - 7); /* back pass through coefs */
+ si += (256 + -3 * 32 + 2 * 32 - 1);
+ bx += (32 + 3 * 32 + 2 * 32 + 1);
+ for (i = 0; i < 7; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si += 32;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx += 32;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si += (32 - 1 + 4 * 32);
+ bx += (5 * 32 + 1);
+ coef -= 7;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (short) sum;
+ }
+}
+/*--------------- 16 pt dual window (interleaved output) -----------------*/
+void i_window16_dual(WININT * vbuf, int vb_ptr, short *pcm)
+{
+ int i, j;
+ unsigned char si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+
+/*-- first 8 --*/
+ si = (unsigned char) (vb_ptr + 8 + 3 * 32);
+ bx = (unsigned char) (si + (16 + 256 - 3 * 32 + 2 * 32));
+ coef = iwincoef;
+ for (i = 0; i < 8; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx += 32;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si += 32;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si += (5 * 32 + 1);
+ bx += (32 + 4 * 32 - 1);
+ coef += 7;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+ }
+/*-- special case --*/
+ bx += (256 - 32);
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx += 32;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+
+/*-- last 7 --*/
+ coef = iwincoef + (111 - 7); /* back pass through coefs */
+ si += (256 + -3 * 32 + 2 * 32 - 1);
+ bx += (32 + 3 * 32 + 2 * 32 + 1);
+ for (i = 0; i < 7; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si += 32;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx += 32;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si += (32 - 1 + 4 * 32);
+ bx += (5 * 32 + 1);
+ coef -= 7;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+ }
+}
+/*--------------- 16 pt dual window (interleaved output) -----------------*/
+void i_window16_dual_right(WININT * vbuf, int vb_ptr, short *pcm)
+{
+/* right identical to dual, for asm */
+ int i, j;
+ unsigned char si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+
+/*-- first 8 --*/
+ si = (unsigned char) (vb_ptr + 8 + 3 * 32);
+ bx = (unsigned char) (si + (16 + 256 - 3 * 32 + 2 * 32));
+ coef = iwincoef;
+ for (i = 0; i < 8; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx += 32;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si += 32;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si += (5 * 32 + 1);
+ bx += (32 + 4 * 32 - 1);
+ coef += 7;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+ }
+/*-- special case --*/
+ bx += (256 - 32);
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx += 32;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+
+/*-- last 7 --*/
+ coef = iwincoef + (111 - 7); /* back pass through coefs */
+ si += (256 + -3 * 32 + 2 * 32 - 1);
+ bx += (32 + 3 * 32 + 2 * 32 + 1);
+ for (i = 0; i < 7; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si += 32;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx += 32;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si += (32 - 1 + 4 * 32);
+ bx += (5 * 32 + 1);
+ coef -= 7;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+ }
+}
+/*------------------------------------------------------------*/
+/*------------------- 8 pt window ------------------------------*/
+void i_window8(WININT * vbuf, int vb_ptr, short *pcm)
+{
+ int i, j;
+ unsigned int si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+/*-- first 4 --*/
+ si = (vb_ptr + (4 + 3 * 16)) & 127;
+ bx = (si + (8 + 128 - 3 * 16 + 2 * 16)) & 127;
+ coef = iwincoef;
+ for (i = 0; i < 4; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si = (si + 16) & 127;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si = (si + (5 * 16 + 1)) & 127;
+ bx = (bx + (16 + 4 * 16 - 1)) & 127;
+ coef += (3 * 7);
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (short) sum;
+ }
+/*-- special case --*/
+ bx = (bx + (128 - 16)) & 127;
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (short) sum;
+
+/*-- last 3 --*/
+ coef = iwincoef + (111 - 3 * 7); /* back pass through coefs */
+ si = (si + (128 - 3 * 16 + 2 * 16 - 1)) & 127;
+ bx = (bx + (16 + 3 * 16 + 2 * 16 + 1)) & 127;
+ for (i = 0; i < 3; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si = (si + 16) & 127;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si = (si + (16 - 1 + 4 * 16)) & 127;
+ bx = (bx + (5 * 16 + 1)) & 127;
+ coef -= (3 * 7);
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (short) sum;
+ }
+}
+/*--------------- 8 pt dual window (interleaved output) --------------*/
+void i_window8_dual(WININT * vbuf, int vb_ptr, short *pcm)
+{
+ int i, j;
+ unsigned int si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+/*-- first 4 --*/
+ si = (vb_ptr + (4 + 3 * 16)) & 127;
+ bx = (si + (8 + 128 - 3 * 16 + 2 * 16)) & 127;
+ coef = iwincoef;
+ for (i = 0; i < 4; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si = (si + 16) & 127;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si = (si + (5 * 16 + 1)) & 127;
+ bx = (bx + (16 + 4 * 16 - 1)) & 127;
+ coef += (3 * 7);
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+ }
+/*-- special case --*/
+ bx = (bx + (128 - 16)) & 127;
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+
+/*-- last 3 --*/
+ coef = iwincoef + (111 - 3 * 7); /* back pass through coefs */
+ si = (si + (128 - 3 * 16 + 2 * 16 - 1)) & 127;
+ bx = (bx + (16 + 3 * 16 + 2 * 16 + 1)) & 127;
+ for (i = 0; i < 3; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si = (si + 16) & 127;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si = (si + (16 - 1 + 4 * 16)) & 127;
+ bx = (bx + (5 * 16 + 1)) & 127;
+ coef -= (3 * 7);
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+ }
+}
+/*------------------------------------------------------------*/
+/*--------------- 8 pt dual window (interleaved output) --------------*/
+void i_window8_dual_right(WININT * vbuf, int vb_ptr, short *pcm)
+{
+ int i, j;
+ unsigned int si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+/* right identical to dual, for asm */
+
+/*-- first 4 --*/
+ si = (vb_ptr + (4 + 3 * 16)) & 127;
+ bx = (si + (8 + 128 - 3 * 16 + 2 * 16)) & 127;
+ coef = iwincoef;
+ for (i = 0; i < 4; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si = (si + 16) & 127;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si = (si + (5 * 16 + 1)) & 127;
+ bx = (bx + (16 + 4 * 16 - 1)) & 127;
+ coef += (3 * 7);
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+ }
+/*-- special case --*/
+ bx = (bx + (128 - 16)) & 127;
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+
+/*-- last 3 --*/
+ coef = iwincoef + (111 - 3 * 7); /* back pass through coefs */
+ si = (si + (128 - 3 * 16 + 2 * 16 - 1)) & 127;
+ bx = (bx + (16 + 3 * 16 + 2 * 16 + 1)) & 127;
+ for (i = 0; i < 3; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si = (si + 16) & 127;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si = (si + (16 - 1 + 4 * 16)) & 127;
+ bx = (bx + (5 * 16 + 1)) & 127;
+ coef -= (3 * 7);
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (short) sum;
+ pcm += 2;
+ }
+}
+/*--------------------------------------------------------*/
diff --git a/codecs/mp3/src/iwinbQ.c b/codecs/mp3/src/iwinbQ.c
new file mode 100755
index 000000000..15c573a16
--- /dev/null
+++ b/codecs/mp3/src/iwinbQ.c
@@ -0,0 +1,712 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/*----- iwinbq.c ---------------------------------------------------
+
+portable c
+mpeg1/2 Layer I/II audio decode
+
+conditional include to iwinm.c
+
+quick integer window - 8 bit output
+
+mods 1/8/97 warnings
+
+--------------------------------------------------------------*/
+/*--------------------------------------------------------------------*/
+void i_windowB(WININT * vbuf, int vb_ptr, unsigned char *pcm)
+{
+ int i, j;
+ unsigned int si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+/*-- first 16 --*/
+ si = (vb_ptr + (16 + 3 * 64)) & 511;
+ bx = (si + (32 + 512 - 3 * 64 + 2 * 64)) & 511;
+ coef = iwincoef;
+ for (i = 0; i < 16; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si = (si + 64) & 511;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si = (si + (5 * 64 + 1)) & 511;
+ bx = (bx + (64 + 4 * 64 - 1)) & 511;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (unsigned char) ((sum >> 8) ^ 0x80);
+ }
+/*-- special case --*/
+ bx = (bx + (512 - 64)) & 511;
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (unsigned char) ((sum >> 8) ^ 0x80);
+
+/*-- last 15 --*/
+ coef = iwincoef + 111; /* back pass through coefs */
+ si = (si + (512 - 3 * 64 + 2 * 64 - 1)) & 511;
+ bx = (bx + (64 + 3 * 64 + 2 * 64 + 1)) & 511;
+ for (i = 0; i < 15; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si = (si + 64) & 511;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si = (si + (64 - 1 + 4 * 64)) & 511;
+ bx = (bx + (5 * 64 + 1)) & 511;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (unsigned char) ((sum >> 8) ^ 0x80);
+ }
+}
+/*------------------------------------------------------------*/
+void i_windowB_dual(WININT * vbuf, int vb_ptr, unsigned char *pcm)
+{
+/* dual window interleaves output */
+ int i, j;
+ unsigned int si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+/*-- first 16 --*/
+ si = (vb_ptr + (16 + 3 * 64)) & 511;
+ bx = (si + (32 + 512 - 3 * 64 + 2 * 64)) & 511;
+ coef = iwincoef;
+ for (i = 0; i < 16; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si = (si + 64) & 511;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si = (si + (5 * 64 + 1)) & 511;
+ bx = (bx + (64 + 4 * 64 - 1)) & 511;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+ }
+/*-- special case --*/
+ bx = (bx + (512 - 64)) & 511;
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+
+/*-- last 15 --*/
+ coef = iwincoef + 111; /* back pass through coefs */
+ si = (si + (512 - 3 * 64 + 2 * 64 - 1)) & 511;
+ bx = (bx + (64 + 3 * 64 + 2 * 64 + 1)) & 511;
+ for (i = 0; i < 15; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si = (si + 64) & 511;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si = (si + (64 - 1 + 4 * 64)) & 511;
+ bx = (bx + (5 * 64 + 1)) & 511;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+ }
+}
+/*------------------------------------------------------------*/
+void i_windowB_dual_right(WININT * vbuf, int vb_ptr, unsigned char *pcm)
+{
+/* right identical to dual, for asm */
+/* dual window interleaves output */
+ int i, j;
+ unsigned int si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+/*-- first 16 --*/
+ si = (vb_ptr + (16 + 3 * 64)) & 511;
+ bx = (si + (32 + 512 - 3 * 64 + 2 * 64)) & 511;
+ coef = iwincoef;
+ for (i = 0; i < 16; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si = (si + 64) & 511;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si = (si + (5 * 64 + 1)) & 511;
+ bx = (bx + (64 + 4 * 64 - 1)) & 511;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+ }
+/*-- special case --*/
+ bx = (bx + (512 - 64)) & 511;
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+
+/*-- last 15 --*/
+ coef = iwincoef + 111; /* back pass through coefs */
+ si = (si + (512 - 3 * 64 + 2 * 64 - 1)) & 511;
+ bx = (bx + (64 + 3 * 64 + 2 * 64 + 1)) & 511;
+ for (i = 0; i < 15; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si = (si + 64) & 511;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx = (bx + 64) & 511;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si = (si + (64 - 1 + 4 * 64)) & 511;
+ bx = (bx + (5 * 64 + 1)) & 511;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+ }
+}
+/*------------------------------------------------------------*/
+/*------------------------------------------------------------*/
+/*------------------- 16 pt window ------------------------------*/
+void i_windowB16(WININT * vbuf, int vb_ptr, unsigned char *pcm)
+{
+ int i, j;
+ unsigned char si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+
+/*-- first 8 --*/
+ si = (unsigned char) (vb_ptr + 8 + 3 * 32);
+ bx = (unsigned char) (si + (16 + 256 - 3 * 32 + 2 * 32));
+ coef = iwincoef;
+ for (i = 0; i < 8; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx += 32;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si += 32;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si += (5 * 32 + 1);
+ bx += (32 + 4 * 32 - 1);
+ coef += 7;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (unsigned char) ((sum >> 8) ^ 0x80);
+ }
+/*-- special case --*/
+ bx += (256 - 32);
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx += 32;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (unsigned char) ((sum >> 8) ^ 0x80);
+
+/*-- last 7 --*/
+ coef = iwincoef + (111 - 7); /* back pass through coefs */
+ si += (256 + -3 * 32 + 2 * 32 - 1);
+ bx += (32 + 3 * 32 + 2 * 32 + 1);
+ for (i = 0; i < 7; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si += 32;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx += 32;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si += (32 - 1 + 4 * 32);
+ bx += (5 * 32 + 1);
+ coef -= 7;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (unsigned char) ((sum >> 8) ^ 0x80);
+ }
+}
+/*--------------- 16 pt dual window (interleaved output) -----------------*/
+void i_windowB16_dual(WININT * vbuf, int vb_ptr, unsigned char *pcm)
+{
+ int i, j;
+ unsigned char si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+
+/*-- first 8 --*/
+ si = (unsigned char) (vb_ptr + 8 + 3 * 32);
+ bx = (unsigned char) (si + (16 + 256 - 3 * 32 + 2 * 32));
+ coef = iwincoef;
+ for (i = 0; i < 8; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx += 32;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si += 32;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si += (5 * 32 + 1);
+ bx += (32 + 4 * 32 - 1);
+ coef += 7;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+ }
+/*-- special case --*/
+ bx += (256 - 32);
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx += 32;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+
+/*-- last 7 --*/
+ coef = iwincoef + (111 - 7); /* back pass through coefs */
+ si += (256 + -3 * 32 + 2 * 32 - 1);
+ bx += (32 + 3 * 32 + 2 * 32 + 1);
+ for (i = 0; i < 7; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si += 32;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx += 32;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si += (32 - 1 + 4 * 32);
+ bx += (5 * 32 + 1);
+ coef -= 7;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+ }
+}
+/*--------------- 16 pt dual window (interleaved output) -----------------*/
+void i_windowB16_dual_right(WININT * vbuf, int vb_ptr, unsigned char *pcm)
+{
+/* right identical to dual, for asm */
+ int i, j;
+ unsigned char si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+
+/*-- first 8 --*/
+ si = (unsigned char) (vb_ptr + 8 + 3 * 32);
+ bx = (unsigned char) (si + (16 + 256 - 3 * 32 + 2 * 32));
+ coef = iwincoef;
+ for (i = 0; i < 8; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx += 32;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si += 32;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si += (5 * 32 + 1);
+ bx += (32 + 4 * 32 - 1);
+ coef += 7;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+ }
+/*-- special case --*/
+ bx += (256 - 32);
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx += 32;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+
+/*-- last 7 --*/
+ coef = iwincoef + (111 - 7); /* back pass through coefs */
+ si += (256 + -3 * 32 + 2 * 32 - 1);
+ bx += (32 + 3 * 32 + 2 * 32 + 1);
+ for (i = 0; i < 7; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si += 32;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx += 32;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si += (32 - 1 + 4 * 32);
+ bx += (5 * 32 + 1);
+ coef -= 7;
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+ }
+}
+/*------------------------------------------------------------*/
+/*------------------- 8 pt window ------------------------------*/
+void i_windowB8(WININT * vbuf, int vb_ptr, unsigned char *pcm)
+{
+ int i, j;
+ unsigned int si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+/*-- first 4 --*/
+ si = (vb_ptr + (4 + 3 * 16)) & 127;
+ bx = (si + (8 + 128 - 3 * 16 + 2 * 16)) & 127;
+ coef = iwincoef;
+ for (i = 0; i < 4; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si = (si + 16) & 127;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si = (si + (5 * 16 + 1)) & 127;
+ bx = (bx + (16 + 4 * 16 - 1)) & 127;
+ coef += (3 * 7);
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (unsigned char) ((sum >> 8) ^ 0x80);
+ }
+/*-- special case --*/
+ bx = (bx + (128 - 16)) & 127;
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (unsigned char) ((sum >> 8) ^ 0x80);
+
+/*-- last 3 --*/
+ coef = iwincoef + (111 - 3 * 7); /* back pass through coefs */
+ si = (si + (128 - 3 * 16 + 2 * 16 - 1)) & 127;
+ bx = (bx + (16 + 3 * 16 + 2 * 16 + 1)) & 127;
+ for (i = 0; i < 3; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si = (si + 16) & 127;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si = (si + (16 - 1 + 4 * 16)) & 127;
+ bx = (bx + (5 * 16 + 1)) & 127;
+ coef -= (3 * 7);
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm++ = (unsigned char) ((sum >> 8) ^ 0x80);
+ }
+}
+/*--------------- 8 pt dual window (interleaved output) --------------*/
+void i_windowB8_dual(WININT * vbuf, int vb_ptr, unsigned char *pcm)
+{
+ int i, j;
+ unsigned int si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+/*-- first 4 --*/
+ si = (vb_ptr + (4 + 3 * 16)) & 127;
+ bx = (si + (8 + 128 - 3 * 16 + 2 * 16)) & 127;
+ coef = iwincoef;
+ for (i = 0; i < 4; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si = (si + 16) & 127;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si = (si + (5 * 16 + 1)) & 127;
+ bx = (bx + (16 + 4 * 16 - 1)) & 127;
+ coef += (3 * 7);
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+ }
+/*-- special case --*/
+ bx = (bx + (128 - 16)) & 127;
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+
+/*-- last 3 --*/
+ coef = iwincoef + (111 - 3 * 7); /* back pass through coefs */
+ si = (si + (128 - 3 * 16 + 2 * 16 - 1)) & 127;
+ bx = (bx + (16 + 3 * 16 + 2 * 16 + 1)) & 127;
+ for (i = 0; i < 3; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si = (si + 16) & 127;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si = (si + (16 - 1 + 4 * 16)) & 127;
+ bx = (bx + (5 * 16 + 1)) & 127;
+ coef -= (3 * 7);
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+ }
+}
+/*------------------------------------------------------------*/
+/*--------------- 8 pt dual window (interleaved output) --------------*/
+void i_windowB8_dual_right(WININT * vbuf, int vb_ptr, unsigned char *pcm)
+{
+ int i, j;
+ unsigned int si, bx;
+ WINCOEF *coef;
+ INT32 sum;
+
+/* right identical to dual, for asm */
+
+/*-- first 4 --*/
+ si = (vb_ptr + (4 + 3 * 16)) & 127;
+ bx = (si + (8 + 128 - 3 * 16 + 2 * 16)) & 127;
+ coef = iwincoef;
+ for (i = 0; i < 4; i++)
+ {
+ sum = -WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[si], (*coef++));
+ si = (si + 16) & 127;
+ sum -= WINMULT(vbuf[bx], (*coef++));
+ }
+ si = (si + (5 * 16 + 1)) & 127;
+ bx = (bx + (16 + 4 * 16 - 1)) & 127;
+ coef += (3 * 7);
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+ }
+/*-- special case --*/
+ bx = (bx + (128 - 16)) & 127;
+ sum = WINMULT(vbuf[bx], (*coef++));
+ for (j = 0; j < 3; j++)
+ {
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[bx], (*coef++));
+ }
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+
+/*-- last 3 --*/
+ coef = iwincoef + (111 - 3 * 7); /* back pass through coefs */
+ si = (si + (128 - 3 * 16 + 2 * 16 - 1)) & 127;
+ bx = (bx + (16 + 3 * 16 + 2 * 16 + 1)) & 127;
+ for (i = 0; i < 3; i++)
+ {
+ sum = WINMULT(vbuf[si], (*coef--));
+ for (j = 0; j < 3; j++)
+ {
+ si = (si + 16) & 127;
+ sum += WINMULT(vbuf[bx], (*coef--));
+ bx = (bx + 16) & 127;
+ sum += WINMULT(vbuf[si], (*coef--));
+ }
+ si = (si + (16 - 1 + 4 * 16)) & 127;
+ bx = (bx + (5 * 16 + 1)) & 127;
+ coef -= (3 * 7);
+ sum >>= WINBITS;
+ if (sum > 32767)
+ sum = 32767;
+ else if (sum < -32768)
+ sum = -32768;
+ *pcm = (unsigned char) ((sum >> 8) ^ 0x80);
+ pcm += 2;
+ }
+}
+/*--------------------------------------------------------*/
diff --git a/codecs/mp3/src/iwinm.c b/codecs/mp3/src/iwinm.c
new file mode 100755
index 000000000..6bd12b627
--- /dev/null
+++ b/codecs/mp3/src/iwinm.c
@@ -0,0 +1,64 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** iwinm.c ***************************************************
+
+MPEG audio decoder, window master
+portable C integer version of cwinm.c
+
+
+
+******************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#include "itype.h"
+
+/*-------------------------------------------------------------------------*/
+/* public vbuf's */
+WININT vbuf[512];
+WININT vbuf2[512];
+
+/*-- integer point window coefs ---*/
+/*-- quick uses only first 116 ----*/
+static WINCOEF iwincoef[264];
+
+/*==================================================================*/
+WINCOEF *i_wincoef_addr()
+{
+ return iwincoef;
+}
+/*-------------------------------------------------------------------*/
+#ifdef FULL_INTEGER
+#include "iwin.c"
+#include "iwinb.c"
+#else
+#include "iwinQ.c"
+#include "iwinbQ.c"
+#endif
+/*-------------------------------------------------------------------*/
diff --git a/codecs/mp3/src/l3dq.c b/codecs/mp3/src/l3dq.c
new file mode 100755
index 000000000..3ee0764aa
--- /dev/null
+++ b/codecs/mp3/src/l3dq.c
@@ -0,0 +1,256 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** quant.c ***************************************************
+ Layer III dequant
+
+ does reordering of short blocks
+
+ mod 8/19/98 decode 22 sf bands
+
+******************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#include <string.h>
+#include "L3.h"
+#include "mhead.h"
+#include "protos.h"
+
+
+/*----------
+static struct {
+int l[23];
+int s[14];} sfBandTable[3] =
+{{{0,4,8,12,16,20,24,30,36,44,52,62,74,90,110,134,162,196,238,288,342,418,576},
+ {0,4,8,12,16,22,30,40,52,66,84,106,136,192}},
+{{0,4,8,12,16,20,24,30,36,42,50,60,72,88,106,128,156,190,230,276,330,384,576},
+ {0,4,8,12,16,22,28,38,50,64,80,100,126,192}},
+{{0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576},
+ {0,4,8,12,16,22,30,42,58,78,104,138,180,192}}};
+----------*/
+
+/*--------------------------------*/
+static int pretab[2][22] =
+{
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0},
+};
+
+
+/* 8 bit plus 2 lookup x = pow(2.0, 0.25*(global_gain-210)) */
+/* two extra slots to do 1/sqrt(2) scaling for ms */
+/* 4 extra slots to do 1/2 scaling for cvt to mono */
+
+/*-------- scaling lookup
+x = pow(2.0, -0.5*(1+scalefact_scale)*scalefac + preemp)
+look_scale[scalefact_scale][preemp][scalefac]
+-----------------------*/
+#if 0
+typedef float LS[4][32];
+#endif
+
+/*--- iSample**(4/3) lookup, -32<=i<=31 ---*/
+
+/*-- pow(2.0, -0.25*8.0*subblock_gain) --*/
+
+/*-- reorder buffer ---*/
+typedef float ARRAY3[3];
+
+
+/*=============================================================*/
+float *quant_init_global_addr(MPEG *m)
+{
+ return m->cupl.look_global;
+}
+/*-------------------------------------------------------------*/
+LS *quant_init_scale_addr(MPEG *m)
+{
+ return m->cupl.look_scale;
+}
+/*-------------------------------------------------------------*/
+float *quant_init_pow_addr(MPEG *m)
+{
+ return m->cupl.look_pow;
+}
+/*-------------------------------------------------------------*/
+float *quant_init_subblock_addr(MPEG *m)
+{
+ return m->cupl.look_subblock;
+}
+/*=============================================================*/
+
+#ifdef _MSC_VER
+#pragma warning(disable: 4056)
+#endif
+
+void dequant(MPEG *m, SAMPLE Sample[], int *nsamp,
+ SCALEFACT * sf,
+ GR * gr,
+ CB_INFO * cb_info, int ncbl_mixed)
+{
+ int i, j;
+ int cb, n, w;
+ float x0, xs;
+ float xsb[3];
+ double tmp;
+ int ncbl;
+ int cbs0;
+ ARRAY3 *buf; /* short block reorder */
+ int nbands;
+ int i0;
+ int non_zero;
+ int cbmax[3];
+
+ nbands = *nsamp;
+
+
+ ncbl = 22; /* long block cb end */
+ cbs0 = 12; /* short block cb start */
+/* ncbl_mixed = 8 or 6 mpeg1 or 2 */
+ if (gr->block_type == 2)
+ {
+ ncbl = 0;
+ cbs0 = 0;
+ if (gr->mixed_block_flag)
+ {
+ ncbl = ncbl_mixed;
+ cbs0 = 3;
+ }
+ }
+/* fill in cb_info -- */
+ /* This doesn't seem used anywhere...
+ cb_info->lb_type = gr->block_type;
+ if (gr->block_type == 2)
+ cb_info->lb_type;
+ */
+ cb_info->cbs0 = cbs0;
+ cb_info->ncbl = ncbl;
+
+ cbmax[2] = cbmax[1] = cbmax[0] = 0;
+/* global gain pre-adjusted by 2 if ms_mode, 0 otherwise */
+ x0 = m->cupl.look_global[(2 + 4) + gr->global_gain];
+ i = 0;
+/*----- long blocks ---*/
+ for (cb = 0; cb < ncbl; cb++)
+ {
+ non_zero = 0;
+ xs = x0 * m->cupl.look_scale[gr->scalefac_scale][pretab[gr->preflag][cb]][sf->l[cb]];
+ n = m->cupl.nBand[0][cb];
+ for (j = 0; j < n; j++, i++)
+ {
+ if (Sample[i].s == 0)
+ Sample[i].x = 0.0F;
+ else
+ {
+ non_zero = 1;
+ if ((Sample[i].s >= (-ISMAX)) && (Sample[i].s < ISMAX))
+ Sample[i].x = xs * m->cupl.look_pow[ISMAX + Sample[i].s];
+ else
+ {
+ float tmpConst = (float)(1.0/3.0);
+ tmp = (double) Sample[i].s;
+ Sample[i].x = (float) (xs * tmp * pow(fabs(tmp), tmpConst));
+ }
+ }
+ }
+ if (non_zero)
+ cbmax[0] = cb;
+ if (i >= nbands)
+ break;
+ }
+
+ cb_info->cbmax = cbmax[0];
+ cb_info->cbtype = 0; // type = long
+
+ if (cbs0 >= 12)
+ return;
+/*---------------------------
+block type = 2 short blocks
+----------------------------*/
+ cbmax[2] = cbmax[1] = cbmax[0] = cbs0;
+ i0 = i; /* save for reorder */
+ buf = m->cupl.re_buf;
+ for (w = 0; w < 3; w++)
+ xsb[w] = x0 * m->cupl.look_subblock[gr->subblock_gain[w]];
+ for (cb = cbs0; cb < 13; cb++)
+ {
+ n = m->cupl.nBand[1][cb];
+ for (w = 0; w < 3; w++)
+ {
+ non_zero = 0;
+ xs = xsb[w] * m->cupl.look_scale[gr->scalefac_scale][0][sf->s[w][cb]];
+ for (j = 0; j < n; j++, i++)
+ {
+ if (Sample[i].s == 0)
+ buf[j][w] = 0.0F;
+ else
+ {
+ non_zero = 1;
+ if ((Sample[i].s >= (-ISMAX)) && (Sample[i].s < ISMAX))
+ buf[j][w] = xs * m->cupl.look_pow[ISMAX + Sample[i].s];
+ else
+ {
+ float tmpConst = (float)(1.0/3.0);
+ tmp = (double) Sample[i].s;
+ buf[j][w] = (float) (xs * tmp * pow(fabs(tmp), tmpConst));
+ }
+ }
+ }
+ if (non_zero)
+ cbmax[w] = cb;
+ }
+ if (i >= nbands)
+ break;
+ buf += n;
+ }
+
+
+ memmove(&Sample[i0].x, &m->cupl.re_buf[0][0], sizeof(float) * (i - i0));
+
+ *nsamp = i; /* update nsamp */
+ cb_info->cbmax_s[0] = cbmax[0];
+ cb_info->cbmax_s[1] = cbmax[1];
+ cb_info->cbmax_s[2] = cbmax[2];
+ if (cbmax[1] > cbmax[0])
+ cbmax[0] = cbmax[1];
+ if (cbmax[2] > cbmax[0])
+ cbmax[0] = cbmax[2];
+
+ cb_info->cbmax = cbmax[0];
+ cb_info->cbtype = 1; /* type = short */
+
+
+ return;
+}
+
+#ifdef _MSC_VER
+#pragma warning(default: 4056)
+#endif
+
+/*-------------------------------------------------------------*/
diff --git a/codecs/mp3/src/l3init.c b/codecs/mp3/src/l3init.c
new file mode 100755
index 000000000..c3e724b3d
--- /dev/null
+++ b/codecs/mp3/src/l3init.c
@@ -0,0 +1,383 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** tinit.c ***************************************************
+ Layer III init tables
+
+
+******************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#include "L3.h"
+#include "mhead.h"
+#include "protos.h"
+
+/* get rid of precision loss warnings on conversion */
+#ifdef _MSC_VER
+#pragma warning(disable:4244 4056)
+#endif
+
+
+
+static const float Ci[8] =
+{
+ -0.6f, -0.535f, -0.33f, -0.185f, -0.095f, -0.041f, -0.0142f, -0.0037f};
+
+
+void hwin_init(MPEG *m); /* hybrid windows -- */
+void imdct_init(MPEG *m);
+typedef struct
+{
+ float *w;
+ float *w2;
+ void *coef;
+}
+IMDCT_INIT_BLOCK;
+
+void msis_init(MPEG *m);
+void msis_init_MPEG2(MPEG *m);
+
+/*=============================================================*/
+int L3table_init(MPEG *m)
+{
+ int i;
+ float *x;
+ LS *ls;
+ int scalefact_scale, preemp, scalefac;
+ double tmp;
+ PAIR *csa;
+
+/*================ quant ===============================*/
+
+/* 8 bit plus 2 lookup x = pow(2.0, 0.25*(global_gain-210)) */
+/* extra 2 for ms scaling by 1/sqrt(2) */
+/* extra 4 for cvt to mono scaling by 1/2 */
+ x = quant_init_global_addr(m);
+ for (i = 0; i < 256 + 2 + 4; i++)
+ x[i] = (float) pow(2.0, 0.25 * ((i - (2 + 4)) - 210 + GLOBAL_GAIN_SCALE));
+
+
+/* x = pow(2.0, -0.5*(1+scalefact_scale)*scalefac + preemp) */
+ ls = quant_init_scale_addr(m);
+ for (scalefact_scale = 0; scalefact_scale < 2; scalefact_scale++)
+ {
+ for (preemp = 0; preemp < 4; preemp++)
+ {
+ for (scalefac = 0; scalefac < 32; scalefac++)
+ {
+ ls[scalefact_scale][preemp][scalefac] =
+ (float) pow(2.0, -0.5 * (1 + scalefact_scale) * (scalefac + preemp));
+ }
+ }
+ }
+
+/*--- iSample**(4/3) lookup, -32<=i<=31 ---*/
+ x = quant_init_pow_addr(m);
+ for (i = 0; i < 64; i++)
+ {
+ tmp = i - 32;
+ x[i] = (float) (tmp * pow(fabs(tmp), (1.0 / 3.0)));
+ }
+
+
+/*-- pow(2.0, -0.25*8.0*subblock_gain) 3 bits --*/
+ x = quant_init_subblock_addr(m);
+ for (i = 0; i < 8; i++)
+ {
+ x[i] = (float) pow(2.0, 0.25 * -8.0 * i);
+ }
+
+/*-------------------------*/
+// quant_init_sf_band(sr_index); replaced by code in sup.c
+
+
+/*================ antialias ===============================*/
+ csa = alias_init_addr(m);
+ for (i = 0; i < 8; i++)
+ {
+ csa[i][0] = (float) (1.0 / sqrt(1.0 + Ci[i] * Ci[i]));
+ csa[i][1] = (float) (Ci[i] / sqrt(1.0 + Ci[i] * Ci[i]));
+ }
+
+
+/*================ msis ===============================*/
+ msis_init(m);
+ msis_init_MPEG2(m);
+
+/*================ imdct ===============================*/
+ imdct_init(m);
+
+/*--- hybrid windows ------------*/
+ hwin_init(m);
+
+ return 0;
+}
+/*====================================================================*/
+typedef float ARRAY36[36];
+ARRAY36 *hwin_init_addr();
+
+/*--------------------------------------------------------------------*/
+void hwin_init(MPEG *m)
+{
+ int i, j;
+ double pi;
+ ARRAY36 *win;
+
+ win = hwin_init_addr(m);
+
+ pi = 4.0 * atan(1.0);
+
+/* type 0 */
+ for (i = 0; i < 36; i++)
+ win[0][i] = (float) sin(pi / 36 * (i + 0.5));
+
+/* type 1 */
+ for (i = 0; i < 18; i++)
+ win[1][i] = (float) sin(pi / 36 * (i + 0.5));
+ for (i = 18; i < 24; i++)
+ win[1][i] = 1.0F;
+ for (i = 24; i < 30; i++)
+ win[1][i] = (float) sin(pi / 12 * (i + 0.5 - 18));
+ for (i = 30; i < 36; i++)
+ win[1][i] = 0.0F;
+
+/* type 3 */
+ for (i = 0; i < 6; i++)
+ win[3][i] = 0.0F;
+ for (i = 6; i < 12; i++)
+ win[3][i] = (float) sin(pi / 12 * (i + 0.5 - 6));
+ for (i = 12; i < 18; i++)
+ win[3][i] = 1.0F;
+ for (i = 18; i < 36; i++)
+ win[3][i] = (float) sin(pi / 36 * (i + 0.5));
+
+/* type 2 */
+ for (i = 0; i < 12; i++)
+ win[2][i] = (float) sin(pi / 12 * (i + 0.5));
+ for (i = 12; i < 36; i++)
+ win[2][i] = 0.0F;
+
+/*--- invert signs by region to match mdct 18pt --> 36pt mapping */
+ for (j = 0; j < 4; j++)
+ {
+ if (j == 2)
+ continue;
+ for (i = 9; i < 36; i++)
+ win[j][i] = -win[j][i];
+ }
+
+/*-- invert signs for short blocks --*/
+ for (i = 3; i < 12; i++)
+ win[2][i] = -win[2][i];
+
+ return;
+}
+/*=============================================================*/
+typedef float ARRAY4[4];
+IMDCT_INIT_BLOCK *imdct_init_addr_18();
+IMDCT_INIT_BLOCK *imdct_init_addr_6();
+
+/*-------------------------------------------------------------*/
+void imdct_init(MPEG *m)
+{
+ int k, p, n;
+ double t, pi;
+ IMDCT_INIT_BLOCK *addr;
+ float *w, *w2;
+ float *v, *v2, *coef87;
+ ARRAY4 *coef;
+
+/*--- 18 point --*/
+ addr = imdct_init_addr_18();
+ w = addr->w;
+ w2 = addr->w2;
+ coef = addr->coef;
+/*----*/
+ n = 18;
+ pi = 4.0 * atan(1.0);
+ t = pi / (4 * n);
+ for (p = 0; p < n; p++)
+ w[p] = (float) (2.0 * cos(t * (2 * p + 1)));
+ for (p = 0; p < 9; p++)
+ w2[p] = (float) 2.0 *cos(2 * t * (2 * p + 1));
+
+ t = pi / (2 * n);
+ for (k = 0; k < 9; k++)
+ {
+ for (p = 0; p < 4; p++)
+ coef[k][p] = (float) cos(t * (2 * k) * (2 * p + 1));
+ }
+
+/*--- 6 point */
+ addr = imdct_init_addr_6();
+ v = addr->w;
+ v2 = addr->w2;
+ coef87 = addr->coef;
+/*----*/
+ n = 6;
+ pi = 4.0 * atan(1.0);
+ t = pi / (4 * n);
+ for (p = 0; p < n; p++)
+ v[p] = (float) 2.0 *cos(t * (2 * p + 1));
+
+ for (p = 0; p < 3; p++)
+ v2[p] = (float) 2.0 *cos(2 * t * (2 * p + 1));
+
+ t = pi / (2 * n);
+ k = 1;
+ p = 0;
+ *coef87 = (float) cos(t * (2 * k) * (2 * p + 1));
+/* adjust scaling to save a few mults */
+ for (p = 0; p < 6; p++)
+ v[p] = v[p] / 2.0f;
+ *coef87 = (float) 2.0 *(*coef87);
+
+
+ return;
+}
+/*===============================================================*/
+typedef float ARRAY8_2[8][2];
+ARRAY8_2 *msis_init_addr(MPEG *m);
+
+/*-------------------------------------------------------------*/
+void msis_init(MPEG *m)
+{
+ int i;
+ double s, c;
+ double pi;
+ double t;
+ ARRAY8_2 *lr;
+
+ lr = msis_init_addr(m);
+
+
+ pi = 4.0 * atan(1.0);
+ t = pi / 12.0;
+ for (i = 0; i < 7; i++)
+ {
+ s = sin(i * t);
+ c = cos(i * t);
+ /* ms_mode = 0 */
+ lr[0][i][0] = (float) (s / (s + c));
+ lr[0][i][1] = (float) (c / (s + c));
+ /* ms_mode = 1 */
+ lr[1][i][0] = (float) (sqrt(2.0) * (s / (s + c)));
+ lr[1][i][1] = (float) (sqrt(2.0) * (c / (s + c)));
+ }
+/* sf = 7 */
+/* ms_mode = 0 */
+ lr[0][i][0] = 1.0f;
+ lr[0][i][1] = 0.0f;
+/* ms_mode = 1, in is bands is routine does ms processing */
+ lr[1][i][0] = 1.0f;
+ lr[1][i][1] = 1.0f;
+
+
+/*-------
+for(i=0;i<21;i++) nBand[0][i] =
+ sfBandTable[sr_index].l[i+1] - sfBandTable[sr_index].l[i];
+for(i=0;i<12;i++) nBand[1][i] =
+ sfBandTable[sr_index].s[i+1] - sfBandTable[sr_index].s[i];
+-------------*/
+
+}
+/*-------------------------------------------------------------*/
+/*===============================================================*/
+typedef float ARRAY2_64_2[2][64][2];
+ARRAY2_64_2 *msis_init_addr_MPEG2(MPEG *m);
+
+/*-------------------------------------------------------------*/
+void msis_init_MPEG2(MPEG *m)
+{
+ int k, n;
+ double t;
+ ARRAY2_64_2 *lr;
+ int intensity_scale, ms_mode, sf, sflen;
+ float ms_factor[2];
+
+
+ ms_factor[0] = 1.0;
+ ms_factor[1] = (float) sqrt(2.0);
+
+ lr = msis_init_addr_MPEG2(m);
+
+/* intensity stereo MPEG2 */
+/* lr2[intensity_scale][ms_mode][sflen_offset+sf][left/right] */
+
+ for (intensity_scale = 0; intensity_scale < 2; intensity_scale++)
+ {
+ t = pow(2.0, -0.25 * (1 + intensity_scale));
+ for (ms_mode = 0; ms_mode < 2; ms_mode++)
+ {
+
+ n = 1;
+ k = 0;
+ for (sflen = 0; sflen < 6; sflen++)
+ {
+ for (sf = 0; sf < (n - 1); sf++, k++)
+ {
+ if (sf == 0)
+ {
+ lr[intensity_scale][ms_mode][k][0] = ms_factor[ms_mode] * 1.0f;
+ lr[intensity_scale][ms_mode][k][1] = ms_factor[ms_mode] * 1.0f;
+ }
+ else if ((sf & 1))
+ {
+ lr[intensity_scale][ms_mode][k][0] =
+ (float) (ms_factor[ms_mode] * pow(t, (sf + 1) / 2));
+ lr[intensity_scale][ms_mode][k][1] = ms_factor[ms_mode] * 1.0f;
+ }
+ else
+ {
+ lr[intensity_scale][ms_mode][k][0] = ms_factor[ms_mode] * 1.0f;
+ lr[intensity_scale][ms_mode][k][1] =
+ (float) (ms_factor[ms_mode] * pow(t, sf / 2));
+ }
+ }
+
+ /* illegal is_pos used to do ms processing */
+ if (ms_mode == 0)
+ { /* ms_mode = 0 */
+ lr[intensity_scale][ms_mode][k][0] = 1.0f;
+ lr[intensity_scale][ms_mode][k][1] = 0.0f;
+ }
+ else
+ {
+ /* ms_mode = 1, in is bands is routine does ms processing */
+ lr[intensity_scale][ms_mode][k][0] = 1.0f;
+ lr[intensity_scale][ms_mode][k][1] = 1.0f;
+ }
+ k++;
+ n = n + n;
+ }
+ }
+ }
+
+}
+/*-------------------------------------------------------------*/
diff --git a/codecs/mp3/src/mdct.c b/codecs/mp3/src/mdct.c
new file mode 100755
index 000000000..7e95317ef
--- /dev/null
+++ b/codecs/mp3/src/mdct.c
@@ -0,0 +1,239 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** mdct.c ***************************************************
+
+Layer III
+
+ cos transform for n=18, n=6
+
+computes c[k] = Sum( cos((pi/4*n)*(2*k+1)*(2*p+1))*f[p] )
+ k = 0, ...n-1, p = 0...n-1
+
+
+inplace ok.
+
+******************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+
+#ifdef ASM_X86
+extern void imdct18_asm(float f[18]);
+extern void imdct6_3_asm(float f[]);
+#endif /* ASM_X86 */
+
+/*------ 18 point xform -------*/
+float mdct18w[18];
+float mdct18w2[9];
+float coef[9][4];
+
+float mdct6_3v[6];
+float mdct6_3v2[3];
+float coef87;
+
+typedef struct
+{
+ float *w;
+ float *w2;
+ void *coef;
+}
+IMDCT_INIT_BLOCK;
+
+static IMDCT_INIT_BLOCK imdct_info_18 =
+{mdct18w, mdct18w2, coef};
+static IMDCT_INIT_BLOCK imdct_info_6 =
+{mdct6_3v, mdct6_3v2, &coef87};
+
+/*====================================================================*/
+IMDCT_INIT_BLOCK *imdct_init_addr_18()
+{
+ return &imdct_info_18;
+}
+IMDCT_INIT_BLOCK *imdct_init_addr_6()
+{
+ return &imdct_info_6;
+}
+/*--------------------------------------------------------------------*/
+void imdct18(float f[18]) /* 18 point */
+{
+#ifdef ASM_X86
+ imdct18_asm(f);
+#else
+ int p;
+ float a[9], b[9];
+ float ap, bp, a8p, b8p;
+ float g1, g2;
+
+
+ for (p = 0; p < 4; p++)
+ {
+ g1 = mdct18w[p] * f[p];
+ g2 = mdct18w[17 - p] * f[17 - p];
+ ap = g1 + g2; // a[p]
+
+ bp = mdct18w2[p] * (g1 - g2); // b[p]
+
+ g1 = mdct18w[8 - p] * f[8 - p];
+ g2 = mdct18w[9 + p] * f[9 + p];
+ a8p = g1 + g2; // a[8-p]
+
+ b8p = mdct18w2[8 - p] * (g1 - g2); // b[8-p]
+
+ a[p] = ap + a8p;
+ a[5 + p] = ap - a8p;
+ b[p] = bp + b8p;
+ b[5 + p] = bp - b8p;
+ }
+ g1 = mdct18w[p] * f[p];
+ g2 = mdct18w[17 - p] * f[17 - p];
+ a[p] = g1 + g2;
+ b[p] = mdct18w2[p] * (g1 - g2);
+
+
+ f[0] = 0.5f * (a[0] + a[1] + a[2] + a[3] + a[4]);
+ f[1] = 0.5f * (b[0] + b[1] + b[2] + b[3] + b[4]);
+
+ f[2] = coef[1][0] * a[5] + coef[1][1] * a[6] + coef[1][2] * a[7]
+ + coef[1][3] * a[8];
+ f[3] = coef[1][0] * b[5] + coef[1][1] * b[6] + coef[1][2] * b[7]
+ + coef[1][3] * b[8] - f[1];
+ f[1] = f[1] - f[0];
+ f[2] = f[2] - f[1];
+
+ f[4] = coef[2][0] * a[0] + coef[2][1] * a[1] + coef[2][2] * a[2]
+ + coef[2][3] * a[3] - a[4];
+ f[5] = coef[2][0] * b[0] + coef[2][1] * b[1] + coef[2][2] * b[2]
+ + coef[2][3] * b[3] - b[4] - f[3];
+ f[3] = f[3] - f[2];
+ f[4] = f[4] - f[3];
+
+ f[6] = coef[3][0] * (a[5] - a[7] - a[8]);
+ f[7] = coef[3][0] * (b[5] - b[7] - b[8]) - f[5];
+ f[5] = f[5] - f[4];
+ f[6] = f[6] - f[5];
+
+ f[8] = coef[4][0] * a[0] + coef[4][1] * a[1] + coef[4][2] * a[2]
+ + coef[4][3] * a[3] + a[4];
+ f[9] = coef[4][0] * b[0] + coef[4][1] * b[1] + coef[4][2] * b[2]
+ + coef[4][3] * b[3] + b[4] - f[7];
+ f[7] = f[7] - f[6];
+ f[8] = f[8] - f[7];
+
+ f[10] = coef[5][0] * a[5] + coef[5][1] * a[6] + coef[5][2] * a[7]
+ + coef[5][3] * a[8];
+ f[11] = coef[5][0] * b[5] + coef[5][1] * b[6] + coef[5][2] * b[7]
+ + coef[5][3] * b[8] - f[9];
+ f[9] = f[9] - f[8];
+ f[10] = f[10] - f[9];
+
+ f[12] = 0.5f * (a[0] + a[2] + a[3]) - a[1] - a[4];
+ f[13] = 0.5f * (b[0] + b[2] + b[3]) - b[1] - b[4] - f[11];
+ f[11] = f[11] - f[10];
+ f[12] = f[12] - f[11];
+
+ f[14] = coef[7][0] * a[5] + coef[7][1] * a[6] + coef[7][2] * a[7]
+ + coef[7][3] * a[8];
+ f[15] = coef[7][0] * b[5] + coef[7][1] * b[6] + coef[7][2] * b[7]
+ + coef[7][3] * b[8] - f[13];
+ f[13] = f[13] - f[12];
+ f[14] = f[14] - f[13];
+
+ f[16] = coef[8][0] * a[0] + coef[8][1] * a[1] + coef[8][2] * a[2]
+ + coef[8][3] * a[3] + a[4];
+ f[17] = coef[8][0] * b[0] + coef[8][1] * b[1] + coef[8][2] * b[2]
+ + coef[8][3] * b[3] + b[4] - f[15];
+ f[15] = f[15] - f[14];
+ f[16] = f[16] - f[15];
+ f[17] = f[17] - f[16];
+
+
+ return;
+#endif
+}
+/*--------------------------------------------------------------------*/
+/* does 3, 6 pt dct. changes order from f[i][window] c[window][i] */
+void imdct6_3(float f[]) /* 6 point */
+{
+#ifdef ASM_X86
+ imdct6_3_asm(f);
+#else
+ int w;
+ float buf[18];
+ float *a, *c; // b[i] = a[3+i]
+
+ float g1, g2;
+ float a02, b02;
+
+ c = f;
+ a = buf;
+ for (w = 0; w < 3; w++)
+ {
+ g1 = mdct6_3v[0] * f[3 * 0];
+ g2 = mdct6_3v[5] * f[3 * 5];
+ a[0] = g1 + g2;
+ a[3 + 0] = mdct6_3v2[0] * (g1 - g2);
+
+ g1 = mdct6_3v[1] * f[3 * 1];
+ g2 = mdct6_3v[4] * f[3 * 4];
+ a[1] = g1 + g2;
+ a[3 + 1] = mdct6_3v2[1] * (g1 - g2);
+
+ g1 = mdct6_3v[2] * f[3 * 2];
+ g2 = mdct6_3v[3] * f[3 * 3];
+ a[2] = g1 + g2;
+ a[3 + 2] = mdct6_3v2[2] * (g1 - g2);
+
+ a += 6;
+ f++;
+ }
+
+ a = buf;
+ for (w = 0; w < 3; w++)
+ {
+ a02 = (a[0] + a[2]);
+ b02 = (a[3 + 0] + a[3 + 2]);
+ c[0] = a02 + a[1];
+ c[1] = b02 + a[3 + 1];
+ c[2] = coef87 * (a[0] - a[2]);
+ c[3] = coef87 * (a[3 + 0] - a[3 + 2]) - c[1];
+ c[1] = c[1] - c[0];
+ c[2] = c[2] - c[1];
+ c[4] = a02 - a[1] - a[1];
+ c[5] = b02 - a[3 + 1] - a[3 + 1] - c[3];
+ c[3] = c[3] - c[2];
+ c[4] = c[4] - c[3];
+ c[5] = c[5] - c[4];
+ a += 6;
+ c += 6;
+ }
+
+ return;
+#endif
+}
+/*--------------------------------------------------------------------*/
diff --git a/codecs/mp3/src/mhead.c b/codecs/mp3/src/mhead.c
new file mode 100755
index 000000000..d368f095f
--- /dev/null
+++ b/codecs/mp3/src/mhead.c
@@ -0,0 +1,321 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/*------------ mhead.c ----------------------------------------------
+ mpeg audio
+ extract info from mpeg header
+ portable version (adapted from c:\eco\mhead.c
+
+ add Layer III
+
+ mods 6/18/97 re mux restart, 32 bit ints
+
+ mod 5/7/98 parse mpeg 2.5
+
+---------------------------------------------------------------------*/
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#include "L3.h"
+#include "mhead.h" /* mpeg header structure */
+
+static int mp_br_table[2][16] =
+{{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0},
+ {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 0}};
+static int mp_sr20_table[2][4] =
+{{441, 480, 320, -999}, {882, 960, 640, -999}};
+
+static int mp_br_tableL1[2][16] =
+{{0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, 0},/* mpeg2 */
+ {0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0}};
+
+static int mp_br_tableL3[2][16] =
+{{0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 0}, /* mpeg 2 */
+ {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 0}};
+
+
+
+static int find_sync(unsigned char *buf, int n);
+static int sync_scan(unsigned char *buf, int n, int i0);
+static int sync_test(unsigned char *buf, int n, int isync, int padbytes);
+
+// jdw
+extern unsigned int g_jdw_additional;
+
+/*--------------------------------------------------------------*/
+int head_info(unsigned char *buf, unsigned int n, MPEG_HEAD * h)
+{
+ int framebytes;
+ int mpeg25_flag;
+
+ if (n > 10000)
+ n = 10000; /* limit scan for free format */
+
+
+
+ h->sync = 0;
+ //if ((buf[0] == 0xFF) && ((buf[1] & 0xF0) == 0xF0))
+ if ((buf[0] == 0xFF) && ((buf[0+1] & 0xF0) == 0xF0))
+ {
+ mpeg25_flag = 0; // mpeg 1 & 2
+
+ }
+ else if ((buf[0] == 0xFF) && ((buf[0+1] & 0xF0) == 0xE0))
+ {
+ mpeg25_flag = 1; // mpeg 2.5
+
+ }
+ else
+ return 0; // sync fail
+
+ h->sync = 1;
+ if (mpeg25_flag)
+ h->sync = 2; //low bit clear signals mpeg25 (as in 0xFFE)
+
+ h->id = (buf[0+1] & 0x08) >> 3;
+ h->option = (buf[0+1] & 0x06) >> 1;
+ h->prot = (buf[0+1] & 0x01);
+
+ h->br_index = (buf[0+2] & 0xf0) >> 4;
+ h->sr_index = (buf[0+2] & 0x0c) >> 2;
+ h->pad = (buf[0+2] & 0x02) >> 1;
+ h->private_bit = (buf[0+2] & 0x01);
+ h->mode = (buf[0+3] & 0xc0) >> 6;
+ h->mode_ext = (buf[0+3] & 0x30) >> 4;
+ h->cr = (buf[0+3] & 0x08) >> 3;
+ h->original = (buf[0+3] & 0x04) >> 2;
+ h->emphasis = (buf[0+3] & 0x03);
+
+
+// if( mpeg25_flag ) {
+ // if( h->sr_index == 2 ) return 0; // fail 8khz
+ //}
+
+
+/* compute framebytes for Layer I, II, III */
+ if (h->option < 1)
+ return 0;
+ if (h->option > 3)
+ return 0;
+
+ framebytes = 0;
+
+ if (h->br_index > 0)
+ {
+ if (h->option == 3)
+ { /* layer I */
+ framebytes =
+ 240 * mp_br_tableL1[h->id][h->br_index]
+ / mp_sr20_table[h->id][h->sr_index];
+ framebytes = 4 * framebytes;
+ }
+ else if (h->option == 2)
+ { /* layer II */
+ framebytes =
+ 2880 * mp_br_table[h->id][h->br_index]
+ / mp_sr20_table[h->id][h->sr_index];
+ }
+ else if (h->option == 1)
+ { /* layer III */
+ if (h->id)
+ { // mpeg1
+
+ framebytes =
+ 2880 * mp_br_tableL3[h->id][h->br_index]
+ / mp_sr20_table[h->id][h->sr_index];
+ }
+ else
+ { // mpeg2
+
+ if (mpeg25_flag)
+ { // mpeg2.2
+
+ framebytes =
+ 2880 * mp_br_tableL3[h->id][h->br_index]
+ / mp_sr20_table[h->id][h->sr_index];
+ }
+ else
+ {
+ framebytes =
+ 1440 * mp_br_tableL3[h->id][h->br_index]
+ / mp_sr20_table[h->id][h->sr_index];
+ }
+ }
+ }
+ }
+ else
+ framebytes = find_sync(buf, n); /* free format */
+
+ return framebytes;
+}
+
+int head_info3(unsigned char *buf, unsigned int n, MPEG_HEAD *h, int *br, unsigned int *searchForward) {
+ unsigned int pBuf = 0;
+ // jdw insertion...
+ while ((pBuf < n) && !((buf[pBuf] == 0xFF) &&
+ ((buf[pBuf+1] & 0xF0) == 0xF0 || (buf[pBuf+1] & 0xF0) == 0xE0)))
+ {
+ pBuf++;
+ }
+
+ if (pBuf == n) return 0;
+
+ *searchForward = pBuf;
+ return head_info2(&(buf[pBuf]),n,h,br);
+
+}
+
+/*--------------------------------------------------------------*/
+int head_info2(unsigned char *buf, unsigned int n, MPEG_HEAD * h, int *br)
+{
+ int framebytes;
+
+/*--- return br (in bits/sec) in addition to frame bytes ---*/
+
+ *br = 0;
+/*-- assume fail --*/
+ framebytes = head_info(buf, n, h);
+
+ if (framebytes == 0)
+ return 0;
+
+ if (h->option == 1)
+ { /* layer III */
+ if (h->br_index > 0)
+ *br = 1000 * mp_br_tableL3[h->id][h->br_index];
+ else
+ {
+ if (h->id) // mpeg1
+
+ *br = 1000 * framebytes * mp_sr20_table[h->id][h->sr_index] / (144 * 20);
+ else
+ { // mpeg2
+
+ if ((h->sync & 1) == 0) // flags mpeg25
+
+ *br = 500 * framebytes * mp_sr20_table[h->id][h->sr_index] / (72 * 20);
+ else
+ *br = 1000 * framebytes * mp_sr20_table[h->id][h->sr_index] / (72 * 20);
+ }
+ }
+ }
+ if (h->option == 2)
+ { /* layer II */
+ if (h->br_index > 0)
+ *br = 1000 * mp_br_table[h->id][h->br_index];
+ else
+ *br = 1000 * framebytes * mp_sr20_table[h->id][h->sr_index]
+ / (144 * 20);
+ }
+ if (h->option == 3)
+ { /* layer I */
+ if (h->br_index > 0)
+ *br = 1000 * mp_br_tableL1[h->id][h->br_index];
+ else
+ *br = 1000 * framebytes * mp_sr20_table[h->id][h->sr_index]
+ / (48 * 20);
+ }
+
+
+ return framebytes;
+}
+/*--------------------------------------------------------------*/
+static int compare(unsigned char *buf, unsigned char *buf2)
+{
+ if (buf[0] != buf2[0])
+ return 0;
+ if (buf[1] != buf2[1])
+ return 0;
+ return 1;
+}
+/*----------------------------------------------------------*/
+/*-- does not scan for initial sync, initial sync assumed --*/
+static int find_sync(unsigned char *buf, int n)
+{
+ int i0, isync, nmatch, pad;
+ int padbytes, option;
+
+/* mod 4/12/95 i0 change from 72, allows as low as 8kbits for mpeg1 */
+ i0 = 24;
+ padbytes = 1;
+ option = (buf[1] & 0x06) >> 1;
+ if (option == 3)
+ {
+ padbytes = 4;
+ i0 = 24; /* for shorter layer I frames */
+ }
+
+ pad = (buf[2] & 0x02) >> 1;
+
+ n -= 3; /* need 3 bytes of header */
+
+ while (i0 < 2000)
+ {
+ isync = sync_scan(buf, n, i0);
+ i0 = isync + 1;
+ isync -= pad;
+ if (isync <= 0)
+ return 0;
+ nmatch = sync_test(buf, n, isync, padbytes);
+ if (nmatch > 0)
+ return isync;
+ }
+
+ return 0;
+}
+/*------------------------------------------------------*/
+/*---- scan for next sync, assume start is valid -------*/
+/*---- return number bytes to next sync ----------------*/
+static int sync_scan(unsigned char *buf, int n, int i0)
+{
+ int i;
+
+ for (i = i0; i < n; i++)
+ if (compare(buf, buf + i))
+ return i;
+
+ return 0;
+}
+/*------------------------------------------------------*/
+/*- test consecutative syncs, input isync without pad --*/
+static int sync_test(unsigned char *buf, int n, int isync, int padbytes)
+{
+ int i, nmatch, pad;
+
+ nmatch = 0;
+ for (i = 0;;)
+ {
+ pad = padbytes * ((buf[i + 2] & 0x02) >> 1);
+ i += (pad + isync);
+ if (i > n)
+ break;
+ if (!compare(buf, buf + i))
+ return -nmatch;
+ nmatch++;
+ }
+ return nmatch;
+}
diff --git a/codecs/mp3/src/msis.c b/codecs/mp3/src/msis.c
new file mode 100755
index 000000000..a30e534b9
--- /dev/null
+++ b/codecs/mp3/src/msis.c
@@ -0,0 +1,300 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** msis.c ***************************************************
+ Layer III
+ antialias, ms and is stereo precessing
+
+**** is_process assumes never switch
+ from short to long in is region *****
+
+is_process does ms or stereo in "forbidded sf regions"
+ //ms_mode = 0
+ lr[0][i][0] = 1.0f;
+ lr[0][i][1] = 0.0f;
+ // ms_mode = 1, in is bands is routine does ms processing
+ lr[1][i][0] = 1.0f;
+ lr[1][i][1] = 1.0f;
+
+******************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#include "L3.h"
+#include "mhead.h"
+
+/* The functions are different than their prototypes, by design */
+
+typedef float ARRAY2[2];
+typedef float ARRAY8_2[8][2];
+
+
+/* nBand[0] = long, nBand[1] = short */
+
+/* intensity stereo */
+/* if ms mode quant pre-scales all values by 1.0/sqrt(2.0) ms_mode in table
+ compensates */
+
+
+/* intensity stereo MPEG2 */
+/* lr2[intensity_scale][ms_mode][sflen_offset+sf][left/right] */
+typedef float ARRAY2_64_2[2][64][2];
+typedef float ARRAY64_2[64][2];
+
+#ifdef ASM_X86
+extern void antialias_asm(float x[], int n);
+#endif /* ASM_X86 */
+
+
+/*===============================================================*/
+ARRAY2 *alias_init_addr(MPEG *m)
+{
+ return m->cupl.csa;
+}
+/*-----------------------------------------------------------*/
+ARRAY8_2 *msis_init_addr(MPEG *m)
+{
+/*-------
+pi = 4.0*atan(1.0);
+t = pi/12.0;
+for(i=0;i<7;i++) {
+ s = sin(i*t);
+ c = cos(i*t);
+ // ms_mode = 0
+ m->cupl.lr[0][i][0] = (float)(s/(s+c));
+ m->cupl.lr[0][i][1] = (float)(c/(s+c));
+ // ms_mode = 1
+ m->cupl.lr[1][i][0] = (float)(sqrt(2.0)*(s/(s+c)));
+ m->cupl.lr[1][i][1] = (float)(sqrt(2.0)*(c/(s+c)));
+}
+//sf = 7
+//ms_mode = 0
+m->cupl.lr[0][i][0] = 1.0f;
+m->cupl.lr[0][i][1] = 0.0f;
+// ms_mode = 1, in is bands is routine does ms processing
+m->cupl.lr[1][i][0] = 1.0f;
+m->cupl.lr[1][i][1] = 1.0f;
+------------*/
+
+ return m->cupl.lr;
+}
+/*-------------------------------------------------------------*/
+ARRAY2_64_2 *msis_init_addr_MPEG2(MPEG *m)
+{
+ return m->cupl.lr2;
+}
+/*===============================================================*/
+void antialias(MPEG *m, float x[], int n)
+{
+#ifdef ASM_X86
+ antialias_asm(x, n);
+#else
+ int i, k;
+ float a, b;
+
+ for (k = 0; k < n; k++)
+ {
+ for (i = 0; i < 8; i++)
+ {
+ a = x[17 - i];
+ b = x[18 + i];
+ x[17 - i] = a * m->cupl.csa[i][0] - b * m->cupl.csa[i][1];
+ x[18 + i] = b * m->cupl.csa[i][0] + a * m->cupl.csa[i][1];
+ }
+ x += 18;
+ }
+#endif
+}
+/*===============================================================*/
+void ms_process(float x[][1152], int n) /* sum-difference stereo */
+{
+ int i;
+ float xl, xr;
+
+/*-- note: sqrt(2) done scaling by dequant ---*/
+ for (i = 0; i < n; i++)
+ {
+ xl = x[0][i] + x[1][i];
+ xr = x[0][i] - x[1][i];
+ x[0][i] = xl;
+ x[1][i] = xr;
+ }
+ return;
+}
+/*===============================================================*/
+void is_process_MPEG1(MPEG *vm, float x[][1152], /* intensity stereo */
+ SCALEFACT * sf,
+ CB_INFO cb_info[2], /* [ch] */
+ int nsamp, int ms_mode)
+{
+ int i, j, n, cb, w;
+ float fl, fr;
+ int m;
+ int isf;
+ float fls[3], frs[3];
+ int cb0;
+
+
+ cb0 = cb_info[1].cbmax; /* start at end of right */
+ i = vm->cupl.sfBandIndex[cb_info[1].cbtype][cb0];
+ cb0++;
+ m = nsamp - i; /* process to len of left */
+
+ if (cb_info[1].cbtype)
+ goto short_blocks;
+/*------------------------*/
+/* long_blocks: */
+ for (cb = cb0; cb < 21; cb++)
+ {
+ isf = sf->l[cb];
+ n = vm->cupl.nBand[0][cb];
+ fl = vm->cupl.lr[ms_mode][isf][0];
+ fr = vm->cupl.lr[ms_mode][isf][1];
+ for (j = 0; j < n; j++, i++)
+ {
+ if (--m < 0)
+ goto exit;
+ x[1][i] = fr * x[0][i];
+ x[0][i] = fl * x[0][i];
+ }
+ }
+ return;
+/*------------------------*/
+ short_blocks:
+ for (cb = cb0; cb < 12; cb++)
+ {
+ for (w = 0; w < 3; w++)
+ {
+ isf = sf->s[w][cb];
+ fls[w] = vm->cupl.lr[ms_mode][isf][0];
+ frs[w] = vm->cupl.lr[ms_mode][isf][1];
+ }
+ n = vm->cupl.nBand[1][cb];
+ for (j = 0; j < n; j++)
+ {
+ m -= 3;
+ if (m < 0)
+ goto exit;
+ x[1][i] = frs[0] * x[0][i];
+ x[0][i] = fls[0] * x[0][i];
+ x[1][1 + i] = frs[1] * x[0][1 + i];
+ x[0][1 + i] = fls[1] * x[0][1 + i];
+ x[1][2 + i] = frs[2] * x[0][2 + i];
+ x[0][2 + i] = fls[2] * x[0][2 + i];
+ i += 3;
+ }
+ }
+
+ exit:
+ return;
+}
+/*===============================================================*/
+void is_process_MPEG2(MPEG *vm, float x[][1152], /* intensity stereo */
+ SCALEFACT * sf,
+ CB_INFO cb_info[2], /* [ch] */
+ IS_SF_INFO * is_sf_info,
+ int nsamp, int ms_mode)
+{
+ int i, j, k, n, cb, w;
+ float fl, fr;
+ int m;
+ int isf;
+ int il[21];
+ int tmp;
+ int r;
+ ARRAY2 *lr;
+ int cb0, cb1;
+
+ lr = vm->cupl.lr2[is_sf_info->intensity_scale][ms_mode];
+
+ if (cb_info[1].cbtype)
+ goto short_blocks;
+
+/*------------------------*/
+/* long_blocks: */
+ cb0 = cb_info[1].cbmax; /* start at end of right */
+ i = vm->cupl.sfBandIndex[0][cb0];
+ m = nsamp - i; /* process to len of left */
+/* gen sf info */
+ for (k = r = 0; r < 3; r++)
+ {
+ tmp = (1 << is_sf_info->slen[r]) - 1;
+ for (j = 0; j < is_sf_info->nr[r]; j++, k++)
+ il[k] = tmp;
+ }
+ for (cb = cb0 + 1; cb < 21; cb++)
+ {
+ isf = il[cb] + sf->l[cb];
+ fl = lr[isf][0];
+ fr = lr[isf][1];
+ n = vm->cupl.nBand[0][cb];
+ for (j = 0; j < n; j++, i++)
+ {
+ if (--m < 0)
+ goto exit;
+ x[1][i] = fr * x[0][i];
+ x[0][i] = fl * x[0][i];
+ }
+ }
+ return;
+/*------------------------*/
+ short_blocks:
+
+ for (k = r = 0; r < 3; r++)
+ {
+ tmp = (1 << is_sf_info->slen[r]) - 1;
+ for (j = 0; j < is_sf_info->nr[r]; j++, k++)
+ il[k] = tmp;
+ }
+
+ for (w = 0; w < 3; w++)
+ {
+ cb0 = cb_info[1].cbmax_s[w]; /* start at end of right */
+ i = vm->cupl.sfBandIndex[1][cb0] + w;
+ cb1 = cb_info[0].cbmax_s[w]; /* process to end of left */
+
+ for (cb = cb0 + 1; cb <= cb1; cb++)
+ {
+ isf = il[cb] + sf->s[w][cb];
+ fl = lr[isf][0];
+ fr = lr[isf][1];
+ n = vm->cupl.nBand[1][cb];
+ for (j = 0; j < n; j++)
+ {
+ x[1][i] = fr * x[0][i];
+ x[0][i] = fl * x[0][i];
+ i += 3;
+ }
+ }
+
+ }
+
+ exit:
+ return;
+}
+/*===============================================================*/
diff --git a/codecs/mp3/src/uph.c b/codecs/mp3/src/uph.c
new file mode 100755
index 000000000..c3cab0a20
--- /dev/null
+++ b/codecs/mp3/src/uph.c
@@ -0,0 +1,505 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** uph.c ***************************************************
+
+Layer 3 audio
+ huffman decode
+
+
+******************************************************************/
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+
+#include "L3.h"
+
+
+#ifdef _MSC_VER
+#pragma warning(disable: 4505)
+#endif
+
+/*===============================================================*/
+
+/* max bits required for any lookup - change if htable changes */
+/* quad required 10 bit w/signs must have (MAXBITS+2) >= 10 */
+#define MAXBITS 9
+
+static HUFF_ELEMENT huff_table_0[4] =
+{{0}, {0}, {0}, {64}}; /* dummy must not use */
+
+#include "htable.h"
+
+/*-- 6 bit lookup (purgebits, value) --*/
+static unsigned char quad_table_a[][2] =
+{
+ {6, 11}, {6, 15}, {6, 13}, {6, 14}, {6, 7}, {6, 5}, {5, 9},
+ {5, 9}, {5, 6}, {5, 6}, {5, 3}, {5, 3}, {5, 10}, {5, 10},
+ {5, 12}, {5, 12}, {4, 2}, {4, 2}, {4, 2}, {4, 2}, {4, 1},
+ {4, 1}, {4, 1}, {4, 1}, {4, 4}, {4, 4}, {4, 4}, {4, 4},
+ {4, 8}, {4, 8}, {4, 8}, {4, 8}, {1, 0}, {1, 0}, {1, 0},
+ {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
+ {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
+ {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
+ {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0}, {1, 0},
+ {1, 0},
+};
+
+
+typedef struct
+{
+ HUFF_ELEMENT *table;
+ int linbits;
+ int ncase;
+}
+HUFF_SETUP;
+
+#define no_bits 0
+#define one_shot 1
+#define no_linbits 2
+#define have_linbits 3
+#define quad_a 4
+#define quad_b 5
+
+
+static HUFF_SETUP table_look[] =
+{
+ {huff_table_0, 0, no_bits},
+ {huff_table_1, 0, one_shot},
+ {huff_table_2, 0, one_shot},
+ {huff_table_3, 0, one_shot},
+ {huff_table_0, 0, no_bits},
+ {huff_table_5, 0, one_shot},
+ {huff_table_6, 0, one_shot},
+ {huff_table_7, 0, no_linbits},
+ {huff_table_8, 0, no_linbits},
+ {huff_table_9, 0, no_linbits},
+ {huff_table_10, 0, no_linbits},
+ {huff_table_11, 0, no_linbits},
+ {huff_table_12, 0, no_linbits},
+ {huff_table_13, 0, no_linbits},
+ {huff_table_0, 0, no_bits},
+ {huff_table_15, 0, no_linbits},
+ {huff_table_16, 1, have_linbits},
+ {huff_table_16, 2, have_linbits},
+ {huff_table_16, 3, have_linbits},
+ {huff_table_16, 4, have_linbits},
+ {huff_table_16, 6, have_linbits},
+ {huff_table_16, 8, have_linbits},
+ {huff_table_16, 10, have_linbits},
+ {huff_table_16, 13, have_linbits},
+ {huff_table_24, 4, have_linbits},
+ {huff_table_24, 5, have_linbits},
+ {huff_table_24, 6, have_linbits},
+ {huff_table_24, 7, have_linbits},
+ {huff_table_24, 8, have_linbits},
+ {huff_table_24, 9, have_linbits},
+ {huff_table_24, 11, have_linbits},
+ {huff_table_24, 13, have_linbits},
+ {huff_table_0, 0, quad_a},
+ {huff_table_0, 0, quad_b},
+};
+
+/*========================================================*/
+extern BITDAT bitdat;
+
+/*------------- get n bits from bitstream -------------*/
+/* unused
+static unsigned int bitget(int n)
+{
+ unsigned int x;
+
+ if (bitdat.bits < n)
+ { */ /* refill bit buf if necessary */
+/* while (bitdat.bits <= 24)
+ {
+ bitdat.bitbuf = (bitdat.bitbuf << 8) | *bitdat.bs_ptr++;
+ bitdat.bits += 8;
+ }
+ }
+ bitdat.bits -= n;
+ x = bitdat.bitbuf >> bitdat.bits;
+ bitdat.bitbuf -= x << bitdat.bits;
+ return x;
+}
+*/
+/*----- get n bits - checks for n+2 avail bits (linbits+sign) -----*/
+static unsigned int bitget_lb(int n)
+{
+ unsigned int x;
+
+ if (bitdat.bits < (n + 2))
+ { /* refill bit buf if necessary */
+ while (bitdat.bits <= 24)
+ {
+ bitdat.bitbuf = (bitdat.bitbuf << 8) | *bitdat.bs_ptr++;
+ bitdat.bits += 8;
+ }
+ }
+ bitdat.bits -= n;
+ x = bitdat.bitbuf >> bitdat.bits;
+ bitdat.bitbuf -= x << bitdat.bits;
+ return x;
+}
+
+
+
+
+/*------------- get n bits but DO NOT remove from bitstream --*/
+static unsigned int bitget2(int n)
+{
+ unsigned int x;
+
+ if (bitdat.bits < (MAXBITS + 2))
+ { /* refill bit buf if necessary */
+ while (bitdat.bits <= 24)
+ {
+ bitdat.bitbuf = (bitdat.bitbuf << 8) | *bitdat.bs_ptr++;
+ bitdat.bits += 8;
+ }
+ }
+ x = bitdat.bitbuf >> (bitdat.bits - n);
+ return x;
+}
+/*------------- remove n bits from bitstream ---------*/
+/* unused
+static void bitget_purge(int n)
+{
+ bitdat.bits -= n;
+ bitdat.bitbuf -= (bitdat.bitbuf >> bitdat.bits) << bitdat.bits;
+}
+*/
+/*------------- get 1 bit from bitstream NO CHECK -------------*/
+/* unused
+static unsigned int bitget_1bit()
+{
+ unsigned int x;
+
+ bitdat.bits--;
+ x = bitdat.bitbuf >> bitdat.bits;
+ bitdat.bitbuf -= x << bitdat.bits;
+ return x;
+}
+*/
+/*========================================================*/
+/*========================================================*/
+#define mac_bitget_check(n) if( bitdat.bits < (n) ) { \
+ while( bitdat.bits <= 24 ) { \
+ bitdat.bitbuf = (bitdat.bitbuf << 8) | *bitdat.bs_ptr++; \
+ bitdat.bits += 8; \
+ } \
+}
+/*---------------------------------------------------------*/
+#define mac_bitget2(n) (bitdat.bitbuf >> (bitdat.bits-n));
+/*---------------------------------------------------------*/
+#define mac_bitget(n) ( bitdat.bits -= n, \
+ code = bitdat.bitbuf >> bitdat.bits, \
+ bitdat.bitbuf -= code << bitdat.bits, \
+ code )
+/*---------------------------------------------------------*/
+#define mac_bitget_purge(n) bitdat.bits -= n, \
+ bitdat.bitbuf -= (bitdat.bitbuf >> bitdat.bits) << bitdat.bits;
+/*---------------------------------------------------------*/
+#define mac_bitget_1bit() ( bitdat.bits--, \
+ code = bitdat.bitbuf >> bitdat.bits, \
+ bitdat.bitbuf -= code << bitdat.bits, \
+ code )
+/*========================================================*/
+/*========================================================*/
+void unpack_huff(int xy[][2], int n, int ntable)
+{
+ int i;
+ HUFF_ELEMENT *t;
+ HUFF_ELEMENT *t0;
+ int linbits;
+ int bits;
+ int code;
+ int x, y;
+
+ if (n <= 0)
+ return;
+ n = n >> 1; /* huff in pairs */
+/*-------------*/
+ t0 = table_look[ntable].table;
+ linbits = table_look[ntable].linbits;
+ switch (table_look[ntable].ncase)
+ {
+ default:
+/*------------------------------------------*/
+ case no_bits:
+/*- table 0, no data, x=y=0--*/
+ for (i = 0; i < n; i++)
+ {
+ xy[i][0] = 0;
+ xy[i][1] = 0;
+ }
+ return;
+/*------------------------------------------*/
+ case one_shot:
+/*- single lookup, no escapes -*/
+ for (i = 0; i < n; i++)
+ {
+ mac_bitget_check((MAXBITS + 2));
+ bits = t0[0].b.signbits;
+ code = mac_bitget2(bits);
+ mac_bitget_purge(t0[1 + code].b.purgebits);
+ x = t0[1 + code].b.x;
+ y = t0[1 + code].b.y;
+ if (x)
+ if (mac_bitget_1bit())
+ x = -x;
+ if (y)
+ if (mac_bitget_1bit())
+ y = -y;
+ xy[i][0] = x;
+ xy[i][1] = y;
+ if (bitdat.bs_ptr > bitdat.bs_ptr_end)
+ break; // bad data protect
+
+ }
+ return;
+/*------------------------------------------*/
+ case no_linbits:
+ for (i = 0; i < n; i++)
+ {
+ t = t0;
+ for (;;)
+ {
+ mac_bitget_check((MAXBITS + 2));
+ bits = t[0].b.signbits;
+ code = mac_bitget2(bits);
+ if (t[1 + code].b.purgebits)
+ break;
+ t += t[1 + code].ptr; /* ptr include 1+code */
+ mac_bitget_purge(bits);
+ }
+ mac_bitget_purge(t[1 + code].b.purgebits);
+ x = t[1 + code].b.x;
+ y = t[1 + code].b.y;
+ if (x)
+ if (mac_bitget_1bit())
+ x = -x;
+ if (y)
+ if (mac_bitget_1bit())
+ y = -y;
+ xy[i][0] = x;
+ xy[i][1] = y;
+ if (bitdat.bs_ptr > bitdat.bs_ptr_end)
+ break; // bad data protect
+
+ }
+ return;
+/*------------------------------------------*/
+ case have_linbits:
+ for (i = 0; i < n; i++)
+ {
+ t = t0;
+ for (;;)
+ {
+ bits = t[0].b.signbits;
+ code = bitget2(bits);
+ if (t[1 + code].b.purgebits)
+ break;
+ t += t[1 + code].ptr; /* ptr includes 1+code */
+ mac_bitget_purge(bits);
+ }
+ mac_bitget_purge(t[1 + code].b.purgebits);
+ x = t[1 + code].b.x;
+ y = t[1 + code].b.y;
+ if (x == 15)
+ x += bitget_lb(linbits);
+ if (x)
+ if (mac_bitget_1bit())
+ x = -x;
+ if (y == 15)
+ y += bitget_lb(linbits);
+ if (y)
+ if (mac_bitget_1bit())
+ y = -y;
+ xy[i][0] = x;
+ xy[i][1] = y;
+ if (bitdat.bs_ptr > bitdat.bs_ptr_end)
+ break; // bad data protect
+
+ }
+ return;
+ }
+/*--- end switch ---*/
+
+}
+/*==========================================================*/
+int unpack_huff_quad(int vwxy[][4], int n, int nbits, int ntable)
+{
+ int i;
+ int code;
+ int x, y, v, w;
+ int tmp;
+ int i_non_zero, tmp_nz;
+
+ tmp_nz = 15;
+ i_non_zero = -1;
+
+ n = n >> 2; /* huff in quads */
+
+ if (ntable)
+ goto case_quad_b;
+
+/* case_quad_a: */
+ for (i = 0; i < n; i++)
+ {
+ if (nbits <= 0)
+ break;
+ mac_bitget_check(10);
+ code = mac_bitget2(6);
+ nbits -= quad_table_a[code][0];
+ mac_bitget_purge(quad_table_a[code][0]);
+ tmp = quad_table_a[code][1];
+ if (tmp)
+ {
+ i_non_zero = i;
+ tmp_nz = tmp;
+ }
+ v = (tmp >> 3) & 1;
+ w = (tmp >> 2) & 1;
+ x = (tmp >> 1) & 1;
+ y = tmp & 1;
+ if (v)
+ {
+ if (mac_bitget_1bit())
+ v = -v;
+ nbits--;
+ }
+ if (w)
+ {
+ if (mac_bitget_1bit())
+ w = -w;
+ nbits--;
+ }
+ if (x)
+ {
+ if (mac_bitget_1bit())
+ x = -x;
+ nbits--;
+ }
+ if (y)
+ {
+ if (mac_bitget_1bit())
+ y = -y;
+ nbits--;
+ }
+ vwxy[i][0] = v;
+ vwxy[i][1] = w;
+ vwxy[i][2] = x;
+ vwxy[i][3] = y;
+ if (bitdat.bs_ptr > bitdat.bs_ptr_end)
+ break; // bad data protect
+
+ }
+ if (nbits < 0)
+ {
+ i--;
+ vwxy[i][0] = 0;
+ vwxy[i][1] = 0;
+ vwxy[i][2] = 0;
+ vwxy[i][3] = 0;
+ }
+
+ i_non_zero = (i_non_zero + 1) << 2;
+
+ if ((tmp_nz & 3) == 0)
+ i_non_zero -= 2;
+
+ return i_non_zero;
+
+/*--------------------*/
+ case_quad_b:
+ for (i = 0; i < n; i++)
+ {
+ if (nbits < 4)
+ break;
+ nbits -= 4;
+ mac_bitget_check(8);
+ tmp = mac_bitget(4) ^ 15; /* one's complement of bitstream */
+ if (tmp)
+ {
+ i_non_zero = i;
+ tmp_nz = tmp;
+ }
+ v = (tmp >> 3) & 1;
+ w = (tmp >> 2) & 1;
+ x = (tmp >> 1) & 1;
+ y = tmp & 1;
+ if (v)
+ {
+ if (mac_bitget_1bit())
+ v = -v;
+ nbits--;
+ }
+ if (w)
+ {
+ if (mac_bitget_1bit())
+ w = -w;
+ nbits--;
+ }
+ if (x)
+ {
+ if (mac_bitget_1bit())
+ x = -x;
+ nbits--;
+ }
+ if (y)
+ {
+ if (mac_bitget_1bit())
+ y = -y;
+ nbits--;
+ }
+ vwxy[i][0] = v;
+ vwxy[i][1] = w;
+ vwxy[i][2] = x;
+ vwxy[i][3] = y;
+ if (bitdat.bs_ptr > bitdat.bs_ptr_end)
+ break; // bad data protect
+
+ }
+ if (nbits < 0)
+ {
+ i--;
+ vwxy[i][0] = 0;
+ vwxy[i][1] = 0;
+ vwxy[i][2] = 0;
+ vwxy[i][3] = 0;
+ }
+
+ i_non_zero = (i_non_zero + 1) << 2;
+
+ if ((tmp_nz & 3) == 0)
+ i_non_zero -= 2;
+
+ return i_non_zero; /* return non-zero sample (to nearest pair) */
+
+}
+/*-----------------------------------------------------*/
diff --git a/codecs/mp3/src/upsf.c b/codecs/mp3/src/upsf.c
new file mode 100755
index 000000000..1280620c2
--- /dev/null
+++ b/codecs/mp3/src/upsf.c
@@ -0,0 +1,404 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/**** upsf.c ***************************************************
+
+Layer III
+ unpack scale factors
+
+
+
+******************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#include "L3.h"
+
+extern int iframe;
+
+unsigned int bitget(int n);
+
+/*------------------------------------------------------------*/
+static const int slen_table[16][2] =
+{
+ {0, 0}, {0, 1},
+ {0, 2}, {0, 3},
+ {3, 0}, {1, 1},
+ {1, 2}, {1, 3},
+ {2, 1}, {2, 2},
+ {2, 3}, {3, 1},
+ {3, 2}, {3, 3},
+ {4, 2}, {4, 3},
+};
+
+/* nr_table[size+3*is_right][block type 0,1,3 2, 2+mixed][4] */
+/* for bt=2 nr is count for group of 3 */
+static const int nr_table[6][3][4] =
+{
+ {{6, 5, 5, 5},
+ {3, 3, 3, 3},
+ {6, 3, 3, 3}},
+
+ {{6, 5, 7, 3},
+ {3, 3, 4, 2},
+ {6, 3, 4, 2}},
+
+ {{11, 10, 0, 0},
+ {6, 6, 0, 0},
+ {6, 3, 6, 0}}, /* adjusted *//* 15, 18, 0, 0, */
+/*-intensity stereo right chan--*/
+ {{7, 7, 7, 0},
+ {4, 4, 4, 0},
+ {6, 5, 4, 0}},
+
+ {{6, 6, 6, 3},
+ {4, 3, 3, 2},
+ {6, 4, 3, 2}},
+
+ {{8, 8, 5, 0},
+ {5, 4, 3, 0},
+ {6, 6, 3, 0}},
+};
+
+/*=============================================================*/
+void unpack_sf_sub_MPEG1(SCALEFACT sf[],
+ GR * grdat,
+ int scfsi, /* bit flag */
+ int gr)
+{
+ int sfb;
+ int slen0, slen1;
+ int block_type, mixed_block_flag, scalefac_compress;
+
+
+ block_type = grdat->block_type;
+ mixed_block_flag = grdat->mixed_block_flag;
+ scalefac_compress = grdat->scalefac_compress;
+
+ slen0 = slen_table[scalefac_compress][0];
+ slen1 = slen_table[scalefac_compress][1];
+
+
+ if (block_type == 2)
+ {
+ if (mixed_block_flag)
+ { /* mixed */
+ for (sfb = 0; sfb < 8; sfb++)
+ sf[0].l[sfb] = bitget(slen0);
+ for (sfb = 3; sfb < 6; sfb++)
+ {
+ sf[0].s[0][sfb] = bitget(slen0);
+ sf[0].s[1][sfb] = bitget(slen0);
+ sf[0].s[2][sfb] = bitget(slen0);
+ }
+ for (sfb = 6; sfb < 12; sfb++)
+ {
+ sf[0].s[0][sfb] = bitget(slen1);
+ sf[0].s[1][sfb] = bitget(slen1);
+ sf[0].s[2][sfb] = bitget(slen1);
+ }
+ return;
+ }
+ for (sfb = 0; sfb < 6; sfb++)
+ {
+ sf[0].s[0][sfb] = bitget(slen0);
+ sf[0].s[1][sfb] = bitget(slen0);
+ sf[0].s[2][sfb] = bitget(slen0);
+ }
+ for (; sfb < 12; sfb++)
+ {
+ sf[0].s[0][sfb] = bitget(slen1);
+ sf[0].s[1][sfb] = bitget(slen1);
+ sf[0].s[2][sfb] = bitget(slen1);
+ }
+ return;
+ }
+
+/* long blocks types 0 1 3, first granule */
+ if (gr == 0)
+ {
+ for (sfb = 0; sfb < 11; sfb++)
+ sf[0].l[sfb] = bitget(slen0);
+ for (; sfb < 21; sfb++)
+ sf[0].l[sfb] = bitget(slen1);
+ return;
+ }
+
+/* long blocks 0, 1, 3, second granule */
+ sfb = 0;
+ if (scfsi & 8)
+ for (; sfb < 6; sfb++)
+ sf[0].l[sfb] = sf[-2].l[sfb];
+ else
+ for (; sfb < 6; sfb++)
+ sf[0].l[sfb] = bitget(slen0);
+ if (scfsi & 4)
+ for (; sfb < 11; sfb++)
+ sf[0].l[sfb] = sf[-2].l[sfb];
+ else
+ for (; sfb < 11; sfb++)
+ sf[0].l[sfb] = bitget(slen0);
+ if (scfsi & 2)
+ for (; sfb < 16; sfb++)
+ sf[0].l[sfb] = sf[-2].l[sfb];
+ else
+ for (; sfb < 16; sfb++)
+ sf[0].l[sfb] = bitget(slen1);
+ if (scfsi & 1)
+ for (; sfb < 21; sfb++)
+ sf[0].l[sfb] = sf[-2].l[sfb];
+ else
+ for (; sfb < 21; sfb++)
+ sf[0].l[sfb] = bitget(slen1);
+
+
+
+ return;
+}
+/*=============================================================*/
+void unpack_sf_sub_MPEG2(SCALEFACT sf[],
+ GR * grdat,
+ int is_and_ch, IS_SF_INFO * sf_info)
+{
+ int sfb;
+ int slen1, slen2, slen3, slen4;
+ int nr1, nr2, nr3, nr4;
+ int i, k;
+ int preflag, intensity_scale;
+ int block_type, mixed_block_flag, scalefac_compress;
+
+
+ block_type = grdat->block_type;
+ mixed_block_flag = grdat->mixed_block_flag;
+ scalefac_compress = grdat->scalefac_compress;
+
+ preflag = 0;
+ intensity_scale = 0; /* to avoid compiler warning */
+ if (is_and_ch == 0)
+ {
+ if (scalefac_compress < 400)
+ {
+ slen2 = scalefac_compress >> 4;
+ slen1 = slen2 / 5;
+ slen2 = slen2 % 5;
+ slen4 = scalefac_compress & 15;
+ slen3 = slen4 >> 2;
+ slen4 = slen4 & 3;
+ k = 0;
+ }
+ else if (scalefac_compress < 500)
+ {
+ scalefac_compress -= 400;
+ slen2 = scalefac_compress >> 2;
+ slen1 = slen2 / 5;
+ slen2 = slen2 % 5;
+ slen3 = scalefac_compress & 3;
+ slen4 = 0;
+ k = 1;
+ }
+ else
+ {
+ scalefac_compress -= 500;
+ slen1 = scalefac_compress / 3;
+ slen2 = scalefac_compress % 3;
+ slen3 = slen4 = 0;
+ if (mixed_block_flag)
+ {
+ slen3 = slen2; /* adjust for long/short mix logic */
+ slen2 = slen1;
+ }
+ preflag = 1;
+ k = 2;
+ }
+ }
+ else
+ { /* intensity stereo ch = 1 (right) */
+ intensity_scale = scalefac_compress & 1;
+ scalefac_compress >>= 1;
+ if (scalefac_compress < 180)
+ {
+ slen1 = scalefac_compress / 36;
+ slen2 = scalefac_compress % 36;
+ slen3 = slen2 % 6;
+ slen2 = slen2 / 6;
+ slen4 = 0;
+ k = 3 + 0;
+ }
+ else if (scalefac_compress < 244)
+ {
+ scalefac_compress -= 180;
+ slen3 = scalefac_compress & 3;
+ scalefac_compress >>= 2;
+ slen2 = scalefac_compress & 3;
+ slen1 = scalefac_compress >> 2;
+ slen4 = 0;
+ k = 3 + 1;
+ }
+ else
+ {
+ scalefac_compress -= 244;
+ slen1 = scalefac_compress / 3;
+ slen2 = scalefac_compress % 3;
+ slen3 = slen4 = 0;
+ k = 3 + 2;
+ }
+ }
+
+ i = 0;
+ if (block_type == 2)
+ i = (mixed_block_flag & 1) + 1;
+ nr1 = nr_table[k][i][0];
+ nr2 = nr_table[k][i][1];
+ nr3 = nr_table[k][i][2];
+ nr4 = nr_table[k][i][3];
+
+
+/* return is scale factor info (for right chan is mode) */
+ if (is_and_ch)
+ {
+ sf_info->nr[0] = nr1;
+ sf_info->nr[1] = nr2;
+ sf_info->nr[2] = nr3;
+ sf_info->slen[0] = slen1;
+ sf_info->slen[1] = slen2;
+ sf_info->slen[2] = slen3;
+ sf_info->intensity_scale = intensity_scale;
+ }
+ grdat->preflag = preflag; /* return preflag */
+
+/*--------------------------------------*/
+ if (block_type == 2)
+ {
+ if (mixed_block_flag)
+ { /* mixed */
+ if (slen1 != 0) /* long block portion */
+ for (sfb = 0; sfb < 6; sfb++)
+ sf[0].l[sfb] = bitget(slen1);
+ else
+ for (sfb = 0; sfb < 6; sfb++)
+ sf[0].l[sfb] = 0;
+ sfb = 3; /* start sfb for short */
+ }
+ else
+ { /* all short, initial short blocks */
+ sfb = 0;
+ if (slen1 != 0)
+ for (i = 0; i < nr1; i++, sfb++)
+ {
+ sf[0].s[0][sfb] = bitget(slen1);
+ sf[0].s[1][sfb] = bitget(slen1);
+ sf[0].s[2][sfb] = bitget(slen1);
+ }
+ else
+ for (i = 0; i < nr1; i++, sfb++)
+ {
+ sf[0].s[0][sfb] = 0;
+ sf[0].s[1][sfb] = 0;
+ sf[0].s[2][sfb] = 0;
+ }
+ }
+/* remaining short blocks */
+ if (slen2 != 0)
+ for (i = 0; i < nr2; i++, sfb++)
+ {
+ sf[0].s[0][sfb] = bitget(slen2);
+ sf[0].s[1][sfb] = bitget(slen2);
+ sf[0].s[2][sfb] = bitget(slen2);
+ }
+ else
+ for (i = 0; i < nr2; i++, sfb++)
+ {
+ sf[0].s[0][sfb] = 0;
+ sf[0].s[1][sfb] = 0;
+ sf[0].s[2][sfb] = 0;
+ }
+ if (slen3 != 0)
+ for (i = 0; i < nr3; i++, sfb++)
+ {
+ sf[0].s[0][sfb] = bitget(slen3);
+ sf[0].s[1][sfb] = bitget(slen3);
+ sf[0].s[2][sfb] = bitget(slen3);
+ }
+ else
+ for (i = 0; i < nr3; i++, sfb++)
+ {
+ sf[0].s[0][sfb] = 0;
+ sf[0].s[1][sfb] = 0;
+ sf[0].s[2][sfb] = 0;
+ }
+ if (slen4 != 0)
+ for (i = 0; i < nr4; i++, sfb++)
+ {
+ sf[0].s[0][sfb] = bitget(slen4);
+ sf[0].s[1][sfb] = bitget(slen4);
+ sf[0].s[2][sfb] = bitget(slen4);
+ }
+ else
+ for (i = 0; i < nr4; i++, sfb++)
+ {
+ sf[0].s[0][sfb] = 0;
+ sf[0].s[1][sfb] = 0;
+ sf[0].s[2][sfb] = 0;
+ }
+ return;
+ }
+
+
+/* long blocks types 0 1 3 */
+ sfb = 0;
+ if (slen1 != 0)
+ for (i = 0; i < nr1; i++, sfb++)
+ sf[0].l[sfb] = bitget(slen1);
+ else
+ for (i = 0; i < nr1; i++, sfb++)
+ sf[0].l[sfb] = 0;
+
+ if (slen2 != 0)
+ for (i = 0; i < nr2; i++, sfb++)
+ sf[0].l[sfb] = bitget(slen2);
+ else
+ for (i = 0; i < nr2; i++, sfb++)
+ sf[0].l[sfb] = 0;
+
+ if (slen3 != 0)
+ for (i = 0; i < nr3; i++, sfb++)
+ sf[0].l[sfb] = bitget(slen3);
+ else
+ for (i = 0; i < nr3; i++, sfb++)
+ sf[0].l[sfb] = 0;
+
+ if (slen4 != 0)
+ for (i = 0; i < nr4; i++, sfb++)
+ sf[0].l[sfb] = bitget(slen4);
+ else
+ for (i = 0; i < nr4; i++, sfb++)
+ sf[0].l[sfb] = 0;
+
+
+}
+/*-------------------------------------------------*/
diff --git a/codecs/mp3/src/wavep.c b/codecs/mp3/src/wavep.c
new file mode 100755
index 000000000..d6d282916
--- /dev/null
+++ b/codecs/mp3/src/wavep.c
@@ -0,0 +1,165 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998-1999 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/*---- wavep.c --------------------------------------------
+
+WAVE FILE HEADER ROUTINES
+with conditional pcm conversion to MS wave format
+portable version
+
+-----------------------------------------------------------*/
+#include <stdlib.h>
+#include <stdio.h>
+#include <float.h>
+#include <math.h>
+#ifdef WIN32
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+#include "port.h"
+
+typedef struct
+{
+ unsigned char riff[4];
+ unsigned char size[4];
+ unsigned char wave[4];
+ unsigned char fmt[4];
+ unsigned char fmtsize[4];
+ unsigned char tag[2];
+ unsigned char nChannels[2];
+ unsigned char nSamplesPerSec[4];
+ unsigned char nAvgBytesPerSec[4];
+ unsigned char nBlockAlign[2];
+ unsigned char nBitsPerSample[2];
+ unsigned char data[4];
+ unsigned char pcm_bytes[4];
+}
+BYTE_WAVE;
+
+static BYTE_WAVE wave =
+{
+ "RIFF",
+ {(sizeof(BYTE_WAVE) - 8), 0, 0, 0},
+ "WAVE",
+ "fmt ",
+ {16, 0, 0, 0},
+ {1, 0},
+ {1, 0},
+ {34, 86, 0, 0}, /* 86 * 256 + 34 = 22050 */
+ {172, 68, 0, 0}, /* 172 * 256 + 68 = 44100 */
+ {2, 0},
+ {16, 0},
+ "data",
+ {0, 0, 0, 0}
+};
+
+/*---------------------------------------------------------*/
+static void set_wave(unsigned char w[], int n, long x)
+{
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ w[i] = (unsigned char) (x & 0xff);
+ x >>= 8;
+ }
+}
+/*---------------------------------------------------------*/
+int write_pcm_header_wave(int handout,
+ long samprate, int channels, int bits, int type)
+{
+ int nwrite;
+
+ if (type == 0)
+ set_wave(wave.tag, sizeof(wave.tag), 1);
+ else if (type == 10)
+ set_wave(wave.tag, sizeof(wave.tag), 7);
+ else
+ return 0;
+
+ set_wave(wave.size, sizeof(wave.size), sizeof(wave) - 8);
+ set_wave(wave.nChannels, sizeof(wave.nChannels), channels);
+ set_wave(wave.nSamplesPerSec, sizeof(wave.nSamplesPerSec), samprate);
+ set_wave(wave.nAvgBytesPerSec, sizeof(wave.nAvgBytesPerSec),
+ (channels * samprate * bits + 7) / 8);
+ set_wave(wave.nBlockAlign, sizeof(wave.nBlockAlign), (channels * bits + 7) / 8);
+ set_wave(wave.nBitsPerSample, sizeof(wave.nBitsPerSample), bits);
+ set_wave(wave.pcm_bytes, sizeof(wave.pcm_bytes), 0);
+
+ nwrite = write(handout, &wave, sizeof(wave));
+ if (nwrite != sizeof(wave))
+ return 0;
+
+ return 1;
+}
+/*-----------------------------------------------*/
+int write_pcm_tailer_wave(int handout, unsigned long pcm_bytes)
+{
+ unsigned long pos;
+ int nwrite;
+
+
+ set_wave(wave.size, sizeof(wave.size), sizeof(wave) - 8 + pcm_bytes);
+ set_wave(wave.pcm_bytes, sizeof(wave.pcm_bytes), pcm_bytes);
+
+
+ pos = lseek(handout, 0L, 2);
+/*-- save current position */
+ lseek(handout, 0L, 0);
+/*-- pos to header --*/
+ nwrite = write(handout, &wave, sizeof(wave));
+ lseek(handout, pos, 0);
+/*-- restore pos --*/
+
+ if (nwrite != sizeof(wave))
+ return 0;
+ return 1;
+}
+/*-----------------------------------------------*/
+/*----------------------------------------------------------------
+ pcm conversion to wave format
+
+ This conversion code required for big endian machine, or,
+ if sizeof(short) != 16 bits.
+ Conversion routines may be used on any machine, but if
+ not required, the do nothing macros in port.h can be used instead
+ to reduce overhead.
+
+-----------------------------------------------------------------*/
+#ifndef LITTLE_SHORT16
+#include "wcvt.c"
+#endif
+/*-----------------------------------------------*/
+int cvt_to_wave_test()
+{
+/*-- test for valid compile ---*/
+
+ return sizeof(short) - 2;
+
+
+}
+/*-----------------------------------------------*/
diff --git a/codecs/mp3/src/wcvt.c b/codecs/mp3/src/wcvt.c
new file mode 100755
index 000000000..d373cd694
--- /dev/null
+++ b/codecs/mp3/src/wcvt.c
@@ -0,0 +1,92 @@
+/*____________________________________________________________________________
+
+ FreeAmp - The Free MP3 Player
+
+ MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
+ Corp. http://www.xingtech.com
+
+ Portions Copyright (C) 1998 EMusic.com
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ $Id$
+____________________________________________________________________________*/
+
+/*---- wcvt.c --------------------------------------------
+
+conditional inclusion to wavep.c
+
+pcm conversion to wave format
+ for big endians or when sizeof(short) > 16 bits
+
+mod 1/9/97 warnings
+
+-----------------------------------------------------------*/
+static int bytes_per_samp = 1;
+static int big_ender;
+static int cvt_flag;
+
+/*-------------------------------------------------------*/
+void cvt_to_wave_init(int bits)
+{
+
+ big_ender = 1;
+ if ((*(unsigned char *) &big_ender) == 1)
+ big_ender = 0;
+
+/*--- printf("\n big_ender = %d", big_ender ); ---*/
+
+ if (bits == 8)
+ bytes_per_samp = 1;
+ else
+ bytes_per_samp = sizeof(short);
+
+
+ cvt_flag = 0;
+ if (bits > 8)
+ {
+ if (big_ender)
+ cvt_flag = 1;
+ cvt_flag |= (sizeof(short) > 2);
+ }
+
+}
+/*-------------------------------------------------------*/
+unsigned int cvt_to_wave(unsigned char *pcm, unsigned int bytes_in)
+{
+ unsigned int i, k;
+ unsigned int nsamp;
+ short tmp;
+ unsigned short *w;
+
+// printf("\n wave convert");
+
+ if (cvt_flag == 0)
+ return bytes_in;
+/*-- no conversion required --*/
+
+ nsamp = bytes_in / bytes_per_samp;
+ w = (unsigned short *) pcm;
+ for (i = 0, k = 0; i < nsamp; i++, k += 2)
+ {
+ tmp = w[i];
+ pcm[k] = (unsigned char) tmp;
+ pcm[k + 1] = (unsigned char) (tmp >> 8);
+ }
+
+ return (nsamp << 1);
+/*--- return bytes out ---*/
+}
+/*-------------------------------------------------------*/
diff --git a/codecs/mp3/src/x86gas.s b/codecs/mp3/src/x86gas.s
new file mode 100755
index 000000000..9fe553703
--- /dev/null
+++ b/codecs/mp3/src/x86gas.s
@@ -0,0 +1,393 @@
+#
+# FreeAmp - The Free MP3 Player
+#
+# Based on MP3 decoder originally Copyright (C) 1995-1997
+# Xing Technology Corp. http://www.xingtech.com
+#
+# Copyright (C) 1999 Mark H. Weaver <mhw@netris.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+# $Id$
+#
+
+#%% extern wincoef,dword
+#%% extern coef32,dword
+#%% ! extern float wincoef[264];
+#%% ! extern float coef32[31];
+
+.equ L_tmp, 0
+#%!.equ L_pcm, 4
+#%% if-not-inline
+.equ L_vbuf, 24
+.equ L_vb_ptr, 28
+.equ L_pcm, 32
+
+.globl window_dual
+ .align 16
+#%% end-not-inline
+#%% ! void window_dual(float *vbuf, int vb_ptr, short *pcm)
+#%% ! {
+window_dual: #%% proc
+#%% if-not-inline
+ pushl %ebp
+ pushl %edi
+ pushl %esi
+ pushl %ebx
+ subl $4,%esp
+
+ movl L_vb_ptr(%esp),%esi
+ movl L_vbuf(%esp),%edi
+#%% end-not-inline
+
+#%! movl vb_ptr,%esi
+#%! movl vbuf,%edi
+#%! movl pcm,%ecx
+#%! pushl %ebp
+#%! subl $8,%esp
+#%! movl %ecx,L_pcm(%esp)
+
+ movl $511,%ebp # ebp = 511
+ leal wincoef,%ecx # coef = wincoef
+ addl $16,%esi # si = vb_ptr + 16
+ movl %esi,%ebx
+ addl $32,%ebx
+ andl %ebp,%ebx # bx = (si + 32) & 511
+
+# First 16
+ movb $16,%dh # i = 16
+ .align 4
+.FirstOuter:
+ fldz # sum = 0.0
+ movb $2,%dl # j = 2
+ .align 4
+.FirstInner:
+.rept 4 # Unrolled loop
+ flds (%ecx) # Push *coef
+ fmuls (%edi,%esi,4) # Multiply by vbuf[si]
+ addl $64,%esi # si += 64
+ addl $4,%ecx # Advance coef pointer
+ andl %ebp,%esi # si &= 511
+ faddp %st,%st(1) # Add to sum
+
+ flds (%ecx) # Push *coef
+ fmuls (%edi,%ebx,4) # Multiply by vbuf[bx]
+ addl $64,%ebx # bx += 64
+ addl $4,%ecx # Advance coef pointer
+ andl %ebp,%ebx # bx &= 511
+ fsubrp %st,%st(1) # Subtract from sum
+.endr
+
+ decb %dl # --j
+ jg .FirstInner # Jump back if j > 0
+
+ fistpl L_tmp(%esp) # tmp = (long) round (sum)
+ incl %esi # si++
+ movl L_tmp(%esp),%eax
+ decl %ebx # bx--
+ movl %eax,%ebp
+ sarl $15,%eax
+ incl %eax
+ sarl $1,%eax
+ jz .FirstInRange # Jump if in range
+
+ sarl $16,%eax # Out of range
+ movl $32767,%ebp
+ xorl %eax,%ebp
+.FirstInRange:
+ movl L_pcm(%esp),%eax
+ movw %bp,(%eax) # Store sample in *pcm
+ addl $4,%eax # Increment pcm
+ movl $511,%ebp # Reload ebp with 511
+ movl %eax,L_pcm(%esp)
+
+ decb %dh # --i
+ jg .FirstOuter # Jump back if i > 0
+
+
+# Special case
+ fldz # sum = 0.0
+ movb $4,%dl # j = 4
+ .align 4
+.SpecialInner:
+.rept 2 # Unrolled loop
+ flds (%ecx) # Push *coef
+ fmuls (%edi,%ebx,4) # Multiply by vbuf[bx]
+ addl $64,%ebx # bx += 64
+ addl $4,%ecx # Increment coef pointer
+ andl %ebp,%ebx # bx &= 511
+ faddp %st,%st(1) # Add to sum
+.endr
+
+ decb %dl # --j
+ jg .SpecialInner # Jump back if j > 0
+
+ fistpl L_tmp(%esp) # tmp = (long) round (sum)
+ decl %esi # si--
+ movl L_tmp(%esp),%eax
+ incl %ebx # bx++
+ movl %eax,%ebp
+ sarl $15,%eax
+ incl %eax
+ sarl $1,%eax
+ jz .SpecialInRange # Jump if within range
+
+ sarl $16,%eax # Out of range
+ movl $32767,%ebp
+ xorl %eax,%ebp
+.SpecialInRange:
+ movl L_pcm(%esp),%eax
+ subl $36,%ecx # Readjust coef pointer for last round
+ movw %bp,(%eax) # Store sample in *pcm
+ addl $4,%eax # Increment pcm
+ movl $511,%ebp # Reload ebp with 511
+ movl %eax,L_pcm(%esp)
+
+
+# Last 15
+ movb $15,%dh # i = 15
+ .align 4
+.LastOuter:
+ fldz # sum = 0.0
+ movb $2,%dl # j = 2
+ .align 4
+.LastInner:
+.rept 4 # Unrolled loop
+ flds (%ecx) # Push *coef
+ fmuls (%edi,%esi,4) # Multiply by vbuf[si]
+ addl $64,%esi # si += 64
+ subl $4,%ecx # Back up coef pointer
+ andl %ebp,%esi # si &= 511
+ faddp %st,%st(1) # Add to sum
+
+ flds (%ecx) # Push *coef
+ fmuls (%edi,%ebx,4) # Multiply by vbuf[bx]
+ addl $64,%ebx # bx += 64
+ subl $4,%ecx # Back up coef pointer
+ andl %ebp,%ebx # bx &= 511
+ faddp %st,%st(1) # Add to sum
+.endr
+
+ decb %dl # --j
+ jg .LastInner # Jump back if j > 0
+
+ fistpl L_tmp(%esp) # tmp = (long) round (sum)
+ decl %esi # si--
+ movl L_tmp(%esp),%eax
+ incl %ebx # bx++
+ movl %eax,%ebp
+ sarl $15,%eax
+ incl %eax
+ sarl $1,%eax
+ jz .LastInRange # Jump if in range
+
+ sarl $16,%eax # Out of range
+ movl $32767,%ebp
+ xorl %eax,%ebp
+.LastInRange:
+ movl L_pcm(%esp),%eax
+ movw %bp,(%eax) # Store sample in *pcm
+ addl $4,%eax # Increment pcm
+ movl $511,%ebp # Reload ebp with 511
+ movl %eax,L_pcm(%esp)
+
+ decb %dh # --i
+ jg .LastOuter # Jump back if i > 0
+
+#%! addl $8,%esp
+#%! popl %ebp
+
+#%% if-not-inline
+# Restore regs and return
+ addl $4,%esp
+ popl %ebx
+ popl %esi
+ popl %edi
+ popl %ebp
+ ret
+#%% end-not-inline
+#%% endp
+#%% ! }
+
+#---------------------------------------------------------------------------
+
+.equ L_mi, 0
+.equ L_m, 4
+.equ L_dummy, 8
+#%!.equ L_in, 12
+#%!.equ L_out, 16
+#%!.equ L_buf, 20 # Temporary buffer
+#%!.equ L_locals, 148 # Bytes used for locals
+#%% if-not-inline
+.equ L_buf, 12 # Temporary buffer
+.equ L_in, 160
+.equ L_out, 164
+.equ L_locals, 140 # Bytes used for locals
+
+.globl asm_fdct32
+ .align 16
+#%% end-not-inline
+#%% ! void asm_fdct32(float in[], float out[])
+#%% ! {
+asm_fdct32: #%% proc
+#%% if-not-inline
+ pushl %ebp
+ pushl %edi
+ pushl %esi
+ pushl %ebx
+ subl $L_locals,%esp
+
+ movl L_in(%esp),%edi # edi = x
+ movl L_out(%esp),%esi # esi = f
+#%% end-not-inline
+
+#%! movl in,%edi # edi = x
+#%! movl out,%esi # esi = f
+#%! pushl %ebp
+#%! subl $L_locals,%esp
+
+ leal coef32-128,%ecx # coef = coef32 - (32 * 4)
+ movl $1,4(%esp) # m = 1
+ movl $16,%ebp # n = 32 / 2
+
+ leal L_buf(%esp),%ebx
+ movl %ebx,L_out(%esp) # From now on, use temp buf instead of orig x
+ jmp .ForwardLoopStart
+
+ .align 4
+.ForwardOuterLoop:
+ movl L_in(%esp),%edi # edi = x
+ movl L_out(%esp),%esi # esi = f
+ movl %edi,L_out(%esp) # Exchange mem versions of f/x for next iter
+.ForwardLoopStart:
+ movl %esi,L_in(%esp)
+ movl L_m(%esp),%ebx # ebx = m (temporarily)
+ movl %ebx,L_mi(%esp) # mi = m
+ sall $1,%ebx # Double m for next iter
+ leal (%ecx,%ebp,8),%ecx # coef += n * 8
+ movl %ebx,L_m(%esp) # Store doubled m
+ leal (%esi,%ebp,4),%ebx # ebx = f2 = f + n * 4
+ sall $3,%ebp # n *= 8
+
+ .align 4
+.ForwardMiddleLoop:
+ movl %ebp,%eax # q = n
+ xorl %edx,%edx # p = 0
+ test $8,%eax
+ jnz .ForwardInnerLoop1
+
+ .align 4
+.ForwardInnerLoop:
+ subl $4,%eax # q -= 4
+ flds (%edi,%eax) # push x[q]
+ flds (%edi,%edx) # push x[p]
+ fld %st(1) # Duplicate top two stack entries
+ fld %st(1)
+ faddp %st,%st(1)
+ fstps (%esi,%edx) # f[p] = x[p] + x[q]
+ fsubp %st,%st(1)
+ fmuls (%ecx,%edx)
+ fstps (%ebx,%edx) # f2[p] = coef[p] * (x[p] - x[q])
+ addl $4,%edx # p += 4
+
+.ForwardInnerLoop1:
+ subl $4,%eax # q -= 4
+ flds (%edi,%eax) # push x[q]
+ flds (%edi,%edx) # push x[p]
+ fld %st(1) # Duplicate top two stack entries
+ fld %st(1)
+ faddp %st,%st(1)
+ fstps (%esi,%edx) # f[p] = x[p] + x[q]
+ fsubp %st,%st(1)
+ fmuls (%ecx,%edx)
+ fstps (%ebx,%edx) # f2[p] = coef[p] * (x[p] - x[q])
+ addl $4,%edx # p += 4
+
+ cmpl %eax,%edx
+ jb .ForwardInnerLoop # Jump back if (p < q)
+
+ addl %ebp,%esi # f += n
+ addl %ebp,%ebx # f2 += n
+ addl %ebp,%edi # x += n
+ decl L_mi(%esp) # mi--
+ jg .ForwardMiddleLoop # Jump back if mi > 0
+
+ sarl $4,%ebp # n /= 16
+ jg .ForwardOuterLoop # Jump back if n > 0
+
+
+# Setup back loop
+ movl $8,%ebx # ebx = m = 8 (temporarily)
+ movl %ebx,%ebp # n = 4 * 2
+
+ .align 4
+.BackOuterLoop:
+ movl L_out(%esp),%esi # esi = f
+ movl %ebx,L_mi(%esp) # mi = m
+ movl L_in(%esp),%edi # edi = x
+ movl %ebx,L_m(%esp) # Store m
+ movl %esi,L_in(%esp) # Exchange mem versions of f/x for next iter
+ movl %edi,%ebx
+ movl %edi,L_out(%esp)
+ subl %ebp,%ebx # ebx = x2 = x - n
+ sall $1,%ebp # n *= 2
+
+ .align 4
+.BackMiddleLoop:
+ movl -4(%ebx,%ebp),%ecx
+ movl %ecx,-8(%esi,%ebp) # f[n - 8] = x2[n - 4]
+ flds -4(%edi,%ebp) # push x[n - 4]
+ fsts -4(%esi,%ebp) # f[n - 4] = x[n - 4], without popping
+ leal -8(%ebp),%eax # q = n - 8
+ leal -16(%ebp),%edx # p = n - 16
+
+ .align 4
+.BackInnerLoop:
+ movl (%ebx,%eax),%ecx
+ movl %ecx,(%esi,%edx) # f[p] = x2[q]
+ flds (%edi,%eax) # push x[q]
+ fadd %st,%st(1)
+ fxch
+ fstps 4(%esi,%edx) # f[p + 4] = x[q] + x[q + 4]
+ subl $4,%eax # q -= 4
+ subl $8,%edx # p -= 8
+ jge .BackInnerLoop # Jump back if p >= 0
+
+ fstps L_dummy(%esp) # Pop (XXX is there a better way to do this?)
+ addl %ebp,%esi # f += n
+ addl %ebp,%ebx # x2 += n
+ addl %ebp,%edi # x += n
+ decl L_mi(%esp) # mi--
+ jg .BackMiddleLoop # Jump back if mi > 0
+
+ movl L_m(%esp),%ebx # ebx = m (temporarily)
+ sarl $1,%ebx # Halve m for next iter
+ jg .BackOuterLoop # Jump back if m > 0
+
+#%! addl $L_locals,%esp
+#%! popl %ebp
+
+#%% if-not-inline
+# Restore regs and return
+ addl $L_locals,%esp
+ popl %ebx
+ popl %esi
+ popl %edi
+ popl %ebp
+ ret
+#%% end-not-inline
+#%% endp
+#%% ! }
+
diff --git a/codecs/mp3/src/x86intel.c b/codecs/mp3/src/x86intel.c
new file mode 100755
index 000000000..d9f0e6125
--- /dev/null
+++ b/codecs/mp3/src/x86intel.c
@@ -0,0 +1,437 @@
+/* *************************************************** */
+/* ************ DO NOT EDIT THIS FILE!!!! ************ */
+/* *************************************************** */
+/* This file was automatically generated by gas2intel. */
+/* Edit the original gas version instead. */
+
+
+/* FreeAmp - The Free MP3 Player */
+
+/* Based on MP3 decoder originally Copyright (C) 1995-1997 */
+/* Xing Technology Corp. http://www.xingtech.com */
+
+/* Copyright (C) 1999 Mark H. Weaver <mhw@netris.org> */
+
+/* This program is free software; you can redistribute it and/or modify */
+/* it under the terms of the GNU General Public License as published by */
+/* the Free Software Foundation; either version 2 of the License, or */
+/* (at your option) any later version. */
+
+/* This program is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
+/* GNU General Public License for more details. */
+
+/* You should have received a copy of the GNU General Public License */
+/* along with this program; if not, write to the Free Software */
+/* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+/* $Id$ */
+/* Generated from Id: x86gas.s,v 1.9 1999/03/05 08:58:18 mhw Exp $ */
+
+
+extern float wincoef[264];
+extern float coef32[31];
+
+#define L_tmp 0
+#define L_pcm 4
+void window_dual(float *vbuf, int vb_ptr, short *pcm)
+{
+__asm {
+
+ mov esi,vb_ptr
+ mov edi,vbuf
+ mov ecx,pcm
+ push ebp
+ sub esp,8
+ mov DWORD PTR [esp+L_pcm],ecx
+
+ mov ebp,511 ; ebp = 511
+ lea ecx,wincoef ; coef = wincoef
+ add esi,16 ; si = vb_ptr + 16
+ mov ebx,esi
+ add ebx,32
+ and ebx,ebp ; bx = (si + 32) & 511
+
+; First 16
+ mov dh,16 ; i = 16
+ align 4
+FirstOuter:
+ fldz ; sum = 0.0
+ mov dl,2 ; j = 2
+ align 4
+FirstInner:
+; REPEAT 4 ; Unrolled loop
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+esi*4] ; Multiply by vbuf[si]
+ add esi,64 ; si += 64
+ add ecx,4 ; Advance coef pointer
+ and esi,ebp ; si &= 511
+ faddp st(1),st ; Add to sum
+
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+ebx*4] ; Multiply by vbuf[bx]
+ add ebx,64 ; bx += 64
+ add ecx,4 ; Advance coef pointer
+ and ebx,ebp ; bx &= 511
+ fsubp st(1),st ; Subtract from sum
+;--
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+esi*4] ; Multiply by vbuf[si]
+ add esi,64 ; si += 64
+ add ecx,4 ; Advance coef pointer
+ and esi,ebp ; si &= 511
+ faddp st(1),st ; Add to sum
+
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+ebx*4] ; Multiply by vbuf[bx]
+ add ebx,64 ; bx += 64
+ add ecx,4 ; Advance coef pointer
+ and ebx,ebp ; bx &= 511
+ fsubp st(1),st ; Subtract from sum
+;--
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+esi*4] ; Multiply by vbuf[si]
+ add esi,64 ; si += 64
+ add ecx,4 ; Advance coef pointer
+ and esi,ebp ; si &= 511
+ faddp st(1),st ; Add to sum
+
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+ebx*4] ; Multiply by vbuf[bx]
+ add ebx,64 ; bx += 64
+ add ecx,4 ; Advance coef pointer
+ and ebx,ebp ; bx &= 511
+ fsubp st(1),st ; Subtract from sum
+;--
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+esi*4] ; Multiply by vbuf[si]
+ add esi,64 ; si += 64
+ add ecx,4 ; Advance coef pointer
+ and esi,ebp ; si &= 511
+ faddp st(1),st ; Add to sum
+
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+ebx*4] ; Multiply by vbuf[bx]
+ add ebx,64 ; bx += 64
+ add ecx,4 ; Advance coef pointer
+ and ebx,ebp ; bx &= 511
+ fsubp st(1),st ; Subtract from sum
+;--
+; END REPEAT
+
+ dec dl ; --j
+ jg FirstInner ; Jump back if j > 0
+
+ fistp DWORD PTR [esp+L_tmp] ; tmp = (long) round (sum)
+ inc esi ; si++
+ mov eax,DWORD PTR [esp+L_tmp]
+ dec ebx ; bx--
+ mov ebp,eax
+ sar eax,15
+ inc eax
+ sar eax,1
+ jz FirstInRange ; Jump if in range
+
+ sar eax,16 ; Out of range
+ mov ebp,32767
+ xor ebp,eax
+FirstInRange:
+ mov eax,DWORD PTR [esp+L_pcm]
+ mov WORD PTR [eax],bp ; Store sample in *pcm
+ add eax,4 ; Increment pcm
+ mov ebp,511 ; Reload ebp with 511
+ mov DWORD PTR [esp+L_pcm],eax
+
+ dec dh ; --i
+ jg FirstOuter ; Jump back if i > 0
+
+
+; Special case
+ fldz ; sum = 0.0
+ mov dl,4 ; j = 4
+ align 4
+SpecialInner:
+; REPEAT 2 ; Unrolled loop
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+ebx*4] ; Multiply by vbuf[bx]
+ add ebx,64 ; bx += 64
+ add ecx,4 ; Increment coef pointer
+ and ebx,ebp ; bx &= 511
+ faddp st(1),st ; Add to sum
+;--
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+ebx*4] ; Multiply by vbuf[bx]
+ add ebx,64 ; bx += 64
+ add ecx,4 ; Increment coef pointer
+ and ebx,ebp ; bx &= 511
+ faddp st(1),st ; Add to sum
+;--
+; END REPEAT
+
+ dec dl ; --j
+ jg SpecialInner ; Jump back if j > 0
+
+ fistp DWORD PTR [esp+L_tmp] ; tmp = (long) round (sum)
+ dec esi ; si--
+ mov eax,DWORD PTR [esp+L_tmp]
+ inc ebx ; bx++
+ mov ebp,eax
+ sar eax,15
+ inc eax
+ sar eax,1
+ jz SpecialInRange ; Jump if within range
+
+ sar eax,16 ; Out of range
+ mov ebp,32767
+ xor ebp,eax
+SpecialInRange:
+ mov eax,DWORD PTR [esp+L_pcm]
+ sub ecx,36 ; Readjust coef pointer for last round
+ mov WORD PTR [eax],bp ; Store sample in *pcm
+ add eax,4 ; Increment pcm
+ mov ebp,511 ; Reload ebp with 511
+ mov DWORD PTR [esp+L_pcm],eax
+
+
+; Last 15
+ mov dh,15 ; i = 15
+ align 4
+LastOuter:
+ fldz ; sum = 0.0
+ mov dl,2 ; j = 2
+ align 4
+LastInner:
+; REPEAT 4 ; Unrolled loop
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+esi*4] ; Multiply by vbuf[si]
+ add esi,64 ; si += 64
+ sub ecx,4 ; Back up coef pointer
+ and esi,ebp ; si &= 511
+ faddp st(1),st ; Add to sum
+
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+ebx*4] ; Multiply by vbuf[bx]
+ add ebx,64 ; bx += 64
+ sub ecx,4 ; Back up coef pointer
+ and ebx,ebp ; bx &= 511
+ faddp st(1),st ; Add to sum
+;--
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+esi*4] ; Multiply by vbuf[si]
+ add esi,64 ; si += 64
+ sub ecx,4 ; Back up coef pointer
+ and esi,ebp ; si &= 511
+ faddp st(1),st ; Add to sum
+
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+ebx*4] ; Multiply by vbuf[bx]
+ add ebx,64 ; bx += 64
+ sub ecx,4 ; Back up coef pointer
+ and ebx,ebp ; bx &= 511
+ faddp st(1),st ; Add to sum
+;--
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+esi*4] ; Multiply by vbuf[si]
+ add esi,64 ; si += 64
+ sub ecx,4 ; Back up coef pointer
+ and esi,ebp ; si &= 511
+ faddp st(1),st ; Add to sum
+
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+ebx*4] ; Multiply by vbuf[bx]
+ add ebx,64 ; bx += 64
+ sub ecx,4 ; Back up coef pointer
+ and ebx,ebp ; bx &= 511
+ faddp st(1),st ; Add to sum
+;--
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+esi*4] ; Multiply by vbuf[si]
+ add esi,64 ; si += 64
+ sub ecx,4 ; Back up coef pointer
+ and esi,ebp ; si &= 511
+ faddp st(1),st ; Add to sum
+
+ fld DWORD PTR [ecx] ; Push *coef
+ fmul DWORD PTR [edi+ebx*4] ; Multiply by vbuf[bx]
+ add ebx,64 ; bx += 64
+ sub ecx,4 ; Back up coef pointer
+ and ebx,ebp ; bx &= 511
+ faddp st(1),st ; Add to sum
+;--
+; END REPEAT
+
+ dec dl ; --j
+ jg LastInner ; Jump back if j > 0
+
+ fistp DWORD PTR [esp+L_tmp] ; tmp = (long) round (sum)
+ dec esi ; si--
+ mov eax,DWORD PTR [esp+L_tmp]
+ inc ebx ; bx++
+ mov ebp,eax
+ sar eax,15
+ inc eax
+ sar eax,1
+ jz LastInRange ; Jump if in range
+
+ sar eax,16 ; Out of range
+ mov ebp,32767
+ xor ebp,eax
+LastInRange:
+ mov eax,DWORD PTR [esp+L_pcm]
+ mov WORD PTR [eax],bp ; Store sample in *pcm
+ add eax,4 ; Increment pcm
+ mov ebp,511 ; Reload ebp with 511
+ mov DWORD PTR [esp+L_pcm],eax
+
+ dec dh ; --i
+ jg LastOuter ; Jump back if i > 0
+
+ add esp,8
+ pop ebp
+
+ }
+}
+
+/*--------------------------------------------------------------------------- */
+
+#define L_mi 0
+#define L_m 4
+#define L_dummy 8
+#define L_in 12
+#define L_out 16
+#define L_buf 20 /* Temporary buffer */
+#define L_locals 148 /* Bytes used for locals */
+void asm_fdct32(float in[], float out[])
+{
+__asm {
+
+ mov edi,in ; edi = x
+ mov esi,out ; esi = f
+ push ebp
+ sub esp,L_locals
+
+ lea ecx,coef32-128 ; coef = coef32 - (32 * 4)
+ mov DWORD PTR [esp+4],1 ; m = 1
+ mov ebp,16 ; n = 32 / 2
+
+ lea ebx,DWORD PTR [esp+L_buf]
+ mov DWORD PTR [esp+L_out],ebx ; From now on, use temp buf instead of orig x
+ jmp ForwardLoopStart
+
+ align 4
+ForwardOuterLoop:
+ mov edi,DWORD PTR [esp+L_in] ; edi = x
+ mov esi,DWORD PTR [esp+L_out] ; esi = f
+ mov DWORD PTR [esp+L_out],edi ; Exchange mem versions of f/x for next iter
+ForwardLoopStart:
+ mov DWORD PTR [esp+L_in],esi
+ mov ebx,DWORD PTR [esp+L_m] ; ebx = m (temporarily)
+ mov DWORD PTR [esp+L_mi],ebx ; mi = m
+ sal ebx,1 ; Double m for next iter
+ lea ecx,DWORD PTR [ecx+ebp*8] ; coef += n * 8
+ mov DWORD PTR [esp+L_m],ebx ; Store doubled m
+ lea ebx,DWORD PTR [esi+ebp*4] ; ebx = f2 = f + n * 4
+ sal ebp,3 ; n *= 8
+
+ align 4
+ForwardMiddleLoop:
+ mov eax,ebp ; q = n
+ xor edx,edx ; p = 0
+ test eax,8
+ jnz ForwardInnerLoop1
+
+ align 4
+ForwardInnerLoop:
+ sub eax,4 ; q -= 4
+ fld DWORD PTR [edi+eax] ; push x[q]
+ fld DWORD PTR [edi+edx] ; push x[p]
+ fld st(1) ; Duplicate top two stack entries
+ fld st(1)
+ faddp st(1),st
+ fstp DWORD PTR [esi+edx] ; f[p] = x[p] + x[q]
+ fsubrp st(1),st
+ fmul DWORD PTR [ecx+edx]
+ fstp DWORD PTR [ebx+edx] ; f2[p] = coef[p] * (x[p] - x[q])
+ add edx,4 ; p += 4
+
+ForwardInnerLoop1:
+ sub eax,4 ; q -= 4
+ fld DWORD PTR [edi+eax] ; push x[q]
+ fld DWORD PTR [edi+edx] ; push x[p]
+ fld st(1) ; Duplicate top two stack entries
+ fld st(1)
+ faddp st(1),st
+ fstp DWORD PTR [esi+edx] ; f[p] = x[p] + x[q]
+ fsubrp st(1),st
+ fmul DWORD PTR [ecx+edx]
+ fstp DWORD PTR [ebx+edx] ; f2[p] = coef[p] * (x[p] - x[q])
+ add edx,4 ; p += 4
+
+ cmp edx,eax
+ jb ForwardInnerLoop ; Jump back if (p < q)
+
+ add esi,ebp ; f += n
+ add ebx,ebp ; f2 += n
+ add edi,ebp ; x += n
+ dec DWORD PTR [esp+L_mi] ; mi--
+ jg ForwardMiddleLoop ; Jump back if mi > 0
+
+ sar ebp,4 ; n /= 16
+ jg ForwardOuterLoop ; Jump back if n > 0
+
+
+; Setup back loop
+ mov ebx,8 ; ebx = m = 8 (temporarily)
+ mov ebp,ebx ; n = 4 * 2
+
+ align 4
+BackOuterLoop:
+ mov esi,DWORD PTR [esp+L_out] ; esi = f
+ mov DWORD PTR [esp+L_mi],ebx ; mi = m
+ mov edi,DWORD PTR [esp+L_in] ; edi = x
+ mov DWORD PTR [esp+L_m],ebx ; Store m
+ mov DWORD PTR [esp+L_in],esi ; Exchange mem versions of f/x for next iter
+ mov ebx,edi
+ mov DWORD PTR [esp+L_out],edi
+ sub ebx,ebp ; ebx = x2 = x - n
+ sal ebp,1 ; n *= 2
+
+ align 4
+BackMiddleLoop:
+ mov ecx,DWORD PTR [ebx+ebp-4]
+ mov DWORD PTR [esi+ebp-8],ecx ; f[n - 8] = x2[n - 4]
+ fld DWORD PTR [edi+ebp-4] ; push x[n - 4]
+ fst DWORD PTR [esi+ebp-4] ; f[n - 4] = x[n - 4], without popping
+ lea eax,DWORD PTR [ebp-8] ; q = n - 8
+ lea edx,DWORD PTR [ebp-16] ; p = n - 16
+
+ align 4
+BackInnerLoop:
+ mov ecx,DWORD PTR [ebx+eax]
+ mov DWORD PTR [esi+edx],ecx ; f[p] = x2[q]
+ fld DWORD PTR [edi+eax] ; push x[q]
+ fadd st(1),st
+ fxch
+ fstp DWORD PTR [esi+edx+4] ; f[p + 4] = x[q] + x[q + 4]
+ sub eax,4 ; q -= 4
+ sub edx,8 ; p -= 8
+ jge BackInnerLoop ; Jump back if p >= 0
+
+ fstp DWORD PTR [esp+L_dummy] ; Pop (XXX is there a better way to do this?)
+ add esi,ebp ; f += n
+ add ebx,ebp ; x2 += n
+ add edi,ebp ; x += n
+ dec DWORD PTR [esp+L_mi] ; mi--
+ jg BackMiddleLoop ; Jump back if mi > 0
+
+ mov ebx,DWORD PTR [esp+L_m] ; ebx = m (temporarily)
+ sar ebx,1 ; Halve m for next iter
+ jg BackOuterLoop ; Jump back if m > 0
+
+ add esp,L_locals
+ pop ebp
+
+ }
+}
+