2
* Mpeg Layer-1 audio decoder
3
* --------------------------
4
* copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
7
* may have a few bugs after last optimization ...
15
void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr)
17
unsigned int *ba=balloc;
18
unsigned int *sca = (unsigned int *) scale_index;
22
int jsbound = fr->jsbound;
23
for (i=0;i<jsbound;i++) {
24
*ba++ = getbits(&bsi,4);
25
*ba++ = getbits(&bsi,4);
27
for (i=jsbound;i<SBLIMIT;i++)
28
*ba++ = getbits(&bsi,4);
32
for (i=0;i<jsbound;i++) {
34
*sca++ = getbits(&bsi,6);
36
*sca++ = getbits(&bsi,6);
38
for (i=jsbound;i<SBLIMIT;i++)
40
*sca++ = getbits(&bsi,6);
41
*sca++ = getbits(&bsi,6);
46
for (i=0;i<SBLIMIT;i++)
47
*ba++ = getbits(&bsi,4);
49
for (i=0;i<SBLIMIT;i++)
51
*sca++ = getbits(&bsi,6);
55
void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
56
unsigned int scale_index[2][SBLIMIT],struct frame *fr)
59
int smpb[2*SBLIMIT]; /* values: 0-65535 */
61
register unsigned int *ba;
62
register unsigned int *sca = (unsigned int *) scale_index;
65
int jsbound = fr->jsbound;
66
register real *f0 = fraction[0];
67
register real *f1 = fraction[1];
69
for (sample=smpb,i=0;i<jsbound;i++) {
71
*sample++ = getbits(&bsi,n+1);
73
*sample++ = getbits(&bsi,n+1);
75
for (i=jsbound;i<SBLIMIT;i++)
77
*sample++ = getbits(&bsi,n+1);
80
for (sample=smpb,i=0;i<jsbound;i++) {
82
*f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
86
*f1++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
90
for (i=jsbound;i<SBLIMIT;i++) {
92
real samp = ( ((-1)<<n) + (*sample++) + 1);
93
*f0++ = samp * muls[n+1][*sca++];
94
*f1++ = samp * muls[n+1][*sca++];
99
for(i=fr->down_sample_sblimit;i<32;i++)
100
fraction[0][i] = fraction[1][i] = 0.0;
103
register real *f0 = fraction[0];
105
for (sample=smpb,i=0;i<SBLIMIT;i++)
107
*sample++ = getbits(&bsi,n+1);
109
for (sample=smpb,i=0;i<SBLIMIT;i++) {
111
*f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
115
for(i=fr->down_sample_sblimit;i<32;i++)
116
fraction[0][i] = 0.0;
120
int do_layer1(struct mpstr *mp,struct frame *fr,int outmode,struct audio_info_struct *ai)
123
int i,stereo = fr->stereo;
124
unsigned int balloc[2*SBLIMIT];
125
unsigned int scale_index[2][SBLIMIT];
126
real fraction[2][SBLIMIT];
127
int single = fr->single;
129
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext<<2)+4 : 32;
131
if(stereo == 1 || single == 3)
134
I_step_one(balloc,scale_index,fr);
136
for (i=0;i<SCALE_BLOCK;i++)
138
I_step_two(fraction,balloc,scale_index,fr);
142
clip += (fr->synth_mono)( (real *) fraction[single],pcm_sample,&pcm_point);
146
clip += (fr->synth)( (real *) fraction[0],0,pcm_sample,&p1);
147
clip += (fr->synth)( (real *) fraction[1],1,pcm_sample,&pcm_point);
150
if(pcm_point >= audiobufsize)
151
audio_flush(outmode,ai);