1 /*****************************************************************************
2 * adec_layer2.c: MPEG Layer II audio decoder
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: adec_layer2.c,v 1.6 2002/02/24 22:06:50 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++)
375 for (sb = 0; sb < sblimit; sb++)
379 switch (allocation[sb])
382 sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
386 code = GetBits( &p_adec->bit_stream, 5 );
389 sample[0][sb] = slope[gr0][sb] * L3_table[code % 3];
391 sample[1][sb] = slope[gr0][sb] * L3_table[code % 3];
393 sample[2][sb] = slope[gr0][sb] * L3_table[code];
397 code = GetBits( &p_adec->bit_stream, 7 );
400 sample[0][sb] = slope[gr0][sb] * L5_table[code % 5];
402 sample[1][sb] = slope[gr0][sb] * L5_table[code % 5];
404 sample[2][sb] = slope[gr0][sb] * L5_table[code];
408 code = GetBits( &p_adec->bit_stream, 10 );
411 sample[0][sb] = slope[gr0][sb] * L9_table[code % 9];
413 sample[1][sb] = slope[gr0][sb] * L9_table[code % 9];
415 sample[2][sb] = slope[gr0][sb] * L9_table[code];
419 for (s = 0; s < 3; s++)
421 code = GetBits( &p_adec->bit_stream,
423 i_read_bits += allocation[sb];
426 slope[gr0][sb] * code + offset[gr0][sb];
431 for (; sb < 32; sb++)
433 sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
436 for (s = 0; s < 3; s++)
438 DCT32( &p_adec->bank_0, sample[s] );
439 PCM( &p_adec->bank_0, buffer, 2 );
441 /* FIXME: one shouldn't have to do it twice ! */
442 DCT32( &p_adec->bank_1, sample[s] );
443 PCM( &p_adec->bank_1, buffer + 1, 2 );
450 p_adec->i_read_bits += i_read_bits;
455 int adec_layer2_stereo( adec_thread_t * p_adec, s16 * buffer )
457 static u8 freq_table[15] = {3, 0, 0, 0, 1, 0, 1, 2, 2, 2, 3, 3, 3, 3, 3};
458 static float L3_table[3] = {-2/3.0, 0, 2/3.0};
459 static float L5_table[5] = {-4/5.0, -2/5.0, 0, 2/5.0, 4/5.0};
460 static float L9_table[9] = {-8/9.0, -6/9.0, -4/9.0, -2/9.0, 0,
461 2/9.0, 4/9.0, 6/9.0, 8/9.0};
463 s8 allocation_0[32], allocation_1[32];
464 u8 scfsi_0[32], scfsi_1[32];
465 float slope_0[3][32], slope_1[3][32];
466 float offset_0[3][32], offset_1[3][32];
467 float sample_0[3][32], sample_1[3][32];
468 alloc_table_t * alloc_table;
477 /* get the right allocation table */
478 adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
480 /* calculate bound */
482 if ((p_adec->header & 0xc0) == 0x40) { /* intensity stereo */
484 index = (p_adec->header >> 4) & 3;
485 if (adec_bound_table[index] < sblimit)
487 bound = adec_bound_table[index];
491 /* parse allocation */
493 for (sb = 0; sb < bound; sb++)
497 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
498 allocation_0[sb] = alloc_table->alloc[sb][index];
500 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
501 allocation_1[sb] = alloc_table->alloc[sb][index];
503 i_read_bits += alloc_table->nbal[sb] * 2;
506 for (; sb < sblimit; sb++)
510 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
511 allocation_0[sb] = allocation_1[sb] = alloc_table->alloc[sb][index];
512 i_read_bits += alloc_table->nbal[sb];
517 for (sb = 0; sb < sblimit; sb++)
519 if (allocation_0[sb])
521 scfsi_0[sb] = GetBits (&p_adec->bit_stream, 2);
525 if (allocation_1[sb])
527 scfsi_1[sb] = GetBits (&p_adec->bit_stream, 2);
532 /* parse scalefactors */
534 for (sb = 0; sb < sblimit; sb++)
536 if (allocation_0[sb])
538 int index_0, index_1, index_2;
543 index_0 = GetBits(&p_adec->bit_stream,6);
544 index_1 = GetBits(&p_adec->bit_stream,6);
545 index_2 = GetBits(&p_adec->bit_stream,6);
548 if (allocation_0[sb] < 0)
550 slope_0[0][sb] = adec_scalefactor_table[index_0];
551 slope_0[1][sb] = adec_scalefactor_table[index_1];
552 slope_0[2][sb] = adec_scalefactor_table[index_2];
559 slope = adec_slope_table[allocation_0[sb]-2];
560 offset = adec_offset_table[allocation_0[sb]-2];
562 scalefactor = adec_scalefactor_table[index_0];
563 slope_0[0][sb] = slope * scalefactor;
564 offset_0[0][sb] = offset * scalefactor;
566 scalefactor = adec_scalefactor_table[index_1];
567 slope_0[1][sb] = slope * scalefactor;
568 offset_0[1][sb] = offset * scalefactor;
570 scalefactor = adec_scalefactor_table[index_2];
571 slope_0[2][sb] = slope * scalefactor;
572 offset_0[2][sb] = offset * scalefactor;
577 index_0 = GetBits(&p_adec->bit_stream,6);
578 index_1 = GetBits(&p_adec->bit_stream,6);
581 if (allocation_0[sb] < 0)
583 slope_0[0][sb] = slope_0[1][sb] =
584 adec_scalefactor_table[index_0];
585 slope_0[2][sb] = adec_scalefactor_table[index_1];
592 slope = adec_slope_table[allocation_0[sb]-2];
593 offset = adec_offset_table[allocation_0[sb]-2];
595 scalefactor = adec_scalefactor_table[index_0];
596 slope_0[0][sb] = slope_0[1][sb] = slope * scalefactor;
597 offset_0[0][sb] = offset_0[1][sb] =
598 offset * scalefactor;
600 scalefactor = adec_scalefactor_table[index_1];
601 slope_0[2][sb] = slope * scalefactor;
602 offset_0[2][sb] = offset * scalefactor;
607 index_0 = GetBits( &p_adec->bit_stream, 6 );
610 if (allocation_0[sb] < 0)
612 slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
613 adec_scalefactor_table[index_0];
620 slope = adec_slope_table[allocation_0[sb]-2];
621 offset = adec_offset_table[allocation_0[sb]-2];
623 scalefactor = adec_scalefactor_table[index_0];
624 slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
626 offset_0[0][sb] = offset_0[1][sb] = offset_0[2][sb] =
627 offset * scalefactor;
632 index_0 = GetBits(&p_adec->bit_stream,6);
633 index_1 = GetBits(&p_adec->bit_stream,6);
636 if (allocation_0[sb] < 0)
638 slope_0[0][sb] = adec_scalefactor_table[index_0];
639 slope_0[1][sb] = slope_0[2][sb] =
640 adec_scalefactor_table[index_1];
647 slope = adec_slope_table[allocation_0[sb]-2];
648 offset = adec_offset_table[allocation_0[sb]-2];
650 scalefactor = adec_scalefactor_table[index_0];
651 slope_0[0][sb] = slope * scalefactor;
652 offset_0[0][sb] = offset * scalefactor;
654 scalefactor = adec_scalefactor_table[index_1];
655 slope_0[1][sb] = slope_0[2][sb] = slope * scalefactor;
656 offset_0[1][sb] = offset_0[2][sb] =
657 offset * scalefactor;
663 if (allocation_1[sb])
665 int index_0, index_1, index_2;
670 index_0 = GetBits(&p_adec->bit_stream,6);
671 index_1 = GetBits(&p_adec->bit_stream,6);
672 index_2 = GetBits(&p_adec->bit_stream,6);
675 if (allocation_1[sb] < 0)
677 slope_1[0][sb] = adec_scalefactor_table[index_0];
678 slope_1[1][sb] = adec_scalefactor_table[index_1];
679 slope_1[2][sb] = adec_scalefactor_table[index_2];
686 slope = adec_slope_table[allocation_1[sb]-2];
687 offset = adec_offset_table[allocation_1[sb]-2];
689 scalefactor = adec_scalefactor_table[index_0];
690 slope_1[0][sb] = slope * scalefactor;
691 offset_1[0][sb] = offset * scalefactor;
693 scalefactor = adec_scalefactor_table[index_1];
694 slope_1[1][sb] = slope * scalefactor;
695 offset_1[1][sb] = offset * scalefactor;
697 scalefactor = adec_scalefactor_table[index_2];
698 slope_1[2][sb] = slope * scalefactor;
699 offset_1[2][sb] = offset * scalefactor;
704 index_0 = GetBits(&p_adec->bit_stream,6);
705 index_1 = GetBits(&p_adec->bit_stream,6);
708 if (allocation_1[sb] < 0)
710 slope_1[0][sb] = slope_1[1][sb] =
711 adec_scalefactor_table[index_0];
712 slope_1[2][sb] = adec_scalefactor_table[index_1];
719 slope = adec_slope_table[allocation_1[sb]-2];
720 offset = adec_offset_table[allocation_1[sb]-2];
722 scalefactor = adec_scalefactor_table[index_0];
723 slope_1[0][sb] = slope_1[1][sb] = slope * scalefactor;
724 offset_1[0][sb] = offset_1[1][sb] =
725 offset * scalefactor;
727 scalefactor = adec_scalefactor_table[index_1];
728 slope_1[2][sb] = slope * scalefactor;
729 offset_1[2][sb] = offset * scalefactor;
734 index_0 = GetBits( &p_adec->bit_stream, 6 );
737 if (allocation_1[sb] < 0)
739 slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
740 adec_scalefactor_table[index_0];
747 slope = adec_slope_table[allocation_1[sb]-2];
748 offset = adec_offset_table[allocation_1[sb]-2];
750 scalefactor = adec_scalefactor_table[index_0];
751 slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
753 offset_1[0][sb] = offset_1[1][sb] = offset_1[2][sb] =
754 offset * scalefactor;
759 index_0 = GetBits(&p_adec->bit_stream,6);
760 index_1 = GetBits(&p_adec->bit_stream,6);
763 if (allocation_1[sb] < 0)
765 slope_1[0][sb] = adec_scalefactor_table[index_0];
766 slope_1[1][sb] = slope_1[2][sb] =
767 adec_scalefactor_table[index_1];
774 slope = adec_slope_table[allocation_1[sb]-2];
775 offset = adec_offset_table[allocation_1[sb]-2];
777 scalefactor = adec_scalefactor_table[index_0];
778 slope_1[0][sb] = slope * scalefactor;
779 offset_1[0][sb] = offset * scalefactor;
781 scalefactor = adec_scalefactor_table[index_1];
782 slope_1[1][sb] = slope_1[2][sb] = slope * scalefactor;
783 offset_1[1][sb] = offset_1[2][sb] =
784 offset * scalefactor;
793 for (gr0 = 0; gr0 < 3; gr0++)
795 for (gr1 = 0; gr1 < 4; gr1++)
797 for (sb = 0; sb < bound; sb++)
801 switch (allocation_0[sb])
804 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
808 code = GetBits( &p_adec->bit_stream, 5 );
811 sample_0[0][sb] = slope_0[gr0][sb] * L3_table[code % 3];
813 sample_0[1][sb] = slope_0[gr0][sb] * L3_table[code % 3];
815 sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code];
819 code = GetBits( &p_adec->bit_stream, 7 );
822 sample_0[0][sb] = slope_0[gr0][sb] * L5_table[code % 5];
824 sample_0[1][sb] = slope_0[gr0][sb] * L5_table[code % 5];
826 sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code];
830 code = GetBits( &p_adec->bit_stream, 10 );
833 sample_0[0][sb] = slope_0[gr0][sb] * L9_table[code % 9];
835 sample_0[1][sb] = slope_0[gr0][sb] * L9_table[code % 9];
837 sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code];
841 for (s = 0; s < 3; s++)
843 code = GetBits( &p_adec->bit_stream,
845 i_read_bits += allocation_0[sb];
848 slope_0[gr0][sb] * code + offset_0[gr0][sb];
852 switch (allocation_1[sb])
855 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
859 code = GetBits( &p_adec->bit_stream, 5 );
862 sample_1[0][sb] = slope_1[gr0][sb] * L3_table[code % 3];
864 sample_1[1][sb] = slope_1[gr0][sb] * L3_table[code % 3];
866 sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code];
870 code = GetBits( &p_adec->bit_stream, 7 );
873 sample_1[0][sb] = slope_1[gr0][sb] * L5_table[code % 5];
875 sample_1[1][sb] = slope_1[gr0][sb] * L5_table[code % 5];
877 sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code];
881 code = GetBits( &p_adec->bit_stream, 10 );
884 sample_1[0][sb] = slope_1[gr0][sb] * L9_table[code % 9];
886 sample_1[1][sb] = slope_1[gr0][sb] * L9_table[code % 9];
888 sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code];
892 for (s = 0; s < 3; s++)
894 code = GetBits( &p_adec->bit_stream,
896 i_read_bits += allocation_1[sb];
899 slope_1[gr0][sb] * code + offset_1[gr0][sb];
904 for (; sb < sblimit; sb++)
908 switch (allocation_0[sb])
911 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
912 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
916 code = GetBits( &p_adec->bit_stream, 5 );
919 sample_0[0][sb] = slope_0[gr0][sb] * L3_table[code % 3];
920 sample_1[0][sb] = slope_1[gr0][sb] * L3_table[code % 3];
922 sample_0[1][sb] = slope_0[gr0][sb] * L3_table[code % 3];
923 sample_1[1][sb] = slope_1[gr0][sb] * L3_table[code % 3];
925 sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code];
926 sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code];
930 code = GetBits( &p_adec->bit_stream, 7 );
933 sample_0[0][sb] = slope_0[gr0][sb] * L5_table[code % 5];
934 sample_1[0][sb] = slope_1[gr0][sb] * L5_table[code % 5];
936 sample_0[1][sb] = slope_0[gr0][sb] * L5_table[code % 5];
937 sample_1[1][sb] = slope_1[gr0][sb] * L5_table[code % 5];
939 sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code];
940 sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code];
944 code = GetBits( &p_adec->bit_stream, 10 );
947 sample_0[0][sb] = slope_0[gr0][sb] * L9_table[code % 9];
948 sample_1[0][sb] = slope_1[gr0][sb] * L9_table[code % 9];
950 sample_0[1][sb] = slope_0[gr0][sb] * L9_table[code % 9];
951 sample_1[1][sb] = slope_1[gr0][sb] * L9_table[code % 9];
953 sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code];
954 sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code];
958 for (s = 0; s < 3; s++)
960 code = GetBits( &p_adec->bit_stream,
962 i_read_bits += allocation_0[sb];
965 slope_0[gr0][sb] * code + offset_0[gr0][sb];
967 slope_1[gr0][sb] * code + offset_1[gr0][sb];
972 for (; sb < 32; sb++)
974 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
975 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
978 for (s = 0; s < 3; s++)
980 DCT32( &p_adec->bank_0, sample_0[s] );
981 PCM( &p_adec->bank_0, buffer, 2 );
983 DCT32( &p_adec->bank_1, sample_1[s] );
984 PCM( &p_adec->bank_1, buffer + 1, 2 );
991 p_adec->i_read_bits += i_read_bits;