r1053: Add Russian translation.
[cinelerra_cv.git] / libmpeg3 / audio / layer2.c
blob79217fe2c7305fe9db1071e0a96751fded435dd7
1 /*
2 * most other tables are calculated on program start (which is (of course)
3 * not ISO-conform) ..
4 * Layer-3 huffman table is in huffman.h
5 */
7 #include "mpeg3private.h"
8 #include "mpeg3protos.h"
9 #include "tables.h"
11 static struct al_table alloc_0[] = {
12 {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
13 {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
14 {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
15 {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
16 {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
17 {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
18 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
19 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
20 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
21 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
22 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
23 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
24 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
25 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
26 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
27 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
28 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
29 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
30 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
31 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
32 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
33 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
34 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
35 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
36 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
37 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
38 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
39 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
40 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
41 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
42 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
43 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
44 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
45 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
46 {2,0},{5,3},{7,5},{16,-32767},
47 {2,0},{5,3},{7,5},{16,-32767},
48 {2,0},{5,3},{7,5},{16,-32767},
49 {2,0},{5,3},{7,5},{16,-32767} };
51 static struct al_table alloc_1[] = {
52 {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
53 {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
54 {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
55 {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
56 {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
57 {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
58 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
59 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
60 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
61 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
62 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
63 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
64 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
65 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
66 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
67 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
68 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
69 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
70 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
71 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
72 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
73 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
74 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
75 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
76 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
77 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
78 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
79 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
80 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
81 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
82 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
83 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
84 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
85 {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
86 {2,0},{5,3},{7,5},{16,-32767},
87 {2,0},{5,3},{7,5},{16,-32767},
88 {2,0},{5,3},{7,5},{16,-32767},
89 {2,0},{5,3},{7,5},{16,-32767},
90 {2,0},{5,3},{7,5},{16,-32767},
91 {2,0},{5,3},{7,5},{16,-32767},
92 {2,0},{5,3},{7,5},{16,-32767} };
94 static struct al_table alloc_2[] = {
95 {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
96 {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
97 {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
98 {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
99 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
100 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
101 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
102 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
103 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
104 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} };
106 static struct al_table alloc_3[] = {
107 {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
108 {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
109 {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
110 {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
111 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
112 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
113 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
114 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
115 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
116 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
117 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
118 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
119 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
120 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} };
122 static struct al_table alloc_4[] = {
123 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
124 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
125 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
126 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
127 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
128 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
129 {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
130 {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
131 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
132 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
133 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
134 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
135 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
136 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
137 {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
138 {2,0},{5,3},{7,5},{10,9},
139 {2,0},{5,3},{7,5},{10,9},
140 {2,0},{5,3},{7,5},{10,9},
141 {2,0},{5,3},{7,5},{10,9},
142 {2,0},{5,3},{7,5},{10,9},
143 {2,0},{5,3},{7,5},{10,9},
144 {2,0},{5,3},{7,5},{10,9},
145 {2,0},{5,3},{7,5},{10,9},
146 {2,0},{5,3},{7,5},{10,9},
147 {2,0},{5,3},{7,5},{10,9},
148 {2,0},{5,3},{7,5},{10,9},
149 {2,0},{5,3},{7,5},{10,9},
150 {2,0},{5,3},{7,5},{10,9},
151 {2,0},{5,3},{7,5},{10,9},
152 {2,0},{5,3},{7,5},{10,9},
153 {2,0},{5,3},{7,5},{10,9},
154 {2,0},{5,3},{7,5},{10,9},
155 {2,0},{5,3},{7,5},{10,9},
156 {2,0},{5,3},{7,5},{10,9} };
159 static int select_table(mpeg3_layer_t *audio)
161 static int translate[3][2][16] =
162 {{{ 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0},
163 { 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0}},
164 {{ 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0},
165 { 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0}},
166 {{ 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0},
167 { 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0}}};
168 int table, sblim;
169 static struct al_table *tables[5] =
170 {alloc_0, alloc_1, alloc_2, alloc_3, alloc_4};
171 static int sblims[5] = {27, 30, 8, 12, 30};
173 if(audio->lsf)
174 table = 4;
175 else
176 table = translate[audio->sampling_frequency_code][2 - audio->channels][audio->bitrate_index];
177 sblim = sblims[table];
179 audio->alloc = tables[table];
180 audio->II_sblimit = sblim;
181 return 0;
184 static int step_one(mpeg3_layer_t *audio,
185 unsigned int *bit_alloc,
186 int *scale)
188 int stereo = audio->channels - 1;
189 int sblimit = audio->II_sblimit;
190 int jsbound = audio->jsbound;
191 int sblimit2 = audio->II_sblimit << stereo;
192 struct al_table *alloc1 = audio->alloc;
193 int i, result = 0;
194 unsigned int *scfsi_buf = audio->layer2_scfsi_buf;
195 unsigned int *scfsi, *bita;
196 unsigned int *bita_end = bit_alloc + 64;
197 int sc, step;
199 bita = bit_alloc;
200 if(stereo)
202 /* Stereo */
203 for(i = jsbound;
204 i && bita < bita_end - 2;
205 i--, alloc1 += (1 << step))
207 *bita++ = (char)mpeg3bits_getbits(audio->stream, step = alloc1->bits);
208 *bita++ = (char)mpeg3bits_getbits(audio->stream, step);
210 for(i = sblimit - jsbound;
211 i && bita < bita_end - 2;
212 i--, alloc1 += (1 << step))
214 bita[0] = (char)mpeg3bits_getbits(audio->stream,
215 step = alloc1->bits);
216 bita[1] = bita[0];
217 bita += 2;
219 bita = bit_alloc;
220 scfsi = scfsi_buf;
221 for(i = sblimit2; i; i--)
222 if(*bita++) *scfsi++ = (char)mpeg3bits_getbits(audio->stream, 2);
224 else
226 /* mono */
227 for(i = sblimit; i; i--, alloc1 += (1 << step))
228 *bita++ = (char)mpeg3bits_getbits(audio->stream, step = alloc1->bits);
230 bita = bit_alloc;
231 scfsi = scfsi_buf;
232 for(i = sblimit; i; i--) if (*bita++) *scfsi++ = (char)mpeg3bits_getbits(audio->stream, 2);
235 bita = bit_alloc;
236 scfsi = scfsi_buf;
237 for(i = sblimit2; i; i--)
239 if(*bita++)
240 switch(*scfsi++)
242 case 0:
243 *scale++ = mpeg3bits_getbits(audio->stream, 6);
244 *scale++ = mpeg3bits_getbits(audio->stream, 6);
245 *scale++ = mpeg3bits_getbits(audio->stream, 6);
246 break;
247 case 1 :
248 *scale++ = sc = mpeg3bits_getbits(audio->stream, 6);
249 *scale++ = sc;
250 *scale++ = mpeg3bits_getbits(audio->stream, 6);
251 break;
252 case 2:
253 *scale++ = sc = mpeg3bits_getbits(audio->stream, 6);
254 *scale++ = sc;
255 *scale++ = sc;
256 break;
257 default: /* case 3 */
258 *scale++ = mpeg3bits_getbits(audio->stream, 6);
259 *scale++ = sc = mpeg3bits_getbits(audio->stream, 6);
260 *scale++ = sc;
261 break;
264 return result;
267 static int step_two(mpeg3_layer_t *audio, unsigned int *bit_alloc, float fraction[2][4][SBLIMIT], int *scale, int x1)
269 int i, j, k, ba, result = 0;
270 int channels = audio->channels;
271 int sblimit = audio->II_sblimit;
272 int jsbound = audio->jsbound;
273 struct al_table *alloc2, *alloc1 = audio->alloc;
274 unsigned int *bita = bit_alloc;
275 int d1, step, test;
277 for(i = 0; i < jsbound; i++, alloc1 += (1 << step))
279 step = alloc1->bits;
280 for(j = 0; j < channels; j++)
282 if(ba = *bita++)
284 k = (alloc2 = alloc1 + ba)->bits;
285 if((d1 = alloc2->d) < 0)
287 float cm = mpeg3_muls[k][scale[x1]];
289 fraction[j][0][i] = ((float)((int)mpeg3bits_getbits(audio->stream, k) + d1)) * cm;
290 fraction[j][1][i] = ((float)((int)mpeg3bits_getbits(audio->stream, k) + d1)) * cm;
291 fraction[j][2][i] = ((float)((int)mpeg3bits_getbits(audio->stream, k) + d1)) * cm;
293 else
295 static int *table[] =
296 {0, 0, 0, mpeg3_grp_3tab, 0, mpeg3_grp_5tab, 0, 0, 0, mpeg3_grp_9tab};
297 unsigned int idx, *tab, m = scale[x1];
299 idx = (unsigned int)mpeg3bits_getbits(audio->stream, k);
300 tab = (unsigned int*)(table[d1] + idx + idx + idx);
301 fraction[j][0][i] = mpeg3_muls[*tab++][m];
302 fraction[j][1][i] = mpeg3_muls[*tab++][m];
303 fraction[j][2][i] = mpeg3_muls[*tab][m];
305 scale += 3;
307 else
308 fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0;
312 for(i = jsbound; i < sblimit; i++, alloc1 += (1 << step))
314 step = alloc1->bits;
315 /* channel 1 and channel 2 bitalloc are the same */
316 bita++;
317 if((ba = *bita++))
319 k=(alloc2 = alloc1+ba)->bits;
320 if((d1 = alloc2->d) < 0)
322 float cm;
324 cm = mpeg3_muls[k][scale[x1 + 3]];
325 fraction[1][0][i] = (fraction[0][0][i] = (float)((int)mpeg3bits_getbits(audio->stream, k) + d1)) * cm;
326 fraction[1][1][i] = (fraction[0][1][i] = (float)((int)mpeg3bits_getbits(audio->stream, k) + d1)) * cm;
327 fraction[1][2][i] = (fraction[0][2][i] = (float)((int)mpeg3bits_getbits(audio->stream, k) + d1)) * cm;
328 cm = mpeg3_muls[k][scale[x1]];
329 fraction[0][0][i] *= cm;
330 fraction[0][1][i] *= cm;
331 fraction[0][2][i] *= cm;
333 else
335 static int *table[] = {0, 0, 0, mpeg3_grp_3tab, 0, mpeg3_grp_5tab, 0, 0, 0, mpeg3_grp_9tab};
336 unsigned int idx, *tab, m1, m2;
338 m1 = scale[x1];
339 m2 = scale[x1+3];
340 idx = (unsigned int)mpeg3bits_getbits(audio->stream, k);
341 tab = (unsigned int*)(table[d1] + idx + idx + idx);
342 fraction[0][0][i] = mpeg3_muls[*tab][m1];
343 fraction[1][0][i] = mpeg3_muls[*tab++][m2];
344 fraction[0][1][i] = mpeg3_muls[*tab][m1];
345 fraction[1][1][i] = mpeg3_muls[*tab++][m2];
346 fraction[0][2][i] = mpeg3_muls[*tab][m1];
347 fraction[1][2][i] = mpeg3_muls[*tab][m2];
349 scale += 6;
351 else
353 fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] =
354 fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0.0;
357 should we use individual scalefac for channel 2 or
358 is the current way the right one , where we just copy channel 1 to
359 channel 2 ??
360 The current 'strange' thing is, that we throw away the scalefac
361 values for the second channel ...!!
362 -> changed .. now we use the scalefac values of channel one !!
366 if(sblimit > SBLIMIT) sblimit = SBLIMIT;
368 for(i = sblimit; i < SBLIMIT; i++)
369 for(j = 0; j < channels; j++)
370 fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0;
372 return result;
375 int mpeg3audio_dolayer2(mpeg3_layer_t *audio,
376 char *frame,
377 int frame_size,
378 float **output,
379 int render)
381 int i, j, result = 0;
382 int channels = audio->channels;
383 float fraction[2][4][SBLIMIT]; /* pick_table clears unused subbands */
384 unsigned int bit_alloc[64];
385 int scale[192];
386 int single = audio->single;
387 int output_position = 0;
390 frame += 4;
391 /* Set up bitstream to use buffer */
392 mpeg3bits_use_ptr(audio->stream, frame);
396 if(audio->error_protection)
397 mpeg3bits_getbits(audio->stream, 16);
399 select_table(audio);
401 audio->jsbound = (audio->mode == MPG_MD_JOINT_STEREO) ?
402 (audio->mode_ext << 2) + 4 : audio->II_sblimit;
404 if(channels == 1 || single == 3)
405 single = 0;
407 result |= step_one(audio, bit_alloc, scale);
409 for(i = 0; i < SCALE_BLOCK && !result; i++)
411 result |= step_two(audio, bit_alloc, fraction, scale, i >> 2);
413 for(j = 0; j < 3; j++)
415 if(single >= 0)
417 /* Monaural */
418 if(render)
419 mpeg3audio_synth_stereo(audio,
420 fraction[0][j],
422 output[0],
423 &(output_position));
424 else
425 output_position += 32;
427 else
429 /* Stereo */
430 int p1 = output_position;
431 if(render)
433 //printf(__FUNCTION__ " 3\n");
434 mpeg3audio_synth_stereo(audio,
435 fraction[0][j],
437 output[0],
438 &p1);
439 //printf(__FUNCTION__ " 4\n");
440 mpeg3audio_synth_stereo(audio,
441 fraction[1][j],
443 output[1],
444 &(output_position));
445 //printf(__FUNCTION__ " 5\n");
447 else
448 output_position += 32;
454 return output_position;