made multithread save by removing global variables
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5483 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -7,8 +7,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "mpg123.h"
|
#include "mpg123.h"
|
||||||
|
#include "mpglib.h"
|
||||||
struct parameter param = { 1 , 1 , 0 , 0 };
|
|
||||||
|
|
||||||
int tabsel_123[2][3][16] = {
|
int tabsel_123[2][3][16] = {
|
||||||
{ {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,},
|
{ {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,},
|
||||||
@@ -24,12 +23,6 @@ long freqs[9] = { 44100, 48000, 32000,
|
|||||||
22050, 24000, 16000 ,
|
22050, 24000, 16000 ,
|
||||||
11025 , 12000 , 8000 };
|
11025 , 12000 , 8000 };
|
||||||
|
|
||||||
int bitindex;
|
|
||||||
unsigned char *wordpointer;
|
|
||||||
unsigned char *pcm_sample;
|
|
||||||
int pcm_point = 0;
|
|
||||||
|
|
||||||
|
|
||||||
#define HDRCMPMASK 0xfffffd00
|
#define HDRCMPMASK 0xfffffd00
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@@ -98,7 +91,6 @@ int decode_header(struct frame *fr,unsigned long newhead)
|
|||||||
switch(fr->lay)
|
switch(fr->lay)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
#ifdef LAYER1
|
|
||||||
#if 0
|
#if 0
|
||||||
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
|
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
|
||||||
(fr->mode_ext<<2)+4 : 32;
|
(fr->mode_ext<<2)+4 : 32;
|
||||||
@@ -106,12 +98,8 @@ int decode_header(struct frame *fr,unsigned long newhead)
|
|||||||
fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
|
fr->framesize = (long) tabsel_123[fr->lsf][0][fr->bitrate_index] * 12000;
|
||||||
fr->framesize /= freqs[fr->sampling_frequency];
|
fr->framesize /= freqs[fr->sampling_frequency];
|
||||||
fr->framesize = ((fr->framesize+fr->padding)<<2)-4;
|
fr->framesize = ((fr->framesize+fr->padding)<<2)-4;
|
||||||
#else
|
|
||||||
fprintf(stderr,"Not supported!\n");
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
#ifdef LAYER2
|
|
||||||
#if 0
|
#if 0
|
||||||
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
|
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
|
||||||
(fr->mode_ext<<2)+4 : fr->II_sblimit;
|
(fr->mode_ext<<2)+4 : fr->II_sblimit;
|
||||||
@@ -119,9 +107,6 @@ int decode_header(struct frame *fr,unsigned long newhead)
|
|||||||
fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
|
fr->framesize = (long) tabsel_123[fr->lsf][1][fr->bitrate_index] * 144000;
|
||||||
fr->framesize /= freqs[fr->sampling_frequency];
|
fr->framesize /= freqs[fr->sampling_frequency];
|
||||||
fr->framesize += fr->padding - 4;
|
fr->framesize += fr->padding - 4;
|
||||||
#else
|
|
||||||
fprintf(stderr,"Not supported!\n");
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
#if 0
|
#if 0
|
||||||
@@ -179,7 +164,7 @@ void print_header_compact(struct frame *fr)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned int getbits(int number_of_bits)
|
unsigned int getbits(struct mpstr *mp, int number_of_bits)
|
||||||
{
|
{
|
||||||
unsigned long rval;
|
unsigned long rval;
|
||||||
|
|
||||||
@@ -187,52 +172,52 @@ unsigned int getbits(int number_of_bits)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
{
|
{
|
||||||
rval = wordpointer[0];
|
rval = mp->wordpointer[0];
|
||||||
rval <<= 8;
|
rval <<= 8;
|
||||||
rval |= wordpointer[1];
|
rval |= mp->wordpointer[1];
|
||||||
rval <<= 8;
|
rval <<= 8;
|
||||||
rval |= wordpointer[2];
|
rval |= mp->wordpointer[2];
|
||||||
rval <<= bitindex;
|
rval <<= mp->bitindex;
|
||||||
rval &= 0xffffff;
|
rval &= 0xffffff;
|
||||||
|
|
||||||
bitindex += number_of_bits;
|
mp->bitindex += number_of_bits;
|
||||||
|
|
||||||
rval >>= (24-number_of_bits);
|
rval >>= (24-number_of_bits);
|
||||||
|
|
||||||
wordpointer += (bitindex>>3);
|
mp->wordpointer += (mp->bitindex>>3);
|
||||||
bitindex &= 7;
|
mp->bitindex &= 7;
|
||||||
}
|
}
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int getbits_fast(int number_of_bits)
|
unsigned int getbits_fast(struct mpstr *mp, int number_of_bits)
|
||||||
{
|
{
|
||||||
unsigned long rval;
|
unsigned long rval;
|
||||||
|
|
||||||
{
|
{
|
||||||
rval = wordpointer[0];
|
rval = mp->wordpointer[0];
|
||||||
rval <<= 8;
|
rval <<= 8;
|
||||||
rval |= wordpointer[1];
|
rval |= mp->wordpointer[1];
|
||||||
rval <<= bitindex;
|
rval <<= mp->bitindex;
|
||||||
rval &= 0xffff;
|
rval &= 0xffff;
|
||||||
bitindex += number_of_bits;
|
mp->bitindex += number_of_bits;
|
||||||
|
|
||||||
rval >>= (16-number_of_bits);
|
rval >>= (16-number_of_bits);
|
||||||
|
|
||||||
wordpointer += (bitindex>>3);
|
mp->wordpointer += (mp->bitindex>>3);
|
||||||
bitindex &= 7;
|
mp->bitindex &= 7;
|
||||||
}
|
}
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int get1bit(void)
|
unsigned int get1bit(struct mpstr *mp)
|
||||||
{
|
{
|
||||||
unsigned char rval;
|
unsigned char rval;
|
||||||
rval = *wordpointer << bitindex;
|
rval = *mp->wordpointer << mp->bitindex;
|
||||||
|
|
||||||
bitindex++;
|
mp->bitindex++;
|
||||||
wordpointer += (bitindex>>3);
|
mp->wordpointer += (mp->bitindex>>3);
|
||||||
bitindex &= 7;
|
mp->bitindex &= 7;
|
||||||
|
|
||||||
return rval>>7;
|
return rval>>7;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ void InitMP3(struct mpstr *mp)
|
|||||||
mp->fr.single = -1;
|
mp->fr.single = -1;
|
||||||
mp->bsnum = 0;
|
mp->bsnum = 0;
|
||||||
mp->synth_bo = 1;
|
mp->synth_bo = 1;
|
||||||
|
mp->bitindex = 0;
|
||||||
|
mp->wordpointer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExitMP3(struct mpstr *mp)
|
void ExitMP3(struct mpstr *mp)
|
||||||
@@ -154,9 +156,9 @@ int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,
|
|||||||
if(mp->fr.framesize > mp->bsize)
|
if(mp->fr.framesize > mp->bsize)
|
||||||
return MP3_NEED_MORE;
|
return MP3_NEED_MORE;
|
||||||
|
|
||||||
wordpointer = mp->bsspace[mp->bsnum] + 512;
|
mp->wordpointer = mp->bsspace[mp->bsnum] + 512;
|
||||||
mp->bsnum = (mp->bsnum + 1) & 0x1;
|
mp->bsnum = (mp->bsnum + 1) & 0x1;
|
||||||
bitindex = 0;
|
mp->bitindex = 0;
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
while(len < mp->framesize) {
|
while(len < mp->framesize) {
|
||||||
@@ -168,7 +170,7 @@ int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,
|
|||||||
else {
|
else {
|
||||||
nlen = blen;
|
nlen = blen;
|
||||||
}
|
}
|
||||||
memcpy(wordpointer+len,mp->tail->pnt+mp->tail->pos,nlen);
|
memcpy(mp->wordpointer+len,mp->tail->pnt+mp->tail->pos,nlen);
|
||||||
len += nlen;
|
len += nlen;
|
||||||
mp->tail->pos += nlen;
|
mp->tail->pos += nlen;
|
||||||
mp->bsize -= nlen;
|
mp->bsize -= nlen;
|
||||||
@@ -179,7 +181,7 @@ int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,
|
|||||||
|
|
||||||
*done = 0;
|
*done = 0;
|
||||||
if(mp->fr.error_protection)
|
if(mp->fr.error_protection)
|
||||||
getbits(16);
|
getbits(mp, 16);
|
||||||
switch(mp->fr.lay) {
|
switch(mp->fr.lay) {
|
||||||
case 1:
|
case 1:
|
||||||
do_layer1(mp, &mp->fr,(unsigned char *) out,done);
|
do_layer1(mp, &mp->fr,(unsigned char *) out,done);
|
||||||
@@ -206,9 +208,9 @@ int set_pointer(struct mpstr *mp, long backstep)
|
|||||||
return MP3_ERR;
|
return MP3_ERR;
|
||||||
}
|
}
|
||||||
bsbufold = mp->bsspace[mp->bsnum] + 512;
|
bsbufold = mp->bsspace[mp->bsnum] + 512;
|
||||||
wordpointer -= backstep;
|
mp->wordpointer -= backstep;
|
||||||
if (backstep)
|
if (backstep)
|
||||||
memcpy(wordpointer,bsbufold+mp->fsizeold-backstep,backstep);
|
memcpy(mp->wordpointer,bsbufold+mp->fsizeold-backstep,backstep);
|
||||||
bitindex = 0;
|
mp->bitindex = 0;
|
||||||
return MP3_OK;
|
return MP3_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,11 @@
|
|||||||
|
|
||||||
#include "mpg123.h"
|
#include "mpg123.h"
|
||||||
|
|
||||||
void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr);
|
void I_step_one(struct mpstr *mp, unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr);
|
||||||
void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
|
void I_step_two(struct mpstr *mp, real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
|
||||||
unsigned int scale_index[2][SBLIMIT],struct frame *fr);
|
unsigned int scale_index[2][SBLIMIT],struct frame *fr);
|
||||||
|
|
||||||
void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr)
|
void I_step_one(struct mpstr *mp, unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr)
|
||||||
{
|
{
|
||||||
unsigned int *ba=balloc;
|
unsigned int *ba=balloc;
|
||||||
unsigned int *sca = (unsigned int *) scale_index;
|
unsigned int *sca = (unsigned int *) scale_index;
|
||||||
@@ -23,38 +23,38 @@ void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],stru
|
|||||||
int i;
|
int i;
|
||||||
int jsbound = fr->jsbound;
|
int jsbound = fr->jsbound;
|
||||||
for (i=0;i<jsbound;i++) {
|
for (i=0;i<jsbound;i++) {
|
||||||
*ba++ = getbits(4);
|
*ba++ = getbits(mp, 4);
|
||||||
*ba++ = getbits(4);
|
*ba++ = getbits(mp, 4);
|
||||||
}
|
}
|
||||||
for (i=jsbound;i<SBLIMIT;i++)
|
for (i=jsbound;i<SBLIMIT;i++)
|
||||||
*ba++ = getbits(4);
|
*ba++ = getbits(mp, 4);
|
||||||
|
|
||||||
ba = balloc;
|
ba = balloc;
|
||||||
|
|
||||||
for (i=0;i<jsbound;i++) {
|
for (i=0;i<jsbound;i++) {
|
||||||
if ((*ba++))
|
if ((*ba++))
|
||||||
*sca++ = getbits(6);
|
*sca++ = getbits(mp, 6);
|
||||||
if ((*ba++))
|
if ((*ba++))
|
||||||
*sca++ = getbits(6);
|
*sca++ = getbits(mp, 6);
|
||||||
}
|
}
|
||||||
for (i=jsbound;i<SBLIMIT;i++)
|
for (i=jsbound;i<SBLIMIT;i++)
|
||||||
if ((*ba++)) {
|
if ((*ba++)) {
|
||||||
*sca++ = getbits(6);
|
*sca++ = getbits(mp, 6);
|
||||||
*sca++ = getbits(6);
|
*sca++ = getbits(mp, 6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<SBLIMIT;i++)
|
for (i=0;i<SBLIMIT;i++)
|
||||||
*ba++ = getbits(4);
|
*ba++ = getbits(mp, 4);
|
||||||
ba = balloc;
|
ba = balloc;
|
||||||
for (i=0;i<SBLIMIT;i++)
|
for (i=0;i<SBLIMIT;i++)
|
||||||
if ((*ba++))
|
if ((*ba++))
|
||||||
*sca++ = getbits(6);
|
*sca++ = getbits(mp, 6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
|
void I_step_two(struct mpstr *mp, real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
|
||||||
unsigned int scale_index[2][SBLIMIT],struct frame *fr)
|
unsigned int scale_index[2][SBLIMIT],struct frame *fr)
|
||||||
{
|
{
|
||||||
int i,n;
|
int i,n;
|
||||||
@@ -70,13 +70,13 @@ void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
|
|||||||
ba = balloc;
|
ba = balloc;
|
||||||
for (sample=smpb,i=0;i<jsbound;i++) {
|
for (sample=smpb,i=0;i<jsbound;i++) {
|
||||||
if ((n = *ba++))
|
if ((n = *ba++))
|
||||||
*sample++ = getbits(n+1);
|
*sample++ = getbits(mp, n+1);
|
||||||
if ((n = *ba++))
|
if ((n = *ba++))
|
||||||
*sample++ = getbits(n+1);
|
*sample++ = getbits(mp, n+1);
|
||||||
}
|
}
|
||||||
for (i=jsbound;i<SBLIMIT;i++)
|
for (i=jsbound;i<SBLIMIT;i++)
|
||||||
if ((n = *ba++))
|
if ((n = *ba++))
|
||||||
*sample++ = getbits(n+1);
|
*sample++ = getbits(mp, n+1);
|
||||||
|
|
||||||
ba = balloc;
|
ba = balloc;
|
||||||
for (sample=smpb,i=0;i<jsbound;i++) {
|
for (sample=smpb,i=0;i<jsbound;i++) {
|
||||||
@@ -104,7 +104,7 @@ void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
|
|||||||
ba = balloc;
|
ba = balloc;
|
||||||
for (sample=smpb,i=0;i<SBLIMIT;i++)
|
for (sample=smpb,i=0;i<SBLIMIT;i++)
|
||||||
if ((n = *ba++))
|
if ((n = *ba++))
|
||||||
*sample++ = getbits(n+1);
|
*sample++ = getbits(mp, n+1);
|
||||||
ba = balloc;
|
ba = balloc;
|
||||||
for (sample=smpb,i=0;i<SBLIMIT;i++) {
|
for (sample=smpb,i=0;i<SBLIMIT;i++) {
|
||||||
if((n=*ba++))
|
if((n=*ba++))
|
||||||
@@ -129,11 +129,11 @@ int do_layer1(struct mpstr *mp, struct frame *fr,unsigned char *pcm_sample,int *
|
|||||||
if(stereo == 1 || single == 3)
|
if(stereo == 1 || single == 3)
|
||||||
single = 0;
|
single = 0;
|
||||||
|
|
||||||
I_step_one(balloc,scale_index,fr);
|
I_step_one(mp, balloc,scale_index,fr);
|
||||||
|
|
||||||
for (i=0;i<SCALE_BLOCK;i++)
|
for (i=0;i<SCALE_BLOCK;i++)
|
||||||
{
|
{
|
||||||
I_step_two(fraction,balloc,scale_index,fr);
|
I_step_two(mp, fraction,balloc,scale_index,fr);
|
||||||
|
|
||||||
if(single >= 0) {
|
if(single >= 0) {
|
||||||
clip += synth_1to1_mono(mp, (real*)fraction[single],pcm_sample,pcm_point);
|
clip += synth_1to1_mono(mp, (real*)fraction[single],pcm_sample,pcm_point);
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ static int grp_9tab[1024 * 3] = { 0, }; /* used: 729 */
|
|||||||
|
|
||||||
real muls[27][64]; /* also used by layer 1 */
|
real muls[27][64]; /* also used by layer 1 */
|
||||||
|
|
||||||
void II_step_one(unsigned int *bit_alloc,int *scale,struct frame *fr);
|
void II_step_one(struct mpstr *mp, unsigned int *bit_alloc,int *scale,struct frame *fr);
|
||||||
void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale,struct frame *fr,int x1);
|
void II_step_two(struct mpstr *mp, unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale,struct frame *fr,int x1);
|
||||||
|
|
||||||
void init_layer2(void)
|
void init_layer2(void)
|
||||||
{
|
{
|
||||||
@@ -60,7 +60,7 @@ void init_layer2(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void II_step_one(unsigned int *bit_alloc,int *scale,struct frame *fr)
|
void II_step_one(struct mpstr *mp, unsigned int *bit_alloc,int *scale,struct frame *fr)
|
||||||
{
|
{
|
||||||
int stereo = fr->stereo-1;
|
int stereo = fr->stereo-1;
|
||||||
int sblimit = fr->II_sblimit;
|
int sblimit = fr->II_sblimit;
|
||||||
@@ -77,12 +77,12 @@ void II_step_one(unsigned int *bit_alloc,int *scale,struct frame *fr)
|
|||||||
{
|
{
|
||||||
for (i=jsbound;i;i--,alloc1+=(1<<step))
|
for (i=jsbound;i;i--,alloc1+=(1<<step))
|
||||||
{
|
{
|
||||||
*bita++ = (char) getbits(step=alloc1->bits);
|
*bita++ = (char) getbits(mp, step=alloc1->bits);
|
||||||
*bita++ = (char) getbits(step);
|
*bita++ = (char) getbits(mp, step);
|
||||||
}
|
}
|
||||||
for (i=sblimit-jsbound;i;i--,alloc1+=(1<<step))
|
for (i=sblimit-jsbound;i;i--,alloc1+=(1<<step))
|
||||||
{
|
{
|
||||||
bita[0] = (char) getbits(step=alloc1->bits);
|
bita[0] = (char) getbits(mp, step=alloc1->bits);
|
||||||
bita[1] = bita[0];
|
bita[1] = bita[0];
|
||||||
bita+=2;
|
bita+=2;
|
||||||
}
|
}
|
||||||
@@ -90,17 +90,17 @@ void II_step_one(unsigned int *bit_alloc,int *scale,struct frame *fr)
|
|||||||
scfsi=scfsi_buf;
|
scfsi=scfsi_buf;
|
||||||
for (i=sblimit2;i;i--)
|
for (i=sblimit2;i;i--)
|
||||||
if (*bita++)
|
if (*bita++)
|
||||||
*scfsi++ = (char) getbits_fast(2);
|
*scfsi++ = (char) getbits_fast(mp, 2);
|
||||||
}
|
}
|
||||||
else /* mono */
|
else /* mono */
|
||||||
{
|
{
|
||||||
for (i=sblimit;i;i--,alloc1+=(1<<step))
|
for (i=sblimit;i;i--,alloc1+=(1<<step))
|
||||||
*bita++ = (char) getbits(step=alloc1->bits);
|
*bita++ = (char) getbits(mp, step=alloc1->bits);
|
||||||
bita = bit_alloc;
|
bita = bit_alloc;
|
||||||
scfsi=scfsi_buf;
|
scfsi=scfsi_buf;
|
||||||
for (i=sblimit;i;i--)
|
for (i=sblimit;i;i--)
|
||||||
if (*bita++)
|
if (*bita++)
|
||||||
*scfsi++ = (char) getbits_fast(2);
|
*scfsi++ = (char) getbits_fast(mp, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bita = bit_alloc;
|
bita = bit_alloc;
|
||||||
@@ -110,30 +110,30 @@ void II_step_one(unsigned int *bit_alloc,int *scale,struct frame *fr)
|
|||||||
switch (*scfsi++)
|
switch (*scfsi++)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
*scale++ = getbits_fast(6);
|
*scale++ = getbits_fast(mp, 6);
|
||||||
*scale++ = getbits_fast(6);
|
*scale++ = getbits_fast(mp, 6);
|
||||||
*scale++ = getbits_fast(6);
|
*scale++ = getbits_fast(mp, 6);
|
||||||
break;
|
break;
|
||||||
case 1 :
|
case 1 :
|
||||||
*scale++ = sc = getbits_fast(6);
|
*scale++ = sc = getbits_fast(mp, 6);
|
||||||
*scale++ = sc;
|
*scale++ = sc;
|
||||||
*scale++ = getbits_fast(6);
|
*scale++ = getbits_fast(mp, 6);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
*scale++ = sc = getbits_fast(6);
|
*scale++ = sc = getbits_fast(mp, 6);
|
||||||
*scale++ = sc;
|
*scale++ = sc;
|
||||||
*scale++ = sc;
|
*scale++ = sc;
|
||||||
break;
|
break;
|
||||||
default: /* case 3 */
|
default: /* case 3 */
|
||||||
*scale++ = getbits_fast(6);
|
*scale++ = getbits_fast(mp, 6);
|
||||||
*scale++ = sc = getbits_fast(6);
|
*scale++ = sc = getbits_fast(mp, 6);
|
||||||
*scale++ = sc;
|
*scale++ = sc;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale,struct frame *fr,int x1)
|
void II_step_two(struct mpstr *mp, unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale,struct frame *fr,int x1)
|
||||||
{
|
{
|
||||||
int i,j,k,ba;
|
int i,j,k,ba;
|
||||||
int stereo = fr->stereo;
|
int stereo = fr->stereo;
|
||||||
@@ -154,15 +154,15 @@ void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale
|
|||||||
if( (d1=alloc2->d) < 0)
|
if( (d1=alloc2->d) < 0)
|
||||||
{
|
{
|
||||||
real cm=muls[k][scale[x1]];
|
real cm=muls[k][scale[x1]];
|
||||||
fraction[j][0][i] = ((real) ((int)getbits(k) + d1)) * cm;
|
fraction[j][0][i] = ((real) ((int)getbits(mp, k) + d1)) * cm;
|
||||||
fraction[j][1][i] = ((real) ((int)getbits(k) + d1)) * cm;
|
fraction[j][1][i] = ((real) ((int)getbits(mp, k) + d1)) * cm;
|
||||||
fraction[j][2][i] = ((real) ((int)getbits(k) + d1)) * cm;
|
fraction[j][2][i] = ((real) ((int)getbits(mp, k) + d1)) * cm;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
|
static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
|
||||||
unsigned int idx,*tab,m=scale[x1];
|
unsigned int idx,*tab,m=scale[x1];
|
||||||
idx = (unsigned int) getbits(k);
|
idx = (unsigned int) getbits(mp, k);
|
||||||
tab = (unsigned int *) (table[d1] + idx + idx + idx);
|
tab = (unsigned int *) (table[d1] + idx + idx + idx);
|
||||||
fraction[j][0][i] = muls[*tab++][m];
|
fraction[j][0][i] = muls[*tab++][m];
|
||||||
fraction[j][1][i] = muls[*tab++][m];
|
fraction[j][1][i] = muls[*tab++][m];
|
||||||
@@ -186,9 +186,9 @@ void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale
|
|||||||
{
|
{
|
||||||
real cm;
|
real cm;
|
||||||
cm=muls[k][scale[x1+3]];
|
cm=muls[k][scale[x1+3]];
|
||||||
fraction[1][0][i] = (fraction[0][0][i] = (real) ((int)getbits(k) + d1) ) * cm;
|
fraction[1][0][i] = (fraction[0][0][i] = (real) ((int)getbits(mp, k) + d1) ) * cm;
|
||||||
fraction[1][1][i] = (fraction[0][1][i] = (real) ((int)getbits(k) + d1) ) * cm;
|
fraction[1][1][i] = (fraction[0][1][i] = (real) ((int)getbits(mp, k) + d1) ) * cm;
|
||||||
fraction[1][2][i] = (fraction[0][2][i] = (real) ((int)getbits(k) + d1) ) * cm;
|
fraction[1][2][i] = (fraction[0][2][i] = (real) ((int)getbits(mp, k) + d1) ) * cm;
|
||||||
cm=muls[k][scale[x1]];
|
cm=muls[k][scale[x1]];
|
||||||
fraction[0][0][i] *= cm; fraction[0][1][i] *= cm; fraction[0][2][i] *= cm;
|
fraction[0][0][i] *= cm; fraction[0][1][i] *= cm; fraction[0][2][i] *= cm;
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale
|
|||||||
static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
|
static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
|
||||||
unsigned int idx,*tab,m1,m2;
|
unsigned int idx,*tab,m1,m2;
|
||||||
m1 = scale[x1]; m2 = scale[x1+3];
|
m1 = scale[x1]; m2 = scale[x1+3];
|
||||||
idx = (unsigned int) getbits(k);
|
idx = (unsigned int) getbits(mp, k);
|
||||||
tab = (unsigned int *) (table[d1] + idx + idx + idx);
|
tab = (unsigned int *) (table[d1] + idx + idx + idx);
|
||||||
fraction[0][0][i] = muls[*tab][m1]; fraction[1][0][i] = muls[*tab++][m2];
|
fraction[0][0][i] = muls[*tab][m1]; fraction[1][0][i] = muls[*tab++][m2];
|
||||||
fraction[0][1][i] = muls[*tab][m1]; fraction[1][1][i] = muls[*tab++][m2];
|
fraction[0][1][i] = muls[*tab][m1]; fraction[1][1][i] = muls[*tab++][m2];
|
||||||
@@ -267,11 +267,11 @@ int do_layer2(struct mpstr *mp, struct frame *fr,unsigned char *pcm_sample,int *
|
|||||||
if(stereo == 1 || single == 3)
|
if(stereo == 1 || single == 3)
|
||||||
single = 0;
|
single = 0;
|
||||||
|
|
||||||
II_step_one(bit_alloc, scale, fr);
|
II_step_one(mp, bit_alloc, scale, fr);
|
||||||
|
|
||||||
for (i=0;i<SCALE_BLOCK;i++)
|
for (i=0;i<SCALE_BLOCK;i++)
|
||||||
{
|
{
|
||||||
II_step_two(bit_alloc,fraction,scale,fr,i>>2);
|
II_step_two(mp, bit_alloc, fraction, scale, fr, i>>2);
|
||||||
for (j=0;j<3;j++) {
|
for (j=0;j<3;j++) {
|
||||||
if(single >= 0) {
|
if(single >= 0) {
|
||||||
clip += synth_1to1_mono(mp, fraction[0][j],pcm_sample,pcm_point);
|
clip += synth_1to1_mono(mp, fraction[0][j],pcm_sample,pcm_point);
|
||||||
|
|||||||
@@ -10,9 +10,6 @@
|
|||||||
#include "mpglib.h"
|
#include "mpglib.h"
|
||||||
#include "huffman.h"
|
#include "huffman.h"
|
||||||
|
|
||||||
#define MPEG1
|
|
||||||
|
|
||||||
|
|
||||||
static real ispow[8207];
|
static real ispow[8207];
|
||||||
static real aa_ca[8],aa_cs[8];
|
static real aa_ca[8],aa_cs[8];
|
||||||
static real COS1[12][6];
|
static real COS1[12][6];
|
||||||
@@ -291,22 +288,21 @@ void init_layer3(int down_sample_sblimit)
|
|||||||
/*
|
/*
|
||||||
* read additional side information
|
* read additional side information
|
||||||
*/
|
*/
|
||||||
#ifdef MPEG1
|
static int III_get_side_info_1(struct mpstr *mp, struct III_sideinfo *si, int stereo,
|
||||||
static int III_get_side_info_1(struct III_sideinfo *si,int stereo,
|
|
||||||
int ms_stereo,long sfreq,int single)
|
int ms_stereo,long sfreq,int single)
|
||||||
{
|
{
|
||||||
int ch, gr;
|
int ch, gr;
|
||||||
int powdiff = (single == 3) ? 4 : 0;
|
int powdiff = (single == 3) ? 4 : 0;
|
||||||
|
|
||||||
si->main_data_begin = getbits(9);
|
si->main_data_begin = getbits(mp, 9);
|
||||||
if (stereo == 1)
|
if (stereo == 1)
|
||||||
si->private_bits = getbits_fast(5);
|
si->private_bits = getbits_fast(mp, 5);
|
||||||
else
|
else
|
||||||
si->private_bits = getbits_fast(3);
|
si->private_bits = getbits_fast(mp, 3);
|
||||||
|
|
||||||
for (ch=0; ch<stereo; ch++) {
|
for (ch=0; ch<stereo; ch++) {
|
||||||
si->ch[ch].gr[0].scfsi = -1;
|
si->ch[ch].gr[0].scfsi = -1;
|
||||||
si->ch[ch].gr[1].scfsi = getbits_fast(4);
|
si->ch[ch].gr[1].scfsi = getbits_fast(mp, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (gr=0; gr<2; gr++)
|
for (gr=0; gr<2; gr++)
|
||||||
@@ -315,31 +311,31 @@ static int III_get_side_info_1(struct III_sideinfo *si,int stereo,
|
|||||||
{
|
{
|
||||||
register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]);
|
register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]);
|
||||||
|
|
||||||
gr_info->part2_3_length = getbits(12);
|
gr_info->part2_3_length = getbits(mp, 12);
|
||||||
gr_info->big_values = getbits_fast(9);
|
gr_info->big_values = getbits_fast(mp, 9);
|
||||||
if(gr_info->big_values > 288) {
|
if(gr_info->big_values > 288) {
|
||||||
fprintf(stderr,"big_values too large!\n");
|
fprintf(stderr,"big_values too large!\n");
|
||||||
gr_info->big_values = 288;
|
gr_info->big_values = 288;
|
||||||
}
|
}
|
||||||
gr_info->pow2gain = gainpow2+256 - getbits_fast(8) + powdiff;
|
gr_info->pow2gain = gainpow2+256 - getbits_fast(mp, 8) + powdiff;
|
||||||
if(ms_stereo)
|
if(ms_stereo)
|
||||||
gr_info->pow2gain += 2;
|
gr_info->pow2gain += 2;
|
||||||
gr_info->scalefac_compress = getbits_fast(4);
|
gr_info->scalefac_compress = getbits_fast(mp, 4);
|
||||||
/* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */
|
/* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */
|
||||||
if(get1bit())
|
if(get1bit(mp))
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
gr_info->block_type = getbits_fast(2);
|
gr_info->block_type = getbits_fast(mp, 2);
|
||||||
gr_info->mixed_block_flag = get1bit();
|
gr_info->mixed_block_flag = get1bit(mp);
|
||||||
gr_info->table_select[0] = getbits_fast(5);
|
gr_info->table_select[0] = getbits_fast(mp, 5);
|
||||||
gr_info->table_select[1] = getbits_fast(5);
|
gr_info->table_select[1] = getbits_fast(mp, 5);
|
||||||
/*
|
/*
|
||||||
* table_select[2] not needed, because there is no region2,
|
* table_select[2] not needed, because there is no region2,
|
||||||
* but to satisfy some verifications tools we set it either.
|
* but to satisfy some verifications tools we set it either.
|
||||||
*/
|
*/
|
||||||
gr_info->table_select[2] = 0;
|
gr_info->table_select[2] = 0;
|
||||||
for(i=0;i<3;i++)
|
for(i=0;i<3;i++)
|
||||||
gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(3)<<3);
|
gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(mp, 3)<<3);
|
||||||
|
|
||||||
if(gr_info->block_type == 0) {
|
if(gr_info->block_type == 0) {
|
||||||
fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n");
|
fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n");
|
||||||
@@ -353,67 +349,66 @@ static int III_get_side_info_1(struct III_sideinfo *si,int stereo,
|
|||||||
{
|
{
|
||||||
int i,r0c,r1c;
|
int i,r0c,r1c;
|
||||||
for (i=0; i<3; i++)
|
for (i=0; i<3; i++)
|
||||||
gr_info->table_select[i] = getbits_fast(5);
|
gr_info->table_select[i] = getbits_fast(mp, 5);
|
||||||
r0c = getbits_fast(4);
|
r0c = getbits_fast(mp, 4);
|
||||||
r1c = getbits_fast(3);
|
r1c = getbits_fast(mp, 3);
|
||||||
gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
|
gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
|
||||||
gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
|
gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
|
||||||
gr_info->block_type = 0;
|
gr_info->block_type = 0;
|
||||||
gr_info->mixed_block_flag = 0;
|
gr_info->mixed_block_flag = 0;
|
||||||
}
|
}
|
||||||
gr_info->preflag = get1bit();
|
gr_info->preflag = get1bit(mp);
|
||||||
gr_info->scalefac_scale = get1bit();
|
gr_info->scalefac_scale = get1bit(mp);
|
||||||
gr_info->count1table_select = get1bit();
|
gr_info->count1table_select = get1bit(mp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return !0;
|
return !0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Side Info for MPEG 2.0 / LSF
|
* Side Info for MPEG 2.0 / LSF
|
||||||
*/
|
*/
|
||||||
static int III_get_side_info_2(struct III_sideinfo *si,int stereo,
|
static int III_get_side_info_2(struct mpstr *mp, struct III_sideinfo *si,int stereo,
|
||||||
int ms_stereo,long sfreq,int single)
|
int ms_stereo,long sfreq,int single)
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
int powdiff = (single == 3) ? 4 : 0;
|
int powdiff = (single == 3) ? 4 : 0;
|
||||||
|
|
||||||
si->main_data_begin = getbits(8);
|
si->main_data_begin = getbits(mp, 8);
|
||||||
if (stereo == 1)
|
if (stereo == 1)
|
||||||
si->private_bits = get1bit();
|
si->private_bits = get1bit(mp);
|
||||||
else
|
else
|
||||||
si->private_bits = getbits_fast(2);
|
si->private_bits = getbits_fast(mp, 2);
|
||||||
|
|
||||||
for (ch=0; ch<stereo; ch++)
|
for (ch=0; ch<stereo; ch++)
|
||||||
{
|
{
|
||||||
register struct gr_info_s *gr_info = &(si->ch[ch].gr[0]);
|
register struct gr_info_s *gr_info = &(si->ch[ch].gr[0]);
|
||||||
|
|
||||||
gr_info->part2_3_length = getbits(12);
|
gr_info->part2_3_length = getbits(mp, 12);
|
||||||
gr_info->big_values = getbits_fast(9);
|
gr_info->big_values = getbits_fast(mp, 9);
|
||||||
if(gr_info->big_values > 288) {
|
if(gr_info->big_values > 288) {
|
||||||
fprintf(stderr,"big_values too large!\n");
|
fprintf(stderr,"big_values too large!\n");
|
||||||
gr_info->big_values = 288;
|
gr_info->big_values = 288;
|
||||||
}
|
}
|
||||||
gr_info->pow2gain = gainpow2+256 - getbits_fast(8) + powdiff;
|
gr_info->pow2gain = gainpow2+256 - getbits_fast(mp, 8) + powdiff;
|
||||||
if(ms_stereo)
|
if(ms_stereo)
|
||||||
gr_info->pow2gain += 2;
|
gr_info->pow2gain += 2;
|
||||||
gr_info->scalefac_compress = getbits(9);
|
gr_info->scalefac_compress = getbits(mp, 9);
|
||||||
/* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */
|
/* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */
|
||||||
if(get1bit())
|
if(get1bit(mp))
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
gr_info->block_type = getbits_fast(2);
|
gr_info->block_type = getbits_fast(mp, 2);
|
||||||
gr_info->mixed_block_flag = get1bit();
|
gr_info->mixed_block_flag = get1bit(mp);
|
||||||
gr_info->table_select[0] = getbits_fast(5);
|
gr_info->table_select[0] = getbits_fast(mp, 5);
|
||||||
gr_info->table_select[1] = getbits_fast(5);
|
gr_info->table_select[1] = getbits_fast(mp, 5);
|
||||||
/*
|
/*
|
||||||
* table_select[2] not needed, because there is no region2,
|
* table_select[2] not needed, because there is no region2,
|
||||||
* but to satisfy some verifications tools we set it either.
|
* but to satisfy some verifications tools we set it either.
|
||||||
*/
|
*/
|
||||||
gr_info->table_select[2] = 0;
|
gr_info->table_select[2] = 0;
|
||||||
for(i=0;i<3;i++)
|
for(i=0;i<3;i++)
|
||||||
gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(3)<<3);
|
gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(mp, 3)<<3);
|
||||||
|
|
||||||
if(gr_info->block_type == 0) {
|
if(gr_info->block_type == 0) {
|
||||||
fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n");
|
fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n");
|
||||||
@@ -434,16 +429,16 @@ static int III_get_side_info_2(struct III_sideinfo *si,int stereo,
|
|||||||
{
|
{
|
||||||
int i,r0c,r1c;
|
int i,r0c,r1c;
|
||||||
for (i=0; i<3; i++)
|
for (i=0; i<3; i++)
|
||||||
gr_info->table_select[i] = getbits_fast(5);
|
gr_info->table_select[i] = getbits_fast(mp, 5);
|
||||||
r0c = getbits_fast(4);
|
r0c = getbits_fast(mp, 4);
|
||||||
r1c = getbits_fast(3);
|
r1c = getbits_fast(mp, 3);
|
||||||
gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
|
gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
|
||||||
gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
|
gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
|
||||||
gr_info->block_type = 0;
|
gr_info->block_type = 0;
|
||||||
gr_info->mixed_block_flag = 0;
|
gr_info->mixed_block_flag = 0;
|
||||||
}
|
}
|
||||||
gr_info->scalefac_scale = get1bit();
|
gr_info->scalefac_scale = get1bit(mp);
|
||||||
gr_info->count1table_select = get1bit();
|
gr_info->count1table_select = get1bit(mp);
|
||||||
}
|
}
|
||||||
return !0;
|
return !0;
|
||||||
}
|
}
|
||||||
@@ -451,8 +446,7 @@ static int III_get_side_info_2(struct III_sideinfo *si,int stereo,
|
|||||||
/*
|
/*
|
||||||
* read scalefactors
|
* read scalefactors
|
||||||
*/
|
*/
|
||||||
#ifdef MPEG1
|
static int III_get_scale_factors_1(struct mpstr *mp, int *scf,struct gr_info_s *gr_info)
|
||||||
static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
|
|
||||||
{
|
{
|
||||||
static const unsigned char slen[2][16] = {
|
static const unsigned char slen[2][16] = {
|
||||||
{0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
|
{0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
|
||||||
@@ -468,15 +462,15 @@ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
|
|||||||
|
|
||||||
if (gr_info->mixed_block_flag) {
|
if (gr_info->mixed_block_flag) {
|
||||||
for (i=8;i;i--)
|
for (i=8;i;i--)
|
||||||
*scf++ = getbits_fast(num0);
|
*scf++ = getbits_fast(mp, num0);
|
||||||
i = 9;
|
i = 9;
|
||||||
numbits -= num0; /* num0 * 17 + num1 * 18 */
|
numbits -= num0; /* num0 * 17 + num1 * 18 */
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;i;i--)
|
for (;i;i--)
|
||||||
*scf++ = getbits_fast(num0);
|
*scf++ = getbits_fast(mp, num0);
|
||||||
for (i = 18; i; i--)
|
for (i = 18; i; i--)
|
||||||
*scf++ = getbits_fast(num1);
|
*scf++ = getbits_fast(mp, num1);
|
||||||
*scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */
|
*scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -485,9 +479,9 @@ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
|
|||||||
|
|
||||||
if(scfsi < 0) { /* scfsi < 0 => granule == 0 */
|
if(scfsi < 0) { /* scfsi < 0 => granule == 0 */
|
||||||
for(i=11;i;i--)
|
for(i=11;i;i--)
|
||||||
*scf++ = getbits_fast(num0);
|
*scf++ = getbits_fast(mp, num0);
|
||||||
for(i=10;i;i--)
|
for(i=10;i;i--)
|
||||||
*scf++ = getbits_fast(num1);
|
*scf++ = getbits_fast(mp, num1);
|
||||||
numbits = (num0 + num1) * 10 + num0;
|
numbits = (num0 + num1) * 10 + num0;
|
||||||
*scf++ = 0;
|
*scf++ = 0;
|
||||||
}
|
}
|
||||||
@@ -495,7 +489,7 @@ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
|
|||||||
numbits = 0;
|
numbits = 0;
|
||||||
if(!(scfsi & 0x8)) {
|
if(!(scfsi & 0x8)) {
|
||||||
for (i=0;i<6;i++)
|
for (i=0;i<6;i++)
|
||||||
*scf++ = getbits_fast(num0);
|
*scf++ = getbits_fast(mp, num0);
|
||||||
numbits += num0 * 6;
|
numbits += num0 * 6;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -504,7 +498,7 @@ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
|
|||||||
|
|
||||||
if(!(scfsi & 0x4)) {
|
if(!(scfsi & 0x4)) {
|
||||||
for (i=0;i<5;i++)
|
for (i=0;i<5;i++)
|
||||||
*scf++ = getbits_fast(num0);
|
*scf++ = getbits_fast(mp, num0);
|
||||||
numbits += num0 * 5;
|
numbits += num0 * 5;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -513,7 +507,7 @@ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
|
|||||||
|
|
||||||
if(!(scfsi & 0x2)) {
|
if(!(scfsi & 0x2)) {
|
||||||
for(i=0;i<5;i++)
|
for(i=0;i<5;i++)
|
||||||
*scf++ = getbits_fast(num1);
|
*scf++ = getbits_fast(mp, num1);
|
||||||
numbits += num1 * 5;
|
numbits += num1 * 5;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -522,7 +516,7 @@ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
|
|||||||
|
|
||||||
if(!(scfsi & 0x1)) {
|
if(!(scfsi & 0x1)) {
|
||||||
for (i=0;i<5;i++)
|
for (i=0;i<5;i++)
|
||||||
*scf++ = getbits_fast(num1);
|
*scf++ = getbits_fast(mp, num1);
|
||||||
numbits += num1 * 5;
|
numbits += num1 * 5;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -533,10 +527,9 @@ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
|
|||||||
}
|
}
|
||||||
return numbits;
|
return numbits;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static int III_get_scale_factors_2(int *scf,struct gr_info_s *gr_info,int i_stereo)
|
static int III_get_scale_factors_2(struct mpstr *mp, int *scf,struct gr_info_s *gr_info,int i_stereo)
|
||||||
{
|
{
|
||||||
unsigned char *pnt;
|
unsigned char *pnt;
|
||||||
int i,j;
|
int i,j;
|
||||||
@@ -573,7 +566,7 @@ static int III_get_scale_factors_2(int *scf,struct gr_info_s *gr_info,int i_ster
|
|||||||
slen >>= 3;
|
slen >>= 3;
|
||||||
if(num) {
|
if(num) {
|
||||||
for(j=0;j<(int)(pnt[i]);j++)
|
for(j=0;j<(int)(pnt[i]);j++)
|
||||||
*scf++ = getbits_fast(num);
|
*scf++ = getbits_fast(mp, num);
|
||||||
numbits += pnt[i] * num;
|
numbits += pnt[i] * num;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -595,7 +588,7 @@ static int pretab2[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
|||||||
/*
|
/*
|
||||||
* don't forget to apply the same changes to III_dequantize_sample_ms() !!!
|
* don't forget to apply the same changes to III_dequantize_sample_ms() !!!
|
||||||
*/
|
*/
|
||||||
static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
|
static int III_dequantize_sample(struct mpstr *mp, real xr[SBLIMIT][SSLIMIT],int *scf,
|
||||||
struct gr_info_s *gr_info,int sfreq,int part2bits)
|
struct gr_info_s *gr_info,int sfreq,int part2bits)
|
||||||
{
|
{
|
||||||
int shift = 1 + gr_info->scalefac_scale;
|
int shift = 1 + gr_info->scalefac_scale;
|
||||||
@@ -673,7 +666,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
|
|||||||
{
|
{
|
||||||
register short *val = h->table;
|
register short *val = h->table;
|
||||||
while((y=*val++)<0) {
|
while((y=*val++)<0) {
|
||||||
if (get1bit())
|
if (get1bit(mp))
|
||||||
val -= y;
|
val -= y;
|
||||||
part2remain--;
|
part2remain--;
|
||||||
}
|
}
|
||||||
@@ -683,15 +676,15 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
|
|||||||
if(x == 15) {
|
if(x == 15) {
|
||||||
max[lwin] = cb;
|
max[lwin] = cb;
|
||||||
part2remain -= h->linbits+1;
|
part2remain -= h->linbits+1;
|
||||||
x += getbits(h->linbits);
|
x += getbits(mp, h->linbits);
|
||||||
if(get1bit())
|
if(get1bit(mp))
|
||||||
*xrpnt = -ispow[x] * v;
|
*xrpnt = -ispow[x] * v;
|
||||||
else
|
else
|
||||||
*xrpnt = ispow[x] * v;
|
*xrpnt = ispow[x] * v;
|
||||||
}
|
}
|
||||||
else if(x) {
|
else if(x) {
|
||||||
max[lwin] = cb;
|
max[lwin] = cb;
|
||||||
if(get1bit())
|
if(get1bit(mp))
|
||||||
*xrpnt = -ispow[x] * v;
|
*xrpnt = -ispow[x] * v;
|
||||||
else
|
else
|
||||||
*xrpnt = ispow[x] * v;
|
*xrpnt = ispow[x] * v;
|
||||||
@@ -703,15 +696,15 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
|
|||||||
if(y == 15) {
|
if(y == 15) {
|
||||||
max[lwin] = cb;
|
max[lwin] = cb;
|
||||||
part2remain -= h->linbits+1;
|
part2remain -= h->linbits+1;
|
||||||
y += getbits(h->linbits);
|
y += getbits(mp, h->linbits);
|
||||||
if(get1bit())
|
if(get1bit(mp))
|
||||||
*xrpnt = -ispow[y] * v;
|
*xrpnt = -ispow[y] * v;
|
||||||
else
|
else
|
||||||
*xrpnt = ispow[y] * v;
|
*xrpnt = ispow[y] * v;
|
||||||
}
|
}
|
||||||
else if(y) {
|
else if(y) {
|
||||||
max[lwin] = cb;
|
max[lwin] = cb;
|
||||||
if(get1bit())
|
if(get1bit(mp))
|
||||||
*xrpnt = -ispow[y] * v;
|
*xrpnt = -ispow[y] * v;
|
||||||
else
|
else
|
||||||
*xrpnt = ispow[y] * v;
|
*xrpnt = ispow[y] * v;
|
||||||
@@ -733,7 +726,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
|
|||||||
a = 0;
|
a = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (get1bit())
|
if (get1bit(mp))
|
||||||
val -= a;
|
val -= a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -762,7 +755,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
|
|||||||
part2remain++;
|
part2remain++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(get1bit())
|
if(get1bit(mp))
|
||||||
*xrpnt = -v;
|
*xrpnt = -v;
|
||||||
else
|
else
|
||||||
*xrpnt = v;
|
*xrpnt = v;
|
||||||
@@ -839,7 +832,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
|
|||||||
{
|
{
|
||||||
register short *val = h->table;
|
register short *val = h->table;
|
||||||
while((y=*val++)<0) {
|
while((y=*val++)<0) {
|
||||||
if (get1bit())
|
if (get1bit(mp))
|
||||||
val -= y;
|
val -= y;
|
||||||
part2remain--;
|
part2remain--;
|
||||||
}
|
}
|
||||||
@@ -849,15 +842,15 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
|
|||||||
if (x == 15) {
|
if (x == 15) {
|
||||||
max = cb;
|
max = cb;
|
||||||
part2remain -= h->linbits+1;
|
part2remain -= h->linbits+1;
|
||||||
x += getbits(h->linbits);
|
x += getbits(mp, h->linbits);
|
||||||
if(get1bit())
|
if(get1bit(mp))
|
||||||
*xrpnt++ = -ispow[x] * v;
|
*xrpnt++ = -ispow[x] * v;
|
||||||
else
|
else
|
||||||
*xrpnt++ = ispow[x] * v;
|
*xrpnt++ = ispow[x] * v;
|
||||||
}
|
}
|
||||||
else if(x) {
|
else if(x) {
|
||||||
max = cb;
|
max = cb;
|
||||||
if(get1bit())
|
if(get1bit(mp))
|
||||||
*xrpnt++ = -ispow[x] * v;
|
*xrpnt++ = -ispow[x] * v;
|
||||||
else
|
else
|
||||||
*xrpnt++ = ispow[x] * v;
|
*xrpnt++ = ispow[x] * v;
|
||||||
@@ -869,15 +862,15 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
|
|||||||
if (y == 15) {
|
if (y == 15) {
|
||||||
max = cb;
|
max = cb;
|
||||||
part2remain -= h->linbits+1;
|
part2remain -= h->linbits+1;
|
||||||
y += getbits(h->linbits);
|
y += getbits(mp, h->linbits);
|
||||||
if(get1bit())
|
if(get1bit(mp))
|
||||||
*xrpnt++ = -ispow[y] * v;
|
*xrpnt++ = -ispow[y] * v;
|
||||||
else
|
else
|
||||||
*xrpnt++ = ispow[y] * v;
|
*xrpnt++ = ispow[y] * v;
|
||||||
}
|
}
|
||||||
else if(y) {
|
else if(y) {
|
||||||
max = cb;
|
max = cb;
|
||||||
if(get1bit())
|
if(get1bit(mp))
|
||||||
*xrpnt++ = -ispow[y] * v;
|
*xrpnt++ = -ispow[y] * v;
|
||||||
else
|
else
|
||||||
*xrpnt++ = ispow[y] * v;
|
*xrpnt++ = ispow[y] * v;
|
||||||
@@ -902,7 +895,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
|
|||||||
a = 0;
|
a = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (get1bit())
|
if (get1bit(mp))
|
||||||
val -= a;
|
val -= a;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -922,7 +915,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
|
|||||||
part2remain++;
|
part2remain++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(get1bit())
|
if(get1bit(mp))
|
||||||
*xrpnt++ = -v;
|
*xrpnt++ = -v;
|
||||||
else
|
else
|
||||||
*xrpnt++ = v;
|
*xrpnt++ = v;
|
||||||
@@ -945,11 +938,11 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
while( part2remain > 16 ) {
|
while( part2remain > 16 ) {
|
||||||
getbits(16); /* Dismiss stuffing Bits */
|
getbits(mp, 16); /* Dismiss stuffing Bits */
|
||||||
part2remain -= 16;
|
part2remain -= 16;
|
||||||
}
|
}
|
||||||
if(part2remain > 0)
|
if(part2remain > 0)
|
||||||
getbits(part2remain);
|
getbits(mp, part2remain);
|
||||||
else if(part2remain < 0) {
|
else if(part2remain < 0) {
|
||||||
fprintf(stderr,"mpg123: Can't rewind stream by %d bits!\n",-part2remain);
|
fprintf(stderr,"mpg123: Can't rewind stream by %d bits!\n",-part2remain);
|
||||||
return 1; /* -> error */
|
return 1; /* -> error */
|
||||||
@@ -1891,17 +1884,13 @@ int do_layer3(struct mpstr *mp, struct frame *fr,unsigned char *pcm_sample,int *
|
|||||||
|
|
||||||
if(fr->lsf) {
|
if(fr->lsf) {
|
||||||
granules = 1;
|
granules = 1;
|
||||||
if(!III_get_side_info_2(&sideinfo,stereo,ms_stereo,sfreq,single))
|
if(!III_get_side_info_2(mp, &sideinfo,stereo,ms_stereo,sfreq,single))
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
granules = 2;
|
granules = 2;
|
||||||
#ifdef MPEG1
|
if(!III_get_side_info_1(mp, &sideinfo,stereo,ms_stereo,sfreq,single))
|
||||||
if(!III_get_side_info_1(&sideinfo,stereo,ms_stereo,sfreq,single))
|
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
|
||||||
fprintf(stderr,"Not supported\n");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(set_pointer(mp, sideinfo.main_data_begin) == MP3_ERR)
|
if(set_pointer(mp, sideinfo.main_data_begin) == MP3_ERR)
|
||||||
@@ -1916,31 +1905,23 @@ int do_layer3(struct mpstr *mp, struct frame *fr,unsigned char *pcm_sample,int *
|
|||||||
struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]);
|
struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]);
|
||||||
long part2bits;
|
long part2bits;
|
||||||
if(fr->lsf)
|
if(fr->lsf)
|
||||||
part2bits = III_get_scale_factors_2(scalefacs[0],gr_info,0);
|
part2bits = III_get_scale_factors_2(mp, scalefacs[0],gr_info,0);
|
||||||
else {
|
else {
|
||||||
#ifdef MPEG1
|
part2bits = III_get_scale_factors_1(mp, scalefacs[0],gr_info);
|
||||||
part2bits = III_get_scale_factors_1(scalefacs[0],gr_info);
|
|
||||||
#else
|
|
||||||
fprintf(stderr,"Not supported\n");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
if(III_dequantize_sample(hybridIn[0], scalefacs[0],gr_info,sfreq,part2bits))
|
if(III_dequantize_sample(mp, hybridIn[0], scalefacs[0],gr_info,sfreq,part2bits))
|
||||||
return clip;
|
return clip;
|
||||||
}
|
}
|
||||||
if(stereo == 2) {
|
if(stereo == 2) {
|
||||||
struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]);
|
struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]);
|
||||||
long part2bits;
|
long part2bits;
|
||||||
if(fr->lsf)
|
if(fr->lsf)
|
||||||
part2bits = III_get_scale_factors_2(scalefacs[1],gr_info,i_stereo);
|
part2bits = III_get_scale_factors_2(mp, scalefacs[1],gr_info,i_stereo);
|
||||||
else {
|
else {
|
||||||
#ifdef MPEG1
|
part2bits = III_get_scale_factors_1(mp, scalefacs[1],gr_info);
|
||||||
part2bits = III_get_scale_factors_1(scalefacs[1],gr_info);
|
|
||||||
#else
|
|
||||||
fprintf(stderr,"Not supported\n");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(III_dequantize_sample(hybridIn[1],scalefacs[1],gr_info,sfreq,part2bits))
|
if(III_dequantize_sample(mp, hybridIn[1],scalefacs[1],gr_info,sfreq,part2bits))
|
||||||
return clip;
|
return clip;
|
||||||
|
|
||||||
if(ms_stereo) {
|
if(ms_stereo) {
|
||||||
|
|||||||
@@ -37,10 +37,6 @@
|
|||||||
|
|
||||||
#define MAXFRAMESIZE 1792
|
#define MAXFRAMESIZE 1792
|
||||||
|
|
||||||
|
|
||||||
/* Pre Shift fo 16 to 8 bit converter table */
|
|
||||||
#define AUSHIFT (3)
|
|
||||||
|
|
||||||
struct mpstr;
|
struct mpstr;
|
||||||
|
|
||||||
struct frame {
|
struct frame {
|
||||||
@@ -68,21 +64,11 @@ struct frame {
|
|||||||
void *alloc;
|
void *alloc;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct parameter {
|
extern unsigned int get1bit(struct mpstr *mp);
|
||||||
int quiet; /* shut up! */
|
extern unsigned int getbits(struct mpstr *mp, int);
|
||||||
int tryresync; /* resync stream after error */
|
extern unsigned int getbits_fast(struct mpstr *mp, int);
|
||||||
int verbose; /* verbose level */
|
|
||||||
int checkrange;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern unsigned int get1bit(void);
|
|
||||||
extern unsigned int getbits(int);
|
|
||||||
extern unsigned int getbits_fast(int);
|
|
||||||
extern int set_pointer(struct mpstr *mp, long backstep);
|
extern int set_pointer(struct mpstr *mp, long backstep);
|
||||||
|
|
||||||
extern unsigned char *wordpointer;
|
|
||||||
extern int bitindex;
|
|
||||||
|
|
||||||
extern void make_decode_tables(long scaleval);
|
extern void make_decode_tables(long scaleval);
|
||||||
extern int do_layer3(struct mpstr *mp, struct frame *fr,unsigned char *,int *);
|
extern int do_layer3(struct mpstr *mp, struct frame *fr,unsigned char *,int *);
|
||||||
extern int do_layer2(struct mpstr *mp, struct frame *fr,unsigned char *,int *);
|
extern int do_layer2(struct mpstr *mp, struct frame *fr,unsigned char *,int *);
|
||||||
@@ -159,14 +145,10 @@ extern void make_decode_tables(long scale);
|
|||||||
extern void make_conv16to8_table(int);
|
extern void make_conv16to8_table(int);
|
||||||
extern void dct64(real *,real *,real *);
|
extern void dct64(real *,real *,real *);
|
||||||
|
|
||||||
extern void synth_ntom_set_step(long,long);
|
|
||||||
|
|
||||||
extern unsigned char *conv16to8;
|
extern unsigned char *conv16to8;
|
||||||
extern long freqs[9];
|
extern long freqs[9];
|
||||||
extern real muls[27][64];
|
extern real muls[27][64];
|
||||||
extern real decwin[512+32];
|
extern real decwin[512+32];
|
||||||
extern real *pnts[5];
|
extern real *pnts[5];
|
||||||
|
|
||||||
extern struct parameter param;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -22,15 +22,17 @@ struct mpstr {
|
|||||||
struct buf *head,*tail;
|
struct buf *head,*tail;
|
||||||
int bsize;
|
int bsize;
|
||||||
int framesize;
|
int framesize;
|
||||||
int fsizeold;
|
int fsizeold;
|
||||||
struct frame fr;
|
struct frame fr;
|
||||||
unsigned char bsspace[2][MAXFRAMESIZE+512]; /* MAXFRAMESIZE */
|
unsigned char bsspace[2][MAXFRAMESIZE+512]; /* MAXFRAMESIZE */
|
||||||
real hybrid_block[2][2][SBLIMIT*SSLIMIT];
|
real hybrid_block[2][2][SBLIMIT*SSLIMIT];
|
||||||
int hybrid_blc[2];
|
int hybrid_blc[2];
|
||||||
unsigned long header;
|
unsigned long header;
|
||||||
int bsnum;
|
int bsnum;
|
||||||
real synth_buffs[2][2][0x110];
|
real synth_buffs[2][2][0x110];
|
||||||
int synth_bo;
|
int synth_bo;
|
||||||
|
int bitindex;
|
||||||
|
unsigned char *wordpointer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MP3_ERR -1
|
#define MP3_ERR -1
|
||||||
|
|||||||
Reference in New Issue
Block a user