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:
beveloper
2003-11-25 23:00:03 +00:00
parent 0596f8f6a1
commit d484cacf51
7 changed files with 166 additions and 214 deletions
@@ -7,8 +7,7 @@
#include <fcntl.h>
#include "mpg123.h"
struct parameter param = { 1 , 1 , 0 , 0 };
#include "mpglib.h"
int tabsel_123[2][3][16] = {
{ {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 ,
11025 , 12000 , 8000 };
int bitindex;
unsigned char *wordpointer;
unsigned char *pcm_sample;
int pcm_point = 0;
#define HDRCMPMASK 0xfffffd00
#if 0
@@ -98,7 +91,6 @@ int decode_header(struct frame *fr,unsigned long newhead)
switch(fr->lay)
{
case 1:
#ifdef LAYER1
#if 0
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
(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 /= freqs[fr->sampling_frequency];
fr->framesize = ((fr->framesize+fr->padding)<<2)-4;
#else
fprintf(stderr,"Not supported!\n");
#endif
break;
case 2:
#ifdef LAYER2
#if 0
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
(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 /= freqs[fr->sampling_frequency];
fr->framesize += fr->padding - 4;
#else
fprintf(stderr,"Not supported!\n");
#endif
break;
case 3:
#if 0
@@ -179,7 +164,7 @@ void print_header_compact(struct frame *fr)
#endif
unsigned int getbits(int number_of_bits)
unsigned int getbits(struct mpstr *mp, int number_of_bits)
{
unsigned long rval;
@@ -187,52 +172,52 @@ unsigned int getbits(int number_of_bits)
return 0;
{
rval = wordpointer[0];
rval = mp->wordpointer[0];
rval <<= 8;
rval |= wordpointer[1];
rval |= mp->wordpointer[1];
rval <<= 8;
rval |= wordpointer[2];
rval <<= bitindex;
rval |= mp->wordpointer[2];
rval <<= mp->bitindex;
rval &= 0xffffff;
bitindex += number_of_bits;
mp->bitindex += number_of_bits;
rval >>= (24-number_of_bits);
wordpointer += (bitindex>>3);
bitindex &= 7;
mp->wordpointer += (mp->bitindex>>3);
mp->bitindex &= 7;
}
return rval;
}
unsigned int getbits_fast(int number_of_bits)
unsigned int getbits_fast(struct mpstr *mp, int number_of_bits)
{
unsigned long rval;
{
rval = wordpointer[0];
rval = mp->wordpointer[0];
rval <<= 8;
rval |= wordpointer[1];
rval <<= bitindex;
rval |= mp->wordpointer[1];
rval <<= mp->bitindex;
rval &= 0xffff;
bitindex += number_of_bits;
mp->bitindex += number_of_bits;
rval >>= (16-number_of_bits);
wordpointer += (bitindex>>3);
bitindex &= 7;
mp->wordpointer += (mp->bitindex>>3);
mp->bitindex &= 7;
}
return rval;
}
unsigned int get1bit(void)
unsigned int get1bit(struct mpstr *mp)
{
unsigned char rval;
rval = *wordpointer << bitindex;
rval = *mp->wordpointer << mp->bitindex;
bitindex++;
wordpointer += (bitindex>>3);
bitindex &= 7;
mp->bitindex++;
mp->wordpointer += (mp->bitindex>>3);
mp->bitindex &= 7;
return rval>>7;
}
@@ -22,6 +22,8 @@ void InitMP3(struct mpstr *mp)
mp->fr.single = -1;
mp->bsnum = 0;
mp->synth_bo = 1;
mp->bitindex = 0;
mp->wordpointer = 0;
}
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)
return MP3_NEED_MORE;
wordpointer = mp->bsspace[mp->bsnum] + 512;
mp->wordpointer = mp->bsspace[mp->bsnum] + 512;
mp->bsnum = (mp->bsnum + 1) & 0x1;
bitindex = 0;
mp->bitindex = 0;
len = 0;
while(len < mp->framesize) {
@@ -168,7 +170,7 @@ int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,
else {
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;
mp->tail->pos += nlen;
mp->bsize -= nlen;
@@ -179,7 +181,7 @@ int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,
*done = 0;
if(mp->fr.error_protection)
getbits(16);
getbits(mp, 16);
switch(mp->fr.lay) {
case 1:
do_layer1(mp, &mp->fr,(unsigned char *) out,done);
@@ -206,9 +208,9 @@ int set_pointer(struct mpstr *mp, long backstep)
return MP3_ERR;
}
bsbufold = mp->bsspace[mp->bsnum] + 512;
wordpointer -= backstep;
mp->wordpointer -= backstep;
if (backstep)
memcpy(wordpointer,bsbufold+mp->fsizeold-backstep,backstep);
bitindex = 0;
memcpy(mp->wordpointer,bsbufold+mp->fsizeold-backstep,backstep);
mp->bitindex = 0;
return MP3_OK;
}
@@ -10,11 +10,11 @@
#include "mpg123.h"
void I_step_one(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_one(struct mpstr *mp, unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr);
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);
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 *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 jsbound = fr->jsbound;
for (i=0;i<jsbound;i++) {
*ba++ = getbits(4);
*ba++ = getbits(4);
*ba++ = getbits(mp, 4);
*ba++ = getbits(mp, 4);
}
for (i=jsbound;i<SBLIMIT;i++)
*ba++ = getbits(4);
*ba++ = getbits(mp, 4);
ba = balloc;
for (i=0;i<jsbound;i++) {
if ((*ba++))
*sca++ = getbits(6);
*sca++ = getbits(mp, 6);
if ((*ba++))
*sca++ = getbits(6);
*sca++ = getbits(mp, 6);
}
for (i=jsbound;i<SBLIMIT;i++)
if ((*ba++)) {
*sca++ = getbits(6);
*sca++ = getbits(6);
*sca++ = getbits(mp, 6);
*sca++ = getbits(mp, 6);
}
}
else {
int i;
for (i=0;i<SBLIMIT;i++)
*ba++ = getbits(4);
*ba++ = getbits(mp, 4);
ba = balloc;
for (i=0;i<SBLIMIT;i++)
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)
{
int i,n;
@@ -70,13 +70,13 @@ void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
ba = balloc;
for (sample=smpb,i=0;i<jsbound;i++) {
if ((n = *ba++))
*sample++ = getbits(n+1);
*sample++ = getbits(mp, n+1);
if ((n = *ba++))
*sample++ = getbits(n+1);
*sample++ = getbits(mp, n+1);
}
for (i=jsbound;i<SBLIMIT;i++)
if ((n = *ba++))
*sample++ = getbits(n+1);
*sample++ = getbits(mp, n+1);
ba = balloc;
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;
for (sample=smpb,i=0;i<SBLIMIT;i++)
if ((n = *ba++))
*sample++ = getbits(n+1);
*sample++ = getbits(mp, n+1);
ba = balloc;
for (sample=smpb,i=0;i<SBLIMIT;i++) {
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)
single = 0;
I_step_one(balloc,scale_index,fr);
I_step_one(mp, balloc,scale_index,fr);
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) {
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 */
void II_step_one(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_one(struct mpstr *mp, unsigned int *bit_alloc,int *scale,struct frame *fr);
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)
{
@@ -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 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))
{
*bita++ = (char) getbits(step=alloc1->bits);
*bita++ = (char) getbits(step);
*bita++ = (char) getbits(mp, step=alloc1->bits);
*bita++ = (char) getbits(mp, 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+=2;
}
@@ -90,17 +90,17 @@ void II_step_one(unsigned int *bit_alloc,int *scale,struct frame *fr)
scfsi=scfsi_buf;
for (i=sblimit2;i;i--)
if (*bita++)
*scfsi++ = (char) getbits_fast(2);
*scfsi++ = (char) getbits_fast(mp, 2);
}
else /* mono */
{
for (i=sblimit;i;i--,alloc1+=(1<<step))
*bita++ = (char) getbits(step=alloc1->bits);
*bita++ = (char) getbits(mp, step=alloc1->bits);
bita = bit_alloc;
scfsi=scfsi_buf;
for (i=sblimit;i;i--)
if (*bita++)
*scfsi++ = (char) getbits_fast(2);
*scfsi++ = (char) getbits_fast(mp, 2);
}
bita = bit_alloc;
@@ -110,30 +110,30 @@ void II_step_one(unsigned int *bit_alloc,int *scale,struct frame *fr)
switch (*scfsi++)
{
case 0:
*scale++ = getbits_fast(6);
*scale++ = getbits_fast(6);
*scale++ = getbits_fast(6);
*scale++ = getbits_fast(mp, 6);
*scale++ = getbits_fast(mp, 6);
*scale++ = getbits_fast(mp, 6);
break;
case 1 :
*scale++ = sc = getbits_fast(6);
*scale++ = sc = getbits_fast(mp, 6);
*scale++ = sc;
*scale++ = getbits_fast(6);
*scale++ = getbits_fast(mp, 6);
break;
case 2:
*scale++ = sc = getbits_fast(6);
*scale++ = sc = getbits_fast(mp, 6);
*scale++ = sc;
*scale++ = sc;
break;
default: /* case 3 */
*scale++ = getbits_fast(6);
*scale++ = sc = getbits_fast(6);
*scale++ = getbits_fast(mp, 6);
*scale++ = sc = getbits_fast(mp, 6);
*scale++ = sc;
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 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)
{
real cm=muls[k][scale[x1]];
fraction[j][0][i] = ((real) ((int)getbits(k) + d1)) * cm;
fraction[j][1][i] = ((real) ((int)getbits(k) + d1)) * cm;
fraction[j][2][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(mp, k) + d1)) * cm;
fraction[j][2][i] = ((real) ((int)getbits(mp, k) + d1)) * cm;
}
else
{
static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
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);
fraction[j][0][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;
cm=muls[k][scale[x1+3]];
fraction[1][0][i] = (fraction[0][0][i] = (real) ((int)getbits(k) + d1) ) * cm;
fraction[1][1][i] = (fraction[0][1][i] = (real) ((int)getbits(k) + d1) ) * cm;
fraction[1][2][i] = (fraction[0][2][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(mp, k) + d1) ) * cm;
fraction[1][2][i] = (fraction[0][2][i] = (real) ((int)getbits(mp, k) + d1) ) * cm;
cm=muls[k][scale[x1]];
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 };
unsigned int idx,*tab,m1,m2;
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);
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];
@@ -267,11 +267,11 @@ int do_layer2(struct mpstr *mp, struct frame *fr,unsigned char *pcm_sample,int *
if(stereo == 1 || single == 3)
single = 0;
II_step_one(bit_alloc, scale, fr);
II_step_one(mp, bit_alloc, scale, fr);
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++) {
if(single >= 0) {
clip += synth_1to1_mono(mp, fraction[0][j],pcm_sample,pcm_point);
@@ -10,9 +10,6 @@
#include "mpglib.h"
#include "huffman.h"
#define MPEG1
static real ispow[8207];
static real aa_ca[8],aa_cs[8];
static real COS1[12][6];
@@ -291,22 +288,21 @@ void init_layer3(int down_sample_sblimit)
/*
* read additional side information
*/
#ifdef MPEG1
static int III_get_side_info_1(struct III_sideinfo *si,int stereo,
static int III_get_side_info_1(struct mpstr *mp, struct III_sideinfo *si, int stereo,
int ms_stereo,long sfreq,int single)
{
int ch, gr;
int powdiff = (single == 3) ? 4 : 0;
si->main_data_begin = getbits(9);
si->main_data_begin = getbits(mp, 9);
if (stereo == 1)
si->private_bits = getbits_fast(5);
si->private_bits = getbits_fast(mp, 5);
else
si->private_bits = getbits_fast(3);
si->private_bits = getbits_fast(mp, 3);
for (ch=0; ch<stereo; ch++) {
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++)
@@ -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]);
gr_info->part2_3_length = getbits(12);
gr_info->big_values = getbits_fast(9);
gr_info->part2_3_length = getbits(mp, 12);
gr_info->big_values = getbits_fast(mp, 9);
if(gr_info->big_values > 288) {
fprintf(stderr,"big_values too large!\n");
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)
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 */
if(get1bit())
if(get1bit(mp))
{
int i;
gr_info->block_type = getbits_fast(2);
gr_info->mixed_block_flag = get1bit();
gr_info->table_select[0] = getbits_fast(5);
gr_info->table_select[1] = getbits_fast(5);
gr_info->block_type = getbits_fast(mp, 2);
gr_info->mixed_block_flag = get1bit(mp);
gr_info->table_select[0] = getbits_fast(mp, 5);
gr_info->table_select[1] = getbits_fast(mp, 5);
/*
* table_select[2] not needed, because there is no region2,
* but to satisfy some verifications tools we set it either.
*/
gr_info->table_select[2] = 0;
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) {
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;
for (i=0; i<3; i++)
gr_info->table_select[i] = getbits_fast(5);
r0c = getbits_fast(4);
r1c = getbits_fast(3);
gr_info->table_select[i] = getbits_fast(mp, 5);
r0c = getbits_fast(mp, 4);
r1c = getbits_fast(mp, 3);
gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
gr_info->block_type = 0;
gr_info->mixed_block_flag = 0;
}
gr_info->preflag = get1bit();
gr_info->scalefac_scale = get1bit();
gr_info->count1table_select = get1bit();
gr_info->preflag = get1bit(mp);
gr_info->scalefac_scale = get1bit(mp);
gr_info->count1table_select = get1bit(mp);
}
}
return !0;
}
#endif
/*
* 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 ch;
int powdiff = (single == 3) ? 4 : 0;
si->main_data_begin = getbits(8);
si->main_data_begin = getbits(mp, 8);
if (stereo == 1)
si->private_bits = get1bit();
si->private_bits = get1bit(mp);
else
si->private_bits = getbits_fast(2);
si->private_bits = getbits_fast(mp, 2);
for (ch=0; ch<stereo; ch++)
{
register struct gr_info_s *gr_info = &(si->ch[ch].gr[0]);
gr_info->part2_3_length = getbits(12);
gr_info->big_values = getbits_fast(9);
gr_info->part2_3_length = getbits(mp, 12);
gr_info->big_values = getbits_fast(mp, 9);
if(gr_info->big_values > 288) {
fprintf(stderr,"big_values too large!\n");
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)
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 */
if(get1bit())
if(get1bit(mp))
{
int i;
gr_info->block_type = getbits_fast(2);
gr_info->mixed_block_flag = get1bit();
gr_info->table_select[0] = getbits_fast(5);
gr_info->table_select[1] = getbits_fast(5);
gr_info->block_type = getbits_fast(mp, 2);
gr_info->mixed_block_flag = get1bit(mp);
gr_info->table_select[0] = getbits_fast(mp, 5);
gr_info->table_select[1] = getbits_fast(mp, 5);
/*
* table_select[2] not needed, because there is no region2,
* but to satisfy some verifications tools we set it either.
*/
gr_info->table_select[2] = 0;
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) {
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;
for (i=0; i<3; i++)
gr_info->table_select[i] = getbits_fast(5);
r0c = getbits_fast(4);
r1c = getbits_fast(3);
gr_info->table_select[i] = getbits_fast(mp, 5);
r0c = getbits_fast(mp, 4);
r1c = getbits_fast(mp, 3);
gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
gr_info->block_type = 0;
gr_info->mixed_block_flag = 0;
}
gr_info->scalefac_scale = get1bit();
gr_info->count1table_select = get1bit();
gr_info->scalefac_scale = get1bit(mp);
gr_info->count1table_select = get1bit(mp);
}
return !0;
}
@@ -451,8 +446,7 @@ static int III_get_side_info_2(struct III_sideinfo *si,int stereo,
/*
* read scalefactors
*/
#ifdef MPEG1
static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
static int III_get_scale_factors_1(struct mpstr *mp, int *scf,struct gr_info_s *gr_info)
{
static const unsigned char slen[2][16] = {
{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) {
for (i=8;i;i--)
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(mp, num0);
i = 9;
numbits -= num0; /* num0 * 17 + num1 * 18 */
}
for (;i;i--)
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(mp, num0);
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 */
}
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 */
for(i=11;i;i--)
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(mp, num0);
for(i=10;i;i--)
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(mp, num1);
numbits = (num0 + num1) * 10 + num0;
*scf++ = 0;
}
@@ -495,7 +489,7 @@ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
numbits = 0;
if(!(scfsi & 0x8)) {
for (i=0;i<6;i++)
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(mp, num0);
numbits += num0 * 6;
}
else {
@@ -504,7 +498,7 @@ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
if(!(scfsi & 0x4)) {
for (i=0;i<5;i++)
*scf++ = getbits_fast(num0);
*scf++ = getbits_fast(mp, num0);
numbits += num0 * 5;
}
else {
@@ -513,7 +507,7 @@ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
if(!(scfsi & 0x2)) {
for(i=0;i<5;i++)
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(mp, num1);
numbits += num1 * 5;
}
else {
@@ -522,7 +516,7 @@ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
if(!(scfsi & 0x1)) {
for (i=0;i<5;i++)
*scf++ = getbits_fast(num1);
*scf++ = getbits_fast(mp, num1);
numbits += num1 * 5;
}
else {
@@ -533,10 +527,9 @@ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
}
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;
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;
if(num) {
for(j=0;j<(int)(pnt[i]);j++)
*scf++ = getbits_fast(num);
*scf++ = getbits_fast(mp, num);
numbits += pnt[i] * num;
}
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() !!!
*/
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)
{
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;
while((y=*val++)<0) {
if (get1bit())
if (get1bit(mp))
val -= y;
part2remain--;
}
@@ -683,15 +676,15 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
if(x == 15) {
max[lwin] = cb;
part2remain -= h->linbits+1;
x += getbits(h->linbits);
if(get1bit())
x += getbits(mp, h->linbits);
if(get1bit(mp))
*xrpnt = -ispow[x] * v;
else
*xrpnt = ispow[x] * v;
}
else if(x) {
max[lwin] = cb;
if(get1bit())
if(get1bit(mp))
*xrpnt = -ispow[x] * v;
else
*xrpnt = ispow[x] * v;
@@ -703,15 +696,15 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
if(y == 15) {
max[lwin] = cb;
part2remain -= h->linbits+1;
y += getbits(h->linbits);
if(get1bit())
y += getbits(mp, h->linbits);
if(get1bit(mp))
*xrpnt = -ispow[y] * v;
else
*xrpnt = ispow[y] * v;
}
else if(y) {
max[lwin] = cb;
if(get1bit())
if(get1bit(mp))
*xrpnt = -ispow[y] * v;
else
*xrpnt = ispow[y] * v;
@@ -733,7 +726,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
a = 0;
break;
}
if (get1bit())
if (get1bit(mp))
val -= a;
}
@@ -762,7 +755,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
part2remain++;
break;
}
if(get1bit())
if(get1bit(mp))
*xrpnt = -v;
else
*xrpnt = v;
@@ -839,7 +832,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
{
register short *val = h->table;
while((y=*val++)<0) {
if (get1bit())
if (get1bit(mp))
val -= y;
part2remain--;
}
@@ -849,15 +842,15 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
if (x == 15) {
max = cb;
part2remain -= h->linbits+1;
x += getbits(h->linbits);
if(get1bit())
x += getbits(mp, h->linbits);
if(get1bit(mp))
*xrpnt++ = -ispow[x] * v;
else
*xrpnt++ = ispow[x] * v;
}
else if(x) {
max = cb;
if(get1bit())
if(get1bit(mp))
*xrpnt++ = -ispow[x] * v;
else
*xrpnt++ = ispow[x] * v;
@@ -869,15 +862,15 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
if (y == 15) {
max = cb;
part2remain -= h->linbits+1;
y += getbits(h->linbits);
if(get1bit())
y += getbits(mp, h->linbits);
if(get1bit(mp))
*xrpnt++ = -ispow[y] * v;
else
*xrpnt++ = ispow[y] * v;
}
else if(y) {
max = cb;
if(get1bit())
if(get1bit(mp))
*xrpnt++ = -ispow[y] * v;
else
*xrpnt++ = ispow[y] * v;
@@ -902,7 +895,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
a = 0;
break;
}
if (get1bit())
if (get1bit(mp))
val -= a;
}
@@ -922,7 +915,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
part2remain++;
break;
}
if(get1bit())
if(get1bit(mp))
*xrpnt++ = -v;
else
*xrpnt++ = v;
@@ -945,11 +938,11 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
}
while( part2remain > 16 ) {
getbits(16); /* Dismiss stuffing Bits */
getbits(mp, 16); /* Dismiss stuffing Bits */
part2remain -= 16;
}
if(part2remain > 0)
getbits(part2remain);
getbits(mp, part2remain);
else if(part2remain < 0) {
fprintf(stderr,"mpg123: Can't rewind stream by %d bits!\n",-part2remain);
return 1; /* -> error */
@@ -1891,17 +1884,13 @@ int do_layer3(struct mpstr *mp, struct frame *fr,unsigned char *pcm_sample,int *
if(fr->lsf) {
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;
}
else {
granules = 2;
#ifdef MPEG1
if(!III_get_side_info_1(&sideinfo,stereo,ms_stereo,sfreq,single))
if(!III_get_side_info_1(mp, &sideinfo,stereo,ms_stereo,sfreq,single))
return -1;
#else
fprintf(stderr,"Not supported\n");
#endif
}
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]);
long part2bits;
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 {
#ifdef MPEG1
part2bits = III_get_scale_factors_1(scalefacs[0],gr_info);
#else
fprintf(stderr,"Not supported\n");
#endif
part2bits = III_get_scale_factors_1(mp, scalefacs[0],gr_info);
}
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;
}
if(stereo == 2) {
struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]);
long part2bits;
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 {
#ifdef MPEG1
part2bits = III_get_scale_factors_1(scalefacs[1],gr_info);
#else
fprintf(stderr,"Not supported\n");
#endif
part2bits = III_get_scale_factors_1(mp, scalefacs[1],gr_info);
}
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;
if(ms_stereo) {
@@ -37,10 +37,6 @@
#define MAXFRAMESIZE 1792
/* Pre Shift fo 16 to 8 bit converter table */
#define AUSHIFT (3)
struct mpstr;
struct frame {
@@ -68,21 +64,11 @@ struct frame {
void *alloc;
};
struct parameter {
int quiet; /* shut up! */
int tryresync; /* resync stream after error */
int verbose; /* verbose level */
int checkrange;
};
extern unsigned int get1bit(void);
extern unsigned int getbits(int);
extern unsigned int getbits_fast(int);
extern unsigned int get1bit(struct mpstr *mp);
extern unsigned int getbits(struct mpstr *mp, int);
extern unsigned int getbits_fast(struct mpstr *mp, int);
extern int set_pointer(struct mpstr *mp, long backstep);
extern unsigned char *wordpointer;
extern int bitindex;
extern void make_decode_tables(long scaleval);
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 *);
@@ -159,14 +145,10 @@ extern void make_decode_tables(long scale);
extern void make_conv16to8_table(int);
extern void dct64(real *,real *,real *);
extern void synth_ntom_set_step(long,long);
extern unsigned char *conv16to8;
extern long freqs[9];
extern real muls[27][64];
extern real decwin[512+32];
extern real *pnts[5];
extern struct parameter param;
#endif
@@ -31,6 +31,8 @@ struct mpstr {
int bsnum;
real synth_buffs[2][2][0x110];
int synth_bo;
int bitindex;
unsigned char *wordpointer;
};
#define MP3_ERR -1