2 * Mpeg Layer-1 audio decoder
3 * --------------------------
4 * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
5 * This file has been copied from mpglib.
8 * may have a few bugs after last optimization ...
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 static void I_step_one(unsigned int balloc
[], unsigned int scale_index
[2][SBLIMIT
],struct frame
*fr
)
29 unsigned int *ba
=balloc
;
30 unsigned int *sca
= (unsigned int *) scale_index
;
34 int jsbound
= fr
->jsbound
;
35 for (i
=0;i
<jsbound
;i
++) {
39 for (i
=jsbound
;i
<SBLIMIT
;i
++)
44 for (i
=0;i
<jsbound
;i
++) {
50 for (i
=jsbound
;i
<SBLIMIT
;i
++)
58 for (i
=0;i
<SBLIMIT
;i
++)
61 for (i
=0;i
<SBLIMIT
;i
++)
67 static void I_step_two(real fraction
[2][SBLIMIT
],unsigned int balloc
[2*SBLIMIT
],
68 unsigned int scale_index
[2][SBLIMIT
],struct frame
*fr
)
71 int smpb
[2*SBLIMIT
]; /* values: 0-65535 */
73 register unsigned int *ba
;
74 register unsigned int *sca
= (unsigned int *) scale_index
;
77 int jsbound
= fr
->jsbound
;
78 register real
*f0
= fraction
[0];
79 register real
*f1
= fraction
[1];
81 for (sample
=smpb
,i
=0;i
<jsbound
;i
++) {
83 *sample
++ = getbits(n
+1);
85 *sample
++ = getbits(n
+1);
87 for (i
=jsbound
;i
<SBLIMIT
;i
++)
89 *sample
++ = getbits(n
+1);
92 for (sample
=smpb
,i
=0;i
<jsbound
;i
++) {
94 *f0
++ = (real
) ( ((-1)<<n
) + (*sample
++) + 1) * muls
[n
+1][*sca
++];
98 *f1
++ = (real
) ( ((-1)<<n
) + (*sample
++) + 1) * muls
[n
+1][*sca
++];
102 for (i
=jsbound
;i
<SBLIMIT
;i
++) {
104 real samp
= ( ((-1)<<n
) + (*sample
++) + 1);
105 *f0
++ = samp
* muls
[n
+1][*sca
++];
106 *f1
++ = samp
* muls
[n
+1][*sca
++];
113 register real
*f0
= fraction
[0];
115 for (sample
=smpb
,i
=0;i
<SBLIMIT
;i
++)
117 *sample
++ = getbits(n
+1);
119 for (sample
=smpb
,i
=0;i
<SBLIMIT
;i
++) {
121 *f0
++ = (real
) ( ((-1)<<n
) + (*sample
++) + 1) * muls
[n
+1][*sca
++];
128 int do_layer1(struct frame
*fr
,unsigned char *pcm_sample
,int *pcm_point
)
131 int i
,stereo
= fr
->stereo
;
132 unsigned int balloc
[2*SBLIMIT
];
133 unsigned int scale_index
[2][SBLIMIT
];
134 real fraction
[2][SBLIMIT
];
135 int single
= fr
->single
;
137 fr
->jsbound
= (fr
->mode
== MPG_MD_JOINT_STEREO
) ? (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
);
149 clip
+= synth_1to1_mono(fr
->mp
,(real
*)fraction
[single
],pcm_sample
,pcm_point
);
153 clip
+= synth_1to1(fr
->mp
,(real
*)fraction
[0],0,pcm_sample
,&p1
);
154 clip
+= synth_1to1(fr
->mp
,(real
*)fraction
[1],1,pcm_sample
,pcm_point
);