Skip to content
Snippets Groups Projects
Commit 75b66055 authored by Mark Spencer's avatar Mark Spencer
Browse files

Version 0.1.1 from FTP

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@95 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 46ba76c2
Branches
Tags
No related merge requests found
Showing
with 6594 additions and 0 deletions
/*____________________________________________________________________________
FreeAmp - The Free MP3 Player
MP3 Decoder originally Copyright (C) 1996-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$
____________________________________________________________________________*/
/**** L3.h ***************************************************
Layer III structures
*** Layer III is 32 bit only ***
*** Layer III code assumes 32 bit int ***
******************************************************************/
#define GLOBAL_GAIN_SCALE (4*15)
/* #define GLOBAL_GAIN_SCALE 0 */
#ifdef _M_IX86
#define LITTLE_ENDIAN 1
#endif
#ifdef _M_ALPHA
#define LITTLE_ENDIAN 1
#endif
#ifdef sparc
#define LITTLE_ENDIAN 0
#endif
#ifndef LITTLE_ENDIAN
#error Layer III LITTLE_ENDIAN must be defined 0 or 1
#endif
/*-----------------------------------------------------------*/
/*---- huffman lookup tables ---*/
/* endian dependent !!! */
#if LITTLE_ENDIAN
typedef union
{
int ptr;
struct
{
unsigned char signbits;
unsigned char x;
unsigned char y;
unsigned char purgebits; // 0 = esc
}
b;
}
HUFF_ELEMENT;
#else /* big endian machines */
typedef union
{
int ptr; /* int must be 32 bits or more */
struct
{
unsigned char purgebits; // 0 = esc
unsigned char y;
unsigned char x;
unsigned char signbits;
}
b;
}
HUFF_ELEMENT;
#endif
/*--------------------------------------------------------------*/
typedef struct
{
unsigned int bitbuf;
int bits;
unsigned char *bs_ptr;
unsigned char *bs_ptr0;
unsigned char *bs_ptr_end; // optional for overrun test
}
BITDAT;
/*-- side info ---*/
typedef struct
{
int part2_3_length;
int big_values;
int global_gain;
int scalefac_compress;
int window_switching_flag;
int block_type;
int mixed_block_flag;
int table_select[3];
int subblock_gain[3];
int region0_count;
int region1_count;
int preflag;
int scalefac_scale;
int count1table_select;
}
GR;
typedef struct
{
int mode;
int mode_ext;
/*---------------*/
int main_data_begin; /* beginning, not end, my spec wrong */
int private_bits;
/*---------------*/
int scfsi[2]; /* 4 bit flags [ch] */
GR gr[2][2]; /* [gran][ch] */
}
SIDE_INFO;
/*-----------------------------------------------------------*/
/*-- scale factors ---*/
// check dimensions - need 21 long, 3*12 short
// plus extra for implicit sf=0 above highest cb
typedef struct
{
int l[23]; /* [cb] */
int s[3][13]; /* [window][cb] */
}
SCALEFACT;
/*-----------------------------------------------------------*/
typedef struct
{
int cbtype; /* long=0 short=1 */
int cbmax; /* max crit band */
// int lb_type; /* long block type 0 1 3 */
int cbs0; /* short band start index 0 3 12 (12=no shorts */
int ncbl; /* number long cb's 0 8 21 */
int cbmax_s[3]; /* cbmax by individual short blocks */
}
CB_INFO;
/*-----------------------------------------------------------*/
/* scale factor infor for MPEG2 intensity stereo */
typedef struct
{
int nr[3];
int slen[3];
int intensity_scale;
}
IS_SF_INFO;
/*-----------------------------------------------------------*/
typedef union
{
int s;
float x;
}
SAMPLE;
/*-----------------------------------------------------------*/
This diff is collapsed.
/*____________________________________________________________________________
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$
____________________________________________________________________________*/
/*---------------------------------------------------------------
mpeg Layer II audio decoder, integer version
variable type control
-----------------------------------------------------------------*/
/*-----------------------------------------------------------------
Variable types can have a large impact on performance. If the
native type int is 32 bit or better, setting all variables to the
native int is probably the best bet. Machines with fast floating
point handware will probably run faster with the floating point
version of this decoder.
On 16 bit machines, use the native 16 bit int where possible
with special consideration given to the multiplies used in
the dct and window (see below).
The code uses the type INT32 when 32 or more bits are required.
Use the native int if possible.
Signed types are required for all but DCTCOEF which may be unsigned.
THe major parts of the decoder are: bit stream unpack (iup.c),
dct (cidct.c), and window (iwinq.c). The compute time relationship
is usually unpack < dct < window.
-------------------------------------------------------------------*/
/*-------------- dct cidct.c -------------------------------------------
dct input is type SAMPLEINT, output is WININT
DCTCOEF: dct coefs, 16 or more bits required
DCTBITS: fractional bits in dct coefs. Coefs are unsigned in
the range 0.50 to 10.2. DCTBITS=10 is a compromise
between precision and the possibility of overflowing
intermediate results.
DCTSATURATE: If set, saturates dct output to 16 bit.
Dct output may overflow if WININT is 16 bit, overflow
is rare, but very noisy. Define to 1 for 16 bit WININT.
Define to 0 otherwise.
The multiply used in the dct (routine forward_bf in cidct.c) requires
the multiplication of a 32 bit variable by a 16 bit unsigned coef
to produce a signed 32 bit result. On 16 bit machines this could be
faster than a full 32x32 multiply.
------------------------------------------------------------------*/
/*-------------- WINDOW iwinq.c ---------------------------------------
window input is type WININT, output is short (16 bit pcm audio)
window coefs WINBITS fractional bits,
coefs are signed range in -1.15 to 0.96.
WINBITS=14 is maximum for 16 bit signed representation.
Some CPU's will multiply faster with fewer bits.
WINBITS less that 8 may cause noticeable quality loss.
WINMULT defines the multiply used in the window (iwinq.c)
WINMULT must produce a 32 bit (or better) result, although both
multipliers may be 16 bit. A 16x16-->32 multiply may offer
a performance advantage if the compiler can be coerced into
doing the right thing.
------------------------------------------------------------------*/
/*-- settings for MS C++ 4.0 flat 32 bit (long=int=32bit) --*/
/*-- asm replacement modules must use these settings ---*/
typedef long INT32;
typedef unsigned long UINT32;
typedef int SAMPLEINT;
typedef int DCTCOEF;
#define DCTBITS 10
#define DCTSATURATE 0
typedef int WININT;
typedef int WINCOEF;
#define WINBITS 10
#define WINMULT(x,coef) ((x)*(coef))
/*____________________________________________________________________________
FreeAmp - The Free MP3 Player
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$
____________________________________________________________________________*/
/* LOL */
#ifndef min
#define min(a,b) ((a>b)?b:a)
#endif
/*____________________________________________________________________________
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$
____________________________________________________________________________*/
/* portable copy of eco\mhead.h */
/* mpeg audio header */
typedef struct
{
int sync; /* 1 if valid sync */
int id;
int option;
int prot;
int br_index;
int sr_index;
int pad;
int private_bit;
int mode;
int mode_ext;
int cr;
int original;
int emphasis;
}
MPEG_HEAD;
/* portable mpeg audio decoder, decoder functions */
typedef struct
{
int in_bytes;
int out_bytes;
}
IN_OUT;
typedef struct
{
int channels;
int outvalues;
long samprate;
int bits;
int framebytes;
int type;
}
DEC_INFO;
typedef IN_OUT(*AUDIO_DECODE_ROUTINE) (void *mv, unsigned char *bs, signed short *pcm);
typedef IN_OUT(*DECODE_FUNCTION) (void *mv, unsigned char *bs, unsigned char *pcm);
struct _mpeg;
typedef struct _mpeg MPEG;
typedef void (*SBT_FUNCTION_F) (MPEG *m, float *sample, short *pcm, int n);
/* main data bit buffer */
#define NBUF (8*1024)
#define BUF_TRIGGER (NBUF-1500)
typedef void (*XFORM_FUNCTION) (void *mv, void *pcm, int igr);
struct _mpeg
{
struct {
float look_c_value[18]; /* built by init */
unsigned char *bs_ptr;
unsigned long bitbuf;
int bits;
long bitval;
int outbytes;
int framebytes;
int outvalues;
int pad;
int stereo_sb;
DEC_INFO decinfo; /* global for Layer III */
int max_sb;
int nsb_limit;
int first_pass;
int first_pass_L1;
int bit_skip;
int nbat[4];
int bat[4][16];
int ballo[64]; /* set by unpack_ba */
unsigned int samp_dispatch[66]; /* set by unpack_ba */
float c_value[64]; /* set by unpack_ba */
unsigned int sf_dispatch[66]; /* set by unpack_ba */
float sf_table[64];
float cs_factor[3][64];
float *sample; /* global for use by Later 3 */
signed char group3_table[32][3];
signed char group5_table[128][3];
signed short group9_table[1024][3];
SBT_FUNCTION_F sbt;
AUDIO_DECODE_ROUTINE audio_decode_routine ;
float *cs_factorL1;
float look_c_valueL1[16];
int nbatL1;
} cup;
struct {
/* cupl3.c */
int nBand[2][22]; /* [long/short][cb] */
int sfBandIndex[2][22]; /* [long/short][cb] */
int mpeg25_flag;
int iframe;
int band_limit;
int band_limit21;
int band_limit12;
int band_limit_nsb;
int nsb_limit;
int gaim_adjust;
int id;
int ncbl_mixed;
int gain_adjust;
int sr_index;
int outvalues;
int outbytes;
int half_outbytes;
int framebytes;
int padframebytes;
int crcbytes;
int pad;
int stereo_flag;
int nchan;
int ms_mode;
int is_mode;
unsigned int zero_level_pcm;
CB_INFO cb_info[2][2];
IS_SF_INFO is_sf_info; /* MPEG-2 intensity stereo */
unsigned char buf[NBUF];
int buf_ptr0;
int buf_ptr1;
int main_pos_bit;
SIDE_INFO side_info;
SCALEFACT sf[2][2]; /* [gr][ch] */
int nsamp[2][2]; /* must start = 0, for nsamp[igr_prev] */
float yout[576]; /* hybrid out, sbt in */
SAMPLE sample[2][2][576];
SBT_FUNCTION_F sbt_L3;
XFORM_FUNCTION Xform;
DECODE_FUNCTION decode_function;
/* msis.c */
/*-- windows by block type --*/
float win[4][36];
float csa[8][2]; /* antialias */
float lr[2][8][2]; /* [ms_mode 0/1][sf][left/right] */
float lr2[2][2][64][2];
/* l3dq.c */
float look_global[256 + 2 + 4];
float look_scale[2][4][32];
#define ISMAX 32
float look_pow[2 * ISMAX];
float look_subblock[8];
float re_buf[192][3];
} cupl;
struct {
signed int vb_ptr;
signed int vb2_ptr;
float vbuf[512];
float vbuf2[512];
int first_pass;
} csbt;
struct {
float coef32[31]; /* 32 pt dct coefs */
} cdct;
};
typedef int (*CVT_FUNCTION_8) (void *mv, unsigned char *pcm);
typedef struct
{
struct {
unsigned char look_u[8192];
short pcm[2304];
int ncnt;
int ncnt1;
int nlast;
int ndeci;
int kdeci;
int first_pass;
short xsave;
CVT_FUNCTION_8 convert_routine;
} dec;
MPEG cupper;
}
MPEG8;
#include "itype.h"
typedef void (*SBT_FUNCTION) (SAMPLEINT * sample, short *pcm, int n);
typedef void (*UNPACK_FUNCTION) ();
typedef struct
{
struct {
DEC_INFO decinfo;
int pad;
int look_c_value[18]; /* built by init */
int look_c_shift[18]; /* built by init */
int outbytes;
int framebytes;
int outvalues;
int max_sb;
int stereo_sb;
int nsb_limit;
int bit_skip;
int nbat[4];
int bat[4][16];
int ballo[64]; /* set by unpack_ba */
unsigned int samp_dispatch[66]; /* set by unpack_ba */
int c_value[64]; /* set by unpack_ba */
int c_shift[64]; /* set by unpack_ba */
unsigned int sf_dispatch[66]; /* set by unpack_ba */
int sf_table[64];
INT32 cs_factor[3][64];
SAMPLEINT sample[2304];
signed char group3_table[32][3];
signed char group5_table[128][3];
signed short group9_table[1024][3];
int nsbt;
SBT_FUNCTION sbt;
UNPACK_FUNCTION unpack_routine;
unsigned char *bs_ptr;
UINT32 bitbuf;
int bits;
INT32 bitval;
int first_pass;
int first_pass_L1;
int nbatL1;
INT32 *cs_factorL1;
int look_c_valueL1[16]; /* built by init */
int look_c_shiftL1[16]; /* built by init */
} iup;
}
MPEGI;
#ifdef __cplusplus
extern "C"
{
#endif
void mpeg_init(MPEG *m);
int head_info(unsigned char *buf, unsigned int n, MPEG_HEAD * h);
int head_info2(unsigned char *buf,
unsigned int n, MPEG_HEAD * h, int *br);
int head_info3(unsigned char *buf, unsigned int n, MPEG_HEAD *h, int*br, unsigned int *searchForward);
/* head_info returns framebytes > 0 for success */
/* audio_decode_init returns 1 for success, 0 for fail */
/* audio_decode returns in_bytes = 0 on sync loss */
int audio_decode_init(MPEG *m, MPEG_HEAD * h, int framebytes_arg,
int reduction_code, int transform_code, int convert_code,
int freq_limit);
void audio_decode_info(MPEG *m, DEC_INFO * info);
IN_OUT audio_decode(MPEG *m, unsigned char *bs, short *pcm);
void mpeg8_init(MPEG8 *m);
int audio_decode8_init(MPEG8 *m, MPEG_HEAD * h, int framebytes_arg,
int reduction_code, int transform_code, int convert_code,
int freq_limit);
void audio_decode8_info(MPEG8 *m, DEC_INFO * info);
IN_OUT audio_decode8(MPEG8 *m, unsigned char *bs, short *pcmbuf);
/*-- integer decode --*/
void i_mpeg_init(MPEGI *m);
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);
void i_audio_decode_info(MPEGI *m, DEC_INFO * info);
IN_OUT i_audio_decode(MPEGI *m, unsigned char *bs, short *pcm);
#ifdef __cplusplus
}
#endif
/*____________________________________________________________________________
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$
____________________________________________________________________________*/
#ifndef O_BINARY
#define O_BINARY 0
#endif
/*--- no kb function unless DOS ---*/
#ifndef KB_OK
#ifdef __MSDOS__
#define KB_OK
#endif
#ifdef _CONSOLE
#define KB_OK
#endif
#endif
#ifdef NEED_KBHIT
#ifdef KB_OK
#ifdef _MSC_VER
#pragma warning(disable: 4032)
#endif
#include <conio.h>
#else
static int kbhit()
{
return 0;
}
static int getch()
{
return 0;
}
#endif
#endif
/*-- no pcm conversion to wave required
if short = 16 bits and little endian ---*/
/* mods 1/9/97 LITTLE_SHORT16 detect */
#ifndef LITTLE_SHORT16
#ifdef __MSDOS__
#undef LITTLE_SHORT16
#define LITTLE_SHORT16
#endif
#ifdef WIN32
#undef LITTLE_SHORT16
#define LITTLE_SHORT16
#endif
#ifdef _M_IX86
#undef LITTLE_SHORT16
#define LITTLE_SHORT16
#endif
#endif
// JDW //
//#ifdef LITTLE_SHORT16
//#define cvt_to_wave_init(a)
//#define cvt_to_wave(a, b) b
//#else
//void cvt_to_wave_init(int bits);
//unsigned int cvt_to_wave(void *a, unsigned int b);
//
//#endif
#ifdef LITTLE_SHORT16
#define cvt_to_wave_init(a)
#define cvt_to_wave(a, b) b
#else
void cvt_to_wave_init(int);
unsigned int cvt_to_wave(unsigned char *,unsigned int);
#endif
int cvt_to_wave_test(void);
/*====================================================================*/
int hybrid(MPEG *m, void *xin, void *xprev, float *y,
int btype, int nlong, int ntot, int nprev);
int hybrid_sum(MPEG *m, void *xin, void *xin_left, float *y,
int btype, int nlong, int ntot);
void sum_f_bands(void *a, void *b, int n);
void FreqInvert(float *y, int n);
void antialias(MPEG *m, void *x, int n);
void ms_process(void *x, int n); /* sum-difference stereo */
void is_process_MPEG1(MPEG *m, void *x, /* intensity stereo */
SCALEFACT * sf,
CB_INFO cb_info[2], /* [ch] */
int nsamp, int ms_mode);
void is_process_MPEG2(MPEG *m, void *x, /* intensity stereo */
SCALEFACT * sf,
CB_INFO cb_info[2], /* [ch] */
IS_SF_INFO * is_sf_info,
int nsamp, int ms_mode);
void unpack_huff(void *xy, int n, int ntable);
int unpack_huff_quad(void *vwxy, int n, int nbits, int ntable);
void dequant(MPEG *m, SAMPLE sample[], int *nsamp,
SCALEFACT * sf,
GR * gr,
CB_INFO * cb_info, int ncbl_mixed);
void unpack_sf_sub_MPEG1(SCALEFACT * scalefac, GR * gr,
int scfsi, /* bit flag */
int igr);
void unpack_sf_sub_MPEG2(SCALEFACT sf[], /* return intensity scale */
GR * grdat,
int is_and_ch, IS_SF_INFO * is_sf_info);
/*---------- quant ---------------------------------*/
/* 8 bit lookup x = pow(2.0, 0.25*(global_gain-210)) */
float *quant_init_global_addr(MPEG *m);
/* x = pow(2.0, -0.5*(1+scalefact_scale)*scalefac + preemp) */
typedef float LS[4][32];
LS *quant_init_scale_addr(MPEG *m);
float *quant_init_pow_addr(MPEG *m);
float *quant_init_subblock_addr(MPEG *m);
typedef int iARRAY22[22];
iARRAY22 *quant_init_band_addr(MPEG *m);
/*---------- antialias ---------------------------------*/
typedef float PAIR[2];
PAIR *alias_init_addr(MPEG *m);
/*____________________________________________________________________________
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$
____________________________________________________________________________*/
/* decoder analysis window gen by dinit.c (asm version table gen) */
0.000000000f, 0.000442505f, -0.003250122f, 0.007003784f,
-0.031082151f, 0.078628540f, -0.100311279f, 0.572036743f,
-1.144989014f, -0.572036743f, -0.100311279f, -0.078628540f,
-0.031082151f, -0.007003784f, -0.003250122f, -0.000442505f,
0.000015259f, 0.000473022f, -0.003326416f, 0.007919312f,
-0.030517576f, 0.084182739f, -0.090927124f, 0.600219727f,
-1.144287109f, -0.543823242f, -0.108856201f, -0.073059082f,
-0.031478882f, -0.006118774f, -0.003173828f, -0.000396729f,
0.000015259f, 0.000534058f, -0.003387451f, 0.008865356f,
-0.029785154f, 0.089706421f, -0.080688477f, 0.628295898f,
-1.142211914f, -0.515609741f, -0.116577141f, -0.067520142f,
-0.031738281f, -0.005294800f, -0.003082275f, -0.000366211f,
0.000015259f, 0.000579834f, -0.003433228f, 0.009841919f,
-0.028884888f, 0.095169067f, -0.069595337f, 0.656219482f,
-1.138763428f, -0.487472534f, -0.123474121f, -0.061996460f,
-0.031845093f, -0.004486084f, -0.002990723f, -0.000320435f,
0.000015259f, 0.000625610f, -0.003463745f, 0.010848999f,
-0.027801514f, 0.100540161f, -0.057617184f, 0.683914185f,
-1.133926392f, -0.459472656f, -0.129577637f, -0.056533810f,
-0.031814575f, -0.003723145f, -0.002899170f, -0.000289917f,
0.000015259f, 0.000686646f, -0.003479004f, 0.011886597f,
-0.026535034f, 0.105819702f, -0.044784546f, 0.711318970f,
-1.127746582f, -0.431655884f, -0.134887695f, -0.051132202f,
-0.031661987f, -0.003005981f, -0.002792358f, -0.000259399f,
0.000015259f, 0.000747681f, -0.003479004f, 0.012939452f,
-0.025085449f, 0.110946655f, -0.031082151f, 0.738372803f,
-1.120223999f, -0.404083252f, -0.139450073f, -0.045837402f,
-0.031387329f, -0.002334595f, -0.002685547f, -0.000244141f,
0.000030518f, 0.000808716f, -0.003463745f, 0.014022826f,
-0.023422241f, 0.115921021f, -0.016510010f, 0.765029907f,
-1.111373901f, -0.376800537f, -0.143264771f, -0.040634155f,
-0.031005858f, -0.001693726f, -0.002578735f, -0.000213623f,
0.000030518f, 0.000885010f, -0.003417969f, 0.015121460f,
-0.021575928f, 0.120697014f, -0.001068115f, 0.791213989f,
-1.101211548f, -0.349868774f, -0.146362305f, -0.035552979f,
-0.030532837f, -0.001098633f, -0.002456665f, -0.000198364f,
0.000030518f, 0.000961304f, -0.003372192f, 0.016235352f,
-0.019531250f, 0.125259399f, 0.015228271f, 0.816864014f,
-1.089782715f, -0.323318481f, -0.148773193f, -0.030609131f,
-0.029937742f, -0.000549316f, -0.002349854f, -0.000167847f,
0.000030518f, 0.001037598f, -0.003280640f, 0.017349243f,
-0.017257690f, 0.129562378f, 0.032379150f, 0.841949463f,
-1.077117920f, -0.297210693f, -0.150497437f, -0.025817871f,
-0.029281614f, -0.000030518f, -0.002243042f, -0.000152588f,
0.000045776f, 0.001113892f, -0.003173828f, 0.018463135f,
-0.014801024f, 0.133590698f, 0.050354004f, 0.866363525f,
-1.063217163f, -0.271591187f, -0.151596069f, -0.021179199f,
-0.028533936f, 0.000442505f, -0.002120972f, -0.000137329f,
0.000045776f, 0.001205444f, -0.003051758f, 0.019577026f,
-0.012115479f, 0.137298584f, 0.069168091f, 0.890090942f,
-1.048156738f, -0.246505737f, -0.152069092f, -0.016708374f,
-0.027725220f, 0.000869751f, -0.002014160f, -0.000122070f,
0.000061035f, 0.001296997f, -0.002883911f, 0.020690918f,
-0.009231566f, 0.140670776f, 0.088775635f, 0.913055420f,
-1.031936646f, -0.221984863f, -0.151962280f, -0.012420653f,
-0.026840210f, 0.001266479f, -0.001907349f, -0.000106812f,
0.000061035f, 0.001388550f, -0.002700806f, 0.021789551f,
-0.006134033f, 0.143676758f, 0.109161377f, 0.935195923f,
-1.014617920f, -0.198059082f, -0.151306152f, -0.008316040f,
-0.025909424f, 0.001617432f, -0.001785278f, -0.000106812f,
0.000076294f, 0.001480103f, -0.002487183f, 0.022857666f,
-0.002822876f, 0.146255493f, 0.130310059f, 0.956481934f,
-0.996246338f, -0.174789429f, -0.150115967f, -0.004394531f,
-0.024932859f, 0.001937866f, -0.001693726f, -0.000091553f,
-0.001586914f, -0.023910521f, -0.148422241f, -0.976852417f,
0.152206421f, 0.000686646f, -0.002227783f, 0.000076294f,
/*____________________________________________________________________________
FreeAmp - The Free MP3 Player
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$
____________________________________________________________________________*/
#ifndef INCLUDED_XINGLMC_H_
#define INCLUDED_XINGLMC_H_
/* system headers */
#include <stdlib.h>
#include <time.h>
/* project headers */
#include "config.h"
#include "pmi.h"
#include "pmo.h"
#include "mutex.h"
#include "event.h"
#include "lmc.h"
#include "thread.h"
#include "mutex.h"
#include "queue.h"
#include "semaphore.h"
extern "C"
{
#include "mhead.h"
#include "port.h"
}
#define BS_BUFBYTES 60000U
#define PCM_BUFBYTES 60000U
typedef struct
{
int (*decode_init) (MPEG_HEAD * h, int framebytes_arg,
int reduction_code, int transform_code,
int convert_code, int freq_limit);
void (*decode_info) (DEC_INFO * info);
IN_OUT(*decode) (unsigned char *bs, short *pcm);
}
AUDIO;
#define FRAMES_FLAG 0x0001
#define BYTES_FLAG 0x0002
#define TOC_FLAG 0x0004
#define VBR_SCALE_FLAG 0x0008
#define FRAMES_AND_BYTES (FRAMES_FLAG | BYTES_FLAG)
// structure to receive extracted header
// toc may be NULL
typedef struct
{
int h_id; // from MPEG header, 0=MPEG2, 1=MPEG1
int samprate; // determined from MPEG header
int flags; // from Xing header data
int frames; // total bit stream frames from Xing header data
int bytes; // total bit stream bytes from Xing header data
int vbr_scale; // encoded vbr scale from Xing header data
unsigned char *toc; // pointer to unsigned char toc_buffer[100]
// may be NULL if toc not desired
} XHEADDATA;
enum
{
lmcError_MinimumError = 1000,
lmcError_DecodeFailed,
lmcError_AudioDecodeInitFailed,
lmcError_DecoderThreadFailed,
lmcError_PMIError,
lmcError_PMOError,
lmcError_MaximumError
};
class XingLMC:public LogicalMediaConverter
{
public:
XingLMC(FAContext *context);
virtual ~XingLMC();
virtual uint32 CalculateSongLength(const char *url);
virtual Error ChangePosition(int32 position);
virtual Error CanDecode();
virtual void Clear();
virtual Error ExtractMediaInfo();
virtual void SetPMI(PhysicalMediaInput *pmi) { m_pPmi = pmi; };
virtual void SetPMO(PhysicalMediaOutput *pmo) { m_pPmo = pmo; };
virtual Error Prepare(PullBuffer *pInputBuffer, PullBuffer *&pOutBuffer);
virtual Error InitDecoder();
virtual Error SetEQData(float *);
virtual Error SetEQData(bool);
virtual vector<char *> *GetExtensions(void);
private:
static void DecodeWorkerThreadFunc(void *);
void DecodeWork();
Error BeginRead(void *&pBuffer, unsigned int iBytesNeeded,
bool bBufferUp = true);
Error BlockingBeginRead(void *&pBuffer,
unsigned int iBytesNeeded);
Error EndRead(size_t iBytesUsed);
Error AdvanceBufferToNextFrame();
Error GetHeadInfo();
Error GetBitstreamStats(float &fTotalSeconds, float &fMsPerFrame,
int &iTotalFrames, int &iSampleRate,
int &iLayer);
int GetXingHeader(XHEADDATA *X, unsigned char *buf);
int SeekPoint(unsigned char TOC[100], int file_bytes, float percent);
int ExtractI4(unsigned char *buf);
PhysicalMediaInput *m_pPmi;
PhysicalMediaOutput *m_pPmo;
int m_iMaxWriteSize;
int32 m_frameBytes, m_iBufferUpInterval, m_iBufferSize;
size_t m_lFileSize;
MPEG_HEAD m_sMpegHead;
int32 m_iBitRate;
bool m_bBufferingUp;
Thread *m_decoderThread;
int32 m_frameCounter;
time_t m_iBufferUpdate;
char *m_szUrl;
const char *m_szError;
AUDIO m_audioMethods;
XHEADDATA *m_pXingHeader;
// These vars are used for a nasty hack.
FILE *m_fpFile;
char *m_pLocalReadBuffer;
};
#endif /* _XINGLMC_H */
/*____________________________________________________________________________
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);
}
/*------------------------------------------------------------*/
/*____________________________________________________________________________
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 */
/*------------------------------------------------------------*/
/*____________________________________________________________________________
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;
}
}
}
/*------------------------------------------------------------*/
/*____________________________________________________________________________
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;
}
}
/*------------------------------------------------------------*/
/*____________________________________________________________________________
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 */
}
/*---------------------------------------------------------*/
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*____________________________________________________________________________
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
/*--------------------------------------------------------*/
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment