1 /*****************************************************************************
2 * adec_layer2.c: MPEG Layer II audio decoder
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: adec_layer2.c,v 1.5 2001/12/30 07:09:55 sam Exp $
7 * Authors: Michel Kaempf <maxx@via.ecp.fr>
8 * Michel Lespinasse <walken@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program 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
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 #include <stdlib.h> /* NULL */
26 #include <string.h> /* memcpy(), memset() */
28 #include <videolan/vlc.h>
30 #include "stream_control.h"
31 #include "input_ext-dec.h"
33 #include "mpeg_adec_generic.h"
34 #include "mpeg_adec.h"
35 #include "adec_math.h" /* DCT32(), PCM() */
39 static float adec_scalefactor_table[64] =
41 2.0000000000000000, 1.5874010519681994, 1.2599210498948732,
42 1.0000000000000000, 0.7937005259840998, 0.6299605249474366,
43 0.5000000000000000, 0.3968502629920499, 0.3149802624737183,
44 0.2500000000000000, 0.1984251314960249, 0.1574901312368591,
45 0.1250000000000000, 0.0992125657480125, 0.0787450656184296,
46 0.0625000000000000, 0.0496062828740062, 0.0393725328092148,
47 0.0312500000000000, 0.0248031414370031, 0.0196862664046074,
48 0.0156250000000000, 0.0124015707185016, 0.0098431332023037,
49 0.0078125000000000, 0.0062007853592508, 0.0049215666011518,
50 0.0039062500000000, 0.0031003926796254, 0.0024607833005759,
51 0.0019531250000000, 0.0015501963398127, 0.0012303916502880,
52 0.0009765625000000, 0.0007750981699063, 0.0006151958251440,
53 0.0004882812500000, 0.0003875490849532, 0.0003075979125720,
54 0.0002441406250000, 0.0001937745424766, 0.0001537989562860,
55 0.0001220703125000, 0.0000968872712383, 0.0000768994781430,
56 0.0000610351562500, 0.0000484436356191, 0.0000384497390715,
57 0.0000305175781250, 0.0000242218178096, 0.0000192248695357,
58 0.0000152587890625, 0.0000121109089048, 0.0000096124347679,
59 0.0000076293945312, 0.0000060554544524, 0.0000048062173839,
60 0.0000038146972656, 0.0000030277272262, 0.0000024031086920,
61 0.0000019073486328, 0.0000015138636131, 0.0000012015543460,
62 0.0000009536743164 /* last element is not in the standard... invalid ??? */
65 static float adec_slope_table[15] =
67 0.6666666666666666, 0.2857142857142857, 0.1333333333333333,
68 0.0645161290322581, 0.0317460317460317, 0.0157480314960630,
69 0.0078431372549020, 0.0039138943248532, 0.0019550342130987,
70 0.0009770395701026, 0.0004884004884005, 0.0002441704309608,
71 0.0001220777635354, 0.0000610370189520, 0.0000305180437934
74 static float adec_offset_table[15] =
76 -0.6666666666666666, -0.8571428571428571, -0.9333333333333333,
77 -0.9677419354838710, -0.9841269841269841, -0.9921259842519685,
78 -0.9960784313725490, -0.9980430528375733, -0.9990224828934506,
79 -0.9995114802149487, -0.9997557997557998, -0.9998779147845196,
80 -0.9999389611182323, -0.9999694814905240, -0.9999847409781033
83 static int adec_bound_table[4] = { 4, 8, 12, 16 };
95 static void adec_layer2_get_table( u32 header, u8 freq_table[15],
96 alloc_table_t ** alloc, int * sblimit )
98 static s8 table_ab0[16] =
100 0, L3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
102 static s8 table_ab3[16] =
104 0, L3, L5, 3, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16
106 static s8 table_ab11[8] =
108 0, L3, L5, 3, L9, 4, 5, 16
110 static s8 table_ab23[8] =
114 static alloc_table_t mpeg1_ab =
116 {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},
117 {table_ab0, table_ab0, table_ab0, table_ab3,
118 table_ab3, table_ab3, table_ab3, table_ab3,
119 table_ab3, table_ab3, table_ab3, table_ab11,
120 table_ab11, table_ab11, table_ab11, table_ab11,
121 table_ab11, table_ab11, table_ab11, table_ab11,
122 table_ab11, table_ab11, table_ab11, table_ab23,
123 table_ab23, table_ab23, table_ab23, table_ab23,
124 table_ab23, table_ab23, NULL, NULL}
127 static s8 table_cd[16] =
129 0, L3, L5, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
131 static alloc_table_t mpeg1_cd =
133 {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},
134 {table_cd, table_cd, table_cd, table_cd,
135 table_cd, table_cd, table_cd, table_cd,
136 table_cd, table_cd, table_cd, table_cd,
137 NULL, NULL, NULL, NULL,
138 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
139 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
142 static s8 table_0[16] =
144 0, L3, L5, 3, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
146 static s8 table_4[8] =
148 0, L3, L5, L9, 4, 5, 6, 7
150 static alloc_table_t mpeg2 =
152 {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},
153 {table_0, table_0, table_0, table_0,
154 table_4, table_4, table_4, table_4,
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, NULL, NULL}
163 static alloc_table_t * alloc_table [4] =
165 &mpeg2, &mpeg1_cd, &mpeg1_ab, &mpeg1_ab
167 static int sblimit_table[12] =
169 30, 8, 27, 30, 30, 8, 27, 27, 30, 12, 27, 30
174 if (!(header & 0x80000))
176 index = 0; /* mpeg2 */
180 index = (header >> 12) & 15; /* mpeg1, bitrate */
181 index = freq_table [index];
184 *alloc = alloc_table[index];
185 index |= (header >> 8) & 12;
186 *sblimit = sblimit_table[index];
189 int adec_layer2_mono( adec_thread_t * p_adec, s16 * buffer )
191 static u8 freq_table[15] = {2, 1, 1, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2};
192 static float L3_table[3] = {-2/3.0, 0, 2/3.0};
193 static float L5_table[5] = {-4/5.0, -2/5.0, 0, 2/5.0, 4/5.0};
194 static float L9_table[9] = {-8/9.0, -6/9.0, -4/9.0, -2/9.0, 0,
195 2/9.0, 4/9.0, 6/9.0, 8/9.0};
202 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 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
221 i_read_bits += alloc_table->nbal[sb];
223 allocation[sb] = alloc_table->alloc[sb][index];
228 for (sb = 0; sb < sblimit; sb++)
232 scfsi[sb] = GetBits (&p_adec->bit_stream, 2);
237 /* parse scalefactors */
239 for (sb = 0; sb < sblimit; sb++)
243 int index_0, index_1, index_2;
248 index_0 = GetBits(&p_adec->bit_stream,6);
249 index_1 = GetBits(&p_adec->bit_stream,6);
250 index_2 = GetBits(&p_adec->bit_stream,6);
253 if (allocation[sb] < 0)
255 slope[0][sb] = adec_scalefactor_table[index_0];
256 slope[1][sb] = adec_scalefactor_table[index_1];
257 slope[2][sb] = adec_scalefactor_table[index_2];
262 float r_slope, r_offset;
264 r_slope = adec_slope_table[allocation[sb]-2];
265 r_offset = adec_offset_table[allocation[sb]-2];
267 r_scalefactor = adec_scalefactor_table[index_0];
268 slope[0][sb] = r_slope * r_scalefactor;
269 offset[0][sb] = r_offset * r_scalefactor;
271 r_scalefactor = adec_scalefactor_table[index_1];
272 slope[1][sb] = r_slope * r_scalefactor;
273 offset[1][sb] = r_offset * r_scalefactor;
275 r_scalefactor = adec_scalefactor_table[index_2];
276 slope[2][sb] = r_slope * r_scalefactor;
277 offset[2][sb] = r_offset * r_scalefactor;
282 index_0 = GetBits(&p_adec->bit_stream,6);
283 index_1 = GetBits(&p_adec->bit_stream,6);
286 if (allocation[sb] < 0)
288 slope[0][sb] = slope[1][sb] =
289 adec_scalefactor_table[index_0];
290 slope[2][sb] = adec_scalefactor_table[index_1];
295 float r_slope, r_offset;
297 r_slope = adec_slope_table[allocation[sb]-2];
298 r_offset = adec_offset_table[allocation[sb]-2];
300 r_scalefactor = adec_scalefactor_table[index_0];
301 slope[0][sb] = slope[1][sb] = r_slope * r_scalefactor;
302 offset[0][sb] = offset[1][sb] =
303 r_offset * r_scalefactor;
305 r_scalefactor = adec_scalefactor_table[index_1];
306 slope[2][sb] = r_slope * r_scalefactor;
307 offset[2][sb] = r_offset * r_scalefactor;
312 index_0 = GetBits( &p_adec->bit_stream, 6 );
315 if (allocation[sb] < 0)
317 slope[0][sb] = slope[1][sb] = slope[2][sb] =
318 adec_scalefactor_table[index_0];
323 float r_slope, r_offset;
325 r_slope = adec_slope_table[allocation[sb]-2];
326 r_offset = adec_offset_table[allocation[sb]-2];
328 r_scalefactor = adec_scalefactor_table[index_0];
329 slope[0][sb] = slope[1][sb] = slope[2][sb] =
330 r_slope * r_scalefactor;
331 offset[0][sb] = offset[1][sb] = offset[2][sb] =
332 r_offset * r_scalefactor;
337 index_0 = GetBits(&p_adec->bit_stream,6);
338 index_1 = GetBits(&p_adec->bit_stream,6);
341 if (allocation[sb] < 0)
343 slope[0][sb] = adec_scalefactor_table[index_0];
344 slope[1][sb] = slope[2][sb] =
345 adec_scalefactor_table[index_1];
350 float r_slope, r_offset;
352 r_slope = adec_slope_table[allocation[sb]-2];
353 r_offset = adec_offset_table[allocation[sb]-2];
355 r_scalefactor = adec_scalefactor_table[index_0];
356 slope[0][sb] = r_slope * r_scalefactor;
357 offset[0][sb] = r_offset * r_scalefactor;
359 r_scalefactor = adec_scalefactor_table[index_1];
360 slope[1][sb] = slope[2][sb] = r_slope * r_scalefactor;
361 offset[1][sb] = offset[2][sb] =
362 r_offset * r_scalefactor;
371 for (gr0 = 0; gr0 < 3; gr0++)
373 for (gr1 = 0; gr1 < 4; gr1++)
377 for (sb = 0; sb < sblimit; sb++)
381 switch (allocation[sb])
384 sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
388 code = GetBits( &p_adec->bit_stream, 5 );
391 sample[0][sb] = slope[gr0][sb] * L3_table[code % 3];
393 sample[1][sb] = slope[gr0][sb] * L3_table[code % 3];
395 sample[2][sb] = slope[gr0][sb] * L3_table[code];
399 code = GetBits( &p_adec->bit_stream, 7 );
402 sample[0][sb] = slope[gr0][sb] * L5_table[code % 5];
404 sample[1][sb] = slope[gr0][sb] * L5_table[code % 5];
406 sample[2][sb] = slope[gr0][sb] * L5_table[code];
410 code = GetBits( &p_adec->bit_stream, 10 );
413 sample[0][sb] = slope[gr0][sb] * L9_table[code % 9];
415 sample[1][sb] = slope[gr0][sb] * L9_table[code % 9];
417 sample[2][sb] = slope[gr0][sb] * L9_table[code];
421 for (s = 0; s < 3; s++)
423 code = GetBits( &p_adec->bit_stream,
425 i_read_bits += allocation[sb];
428 slope[gr0][sb] * code + offset[gr0][sb];
433 for (; sb < 32; sb++)
435 sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
438 for (s = 0; s < 3; s++)
440 DCT32 (sample[s], &p_adec->bank_0);
442 PCM (&p_adec->bank_0, &XXX_buf, 2);
444 /* FIXME: one shouldn't have to do it twice ! */
445 DCT32 (sample[s], &p_adec->bank_1);
447 PCM (&p_adec->bank_1, &XXX_buf, 2);
454 p_adec->i_read_bits += i_read_bits;
459 int adec_layer2_stereo( adec_thread_t * p_adec, s16 * buffer )
461 static u8 freq_table[15] = {3, 0, 0, 0, 1, 0, 1, 2, 2, 2, 3, 3, 3, 3, 3};
462 static float L3_table[3] = {-2/3.0, 0, 2/3.0};
463 static float L5_table[5] = {-4/5.0, -2/5.0, 0, 2/5.0, 4/5.0};
464 static float L9_table[9] = {-8/9.0, -6/9.0, -4/9.0, -2/9.0, 0,
465 2/9.0, 4/9.0, 6/9.0, 8/9.0};
467 s8 allocation_0[32], allocation_1[32];
468 u8 scfsi_0[32], scfsi_1[32];
469 float slope_0[3][32], slope_1[3][32];
470 float offset_0[3][32], offset_1[3][32];
471 float sample_0[3][32], sample_1[3][32];
472 alloc_table_t * alloc_table;
481 /* get the right allocation table */
482 adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
484 /* calculate bound */
486 if ((p_adec->header & 0xc0) == 0x40) { /* intensity stereo */
488 index = (p_adec->header >> 4) & 3;
489 if (adec_bound_table[index] < sblimit)
491 bound = adec_bound_table[index];
495 /* parse allocation */
497 for (sb = 0; sb < bound; sb++)
501 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
502 allocation_0[sb] = alloc_table->alloc[sb][index];
504 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
505 allocation_1[sb] = alloc_table->alloc[sb][index];
507 i_read_bits += alloc_table->nbal[sb] * 2;
510 for (; sb < sblimit; sb++)
514 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
515 allocation_0[sb] = allocation_1[sb] = alloc_table->alloc[sb][index];
516 i_read_bits += alloc_table->nbal[sb];
521 for (sb = 0; sb < sblimit; sb++)
523 if (allocation_0[sb])
525 scfsi_0[sb] = GetBits (&p_adec->bit_stream, 2);
529 if (allocation_1[sb])
531 scfsi_1[sb] = GetBits (&p_adec->bit_stream, 2);
536 /* parse scalefactors */
538 for (sb = 0; sb < sblimit; sb++)
540 if (allocation_0[sb])
542 int index_0, index_1, index_2;
547 index_0 = GetBits(&p_adec->bit_stream,6);
548 index_1 = GetBits(&p_adec->bit_stream,6);
549 index_2 = GetBits(&p_adec->bit_stream,6);
552 if (allocation_0[sb] < 0)
554 slope_0[0][sb] = adec_scalefactor_table[index_0];
555 slope_0[1][sb] = adec_scalefactor_table[index_1];
556 slope_0[2][sb] = adec_scalefactor_table[index_2];
563 slope = adec_slope_table[allocation_0[sb]-2];
564 offset = adec_offset_table[allocation_0[sb]-2];
566 scalefactor = adec_scalefactor_table[index_0];
567 slope_0[0][sb] = slope * scalefactor;
568 offset_0[0][sb] = offset * scalefactor;
570 scalefactor = adec_scalefactor_table[index_1];
571 slope_0[1][sb] = slope * scalefactor;
572 offset_0[1][sb] = offset * scalefactor;
574 scalefactor = adec_scalefactor_table[index_2];
575 slope_0[2][sb] = slope * scalefactor;
576 offset_0[2][sb] = offset * scalefactor;
581 index_0 = GetBits(&p_adec->bit_stream,6);
582 index_1 = GetBits(&p_adec->bit_stream,6);
585 if (allocation_0[sb] < 0)
587 slope_0[0][sb] = slope_0[1][sb] =
588 adec_scalefactor_table[index_0];
589 slope_0[2][sb] = adec_scalefactor_table[index_1];
596 slope = adec_slope_table[allocation_0[sb]-2];
597 offset = adec_offset_table[allocation_0[sb]-2];
599 scalefactor = adec_scalefactor_table[index_0];
600 slope_0[0][sb] = slope_0[1][sb] = slope * scalefactor;
601 offset_0[0][sb] = offset_0[1][sb] =
602 offset * scalefactor;
604 scalefactor = adec_scalefactor_table[index_1];
605 slope_0[2][sb] = slope * scalefactor;
606 offset_0[2][sb] = offset * scalefactor;
611 index_0 = GetBits( &p_adec->bit_stream, 6 );
614 if (allocation_0[sb] < 0)
616 slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
617 adec_scalefactor_table[index_0];
624 slope = adec_slope_table[allocation_0[sb]-2];
625 offset = adec_offset_table[allocation_0[sb]-2];
627 scalefactor = adec_scalefactor_table[index_0];
628 slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
630 offset_0[0][sb] = offset_0[1][sb] = offset_0[2][sb] =
631 offset * scalefactor;
636 index_0 = GetBits(&p_adec->bit_stream,6);
637 index_1 = GetBits(&p_adec->bit_stream,6);
640 if (allocation_0[sb] < 0)
642 slope_0[0][sb] = adec_scalefactor_table[index_0];
643 slope_0[1][sb] = slope_0[2][sb] =
644 adec_scalefactor_table[index_1];
651 slope = adec_slope_table[allocation_0[sb]-2];
652 offset = adec_offset_table[allocation_0[sb]-2];
654 scalefactor = adec_scalefactor_table[index_0];
655 slope_0[0][sb] = slope * scalefactor;
656 offset_0[0][sb] = offset * scalefactor;
658 scalefactor = adec_scalefactor_table[index_1];
659 slope_0[1][sb] = slope_0[2][sb] = slope * scalefactor;
660 offset_0[1][sb] = offset_0[2][sb] =
661 offset * scalefactor;
667 if (allocation_1[sb])
669 int index_0, index_1, index_2;
674 index_0 = GetBits(&p_adec->bit_stream,6);
675 index_1 = GetBits(&p_adec->bit_stream,6);
676 index_2 = GetBits(&p_adec->bit_stream,6);
679 if (allocation_1[sb] < 0)
681 slope_1[0][sb] = adec_scalefactor_table[index_0];
682 slope_1[1][sb] = adec_scalefactor_table[index_1];
683 slope_1[2][sb] = adec_scalefactor_table[index_2];
690 slope = adec_slope_table[allocation_1[sb]-2];
691 offset = adec_offset_table[allocation_1[sb]-2];
693 scalefactor = adec_scalefactor_table[index_0];
694 slope_1[0][sb] = slope * scalefactor;
695 offset_1[0][sb] = offset * scalefactor;
697 scalefactor = adec_scalefactor_table[index_1];
698 slope_1[1][sb] = slope * scalefactor;
699 offset_1[1][sb] = offset * scalefactor;
701 scalefactor = adec_scalefactor_table[index_2];
702 slope_1[2][sb] = slope * scalefactor;
703 offset_1[2][sb] = offset * scalefactor;
708 index_0 = GetBits(&p_adec->bit_stream,6);
709 index_1 = GetBits(&p_adec->bit_stream,6);
712 if (allocation_1[sb] < 0)
714 slope_1[0][sb] = slope_1[1][sb] =
715 adec_scalefactor_table[index_0];
716 slope_1[2][sb] = adec_scalefactor_table[index_1];
723 slope = adec_slope_table[allocation_1[sb]-2];
724 offset = adec_offset_table[allocation_1[sb]-2];
726 scalefactor = adec_scalefactor_table[index_0];
727 slope_1[0][sb] = slope_1[1][sb] = slope * scalefactor;
728 offset_1[0][sb] = offset_1[1][sb] =
729 offset * scalefactor;
731 scalefactor = adec_scalefactor_table[index_1];
732 slope_1[2][sb] = slope * scalefactor;
733 offset_1[2][sb] = offset * scalefactor;
738 index_0 = GetBits( &p_adec->bit_stream, 6 );
741 if (allocation_1[sb] < 0)
743 slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
744 adec_scalefactor_table[index_0];
751 slope = adec_slope_table[allocation_1[sb]-2];
752 offset = adec_offset_table[allocation_1[sb]-2];
754 scalefactor = adec_scalefactor_table[index_0];
755 slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
757 offset_1[0][sb] = offset_1[1][sb] = offset_1[2][sb] =
758 offset * scalefactor;
763 index_0 = GetBits(&p_adec->bit_stream,6);
764 index_1 = GetBits(&p_adec->bit_stream,6);
767 if (allocation_1[sb] < 0)
769 slope_1[0][sb] = adec_scalefactor_table[index_0];
770 slope_1[1][sb] = slope_1[2][sb] =
771 adec_scalefactor_table[index_1];
778 slope = adec_slope_table[allocation_1[sb]-2];
779 offset = adec_offset_table[allocation_1[sb]-2];
781 scalefactor = adec_scalefactor_table[index_0];
782 slope_1[0][sb] = slope * scalefactor;
783 offset_1[0][sb] = offset * scalefactor;
785 scalefactor = adec_scalefactor_table[index_1];
786 slope_1[1][sb] = slope_1[2][sb] = slope * scalefactor;
787 offset_1[1][sb] = offset_1[2][sb] =
788 offset * scalefactor;
797 for (gr0 = 0; gr0 < 3; gr0++)
799 for (gr1 = 0; gr1 < 4; gr1++)
803 for (sb = 0; sb < bound; sb++)
807 switch (allocation_0[sb])
810 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
814 code = GetBits( &p_adec->bit_stream, 5 );
817 sample_0[0][sb] = slope_0[gr0][sb] * L3_table[code % 3];
819 sample_0[1][sb] = slope_0[gr0][sb] * L3_table[code % 3];
821 sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code];
825 code = GetBits( &p_adec->bit_stream, 7 );
828 sample_0[0][sb] = slope_0[gr0][sb] * L5_table[code % 5];
830 sample_0[1][sb] = slope_0[gr0][sb] * L5_table[code % 5];
832 sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code];
836 code = GetBits( &p_adec->bit_stream, 10 );
839 sample_0[0][sb] = slope_0[gr0][sb] * L9_table[code % 9];
841 sample_0[1][sb] = slope_0[gr0][sb] * L9_table[code % 9];
843 sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code];
847 for (s = 0; s < 3; s++)
849 code = GetBits( &p_adec->bit_stream,
851 i_read_bits += allocation_0[sb];
854 slope_0[gr0][sb] * code + offset_0[gr0][sb];
858 switch (allocation_1[sb])
861 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
865 code = GetBits( &p_adec->bit_stream, 5 );
868 sample_1[0][sb] = slope_1[gr0][sb] * L3_table[code % 3];
870 sample_1[1][sb] = slope_1[gr0][sb] * L3_table[code % 3];
872 sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code];
876 code = GetBits( &p_adec->bit_stream, 7 );
879 sample_1[0][sb] = slope_1[gr0][sb] * L5_table[code % 5];
881 sample_1[1][sb] = slope_1[gr0][sb] * L5_table[code % 5];
883 sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code];
887 code = GetBits( &p_adec->bit_stream, 10 );
890 sample_1[0][sb] = slope_1[gr0][sb] * L9_table[code % 9];
892 sample_1[1][sb] = slope_1[gr0][sb] * L9_table[code % 9];
894 sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code];
898 for (s = 0; s < 3; s++)
900 code = GetBits( &p_adec->bit_stream,
902 i_read_bits += allocation_1[sb];
905 slope_1[gr0][sb] * code + offset_1[gr0][sb];
910 for (; sb < sblimit; sb++)
914 switch (allocation_0[sb])
917 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
918 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
922 code = GetBits( &p_adec->bit_stream, 5 );
925 sample_0[0][sb] = slope_0[gr0][sb] * L3_table[code % 3];
926 sample_1[0][sb] = slope_1[gr0][sb] * L3_table[code % 3];
928 sample_0[1][sb] = slope_0[gr0][sb] * L3_table[code % 3];
929 sample_1[1][sb] = slope_1[gr0][sb] * L3_table[code % 3];
931 sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code];
932 sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code];
936 code = GetBits( &p_adec->bit_stream, 7 );
939 sample_0[0][sb] = slope_0[gr0][sb] * L5_table[code % 5];
940 sample_1[0][sb] = slope_1[gr0][sb] * L5_table[code % 5];
942 sample_0[1][sb] = slope_0[gr0][sb] * L5_table[code % 5];
943 sample_1[1][sb] = slope_1[gr0][sb] * L5_table[code % 5];
945 sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code];
946 sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code];
950 code = GetBits( &p_adec->bit_stream, 10 );
953 sample_0[0][sb] = slope_0[gr0][sb] * L9_table[code % 9];
954 sample_1[0][sb] = slope_1[gr0][sb] * L9_table[code % 9];
956 sample_0[1][sb] = slope_0[gr0][sb] * L9_table[code % 9];
957 sample_1[1][sb] = slope_1[gr0][sb] * L9_table[code % 9];
959 sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code];
960 sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code];
964 for (s = 0; s < 3; s++)
966 code = GetBits( &p_adec->bit_stream,
968 i_read_bits += allocation_0[sb];
971 slope_0[gr0][sb] * code + offset_0[gr0][sb];
973 slope_1[gr0][sb] * code + offset_1[gr0][sb];
978 for (; sb < 32; sb++)
980 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
981 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
984 for (s = 0; s < 3; s++)
986 DCT32 (sample_0[s], &p_adec->bank_0);
988 PCM (&p_adec->bank_0, &XXX_buf, 2);
990 DCT32 (sample_1[s], &p_adec->bank_1);
992 PCM (&p_adec->bank_1, &XXX_buf, 2);
999 p_adec->i_read_bits += i_read_bits;