2 * Modified for use with MPlayer, for details see the CVS changelog at
3 * http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
8 * Mpeg Layer-1 audio decoder
9 * --------------------------
10 * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
13 * may have a few bugs after last optimization ...
19 static void I_step_one(unsigned int balloc
[], unsigned int scale_index
[2][SBLIMIT
],struct frame
*fr
)
21 unsigned int *ba
=balloc
;
22 unsigned int *sca
= (unsigned int *) scale_index
;
26 int jsbound
= fr
->jsbound
;
27 for (i
=0;i
<jsbound
;i
++) {
31 for (i
=jsbound
;i
<SBLIMIT
;i
++)
36 for (i
=0;i
<jsbound
;i
++) {
42 for (i
=jsbound
;i
<SBLIMIT
;i
++)
50 for (i
=0;i
<SBLIMIT
;i
++)
53 for (i
=0;i
<SBLIMIT
;i
++)
59 static void I_step_two(real fraction
[2][SBLIMIT
],unsigned int balloc
[2*SBLIMIT
],
60 unsigned int scale_index
[2][SBLIMIT
],struct frame
*fr
)
63 int smpb
[2*SBLIMIT
]; /* values: 0-65535 */
65 register unsigned int *ba
;
66 register unsigned int *sca
= (unsigned int *) scale_index
;
69 int jsbound
= fr
->jsbound
;
70 register real
*f0
= fraction
[0];
71 register real
*f1
= fraction
[1];
73 for (sample
=smpb
,i
=0;i
<jsbound
;i
++) {
75 *sample
++ = getbits(n
+1);
77 *sample
++ = getbits(n
+1);
79 for (i
=jsbound
;i
<SBLIMIT
;i
++)
81 *sample
++ = getbits(n
+1);
84 for (sample
=smpb
,i
=0;i
<jsbound
;i
++) {
86 *f0
++ = (real
) ( ((-1)<<n
) + (*sample
++) + 1) * muls
[n
+1][*sca
++];
90 *f1
++ = (real
) ( ((-1)<<n
) + (*sample
++) + 1) * muls
[n
+1][*sca
++];
94 for (i
=jsbound
;i
<SBLIMIT
;i
++) {
96 real samp
= ( ((-1)<<n
) + (*sample
++) + 1);
97 *f0
++ = samp
* muls
[n
+1][*sca
++];
98 *f1
++ = samp
* muls
[n
+1][*sca
++];
103 for(i
=fr
->down_sample_sblimit
;i
<32;i
++)
104 fraction
[0][i
] = fraction
[1][i
] = 0.0;
107 register real
*f0
= fraction
[0];
109 for (sample
=smpb
,i
=0;i
<SBLIMIT
;i
++)
111 *sample
++ = getbits(n
+1);
113 for (sample
=smpb
,i
=0;i
<SBLIMIT
;i
++) {
115 *f0
++ = (real
) ( ((-1)<<n
) + (*sample
++) + 1) * muls
[n
+1][*sca
++];
119 for(i
=fr
->down_sample_sblimit
;i
<32;i
++)
120 fraction
[0][i
] = 0.0;
124 static int do_layer1(struct frame
*fr
,int single
)
127 int i
,stereo
= fr
->stereo
;
128 unsigned int balloc
[2*SBLIMIT
];
129 unsigned int scale_index
[2][SBLIMIT
];
130 real fraction
[2][SBLIMIT
];
131 // int single = fr->single;
133 // printf("do_layer1(0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X )\n",
134 // wordpointer[0],wordpointer[1],wordpointer[2],wordpointer[3],wordpointer[4],wordpointer[5],wordpointer[6],wordpointer[7]);
136 fr
->jsbound
= (fr
->mode
== MPG_MD_JOINT_STEREO
) ?
137 (fr
->mode_ext
<<2)+4 : 32;
139 if(stereo
== 1 || single
== 3)
142 I_step_one(balloc
,scale_index
,fr
);
144 for (i
=0;i
<SCALE_BLOCK
;i
++)
146 I_step_two(fraction
,balloc
,scale_index
,fr
);
150 clip
+= (fr
->synth_mono
)( (real
*) fraction
[single
],pcm_sample
,&pcm_point
);
154 clip
+= (fr
->synth
)( (real
*) fraction
[0],0,pcm_sample
,&p1
);
155 clip
+= (fr
->synth
)( (real
*) fraction
[1],1,pcm_sample
,&pcm_point
);