1 /*****************************************************************************
2 * adec_layer2.c: MPEG Layer II audio decoder
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: adec_layer2.c,v 1.7 2002/06/01 12:32:00 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() */
29 #include <vlc/decoder.h>
31 #include "mpeg_adec_generic.h"
32 #include "mpeg_adec.h"
33 #include "adec_math.h" /* DCT32(), PCM() */
37 static float adec_scalefactor_table[64] =
39 2.0000000000000000, 1.5874010519681994, 1.2599210498948732,
40 1.0000000000000000, 0.7937005259840998, 0.6299605249474366,
41 0.5000000000000000, 0.3968502629920499, 0.3149802624737183,
42 0.2500000000000000, 0.1984251314960249, 0.1574901312368591,
43 0.1250000000000000, 0.0992125657480125, 0.0787450656184296,
44 0.0625000000000000, 0.0496062828740062, 0.0393725328092148,
45 0.0312500000000000, 0.0248031414370031, 0.0196862664046074,
46 0.0156250000000000, 0.0124015707185016, 0.0098431332023037,
47 0.0078125000000000, 0.0062007853592508, 0.0049215666011518,
48 0.0039062500000000, 0.0031003926796254, 0.0024607833005759,
49 0.0019531250000000, 0.0015501963398127, 0.0012303916502880,
50 0.0009765625000000, 0.0007750981699063, 0.0006151958251440,
51 0.0004882812500000, 0.0003875490849532, 0.0003075979125720,
52 0.0002441406250000, 0.0001937745424766, 0.0001537989562860,
53 0.0001220703125000, 0.0000968872712383, 0.0000768994781430,
54 0.0000610351562500, 0.0000484436356191, 0.0000384497390715,
55 0.0000305175781250, 0.0000242218178096, 0.0000192248695357,
56 0.0000152587890625, 0.0000121109089048, 0.0000096124347679,
57 0.0000076293945312, 0.0000060554544524, 0.0000048062173839,
58 0.0000038146972656, 0.0000030277272262, 0.0000024031086920,
59 0.0000019073486328, 0.0000015138636131, 0.0000012015543460,
60 0.0000009536743164 /* last element is not in the standard... invalid ??? */
63 static float adec_slope_table[15] =
65 0.6666666666666666, 0.2857142857142857, 0.1333333333333333,
66 0.0645161290322581, 0.0317460317460317, 0.0157480314960630,
67 0.0078431372549020, 0.0039138943248532, 0.0019550342130987,
68 0.0009770395701026, 0.0004884004884005, 0.0002441704309608,
69 0.0001220777635354, 0.0000610370189520, 0.0000305180437934
72 static float adec_offset_table[15] =
74 -0.6666666666666666, -0.8571428571428571, -0.9333333333333333,
75 -0.9677419354838710, -0.9841269841269841, -0.9921259842519685,
76 -0.9960784313725490, -0.9980430528375733, -0.9990224828934506,
77 -0.9995114802149487, -0.9997557997557998, -0.9998779147845196,
78 -0.9999389611182323, -0.9999694814905240, -0.9999847409781033
81 static int adec_bound_table[4] = { 4, 8, 12, 16 };
93 static void adec_layer2_get_table( u32 header, u8 freq_table[15],
94 alloc_table_t ** alloc, int * sblimit )
96 static s8 table_ab0[16] =
98 0, L3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
100 static s8 table_ab3[16] =
102 0, L3, L5, 3, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16
104 static s8 table_ab11[8] =
106 0, L3, L5, 3, L9, 4, 5, 16
108 static s8 table_ab23[8] =
112 static alloc_table_t mpeg1_ab =
114 {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},
115 {table_ab0, table_ab0, table_ab0, table_ab3,
116 table_ab3, table_ab3, table_ab3, table_ab3,
117 table_ab3, table_ab3, table_ab3, table_ab11,
118 table_ab11, table_ab11, table_ab11, table_ab11,
119 table_ab11, table_ab11, table_ab11, table_ab11,
120 table_ab11, table_ab11, table_ab11, table_ab23,
121 table_ab23, table_ab23, table_ab23, table_ab23,
122 table_ab23, table_ab23, NULL, NULL}
125 static s8 table_cd[16] =
127 0, L3, L5, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
129 static alloc_table_t mpeg1_cd =
131 {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},
132 {table_cd, table_cd, table_cd, table_cd,
133 table_cd, table_cd, table_cd, table_cd,
134 table_cd, table_cd, table_cd, table_cd,
135 NULL, NULL, NULL, NULL,
136 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
137 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
140 static s8 table_0[16] =
142 0, L3, L5, 3, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
144 static s8 table_4[8] =
146 0, L3, L5, L9, 4, 5, 6, 7
148 static alloc_table_t mpeg2 =
150 {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},
151 {table_0, table_0, table_0, table_0,
152 table_4, table_4, table_4, table_4,
153 table_4, table_4, table_4, table_4,
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, NULL, NULL}
161 static alloc_table_t * alloc_table [4] =
163 &mpeg2, &mpeg1_cd, &mpeg1_ab, &mpeg1_ab
165 static int sblimit_table[12] =
167 30, 8, 27, 30, 30, 8, 27, 27, 30, 12, 27, 30
172 if (!(header & 0x80000))
174 index = 0; /* mpeg2 */
178 index = (header >> 12) & 15; /* mpeg1, bitrate */
179 index = freq_table [index];
182 *alloc = alloc_table[index];
183 index |= (header >> 8) & 12;
184 *sblimit = sblimit_table[index];
187 int adec_layer2_mono( adec_thread_t * p_adec, s16 * buffer )
189 static u8 freq_table[15] = {2, 1, 1, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2};
190 static float L3_table[3] = {-2/3.0, 0, 2/3.0};
191 static float L5_table[5] = {-4/5.0, -2/5.0, 0, 2/5.0, 4/5.0};
192 static float L9_table[9] = {-8/9.0, -6/9.0, -4/9.0, -2/9.0, 0,
193 2/9.0, 4/9.0, 6/9.0, 8/9.0};
200 alloc_table_t * alloc_table;
208 /* get the right allocation table */
209 adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
211 /* parse allocation */
214 for (sb = 0; sb < sblimit; sb++)
218 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
219 i_read_bits += alloc_table->nbal[sb];
221 allocation[sb] = alloc_table->alloc[sb][index];
226 for (sb = 0; sb < sblimit; sb++)
230 scfsi[sb] = GetBits (&p_adec->bit_stream, 2);
235 /* parse scalefactors */
237 for (sb = 0; sb < sblimit; sb++)
241 int index_0, index_1, index_2;
246 index_0 = GetBits(&p_adec->bit_stream,6);
247 index_1 = GetBits(&p_adec->bit_stream,6);
248 index_2 = GetBits(&p_adec->bit_stream,6);
251 if (allocation[sb] < 0)
253 slope[0][sb] = adec_scalefactor_table[index_0];
254 slope[1][sb] = adec_scalefactor_table[index_1];
255 slope[2][sb] = adec_scalefactor_table[index_2];
260 float r_slope, r_offset;
262 r_slope = adec_slope_table[allocation[sb]-2];
263 r_offset = adec_offset_table[allocation[sb]-2];
265 r_scalefactor = adec_scalefactor_table[index_0];
266 slope[0][sb] = r_slope * r_scalefactor;
267 offset[0][sb] = r_offset * r_scalefactor;
269 r_scalefactor = adec_scalefactor_table[index_1];
270 slope[1][sb] = r_slope * r_scalefactor;
271 offset[1][sb] = r_offset * r_scalefactor;
273 r_scalefactor = adec_scalefactor_table[index_2];
274 slope[2][sb] = r_slope * r_scalefactor;
275 offset[2][sb] = r_offset * r_scalefactor;
280 index_0 = GetBits(&p_adec->bit_stream,6);
281 index_1 = GetBits(&p_adec->bit_stream,6);
284 if (allocation[sb] < 0)
286 slope[0][sb] = slope[1][sb] =
287 adec_scalefactor_table[index_0];
288 slope[2][sb] = adec_scalefactor_table[index_1];
293 float r_slope, r_offset;
295 r_slope = adec_slope_table[allocation[sb]-2];
296 r_offset = adec_offset_table[allocation[sb]-2];
298 r_scalefactor = adec_scalefactor_table[index_0];
299 slope[0][sb] = slope[1][sb] = r_slope * r_scalefactor;
300 offset[0][sb] = offset[1][sb] =
301 r_offset * r_scalefactor;
303 r_scalefactor = adec_scalefactor_table[index_1];
304 slope[2][sb] = r_slope * r_scalefactor;
305 offset[2][sb] = r_offset * r_scalefactor;
310 index_0 = GetBits( &p_adec->bit_stream, 6 );
313 if (allocation[sb] < 0)
315 slope[0][sb] = slope[1][sb] = slope[2][sb] =
316 adec_scalefactor_table[index_0];
321 float r_slope, r_offset;
323 r_slope = adec_slope_table[allocation[sb]-2];
324 r_offset = adec_offset_table[allocation[sb]-2];
326 r_scalefactor = adec_scalefactor_table[index_0];
327 slope[0][sb] = slope[1][sb] = slope[2][sb] =
328 r_slope * r_scalefactor;
329 offset[0][sb] = offset[1][sb] = offset[2][sb] =
330 r_offset * r_scalefactor;
335 index_0 = GetBits(&p_adec->bit_stream,6);
336 index_1 = GetBits(&p_adec->bit_stream,6);
339 if (allocation[sb] < 0)
341 slope[0][sb] = adec_scalefactor_table[index_0];
342 slope[1][sb] = slope[2][sb] =
343 adec_scalefactor_table[index_1];
348 float r_slope, r_offset;
350 r_slope = adec_slope_table[allocation[sb]-2];
351 r_offset = adec_offset_table[allocation[sb]-2];
353 r_scalefactor = adec_scalefactor_table[index_0];
354 slope[0][sb] = r_slope * r_scalefactor;
355 offset[0][sb] = r_offset * r_scalefactor;
357 r_scalefactor = adec_scalefactor_table[index_1];
358 slope[1][sb] = slope[2][sb] = r_slope * r_scalefactor;
359 offset[1][sb] = offset[2][sb] =
360 r_offset * r_scalefactor;
369 for (gr0 = 0; gr0 < 3; gr0++)
371 for (gr1 = 0; gr1 < 4; gr1++)
373 for (sb = 0; sb < sblimit; sb++)
377 switch (allocation[sb])
380 sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
384 code = GetBits( &p_adec->bit_stream, 5 );
387 sample[0][sb] = slope[gr0][sb] * L3_table[code % 3];
389 sample[1][sb] = slope[gr0][sb] * L3_table[code % 3];
391 sample[2][sb] = slope[gr0][sb] * L3_table[code];
395 code = GetBits( &p_adec->bit_stream, 7 );
398 sample[0][sb] = slope[gr0][sb] * L5_table[code % 5];
400 sample[1][sb] = slope[gr0][sb] * L5_table[code % 5];
402 sample[2][sb] = slope[gr0][sb] * L5_table[code];
406 code = GetBits( &p_adec->bit_stream, 10 );
409 sample[0][sb] = slope[gr0][sb] * L9_table[code % 9];
411 sample[1][sb] = slope[gr0][sb] * L9_table[code % 9];
413 sample[2][sb] = slope[gr0][sb] * L9_table[code];
417 for (s = 0; s < 3; s++)
419 code = GetBits( &p_adec->bit_stream,
421 i_read_bits += allocation[sb];
424 slope[gr0][sb] * code + offset[gr0][sb];
429 for (; sb < 32; sb++)
431 sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
434 for (s = 0; s < 3; s++)
436 DCT32( &p_adec->bank_0, sample[s] );
437 PCM( &p_adec->bank_0, buffer, 2 );
439 /* FIXME: one shouldn't have to do it twice ! */
440 DCT32( &p_adec->bank_1, sample[s] );
441 PCM( &p_adec->bank_1, buffer + 1, 2 );
448 p_adec->i_read_bits += i_read_bits;
453 int adec_layer2_stereo( adec_thread_t * p_adec, s16 * buffer )
455 static u8 freq_table[15] = {3, 0, 0, 0, 1, 0, 1, 2, 2, 2, 3, 3, 3, 3, 3};
456 static float L3_table[3] = {-2/3.0, 0, 2/3.0};
457 static float L5_table[5] = {-4/5.0, -2/5.0, 0, 2/5.0, 4/5.0};
458 static float L9_table[9] = {-8/9.0, -6/9.0, -4/9.0, -2/9.0, 0,
459 2/9.0, 4/9.0, 6/9.0, 8/9.0};
461 s8 allocation_0[32], allocation_1[32];
462 u8 scfsi_0[32], scfsi_1[32];
463 float slope_0[3][32], slope_1[3][32];
464 float offset_0[3][32], offset_1[3][32];
465 float sample_0[3][32], sample_1[3][32];
466 alloc_table_t * alloc_table;
475 /* get the right allocation table */
476 adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
478 /* calculate bound */
480 if ((p_adec->header & 0xc0) == 0x40) { /* intensity stereo */
482 index = (p_adec->header >> 4) & 3;
483 if (adec_bound_table[index] < sblimit)
485 bound = adec_bound_table[index];
489 /* parse allocation */
491 for (sb = 0; sb < bound; sb++)
495 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
496 allocation_0[sb] = alloc_table->alloc[sb][index];
498 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
499 allocation_1[sb] = alloc_table->alloc[sb][index];
501 i_read_bits += alloc_table->nbal[sb] * 2;
504 for (; sb < sblimit; sb++)
508 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
509 allocation_0[sb] = allocation_1[sb] = alloc_table->alloc[sb][index];
510 i_read_bits += alloc_table->nbal[sb];
515 for (sb = 0; sb < sblimit; sb++)
517 if (allocation_0[sb])
519 scfsi_0[sb] = GetBits (&p_adec->bit_stream, 2);
523 if (allocation_1[sb])
525 scfsi_1[sb] = GetBits (&p_adec->bit_stream, 2);
530 /* parse scalefactors */
532 for (sb = 0; sb < sblimit; sb++)
534 if (allocation_0[sb])
536 int index_0, index_1, index_2;
541 index_0 = GetBits(&p_adec->bit_stream,6);
542 index_1 = GetBits(&p_adec->bit_stream,6);
543 index_2 = GetBits(&p_adec->bit_stream,6);
546 if (allocation_0[sb] < 0)
548 slope_0[0][sb] = adec_scalefactor_table[index_0];
549 slope_0[1][sb] = adec_scalefactor_table[index_1];
550 slope_0[2][sb] = adec_scalefactor_table[index_2];
557 slope = adec_slope_table[allocation_0[sb]-2];
558 offset = adec_offset_table[allocation_0[sb]-2];
560 scalefactor = adec_scalefactor_table[index_0];
561 slope_0[0][sb] = slope * scalefactor;
562 offset_0[0][sb] = offset * scalefactor;
564 scalefactor = adec_scalefactor_table[index_1];
565 slope_0[1][sb] = slope * scalefactor;
566 offset_0[1][sb] = offset * scalefactor;
568 scalefactor = adec_scalefactor_table[index_2];
569 slope_0[2][sb] = slope * scalefactor;
570 offset_0[2][sb] = offset * scalefactor;
575 index_0 = GetBits(&p_adec->bit_stream,6);
576 index_1 = GetBits(&p_adec->bit_stream,6);
579 if (allocation_0[sb] < 0)
581 slope_0[0][sb] = slope_0[1][sb] =
582 adec_scalefactor_table[index_0];
583 slope_0[2][sb] = adec_scalefactor_table[index_1];
590 slope = adec_slope_table[allocation_0[sb]-2];
591 offset = adec_offset_table[allocation_0[sb]-2];
593 scalefactor = adec_scalefactor_table[index_0];
594 slope_0[0][sb] = slope_0[1][sb] = slope * scalefactor;
595 offset_0[0][sb] = offset_0[1][sb] =
596 offset * scalefactor;
598 scalefactor = adec_scalefactor_table[index_1];
599 slope_0[2][sb] = slope * scalefactor;
600 offset_0[2][sb] = offset * scalefactor;
605 index_0 = GetBits( &p_adec->bit_stream, 6 );
608 if (allocation_0[sb] < 0)
610 slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
611 adec_scalefactor_table[index_0];
618 slope = adec_slope_table[allocation_0[sb]-2];
619 offset = adec_offset_table[allocation_0[sb]-2];
621 scalefactor = adec_scalefactor_table[index_0];
622 slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
624 offset_0[0][sb] = offset_0[1][sb] = offset_0[2][sb] =
625 offset * scalefactor;
630 index_0 = GetBits(&p_adec->bit_stream,6);
631 index_1 = GetBits(&p_adec->bit_stream,6);
634 if (allocation_0[sb] < 0)
636 slope_0[0][sb] = adec_scalefactor_table[index_0];
637 slope_0[1][sb] = slope_0[2][sb] =
638 adec_scalefactor_table[index_1];
645 slope = adec_slope_table[allocation_0[sb]-2];
646 offset = adec_offset_table[allocation_0[sb]-2];
648 scalefactor = adec_scalefactor_table[index_0];
649 slope_0[0][sb] = slope * scalefactor;
650 offset_0[0][sb] = offset * scalefactor;
652 scalefactor = adec_scalefactor_table[index_1];
653 slope_0[1][sb] = slope_0[2][sb] = slope * scalefactor;
654 offset_0[1][sb] = offset_0[2][sb] =
655 offset * scalefactor;
661 if (allocation_1[sb])
663 int index_0, index_1, index_2;
668 index_0 = GetBits(&p_adec->bit_stream,6);
669 index_1 = GetBits(&p_adec->bit_stream,6);
670 index_2 = GetBits(&p_adec->bit_stream,6);
673 if (allocation_1[sb] < 0)
675 slope_1[0][sb] = adec_scalefactor_table[index_0];
676 slope_1[1][sb] = adec_scalefactor_table[index_1];
677 slope_1[2][sb] = adec_scalefactor_table[index_2];
684 slope = adec_slope_table[allocation_1[sb]-2];
685 offset = adec_offset_table[allocation_1[sb]-2];
687 scalefactor = adec_scalefactor_table[index_0];
688 slope_1[0][sb] = slope * scalefactor;
689 offset_1[0][sb] = offset * scalefactor;
691 scalefactor = adec_scalefactor_table[index_1];
692 slope_1[1][sb] = slope * scalefactor;
693 offset_1[1][sb] = offset * scalefactor;
695 scalefactor = adec_scalefactor_table[index_2];
696 slope_1[2][sb] = slope * scalefactor;
697 offset_1[2][sb] = offset * scalefactor;
702 index_0 = GetBits(&p_adec->bit_stream,6);
703 index_1 = GetBits(&p_adec->bit_stream,6);
706 if (allocation_1[sb] < 0)
708 slope_1[0][sb] = slope_1[1][sb] =
709 adec_scalefactor_table[index_0];
710 slope_1[2][sb] = adec_scalefactor_table[index_1];
717 slope = adec_slope_table[allocation_1[sb]-2];
718 offset = adec_offset_table[allocation_1[sb]-2];
720 scalefactor = adec_scalefactor_table[index_0];
721 slope_1[0][sb] = slope_1[1][sb] = slope * scalefactor;
722 offset_1[0][sb] = offset_1[1][sb] =
723 offset * scalefactor;
725 scalefactor = adec_scalefactor_table[index_1];
726 slope_1[2][sb] = slope * scalefactor;
727 offset_1[2][sb] = offset * scalefactor;
732 index_0 = GetBits( &p_adec->bit_stream, 6 );
735 if (allocation_1[sb] < 0)
737 slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
738 adec_scalefactor_table[index_0];
745 slope = adec_slope_table[allocation_1[sb]-2];
746 offset = adec_offset_table[allocation_1[sb]-2];
748 scalefactor = adec_scalefactor_table[index_0];
749 slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
751 offset_1[0][sb] = offset_1[1][sb] = offset_1[2][sb] =
752 offset * scalefactor;
757 index_0 = GetBits(&p_adec->bit_stream,6);
758 index_1 = GetBits(&p_adec->bit_stream,6);
761 if (allocation_1[sb] < 0)
763 slope_1[0][sb] = adec_scalefactor_table[index_0];
764 slope_1[1][sb] = slope_1[2][sb] =
765 adec_scalefactor_table[index_1];
772 slope = adec_slope_table[allocation_1[sb]-2];
773 offset = adec_offset_table[allocation_1[sb]-2];
775 scalefactor = adec_scalefactor_table[index_0];
776 slope_1[0][sb] = slope * scalefactor;
777 offset_1[0][sb] = offset * scalefactor;
779 scalefactor = adec_scalefactor_table[index_1];
780 slope_1[1][sb] = slope_1[2][sb] = slope * scalefactor;
781 offset_1[1][sb] = offset_1[2][sb] =
782 offset * scalefactor;
791 for (gr0 = 0; gr0 < 3; gr0++)
793 for (gr1 = 0; gr1 < 4; gr1++)
795 for (sb = 0; sb < bound; sb++)
799 switch (allocation_0[sb])
802 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
806 code = GetBits( &p_adec->bit_stream, 5 );
809 sample_0[0][sb] = slope_0[gr0][sb] * L3_table[code % 3];
811 sample_0[1][sb] = slope_0[gr0][sb] * L3_table[code % 3];
813 sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code];
817 code = GetBits( &p_adec->bit_stream, 7 );
820 sample_0[0][sb] = slope_0[gr0][sb] * L5_table[code % 5];
822 sample_0[1][sb] = slope_0[gr0][sb] * L5_table[code % 5];
824 sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code];
828 code = GetBits( &p_adec->bit_stream, 10 );
831 sample_0[0][sb] = slope_0[gr0][sb] * L9_table[code % 9];
833 sample_0[1][sb] = slope_0[gr0][sb] * L9_table[code % 9];
835 sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code];
839 for (s = 0; s < 3; s++)
841 code = GetBits( &p_adec->bit_stream,
843 i_read_bits += allocation_0[sb];
846 slope_0[gr0][sb] * code + offset_0[gr0][sb];
850 switch (allocation_1[sb])
853 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
857 code = GetBits( &p_adec->bit_stream, 5 );
860 sample_1[0][sb] = slope_1[gr0][sb] * L3_table[code % 3];
862 sample_1[1][sb] = slope_1[gr0][sb] * L3_table[code % 3];
864 sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code];
868 code = GetBits( &p_adec->bit_stream, 7 );
871 sample_1[0][sb] = slope_1[gr0][sb] * L5_table[code % 5];
873 sample_1[1][sb] = slope_1[gr0][sb] * L5_table[code % 5];
875 sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code];
879 code = GetBits( &p_adec->bit_stream, 10 );
882 sample_1[0][sb] = slope_1[gr0][sb] * L9_table[code % 9];
884 sample_1[1][sb] = slope_1[gr0][sb] * L9_table[code % 9];
886 sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code];
890 for (s = 0; s < 3; s++)
892 code = GetBits( &p_adec->bit_stream,
894 i_read_bits += allocation_1[sb];
897 slope_1[gr0][sb] * code + offset_1[gr0][sb];
902 for (; sb < sblimit; sb++)
906 switch (allocation_0[sb])
909 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
910 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
914 code = GetBits( &p_adec->bit_stream, 5 );
917 sample_0[0][sb] = slope_0[gr0][sb] * L3_table[code % 3];
918 sample_1[0][sb] = slope_1[gr0][sb] * L3_table[code % 3];
920 sample_0[1][sb] = slope_0[gr0][sb] * L3_table[code % 3];
921 sample_1[1][sb] = slope_1[gr0][sb] * L3_table[code % 3];
923 sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code];
924 sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code];
928 code = GetBits( &p_adec->bit_stream, 7 );
931 sample_0[0][sb] = slope_0[gr0][sb] * L5_table[code % 5];
932 sample_1[0][sb] = slope_1[gr0][sb] * L5_table[code % 5];
934 sample_0[1][sb] = slope_0[gr0][sb] * L5_table[code % 5];
935 sample_1[1][sb] = slope_1[gr0][sb] * L5_table[code % 5];
937 sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code];
938 sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code];
942 code = GetBits( &p_adec->bit_stream, 10 );
945 sample_0[0][sb] = slope_0[gr0][sb] * L9_table[code % 9];
946 sample_1[0][sb] = slope_1[gr0][sb] * L9_table[code % 9];
948 sample_0[1][sb] = slope_0[gr0][sb] * L9_table[code % 9];
949 sample_1[1][sb] = slope_1[gr0][sb] * L9_table[code % 9];
951 sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code];
952 sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code];
956 for (s = 0; s < 3; s++)
958 code = GetBits( &p_adec->bit_stream,
960 i_read_bits += allocation_0[sb];
963 slope_0[gr0][sb] * code + offset_0[gr0][sb];
965 slope_1[gr0][sb] * code + offset_1[gr0][sb];
970 for (; sb < 32; sb++)
972 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
973 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
976 for (s = 0; s < 3; s++)
978 DCT32( &p_adec->bank_0, sample_0[s] );
979 PCM( &p_adec->bank_0, buffer, 2 );
981 DCT32( &p_adec->bank_1, sample_1[s] );
982 PCM( &p_adec->bank_1, buffer + 1, 2 );
989 p_adec->i_read_bits += i_read_bits;