2002-08-29 01:43:43 +02:00
|
|
|
/*
|
|
|
|
* Mpeg Layer-1,2,3 audio decoder
|
2002-06-04 19:53:46 +02:00
|
|
|
* ------------------------------
|
|
|
|
* copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
|
|
|
|
* See also 'README'
|
|
|
|
*
|
|
|
|
* slighlty optimized for machines without autoincrement/decrement.
|
|
|
|
* The performance is highly compiler dependend. Maybe
|
|
|
|
* the decode.c version for 'normal' processor may be faster
|
|
|
|
* even for Intel processors.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-06-04 19:53:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "mpg123.h"
|
|
|
|
#include "mpglib.h"
|
|
|
|
|
|
|
|
/* old WRITE_SAMPLE */
|
|
|
|
#define WRITE_SAMPLE(samples,sum,clip) \
|
|
|
|
if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
|
|
|
|
else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
|
|
|
|
else { *(samples) = sum; }
|
|
|
|
|
2007-07-10 21:09:25 +02:00
|
|
|
int synth_1to1_mono(struct mpstr *mp,real *bandPtr,unsigned char *samples,int *pnt)
|
2002-06-04 19:53:46 +02:00
|
|
|
{
|
|
|
|
short samples_tmp[64];
|
|
|
|
short *tmp1 = samples_tmp;
|
|
|
|
int i,ret;
|
|
|
|
int pnt1 = 0;
|
|
|
|
|
2007-07-10 21:09:25 +02:00
|
|
|
ret = synth_1to1(mp,bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
|
2002-06-04 19:53:46 +02:00
|
|
|
samples += *pnt;
|
|
|
|
|
|
|
|
for(i=0;i<32;i++) {
|
|
|
|
*( (short *) samples) = *tmp1;
|
|
|
|
samples += 2;
|
|
|
|
tmp1 += 2;
|
|
|
|
}
|
|
|
|
*pnt += 64;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-10 21:09:25 +02:00
|
|
|
int synth_1to1(struct mpstr *mp,real *bandPtr,int channel,unsigned char *out,int *pnt)
|
2002-06-04 19:53:46 +02:00
|
|
|
{
|
|
|
|
static const int step = 2;
|
|
|
|
int bo;
|
|
|
|
short *samples = (short *) (out + *pnt);
|
|
|
|
|
|
|
|
real *b0,(*buf)[0x110];
|
2002-08-29 01:43:43 +02:00
|
|
|
int clip = 0;
|
2002-06-04 19:53:46 +02:00
|
|
|
int bo1;
|
|
|
|
|
2007-07-10 21:09:25 +02:00
|
|
|
bo = mp->synth_bo;
|
2002-06-04 19:53:46 +02:00
|
|
|
|
|
|
|
if(!channel) {
|
|
|
|
bo--;
|
|
|
|
bo &= 0xf;
|
2007-07-10 21:09:25 +02:00
|
|
|
buf = mp->synth_buffs[0];
|
2002-06-04 19:53:46 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
samples++;
|
2007-07-10 21:09:25 +02:00
|
|
|
buf = mp->synth_buffs[1];
|
2002-06-04 19:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(bo & 0x1) {
|
|
|
|
b0 = buf[0];
|
|
|
|
bo1 = bo;
|
|
|
|
dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
b0 = buf[1];
|
|
|
|
bo1 = bo+1;
|
|
|
|
dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
|
|
|
|
}
|
|
|
|
|
2007-07-10 21:09:25 +02:00
|
|
|
mp->synth_bo = bo;
|
2002-08-29 01:43:43 +02:00
|
|
|
|
2002-06-04 19:53:46 +02:00
|
|
|
{
|
|
|
|
register int j;
|
|
|
|
real *window = decwin + 16 - bo1;
|
|
|
|
|
|
|
|
for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step)
|
|
|
|
{
|
|
|
|
real sum;
|
|
|
|
sum = window[0x0] * b0[0x0];
|
|
|
|
sum -= window[0x1] * b0[0x1];
|
|
|
|
sum += window[0x2] * b0[0x2];
|
|
|
|
sum -= window[0x3] * b0[0x3];
|
|
|
|
sum += window[0x4] * b0[0x4];
|
|
|
|
sum -= window[0x5] * b0[0x5];
|
|
|
|
sum += window[0x6] * b0[0x6];
|
|
|
|
sum -= window[0x7] * b0[0x7];
|
|
|
|
sum += window[0x8] * b0[0x8];
|
|
|
|
sum -= window[0x9] * b0[0x9];
|
|
|
|
sum += window[0xA] * b0[0xA];
|
|
|
|
sum -= window[0xB] * b0[0xB];
|
|
|
|
sum += window[0xC] * b0[0xC];
|
|
|
|
sum -= window[0xD] * b0[0xD];
|
|
|
|
sum += window[0xE] * b0[0xE];
|
|
|
|
sum -= window[0xF] * b0[0xF];
|
|
|
|
|
|
|
|
WRITE_SAMPLE(samples,sum,clip);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
real sum;
|
|
|
|
sum = window[0x0] * b0[0x0];
|
|
|
|
sum += window[0x2] * b0[0x2];
|
|
|
|
sum += window[0x4] * b0[0x4];
|
|
|
|
sum += window[0x6] * b0[0x6];
|
|
|
|
sum += window[0x8] * b0[0x8];
|
|
|
|
sum += window[0xA] * b0[0xA];
|
|
|
|
sum += window[0xC] * b0[0xC];
|
|
|
|
sum += window[0xE] * b0[0xE];
|
|
|
|
WRITE_SAMPLE(samples,sum,clip);
|
|
|
|
b0-=0x10,window-=0x20,samples+=step;
|
|
|
|
}
|
|
|
|
window += bo1<<1;
|
|
|
|
|
|
|
|
for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step)
|
|
|
|
{
|
|
|
|
real sum;
|
|
|
|
sum = -window[-0x1] * b0[0x0];
|
|
|
|
sum -= window[-0x2] * b0[0x1];
|
|
|
|
sum -= window[-0x3] * b0[0x2];
|
|
|
|
sum -= window[-0x4] * b0[0x3];
|
|
|
|
sum -= window[-0x5] * b0[0x4];
|
|
|
|
sum -= window[-0x6] * b0[0x5];
|
|
|
|
sum -= window[-0x7] * b0[0x6];
|
|
|
|
sum -= window[-0x8] * b0[0x7];
|
|
|
|
sum -= window[-0x9] * b0[0x8];
|
|
|
|
sum -= window[-0xA] * b0[0x9];
|
|
|
|
sum -= window[-0xB] * b0[0xA];
|
|
|
|
sum -= window[-0xC] * b0[0xB];
|
|
|
|
sum -= window[-0xD] * b0[0xC];
|
|
|
|
sum -= window[-0xE] * b0[0xD];
|
|
|
|
sum -= window[-0xF] * b0[0xE];
|
|
|
|
sum -= window[-0x0] * b0[0xF];
|
|
|
|
|
|
|
|
WRITE_SAMPLE(samples,sum,clip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*pnt += 128;
|
|
|
|
|
|
|
|
return clip;
|
|
|
|
}
|