3
* Mpeg Layer-1 audio decoder
4
* --------------------------
5
* copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
8
* may have a few bugs after last optimization ...
15
/* Used by the getbits macros */
16
static unsigned long rval;
19
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;
27
int jsbound = fr->jsbound;
29
for (i = 0; i < jsbound; i++)
31
*ba++ = mpg123_getbits(4);
32
*ba++ = mpg123_getbits(4);
34
for (i = jsbound; i < SBLIMIT; i++)
35
*ba++ = mpg123_getbits(4);
39
for (i = 0; i < jsbound; i++)
42
*sca++ = mpg123_getbits(6);
44
*sca++ = mpg123_getbits(6);
46
for (i = jsbound; i < SBLIMIT; i++)
49
*sca++ = mpg123_getbits(6);
50
*sca++ = mpg123_getbits(6);
57
for (i = 0; i < SBLIMIT; i++)
58
*ba++ = mpg123_getbits(4);
60
for (i = 0; i < SBLIMIT; i++)
62
*sca++ = mpg123_getbits(6);
67
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;
78
int jsbound = fr->jsbound;
79
register real *f0 = fraction[0];
80
register real *f1 = fraction[1];
83
for (sample = smpb, i = 0; i < jsbound; i++)
86
*sample++ = mpg123_getbits(n + 1);
88
*sample++ = mpg123_getbits(n + 1);
90
for (i = jsbound; i < SBLIMIT; i++)
92
*sample++ = mpg123_getbits(n + 1);
95
for (sample = smpb, i = 0; i < jsbound; i++)
98
*f0++ = (real) (((-1) << n) + (*sample++) + 1) * mpg123_muls[n + 1][*sca++];
102
*f1++ = (real) (((-1) << n) + (*sample++) + 1) * mpg123_muls[n + 1][*sca++];
106
for (i = jsbound; i < SBLIMIT; i++)
110
real samp = (((-1) << n) + (*sample++) + 1);
112
*f0++ = samp * mpg123_muls[n + 1][*sca++];
113
*f1++ = samp * mpg123_muls[n + 1][*sca++];
118
for (i = fr->down_sample_sblimit; i < 32; i++)
119
fraction[0][i] = fraction[1][i] = 0.0;
123
register real *f0 = fraction[0];
126
for (sample = smpb, i = 0; i < SBLIMIT; i++)
128
*sample++ = mpg123_getbits(n + 1);
130
for (sample = smpb, i = 0; i < SBLIMIT; i++)
133
*f0++ = (real) (((-1) << n) + (*sample++) + 1) * mpg123_muls[n + 1][*sca++];
137
for (i = fr->down_sample_sblimit; i < 32; i++)
138
fraction[0][i] = 0.0;
142
int mpg123_do_layer1(struct frame *fr)
144
int i, stereo = fr->stereo;
145
unsigned int balloc[2 * SBLIMIT];
146
unsigned int scale_index[2][SBLIMIT];
147
real fraction[2][SBLIMIT];
148
int single = fr->single;
150
fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext << 2) + 4 : 32;
152
if (stereo == 1 || single == 3)
155
I_step_one(balloc, scale_index, fr);
157
for (i = 0; i < SCALE_BLOCK; i++)
159
I_step_two(fraction, balloc, scale_index, fr);
163
(fr->synth_mono) ((real *) fraction[single], mpg123_pcm_sample, &mpg123_pcm_point);
167
int p1 = mpg123_pcm_point;
169
(fr->synth) ((real *) fraction[0], 0, mpg123_pcm_sample, &p1);
170
(fr->synth) ((real *) fraction[1], 1, mpg123_pcm_sample, &mpg123_pcm_point);
174
if (mpg123_info->output_audio)
177
mpg123_ip.add_vis_pcm(mpg123_ip.output->written_time(), mpg123_cfg.resolution == 16 ? FMT_S16_NE : FMT_U8,
178
mpg123_cfg.channels == 2 ? fr->stereo : 1, mpg123_pcm_point, mpg123_pcm_sample);
179
while (mpg123_ip.output->buffer_free() < mpg123_pcm_point && mpg123_info->going && mpg123_info->jump_to_time == -1)
181
if (mpg123_info->going && mpg123_info->jump_to_time == -1)
182
mpg123_ip.output->write_audio(mpg123_pcm_sample, mpg123_pcm_point);
185
mpg123_pcm_point = 0;