1 /*****************************************************************************
2 * adec_layer2.c: MPEG Layer II audio decoder
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
26 * - optimiser les NeedBits() et les GetBits() du code là où c'est possible ;
30 #include "int_types.h"
32 #include "adec_generic.h"
33 #include "adec_math.h" /* DCT32(), PCM() */
34 #include "adec_bit_stream.h"
36 #define NULL ((void *)0)
40 static float adec_scalefactor_table[64] =
42 2.0000000000000000, 1.5874010519681994, 1.2599210498948732,
43 1.0000000000000000, 0.7937005259840998, 0.6299605249474366,
44 0.5000000000000000, 0.3968502629920499, 0.3149802624737183,
45 0.2500000000000000, 0.1984251314960249, 0.1574901312368591,
46 0.1250000000000000, 0.0992125657480125, 0.0787450656184296,
47 0.0625000000000000, 0.0496062828740062, 0.0393725328092148,
48 0.0312500000000000, 0.0248031414370031, 0.0196862664046074,
49 0.0156250000000000, 0.0124015707185016, 0.0098431332023037,
50 0.0078125000000000, 0.0062007853592508, 0.0049215666011518,
51 0.0039062500000000, 0.0031003926796254, 0.0024607833005759,
52 0.0019531250000000, 0.0015501963398127, 0.0012303916502880,
53 0.0009765625000000, 0.0007750981699063, 0.0006151958251440,
54 0.0004882812500000, 0.0003875490849532, 0.0003075979125720,
55 0.0002441406250000, 0.0001937745424766, 0.0001537989562860,
56 0.0001220703125000, 0.0000968872712383, 0.0000768994781430,
57 0.0000610351562500, 0.0000484436356191, 0.0000384497390715,
58 0.0000305175781250, 0.0000242218178096, 0.0000192248695357,
59 0.0000152587890625, 0.0000121109089048, 0.0000096124347679,
60 0.0000076293945312, 0.0000060554544524, 0.0000048062173839,
61 0.0000038146972656, 0.0000030277272262, 0.0000024031086920,
62 0.0000019073486328, 0.0000015138636131, 0.0000012015543460,
63 0.0000009536743164 /* last element is not in the standard... invalid ??? */
66 static float adec_slope_table[15] =
68 0.6666666666666666, 0.2857142857142857, 0.1333333333333333,
69 0.0645161290322581, 0.0317460317460317, 0.0157480314960630,
70 0.0078431372549020, 0.0039138943248532, 0.0019550342130987,
71 0.0009770395701026, 0.0004884004884005, 0.0002441704309608,
72 0.0001220777635354, 0.0000610370189520, 0.0000305180437934
75 static float adec_offset_table[15] =
77 -0.6666666666666666, -0.8571428571428571, -0.9333333333333333,
78 -0.9677419354838710, -0.9841269841269841, -0.9921259842519685,
79 -0.9960784313725490, -0.9980430528375733, -0.9990224828934506,
80 -0.9995114802149487, -0.9997557997557998, -0.9998779147845196,
81 -0.9999389611182323, -0.9999694814905240, -0.9999847409781033
84 static int adec_bound_table[4] = { 4, 8, 12, 16 };
96 static void adec_layer2_get_table( u32 header, u8 freq_table[15],
97 alloc_table_t ** alloc, int * sblimit )
99 static s8 table_ab0[16] =
101 0, L3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
103 static s8 table_ab3[16] =
105 0, L3, L5, 3, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16
107 static s8 table_ab11[8] =
109 0, L3, L5, 3, L9, 4, 5, 16
111 static s8 table_ab23[8] =
115 static alloc_table_t mpeg1_ab =
117 {4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,0,0},
118 {table_ab0, table_ab0, table_ab0, table_ab3,
119 table_ab3, table_ab3, table_ab3, table_ab3,
120 table_ab3, table_ab3, table_ab3, table_ab11,
121 table_ab11, table_ab11, table_ab11, table_ab11,
122 table_ab11, table_ab11, table_ab11, table_ab11,
123 table_ab11, table_ab11, table_ab11, table_ab23,
124 table_ab23, table_ab23, table_ab23, table_ab23,
125 table_ab23, table_ab23, NULL, NULL}
128 static s8 table_cd[16] =
130 0, L3, L5, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
132 static alloc_table_t mpeg1_cd =
134 {4,4,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
135 {table_cd, table_cd, table_cd, table_cd,
136 table_cd, table_cd, table_cd, table_cd,
137 table_cd, table_cd, table_cd, table_cd,
138 NULL, NULL, NULL, NULL,
139 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
140 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
143 static s8 table_0[16] =
145 0, L3, L5, 3, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
147 static s8 table_4[8] =
149 0, L3, L5, L9, 4, 5, 6, 7
151 static alloc_table_t mpeg2 =
153 {4,4,4,4,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0},
154 {table_0, table_0, table_0, table_0,
155 table_4, table_4, table_4, table_4,
156 table_4, table_4, table_4, table_4,
157 table_4, table_4, table_4, table_4,
158 table_4, table_4, table_4, table_4,
159 table_4, table_4, table_4, table_4,
160 table_4, table_4, table_4, table_4,
161 table_4, table_4, NULL, NULL}
164 static alloc_table_t * alloc_table [4] =
166 &mpeg2, &mpeg1_cd, &mpeg1_ab, &mpeg1_ab
168 static int sblimit_table[12] =
170 30, 8, 27, 30, 30, 8, 27, 27, 30, 12, 27, 30
175 if (!(header & 0x80000))
177 index = 0; /* mpeg2 */
181 index = (header >> 12) & 15; /* mpeg1, bitrate */
182 index = freq_table [index];
185 *alloc = alloc_table[index];
186 index |= (header >> 8) & 12;
187 *sblimit = sblimit_table[index];
190 int adec_layer2_mono (audiodec_t * p_adec, s16 * buffer)
192 static u8 freq_table[15] = {2, 1, 1, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2};
193 static float L3_table[3] = {-2/3.0, 0, 2/3.0};
194 static float L5_table[5] = {-4/5.0, -2/5.0, 0, 2/5.0, 4/5.0};
195 static float L9_table[9] = {-8/9.0, -6/9.0, -4/9.0, -2/9.0, 0,
196 2/9.0, 4/9.0, 6/9.0, 8/9.0};
203 alloc_table_t * alloc_table;
210 /* get the right allocation table */
211 adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
213 /* parse allocation */
216 for (sb = 0; sb < sblimit; sb++)
220 NeedBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
221 index = p_adec->bit_stream.buffer >> (32 - alloc_table->nbal[sb]);
222 DumpBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
224 allocation[sb] = alloc_table->alloc[sb][index];
229 for (sb = 0; sb < sblimit; sb++)
233 NeedBits (&p_adec->bit_stream, 2);
234 scfsi[sb] = p_adec->bit_stream.buffer >> (32 - 2);
235 DumpBits (&p_adec->bit_stream, 2);
239 /* parse scalefactors */
241 for (sb = 0; sb < sblimit; sb++)
245 int index_0, index_1, index_2;
250 NeedBits (&p_adec->bit_stream, 18);
251 index_0 = p_adec->bit_stream.buffer >> (32 - 6);
252 index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
253 index_2 = (p_adec->bit_stream.buffer >> (32 - 18)) & 63;
254 DumpBits (&p_adec->bit_stream, 18);
256 if (allocation[sb] < 0)
258 slope[0][sb] = adec_scalefactor_table[index_0];
259 slope[1][sb] = adec_scalefactor_table[index_1];
260 slope[2][sb] = adec_scalefactor_table[index_2];
265 float r_slope, r_offset;
267 r_slope = adec_slope_table[allocation[sb]-2];
268 r_offset = adec_offset_table[allocation[sb]-2];
270 r_scalefactor = adec_scalefactor_table[index_0];
271 slope[0][sb] = r_slope * r_scalefactor;
272 offset[0][sb] = r_offset * r_scalefactor;
274 r_scalefactor = adec_scalefactor_table[index_1];
275 slope[1][sb] = r_slope * r_scalefactor;
276 offset[1][sb] = r_offset * r_scalefactor;
278 r_scalefactor = adec_scalefactor_table[index_2];
279 slope[2][sb] = r_slope * r_scalefactor;
280 offset[2][sb] = r_offset * r_scalefactor;
285 NeedBits (&p_adec->bit_stream, 12);
286 index_0 = p_adec->bit_stream.buffer >> (32 - 6);
287 index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
288 DumpBits (&p_adec->bit_stream, 12);
290 if (allocation[sb] < 0)
292 slope[0][sb] = slope[1][sb] =
293 adec_scalefactor_table[index_0];
294 slope[2][sb] = adec_scalefactor_table[index_1];
299 float r_slope, r_offset;
301 r_slope = adec_slope_table[allocation[sb]-2];
302 r_offset = adec_offset_table[allocation[sb]-2];
304 r_scalefactor = adec_scalefactor_table[index_0];
305 slope[0][sb] = slope[1][sb] = r_slope * r_scalefactor;
306 offset[0][sb] = offset[1][sb] =
307 r_offset * r_scalefactor;
309 r_scalefactor = adec_scalefactor_table[index_1];
310 slope[2][sb] = r_slope * r_scalefactor;
311 offset[2][sb] = r_offset * r_scalefactor;
316 NeedBits (&p_adec->bit_stream, 6);
317 index_0 = p_adec->bit_stream.buffer >> (32 - 6);
318 DumpBits (&p_adec->bit_stream, 6);
320 if (allocation[sb] < 0)
322 slope[0][sb] = slope[1][sb] = slope[2][sb] =
323 adec_scalefactor_table[index_0];
328 float r_slope, r_offset;
330 r_slope = adec_slope_table[allocation[sb]-2];
331 r_offset = adec_offset_table[allocation[sb]-2];
333 r_scalefactor = adec_scalefactor_table[index_0];
334 slope[0][sb] = slope[1][sb] = slope[2][sb] =
335 r_slope * r_scalefactor;
336 offset[0][sb] = offset[1][sb] = offset[2][sb] =
337 r_offset * r_scalefactor;
342 NeedBits (&p_adec->bit_stream, 12);
343 index_0 = p_adec->bit_stream.buffer >> (32 - 6);
344 index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
345 DumpBits (&p_adec->bit_stream, 12);
347 if (allocation[sb] < 0)
349 slope[0][sb] = adec_scalefactor_table[index_0];
350 slope[1][sb] = slope[2][sb] =
351 adec_scalefactor_table[index_1];
356 float r_slope, r_offset;
358 r_slope = adec_slope_table[allocation[sb]-2];
359 r_offset = adec_offset_table[allocation[sb]-2];
361 r_scalefactor = adec_scalefactor_table[index_0];
362 slope[0][sb] = r_slope * r_scalefactor;
363 offset[0][sb] = r_offset * r_scalefactor;
365 r_scalefactor = adec_scalefactor_table[index_1];
366 slope[1][sb] = slope[2][sb] = r_slope * r_scalefactor;
367 offset[1][sb] = offset[2][sb] =
368 r_offset * r_scalefactor;
377 for (gr0 = 0; gr0 < 3; gr0++)
379 for (gr1 = 0; gr1 < 4; gr1++)
383 for (sb = 0; sb < sblimit; sb++)
387 switch (allocation[sb])
390 sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
394 NeedBits (&p_adec->bit_stream, 5);
395 code = p_adec->bit_stream.buffer >> (32 - 5);
396 DumpBits (&p_adec->bit_stream, 5);
398 sample[0][sb] = slope[gr0][sb] * L3_table[code % 3];
400 sample[1][sb] = slope[gr0][sb] * L3_table[code % 3];
402 sample[2][sb] = slope[gr0][sb] * L3_table[code];
406 NeedBits (&p_adec->bit_stream, 7);
407 code = p_adec->bit_stream.buffer >> (32 - 7);
408 DumpBits (&p_adec->bit_stream, 7);
410 sample[0][sb] = slope[gr0][sb] * L5_table[code % 5];
412 sample[1][sb] = slope[gr0][sb] * L5_table[code % 5];
414 sample[2][sb] = slope[gr0][sb] * L5_table[code];
418 NeedBits (&p_adec->bit_stream, 10);
419 code = p_adec->bit_stream.buffer >> (32 - 10);
420 DumpBits (&p_adec->bit_stream, 10);
422 sample[0][sb] = slope[gr0][sb] * L9_table[code % 9];
424 sample[1][sb] = slope[gr0][sb] * L9_table[code % 9];
426 sample[2][sb] = slope[gr0][sb] * L9_table[code];
430 for (s = 0; s < 3; s++)
432 NeedBits (&p_adec->bit_stream, allocation[sb]);
433 code = ( p_adec->bit_stream.buffer >>
434 (32 - allocation[sb]) );
435 DumpBits (&p_adec->bit_stream, allocation[sb]);
438 slope[gr0][sb] * code + offset[gr0][sb];
443 for (; sb < 32; sb++)
445 sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
448 for (s = 0; s < 3; s++)
450 DCT32 (sample[s], &p_adec->bank_0);
452 PCM (&p_adec->bank_0, &XXX_buf, 2);
454 /* FIXME: one shouldn't have to do it twice ! */
455 DCT32 (sample[s], &p_adec->bank_1);
457 PCM (&p_adec->bank_1, &XXX_buf, 2);
467 int adec_layer2_stereo (audiodec_t * p_adec, s16 * buffer)
469 static u8 freq_table[15] = {3, 0, 0, 0, 1, 0, 1, 2, 2, 2, 3, 3, 3, 3, 3};
470 static float L3_table[3] = {-2/3.0, 0, 2/3.0};
471 static float L5_table[5] = {-4/5.0, -2/5.0, 0, 2/5.0, 4/5.0};
472 static float L9_table[9] = {-8/9.0, -6/9.0, -4/9.0, -2/9.0, 0,
473 2/9.0, 4/9.0, 6/9.0, 8/9.0};
475 s8 allocation_0[32], allocation_1[32];
476 u8 scfsi_0[32], scfsi_1[32];
477 float slope_0[3][32], slope_1[3][32];
478 float offset_0[3][32], offset_1[3][32];
479 float sample_0[3][32], sample_1[3][32];
480 alloc_table_t * alloc_table;
488 /* get the right allocation table */
489 adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
491 /* calculate bound */
493 if ((p_adec->header & 0xc0) == 0x40) { /* intensity stereo */
495 index = (p_adec->header >> 4) & 3;
496 if (adec_bound_table[index] < sblimit)
498 bound = adec_bound_table[index];
502 /* parse allocation */
504 for (sb = 0; sb < bound; sb++)
508 NeedBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
509 index = p_adec->bit_stream.buffer >> (32 - alloc_table->nbal[sb]);
510 DumpBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
512 allocation_0[sb] = alloc_table->alloc[sb][index];
514 NeedBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
515 index = p_adec->bit_stream.buffer >> (32 - alloc_table->nbal[sb]);
516 DumpBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
518 allocation_1[sb] = alloc_table->alloc[sb][index];
521 for (; sb < sblimit; sb++)
525 NeedBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
526 index = p_adec->bit_stream.buffer >> (32 - alloc_table->nbal[sb]);
527 DumpBits (&p_adec->bit_stream, alloc_table->nbal[sb]);
529 allocation_0[sb] = allocation_1[sb] = alloc_table->alloc[sb][index];
534 for (sb = 0; sb < sblimit; sb++)
536 if (allocation_0[sb])
538 NeedBits (&p_adec->bit_stream, 2);
539 scfsi_0[sb] = p_adec->bit_stream.buffer >> (32 - 2);
540 DumpBits (&p_adec->bit_stream, 2);
543 if (allocation_1[sb])
545 NeedBits (&p_adec->bit_stream, 2);
546 scfsi_1[sb] = p_adec->bit_stream.buffer >> (32 - 2);
547 DumpBits (&p_adec->bit_stream, 2);
551 /* parse scalefactors */
553 for (sb = 0; sb < sblimit; sb++)
555 if (allocation_0[sb])
557 int index_0, index_1, index_2;
562 NeedBits (&p_adec->bit_stream, 18);
563 index_0 = p_adec->bit_stream.buffer >> (32 - 6);
564 index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
565 index_2 = (p_adec->bit_stream.buffer >> (32 - 18)) & 63;
566 DumpBits (&p_adec->bit_stream, 18);
568 if (allocation_0[sb] < 0)
570 slope_0[0][sb] = adec_scalefactor_table[index_0];
571 slope_0[1][sb] = adec_scalefactor_table[index_1];
572 slope_0[2][sb] = adec_scalefactor_table[index_2];
579 slope = adec_slope_table[allocation_0[sb]-2];
580 offset = adec_offset_table[allocation_0[sb]-2];
582 scalefactor = adec_scalefactor_table[index_0];
583 slope_0[0][sb] = slope * scalefactor;
584 offset_0[0][sb] = offset * scalefactor;
586 scalefactor = adec_scalefactor_table[index_1];
587 slope_0[1][sb] = slope * scalefactor;
588 offset_0[1][sb] = offset * scalefactor;
590 scalefactor = adec_scalefactor_table[index_2];
591 slope_0[2][sb] = slope * scalefactor;
592 offset_0[2][sb] = offset * scalefactor;
597 NeedBits (&p_adec->bit_stream, 12);
598 index_0 = p_adec->bit_stream.buffer >> (32 - 6);
599 index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
600 DumpBits (&p_adec->bit_stream, 12);
602 if (allocation_0[sb] < 0)
604 slope_0[0][sb] = slope_0[1][sb] =
605 adec_scalefactor_table[index_0];
606 slope_0[2][sb] = adec_scalefactor_table[index_1];
613 slope = adec_slope_table[allocation_0[sb]-2];
614 offset = adec_offset_table[allocation_0[sb]-2];
616 scalefactor = adec_scalefactor_table[index_0];
617 slope_0[0][sb] = slope_0[1][sb] = slope * scalefactor;
618 offset_0[0][sb] = offset_0[1][sb] =
619 offset * scalefactor;
621 scalefactor = adec_scalefactor_table[index_1];
622 slope_0[2][sb] = slope * scalefactor;
623 offset_0[2][sb] = offset * scalefactor;
628 NeedBits (&p_adec->bit_stream, 6);
629 index_0 = p_adec->bit_stream.buffer >> (32 - 6);
630 DumpBits (&p_adec->bit_stream, 6);
632 if (allocation_0[sb] < 0)
634 slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
635 adec_scalefactor_table[index_0];
642 slope = adec_slope_table[allocation_0[sb]-2];
643 offset = adec_offset_table[allocation_0[sb]-2];
645 scalefactor = adec_scalefactor_table[index_0];
646 slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
648 offset_0[0][sb] = offset_0[1][sb] = offset_0[2][sb] =
649 offset * scalefactor;
654 NeedBits (&p_adec->bit_stream, 12);
655 index_0 = p_adec->bit_stream.buffer >> (32 - 6);
656 index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
657 DumpBits (&p_adec->bit_stream, 12);
659 if (allocation_0[sb] < 0)
661 slope_0[0][sb] = adec_scalefactor_table[index_0];
662 slope_0[1][sb] = slope_0[2][sb] =
663 adec_scalefactor_table[index_1];
670 slope = adec_slope_table[allocation_0[sb]-2];
671 offset = adec_offset_table[allocation_0[sb]-2];
673 scalefactor = adec_scalefactor_table[index_0];
674 slope_0[0][sb] = slope * scalefactor;
675 offset_0[0][sb] = offset * scalefactor;
677 scalefactor = adec_scalefactor_table[index_1];
678 slope_0[1][sb] = slope_0[2][sb] = slope * scalefactor;
679 offset_0[1][sb] = offset_0[2][sb] =
680 offset * scalefactor;
686 if (allocation_1[sb])
688 int index_0, index_1, index_2;
693 NeedBits (&p_adec->bit_stream, 18);
694 index_0 = p_adec->bit_stream.buffer >> (32 - 6);
695 index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
696 index_2 = (p_adec->bit_stream.buffer >> (32 - 18)) & 63;
697 DumpBits (&p_adec->bit_stream, 18);
699 if (allocation_1[sb] < 0)
701 slope_1[0][sb] = adec_scalefactor_table[index_0];
702 slope_1[1][sb] = adec_scalefactor_table[index_1];
703 slope_1[2][sb] = adec_scalefactor_table[index_2];
710 slope = adec_slope_table[allocation_1[sb]-2];
711 offset = adec_offset_table[allocation_1[sb]-2];
713 scalefactor = adec_scalefactor_table[index_0];
714 slope_1[0][sb] = slope * scalefactor;
715 offset_1[0][sb] = offset * scalefactor;
717 scalefactor = adec_scalefactor_table[index_1];
718 slope_1[1][sb] = slope * scalefactor;
719 offset_1[1][sb] = offset * scalefactor;
721 scalefactor = adec_scalefactor_table[index_2];
722 slope_1[2][sb] = slope * scalefactor;
723 offset_1[2][sb] = offset * scalefactor;
728 NeedBits (&p_adec->bit_stream, 12);
729 index_0 = p_adec->bit_stream.buffer >> (32 - 6);
730 index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
731 DumpBits (&p_adec->bit_stream, 12);
733 if (allocation_1[sb] < 0)
735 slope_1[0][sb] = slope_1[1][sb] =
736 adec_scalefactor_table[index_0];
737 slope_1[2][sb] = adec_scalefactor_table[index_1];
744 slope = adec_slope_table[allocation_1[sb]-2];
745 offset = adec_offset_table[allocation_1[sb]-2];
747 scalefactor = adec_scalefactor_table[index_0];
748 slope_1[0][sb] = slope_1[1][sb] = slope * scalefactor;
749 offset_1[0][sb] = offset_1[1][sb] =
750 offset * scalefactor;
752 scalefactor = adec_scalefactor_table[index_1];
753 slope_1[2][sb] = slope * scalefactor;
754 offset_1[2][sb] = offset * scalefactor;
759 NeedBits (&p_adec->bit_stream, 6);
760 index_0 = p_adec->bit_stream.buffer >> (32 - 6);
761 DumpBits (&p_adec->bit_stream, 6);
763 if (allocation_1[sb] < 0)
765 slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
766 adec_scalefactor_table[index_0];
773 slope = adec_slope_table[allocation_1[sb]-2];
774 offset = adec_offset_table[allocation_1[sb]-2];
776 scalefactor = adec_scalefactor_table[index_0];
777 slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
779 offset_1[0][sb] = offset_1[1][sb] = offset_1[2][sb] =
780 offset * scalefactor;
785 NeedBits (&p_adec->bit_stream, 12);
786 index_0 = p_adec->bit_stream.buffer >> (32 - 6);
787 index_1 = (p_adec->bit_stream.buffer >> (32 - 12)) & 63;
788 DumpBits (&p_adec->bit_stream, 12);
790 if (allocation_1[sb] < 0)
792 slope_1[0][sb] = adec_scalefactor_table[index_0];
793 slope_1[1][sb] = slope_1[2][sb] =
794 adec_scalefactor_table[index_1];
801 slope = adec_slope_table[allocation_1[sb]-2];
802 offset = adec_offset_table[allocation_1[sb]-2];
804 scalefactor = adec_scalefactor_table[index_0];
805 slope_1[0][sb] = slope * scalefactor;
806 offset_1[0][sb] = offset * scalefactor;
808 scalefactor = adec_scalefactor_table[index_1];
809 slope_1[1][sb] = slope_1[2][sb] = slope * scalefactor;
810 offset_1[1][sb] = offset_1[2][sb] =
811 offset * scalefactor;
820 for (gr0 = 0; gr0 < 3; gr0++)
822 for (gr1 = 0; gr1 < 4; gr1++)
826 for (sb = 0; sb < bound; sb++)
830 switch (allocation_0[sb])
833 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
837 NeedBits (&p_adec->bit_stream, 5);
838 code = p_adec->bit_stream.buffer >> (32 - 5);
839 DumpBits (&p_adec->bit_stream, 5);
841 sample_0[0][sb] = slope_0[gr0][sb] * L3_table[code % 3];
843 sample_0[1][sb] = slope_0[gr0][sb] * L3_table[code % 3];
845 sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code];
849 NeedBits (&p_adec->bit_stream, 7);
850 code = p_adec->bit_stream.buffer >> (32 - 7);
851 DumpBits (&p_adec->bit_stream, 7);
853 sample_0[0][sb] = slope_0[gr0][sb] * L5_table[code % 5];
855 sample_0[1][sb] = slope_0[gr0][sb] * L5_table[code % 5];
857 sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code];
861 NeedBits (&p_adec->bit_stream, 10);
862 code = p_adec->bit_stream.buffer >> (32 - 10);
863 DumpBits (&p_adec->bit_stream, 10);
865 sample_0[0][sb] = slope_0[gr0][sb] * L9_table[code % 9];
867 sample_0[1][sb] = slope_0[gr0][sb] * L9_table[code % 9];
869 sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code];
873 for (s = 0; s < 3; s++)
875 NeedBits (&p_adec->bit_stream, allocation_0[sb]);
876 code = ( p_adec->bit_stream.buffer >>
877 (32 - allocation_0[sb]) );
878 DumpBits (&p_adec->bit_stream, allocation_0[sb]);
881 slope_0[gr0][sb] * code + offset_0[gr0][sb];
885 switch (allocation_1[sb])
888 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
892 NeedBits (&p_adec->bit_stream, 5);
893 code = p_adec->bit_stream.buffer >> (32 - 5);
894 DumpBits (&p_adec->bit_stream, 5);
896 sample_1[0][sb] = slope_1[gr0][sb] * L3_table[code % 3];
898 sample_1[1][sb] = slope_1[gr0][sb] * L3_table[code % 3];
900 sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code];
904 NeedBits (&p_adec->bit_stream, 7);
905 code = p_adec->bit_stream.buffer >> (32 - 7);
906 DumpBits (&p_adec->bit_stream, 7);
908 sample_1[0][sb] = slope_1[gr0][sb] * L5_table[code % 5];
910 sample_1[1][sb] = slope_1[gr0][sb] * L5_table[code % 5];
912 sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code];
916 NeedBits (&p_adec->bit_stream, 10);
917 code = p_adec->bit_stream.buffer >> (32 - 10);
918 DumpBits (&p_adec->bit_stream, 10);
920 sample_1[0][sb] = slope_1[gr0][sb] * L9_table[code % 9];
922 sample_1[1][sb] = slope_1[gr0][sb] * L9_table[code % 9];
924 sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code];
928 for (s = 0; s < 3; s++)
930 NeedBits (&p_adec->bit_stream, allocation_1[sb]);
931 code = ( p_adec->bit_stream.buffer >>
932 (32 - allocation_1[sb]) );
933 DumpBits (&p_adec->bit_stream, allocation_1[sb]);
936 slope_1[gr0][sb] * code + offset_1[gr0][sb];
941 for (; sb < sblimit; sb++)
945 switch (allocation_0[sb])
948 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
949 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
953 NeedBits (&p_adec->bit_stream, 5);
954 code = p_adec->bit_stream.buffer >> (32 - 5);
955 DumpBits (&p_adec->bit_stream, 5);
957 sample_0[0][sb] = slope_0[gr0][sb] * L3_table[code % 3];
958 sample_1[0][sb] = slope_1[gr0][sb] * L3_table[code % 3];
960 sample_0[1][sb] = slope_0[gr0][sb] * L3_table[code % 3];
961 sample_1[1][sb] = slope_1[gr0][sb] * L3_table[code % 3];
963 sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code];
964 sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code];
968 NeedBits (&p_adec->bit_stream, 7);
969 code = p_adec->bit_stream.buffer >> (32 - 7);
970 DumpBits (&p_adec->bit_stream, 7);
972 sample_0[0][sb] = slope_0[gr0][sb] * L5_table[code % 5];
973 sample_1[0][sb] = slope_1[gr0][sb] * L5_table[code % 5];
975 sample_0[1][sb] = slope_0[gr0][sb] * L5_table[code % 5];
976 sample_1[1][sb] = slope_1[gr0][sb] * L5_table[code % 5];
978 sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code];
979 sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code];
983 NeedBits (&p_adec->bit_stream, 10);
984 code = p_adec->bit_stream.buffer >> (32 - 10);
985 DumpBits (&p_adec->bit_stream, 10);
987 sample_0[0][sb] = slope_0[gr0][sb] * L9_table[code % 9];
988 sample_1[0][sb] = slope_1[gr0][sb] * L9_table[code % 9];
990 sample_0[1][sb] = slope_0[gr0][sb] * L9_table[code % 9];
991 sample_1[1][sb] = slope_1[gr0][sb] * L9_table[code % 9];
993 sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code];
994 sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code];
998 for (s = 0; s < 3; s++)
1000 NeedBits (&p_adec->bit_stream, allocation_0[sb]);
1001 code = ( p_adec->bit_stream.buffer >>
1002 (32 - allocation_0[sb]) );
1003 DumpBits (&p_adec->bit_stream, allocation_0[sb]);
1006 slope_0[gr0][sb] * code + offset_0[gr0][sb];
1008 slope_1[gr0][sb] * code + offset_1[gr0][sb];
1013 for (; sb < 32; sb++)
1015 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
1016 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
1019 for (s = 0; s < 3; s++)
1021 DCT32 (sample_0[s], &p_adec->bank_0);
1023 PCM (&p_adec->bank_0, &XXX_buf, 2);
1025 DCT32 (sample_1[s], &p_adec->bank_1);
1027 PCM (&p_adec->bank_1, &XXX_buf, 2);