2009-07-06 23:26:13 +00:00
|
|
|
/*
|
|
|
|
* Mpeg Layer-1 audio decoder
|
2003-07-24 22:12:59 +00:00
|
|
|
* --------------------------
|
|
|
|
* copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
|
|
|
|
* near unoptimzed ...
|
|
|
|
*
|
2009-07-06 23:26:13 +00:00
|
|
|
* may have a few bugs after last optimization ...
|
2003-07-24 22:12:59 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-07-30 22:20:50 +00:00
|
|
|
/*
|
|
|
|
* Modified for use with MPlayer, for details see the changelog at
|
|
|
|
* http://svn.mplayerhq.hu/mplayer/trunk/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* The above-mentioned README file has the following to say about licensing:
|
|
|
|
*
|
|
|
|
* COPYING: you may use this source under LGPL terms!
|
|
|
|
*/
|
|
|
|
|
2003-07-24 22:12:59 +00:00
|
|
|
//#include "mpg123.h"
|
|
|
|
|
|
|
|
static void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr)
|
|
|
|
{
|
|
|
|
unsigned int *ba=balloc;
|
|
|
|
unsigned int *sca = (unsigned int *) scale_index;
|
|
|
|
|
2005-04-10 16:39:00 +00:00
|
|
|
if(fr->stereo == 2) {
|
2003-07-24 22:12:59 +00:00
|
|
|
int i;
|
|
|
|
int jsbound = fr->jsbound;
|
2009-07-06 23:26:13 +00:00
|
|
|
for (i=0;i<jsbound;i++) {
|
2003-07-24 22:12:59 +00:00
|
|
|
*ba++ = getbits(4);
|
|
|
|
*ba++ = getbits(4);
|
|
|
|
}
|
|
|
|
for (i=jsbound;i<SBLIMIT;i++)
|
|
|
|
*ba++ = getbits(4);
|
|
|
|
|
|
|
|
ba = balloc;
|
|
|
|
|
|
|
|
for (i=0;i<jsbound;i++) {
|
|
|
|
if ((*ba++))
|
|
|
|
*sca++ = getbits(6);
|
|
|
|
if ((*ba++))
|
|
|
|
*sca++ = getbits(6);
|
|
|
|
}
|
|
|
|
for (i=jsbound;i<SBLIMIT;i++)
|
|
|
|
if ((*ba++)) {
|
|
|
|
*sca++ = getbits(6);
|
|
|
|
*sca++ = getbits(6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int i;
|
|
|
|
for (i=0;i<SBLIMIT;i++)
|
|
|
|
*ba++ = getbits(4);
|
|
|
|
ba = balloc;
|
|
|
|
for (i=0;i<SBLIMIT;i++)
|
|
|
|
if ((*ba++))
|
|
|
|
*sca++ = getbits(6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
|
|
|
|
unsigned int scale_index[2][SBLIMIT],struct frame *fr)
|
|
|
|
{
|
|
|
|
int i,n;
|
|
|
|
int smpb[2*SBLIMIT]; /* values: 0-65535 */
|
|
|
|
int *sample;
|
|
|
|
register unsigned int *ba;
|
|
|
|
register unsigned int *sca = (unsigned int *) scale_index;
|
|
|
|
|
2005-04-10 16:39:00 +00:00
|
|
|
if(fr->stereo == 2) {
|
2003-07-24 22:12:59 +00:00
|
|
|
int jsbound = fr->jsbound;
|
|
|
|
register real *f0 = fraction[0];
|
|
|
|
register real *f1 = fraction[1];
|
|
|
|
ba = balloc;
|
|
|
|
for (sample=smpb,i=0;i<jsbound;i++) {
|
|
|
|
if ((n = *ba++))
|
|
|
|
*sample++ = getbits(n+1);
|
|
|
|
if ((n = *ba++))
|
|
|
|
*sample++ = getbits(n+1);
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
for (i=jsbound;i<SBLIMIT;i++)
|
2003-07-24 22:12:59 +00:00
|
|
|
if ((n = *ba++))
|
|
|
|
*sample++ = getbits(n+1);
|
|
|
|
|
|
|
|
ba = balloc;
|
|
|
|
for (sample=smpb,i=0;i<jsbound;i++) {
|
|
|
|
if((n=*ba++))
|
|
|
|
*f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
|
|
|
|
else
|
|
|
|
*f0++ = 0.0;
|
|
|
|
if((n=*ba++))
|
|
|
|
*f1++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
|
|
|
|
else
|
|
|
|
*f1++ = 0.0;
|
|
|
|
}
|
|
|
|
for (i=jsbound;i<SBLIMIT;i++) {
|
|
|
|
if ((n=*ba++)) {
|
|
|
|
real samp = ( ((-1)<<n) + (*sample++) + 1);
|
|
|
|
*f0++ = samp * muls[n+1][*sca++];
|
|
|
|
*f1++ = samp * muls[n+1][*sca++];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*f0++ = *f1++ = 0.0;
|
|
|
|
}
|
|
|
|
for(i=fr->down_sample_sblimit;i<32;i++)
|
|
|
|
fraction[0][i] = fraction[1][i] = 0.0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
register real *f0 = fraction[0];
|
|
|
|
ba = balloc;
|
|
|
|
for (sample=smpb,i=0;i<SBLIMIT;i++)
|
|
|
|
if ((n = *ba++))
|
|
|
|
*sample++ = getbits(n+1);
|
|
|
|
ba = balloc;
|
|
|
|
for (sample=smpb,i=0;i<SBLIMIT;i++) {
|
|
|
|
if((n=*ba++))
|
|
|
|
*f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
|
|
|
|
else
|
|
|
|
*f0++ = 0.0;
|
|
|
|
}
|
|
|
|
for(i=fr->down_sample_sblimit;i<32;i++)
|
|
|
|
fraction[0][i] = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_layer1(struct frame *fr,int single)
|
|
|
|
{
|
|
|
|
int clip=0;
|
|
|
|
int i,stereo = fr->stereo;
|
|
|
|
unsigned int balloc[2*SBLIMIT];
|
|
|
|
unsigned int scale_index[2][SBLIMIT];
|
2007-06-06 05:13:13 +00:00
|
|
|
DECLARE_ALIGNED(16, real, fraction[2][SBLIMIT]);
|
2003-07-24 22:12:59 +00:00
|
|
|
// int single = fr->single;
|
|
|
|
|
|
|
|
// printf("do_layer1(0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X )\n",
|
|
|
|
// wordpointer[0],wordpointer[1],wordpointer[2],wordpointer[3],wordpointer[4],wordpointer[5],wordpointer[6],wordpointer[7]);
|
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
|
2003-07-24 22:12:59 +00:00
|
|
|
(fr->mode_ext<<2)+4 : 32;
|
|
|
|
|
|
|
|
if(stereo == 1 || single == 3)
|
|
|
|
single = 0;
|
|
|
|
|
|
|
|
I_step_one(balloc,scale_index,fr);
|
|
|
|
|
|
|
|
for (i=0;i<SCALE_BLOCK;i++)
|
|
|
|
{
|
|
|
|
I_step_two(fraction,balloc,scale_index,fr);
|
|
|
|
|
|
|
|
if(single >= 0)
|
|
|
|
{
|
|
|
|
clip += (fr->synth_mono)( (real *) fraction[single],pcm_sample,&pcm_point);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int p1 = pcm_point;
|
|
|
|
clip += (fr->synth)( (real *) fraction[0],0,pcm_sample,&p1);
|
|
|
|
clip += (fr->synth)( (real *) fraction[1],1,pcm_sample,&pcm_point);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return clip;
|
|
|
|
}
|