Mercurial > audlegacy
changeset 127:05d824e30afd trunk
[svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
author | nenolod |
---|---|
date | Wed, 09 Nov 2005 16:40:03 -0800 |
parents | 2d3d921a44e2 |
children | f6ceb8f4ad5c |
files | Plugins/Input/mpg123/common.h Plugins/Input/mpg123/decode.c Plugins/Input/mpg123/decode_2to1.c Plugins/Input/mpg123/decode_3dnow.s Plugins/Input/mpg123/decode_4to1.c Plugins/Input/mpg123/decode_MMX.s Plugins/Input/mpg123/decode_i386.c Plugins/Input/mpg123/decode_i586.s Plugins/Input/mpg123/getbits.c Plugins/Input/mpg123/getbits.h Plugins/Input/mpg123/layer1.c Plugins/Input/mpg123/layer2.c Plugins/Input/mpg123/layer3.c Plugins/Input/mpg123/mpg123.h |
diffstat | 14 files changed, 2356 insertions(+), 2472 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Plugins/Input/mpg123/common.h Wed Nov 09 16:40:03 2005 -0800 @@ -0,0 +1,18 @@ +/* + * common.h + */ + +extern void print_id3_tag(unsigned char *buf); +extern unsigned long firsthead; +extern double compute_tpf(struct frame *fr); +extern double compute_bpf(struct frame *fr); +extern long compute_buffer_offset(struct frame *fr); + +/* +struct bitstream_info { + int bitindex; + unsigned char *wordpointer; +}; +*/ + +
--- a/Plugins/Input/mpg123/decode.c Tue Nov 08 12:04:15 2005 -0800 +++ b/Plugins/Input/mpg123/decode.c Wed Nov 09 16:40:03 2005 -0800 @@ -1,4 +1,3 @@ - /* * Mpeg Layer-1,2,3 audio decoder * ------------------------------ @@ -14,223 +13,206 @@ #include "mpg123.h" #define WRITE_SAMPLE(samples,sum,clip) \ - if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \ - else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \ - else { *(samples) = sum; } + if( (sum) > REAL_PLUS_32767) { *(samples) = 0x7fff; (clip)++; } \ + else if( (sum) < REAL_MINUS_32768) { *(samples) = -0x8000; (clip)++; } \ + else { *(samples) = REAL_TO_SHORT(sum); } -int -mpg123_synth_1to1_8bit(real * bandPtr, int channel, - unsigned char *samples, int *pnt) +int mpg123_synth_1to1_8bit(real *bandPtr,int channel,unsigned char *samples,int *pnt) { - short samples_tmp[64]; - short *tmp1 = samples_tmp + channel; - int i, ret; - int pnt1 = 0; + short samples_tmp[64]; + short *tmp1 = samples_tmp + channel; + int i,ret; + int pnt1=0; - ret = - mpg123_synth_1to1(bandPtr, channel, (unsigned char *) samples_tmp, - &pnt1); - samples += channel + *pnt; + ret = mpg123_synth_1to1(bandPtr,channel,(unsigned char *) samples_tmp,&pnt1); + samples += channel + *pnt; - for (i = 0; i < 32; i++) { - *samples = (*tmp1 >> 8) ^ 128; - samples += 2; - tmp1 += 2; - } - *pnt += 64; + for(i=0;i<32;i++) { + *samples = mpg123_conv16to8[*tmp1>>AUSHIFT]; + samples += 2; + tmp1 += 2; + } + *pnt += 64; - return ret; + return ret; } -int -mpg123_synth_1to1_8bit_mono(real * bandPtr, unsigned char *samples, int *pnt) +int mpg123_synth_1to1_8bit_mono(real *bandPtr,unsigned char *samples,int *pnt) { - short samples_tmp[64]; - short *tmp1 = samples_tmp; - int i, ret; - int pnt1 = 0; + short samples_tmp[64]; + short *tmp1 = samples_tmp; + int i,ret; + int pnt1 = 0; + + ret = mpg123_synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1); + samples += *pnt; + + for(i=0;i<32;i++) { + *samples++ = mpg123_conv16to8[*tmp1>>AUSHIFT]; + tmp1 += 2; + } + *pnt += 32; + + return ret; +} - ret = mpg123_synth_1to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1); - samples += *pnt; +int mpg123_synth_1to1_8bit_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt) +{ + short samples_tmp[64]; + short *tmp1 = samples_tmp; + int i,ret; + int pnt1 = 0; - for (i = 0; i < 32; i++) { - *samples++ = (*tmp1 >> 8) ^ 128; - tmp1 += 2; - } - *pnt += 32; + ret = mpg123_synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1); + samples += *pnt; - return ret; + for(i=0;i<32;i++) { + *samples++ = mpg123_conv16to8[*tmp1>>AUSHIFT]; + *samples++ = mpg123_conv16to8[*tmp1>>AUSHIFT]; + tmp1 += 2; + } + *pnt += 64; + + return ret; } -#if 0 -int -mpg123_synth_1to1_8bit_mono2stereo(real * bandPtr, - unsigned char *samples, int *pnt) +int mpg123_synth_1to1_mono(real *bandPtr,unsigned char *samples,int *pnt) { - short samples_tmp[64]; - short *tmp1 = samples_tmp; - int i, ret; - int pnt1 = 0; + short samples_tmp[64]; + short *tmp1 = samples_tmp; + int i,ret; + int pnt1 = 0; - ret = mpg123_synth_1to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1); - samples += *pnt; + ret = mpg123_synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1); + samples += *pnt; - for (i = 0; i < 32; i++) { - *samples++ = (*tmp1 >> 8) ^ 128; - *samples++ = (*tmp1 >> 8) ^ 128; - tmp1 += 2; - } - *pnt += 64; + for(i=0;i<32;i++) { + *( (short *)samples) = *tmp1; + samples += 2; + tmp1 += 2; + } + *pnt += 64; - return ret; + return ret; } -#endif + -int -mpg123_synth_1to1_mono(real * bandPtr, unsigned char *samples, int *pnt) +int mpg123_synth_1to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt) { - short samples_tmp[64]; - short *tmp1 = samples_tmp; - int i, ret; - int pnt1 = 0; + int i,ret; - ret = mpg123_synth_1to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1); - samples += *pnt; + ret = mpg123_synth_1to1(bandPtr,0,samples,pnt); + samples = samples + *pnt - 128; - for (i = 0; i < 32; i++) { - *((short *) samples) = *tmp1; - samples += 2; - tmp1 += 2; - } - *pnt += 64; + for(i=0;i<32;i++) { + ((short *)samples)[1] = ((short *)samples)[0]; + samples+=4; + } - return ret; + return ret; } -#if 0 -int -mpg123_synth_1to1_mono2stereo(real * bandPtr, unsigned char *samples, - int *pnt) + +int mpg123_synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt) { - int i, ret; - - ret = mpg123_synth_1to1(bandPtr, 0, samples, pnt); - samples = samples + *pnt - 128; + static real buffs[2][2][0x110]; + static const int step = 2; + static int bo = 1; + short *samples = (short *) (out+*pnt); - for (i = 0; i < 32; i++) { - ((short *) samples)[1] = ((short *) samples)[0]; - samples += 4; - } + real *b0,(*buf)[0x110]; + int clip = 0; + int bo1; - return ret; -} -#endif - -int -mpg123_synth_1to1(real * bandPtr, int channel, unsigned char *out, int *pnt) -{ - static real buffs[2][2][0x110]; - static const int step = 2; - static int bo = 1; - short *samples = (short *) (out + *pnt); + if(!channel) { + bo--; + bo &= 0xf; + buf = buffs[0]; + } + else { + samples++; + buf = buffs[1]; + } - real *b0, (*buf)[0x110]; - int clip = 0; - int bo1; - int i = 0; + if(bo & 0x1) { + b0 = buf[0]; + bo1 = bo; + mpg123_dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr); + } + else { + b0 = buf[1]; + bo1 = bo+1; + mpg123_dct64(buf[0]+bo,buf[1]+bo+1,bandPtr); + } -/* if(param.equalizer) - do_equalizer(bandPtr,channel); */ - if (!channel) { - bo--; - bo &= 0xf; - buf = buffs[0]; - } - else { - samples++; - buf = buffs[1]; - } + { + register int j; + real *window = mpg123_decwin + 16 - bo1; + + for (j=16;j;j--,window+=0x10,samples+=step) + { + real sum; + sum = REAL_MUL(*window++, *b0++); + sum -= REAL_MUL(*window++, *b0++); + sum += REAL_MUL(*window++, *b0++); + sum -= REAL_MUL(*window++, *b0++); + sum += REAL_MUL(*window++, *b0++); + sum -= REAL_MUL(*window++, *b0++); + sum += REAL_MUL(*window++, *b0++); + sum -= REAL_MUL(*window++, *b0++); + sum += REAL_MUL(*window++, *b0++); + sum -= REAL_MUL(*window++, *b0++); + sum += REAL_MUL(*window++, *b0++); + sum -= REAL_MUL(*window++, *b0++); + sum += REAL_MUL(*window++, *b0++); + sum -= REAL_MUL(*window++, *b0++); + sum += REAL_MUL(*window++, *b0++); + sum -= REAL_MUL(*window++, *b0++); - if (bo & 0x1) { - b0 = buf[0]; - bo1 = bo; - mpg123_dct64(buf[1] + ((bo + 1) & 0xf), buf[0] + bo, bandPtr); - } - else { - b0 = buf[1]; - bo1 = bo + 1; - mpg123_dct64(buf[0] + bo, buf[1] + bo + 1, bandPtr); + WRITE_SAMPLE(samples,sum,clip); } { - register int j; - real *window = mpg123_decwin + 16 - bo1; - - for (j = 16; j; j--, window += 0x10, samples += step) { - real sum; - - sum = *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - i++; - WRITE_SAMPLE(samples, sum, clip); - } - - { - real sum; + real sum; + sum = REAL_MUL(window[0x0], b0[0x0]); + sum += REAL_MUL(window[0x2], b0[0x2]); + sum += REAL_MUL(window[0x4], b0[0x4]); + sum += REAL_MUL(window[0x6], b0[0x6]); + sum += REAL_MUL(window[0x8], b0[0x8]); + sum += REAL_MUL(window[0xA], b0[0xA]); + sum += REAL_MUL(window[0xC], b0[0xC]); + sum += REAL_MUL(window[0xE], b0[0xE]); + WRITE_SAMPLE(samples,sum,clip); + b0-=0x10,window-=0x20,samples+=step; + } + window += bo1<<1; - 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 -= 0x20, window -= 0x10, samples += step) { - real sum; + for (j=15;j;j--,b0-=0x20,window-=0x10,samples+=step) + { + real sum; + sum = -REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); + sum -= REAL_MUL(*(--window), *b0++); - sum = -*(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - WRITE_SAMPLE(samples, sum, clip); - } + WRITE_SAMPLE(samples,sum,clip); } - - *pnt += 128; + } - return clip; + *pnt += 128; + + return clip; }
--- a/Plugins/Input/mpg123/decode_2to1.c Tue Nov 08 12:04:15 2005 -0800 +++ b/Plugins/Input/mpg123/decode_2to1.c Wed Nov 09 16:40:03 2005 -0800 @@ -1,4 +1,3 @@ - /* * Mpeg Layer-1,2,3 audio decoder * ------------------------------ @@ -19,233 +18,211 @@ else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \ else { *(samples) = sum; } -int -mpg123_synth_2to1_8bit(real * bandPtr, int channel, - unsigned char *samples, int *pnt) +int mpg123_synth_2to1_8bit(real *bandPtr,int channel,unsigned char *samples,int *pnt) { - short samples_tmp[32]; - short *tmp1 = samples_tmp + channel; - int i, ret; - int pnt1 = 0; + short samples_tmp[32]; + short *tmp1 = samples_tmp + channel; + int i,ret; + int pnt1 = 0; - ret = - mpg123_synth_2to1(bandPtr, channel, (unsigned char *) samples_tmp, - &pnt1); - samples += channel + *pnt; + ret = mpg123_synth_2to1(bandPtr,channel,(unsigned char *) samples_tmp,&pnt1); + samples += channel + *pnt; - for (i = 0; i < 16; i++) { - *samples = (*tmp1 >> 8) ^ 128; - samples += 2; - tmp1 += 2; - } - *pnt += 32; + for(i=0;i<16;i++) { + *samples = mpg123_conv16to8[*tmp1>>AUSHIFT]; + samples += 2; + tmp1 += 2; + } + *pnt += 32; - return ret; + return ret; } -int -mpg123_synth_2to1_8bit_mono(real * bandPtr, unsigned char *samples, int *pnt) +int mpg123_synth_2to1_8bit_mono(real *bandPtr,unsigned char *samples,int *pnt) { - short samples_tmp[32]; - short *tmp1 = samples_tmp; - int i, ret; - int pnt1 = 0; + short samples_tmp[32]; + short *tmp1 = samples_tmp; + int i,ret; + int pnt1 = 0; + + ret = mpg123_synth_2to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1); + samples += *pnt; + + for(i=0;i<16;i++) { + *samples++ = mpg123_conv16to8[*tmp1>>AUSHIFT]; + tmp1 += 2; + } + *pnt += 16; + + return ret; +} - ret = mpg123_synth_2to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1); - samples += *pnt; + +int mpg123_synth_2to1_8bit_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt) +{ + short samples_tmp[32]; + short *tmp1 = samples_tmp; + int i,ret; + int pnt1 = 0; - for (i = 0; i < 16; i++) { - *samples++ = (*tmp1 >> 8) ^ 128; - tmp1 += 2; - } - *pnt += 16; + ret = mpg123_synth_2to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1); + samples += *pnt; - return ret; + for(i=0;i<16;i++) { + *samples++ = mpg123_conv16to8[*tmp1>>AUSHIFT]; + *samples++ = mpg123_conv16to8[*tmp1>>AUSHIFT]; + tmp1 += 2; + } + *pnt += 32; + + return ret; } -#if 0 -int -mpg123_synth_2to1_8bit_mono2stereo(real * bandPtr, - unsigned char *samples, int *pnt) +int mpg123_synth_2to1_mono(real *bandPtr,unsigned char *samples,int *pnt) { - short samples_tmp[32]; - short *tmp1 = samples_tmp; - int i, ret; - int pnt1 = 0; + short samples_tmp[32]; + short *tmp1 = samples_tmp; + int i,ret; + int pnt1=0; - ret = mpg123_synth_2to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1); - samples += *pnt; + ret = mpg123_synth_2to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1); + samples += *pnt; - for (i = 0; i < 16; i++) { - *samples++ = (*tmp1 >> 8) ^ 128; - *samples++ = (*tmp1 >> 8) ^ 128; - tmp1 += 2; - } - *pnt += 32; + for(i=0;i<16;i++) { + *( (short *) samples) = *tmp1; + samples += 2; + tmp1 += 2; + } + *pnt += 32; - return ret; + return ret; } -#endif -int -mpg123_synth_2to1_mono(real * bandPtr, unsigned char *samples, int *pnt) +int mpg123_synth_2to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt) { - short samples_tmp[32]; - short *tmp1 = samples_tmp; - int i, ret; - int pnt1 = 0; + int i,ret; - ret = mpg123_synth_2to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1); - samples += *pnt; + ret = mpg123_synth_2to1(bandPtr,0,samples,pnt); + samples = samples + *pnt - 64; - for (i = 0; i < 16; i++) { - *((short *) samples) = *tmp1; - samples += 2; - tmp1 += 2; - } - *pnt += 32; - - return ret; + for(i=0;i<16;i++) { + ((short *)samples)[1] = ((short *)samples)[0]; + samples+=4; + } + + return ret; } -#if 0 -int -mpg123_synth_2to1_mono2stereo(real * bandPtr, unsigned char *samples, - int *pnt) +int mpg123_synth_2to1(real *bandPtr,int channel,unsigned char *out,int *pnt) { - int i, ret; - - ret = mpg123_synth_2to1(bandPtr, 0, samples, pnt); - samples = samples + *pnt - 64; + static real buffs[2][2][0x110]; + static const int step = 2; + static int bo = 1; + short *samples = (short *) (out + *pnt); - for (i = 0; i < 16; i++) { - ((short *) samples)[1] = ((short *) samples)[0]; - samples += 4; - } + real *b0,(*buf)[0x110]; + int clip = 0; + int bo1; - return ret; -} -#endif - -int -mpg123_synth_2to1(real * bandPtr, int channel, unsigned char *out, int *pnt) -{ - static real buffs[2][2][0x110]; - static const int step = 2; - static int bo = 1; - short *samples = (short *) (out + *pnt); + if(!channel) { + bo--; + bo &= 0xf; + buf = buffs[0]; + } + else { + samples++; + buf = buffs[1]; + } - real *b0, (*buf)[0x110]; - int clip = 0; - int bo1; + if(bo & 0x1) { + b0 = buf[0]; + bo1 = bo; + mpg123_dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr); + } + else { + b0 = buf[1]; + bo1 = bo+1; + mpg123_dct64(buf[0]+bo,buf[1]+bo+1,bandPtr); + } -/* if(param.equalizer) - do_equalizer(bandPtr,channel); */ + { + register int j; + real *window = mpg123_decwin + 16 - bo1; - if (!channel) { - bo--; - bo &= 0xf; - buf = buffs[0]; - } - else { - samples++; - buf = buffs[1]; - } + for (j=8;j;j--,b0+=0x10,window+=0x30) + { + real sum; + sum = *window++ * *b0++; + sum -= *window++ * *b0++; + sum += *window++ * *b0++; + sum -= *window++ * *b0++; + sum += *window++ * *b0++; + sum -= *window++ * *b0++; + sum += *window++ * *b0++; + sum -= *window++ * *b0++; + sum += *window++ * *b0++; + sum -= *window++ * *b0++; + sum += *window++ * *b0++; + sum -= *window++ * *b0++; + sum += *window++ * *b0++; + sum -= *window++ * *b0++; + sum += *window++ * *b0++; + sum -= *window++ * *b0++; - if (bo & 0x1) { - b0 = buf[0]; - bo1 = bo; - mpg123_dct64(buf[1] + ((bo + 1) & 0xf), buf[0] + bo, bandPtr); - } - else { - b0 = buf[1]; - bo1 = bo + 1; - mpg123_dct64(buf[0] + bo, buf[1] + bo + 1, bandPtr); + WRITE_SAMPLE(samples,sum,clip); samples += step; +#if 0 + WRITE_SAMPLE(samples,sum,clip); samples += step; +#endif } { - register int j; - real *window = mpg123_decwin + 16 - bo1; - - for (j = 8; j; j--, b0 += 0x10, window += 0x30) { - real sum; - - sum = *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - - WRITE_SAMPLE(samples, sum, clip); - samples += step; + 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); samples += step; #if 0 - WRITE_SAMPLE(samples, sum, clip); - samples += step; + WRITE_SAMPLE(samples,sum,clip); samples += step; #endif - } - - { - real sum; + b0-=0x20,window-=0x40; + } + window += bo1<<1; - 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); - samples += step; -#if 0 - WRITE_SAMPLE(samples, sum, clip); - samples += step; -#endif - b0 -= 0x20, window -= 0x40; - } - window += bo1 << 1; - - for (j = 7; j; j--, b0 -= 0x30, window -= 0x30) { - real sum; + for (j=7;j;j--,b0-=0x30,window-=0x30) + { + real sum; + sum = -*(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; - sum = -*(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; + WRITE_SAMPLE(samples,sum,clip); samples += step; +#if 0 + WRITE_SAMPLE(samples,sum,clip); samples += step; +#endif + } + } - WRITE_SAMPLE(samples, sum, clip); - samples += step; -#if 0 - WRITE_SAMPLE(samples, sum, clip); - samples += step; -#endif - } - } + *pnt += 64; - *pnt += 64; + return clip; +} - return clip; -} +
--- a/Plugins/Input/mpg123/decode_3dnow.s Tue Nov 08 12:04:15 2005 -0800 +++ b/Plugins/Input/mpg123/decode_3dnow.s Wed Nov 09 16:40:03 2005 -0800 @@ -1,34 +1,31 @@ -/ -/ decode_3dnow.s - 3DNow! optimized synth_1to1() -/ -/ This code based 'decode_3dnow.s' by Syuuhei Kashiyama -/ <squash@mb.kcom.ne.jp>,only two types of changes have been made: -/ -/ - remove PREFETCH instruction for speedup -/ - change function name for support 3DNow! automatic detect -/ - femms moved to before 'call dct64_3dnow' -/ -/ You can find Kashiyama's original 3dnow! support patch -/ (for mpg123-0.59o) at -/ http://user.ecc.u-tokyo.ac.jp/~g810370/linux-simd/ (Japanese). -/ -/ by KIMURA Takuhiro <kim@hannah.ipc.miyakyo-u.ac.jp> - until 31.Mar.1999 -/ <kim@comtec.co.jp> - after 1.Apr.1999 -/ -/ porting xmms-0.9.1 by Osamu kayasono <jacobi@jcom.home.ne.jp> -/ - rename function name for xmms -/ - disable equalizer for mpg123 +# +# decode_3dnow.s - 3DNow! optimized synth_1to1() +# +# This code based 'decode_3dnow.s' by Syuuhei Kashiyama +# <squash@mb.kcom.ne.jp>,only two types of changes have been made: +# +# - remove PREFETCH instruction for speedup +# - change function name for support 3DNow! automatic detect +# - femms moved to before 'call dct64_3dnow' +# +# You can find Kashiyama's original 3dnow! support patch +# (for mpg123-0.59o) at +# http:#/user.ecc.u-tokyo.ac.jp/~g810370/linux-simd/ (Japanese). +# +# by KIMURA Takuhiro <kim@hannah.ipc.miyakyo-u.ac.jp> - until 31.Mar.1999 +# <kim@comtec.co.jp> - after 1.Apr.1999 +# -/// -/// Replacement of synth_1to1() with AMD's 3DNow! SIMD operations support -/// -/// Syuuhei Kashiyama <squash@mb.kcom.ne.jp> -/// -/// The author of this program disclaim whole expressed or implied -/// warranties with regard to this program, and in no event shall the -/// author of this program liable to whatever resulted from the use of -/// this program. Use it at your own risk. -/// +##/ +##/ Replacement of synth_1to1() with AMD's 3DNow! SIMD operations support +##/ +##/ Syuuhei Kashiyama <squash@mb.kcom.ne.jp> +##/ +##/ The author of this program disclaim whole expressed or implied +##/ warranties with regard to this program, and in no event shall the +##/ author of this program liable to whatever resulted from the use of +##/ this program. Use it at your own risk. +##/ .local buffs.40 .comm buffs.40,4352,32 @@ -57,14 +54,7 @@ femms -/// / disable equalizer by Osamu Kayasono -/// cmpl $0,equalfile -/// je .L25 -/// pushl %ebx -/// pushl 48(%esp) -/// call do_equalizer_3dnow -/// addl $8,%esp -///.L25: +.L25: testl %ebx,%ebx jne .L26 decl bo.42 @@ -219,37 +209,37 @@ punpckldq 20(%ebx),%mm5 punpckldq -24(%edx),%mm6 pfadd %mm3,%mm0 - movd 24(%ebx),%mm1 - movd -28(%edx),%mm2 + movd 24(%ebx),%mm1 + movd -28(%edx),%mm2 pfmul %mm6,%mm5 punpckldq 28(%ebx),%mm1 punpckldq -32(%edx),%mm2 pfadd %mm5,%mm0 - movd 32(%ebx),%mm3 - movd -36(%edx),%mm4 + movd 32(%ebx),%mm3 + movd -36(%edx),%mm4 pfmul %mm2,%mm1 punpckldq 36(%ebx),%mm3 punpckldq -40(%edx),%mm4 - pfadd %mm1,%mm0 - movd 40(%ebx),%mm5 - movd -44(%edx),%mm6 - pfmul %mm4,%mm3 + pfadd %mm1,%mm0 + movd 40(%ebx),%mm5 + movd -44(%edx),%mm6 + pfmul %mm4,%mm3 punpckldq 44(%ebx),%mm5 punpckldq -48(%edx),%mm6 - pfadd %mm3,%mm0 - movd 48(%ebx),%mm1 - movd -52(%edx),%mm2 - pfmul %mm6,%mm5 - punpckldq 52(%ebx),%mm1 + pfadd %mm3,%mm0 + movd 48(%ebx),%mm1 + movd -52(%edx),%mm2 + pfmul %mm6,%mm5 + punpckldq 52(%ebx),%mm1 punpckldq -56(%edx),%mm2 pfadd %mm0,%mm5 - movd 56(%ebx),%mm3 - movd -60(%edx),%mm4 + movd 56(%ebx),%mm3 + movd -60(%edx),%mm4 pfmul %mm2,%mm1 punpckldq 60(%ebx),%mm3 punpckldq (%edx),%mm4 - pfadd %mm1,%mm5 - addl $-128,%edx + pfadd %mm1,%mm5 + addl $-128,%edx addl $-64,%ebx movd (%ebx),%mm0 movd -4(%edx),%mm1
--- a/Plugins/Input/mpg123/decode_4to1.c Tue Nov 08 12:04:15 2005 -0800 +++ b/Plugins/Input/mpg123/decode_4to1.c Wed Nov 09 16:40:03 2005 -0800 @@ -1,4 +1,3 @@ - /* * Mpeg Layer-1,2,3 audio decoder * ------------------------------ @@ -20,245 +19,217 @@ else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \ else { *(samples) = sum; } -int -mpg123_synth_4to1_8bit(real * bandPtr, int channel, - unsigned char *samples, int *pnt) +int mpg123_synth_4to1_8bit(real *bandPtr,int channel,unsigned char *samples,int *pnt) { - short samples_tmp[16]; - short *tmp1 = samples_tmp + channel; - int i, ret; - int pnt1 = 0; + short samples_tmp[16]; + short *tmp1 = samples_tmp + channel; + int i,ret; + int pnt1 = 0; - ret = - mpg123_synth_4to1(bandPtr, channel, (unsigned char *) samples_tmp, - &pnt1); - samples += channel + *pnt; + ret = mpg123_synth_4to1(bandPtr,channel,(unsigned char *) samples_tmp,&pnt1); + samples += channel + *pnt; - for (i = 0; i < 8; i++) { - *samples = (*tmp1 >> 8) ^ 128; - samples += 2; - tmp1 += 2; - } - *pnt += 16; + for(i=0;i<8;i++) { + *samples = mpg123_conv16to8[*tmp1>>AUSHIFT]; + samples += 2; + tmp1 += 2; + } + *pnt += 16; - return ret; + return ret; } -int -mpg123_synth_4to1_8bit_mono(real * bandPtr, unsigned char *samples, int *pnt) +int mpg123_synth_4to1_8bit_mono(real *bandPtr,unsigned char *samples,int *pnt) { - short samples_tmp[16]; - short *tmp1 = samples_tmp; - int i, ret; - int pnt1 = 0; + short samples_tmp[16]; + short *tmp1 = samples_tmp; + int i,ret; + int pnt1 = 0; + + ret = mpg123_synth_4to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1); + samples += *pnt; + + for(i=0;i<8;i++) { + *samples++ = mpg123_conv16to8[*tmp1>>AUSHIFT]; + tmp1 += 2; + } + *pnt += 8; + + return ret; +} - ret = mpg123_synth_4to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1); - samples += *pnt; + +int mpg123_synth_4to1_8bit_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt) +{ + short samples_tmp[16]; + short *tmp1 = samples_tmp; + int i,ret; + int pnt1 = 0; - for (i = 0; i < 8; i++) { - *samples++ = (*tmp1 >> 8) ^ 128; - tmp1 += 2; - } - *pnt += 8; + ret = mpg123_synth_4to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1); + samples += *pnt; - return ret; + for(i=0;i<8;i++) { + *samples++ = mpg123_conv16to8[*tmp1>>AUSHIFT]; + *samples++ = mpg123_conv16to8[*tmp1>>AUSHIFT]; + tmp1 += 2; + } + *pnt += 16; + + return ret; } -#if 0 -int -mpg123_synth_4to1_8bit_mono2stereo(real * bandPtr, - unsigned char *samples, int *pnt) +int mpg123_synth_4to1_mono(real *bandPtr,unsigned char *samples,int *pnt) { - short samples_tmp[16]; - short *tmp1 = samples_tmp; - int i, ret; - int pnt1 = 0; + short samples_tmp[16]; + short *tmp1 = samples_tmp; + int i,ret; + int pnt1 = 0; - ret = mpg123_synth_4to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1); - samples += *pnt; + ret = mpg123_synth_4to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1); + samples += *pnt; - for (i = 0; i < 8; i++) { - *samples++ = (*tmp1 >> 8) ^ 128; - *samples++ = (*tmp1 >> 8) ^ 128; - tmp1 += 2; - } - *pnt += 16; + for(i=0;i<8;i++) { + *( (short *)samples) = *tmp1; + samples += 2; + tmp1 += 2; + } + *pnt += 16; - return ret; + return ret; } -#endif -int -mpg123_synth_4to1_mono(real * bandPtr, unsigned char *samples, int *pnt) +int mpg123_synth_4to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt) { - short samples_tmp[16]; - short *tmp1 = samples_tmp; - int i, ret; - int pnt1 = 0; + int i,ret; - ret = mpg123_synth_4to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1); - samples += *pnt; + ret = mpg123_synth_4to1(bandPtr,0,samples,pnt); + samples = samples + *pnt - 32; - for (i = 0; i < 8; i++) { - *((short *) samples) = *tmp1; - samples += 2; - tmp1 += 2; - } - *pnt += 16; + for(i=0;i<8;i++) { + ((short *)samples)[1] = ((short *)samples)[0]; + samples+=4; + } - return ret; + return ret; } -#if 0 -int -mpg123_synth_4to1_mono2stereo(real * bandPtr, unsigned char *samples, - int *pnt) +int mpg123_synth_4to1(real *bandPtr,int channel,unsigned char *out,int *pnt) { - int i, ret; - - ret = mpg123_synth_4to1(bandPtr, 0, samples, pnt); - samples = samples + *pnt - 32; + static real buffs[2][2][0x110]; + static const int step = 2; + static int bo = 1; + short *samples = (short *) (out + *pnt); - for (i = 0; i < 8; i++) { - ((short *) samples)[1] = ((short *) samples)[0]; - samples += 4; - } + real *b0,(*buf)[0x110]; + int clip = 0; + int bo1; - return ret; -} -#endif - -int -mpg123_synth_4to1(real * bandPtr, int channel, unsigned char *out, int *pnt) -{ - static real buffs[2][2][0x110]; - static const int step = 2; - static int bo = 1; - short *samples = (short *) (out + *pnt); + if(!channel) { + bo--; + bo &= 0xf; + buf = buffs[0]; + } + else { + samples++; + buf = buffs[1]; + } - real *b0, (*buf)[0x110]; - int clip = 0; - int bo1; + if(bo & 0x1) { + b0 = buf[0]; + bo1 = bo; + mpg123_dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr); + } + else { + b0 = buf[1]; + bo1 = bo+1; + mpg123_dct64(buf[0]+bo,buf[1]+bo+1,bandPtr); + } -/* if(param.equalizer) - do_equalizer(bandPtr,channel); */ + { + register int j; + real *window = mpg123_decwin + 16 - bo1; - if (!channel) { - bo--; - bo &= 0xf; - buf = buffs[0]; - } - else { - samples++; - buf = buffs[1]; - } + for (j=4;j;j--,b0+=0x30,window+=0x70) + { + real sum; + sum = *window++ * *b0++; + sum -= *window++ * *b0++; + sum += *window++ * *b0++; + sum -= *window++ * *b0++; + sum += *window++ * *b0++; + sum -= *window++ * *b0++; + sum += *window++ * *b0++; + sum -= *window++ * *b0++; + sum += *window++ * *b0++; + sum -= *window++ * *b0++; + sum += *window++ * *b0++; + sum -= *window++ * *b0++; + sum += *window++ * *b0++; + sum -= *window++ * *b0++; + sum += *window++ * *b0++; + sum -= *window++ * *b0++; - if (bo & 0x1) { - b0 = buf[0]; - bo1 = bo; - mpg123_dct64(buf[1] + ((bo + 1) & 0xf), buf[0] + bo, bandPtr); - } - else { - b0 = buf[1]; - bo1 = bo + 1; - mpg123_dct64(buf[0] + bo, buf[1] + bo + 1, bandPtr); + WRITE_SAMPLE(samples,sum,clip); samples += step; +#if 0 + WRITE_SAMPLE(samples,sum,clip); samples += step; + WRITE_SAMPLE(samples,sum,clip); samples += step; + WRITE_SAMPLE(samples,sum,clip); samples += step; +#endif } { - register int j; - real *window = mpg123_decwin + 16 - bo1; - - for (j = 4; j; j--, b0 += 0x30, window += 0x70) { - real sum; - - sum = *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - sum += *window++ * *b0++; - sum -= *window++ * *b0++; - - WRITE_SAMPLE(samples, sum, clip); - samples += step; -#if 0 - WRITE_SAMPLE(samples, sum, clip); - samples += step; - WRITE_SAMPLE(samples, sum, clip); - samples += step; - WRITE_SAMPLE(samples, sum, clip); - samples += step; -#endif - } - - { - 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); - samples += step; + 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); samples += step; #if 0 - WRITE_SAMPLE(samples, sum, clip); - samples += step; - WRITE_SAMPLE(samples, sum, clip); - samples += step; - WRITE_SAMPLE(samples, sum, clip); - samples += step; + WRITE_SAMPLE(samples,sum,clip); samples += step; + WRITE_SAMPLE(samples,sum,clip); samples += step; + WRITE_SAMPLE(samples,sum,clip); samples += step; #endif - b0 -= 0x40, window -= 0x80; - } - window += bo1 << 1; - - for (j = 3; j; j--, b0 -= 0x50, window -= 0x70) { - real sum; + b0-=0x40,window-=0x80; + } + window += bo1<<1; - sum = -*(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; - sum -= *(--window) * *b0++; + for (j=3;j;j--,b0-=0x50,window-=0x70) + { + real sum; + sum = -*(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; + sum -= *(--window) * *b0++; - WRITE_SAMPLE(samples, sum, clip); - samples += step; + WRITE_SAMPLE(samples,sum,clip); samples += step; #if 0 - WRITE_SAMPLE(samples, sum, clip); - samples += step; - WRITE_SAMPLE(samples, sum, clip); - samples += step; - WRITE_SAMPLE(samples, sum, clip); - samples += step; + WRITE_SAMPLE(samples,sum,clip); samples += step; + WRITE_SAMPLE(samples,sum,clip); samples += step; + WRITE_SAMPLE(samples,sum,clip); samples += step; #endif - } } + } + + *pnt += 32; - *pnt += 32; + return clip; +} - return clip; -} +
--- a/Plugins/Input/mpg123/decode_MMX.s Tue Nov 08 12:04:15 2005 -0800 +++ b/Plugins/Input/mpg123/decode_MMX.s Wed Nov 09 16:40:03 2005 -0800 @@ -2,9 +2,9 @@ .text -.globl mpg123_synth_MMX +.globl synth_1to1_MMX -mpg123_synth_MMX: +synth_1to1_MMX: pushl %ebp pushl %edi pushl %esi @@ -38,7 +38,7 @@ .L2: pushl %edx pushl %ecx - call dct64_MMX + call mpg123_dct64_MMX addl $12,%esp leal 1(%ebx), %ecx subl %ebp,%ebx
--- a/Plugins/Input/mpg123/decode_i386.c Tue Nov 08 12:04:15 2005 -0800 +++ b/Plugins/Input/mpg123/decode_i386.c Wed Nov 09 16:40:03 2005 -0800 @@ -1,4 +1,3 @@ - /* * Mpeg Layer-1,2,3 audio decoder * ------------------------------ @@ -17,8 +16,6 @@ #include "mpg123.h" -int mpg123_synth_1to1_pent(real *, int, unsigned char *); - #if 0 /* old WRITE_SAMPLE */ #define WRITE_SAMPLE(samples,sum,clip) \ @@ -37,241 +34,219 @@ } #endif -int -mpg123_synth_1to1_8bit(real * bandPtr, int channel, - unsigned char *samples, int *pnt) +int mpg123_synth_1to1_8bit(real *bandPtr,int channel,unsigned char *samples,int *pnt) { - short samples_tmp[64]; - short *tmp1 = samples_tmp + channel; - int i, ret; - int pnt1 = 0; + short samples_tmp[64]; + short *tmp1 = samples_tmp + channel; + int i,ret; + int pnt1 = 0; + + ret = mpg123_synth_1to1(bandPtr,channel,(unsigned char *)samples_tmp,&pnt1); + samples += channel + *pnt; + + for(i=0;i<32;i++) { + *samples = mpg123_conv16to8[*tmp1>>AUSHIFT]; + samples += 2; + tmp1 += 2; + } + *pnt += 64; - ret = - mpg123_synth_1to1(bandPtr, channel, (unsigned char *) samples_tmp, - &pnt1); - samples += channel + *pnt; + return ret; +} + +int mpg123_synth_1to1_8bit_mono(real *bandPtr,unsigned char *samples,int *pnt) +{ + short samples_tmp[64]; + short *tmp1 = samples_tmp; + int i,ret; + int pnt1 = 0; - for (i = 0; i < 32; i++) { - *samples = (*tmp1 >> 8) ^ 128; - samples += 2; - tmp1 += 2; - } - *pnt += 64; + ret = mpg123_synth_1to1(bandPtr,0,(unsigned char *)samples_tmp,&pnt1); + samples += *pnt; - return ret; + for(i=0;i<32;i++) { + *samples++ = mpg123_conv16to8[*tmp1>>AUSHIFT]; + tmp1+=2; + } + *pnt += 32; + + return ret; } -int -mpg123_synth_1to1_8bit_mono(real * bandPtr, unsigned char *samples, int *pnt) +int mpg123_synth_1to1_8bit_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt) { - short samples_tmp[64]; - short *tmp1 = samples_tmp; - int i, ret; - int pnt1 = 0; + short samples_tmp[64]; + short *tmp1 = samples_tmp; + int i,ret; + int pnt1 = 0; - ret = mpg123_synth_1to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1); - samples += *pnt; + ret = mpg123_synth_1to1(bandPtr,0,(unsigned char *)samples_tmp,&pnt1); + samples += *pnt; - for (i = 0; i < 32; i++) { - *samples++ = (*tmp1 >> 8) ^ 128; - tmp1 += 2; - } - *pnt += 32; + for(i=0;i<32;i++) { + *samples++ = mpg123_conv16to8[*tmp1>>AUSHIFT]; + *samples++ = mpg123_conv16to8[*tmp1>>AUSHIFT]; + tmp1 += 2; + } + *pnt += 64; - return ret; + return ret; } -#if 0 -int -mpg123_synth_1to1_8bit_mono2stereo(real * bandPtr, - unsigned char *samples, int *pnt) +int mpg123_synth_1to1_mono(real *bandPtr,unsigned char *samples,int *pnt) { - short samples_tmp[64]; - short *tmp1 = samples_tmp; - int i, ret; - int pnt1 = 0; + short samples_tmp[64]; + short *tmp1 = samples_tmp; + int i,ret; + int pnt1 = 0; + + ret = mpg123_synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1); + samples += *pnt; + + for(i=0;i<32;i++) { + *( (short *) samples) = *tmp1; + samples += 2; + tmp1 += 2; + } + *pnt += 64; + + return ret; +} + - ret = mpg123_synth_1to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1); - samples += *pnt; +int mpg123_synth_1to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt) +{ + int i,ret; + + ret = mpg123_synth_1to1(bandPtr,0,samples,pnt); + samples = samples + *pnt - 128; + + for(i=0;i<32;i++) { + ((short *)samples)[1] = ((short *)samples)[0]; + samples+=4; + } - for (i = 0; i < 32; i++) { - *samples++ = (*tmp1 >> 8) ^ 128; - *samples++ = (*tmp1 >> 8) ^ 128; - tmp1 += 2; - } - *pnt += 64; + return ret; +} - return ret; -} +int mpg123_synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt) +{ +#ifndef PENTIUM_OPT + static real buffs[2][2][0x110]; + static const int step = 2; + static int bo = 1; + short *samples = (short *) (out + *pnt); + + real *b0,(*buf)[0x110]; + int clip = 0; + int bo1; #endif -int -mpg123_synth_1to1_mono(real * bandPtr, unsigned char *samples, int *pnt) -{ - short samples_tmp[64]; - short *tmp1 = samples_tmp; - int i, ret; - int pnt1 = 0; - - ret = mpg123_synth_1to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1); - samples += *pnt; - - for (i = 0; i < 32; i++) { - *((short *) samples) = *tmp1; - samples += 2; - tmp1 += 2; - } - *pnt += 64; - - return ret; -} - -#if 0 -int -mpg123_synth_1to1_mono2stereo(real * bandPtr, unsigned char *samples, - int *pnt) -{ - int i, ret; - - ret = mpg123_synth_1to1(bandPtr, 0, samples, pnt); - samples = samples + *pnt - 128; - - for (i = 0; i < 32; i++) { - ((short *) samples)[1] = ((short *) samples)[0]; - samples += 4; - } +#ifndef PENTIUM_OPT + if(!channel) { + bo--; + bo &= 0xf; + buf = buffs[0]; + } + else { + samples++; + buf = buffs[1]; + } - return ret; -} -#endif - -int -mpg123_synth_1to1(real * bandPtr, int channel, unsigned char *out, int *pnt) -{ -#ifndef I386_ASSEM - static real buffs[2][2][0x110]; - static const int step = 2; - static int bo = 1; - short *samples = (short *) (out + *pnt); - - real *b0, (*buf)[0x110]; - int clip = 0; - int bo1; + if(bo & 0x1) { + b0 = buf[0]; + bo1 = bo; + mpg123_dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr); + } + else { + b0 = buf[1]; + bo1 = bo+1; + mpg123_dct64(buf[0]+bo,buf[1]+bo+1,bandPtr); + } + + { + register int j; + real *window = mpg123_decwin + 16 - bo1; - if (!channel) { - bo--; - bo &= 0xf; - buf = buffs[0]; - } - else { - samples++; - buf = buffs[1]; - } + 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]; - if (bo & 0x1) { - b0 = buf[0]; - bo1 = bo; - mpg123_dct64(buf[1] + ((bo + 1) & 0xf), buf[0] + bo, bandPtr); - } - else { - b0 = buf[1]; - bo1 = bo + 1; - mpg123_dct64(buf[0] + bo, buf[1] + bo + 1, bandPtr); + WRITE_SAMPLE(samples,sum,clip); } { - register int j; - real *window = mpg123_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; + 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]; + 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); - } + WRITE_SAMPLE(samples,sum,clip); } - *pnt += 128; - - return clip; -#else - { - int ret; + } + *pnt += 128; - ret = mpg123_synth_1to1_pent(bandPtr, channel, out + *pnt); - *pnt += 128; - return ret; - } -#endif -} - -#ifdef USE_SIMD -int mpg123_synth_MMX(real *, int, short *, short *, int *); - -int -mpg123_synth_1to1_mmx(real * bandPtr, int channel, unsigned char *out, - int *pnt) -{ + return clip; +#elif defined(USE_MMX) + { static short buffs[2][2][0x110]; static int bo = 1; short *samples = (short *) (out + *pnt); - - mpg123_synth_MMX(bandPtr, channel, samples, (short *) buffs, &bo); + mpg123_synth_1to1_MMX(bandPtr, channel, samples, (short *) buffs, &bo); *pnt += 128; return 0; + } +#else + { + int ret; + ret = mpg123_synth_1to1_pent(bandPtr,channel,out+*pnt); + *pnt += 128; + return ret; + } +#endif } -#endif
--- a/Plugins/Input/mpg123/decode_i586.s Tue Nov 08 12:04:15 2005 -0800 +++ b/Plugins/Input/mpg123/decode_i586.s Wed Nov 09 16:40:03 2005 -0800 @@ -1,28 +1,30 @@ -/ -/ mpg123_synth_1to1 works the same way as the c version of this -/ file. only two types of changes have been made: -/ - reordered floating point instructions to -/ prevent pipline stalls -/ - made WRITE_SAMPLE use integer instead of -/ (slower) floating point -/ all kinds of x86 processors should benefit from these -/ modifications. -/ -/ useful sources of information on optimizing x86 code include: -/ -/ Intel Architecture Optimization Manual -/ http://www.intel.com/design/pentium/manuals/242816.htm -/ -/ Cyrix 6x86 Instruction Set Summary -/ ftp://ftp.cyrix.com/6x86/6x-dbch6.pdf -/ -/ AMD-K5 Processor Software Development -/ http://www.amd.com/products/cpg/techdocs/appnotes/20007e.pdf -/ -/ Stefan Bieschewski <stb@acm.org> -/ -/ $Id: decode_i586.s,v 1.1.1.1 2003/11/19 16:03:18 mderezynski Exp $ -/ +# +# synth_1to1 works the same way as the c version of this +# file. only two types of changes have been made: +# - reordered floating point instructions to +# prevent pipline stalls +# - made WRITE_SAMPLE use integer instead of +# (slower) floating point +# all kinds of x86 processors should benefit from these +# modifications. +# +# useful sources of information on optimizing x86 code include: +# +# Intel Architecture Optimization Manual +# http:#/www.intel.com/design/pentium/manuals/242816.htm +# +# Cyrix 6x86 Instruction Set Summary +# ftp:#/ftp.cyrix.com/6x86/6x-dbch6.pdf +# +# AMD-K5 Processor Software Development +# http:#/www.amd.com/products/cpg/techdocs/appnotes/20007e.pdf +# +# Stefan Bieschewski <stb@acm.org> +# +# You can use this part under GPL. +# +# $Id: decode_i586.s,v 1.3 2000/10/25 11:05:23 hippm Exp $ +# .bss .comm buffs,4352,4 .data
--- a/Plugins/Input/mpg123/getbits.c Tue Nov 08 12:04:15 2005 -0800 +++ b/Plugins/Input/mpg123/getbits.c Wed Nov 09 16:40:03 2005 -0800 @@ -1,132 +1,116 @@ #include "mpg123.h" - -#if 0 -static void -check_buffer_range(int size) -{ - int pos = (bsi.wordpointer - bsbuf) + (size >> 3); +#include "common.h" - if (pos >= fsizeold) { - fprintf(stderr, "Pointer out of range (%d,%d)!\n", pos, fsizeold); - } -} -#endif - -void -mpg123_backbits(int number_of_bits) +void mpg123_backbits(struct bitstream_info *bitbuf,int number_of_bits) { - bsi.bitindex -= number_of_bits; - bsi.wordpointer += (bsi.bitindex >> 3); - bsi.bitindex &= 0x7; + bitbuf->bitindex -= number_of_bits; + bitbuf->wordpointer += (bitbuf->bitindex>>3); + bitbuf->bitindex &= 0x7; } -int -mpg123_getbitoffset(void) +int mpg123_getbitoffset(struct bitstream_info *bitbuf) { - return (-bsi.bitindex) & 0x7; + return (-bitbuf->bitindex)&0x7; } -int -mpg123_getbyte(void) +int mpg123_getbyte(struct bitstream_info *bitbuf) { #ifdef DEBUG_GETBITS - if (bsi.bitindex) - fprintf(stderr, "getbyte called unsynched!\n"); + if(bitbuf->bitindex) + fprintf(stderr,"getbyte called unsynched!\n"); #endif - return *bsi.wordpointer++; + return *bitbuf->wordpointer++; } -unsigned int -mpg123_getbits(int number_of_bits) +unsigned int mpg123_getbits(struct bitstream_info *bitbuf,int number_of_bits) { - unsigned long rval; + unsigned long rval; #ifdef DEBUG_GETBITS - fprintf(stderr, "g%d", number_of_bits); +fprintf(stderr,"g%d",number_of_bits); #endif - if (!number_of_bits) - return 0; + if(!number_of_bits) + return 0; #if 0 - check_buffer_range(number_of_bits + bsi.bitindex); + check_buffer_range(number_of_bits+bitbuf->bitindex); #endif - { - rval = bsi.wordpointer[0]; - rval <<= 8; - rval |= bsi.wordpointer[1]; - rval <<= 8; - rval |= bsi.wordpointer[2]; + { + rval = bitbuf->wordpointer[0]; + rval <<= 8; + rval |= bitbuf->wordpointer[1]; + rval <<= 8; + rval |= bitbuf->wordpointer[2]; - rval <<= bsi.bitindex; - rval &= 0xffffff; + rval <<= bitbuf->bitindex; + rval &= 0xffffff; - bsi.bitindex += number_of_bits; + bitbuf->bitindex += number_of_bits; - rval >>= (24 - number_of_bits); + rval >>= (24-number_of_bits); - bsi.wordpointer += (bsi.bitindex >> 3); - bsi.bitindex &= 7; - } + bitbuf->wordpointer += (bitbuf->bitindex>>3); + bitbuf->bitindex &= 7; + } #ifdef DEBUG_GETBITS - fprintf(stderr, ":%x ", rval); +fprintf(stderr,":%x ",rval); #endif - return rval; + return rval; } -unsigned int -mpg123_getbits_fast(int number_of_bits) +unsigned int mpg123_getbits_fast(struct bitstream_info *bitbuf,int number_of_bits) { - unsigned int rval; + unsigned int rval; #ifdef DEBUG_GETBITS - fprintf(stderr, "g%d", number_of_bits); +fprintf(stderr,"g%d",number_of_bits); #endif #if 0 - check_buffer_range(number_of_bits + bsi.bitindex); + check_buffer_range(number_of_bits+bitbuf->bitindex); #endif - rval = (unsigned char) (bsi.wordpointer[0] << bsi.bitindex); - rval |= ((unsigned int) bsi.wordpointer[1] << bsi.bitindex) >> 8; - rval <<= number_of_bits; - rval >>= 8; + rval = (unsigned char) (bitbuf->wordpointer[0] << bitbuf->bitindex); + rval |= ((unsigned int) bitbuf->wordpointer[1]<<bitbuf->bitindex)>>8; + rval <<= number_of_bits; + rval >>= 8; - bsi.bitindex += number_of_bits; + bitbuf->bitindex += number_of_bits; - bsi.wordpointer += (bsi.bitindex >> 3); - bsi.bitindex &= 7; + bitbuf->wordpointer += (bitbuf->bitindex>>3); + bitbuf->bitindex &= 7; #ifdef DEBUG_GETBITS - fprintf(stderr, ":%x ", rval); +fprintf(stderr,":%x ",rval); #endif - return rval; + return rval; } -unsigned int -mpg123_get1bit(void) +unsigned int mpg123_get1bit(struct bitstream_info *bitbuf) { - unsigned char rval; + unsigned char rval; #ifdef DEBUG_GETBITS - fprintf(stderr, "g%d", 1); +fprintf(stderr,"g%d",1); #endif #if 0 - check_buffer_range(1 + bsi.bitindex); + check_buffer_range(1+bitbuf->bitindex); #endif - rval = *bsi.wordpointer << bsi.bitindex; + rval = *(bitbuf->wordpointer) << bitbuf->bitindex; - bsi.bitindex++; - bsi.wordpointer += (bsi.bitindex >> 3); - bsi.bitindex &= 7; + bitbuf->bitindex++; + bitbuf->wordpointer += (bitbuf->bitindex>>3); + bitbuf->bitindex &= 7; #ifdef DEBUG_GETBITS - fprintf(stderr, ":%d ", rval >> 7); +fprintf(stderr,":%d ",rval>>7); #endif - return rval >> 7; + return rval>>7; } +
--- a/Plugins/Input/mpg123/getbits.h Tue Nov 08 12:04:15 2005 -0800 +++ b/Plugins/Input/mpg123/getbits.h Wed Nov 09 16:40:03 2005 -0800 @@ -1,46 +1,33 @@ -/* - * This does the same as getbits.c but with defines to - * force inlining - */ +/* that's the same file as getits.c but with defines to + force inlining */ + +unsigned long rval; +unsigned char rval_uc; -#define mpg123_backbits(nob) \ -do { \ - bsi.bitindex -= nob; \ - bsi.wordpointer += (bsi.bitindex >> 3); \ - bsi.bitindex &= 0x7; \ -} while (0) +#define mpg123_backbits(bitbuf,nob) ((void)( \ + (*(bitbuf)).bitindex -= (nob), \ + (*(bitbuf)).wordpointer += ((*(bitbuf)).bitindex>>3), \ + (*(bitbuf)).bitindex &= 0x7 )) -#define mpg123_getbitoffset() ((-bsi.bitindex) & 0x7) -#define mpg123_getbyte() (*bsi.wordpointer++) +#define mpg123_getbitoffset(bitbuf) ((-(*(bitbuf)).bitindex)&0x7) +#define mpg123_getbyte(bitbuf) (*(*(bitbuf)).wordpointer++) -#define mpg123_getbits(nob) \ - (rval = bsi.wordpointer[0], \ - rval <<= 8, \ - rval |= bsi.wordpointer[1], \ - rval <<= 8, \ - rval |= bsi.wordpointer[2], \ - rval <<= bsi.bitindex, \ - rval &= 0xffffff, \ - bsi.bitindex += (nob), \ - rval >>= (24-(nob)), \ - bsi.wordpointer += (bsi.bitindex>>3), \ - bsi.bitindex &= 7, \ - rval) +#define mpg123_getbits(bitbuf,nob) ( \ + rval = (*(bitbuf)).wordpointer[0], rval <<= 8, rval |= (*(bitbuf)).wordpointer[1], \ + rval <<= 8, rval |= (*(bitbuf)).wordpointer[2], rval <<= (*(bitbuf)).bitindex, \ + rval &= 0xffffff, (*(bitbuf)).bitindex += (nob), \ + rval >>= (24-(nob)), (*(bitbuf)).wordpointer += ((*(bitbuf)).bitindex>>3), \ + (*(bitbuf)).bitindex &= 7,rval) -#define mpg123_getbits_fast(nob) \ - (rval = (unsigned char) (bsi.wordpointer[0] << bsi.bitindex), \ - rval |= ((unsigned long) bsi.wordpointer[1] << bsi.bitindex) >> 8, \ - rval <<= (nob), \ - rval >>= 8, \ - bsi.bitindex += (nob), \ - bsi.wordpointer += (bsi.bitindex >> 3), \ - bsi.bitindex &= 7, \ - rval) +#define mpg123_getbits_fast(bitbuf,nob) ( \ + rval = (unsigned char) ((*(bitbuf)).wordpointer[0] << (*(bitbuf)).bitindex), \ + rval |= ((unsigned long) (*(bitbuf)).wordpointer[1]<<(*(bitbuf)).bitindex)>>8, \ + rval <<= (nob), rval >>= 8, \ + (*(bitbuf)).bitindex += (nob), (*(bitbuf)).wordpointer += ((*(bitbuf)).bitindex>>3), \ + (*(bitbuf)).bitindex &= 7, rval ) -#define mpg123_get1bit() \ - (rval_uc = *bsi.wordpointer << bsi.bitindex, \ - bsi.bitindex++, \ - bsi.wordpointer += (bsi.bitindex>>3), \ - bsi.bitindex &= 7, \ - rval_uc >> 7) +#define mpg123_get1bit(bitbuf) ( \ + rval_uc = *(*(bitbuf)).wordpointer << (*(bitbuf)).bitindex, (*(bitbuf)).bitindex++, \ + (*(bitbuf)).wordpointer += ((*(bitbuf)).bitindex>>3), (*(bitbuf)).bitindex &= 7, rval_uc>>7 ) +
--- a/Plugins/Input/mpg123/layer1.c Tue Nov 08 12:04:15 2005 -0800 +++ b/Plugins/Input/mpg123/layer1.c Wed Nov 09 16:40:03 2005 -0800 @@ -1,141 +1,120 @@ - -/* - * Mpeg Layer-1 audio decoder +/* + * Mpeg Layer-1 audio decoder * -------------------------- * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README' * near unoptimzed ... * - * may have a few bugs after last optimization ... + * may have a few bugs after last optimization ... * */ - #include "audacious/output.h" #include "mpg123.h" #include "getbits.h" - -/* Used by the getbits macros */ -static unsigned long rval; - -void -I_step_one(unsigned int balloc[], - 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) { - unsigned int *ba = balloc; - unsigned int *sca = (unsigned int *) scale_index; + unsigned int *ba=balloc; + unsigned int *sca = (unsigned int *) scale_index; - if (fr->stereo) { - int i; - int jsbound = fr->jsbound; + if(fr->stereo) { + int i; + int jsbound = fr->jsbound; + for (i=0;i<jsbound;i++) { + *ba++ = mpg123_getbits(&bsi,4); + *ba++ = mpg123_getbits(&bsi,4); + } + for (i=jsbound;i<SBLIMIT;i++) + *ba++ = mpg123_getbits(&bsi,4); - for (i = 0; i < jsbound; i++) { - *ba++ = mpg123_getbits(4); - *ba++ = mpg123_getbits(4); - } - for (i = jsbound; i < SBLIMIT; i++) - *ba++ = mpg123_getbits(4); + ba = balloc; - ba = balloc; - - for (i = 0; i < jsbound; i++) { - if ((*ba++)) - *sca++ = mpg123_getbits(6); - if ((*ba++)) - *sca++ = mpg123_getbits(6); - } - for (i = jsbound; i < SBLIMIT; i++) - if ((*ba++)) { - *sca++ = mpg123_getbits(6); - *sca++ = mpg123_getbits(6); - } + for (i=0;i<jsbound;i++) { + if ((*ba++)) + *sca++ = mpg123_getbits(&bsi,6); + if ((*ba++)) + *sca++ = mpg123_getbits(&bsi,6); } - else { - int i; - - for (i = 0; i < SBLIMIT; i++) - *ba++ = mpg123_getbits(4); - ba = balloc; - for (i = 0; i < SBLIMIT; i++) - if ((*ba++)) - *sca++ = mpg123_getbits(6); - } + for (i=jsbound;i<SBLIMIT;i++) + if ((*ba++)) { + *sca++ = mpg123_getbits(&bsi,6); + *sca++ = mpg123_getbits(&bsi,6); + } + } + else { + int i; + for (i=0;i<SBLIMIT;i++) + *ba++ = mpg123_getbits(&bsi,4); + ba = balloc; + for (i=0;i<SBLIMIT;i++) + if ((*ba++)) + *sca++ = mpg123_getbits(&bsi,6); + } } -void -I_step_two(real fraction[2][SBLIMIT], - unsigned int balloc[2 * SBLIMIT], - unsigned int scale_index[2][SBLIMIT], struct frame *fr) +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; + int i,n; + int smpb[2*SBLIMIT]; /* values: 0-65535 */ + int *sample; + register unsigned int *ba; + register unsigned int *sca = (unsigned int *) scale_index; - if (fr->stereo) { - 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++ = mpg123_getbits(n + 1); - if ((n = *ba++)) - *sample++ = mpg123_getbits(n + 1); - } - for (i = jsbound; i < SBLIMIT; i++) - if ((n = *ba++)) - *sample++ = mpg123_getbits(n + 1); + if(fr->stereo) { + 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++ = mpg123_getbits(&bsi,n+1); + if ((n = *ba++)) + *sample++ = mpg123_getbits(&bsi,n+1); + } + for (i=jsbound;i<SBLIMIT;i++) + if ((n = *ba++)) + *sample++ = mpg123_getbits(&bsi,n+1); - ba = balloc; - for (sample = smpb, i = 0; i < jsbound; i++) { - if ((n = *ba++)) - *f0++ = - (real) (((-1) << n) + (*sample++) + - 1) * mpg123_muls[n + 1][*sca++]; - else - *f0++ = 0.0; - if ((n = *ba++)) - *f1++ = - (real) (((-1) << n) + (*sample++) + - 1) * mpg123_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 * mpg123_muls[n + 1][*sca++]; - *f1++ = samp * mpg123_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; + ba = balloc; + for (sample=smpb,i=0;i<jsbound;i++) { + if((n=*ba++)) + *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * mpg123_muls[n+1][*sca++]; + else + *f0++ = 0.0; + if((n=*ba++)) + *f1++ = (real) ( ((-1)<<n) + (*sample++) + 1) * mpg123_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 * mpg123_muls[n+1][*sca++]; + *f1++ = samp * mpg123_muls[n+1][*sca++]; + } + else + *f0++ = *f1++ = 0.0; } - else { - register real *f0 = fraction[0]; - - ba = balloc; - for (sample = smpb, i = 0; i < SBLIMIT; i++) - if ((n = *ba++)) - *sample++ = mpg123_getbits(n + 1); - ba = balloc; - for (sample = smpb, i = 0; i < SBLIMIT; i++) { - if ((n = *ba++)) - *f0++ = - (real) (((-1) << n) + (*sample++) + - 1) * mpg123_muls[n + 1][*sca++]; - else - *f0++ = 0.0; - } - for (i = fr->down_sample_sblimit; i < 32; i++) - fraction[0][i] = 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++ = mpg123_getbits(&bsi,n+1); + ba = balloc; + for (sample=smpb,i=0;i<SBLIMIT;i++) { + if((n=*ba++)) + *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * mpg123_muls[n+1][*sca++]; + else + *f0++ = 0.0; } + for(i=fr->down_sample_sblimit;i<32;i++) + fraction[0][i] = 0.0; + } } int
--- a/Plugins/Input/mpg123/layer2.c Tue Nov 08 12:04:15 2005 -0800 +++ b/Plugins/Input/mpg123/layer2.c Wed Nov 09 16:40:03 2005 -0800 @@ -1,291 +1,260 @@ - -/* - * Mpeg Layer-2 audio decoder +/* + * Mpeg Layer-2 audio decoder * -------------------------- * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README' * */ -#include <glib.h> #include <math.h> - #include "audacious/output.h" #include "mpg123.h" #include "l2tables.h" #include "getbits.h" - static int grp_3tab[32 * 3] = { 0, }; /* used: 27 */ static int grp_5tab[128 * 3] = { 0, }; /* used: 125 */ static int grp_9tab[1024 * 3] = { 0, }; /* used: 729 */ -real mpg123_muls[27][64]; /* also used by layer 1 */ +real mpg123_muls[27][64]; /* also used by layer 1 */ -/* Used by the getbits macros */ -static unsigned long rval; - -void -mpg123_init_layer2(gboolean mmx) +void mpg123_init_layer2(gboolean mmx) { - static double mulmul[27] = { - 0.0, -2.0 / 3.0, 2.0 / 3.0, 2.0 / 7.0, 2.0 / 15.0, - 2.0 / 31.0, 2.0 / 63.0, 2.0 / 127.0, 2.0 / 255.0, - 2.0 / 511.0, 2.0 / 1023.0, 2.0 / 2047.0, 2.0 / 4095.0, - 2.0 / 8191.0, 2.0 / 16383.0, 2.0 / 32767.0, 2.0 / 65535.0, - -4.0 / 5.0, -2.0 / 5.0, 2.0 / 5.0, 4.0 / 5.0, -8.0 / 9.0, - -4.0 / 9.0, -2.0 / 9.0, 2.0 / 9.0, 4.0 / 9.0, 8.0 / 9.0 - }; - static int base[3][9] = { - {1, 0, 2,}, - {17, 18, 0, 19, 20,}, - {21, 1, 22, 23, 0, 24, 25, 2, 26} - }; - int i, j, k, l, len; - real *table; - static int tablen[3] = { 3, 5, 9 }; - static int *itable, *tables[3] = { grp_3tab, grp_5tab, grp_9tab }; + static double mulmul[27] = { + 0.0 , -2.0/3.0 , 2.0/3.0 , + 2.0/7.0 , 2.0/15.0 , 2.0/31.0, 2.0/63.0 , 2.0/127.0 , 2.0/255.0 , + 2.0/511.0 , 2.0/1023.0 , 2.0/2047.0 , 2.0/4095.0 , 2.0/8191.0 , + 2.0/16383.0 , 2.0/32767.0 , 2.0/65535.0 , + -4.0/5.0 , -2.0/5.0 , 2.0/5.0, 4.0/5.0 , + -8.0/9.0 , -4.0/9.0 , -2.0/9.0 , 2.0/9.0 , 4.0/9.0 , 8.0/9.0 }; + static int base[3][9] = { + { 1 , 0, 2 , } , + { 17, 18, 0 , 19, 20 , } , + { 21, 1, 22, 23, 0, 24, 25, 2, 26 } }; + int i,j,k,l,len; + real *table; + static int tablen[3] = { 3 , 5 , 9 }; + static int *itable,*tables[3] = { grp_3tab , grp_5tab , grp_9tab }; +#ifdef REAL_IS_FIXED + const double twotothethird = pow((double)2.0, (double)1/3); +#endif - for (i = 0; i < 3; i++) { - itable = tables[i]; - len = tablen[i]; - for (j = 0; j < len; j++) - for (k = 0; k < len; k++) - for (l = 0; l < len; l++) { - *itable++ = base[i][l]; - *itable++ = base[i][k]; - *itable++ = base[i][j]; - } - } + for(i=0;i<3;i++) + { + itable = tables[i]; + len = tablen[i]; + for(j=0;j<len;j++) + for(k=0;k<len;k++) + for(l=0;l<len;l++) + { + *itable++ = base[i][l]; + *itable++ = base[i][k]; + *itable++ = base[i][j]; + } + } - for (k = 0; k < 27; k++) { - double m = mulmul[k]; - table = mpg123_muls[k]; + for(k=0;k<27;k++) + { + double m=mulmul[k]; + + table = mpg123_muls[k]; #ifdef USE_SIMD - if (mmx) - for (j = 3, i = 0; i < 63; i++, j--) - *table++ = 16384 * m * pow(2.0, (double) j / 3.0); - else + if(mmx) + for(j=3,i=0;i<63;i++,j--) + *table++ = 16384 * m * pow(2.0,(double) j / 3.0); + else #endif - for (j = 3, i = 0; i < 63; i++, j--) - *table++ = m * pow(2.0, (double) j / 3.0); - *table++ = 0.0; - } + for(j=3,i=0;i<63;i++,j--) + *table = m * pow(2.0, (double) j / 3.0); + *table++ = 0.0; + } } -void -II_step_one(unsigned int *bit_alloc, int *scale, struct frame *fr) + +void II_step_one(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 jsbound = fr->jsbound; - int sblimit2 = fr->II_sblimit << stereo; + int sblimit2 = fr->II_sblimit<<stereo; struct al_table *alloc1 = fr->alloc; int i; static unsigned int scfsi_buf[64]; - unsigned int *scfsi, *bita; - int sc, step; + unsigned int *scfsi,*bita; + int sc,step; bita = bit_alloc; - if (stereo) { - for (i = jsbound; i > 0; i--, alloc1 += (1 << step)) { - *bita++ = (char) mpg123_getbits(step = alloc1->bits); - *bita++ = (char) mpg123_getbits(step); - } - for (i = sblimit - jsbound; i > 0; i--, alloc1 += (1 << step)) { - bita[0] = (char) mpg123_getbits(step = alloc1->bits); - bita[1] = bita[0]; - bita += 2; - } - bita = bit_alloc; - scfsi = scfsi_buf; - for (i = sblimit2; i; i--) - if (*bita++) - *scfsi++ = (char) mpg123_getbits_fast(2); + if(stereo) + { + for (i=jsbound;i;i--,alloc1+=(1<<step)) + { + *bita++ = (char) mpg123_getbits(&bsi,step=alloc1->bits); + *bita++ = (char) mpg123_getbits(&bsi,step); + } + for (i=sblimit-jsbound;i;i--,alloc1+=(1<<step)) + { + bita[0] = (char) mpg123_getbits(&bsi,step=alloc1->bits); + bita[1] = bita[0]; + bita+=2; + } + bita = bit_alloc; + scfsi=scfsi_buf; + for (i=sblimit2;i;i--) + if (*bita++) + *scfsi++ = (char) mpg123_getbits_fast(&bsi,2); } - else - /* mono */ + else /* mono */ { - for (i = sblimit; i; i--, alloc1 += (1 << step)) - *bita++ = (char) mpg123_getbits(step = alloc1->bits); - bita = bit_alloc; - scfsi = scfsi_buf; - for (i = sblimit; i; i--) - if (*bita++) - *scfsi++ = (char) mpg123_getbits_fast(2); + for (i=sblimit;i;i--,alloc1+=(1<<step)) + *bita++ = (char) mpg123_getbits(&bsi,step=alloc1->bits); + bita = bit_alloc; + scfsi=scfsi_buf; + for (i=sblimit;i;i--) + if (*bita++) + *scfsi++ = (char) mpg123_getbits_fast(&bsi,2); } bita = bit_alloc; - scfsi = scfsi_buf; - for (i = sblimit2; i; i--) - if (*bita++) - switch (*scfsi++) { - case 0: - *scale++ = mpg123_getbits_fast(6); - *scale++ = mpg123_getbits_fast(6); - *scale++ = mpg123_getbits_fast(6); + scfsi=scfsi_buf; + for (i=sblimit2;i;i--) + if (*bita++) + switch (*scfsi++) + { + case 0: + *scale++ = mpg123_getbits_fast(&bsi,6); + *scale++ = mpg123_getbits_fast(&bsi,6); + *scale++ = mpg123_getbits_fast(&bsi,6); break; - case 1: - *scale++ = sc = mpg123_getbits_fast(6); + case 1 : + *scale++ = sc = mpg123_getbits_fast(&bsi,6); *scale++ = sc; - *scale++ = mpg123_getbits_fast(6); + *scale++ = mpg123_getbits_fast(&bsi,6); break; - case 2: - *scale++ = sc = mpg123_getbits_fast(6); + case 2: + *scale++ = sc = mpg123_getbits_fast(&bsi,6); *scale++ = sc; *scale++ = sc; break; - default: /* case 3 */ - *scale++ = mpg123_getbits_fast(6); - *scale++ = sc = mpg123_getbits_fast(6); + default: /* case 3 */ + *scale++ = mpg123_getbits_fast(&bsi,6); + *scale++ = sc = mpg123_getbits_fast(&bsi,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(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 sblimit = fr->II_sblimit; int jsbound = fr->jsbound; - struct al_table *alloc2, *alloc1 = fr->alloc; - unsigned int *bita = bit_alloc; - int d1, step; - - for (i = 0; i < jsbound; i++, alloc1 += (1 << step)) { - step = alloc1->bits; - for (j = 0; j < stereo; j++) { - if ((ba = *bita++)) { - k = (alloc2 = alloc1 + ba)->bits; - if ((d1 = alloc2->d) < 0) { - real cm = mpg123_muls[k][scale[x1]]; + struct al_table *alloc2,*alloc1 = fr->alloc; + unsigned int *bita=bit_alloc; + int d1,step; - fraction[j][0][i] = - ((real) ((int) mpg123_getbits(k) + d1)) * cm; - fraction[j][1][i] = - ((real) ((int) mpg123_getbits(k) + d1)) * cm; - fraction[j][2][i] = - ((real) ((int) mpg123_getbits(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) mpg123_getbits(k); - tab = (unsigned int *) (table[d1] + idx + idx + idx); - fraction[j][0][i] = mpg123_muls[*tab++][m]; - fraction[j][1][i] = mpg123_muls[*tab++][m]; - fraction[j][2][i] = mpg123_muls[*tab][m]; - } - scale += 3; - } - else - fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = - 0.0; + for (i=0;i<jsbound;i++,alloc1+=(1<<step)) + { + step = alloc1->bits; + for (j=0;j<stereo;j++) + { + if ( (ba=*bita++) ) + { + k=(alloc2 = alloc1+ba)->bits; + if( (d1=alloc2->d) < 0) + { + real cm = mpg123_muls[k][scale[x1]]; + fraction[j][0][i] = ((real) ((int)mpg123_getbits(&bsi,k) + d1)) * cm; + fraction[j][1][i] = ((real) ((int)mpg123_getbits(&bsi,k) + d1)) * cm; + fraction[j][2][i] = ((real) ((int)mpg123_getbits(&bsi,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) mpg123_getbits(&bsi,k); + tab = (unsigned int *) (table[d1] + idx + idx + idx); + fraction[j][0][i] = mpg123_muls[*tab++][m]; + fraction[j][1][i] = mpg123_muls[*tab++][m]; + fraction[j][2][i] = mpg123_muls[*tab][m]; + } + scale+=3; } + else + fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0; + } } - for (i = jsbound; i < sblimit; i++, alloc1 += (1 << step)) { - step = alloc1->bits; - bita++; /* channel 1 and channel 2 bitalloc are the same */ - if ((ba = *bita++)) { - k = (alloc2 = alloc1 + ba)->bits; - if ((d1 = alloc2->d) < 0) { - real cm; - - cm = mpg123_muls[k][scale[x1 + 3]]; - fraction[1][0][i] = (fraction[0][0][i] = - (real) ((int) mpg123_getbits(k) + - d1)) * cm; - fraction[1][1][i] = (fraction[0][1][i] = - (real) ((int) mpg123_getbits(k) + - d1)) * cm; - fraction[1][2][i] = (fraction[0][2][i] = - (real) ((int) mpg123_getbits(k) + - d1)) * cm; - cm = mpg123_muls[k][scale[x1]]; - fraction[0][0][i] *= cm; - fraction[0][1][i] *= cm; - fraction[0][2][i] *= cm; - } - else { - 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) mpg123_getbits(k); - tab = (unsigned int *) (table[d1] + idx + idx + idx); - fraction[0][0][i] = mpg123_muls[*tab][m1]; - fraction[1][0][i] = mpg123_muls[*tab++][m2]; - fraction[0][1][i] = mpg123_muls[*tab][m1]; - fraction[1][1][i] = mpg123_muls[*tab++][m2]; - fraction[0][2][i] = mpg123_muls[*tab][m1]; - fraction[1][2][i] = mpg123_muls[*tab][m2]; - } - scale += 6; + for (i=jsbound;i<sblimit;i++,alloc1+=(1<<step)) + { + step = alloc1->bits; + bita++; /* channel 1 and channel 2 bitalloc are the same */ + if ( (ba=*bita++) ) + { + k=(alloc2 = alloc1+ba)->bits; + if( (d1=alloc2->d) < 0) + { + real cm; + cm = mpg123_muls[k][scale[x1+3]]; + fraction[1][0][i] = (fraction[0][0][i] = (real) ((int)mpg123_getbits(&bsi,k) + d1) ) * cm; + fraction[1][1][i] = (fraction[0][1][i] = (real) ((int)mpg123_getbits(&bsi,k) + d1) ) * cm; + fraction[1][2][i] = (fraction[0][2][i] = (real) ((int)mpg123_getbits(&bsi,k) + d1) ) * cm; + cm = mpg123_muls[k][scale[x1]]; + fraction[0][0][i] *= cm; fraction[0][1][i] *= cm; fraction[0][2][i] *= cm; } - else { - fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] = - fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = - 0.0; + else + { + 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) mpg123_getbits(&bsi,k); + tab = (unsigned int *) (table[d1] + idx + idx + idx); + fraction[0][0][i] = mpg123_muls[*tab][m1]; fraction[1][0][i] = mpg123_muls[*tab++][m2]; + fraction[0][1][i] = mpg123_muls[*tab][m1]; fraction[1][1][i] = mpg123_muls[*tab++][m2]; + fraction[0][2][i] = mpg123_muls[*tab][m1]; fraction[1][2][i] = mpg123_muls[*tab][m2]; } -/* - should we use individual scalefac for channel 2 or - is the current way the right one , where we just copy channel 1 to - channel 2 ?? - The current 'strange' thing is, that we throw away the scalefac - values for the second channel ...!! - -> changed .. now we use the scalefac values of channel one !! - */ + scale+=6; + } + else { + fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] = + fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0.0; + } } - if (sblimit > (fr->down_sample_sblimit)) - sblimit = fr->down_sample_sblimit; + if(sblimit > (fr->down_sample_sblimit) ) + sblimit = fr->down_sample_sblimit; - for (i = sblimit; i < SBLIMIT; i++) - for (j = 0; j < stereo; j++) - fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0; + for(i=sblimit;i<SBLIMIT;i++) + for (j=0;j<stereo;j++) + fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0; } -static void -II_select_table(struct frame *fr) +static void II_select_table(struct frame *fr) { - static int translate[3][2][16] = { - {{0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 1, 1, 1, 1, 1, 0}, - {0, 2, 2, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}}, - {{0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, - {{0, 3, 3, 3, 3, 3, 3, 0, 0, 0, 1, 1, 1, 1, 1, 0}, - {0, 3, 3, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}} - }; + static int translate[3][2][16] = + { { { 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0 } , + { 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0 } } , + { { 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0 } , + { 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0 } } , + { { 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0 } , + { 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0 } } }; - int table, sblim; - static struct al_table *tables[5] = - { alloc_0, alloc_1, alloc_2, alloc_3, alloc_4 }; - static int sblims[5] = { 27, 30, 8, 12, 30 }; + int table,sblim; + static struct al_table *tables[5] = + { alloc_0, alloc_1, alloc_2, alloc_3 , alloc_4 }; + static int sblims[5] = { 27 , 30 , 8, 12 , 30 }; - if (fr->lsf) - table = 4; - else - table = - translate[fr->sampling_frequency][2 - - fr->stereo][fr->bitrate_index]; - sblim = sblims[table]; + if(fr->lsf) + table = 4; + else + table = translate[fr->sampling_frequency][2-fr->stereo][fr->bitrate_index]; + sblim = sblims[table]; - fr->alloc = tables[table]; - fr->II_sblimit = sblim; + fr->alloc = tables[table]; + fr->II_sblimit = sblim; } - int mpg123_do_layer2(struct frame *fr) {
--- a/Plugins/Input/mpg123/layer3.c Tue Nov 08 12:04:15 2005 -0800 +++ b/Plugins/Input/mpg123/layer3.c Wed Nov 09 16:40:03 2005 -0800 @@ -1,132 +1,111 @@ - -/* - * Mpeg Layer-3 audio decoder +/* + * Mpeg Layer-3 audio decoder * -------------------------- * copyright (c) 1995-1999 by Michael Hipp. * All rights reserved. See also 'README' * - * Optimize-TODO: put short bands into the band-field without the stride of 3 reals + * Optimize-TODO: put short bands into the band-field without the stride + * of 3 reals * Length-optimze: unify long and short band code where it is possible - */ + */ + +#if 0 +#define L3_DEBUG 1 +#endif + +#if 0 +#define CUT_HF +#endif #include <stdlib.h> #include <math.h> - +#include <glib.h> #include "audacious/output.h" - #include "mpg123.h" #include "huffman.h" + +#include "common.h" + #include "getbits.h" - 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 win[4][36]; static real win1[4][36]; -static real gainpow2[256 + 118 + 4]; -real COS9[9]; -static real COS6_1, COS6_2; -real tfcos36[9]; +static real gainpow2[256+118+4]; + +/* non static for external 3dnow functions */ +real COS9[9]; +static real COS6_1,COS6_2; +real tfcos36[9]; + static real tfcos12[3]; #define NEW_DCT9 #ifdef NEW_DCT9 -static real cos9[3], cos18[3]; -#endif - -#ifdef USE_SIMD -# define DCT36 (fr->dct36) -#else -# define DCT36 mpg123_dct36 +static real cos9[3],cos18[3]; #endif struct bandInfoStruct { - int longIdx[23]; - int longDiff[22]; - int shortIdx[14]; - int shortDiff[13]; + int longIdx[23]; + int longDiff[22]; + int shortIdx[14]; + int shortDiff[13]; }; int longLimit[9][23]; int shortLimit[9][14]; -/* Used by the getbits macros */ -static unsigned long rval; -static unsigned char rval_uc; +struct bandInfoStruct bandInfo[9] = { -struct bandInfoStruct bandInfo[9] = { /* MPEG 1.0 */ - {{0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, 74, 90, 110, 134, 162, - 196, 238, 288, 342, 418, 576}, - {4, 4, 4, 4, 4, 4, 6, 6, 8, 8, 10, 12, 16, 20, 24, 28, 34, 42, 50, 54, - 76, 158}, - {0, 4 * 3, 8 * 3, 12 * 3, 16 * 3, 22 * 3, 30 * 3, 40 * 3, 52 * 3, - 66 * 3, 84 * 3, 106 * 3, 136 * 3, 192 * 3}, - {4, 4, 4, 4, 6, 8, 10, 12, 14, 18, 22, 30, 56}}, + { {0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576}, + {4,4,4,4,4,4,6,6,8, 8,10,12,16,20,24,28,34,42,50,54, 76,158}, + {0,4*3,8*3,12*3,16*3,22*3,30*3,40*3,52*3,66*3, 84*3,106*3,136*3,192*3}, + {4,4,4,4,6,8,10,12,14,18,22,30,56} } , - {{0, 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, 72, 88, 106, 128, 156, - 190, 230, 276, 330, 384, 576}, - {4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10, 12, 16, 18, 22, 28, 34, 40, 46, 54, - 54, 192}, - {0, 4 * 3, 8 * 3, 12 * 3, 16 * 3, 22 * 3, 28 * 3, 38 * 3, 50 * 3, - 64 * 3, 80 * 3, 100 * 3, 126 * 3, 192 * 3}, - {4, 4, 4, 4, 6, 6, 10, 12, 14, 16, 20, 26, 66}}, + { {0,4,8,12,16,20,24,30,36,42,50,60,72, 88,106,128,156,190,230,276,330,384,576}, + {4,4,4,4,4,4,6,6,6, 8,10,12,16,18,22,28,34,40,46,54, 54,192}, + {0,4*3,8*3,12*3,16*3,22*3,28*3,38*3,50*3,64*3, 80*3,100*3,126*3,192*3}, + {4,4,4,4,6,6,10,12,14,16,20,26,66} } , - {{0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, 82, 102, 126, 156, 194, - 240, 296, 364, 448, 550, 576}, - {4, 4, 4, 4, 4, 4, 6, 6, 8, 10, 12, 16, 20, 24, 30, 38, 46, 56, 68, - 84, 102, 26}, - {0, 4 * 3, 8 * 3, 12 * 3, 16 * 3, 22 * 3, 30 * 3, 42 * 3, 58 * 3, - 78 * 3, 104 * 3, 138 * 3, 180 * 3, 192 * 3}, - {4, 4, 4, 4, 6, 8, 12, 16, 20, 26, 34, 42, 12}}, + { {0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576} , + {4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102, 26} , + {0,4*3,8*3,12*3,16*3,22*3,30*3,42*3,58*3,78*3,104*3,138*3,180*3,192*3} , + {4,4,4,4,6,8,12,16,20,26,34,42,12} } , /* MPEG 2.0 */ - {{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, - 238, 284, 336, 396, 464, 522, 576}, - {6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 38, 46, 52, 60, - 68, 58, 54}, - {0, 4 * 3, 8 * 3, 12 * 3, 18 * 3, 24 * 3, 32 * 3, 42 * 3, 56 * 3, - 74 * 3, 100 * 3, 132 * 3, 174 * 3, 192 * 3}, - {4, 4, 4, 6, 6, 8, 10, 14, 18, 26, 32, 42, 18}}, + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 } , + {0,4*3,8*3,12*3,18*3,24*3,32*3,42*3,56*3,74*3,100*3,132*3,174*3,192*3} , + {4,4,4,6,6,8,10,14,18,26,32,42,18 } } , /* { {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576}, {6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,52,64,70,76,36 } , */ /* changed 19th value fropm 330 to 332 */ - {{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 114, 136, 162, 194, - 232, 278, 332, 394, 464, 540, 576}, - {6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 18, 22, 26, 32, 38, 46, 54, 62, - 70, 76, 36}, - {0, 4 * 3, 8 * 3, 12 * 3, 18 * 3, 26 * 3, 36 * 3, 48 * 3, 62 * 3, - 80 * 3, 104 * 3, 136 * 3, 180 * 3, 192 * 3}, - {4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 32, 44, 12}}, + { {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,332,394,464,540,576}, + {6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,54,62,70,76,36 } , + {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,136*3,180*3,192*3} , + {4,4,4,6,8,10,12,14,18,24,32,44,12 } } , - {{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, - 238, 284, 336, 396, 464, 522, 576}, - {6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 38, 46, 52, 60, - 68, 58, 54}, - {0, 4 * 3, 8 * 3, 12 * 3, 18 * 3, 26 * 3, 36 * 3, 48 * 3, 62 * 3, - 80 * 3, 104 * 3, 134 * 3, 174 * 3, 192 * 3}, - {4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18}}, + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 }, + {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,134*3,174*3,192*3}, + {4,4,4,6,8,10,12,14,18,24,30,40,18 } } , /* MPEG 2.5 */ - {{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, - 238, 284, 336, 396, 464, 522, 576}, - {6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 38, 46, 52, 60, - 68, 58, 54}, - {0, 12, 24, 36, 54, 78, 108, 144, 186, 240, 312, 402, 522, 576}, - {4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18}}, - {{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, - 238, 284, 336, 396, 464, 522, 576}, - {6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16, 20, 24, 28, 32, 38, 46, 52, 60, - 68, 58, 54}, - {0, 12, 24, 36, 54, 78, 108, 144, 186, 240, 312, 402, 522, 576}, - {4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18}}, - {{0, 12, 24, 36, 48, 60, 72, 88, 108, 132, 160, 192, 232, 280, 336, - 400, 476, 566, 568, 570, 572, 574, 576}, - {12, 12, 12, 12, 12, 12, 16, 20, 24, 28, 32, 40, 48, 56, 64, 76, 90, - 2, 2, 2, 2, 2}, - {0, 24, 48, 72, 108, 156, 216, 288, 372, 480, 486, 492, 498, 576}, - {8, 8, 8, 12, 16, 20, 24, 28, 36, 2, 2, 2, 26}}, + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} , + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54}, + {0,12,24,36,54,78,108,144,186,240,312,402,522,576}, + {4,4,4,6,8,10,12,14,18,24,30,40,18} }, + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} , + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54}, + {0,12,24,36,54,78,108,144,186,240,312,402,522,576}, + {4,4,4,6,8,10,12,14,18,24,30,40,18} }, + { {0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576}, + {12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2}, + {0, 24, 48, 72,108,156,216,288,372,480,486,492,498,576}, + {8,8,8,12,16,20,24,28,36,2,2,2,26} } , }; static int mapbuf0[9][152]; @@ -135,15 +114,12 @@ static int *map[9][3]; static int *mapend[9][3]; -static unsigned int n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */ -static unsigned int i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */ +static unsigned int n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */ +static unsigned int i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */ -static real tan1_1[16], tan2_1[16], tan1_2[16], tan2_2[16]; -static real pow1_1[2][16], pow2_1[2][16], pow1_2[2][16], pow2_2[2][16]; +static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16]; +static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16]; -/* - * init tables for layer-3 - */ void mpg123_init_layer3(int down_sample_sblimit) { @@ -384,890 +360,839 @@ /* * read additional side information (for MPEG 1 and MPEG 2) */ -static int -III_get_side_info(struct III_sideinfo *si, int stereo, - int ms_stereo, long sfreq, int single, int lsf) +static int III_get_side_info(struct III_sideinfo *si,int stereo, + int ms_stereo,long sfreq,int single,int lsf) { - int ch, gr; - int powdiff = (single == 3) ? 4 : 0; + int ch, gr; + int powdiff = (single == 3) ? 4 : 0; - static const int tabs[2][5] = { {2, 9, 5, 3, 4}, {1, 8, 1, 2, 9} }; - const int *tab = tabs[lsf]; - - si->main_data_begin = mpg123_getbits(tab[1]); - if (stereo == 1) - si->private_bits = mpg123_getbits_fast(tab[2]); - else - si->private_bits = mpg123_getbits_fast(tab[3]); + static const int tabs[2][5] = { { 2,9,5,3,4 } , { 1,8,1,2,9 } }; + const int *tab = tabs[lsf]; + + si->main_data_begin = mpg123_getbits(&bsi,tab[1]); + if (stereo == 1) + si->private_bits = mpg123_getbits_fast(&bsi,tab[2]); + else + si->private_bits = mpg123_getbits_fast(&bsi,tab[3]); - if (!lsf) { - for (ch = 0; ch < stereo; ch++) { - si->ch[ch].gr[0].scfsi = -1; - si->ch[ch].gr[1].scfsi = mpg123_getbits_fast(4); - } - } + if(!lsf) { + for (ch=0; ch<stereo; ch++) { + si->ch[ch].gr[0].scfsi = -1; + si->ch[ch].gr[1].scfsi = mpg123_getbits_fast(&bsi,4); + } + } - for (gr = 0; gr < tab[0]; gr++) { - for (ch = 0; ch < stereo; ch++) { - register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]); + for (gr=0; gr<tab[0]; gr++) { + for (ch=0; ch<stereo; ch++) { + register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]); - gr_info->part2_3_length = mpg123_getbits(12); - gr_info->big_values = mpg123_getbits(9); - if (gr_info->big_values > 288) { - /* fprintf(stderr, "big_values too large!\n"); */ - /* gr_info->big_values = 288; */ - return 0; - } - gr_info->pow2gain = - gainpow2 + 256 - mpg123_getbits_fast(8) + powdiff; - if (ms_stereo) - gr_info->pow2gain += 2; - gr_info->scalefac_compress = mpg123_getbits(tab[4]); + gr_info->part2_3_length = mpg123_getbits(&bsi,12); + gr_info->big_values = mpg123_getbits(&bsi,9); + if(gr_info->big_values > 288) { + gr_info->big_values = 288; + } + gr_info->pow2gain = gainpow2+256 - mpg123_getbits_fast(&bsi,8) + powdiff; + if(ms_stereo) + gr_info->pow2gain += 2; + gr_info->scalefac_compress = mpg123_getbits(&bsi,tab[4]); - if (mpg123_get1bit()) { /* window switch flag */ - int i; + if(mpg123_get1bit(&bsi)) { /* window switch flag */ + int i; +#ifdef L3_DEBUG +if(2*gr_info->big_values > bandInfo[sfreq].shortIdx[12]) + fprintf(stderr,"L3: BigValues too large, doesn't make sense %d %d\n",2*gr_info->big_values,bandInfo[sfreq].shortIdx[12]); +#endif - gr_info->block_type = mpg123_getbits_fast(2); - gr_info->mixed_block_flag = mpg123_get1bit(); - gr_info->table_select[0] = mpg123_getbits_fast(5); - gr_info->table_select[1] = mpg123_getbits_fast(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 + (mpg123_getbits_fast(3) << 3); - - if (gr_info->block_type == 0) { - /* fprintf(stderr, "Blocktype == 0 and window-switching == 1 not allowed.\n"); */ - /* exit(1); */ - return 0; - } + gr_info->block_type = mpg123_getbits_fast(&bsi,2); + gr_info->mixed_block_flag = mpg123_get1bit(&bsi); + gr_info->table_select[0] = mpg123_getbits_fast(&bsi,5); + gr_info->table_select[1] = mpg123_getbits_fast(&bsi,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 + (mpg123_getbits_fast(&bsi,3)<<3); - /* region_count/start parameters are implicit in this case. */ - if (!lsf || gr_info->block_type == 2) - gr_info->region1start = 36 >> 1; - else { - /* check this again for 2.5 and sfreq=8 */ - if (sfreq == 8) - gr_info->region1start = 108 >> 1; - else - gr_info->region1start = 54 >> 1; - } - gr_info->region2start = 576 >> 1; - } - else { - int i, r0c, r1c; + if(gr_info->block_type == 0) { + return 0; + } + + /* region_count/start parameters are implicit in this case. */ + if(!lsf || gr_info->block_type == 2) + gr_info->region1start = 36>>1; + else { +/* check this again for 2.5 and sfreq=8 */ + if(sfreq == 8) + gr_info->region1start = 108>>1; + else + gr_info->region1start = 54>>1; + } + gr_info->region2start = 576>>1; + } + else { + int i,r0c,r1c; +#ifdef L3_DEBUG +if(2*gr_info->big_values > bandInfo[sfreq].longIdx[21]) + fprintf(stderr,"L3: BigValues too large, doesn't make sense %d %d\n",2*gr_info->big_values,bandInfo[sfreq].longIdx[21]); +#endif + for (i=0; i<3; i++) + gr_info->table_select[i] = mpg123_getbits_fast(&bsi,5); + r0c = mpg123_getbits_fast(&bsi,4); + r1c = mpg123_getbits_fast(&bsi,3); + gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ; + if(r0c + r1c + 2 > 22) + gr_info->region2start = 576>>1; + else + gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1; + gr_info->block_type = 0; + gr_info->mixed_block_flag = 0; + } + if(!lsf) + gr_info->preflag = mpg123_get1bit(&bsi); + gr_info->scalefac_scale = mpg123_get1bit(&bsi); + gr_info->count1table_select = mpg123_get1bit(&bsi); + } + } - for (i = 0; i < 3; i++) - gr_info->table_select[i] = mpg123_getbits_fast(5); - r0c = mpg123_getbits_fast(4); - r1c = mpg123_getbits_fast(3); - gr_info->region1start = bandInfo[sfreq].longIdx[r0c + 1] >> 1; - if (r0c + r1c + 2 > 22) - gr_info->region2start = 576 >> 1; - else - gr_info->region2start = - bandInfo[sfreq].longIdx[r0c + 1 + r1c + 1] >> 1; - gr_info->block_type = 0; - gr_info->mixed_block_flag = 0; - } - if (!lsf) - gr_info->preflag = mpg123_get1bit(); - gr_info->scalefac_scale = mpg123_get1bit(); - gr_info->count1table_select = mpg123_get1bit(); - } - } - return 1; + return !0; } - /* * read scalefactors */ -static int -III_get_scale_factors_1(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] = { - {0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4}, - {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3} - }; - int numbits; - int num0 = slen[0][gr_info->scalefac_compress]; - int num1 = slen[1][gr_info->scalefac_compress]; + static const unsigned char slen[2][16] = { + {0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4}, + {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3} + }; + int numbits; + int num0 = slen[0][gr_info->scalefac_compress]; + int num1 = slen[1][gr_info->scalefac_compress]; if (gr_info->block_type == 2) { - int i = 18; - - numbits = (num0 + num1) * 18; + int i=18; + numbits = (num0 + num1) * 18; - if (gr_info->mixed_block_flag) { - for (i = 8; i; i--) - *scf++ = mpg123_getbits_fast(num0); - i = 9; - numbits -= num0; /* num0 * 17 + num1 * 18 */ - } + if (gr_info->mixed_block_flag) { + for (i=8;i;i--) + *scf++ = mpg123_getbits_fast(&bsi,num0); + i = 9; + numbits -= num0; /* num0 * 17 + num1 * 18 */ + } - for (; i; i--) - *scf++ = mpg123_getbits_fast(num0); - for (i = 18; i; i--) - *scf++ = mpg123_getbits_fast(num1); - *scf++ = 0; - *scf++ = 0; - *scf++ = 0; /* short[13][0..2] = 0 */ + for (;i;i--) + *scf++ = mpg123_getbits_fast(&bsi,num0); + for (i = 18; i; i--) + *scf++ = mpg123_getbits_fast(&bsi,num1); + *scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */ } else { - int i; - int scfsi = gr_info->scfsi; + int i; + int scfsi = gr_info->scfsi; - if (scfsi < 0) { /* scfsi < 0 => granule == 0 */ - for (i = 11; i; i--) - *scf++ = mpg123_getbits_fast(num0); - for (i = 10; i; i--) - *scf++ = mpg123_getbits_fast(num1); - numbits = (num0 + num1) * 10 + num0; - *scf++ = 0; + if(scfsi < 0) { /* scfsi < 0 => granule == 0 */ + for(i=11;i;i--) + *scf++ = mpg123_getbits_fast(&bsi,num0); + for(i=10;i;i--) + *scf++ = mpg123_getbits_fast(&bsi,num1); + numbits = (num0 + num1) * 10 + num0; + *scf++ = 0; + } + else { + numbits = 0; + if(!(scfsi & 0x8)) { + for (i=0;i<6;i++) + *scf++ = mpg123_getbits_fast(&bsi,num0); + numbits += num0 * 6; } else { - numbits = 0; - if (!(scfsi & 0x8)) { - for (i = 0; i < 6; i++) - *scf++ = mpg123_getbits_fast(num0); - numbits += num0 * 6; - } - else { - scf += 6; - } + scf += 6; + } - if (!(scfsi & 0x4)) { - for (i = 0; i < 5; i++) - *scf++ = mpg123_getbits_fast(num0); - numbits += num0 * 5; - } - else { - scf += 5; - } + if(!(scfsi & 0x4)) { + for (i=0;i<5;i++) + *scf++ = mpg123_getbits_fast(&bsi,num0); + numbits += num0 * 5; + } + else { + scf += 5; + } - if (!(scfsi & 0x2)) { - for (i = 0; i < 5; i++) - *scf++ = mpg123_getbits_fast(num1); - numbits += num1 * 5; - } - else { - scf += 5; - } + if(!(scfsi & 0x2)) { + for(i=0;i<5;i++) + *scf++ = mpg123_getbits_fast(&bsi,num1); + numbits += num1 * 5; + } + else { + scf += 5; + } - if (!(scfsi & 0x1)) { - for (i = 0; i < 5; i++) - *scf++ = mpg123_getbits_fast(num1); - numbits += num1 * 5; - } - else { - scf += 5; - } - *scf++ = 0; /* no l[21] in original sources */ + if(!(scfsi & 0x1)) { + for (i=0;i<5;i++) + *scf++ = mpg123_getbits_fast(&bsi,num1); + numbits += num1 * 5; } + else { + scf += 5; + } + *scf++ = 0; /* no l[21] in original sources */ + } } return numbits; } -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(int *scf,struct gr_info_s *gr_info,int i_stereo) { - unsigned char *pnt; - int i, j, n = 0, numbits = 0; - unsigned int slen; + unsigned char *pnt; + int i,j,n=0,numbits=0; + unsigned int slen; - static unsigned char stab[3][6][4] = { - {{6, 5, 5, 5}, {6, 5, 7, 3}, {11, 10, 0, 0}, - {7, 7, 7, 0}, {6, 6, 6, 3}, {8, 8, 5, 0}}, - {{9, 9, 9, 9}, {9, 9, 12, 6}, {18, 18, 0, 0}, - {12, 12, 12, 0}, {12, 9, 9, 6}, {15, 12, 9, 0}}, - {{6, 9, 9, 9}, {6, 9, 12, 6}, {15, 18, 0, 0}, - {6, 15, 12, 0}, {6, 12, 9, 6}, {6, 18, 9, 0}} - }; + static unsigned char stab[3][6][4] = { + { { 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0} , + { 7, 7, 7,0 } , { 6, 6, 6,3 } , { 8, 8,5,0} } , + { { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0} , + {12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} } , + { { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0} , + { 6,15,12,0 } , { 6,12, 9,6 } , { 6,18,9,0} } }; - if (i_stereo) /* i_stereo AND second channel -> mpg123_do_layer3() checks this */ - slen = i_slen2[gr_info->scalefac_compress >> 1]; - else - slen = n_slen2[gr_info->scalefac_compress]; + if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */ + slen = i_slen2[gr_info->scalefac_compress>>1]; + else + slen = n_slen2[gr_info->scalefac_compress]; - gr_info->preflag = (slen >> 15) & 0x1; + gr_info->preflag = (slen>>15) & 0x1; - n = 0; - if (gr_info->block_type == 2) { - n++; - if (gr_info->mixed_block_flag) - n++; - } + n = 0; + if( gr_info->block_type == 2 ) { + n++; + if(gr_info->mixed_block_flag) + n++; + } - pnt = stab[n][(slen >> 12) & 0x7]; - - for (i = 0; i < 4; i++) { - int num = slen & 0x7; + pnt = stab[n][(slen>>12)&0x7]; - slen >>= 3; - if (num) { - for (j = 0; j < (int) (pnt[i]); j++) - *scf++ = mpg123_getbits_fast(num); - numbits += pnt[i] * num; - } - else { - for (j = 0; j < (int) (pnt[i]); j++) - *scf++ = 0; - } + for(i=0;i<4;i++) { + int num = slen & 0x7; + slen >>= 3; + if(num) { + for(j=0;j<(int)(pnt[i]);j++) + *scf++ = mpg123_getbits_fast(&bsi,num); + numbits += pnt[i] * num; } + else { + for(j=0;j<(int)(pnt[i]);j++) + *scf++ = 0; + } + } + + n = (n << 1) + 1; + for(i=0;i<n;i++) + *scf++ = 0; - n = (n << 1) + 1; - for (i = 0; i < n; i++) - *scf++ = 0; - - return numbits; + return numbits; } -static int pretab1[22] = - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0 }; -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 }; +static int pretab1[22] = {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0}; +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}; /* * Dequantize samples (includes huffman decoding) */ /* 24 is enough because tab13 has max. a 19 bit huffvector */ -#define BITSHIFT ((sizeof (long) - 1) * 8) - -#define REFRESH_MASK() \ -while(num < BITSHIFT) { \ - mask |= ((unsigned long)mpg123_getbyte()) << (BITSHIFT - num); \ - num += 8; \ - part2remain -= 8; \ -} - -static int -III_dequantize_sample(real xr[SBLIMIT][SSLIMIT], int *scf, - struct gr_info_s *gr_info, int sfreq, int part2bits) -{ - int shift = 1 + gr_info->scalefac_scale; - real *xrpnt = (real *) xr; - int l[3], l3; - int part2remain = gr_info->part2_3_length - part2bits; - int *me; - - int num = mpg123_getbitoffset(); - long mask; - /* we must split this, because for num==0 the shift is undefined if you do it in one step */ - mask = ((unsigned long) mpg123_getbits(num)) << BITSHIFT; - mask <<= 8 - num; - part2remain -= num; - - { - int bv = gr_info->big_values; - int region1 = gr_info->region1start; - int region2 = gr_info->region2start; +#define BITSHIFT ((sizeof(long)-1)*8) +#define REFRESH_MASK \ + while(num < BITSHIFT) { \ + mask |= ((unsigned long)mpg123_getbyte(&bsi))<<(BITSHIFT-num); \ + num += 8; \ + part2remain -= 8; } - l3 = ((576 >> 1) - bv) >> 1; -/* - * we may lose the 'odd' bit here !! - * check this later again - */ - if (bv <= region1) { - l[0] = bv; - l[1] = 0; - l[2] = 0; - } - else { - l[0] = region1; - if (bv <= region2) { - l[1] = bv - l[0]; - l[2] = 0; - } - else { - l[1] = region2 - l[0]; - l[2] = bv - region2; - } - } - } - - if (gr_info->block_type == 2) { - /* - * decoding with short or mixed mode BandIndex table - */ - int i, max[4]; - int step = 0, lwin = 3, cb = 0; - register real v = 0.0; - register int *m, mc; +static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf, + struct gr_info_s *gr_info,int sfreq,int part2bits) +{ + int shift = 1 + gr_info->scalefac_scale; + real *xrpnt = (real *) xr; + int l[3],l3; + int part2remain = gr_info->part2_3_length - part2bits; + int *me; - if (gr_info->mixed_block_flag) { - max[3] = -1; - max[0] = max[1] = max[2] = 2; - m = map[sfreq][0]; - me = mapend[sfreq][0]; - } - else { - max[0] = max[1] = max[2] = max[3] = -1; - /* max[3] not really needed in this case */ - m = map[sfreq][1]; - me = mapend[sfreq][1]; - } - - mc = 0; - for (i = 0; i < 2; i++) { - int lp = l[i]; - struct newhuff *h = ht + gr_info->table_select[i]; + int num = mpg123_getbitoffset(&bsi); + long mask; + /* we must split this, because for num==0 the shift is undefined if you do it in one step */ + mask = ((unsigned long) mpg123_getbits(&bsi,num))<<BITSHIFT; + mask <<= 8-num; + part2remain -= num; - for (; lp; lp--, mc--) { - register int x, y; - if ((!mc)) { - mc = *m++; - xrpnt = ((real *) xr) + (*m++); - lwin = *m++; - cb = *m++; - if (lwin == 3) { - v = gr_info->pow2gain[(*scf++) << shift]; - step = 1; - } - else { - v = gr_info->full_gain[lwin][(*scf++) << shift]; - step = 3; - } - } - { - register short *val = h->table; + { + int bv = gr_info->big_values; + int region1 = gr_info->region1start; + int region2 = gr_info->region2start; - REFRESH_MASK(); - while ((y = *val++) < 0) { - if (mask < 0) - val -= y; - num--; - mask <<= 1; - } - x = y >> 4; - y &= 0xf; - } - if (x == 15 && h->linbits) { - max[lwin] = cb; - REFRESH_MASK(); - x += ((unsigned long) mask) >> (BITSHIFT + 8 - - h->linbits); - num -= h->linbits + 1; - mask <<= h->linbits; - if (mask < 0) - *xrpnt = -ispow[x] * v; - else - *xrpnt = ispow[x] * v; - mask <<= 1; - } - else if (x) { - max[lwin] = cb; - if (mask < 0) - *xrpnt = -ispow[x] * v; - else - *xrpnt = ispow[x] * v; - num--; - mask <<= 1; - } - else - *xrpnt = 0.0; - xrpnt += step; - if (y == 15 && h->linbits) { - max[lwin] = cb; - REFRESH_MASK(); - y += ((unsigned long) mask) >> (BITSHIFT + 8 - - h->linbits); - num -= h->linbits + 1; - mask <<= h->linbits; - if (mask < 0) - *xrpnt = -ispow[y] * v; - else - *xrpnt = ispow[y] * v; - mask <<= 1; - } - else if (y) { - max[lwin] = cb; - if (mask < 0) - *xrpnt = -ispow[y] * v; - else - *xrpnt = ispow[y] * v; - num--; - mask <<= 1; - } - else - *xrpnt = 0.0; - xrpnt += step; - } - } - - for (; l3 && (part2remain + num > 0); l3--) { - struct newhuff *h = htc + gr_info->count1table_select; - register short *val = h->table, a; + l3 = ((576>>1)-bv)>>1; +/* + * we may lose the 'odd' bit here !! + * check this later again + */ + if(bv <= region1) { + l[0] = bv; l[1] = l[2] = 0; + } + else { + l[0] = region1; + if(bv <= region2) { + l[1] = bv - l[0]; l[2] = 0; + } + else { + l[1] = region2 - l[0]; l[2] = bv - region2; + } + } + } + + if(gr_info->block_type == 2) { + /* + * decoding with short or mixed mode BandIndex table + */ + int i,max[4]; + int step=0,lwin=3,cb=0; + register real v = 0.0; + register int *m,mc; - REFRESH_MASK(); - while ((a = *val++) < 0) { - if (mask < 0) - val -= a; - num--; - mask <<= 1; - } - if (part2remain + num <= 0) { - num -= part2remain + num; - break; - } - - for (i = 0; i < 4; i++) { - if (!(i & 1)) { - if (!mc) { - mc = *m++; - xrpnt = ((real *) xr) + (*m++); - lwin = *m++; - cb = *m++; - if (lwin == 3) { - v = gr_info->pow2gain[(*scf++) << shift]; - step = 1; - } - else { - v = gr_info->full_gain[lwin][(*scf++) << shift]; - step = 3; - } - } - mc--; - } - if ((a & (0x8 >> i))) { - max[lwin] = cb; - if (part2remain + num <= 0) { - break; - } - if (mask < 0) - *xrpnt = -v; - else - *xrpnt = v; - num--; - mask <<= 1; - } - else - *xrpnt = 0.0; - xrpnt += step; - } - } - - if (lwin < 3) { /* short band? */ - while (1) { - /* HACK Prevent overflowing the xr buffer */ - if (mc * 6 > &xr[SBLIMIT][SSLIMIT] - xrpnt) - return 1; - - for (; mc > 0; mc--) { - *xrpnt = 0.0; - xrpnt += 3; /* short band -> step=3 */ - *xrpnt = 0.0; - xrpnt += 3; - } - if (m >= me) - break; - mc = *m++; - xrpnt = ((real *) xr) + *m++; - if (*m++ == 0) - break; /* optimize: field will be set to zero at the end of the function */ - m++; /* cb */ - } - } - - gr_info->maxband[0] = max[0] + 1; - gr_info->maxband[1] = max[1] + 1; - gr_info->maxband[2] = max[2] + 1; - gr_info->maxbandl = max[3] + 1; - - { - int rmax = max[0] > max[1] ? max[0] : max[1]; - - rmax = (rmax > max[2] ? rmax : max[2]) + 1; - gr_info->maxb = - rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3] + 1]; - } - + if(gr_info->mixed_block_flag) { + max[3] = -1; + max[0] = max[1] = max[2] = 2; + m = map[sfreq][0]; + me = mapend[sfreq][0]; } else { - /* - * decoding with 'long' BandIndex table (block_type != 2) - */ - int *pretab = gr_info->preflag ? pretab1 : pretab2; - int i, max = -1; - int cb = 0; - int *m = map[sfreq][2]; - register real v = 0.0; - int mc = 0; - - /* - * long hash table values - */ - for (i = 0; i < 3; i++) { - int lp = l[i]; - struct newhuff *h = ht + gr_info->table_select[i]; - - for (; lp; lp--, mc--) { - int x, y; + max[0] = max[1] = max[2] = max[3] = -1; + /* max[3] not really needed in this case */ + m = map[sfreq][1]; + me = mapend[sfreq][1]; + } - if (!mc) { - mc = *m++; - cb = *m++; -/* if (cb == 21) */ -/* v = 0.0; */ -/* else */ - v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; + mc = 0; + for(i=0;i<2;i++) { + int lp = l[i]; + struct newhuff *h = ht+gr_info->table_select[i]; + for(;lp;lp--,mc--) { + register int x,y; + if( (!mc) ) { + mc = *m++; + xrpnt = ((real *) xr) + (*m++); + lwin = *m++; + cb = *m++; + if(lwin == 3) { + v = gr_info->pow2gain[(*scf++) << shift]; + step = 1; + } + else { + v = gr_info->full_gain[lwin][(*scf++) << shift]; + step = 3; + } + } + { + register short *val = h->table; + REFRESH_MASK; + while((y=*val++)<0) { + if (mask < 0) + val -= y; + num--; + mask <<= 1; + } + x = y >> 4; + y &= 0xf; + } + if(x == 15 && h->linbits) { + max[lwin] = cb; + REFRESH_MASK; + x += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits); + num -= h->linbits+1; + mask <<= h->linbits; + if(mask < 0) + *xrpnt = REAL_MUL(-ispow[x], v); + else + *xrpnt = REAL_MUL(ispow[x], v); + mask <<= 1; + } + else if(x) { + max[lwin] = cb; + if(mask < 0) + *xrpnt = REAL_MUL(-ispow[x], v); + else + *xrpnt = REAL_MUL(ispow[x], v); + num--; + mask <<= 1; + } + else + *xrpnt = DOUBLE_TO_REAL(0.0); + xrpnt += step; + if(y == 15 && h->linbits) { + max[lwin] = cb; + REFRESH_MASK; + y += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits); + num -= h->linbits+1; + mask <<= h->linbits; + if(mask < 0) + *xrpnt = REAL_MUL(-ispow[y], v); + else + *xrpnt = REAL_MUL(ispow[y], v); + mask <<= 1; + } + else if(y) { + max[lwin] = cb; + if(mask < 0) + *xrpnt = REAL_MUL(-ispow[y], v); + else + *xrpnt = REAL_MUL(ispow[y], v); + num--; + mask <<= 1; + } + else + *xrpnt = DOUBLE_TO_REAL(0.0); + xrpnt += step; + } + } - } - { - register short *val = h->table; - REFRESH_MASK(); - while ((y = *val++) < 0) { - if (mask < 0) - val -= y; - num--; - mask <<= 1; - } - x = y >> 4; - y &= 0xf; - } + for(;l3 && (part2remain+num > 0);l3--) { + struct newhuff *h = htc+gr_info->count1table_select; + register short *val = h->table,a; + + REFRESH_MASK; + while((a=*val++)<0) { + if (mask < 0) + val -= a; + num--; + mask <<= 1; + } + if(part2remain+num <= 0) { + num -= part2remain+num; + break; + } - if (x == 15 && h->linbits) { - max = cb; - REFRESH_MASK(); - x += ((unsigned long) mask) >> (BITSHIFT + 8 - - h->linbits); - num -= h->linbits + 1; - mask <<= h->linbits; - if (mask < 0) - *xrpnt++ = -ispow[x] * v; - else - *xrpnt++ = ispow[x] * v; - mask <<= 1; - } - else if (x) { - max = cb; - if (mask < 0) - *xrpnt++ = -ispow[x] * v; - else - *xrpnt++ = ispow[x] * v; - num--; - mask <<= 1; - } - else - *xrpnt++ = 0.0; + for(i=0;i<4;i++) { + if(!(i & 1)) { + if(!mc) { + mc = *m++; + xrpnt = ((real *) xr) + (*m++); + lwin = *m++; + cb = *m++; + if(lwin == 3) { + v = gr_info->pow2gain[(*scf++) << shift]; + step = 1; + } + else { + v = gr_info->full_gain[lwin][(*scf++) << shift]; + step = 3; + } + } + mc--; + } + if( (a & (0x8>>i)) ) { + max[lwin] = cb; + if(part2remain+num <= 0) { + break; + } + if(mask < 0) + *xrpnt = -v; + else + *xrpnt = v; + num--; + mask <<= 1; + } + else + *xrpnt = DOUBLE_TO_REAL(0.0); + xrpnt += step; + } + } + + if(lwin < 3) { /* short band? */ + while(1) { + for(;mc > 0;mc--) { + *xrpnt = DOUBLE_TO_REAL(0.0); xrpnt += 3; /* short band -> step=3 */ + *xrpnt = DOUBLE_TO_REAL(0.0); xrpnt += 3; + } + if(m >= me) + break; + mc = *m++; + xrpnt = ((real *) xr) + *m++; + if(*m++ == 0) + break; /* optimize: field will be set to zero at the end of the function */ + m++; /* cb */ + } + } - if (y == 15 && h->linbits) { - max = cb; - REFRESH_MASK(); - y += ((unsigned long) mask) >> (BITSHIFT + 8 - - h->linbits); - num -= h->linbits + 1; - mask <<= h->linbits; - if (mask < 0) - *xrpnt++ = -ispow[y] * v; - else - *xrpnt++ = ispow[y] * v; - mask <<= 1; - } - else if (y) { - max = cb; - if (mask < 0) - *xrpnt++ = -ispow[y] * v; - else - *xrpnt++ = ispow[y] * v; - num--; - mask <<= 1; - } - else - *xrpnt++ = 0.0; - } + gr_info->maxband[0] = max[0]+1; + gr_info->maxband[1] = max[1]+1; + gr_info->maxband[2] = max[2]+1; + gr_info->maxbandl = max[3]+1; + + { + int rmax = max[0] > max[1] ? max[0] : max[1]; + rmax = (rmax > max[2] ? rmax : max[2]) + 1; + gr_info->maxb = rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3]+1]; + } + + } + else { + /* + * decoding with 'long' BandIndex table (block_type != 2) + */ + int *pretab = gr_info->preflag ? pretab1 : pretab2; + int i,max = -1; + int cb = 0; + int *m = map[sfreq][2]; + register real v = 0.0; + int mc = 0; + + /* + * long hash table values + */ + for(i=0;i<3;i++) { + int lp = l[i]; + struct newhuff *h = ht+gr_info->table_select[i]; + + for(;lp;lp--,mc--) { + int x,y; + + if(!mc) { + mc = *m++; + cb = *m++; +#ifdef CUT_HF + if(cb == 21) { + fprintf(stderr,"c"); + v = 0.0; + } + else +#endif + v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; + + } + { + register short *val = h->table; + REFRESH_MASK; + while((y=*val++)<0) { + if (mask < 0) + val -= y; + num--; + mask <<= 1; + } + x = y >> 4; + y &= 0xf; } - /* - * short (count1table) values - */ - for (; l3 && (part2remain + num > 0); l3--) { - struct newhuff *h = htc + gr_info->count1table_select; - register short *val = h->table, a; - - REFRESH_MASK(); - while ((a = *val++) < 0) { - if (mask < 0) - val -= a; - num--; - mask <<= 1; - } - if (part2remain + num <= 0) { - num -= part2remain + num; - break; - } + if (x == 15 && h->linbits) { + max = cb; + REFRESH_MASK; + x += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits); + num -= h->linbits+1; + mask <<= h->linbits; + if(mask < 0) + *xrpnt++ = REAL_MUL(-ispow[x], v); + else + *xrpnt++ = REAL_MUL(ispow[x], v); + mask <<= 1; + } + else if(x) { + max = cb; + if(mask < 0) + *xrpnt++ = REAL_MUL(-ispow[x], v); + else + *xrpnt++ = REAL_MUL(ispow[x], v); + num--; + mask <<= 1; + } + else + *xrpnt++ = DOUBLE_TO_REAL(0.0); - for (i = 0; i < 4; i++) { - if (!(i & 1)) { - if (!mc) { - mc = *m++; - cb = *m++; -/* if (cb == 21) */ -/* v = 0.0; */ -/* else */ - v = gr_info-> - pow2gain[((*scf++) + (*pretab++)) << shift]; - } - mc--; - } - if ((a & (0x8 >> i))) { - max = cb; - if (part2remain + num <= 0) { - break; - } - if (mask < 0) - *xrpnt++ = -v; - else - *xrpnt++ = v; - num--; - mask <<= 1; - } - else - *xrpnt++ = 0.0; - } + if (y == 15 && h->linbits) { + max = cb; + REFRESH_MASK; + y += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits); + num -= h->linbits+1; + mask <<= h->linbits; + if(mask < 0) + *xrpnt++ = REAL_MUL(-ispow[y], v); + else + *xrpnt++ = REAL_MUL(ispow[y], v); + mask <<= 1; } - - gr_info->maxbandl = max + 1; - gr_info->maxb = longLimit[sfreq][gr_info->maxbandl]; + else if(y) { + max = cb; + if(mask < 0) + *xrpnt++ = REAL_MUL(-ispow[y], v); + else + *xrpnt++ = REAL_MUL(ispow[y], v); + num--; + mask <<= 1; + } + else + *xrpnt++ = DOUBLE_TO_REAL(0.0); + } } - part2remain += num; - mpg123_backbits(num); - num = 0; + /* + * short (count1table) values + */ + for(;l3 && (part2remain+num > 0);l3--) { + struct newhuff *h = htc+gr_info->count1table_select; + register short *val = h->table,a; - while (xrpnt < &xr[SBLIMIT][0]) - *xrpnt++ = 0.0; + REFRESH_MASK; + while((a=*val++)<0) { + if (mask < 0) + val -= a; + num--; + mask <<= 1; + } + if(part2remain+num <= 0) { + num -= part2remain+num; + break; + } - while (part2remain > 16) { - mpg123_getbits(16); /* Dismiss stuffing Bits */ - part2remain -= 16; + for(i=0;i<4;i++) { + if(!(i & 1)) { + if(!mc) { + mc = *m++; + cb = *m++; +#ifdef CUT_HF + if(cb == 21) { + fprintf(stderr,"c"); + v = 0.0; + } + else +#endif + v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; + } + mc--; + } + if ( (a & (0x8>>i)) ) { + max = cb; + if(part2remain+num <= 0) { + break; + } + if(mask < 0) + *xrpnt++ = -v; + else + *xrpnt++ = v; + num--; + mask <<= 1; + } + else + *xrpnt++ = DOUBLE_TO_REAL(0.0); + } } - if (part2remain > 0) - mpg123_getbits(part2remain); - else if (part2remain < 0) { -/* fprintf(stderr, "mpg123: Can't rewind stream by %d bits!\n", */ -/* -part2remain); */ - return 1; /* -> error */ - } - return 0; + + gr_info->maxbandl = max+1; + gr_info->maxb = longLimit[sfreq][gr_info->maxbandl]; + } + + part2remain += num; + mpg123_backbits(&bsi,num); + num = 0; + + while(xrpnt < &xr[SBLIMIT][0]) + *xrpnt++ = DOUBLE_TO_REAL(0.0); + + while( part2remain > 16 ) { + mpg123_getbits(&bsi,16); /* Dismiss stuffing Bits */ + part2remain -= 16; + } + if(part2remain > 0) + mpg123_getbits(&bsi,part2remain); +#if 0 + else if(part2remain < 0) { + g_warn("Can't rewind stream by %d bits!\n",-part2remain); + } +#endif + return 0; } -/* +/* * III_stereo: calculate real channel values for Joint-I-Stereo-mode */ -static void -III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT], int *scalefac, - struct gr_info_s *gr_info, int sfreq, int ms_stereo, int lsf) +static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac, + struct gr_info_s *gr_info,int sfreq,int ms_stereo,int lsf) { - real(*xr)[SBLIMIT * SSLIMIT] = (real(*)[SBLIMIT * SSLIMIT]) xr_buf; - struct bandInfoStruct *bi = &bandInfo[sfreq]; + real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf; + struct bandInfoStruct *bi = &bandInfo[sfreq]; + + const real *tab1,*tab2; + + int tab; + static const real *tabs[3][2][2] = { + { { tan1_1,tan2_1 } , { tan1_2,tan2_2 } }, + { { pow1_1[0],pow2_1[0] } , { pow1_2[0],pow2_2[0] } } , + { { pow1_1[1],pow2_1[1] } , { pow1_2[1],pow2_2[1] } } + }; - const real *tab1, *tab2; + tab = lsf + (gr_info->scalefac_compress & lsf); + tab1 = tabs[tab][ms_stereo][0]; + tab2 = tabs[tab][ms_stereo][1]; +#if 0 + if(lsf) { + int p = gr_info->scalefac_compress & 0x1; + if(ms_stereo) { + tab1 = pow1_2[p]; tab2 = pow2_2[p]; + } + else { + tab1 = pow1_1[p]; tab2 = pow2_1[p]; + } + } + else { + if(ms_stereo) { + tab1 = tan1_2; tab2 = tan2_2; + } + else { + tab1 = tan1_1; tab2 = tan2_1; + } + } +#endif + + if (gr_info->block_type == 2) { + int lwin,do_l = 0; + if( gr_info->mixed_block_flag ) + do_l = 1; + + for (lwin=0;lwin<3;lwin++) { /* process each window */ + /* get first band with zero values */ + int is_p,sb,idx,sfb = gr_info->maxband[lwin]; /* sfb is minimal 3 for mixed mode */ + if(sfb > 3) + do_l = 0; + + for(;sfb<12;sfb++) { + is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ + if(is_p != 7) { + real t1,t2; + sb = bi->shortDiff[sfb]; + idx = bi->shortIdx[sfb] + lwin; + t1 = tab1[is_p]; t2 = tab2[is_p]; + for (; sb > 0; sb--,idx+=3) { + real v = xr[0][idx]; + xr[0][idx] = REAL_MUL(v, t1); + xr[1][idx] = REAL_MUL(v, t2); + } + } + } #if 1 - int tab; - static const real *tabs[3][2][2] = { - {{tan1_1, tan2_1}, {tan1_2, tan2_2}}, - {{pow1_1[0], pow2_1[0]}, {pow1_2[0], pow2_2[0]}}, - {{pow1_1[1], pow2_1[1]}, {pow1_2[1], pow2_2[1]}} - }; - - tab = lsf + (gr_info->scalefac_compress & lsf); - tab1 = tabs[tab][ms_stereo][0]; - tab2 = tabs[tab][ms_stereo][1]; +/* in the original: copy 10 to 11 , here: copy 11 to 12 +maybe still wrong??? (copy 12 to 13?) */ + is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ + sb = bi->shortDiff[12]; + idx = bi->shortIdx[12] + lwin; #else - if (lsf) { - int p = gr_info->scalefac_compress & 0x1; - - if (ms_stereo) { - tab1 = pow1_2[p]; - tab2 = pow2_2[p]; - } - else { - tab1 = pow1_1[p]; - tab2 = pow2_1[p]; - } - } - else { - if (ms_stereo) { - tab1 = tan1_2; - tab2 = tan2_2; - } - else { - tab1 = tan1_1; - tab2 = tan2_1; - } - } + is_p = scalefac[10*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ + sb = bi->shortDiff[11]; + idx = bi->shortIdx[11] + lwin; #endif - - if (gr_info->block_type == 2) { - int lwin, do_l = 0; - - if (gr_info->mixed_block_flag) - do_l = 1; - - for (lwin = 0; lwin < 3; lwin++) { /* process each window */ - /* get first band with zero values */ - int is_p, sb, idx, sfb = gr_info->maxband[lwin]; /* sfb is minimal 3 for mixed mode */ - - if (sfb > 3) - do_l = 0; - - for (; sfb < 12; sfb++) { - is_p = scalefac[sfb * 3 + lwin - gr_info->mixed_block_flag]; /* scale: 0-15 */ - if (is_p != 7) { - real t1, t2; - - sb = bi->shortDiff[sfb]; - idx = bi->shortIdx[sfb] + lwin; - t1 = tab1[is_p]; - t2 = tab2[is_p]; - for (; sb > 0; sb--, idx += 3) { - real v = xr[0][idx]; - - xr[0][idx] = v * t1; - xr[1][idx] = v * t2; - } - } - } - -#if 1 -/* in the original: copy 10 to 11 , here: copy 11 to 12 - maybe still wrong??? (copy 12 to 13?) */ - is_p = scalefac[11 * 3 + lwin - gr_info->mixed_block_flag]; /* scale: 0-15 */ - sb = bi->shortDiff[12]; - idx = bi->shortIdx[12] + lwin; -#else - is_p = scalefac[10 * 3 + lwin - gr_info->mixed_block_flag]; /* scale: 0-15 */ - sb = bi->shortDiff[11]; - idx = bi->shortIdx[11] + lwin; -#endif - if (is_p != 7) { - real t1, t2; - t1 = tab1[is_p]; - t2 = tab2[is_p]; - for (; sb > 0; sb--, idx += 3) { - real v = xr[0][idx]; - xr[0][idx] = v * t1; - xr[1][idx] = v * t2; - } - } - } /* end for(lwin; .. ; . ) */ + if(is_p != 7) { + real t1,t2; + t1 = tab1[is_p]; t2 = tab2[is_p]; + for ( ; sb > 0; sb--,idx+=3 ) { + real v = xr[0][idx]; + xr[0][idx] = REAL_MUL(v, t1); + xr[1][idx] = REAL_MUL(v, t2); + } + } + } /* end for(lwin; .. ; . ) */ /* also check l-part, if ALL bands in the three windows are 'empty' - * and mode = mixed_mode + * and mode = mixed_mode */ - if (do_l) { - int sfb = gr_info->maxbandl; - int idx = bi->longIdx[sfb]; - - for (; sfb < 8; sfb++) { - int sb = bi->longDiff[sfb]; - int is_p = scalefac[sfb]; /* scale: 0-15 */ - - if (is_p != 7) { - real t1, t2; + if (do_l) { + int sfb = gr_info->maxbandl; + int idx = bi->longIdx[sfb]; - t1 = tab1[is_p]; - t2 = tab2[is_p]; - for (; sb > 0; sb--, idx++) { - real v = xr[0][idx]; - - xr[0][idx] = v * t1; - xr[1][idx] = v * t2; - } - } - else - idx += sb; - } - } - } - else { /* ((gr_info->block_type != 2)) */ - int sfb = gr_info->maxbandl; - int is_p, idx = bi->longIdx[sfb]; + for ( ; sfb<8; sfb++ ) { + int sb = bi->longDiff[sfb]; + int is_p = scalefac[sfb]; /* scale: 0-15 */ + if(is_p != 7) { + real t1,t2; + t1 = tab1[is_p]; t2 = tab2[is_p]; + for ( ; sb > 0; sb--,idx++) { + real v = xr[0][idx]; + xr[0][idx] = REAL_MUL(v, t1); + xr[1][idx] = REAL_MUL(v, t2); + } + } + else + idx += sb; + } + } + } + else { /* ((gr_info->block_type != 2)) */ + int sfb = gr_info->maxbandl; + int is_p,idx = bi->longIdx[sfb]; /* hmm ... maybe the maxbandl stuff for i-stereo is buggy? */ - if (sfb <= 21) { - for (; sfb < 21; sfb++) { - int sb = bi->longDiff[sfb]; + if(sfb <= 21) { + for ( ; sfb<21; sfb++) { + int sb = bi->longDiff[sfb]; + is_p = scalefac[sfb]; /* scale: 0-15 */ + if(is_p != 7) { + real t1,t2; + t1 = tab1[is_p]; t2 = tab2[is_p]; + for ( ; sb > 0; sb--,idx++) { + real v = xr[0][idx]; + xr[0][idx] = REAL_MUL(v, t1); + xr[1][idx] = REAL_MUL(v, t2); + } + } + else + idx += sb; + } - is_p = scalefac[sfb]; /* scale: 0-15 */ - if (is_p != 7) { - real t1, t2; - t1 = tab1[is_p]; - t2 = tab2[is_p]; - for (; sb > 0; sb--, idx++) { - real v = xr[0][idx]; - xr[0][idx] = v * t1; - xr[1][idx] = v * t2; - } - } - else - idx += sb; - } + is_p = scalefac[20]; + if(is_p != 7) { /* copy l-band 20 to l-band 21 */ + int sb; + real t1 = tab1[is_p],t2 = tab2[is_p]; - is_p = scalefac[20]; - if (is_p != 7) { /* copy l-band 20 to l-band 21 */ - int sb; - real t1 = tab1[is_p], t2 = tab2[is_p]; - - for (sb = bi->longDiff[21]; sb > 0; sb--, idx++) { - real v = xr[0][idx]; - - xr[0][idx] = v * t1; - xr[1][idx] = v * t2; - } - } + for ( sb = bi->longDiff[21]; sb > 0; sb--,idx++ ) { + real v = xr[0][idx]; + xr[0][idx] = REAL_MUL(v, t1); + xr[1][idx] = REAL_MUL(v, t2); + } } - } /* ... */ + } /* end: if(sfb <= 21) */ + } /* ... */ } -static void -III_antialias(real xr[SBLIMIT][SSLIMIT], struct gr_info_s *gr_info) -{ - int sblim; +static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info) { + int sblim; - if (gr_info->block_type == 2) { - if (!gr_info->mixed_block_flag) - return; - sblim = 1; - } - else { - sblim = gr_info->maxb - 1; - } + if(gr_info->block_type == 2) { + if(!gr_info->mixed_block_flag) + return; + sblim = 1; + } + else { + sblim = gr_info->maxb-1; + } - /* 31 alias-reduction operations between each pair of sub-bands */ - /* with 8 butterflies between each pair */ + /* 31 alias-reduction operations between each pair of sub-bands */ + /* with 8 butterflies between each pair */ - { - int sb; - real *xr1 = (real *) xr[1]; + { + int sb; + real *xr1=(real *) xr[1]; - if (sblim < 1 || sblim > SBLIMIT) - return; + for(sb=sblim;sb;sb--,xr1+=10) { + int ss; + real *cs=aa_cs,*ca=aa_ca; + real *xr2 = xr1; - for (sb = sblim; sb; sb--, xr1 += 10) { - int ss; - real *cs = aa_cs, *ca = aa_ca; - real *xr2 = xr1; - - for (ss = 7; ss >= 0; ss--) { /* upper and lower butterfly inputs */ - register real bu = *--xr2, bd = *xr1; - - *xr2 = (bu * (*cs)) - (bd * (*ca)); - *xr1++ = (bd * (*cs++)) + (bu * (*ca++)); - } - } - } + for(ss=7;ss>=0;ss--) + { /* upper and lower butterfly inputs */ + register real bu = *--xr2,bd = *xr1; + *xr2 = REAL_MUL(bu, *cs) - REAL_MUL(bd, *ca); + *xr1++ = REAL_MUL(bd, *cs++) + REAL_MUL(bu, *ca++); + } + } + } } -/* +/* This is an optimized DCT from Jeff Tsay's maplay 1.2+ package. Saved one multiplication by doing the 'twiddle factor' stuff together with the window mul. (MH) @@ -1308,329 +1233,426 @@ /* */ /*------------------------------------------------------------------*/ -#define MACRO(v) \ -do { \ - real tmpval; \ - \ - tmpval = tmp[(v)] + tmp[17-(v)]; \ - out2[9+(v)] = tmpval * w[27+(v)]; \ - out2[8-(v)] = tmpval * w[26-(v)]; \ - tmpval = tmp[(v)] - tmp[17-(v)]; \ - ts[SBLIMIT*(8-(v))] = out1[8-(v)] + tmpval * w[8-(v)]; \ - ts[SBLIMIT*(9+(v))] = out1[9+(v)] + tmpval * w[9+(v)]; \ -} while (0) +void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf) +{ +#ifdef NEW_DCT9 + real tmp[18]; +#endif -#ifndef USE_SIMD -static -#endif - void -mpg123_dct36(real * inbuf, real * o1, real * o2, real * wintab, real * tsbuf) -{ - real tmp[18]; + { register real *in = inbuf; - in[17] += in[16]; - in[16] += in[15]; - in[15] += in[14]; - in[14] += in[13]; - in[13] += in[12]; - in[12] += in[11]; - in[11] += in[10]; - in[10] += in[9]; - in[9] += in[8]; - in[8] += in[7]; - in[7] += in[6]; - in[6] += in[5]; - in[5] += in[4]; - in[4] += in[3]; - in[3] += in[2]; - in[2] += in[1]; - in[1] += in[0]; + in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14]; + in[14]+=in[13]; in[13]+=in[12]; in[12]+=in[11]; + in[11]+=in[10]; in[10]+=in[9]; in[9] +=in[8]; + in[8] +=in[7]; in[7] +=in[6]; in[6] +=in[5]; + in[5] +=in[4]; in[4] +=in[3]; in[3] +=in[2]; + in[2] +=in[1]; in[1] +=in[0]; + + in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9]; + in[9] +=in[7]; in[7] +=in[5]; in[5] +=in[3]; in[3] +=in[1]; + + +#ifdef NEW_DCT9 +#if 1 + { + real t3; + { + real t0, t1, t2; + + t0 = REAL_MUL(COS6_2, (in[8] + in[16] - in[4])); + t1 = REAL_MUL(COS6_2, in[12]); + + t3 = in[0]; + t2 = t3 - t1 - t1; + tmp[1] = tmp[7] = t2 - t0; + tmp[4] = t2 + t0 + t0; + t3 += t1; + + t2 = REAL_MUL(COS6_1, (in[10] + in[14] - in[2])); + tmp[1] -= t2; + tmp[7] += t2; + } + { + real t0, t1, t2; + + t0 = REAL_MUL(cos9[0], (in[4] + in[8] )); + t1 = REAL_MUL(cos9[1], (in[8] - in[16])); + t2 = REAL_MUL(cos9[2], (in[4] + in[16])); + + tmp[2] = tmp[6] = t3 - t0 - t2; + tmp[0] = tmp[8] = t3 + t0 + t1; + tmp[3] = tmp[5] = t3 - t1 + t2; + } + } + { + real t1, t2, t3; + + t1 = REAL_MUL(cos18[0], (in[2] + in[10])); + t2 = REAL_MUL(cos18[1], (in[10] - in[14])); + t3 = REAL_MUL(COS6_1, in[6]); + + { + real t0 = t1 + t2 + t3; + tmp[0] += t0; + tmp[8] -= t0; + } - in[17] += in[15]; - in[15] += in[13]; - in[13] += in[11]; - in[11] += in[9]; - in[9] += in[7]; - in[7] += in[5]; - in[5] += in[3]; - in[3] += in[1]; + t2 -= t3; + t1 -= t3; + + t3 = REAL_MUL(cos18[2], (in[2] + in[14])); + + t1 += t3; + tmp[3] += t1; + tmp[5] -= t1; + + t2 -= t3; + tmp[2] += t2; + tmp[6] -= t2; + } + +#else + { + real t0, t1, t2, t3, t4, t5, t6, t7; + + t1 = REAL_MUL(COS6_2, in[12]); + t2 = REAL_MUL(COS6_2, (in[8] + in[16] - in[4])); + + t3 = in[0] + t1; + t4 = in[0] - t1 - t1; + t5 = t4 - t2; + tmp[4] = t4 + t2 + t2; + + t0 = REAL_MUL(cos9[0], (in[4] + in[8])); + t1 = REAL_MUL(cos9[1], (in[8] - in[16])); + t2 = REAL_MUL(cos9[2], (in[4] + in[16])); + + t6 = t3 - t0 - t2; + t0 += t3 + t1; + t3 += t2 - t1; + + t2 = REAL_MUL(cos18[0], (in[2] + in[10])); + t4 = REAL_MUL(cos18[1], (in[10] - in[14])); + t7 = REAL_MUL(COS6_1, in[6]); + + t1 = t2 + t4 + t7; + tmp[0] = t0 + t1; + tmp[8] = t0 - t1; + t1 = REAL_MUL(cos18[2], (in[2] + in[14])); + t2 += t1 - t7; + + tmp[3] = t3 + t2; + t0 = REAL_MUL(COS6_1, (in[10] + in[14] - in[2])); + tmp[5] = t3 - t2; + + t4 -= t1 + t7; + + tmp[1] = t5 - t0; + tmp[7] = t5 + t0; + tmp[2] = t6 + t4; + tmp[6] = t6 - t4; + } +#endif { - real t3; - { - real t0, t1, t2; + real t0, t1, t2, t3, t4, t5, t6, t7; + + t1 = REAL_MUL(COS6_2, in[13]); + t2 = REAL_MUL(COS6_2, (in[9] + in[17] - in[5])); + + t3 = in[1] + t1; + t4 = in[1] - t1 - t1; + t5 = t4 - t2; - t0 = COS6_2 * (in[8] + in[16] - in[4]); - t1 = COS6_2 * in[12]; + t0 = REAL_MUL(cos9[0], (in[5] + in[9])); + t1 = REAL_MUL(cos9[1], (in[9] - in[17])); + + tmp[13] = REAL_MUL((t4 + t2 + t2), tfcos36[17-13]); + t2 = REAL_MUL(cos9[2], (in[5] + in[17])); + + t6 = t3 - t0 - t2; + t0 += t3 + t1; + t3 += t2 - t1; + + t2 = REAL_MUL(cos18[0], (in[3] + in[11])); + t4 = REAL_MUL(cos18[1], (in[11] - in[15])); + t7 = REAL_MUL(COS6_1, in[7]); - t3 = in[0]; - t2 = t3 - t1 - t1; - tmp[1] = tmp[7] = t2 - t0; - tmp[4] = t2 + t0 + t0; - t3 += t1; + t1 = t2 + t4 + t7; + tmp[17] = REAL_MUL((t0 + t1), tfcos36[17-17]); + tmp[9] = REAL_MUL((t0 - t1), tfcos36[17-9]); + t1 = REAL_MUL(cos18[2], (in[3] + in[15])); + t2 += t1 - t7; + + tmp[14] = REAL_MUL((t3 + t2), tfcos36[17-14]); + t0 = REAL_MUL(COS6_1, (in[11] + in[15] - in[3])); + tmp[12] = REAL_MUL((t3 - t2), tfcos36[17-12]); + + t4 -= t1 + t7; - t2 = COS6_1 * (in[10] + in[14] - in[2]); - tmp[1] -= t2; - tmp[7] += t2; - } - { - real t0, t1, t2; + tmp[16] = REAL_MUL((t5 - t0), tfcos36[17-16]); + tmp[10] = REAL_MUL((t5 + t0), tfcos36[17-10]); + tmp[15] = REAL_MUL((t6 + t4), tfcos36[17-15]); + tmp[11] = REAL_MUL((t6 - t4), tfcos36[17-11]); + } - t0 = cos9[0] * (in[4] + in[8]); - t1 = cos9[1] * (in[8] - in[16]); - t2 = cos9[2] * (in[4] + in[16]); +#define MACRO(v) { \ + real tmpval; \ + tmpval = tmp[(v)] + tmp[17-(v)]; \ + out2[9+(v)] = REAL_MUL(tmpval, w[27+(v)]); \ + out2[8-(v)] = REAL_MUL(tmpval, w[26-(v)]); \ + tmpval = tmp[(v)] - tmp[17-(v)]; \ + ts[SBLIMIT*(8-(v))] = out1[8-(v)] + REAL_MUL(tmpval, w[8-(v)]); \ + ts[SBLIMIT*(9+(v))] = out1[9+(v)] + REAL_MUL(tmpval, w[9+(v)]); } + +{ + register real *out2 = o2; + register real *w = wintab; + register real *out1 = o1; + register real *ts = tsbuf; - tmp[2] = tmp[6] = t3 - t0 - t2; - tmp[0] = tmp[8] = t3 + t0 + t1; - tmp[3] = tmp[5] = t3 - t1 + t2; - } - } - { - real t1, t2, t3; + MACRO(0); + MACRO(1); + MACRO(2); + MACRO(3); + MACRO(4); + MACRO(5); + MACRO(6); + MACRO(7); + MACRO(8); +} - t1 = cos18[0] * (in[2] + in[10]); - t2 = cos18[1] * (in[10] - in[14]); - t3 = COS6_1 * in[6]; +#else + + { - { - real t0 = t1 + t2 + t3; - tmp[0] += t0; - tmp[8] -= t0; - } - - t2 -= t3; - t1 -= t3; +#define MACRO0(v) { \ + real tmp; \ + out2[9+(v)] = REAL_MUL((tmp = sum0 + sum1), w[27+(v)]); \ + out2[8-(v)] = REAL_MUL(tmp, w[26-(v)]); } \ + sum0 -= sum1; \ + ts[SBLIMIT*(8-(v))] = out1[8-(v)] + REAL_MUL(sum0, w[8-(v)]); \ + ts[SBLIMIT*(9+(v))] = out1[9+(v)] + REAL_MUL(sum0, w[9+(v)]); +#define MACRO1(v) { \ + real sum0,sum1; \ + sum0 = tmp1a + tmp2a; \ + sum1 = REAL_MUL((tmp1b + tmp2b), tfcos36[(v)]); \ + MACRO0(v); } +#define MACRO2(v) { \ + real sum0,sum1; \ + sum0 = tmp2a - tmp1a; \ + sum1 = REAL_MUL((tmp2b - tmp1b), tfcos36[(v)]); \ + MACRO0(v); } - t3 = cos18[2] * (in[2] + in[14]); + register const real *c = COS9; + register real *out2 = o2; + register real *w = wintab; + register real *out1 = o1; + register real *ts = tsbuf; + + real ta33,ta66,tb33,tb66; - t1 += t3; - tmp[3] += t1; - tmp[5] -= t1; + ta33 = REAL_MUL(in[2*3+0], c[3]); + ta66 = REAL_MUL(in[2*6+0], c[6]); + tb33 = REAL_MUL(in[2*3+1], c[3]); + tb66 = REAL_MUL(in[2*6+1], c[6]); - t2 -= t3; - tmp[2] += t2; - tmp[6] -= t2; + { + real tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a = REAL_MUL(in[2*1+0], c[1]) + ta33 + REAL_MUL(in[2*5+0], c[5]) + REAL_MUL(in[2*7+0], c[7]); + tmp1b = REAL_MUL(in[2*1+1], c[1]) + tb33 + REAL_MUL(in[2*5+1], c[5]) + REAL_MUL(in[2*7+1], c[7]); + tmp2a = REAL_MUL(in[2*2+0], c[2]) + REAL_MUL(in[2*4+0], c[4]) + ta66 + REAL_MUL(in[2*8+0], c[8]); + tmp2b = REAL_MUL(in[2*2+1], c[2]) + REAL_MUL(in[2*4+1], c[4]) + tb66 + REAL_MUL(in[2*8+1], c[8]); + + MACRO1(0); + MACRO2(8); } { - real t0, t1, t2, t3, t4, t5, t6, t7; - - t1 = COS6_2 * in[13]; - t2 = COS6_2 * (in[9] + in[17] - in[5]); - - t3 = in[1] + t1; - t4 = in[1] - t1 - t1; - t5 = t4 - t2; - - t0 = cos9[0] * (in[5] + in[9]); - t1 = cos9[1] * (in[9] - in[17]); - - tmp[13] = (t4 + t2 + t2) * tfcos36[17 - 13]; - t2 = cos9[2] * (in[5] + in[17]); - - t6 = t3 - t0 - t2; - t0 += t3 + t1; - t3 += t2 - t1; + real tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a = REAL_MUL(( in[2*1+0] - in[2*5+0] - in[2*7+0] ), c[3]); + tmp1b = REAL_MUL(( in[2*1+1] - in[2*5+1] - in[2*7+1] ), c[3]); + tmp2a = REAL_MUL(( in[2*2+0] - in[2*4+0] - in[2*8+0] ), c[6]) - in[2*6+0] + in[2*0+0]; + tmp2b = REAL_MUL(( in[2*2+1] - in[2*4+1] - in[2*8+1] ), c[6]) - in[2*6+1] + in[2*0+1]; - t2 = cos18[0] * (in[3] + in[11]); - t4 = cos18[1] * (in[11] - in[15]); - t7 = COS6_1 * in[7]; - - t1 = t2 + t4 + t7; - tmp[17] = (t0 + t1) * tfcos36[17 - 17]; - tmp[9] = (t0 - t1) * tfcos36[17 - 9]; - t1 = cos18[2] * (in[3] + in[15]); - t2 += t1 - t7; - - tmp[14] = (t3 + t2) * tfcos36[17 - 14]; - t0 = COS6_1 * (in[11] + in[15] - in[3]); - tmp[12] = (t3 - t2) * tfcos36[17 - 12]; - - t4 -= t1 + t7; - - tmp[16] = (t5 - t0) * tfcos36[17 - 16]; - tmp[10] = (t5 + t0) * tfcos36[17 - 10]; - tmp[15] = (t6 + t4) * tfcos36[17 - 15]; - tmp[11] = (t6 - t4) * tfcos36[17 - 11]; + MACRO1(1); + MACRO2(7); } { - register real *out2 = o2; - register real *w = wintab; - register real *out1 = o1; - register real *ts = tsbuf; + real tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a = REAL_MUL(in[2*1+0], c[5]) - ta33 - REAL_MUL(in[2*5+0], c[7]) + REAL_MUL(in[2*7+0], c[1]); + tmp1b = REAL_MUL(in[2*1+1], c[5]) - tb33 - REAL_MUL(in[2*5+1], c[7]) + REAL_MUL(in[2*7+1], c[1]); + tmp2a = - REAL_MUL(in[2*2+0], c[8]) - REAL_MUL(in[2*4+0], c[2]) + ta66 + REAL_MUL(in[2*8+0], c[4]); + tmp2b = - REAL_MUL(in[2*2+1], c[8]) - REAL_MUL(in[2*4+1], c[2]) + tb66 + REAL_MUL(in[2*8+1], c[4]); + + MACRO1(2); + MACRO2(6); + } - MACRO(0); - MACRO(1); - MACRO(2); - MACRO(3); - MACRO(4); - MACRO(5); - MACRO(6); - MACRO(7); - MACRO(8); + { + real tmp1a,tmp2a,tmp1b,tmp2b; + tmp1a = REAL_MUL(in[2*1+0], c[7]) - ta33 + REAL_MUL(in[2*5+0], c[1]) - REAL_MUL(in[2*7+0], c[5]); + tmp1b = REAL_MUL(in[2*1+1], c[7]) - tb33 + REAL_MUL(in[2*5+1], c[1]) - REAL_MUL(in[2*7+1], c[5]); + tmp2a = - REAL_MUL(in[2*2+0], c[4]) + REAL_MUL(in[2*4+0], c[8]) + ta66 - REAL_MUL(in[2*8+0], c[2]); + tmp2b = - REAL_MUL(in[2*2+1], c[4]) + REAL_MUL(in[2*4+1], c[8]) + tb66 - REAL_MUL(in[2*8+1], c[2]); + + MACRO1(3); + MACRO2(5); } + + { + real sum0,sum1; + sum0 = in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0]; + sum1 = REAL_MUL((in[2*0+1] - in[2*2+1] + in[2*4+1] - in[2*6+1] + in[2*8+1] ), tfcos36[4]); + MACRO0(4); + } + } +#endif + + } } /* * new DCT12 */ -static void -dct12(real * in, real * rawout1, real * rawout2, - register real * wi, register real * ts) +static void dct12(real *in,real *rawout1,real *rawout2,register real *wi,register real *ts) { +#define DCT12_PART1 \ + in5 = in[5*3]; \ + in5 += (in4 = in[4*3]); \ + in4 += (in3 = in[3*3]); \ + in3 += (in2 = in[2*3]); \ + in2 += (in1 = in[1*3]); \ + in1 += (in0 = in[0*3]); \ + \ + in5 += in3; in3 += in1; \ + \ + in2 = REAL_MUL(in2, COS6_1); \ + in3 = REAL_MUL(in3, COS6_1); \ -#define DCT12_PART1() \ -do { \ - in5 = in[5*3]; \ - in5 += (in4 = in[4*3]); \ - in4 += (in3 = in[3*3]); \ - in3 += (in2 = in[2*3]); \ - in2 += (in1 = in[1*3]); \ - in1 += (in0 = in[0*3]); \ - \ - in5 += in3; in3 += in1; \ - \ - in2 *= COS6_1; \ - in3 *= COS6_1; \ -} while (0) - -#define DCT12_PART2() \ -do { \ - in0 += in4 * COS6_2; \ - \ - in4 = in0 + in2; \ - in0 -= in2; \ - \ - in1 += in5 * COS6_2; \ - \ - in5 = (in1 + in3) * tfcos12[0]; \ - in1 = (in1 - in3) * tfcos12[2]; \ - \ - in3 = in4 + in5; \ - in4 -= in5; \ - \ - in2 = in0 + in1; \ - in0 -= in1; \ -} while (0) +#define DCT12_PART2 \ + in0 += REAL_MUL(in4, COS6_2); \ + \ + in4 = in0 + in2; \ + in0 -= in2; \ + \ + in1 += REAL_MUL(in5, COS6_2); \ + \ + in5 = REAL_MUL((in1 + in3), tfcos12[0]); \ + in1 = REAL_MUL((in1 - in3), tfcos12[2]); \ + \ + in3 = in4 + in5; \ + in4 -= in5; \ + \ + in2 = in0 + in1; \ + in0 -= in1; - { - real in0, in1, in2, in3, in4, in5; - register real *out1 = rawout1; + { + real in0,in1,in2,in3,in4,in5; + register real *out1 = rawout1; + ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2]; + ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5]; + + DCT12_PART1 - ts[SBLIMIT * 0] = out1[0]; - ts[SBLIMIT * 1] = out1[1]; - ts[SBLIMIT * 2] = out1[2]; - ts[SBLIMIT * 3] = out1[3]; - ts[SBLIMIT * 4] = out1[4]; - ts[SBLIMIT * 5] = out1[5]; - - DCT12_PART1(); - - { - real tmp0, tmp1 = (in0 - in4); - - { - real tmp2 = (in1 - in5) * tfcos12[1]; + { + real tmp0,tmp1 = (in0 - in4); + { + real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]); + tmp0 = tmp1 + tmp2; + tmp1 -= tmp2; + } + ts[(17-1)*SBLIMIT] = out1[17-1] + REAL_MUL(tmp0, wi[11-1]); + ts[(12+1)*SBLIMIT] = out1[12+1] + REAL_MUL(tmp0, wi[6+1]); + ts[(6 +1)*SBLIMIT] = out1[6 +1] + REAL_MUL(tmp1, wi[1]); + ts[(11-1)*SBLIMIT] = out1[11-1] + REAL_MUL(tmp1, wi[5-1]); + } - tmp0 = tmp1 + tmp2; - tmp1 -= tmp2; - } - ts[(17 - 1) * SBLIMIT] = out1[17 - 1] + tmp0 * wi[11 - 1]; - ts[(12 + 1) * SBLIMIT] = out1[12 + 1] + tmp0 * wi[6 + 1]; - ts[(6 + 1) * SBLIMIT] = out1[6 + 1] + tmp1 * wi[1]; - ts[(11 - 1) * SBLIMIT] = out1[11 - 1] + tmp1 * wi[5 - 1]; - } + DCT12_PART2 - DCT12_PART2(); - - ts[(17 - 0) * SBLIMIT] = out1[17 - 0] + in2 * wi[11 - 0]; - ts[(12 + 0) * SBLIMIT] = out1[12 + 0] + in2 * wi[6 + 0]; - ts[(12 + 2) * SBLIMIT] = out1[12 + 2] + in3 * wi[6 + 2]; - ts[(17 - 2) * SBLIMIT] = out1[17 - 2] + in3 * wi[11 - 2]; + ts[(17-0)*SBLIMIT] = out1[17-0] + REAL_MUL(in2, wi[11-0]); + ts[(12+0)*SBLIMIT] = out1[12+0] + REAL_MUL(in2, wi[6+0]); + ts[(12+2)*SBLIMIT] = out1[12+2] + REAL_MUL(in3, wi[6+2]); + ts[(17-2)*SBLIMIT] = out1[17-2] + REAL_MUL(in3, wi[11-2]); - ts[(6 + 0) * SBLIMIT] = out1[6 + 0] + in0 * wi[0]; - ts[(11 - 0) * SBLIMIT] = out1[11 - 0] + in0 * wi[5 - 0]; - ts[(6 + 2) * SBLIMIT] = out1[6 + 2] + in4 * wi[2]; - ts[(11 - 2) * SBLIMIT] = out1[11 - 2] + in4 * wi[5 - 2]; - } - - in++; + ts[(6 +0)*SBLIMIT] = out1[6+0] + REAL_MUL(in0, wi[0]); + ts[(11-0)*SBLIMIT] = out1[11-0] + REAL_MUL(in0, wi[5-0]); + ts[(6 +2)*SBLIMIT] = out1[6+2] + REAL_MUL(in4, wi[2]); + ts[(11-2)*SBLIMIT] = out1[11-2] + REAL_MUL(in4, wi[5-2]); + } - { - real in0, in1, in2, in3, in4, in5; - register real *out2 = rawout2; - - DCT12_PART1(); + in++; - { - real tmp0, tmp1 = (in0 - in4); - - { - real tmp2 = (in1 - in5) * tfcos12[1]; + { + real in0,in1,in2,in3,in4,in5; + register real *out2 = rawout2; + + DCT12_PART1 - tmp0 = tmp1 + tmp2; - tmp1 -= tmp2; - } - out2[5 - 1] = tmp0 * wi[11 - 1]; - out2[0 + 1] = tmp0 * wi[6 + 1]; - ts[(12 + 1) * SBLIMIT] += tmp1 * wi[1]; - ts[(17 - 1) * SBLIMIT] += tmp1 * wi[5 - 1]; - } - - DCT12_PART2(); + { + real tmp0,tmp1 = (in0 - in4); + { + real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]); + tmp0 = tmp1 + tmp2; + tmp1 -= tmp2; + } + out2[5-1] = REAL_MUL(tmp0, wi[11-1]); + out2[0+1] = REAL_MUL(tmp0, wi[6+1]); + ts[(12+1)*SBLIMIT] += REAL_MUL(tmp1, wi[1]); + ts[(17-1)*SBLIMIT] += REAL_MUL(tmp1, wi[5-1]); + } - out2[5 - 0] = in2 * wi[11 - 0]; - out2[0 + 0] = in2 * wi[6 + 0]; - out2[0 + 2] = in3 * wi[6 + 2]; - out2[5 - 2] = in3 * wi[11 - 2]; + DCT12_PART2 + + out2[5-0] = REAL_MUL(in2, wi[11-0]); + out2[0+0] = REAL_MUL(in2, wi[6+0]); + out2[0+2] = REAL_MUL(in3, wi[6+2]); + out2[5-2] = REAL_MUL(in3, wi[11-2]); - ts[(12 + 0) * SBLIMIT] += in0 * wi[0]; - ts[(17 - 0) * SBLIMIT] += in0 * wi[5 - 0]; - ts[(12 + 2) * SBLIMIT] += in4 * wi[2]; - ts[(17 - 2) * SBLIMIT] += in4 * wi[5 - 2]; - } + ts[(12+0)*SBLIMIT] += REAL_MUL(in0, wi[0]); + ts[(17-0)*SBLIMIT] += REAL_MUL(in0, wi[5-0]); + ts[(12+2)*SBLIMIT] += REAL_MUL(in4, wi[2]); + ts[(17-2)*SBLIMIT] += REAL_MUL(in4, wi[5-2]); + } - in++; - - { - real in0, in1, in2, in3, in4, in5; - register real *out2 = rawout2; - - out2[12] = out2[13] = out2[14] = out2[15] = out2[16] = out2[17] = 0.0; + in++; - DCT12_PART1(); + { + real in0,in1,in2,in3,in4,in5; + register real *out2 = rawout2; + out2[12]=out2[13]=out2[14]=out2[15]=out2[16]=out2[17]=0.0; - { - real tmp0, tmp1 = (in0 - in4); - - { - real tmp2 = (in1 - in5) * tfcos12[1]; + DCT12_PART1 - tmp0 = tmp1 + tmp2; - tmp1 -= tmp2; - } - out2[11 - 1] = tmp0 * wi[11 - 1]; - out2[6 + 1] = tmp0 * wi[6 + 1]; - out2[0 + 1] += tmp1 * wi[1]; - out2[5 - 1] += tmp1 * wi[5 - 1]; - } - - DCT12_PART2(); + { + real tmp0,tmp1 = (in0 - in4); + { + real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]); + tmp0 = tmp1 + tmp2; + tmp1 -= tmp2; + } + out2[11-1] = REAL_MUL(tmp0, wi[11-1]); + out2[6 +1] = REAL_MUL(tmp0, wi[6+1]); + out2[0+1] += REAL_MUL(tmp1, wi[1]); + out2[5-1] += REAL_MUL(tmp1, wi[5-1]); + } - out2[11 - 0] = in2 * wi[11 - 0]; - out2[6 + 0] = in2 * wi[6 + 0]; - out2[6 + 2] = in3 * wi[6 + 2]; - out2[11 - 2] = in3 * wi[11 - 2]; + DCT12_PART2 - out2[0 + 0] += in0 * wi[0]; - out2[5 - 0] += in0 * wi[5 - 0]; - out2[0 + 2] += in4 * wi[2]; - out2[5 - 2] += in4 * wi[5 - 2]; - } + out2[11-0] = REAL_MUL(in2, wi[11-0]); + out2[6 +0] = REAL_MUL(in2, wi[6+0]); + out2[6 +2] = REAL_MUL(in3, wi[6+2]); + out2[11-2] = REAL_MUL(in3, wi[11-2]); + + out2[0+0] += REAL_MUL(in0, wi[0]); + out2[5-0] += REAL_MUL(in0, wi[5-0]); + out2[0+2] += REAL_MUL(in4, wi[2]); + out2[5-2] += REAL_MUL(in4, wi[5-2]); + } } /* @@ -1658,8 +1680,8 @@ if (gr_info->mixed_block_flag) { sb = 2; - DCT36(fsIn[0], rawout1, rawout2, win[0], tspnt); - DCT36(fsIn[1], rawout1 + 18, rawout2 + 18, win1[0], tspnt + 1); + dct36(fsIn[0], rawout1, rawout2, win[0], tspnt); + dct36(fsIn[1], rawout1 + 18, rawout2 + 18, win1[0], tspnt + 1); rawout1 += 36; rawout2 += 36; tspnt += 2; @@ -1677,8 +1699,8 @@ else { for (; sb < gr_info->maxb; sb += 2, tspnt += 2, rawout1 += 36, rawout2 += 36) { - DCT36(fsIn[sb], rawout1, rawout2, win[bt], tspnt); - DCT36(fsIn[sb + 1], rawout1 + 18, rawout2 + 18, win1[bt], + dct36(fsIn[sb], rawout1, rawout2, win[bt], tspnt); + dct36(fsIn[sb + 1], rawout1 + 18, rawout2 + 18, win1[bt], tspnt + 1); } } @@ -1691,10 +1713,6 @@ } } } - -/* - * main layer3 handler - */ int mpg123_do_layer3(struct frame *fr) {
--- a/Plugins/Input/mpg123/mpg123.h Tue Nov 08 12:04:15 2005 -0800 +++ b/Plugins/Input/mpg123/mpg123.h Wed Nov 09 16:40:03 2005 -0800 @@ -45,6 +45,18 @@ #define ENCODING_SEPARATOR " ,:;|/" +#define MAXFRAMESIZE 4096 + +#define DOUBLE_TO_REAL(x) (x) +#define REAL_MUL(x, y) (x * y) + +#ifndef REAL_PLUS_32767 +# define REAL_PLUS_32767 32767.0 +#endif +#ifndef REAL_MINUS_32768 +# define REAL_MINUS_32768 -32768.0 +#endif + struct id3v1tag_t { char tag[3]; /* always "TAG": defines ID3v1 tag 128 bytes before EOF */ char title[30]; @@ -159,6 +171,26 @@ extern struct bitstream_info bsi; +struct mpstr { + int bsize; + int framesize; + int fsizeold; + struct frame fr; + /* int (*do_layer)(struct mpstr *,struct frame *fr,int,struct audio_info_struct *); */ + unsigned char bsspace[2][MAXFRAMESIZE+512]; /* MAXFRAMESIZE */ + real hybrid_block[2][2][SBLIMIT*SSLIMIT]; + int hybrid_blc[2]; + unsigned long header; + int bsnum; + real synth_buffs[2][2][0x110]; + int synth_bo; + + struct bitstream_info bsi; +}; + + +#define AUSHIFT 3 + /* ------ Declarations from "http.c" ------ */ extern int mpg123_http_open(char *url);