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 ...
12 * Modified for use with MPlayer, for details see the changelog at
13 * http://svn.mplayerhq.hu/mplayer/trunk/
16 * The above-mentioned README file has the following to say about licensing:
18 * COPYING: you may use this source under LGPL terms!
23 static void I_step_one(unsigned int balloc
[], unsigned int scale_index
[2][SBLIMIT
],struct frame
*fr
)
25 unsigned int *ba
=balloc
;
26 unsigned int *sca
= (unsigned int *) scale_index
;
30 int jsbound
= fr
->jsbound
;
31 for (i
=0;i
<jsbound
;i
++) {
35 for (i
=jsbound
;i
<SBLIMIT
;i
++)
40 for (i
=0;i
<jsbound
;i
++) {
46 for (i
=jsbound
;i
<SBLIMIT
;i
++)
54 for (i
=0;i
<SBLIMIT
;i
++)
57 for (i
=0;i
<SBLIMIT
;i
++)
63 static void I_step_two(real fraction
[2][SBLIMIT
],unsigned int balloc
[2*SBLIMIT
],
64 unsigned int scale_index
[2][SBLIMIT
],struct frame
*fr
)
67 int smpb
[2*SBLIMIT
]; /* values: 0-65535 */
69 register unsigned int *ba
;
70 register unsigned int *sca
= (unsigned int *) scale_index
;
73 int jsbound
= fr
->jsbound
;
74 register real
*f0
= fraction
[0];
75 register real
*f1
= fraction
[1];
77 for (sample
=smpb
,i
=0;i
<jsbound
;i
++) {
79 *sample
++ = getbits(n
+1);
81 *sample
++ = getbits(n
+1);
83 for (i
=jsbound
;i
<SBLIMIT
;i
++)
85 *sample
++ = getbits(n
+1);
88 for (sample
=smpb
,i
=0;i
<jsbound
;i
++) {
90 *f0
++ = (real
) ( ((-1)<<n
) + (*sample
++) + 1) * muls
[n
+1][*sca
++];
94 *f1
++ = (real
) ( ((-1)<<n
) + (*sample
++) + 1) * muls
[n
+1][*sca
++];
98 for (i
=jsbound
;i
<SBLIMIT
;i
++) {
100 real samp
= ( ((-1)<<n
) + (*sample
++) + 1);
101 *f0
++ = samp
* muls
[n
+1][*sca
++];
102 *f1
++ = samp
* muls
[n
+1][*sca
++];
107 for(i
=fr
->down_sample_sblimit
;i
<32;i
++)
108 fraction
[0][i
] = fraction
[1][i
] = 0.0;
111 register real
*f0
= fraction
[0];
113 for (sample
=smpb
,i
=0;i
<SBLIMIT
;i
++)
115 *sample
++ = getbits(n
+1);
117 for (sample
=smpb
,i
=0;i
<SBLIMIT
;i
++) {
119 *f0
++ = (real
) ( ((-1)<<n
) + (*sample
++) + 1) * muls
[n
+1][*sca
++];
123 for(i
=fr
->down_sample_sblimit
;i
<32;i
++)
124 fraction
[0][i
] = 0.0;
128 static int do_layer1(struct frame
*fr
,int single
)
131 int i
,stereo
= fr
->stereo
;
132 unsigned int balloc
[2*SBLIMIT
];
133 unsigned int scale_index
[2][SBLIMIT
];
134 DECLARE_ALIGNED(16, real
, fraction
[2][SBLIMIT
]);
135 // int single = fr->single;
137 // printf("do_layer1(0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X )\n",
138 // wordpointer[0],wordpointer[1],wordpointer[2],wordpointer[3],wordpointer[4],wordpointer[5],wordpointer[6],wordpointer[7]);
140 fr
->jsbound
= (fr
->mode
== MPG_MD_JOINT_STEREO
) ?
141 (fr
->mode_ext
<<2)+4 : 32;
143 if(stereo
== 1 || single
== 3)
146 I_step_one(balloc
,scale_index
,fr
);
148 for (i
=0;i
<SCALE_BLOCK
;i
++)
150 I_step_two(fraction
,balloc
,scale_index
,fr
);
154 clip
+= (fr
->synth_mono
)( (real
*) fraction
[single
],pcm_sample
,&pcm_point
);
158 clip
+= (fr
->synth
)( (real
*) fraction
[0],0,pcm_sample
,&p1
);
159 clip
+= (fr
->synth
)( (real
*) fraction
[1],1,pcm_sample
,&pcm_point
);