1 /*****************************************************************************
2 * adec_layer2.c: MPEG Layer II audio decoder
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: adec_layer2.c,v 1.3 2001/03/21 13:42:34 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 *****************************************************************************/
28 * - optimiser les NeedBits() et les GetBits() du code là où c'est possible ;
38 #include "stream_control.h"
39 #include "input_ext-dec.h"
41 #include "adec_generic.h"
42 #include "audio_decoder.h"
43 #include "adec_math.h" /* DCT32(), PCM() */
45 #define NULL ((void *)0)
49 static float adec_scalefactor_table[64] =
51 2.0000000000000000, 1.5874010519681994, 1.2599210498948732,
52 1.0000000000000000, 0.7937005259840998, 0.6299605249474366,
53 0.5000000000000000, 0.3968502629920499, 0.3149802624737183,
54 0.2500000000000000, 0.1984251314960249, 0.1574901312368591,
55 0.1250000000000000, 0.0992125657480125, 0.0787450656184296,
56 0.0625000000000000, 0.0496062828740062, 0.0393725328092148,
57 0.0312500000000000, 0.0248031414370031, 0.0196862664046074,
58 0.0156250000000000, 0.0124015707185016, 0.0098431332023037,
59 0.0078125000000000, 0.0062007853592508, 0.0049215666011518,
60 0.0039062500000000, 0.0031003926796254, 0.0024607833005759,
61 0.0019531250000000, 0.0015501963398127, 0.0012303916502880,
62 0.0009765625000000, 0.0007750981699063, 0.0006151958251440,
63 0.0004882812500000, 0.0003875490849532, 0.0003075979125720,
64 0.0002441406250000, 0.0001937745424766, 0.0001537989562860,
65 0.0001220703125000, 0.0000968872712383, 0.0000768994781430,
66 0.0000610351562500, 0.0000484436356191, 0.0000384497390715,
67 0.0000305175781250, 0.0000242218178096, 0.0000192248695357,
68 0.0000152587890625, 0.0000121109089048, 0.0000096124347679,
69 0.0000076293945312, 0.0000060554544524, 0.0000048062173839,
70 0.0000038146972656, 0.0000030277272262, 0.0000024031086920,
71 0.0000019073486328, 0.0000015138636131, 0.0000012015543460,
72 0.0000009536743164 /* last element is not in the standard... invalid ??? */
75 static float adec_slope_table[15] =
77 0.6666666666666666, 0.2857142857142857, 0.1333333333333333,
78 0.0645161290322581, 0.0317460317460317, 0.0157480314960630,
79 0.0078431372549020, 0.0039138943248532, 0.0019550342130987,
80 0.0009770395701026, 0.0004884004884005, 0.0002441704309608,
81 0.0001220777635354, 0.0000610370189520, 0.0000305180437934
84 static float adec_offset_table[15] =
86 -0.6666666666666666, -0.8571428571428571, -0.9333333333333333,
87 -0.9677419354838710, -0.9841269841269841, -0.9921259842519685,
88 -0.9960784313725490, -0.9980430528375733, -0.9990224828934506,
89 -0.9995114802149487, -0.9997557997557998, -0.9998779147845196,
90 -0.9999389611182323, -0.9999694814905240, -0.9999847409781033
93 static int adec_bound_table[4] = { 4, 8, 12, 16 };
105 static void adec_layer2_get_table( u32 header, u8 freq_table[15],
106 alloc_table_t ** alloc, int * sblimit )
108 static s8 table_ab0[16] =
110 0, L3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
112 static s8 table_ab3[16] =
114 0, L3, L5, 3, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16
116 static s8 table_ab11[8] =
118 0, L3, L5, 3, L9, 4, 5, 16
120 static s8 table_ab23[8] =
124 static alloc_table_t mpeg1_ab =
126 {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},
127 {table_ab0, table_ab0, table_ab0, table_ab3,
128 table_ab3, table_ab3, table_ab3, table_ab3,
129 table_ab3, table_ab3, table_ab3, table_ab11,
130 table_ab11, table_ab11, table_ab11, table_ab11,
131 table_ab11, table_ab11, table_ab11, table_ab11,
132 table_ab11, table_ab11, table_ab11, table_ab23,
133 table_ab23, table_ab23, table_ab23, table_ab23,
134 table_ab23, table_ab23, NULL, NULL}
137 static s8 table_cd[16] =
139 0, L3, L5, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
141 static alloc_table_t mpeg1_cd =
143 {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},
144 {table_cd, table_cd, table_cd, table_cd,
145 table_cd, table_cd, table_cd, table_cd,
146 table_cd, table_cd, table_cd, table_cd,
147 NULL, NULL, NULL, NULL,
148 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
149 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
152 static s8 table_0[16] =
154 0, L3, L5, 3, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
156 static s8 table_4[8] =
158 0, L3, L5, L9, 4, 5, 6, 7
160 static alloc_table_t mpeg2 =
162 {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},
163 {table_0, table_0, table_0, table_0,
164 table_4, table_4, table_4, table_4,
165 table_4, table_4, table_4, table_4,
166 table_4, table_4, table_4, table_4,
167 table_4, table_4, table_4, table_4,
168 table_4, table_4, table_4, table_4,
169 table_4, table_4, table_4, table_4,
170 table_4, table_4, NULL, NULL}
173 static alloc_table_t * alloc_table [4] =
175 &mpeg2, &mpeg1_cd, &mpeg1_ab, &mpeg1_ab
177 static int sblimit_table[12] =
179 30, 8, 27, 30, 30, 8, 27, 27, 30, 12, 27, 30
184 if (!(header & 0x80000))
186 index = 0; /* mpeg2 */
190 index = (header >> 12) & 15; /* mpeg1, bitrate */
191 index = freq_table [index];
194 *alloc = alloc_table[index];
195 index |= (header >> 8) & 12;
196 *sblimit = sblimit_table[index];
199 int adec_layer2_mono( adec_thread_t * p_adec, s16 * buffer )
201 static u8 freq_table[15] = {2, 1, 1, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2};
202 static float L3_table[3] = {-2/3.0, 0, 2/3.0};
203 static float L5_table[5] = {-4/5.0, -2/5.0, 0, 2/5.0, 4/5.0};
204 static float L9_table[9] = {-8/9.0, -6/9.0, -4/9.0, -2/9.0, 0,
205 2/9.0, 4/9.0, 6/9.0, 8/9.0};
212 alloc_table_t * alloc_table;
220 /* get the right allocation table */
221 adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
223 /* parse allocation */
226 for (sb = 0; sb < sblimit; sb++)
230 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
231 i_read_bits += alloc_table->nbal[sb];
233 allocation[sb] = alloc_table->alloc[sb][index];
238 for (sb = 0; sb < sblimit; sb++)
242 scfsi[sb] = GetBits (&p_adec->bit_stream, 2);
247 /* parse scalefactors */
249 for (sb = 0; sb < sblimit; sb++)
253 int index_0, index_1, index_2;
258 index_0 = GetBits(&p_adec->bit_stream,6);
259 index_1 = GetBits(&p_adec->bit_stream,6);
260 index_2 = GetBits(&p_adec->bit_stream,6);
263 if (allocation[sb] < 0)
265 slope[0][sb] = adec_scalefactor_table[index_0];
266 slope[1][sb] = adec_scalefactor_table[index_1];
267 slope[2][sb] = adec_scalefactor_table[index_2];
272 float r_slope, r_offset;
274 r_slope = adec_slope_table[allocation[sb]-2];
275 r_offset = adec_offset_table[allocation[sb]-2];
277 r_scalefactor = adec_scalefactor_table[index_0];
278 slope[0][sb] = r_slope * r_scalefactor;
279 offset[0][sb] = r_offset * r_scalefactor;
281 r_scalefactor = adec_scalefactor_table[index_1];
282 slope[1][sb] = r_slope * r_scalefactor;
283 offset[1][sb] = r_offset * r_scalefactor;
285 r_scalefactor = adec_scalefactor_table[index_2];
286 slope[2][sb] = r_slope * r_scalefactor;
287 offset[2][sb] = r_offset * r_scalefactor;
292 index_0 = GetBits(&p_adec->bit_stream,6);
293 index_1 = GetBits(&p_adec->bit_stream,6);
296 if (allocation[sb] < 0)
298 slope[0][sb] = slope[1][sb] =
299 adec_scalefactor_table[index_0];
300 slope[2][sb] = adec_scalefactor_table[index_1];
305 float r_slope, r_offset;
307 r_slope = adec_slope_table[allocation[sb]-2];
308 r_offset = adec_offset_table[allocation[sb]-2];
310 r_scalefactor = adec_scalefactor_table[index_0];
311 slope[0][sb] = slope[1][sb] = r_slope * r_scalefactor;
312 offset[0][sb] = offset[1][sb] =
313 r_offset * r_scalefactor;
315 r_scalefactor = adec_scalefactor_table[index_1];
316 slope[2][sb] = r_slope * r_scalefactor;
317 offset[2][sb] = r_offset * r_scalefactor;
322 index_0 = GetBits( &p_adec->bit_stream, 6 );
325 if (allocation[sb] < 0)
327 slope[0][sb] = slope[1][sb] = slope[2][sb] =
328 adec_scalefactor_table[index_0];
333 float r_slope, r_offset;
335 r_slope = adec_slope_table[allocation[sb]-2];
336 r_offset = adec_offset_table[allocation[sb]-2];
338 r_scalefactor = adec_scalefactor_table[index_0];
339 slope[0][sb] = slope[1][sb] = slope[2][sb] =
340 r_slope * r_scalefactor;
341 offset[0][sb] = offset[1][sb] = offset[2][sb] =
342 r_offset * r_scalefactor;
347 index_0 = GetBits(&p_adec->bit_stream,6);
348 index_1 = GetBits(&p_adec->bit_stream,6);
351 if (allocation[sb] < 0)
353 slope[0][sb] = adec_scalefactor_table[index_0];
354 slope[1][sb] = slope[2][sb] =
355 adec_scalefactor_table[index_1];
360 float r_slope, r_offset;
362 r_slope = adec_slope_table[allocation[sb]-2];
363 r_offset = adec_offset_table[allocation[sb]-2];
365 r_scalefactor = adec_scalefactor_table[index_0];
366 slope[0][sb] = r_slope * r_scalefactor;
367 offset[0][sb] = r_offset * r_scalefactor;
369 r_scalefactor = adec_scalefactor_table[index_1];
370 slope[1][sb] = slope[2][sb] = r_slope * r_scalefactor;
371 offset[1][sb] = offset[2][sb] =
372 r_offset * r_scalefactor;
381 for (gr0 = 0; gr0 < 3; gr0++)
383 for (gr1 = 0; gr1 < 4; gr1++)
387 for (sb = 0; sb < sblimit; sb++)
391 switch (allocation[sb])
394 sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
398 code = GetBits( &p_adec->bit_stream, 5 );
401 sample[0][sb] = slope[gr0][sb] * L3_table[code % 3];
403 sample[1][sb] = slope[gr0][sb] * L3_table[code % 3];
405 sample[2][sb] = slope[gr0][sb] * L3_table[code];
409 code = GetBits( &p_adec->bit_stream, 7 );
412 sample[0][sb] = slope[gr0][sb] * L5_table[code % 5];
414 sample[1][sb] = slope[gr0][sb] * L5_table[code % 5];
416 sample[2][sb] = slope[gr0][sb] * L5_table[code];
420 code = GetBits( &p_adec->bit_stream, 10 );
423 sample[0][sb] = slope[gr0][sb] * L9_table[code % 9];
425 sample[1][sb] = slope[gr0][sb] * L9_table[code % 9];
427 sample[2][sb] = slope[gr0][sb] * L9_table[code];
431 for (s = 0; s < 3; s++)
433 code = GetBits( &p_adec->bit_stream,
435 i_read_bits += 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);
464 p_adec->i_read_bits += i_read_bits;
469 int adec_layer2_stereo( adec_thread_t * p_adec, s16 * buffer )
471 static u8 freq_table[15] = {3, 0, 0, 0, 1, 0, 1, 2, 2, 2, 3, 3, 3, 3, 3};
472 static float L3_table[3] = {-2/3.0, 0, 2/3.0};
473 static float L5_table[5] = {-4/5.0, -2/5.0, 0, 2/5.0, 4/5.0};
474 static float L9_table[9] = {-8/9.0, -6/9.0, -4/9.0, -2/9.0, 0,
475 2/9.0, 4/9.0, 6/9.0, 8/9.0};
477 s8 allocation_0[32], allocation_1[32];
478 u8 scfsi_0[32], scfsi_1[32];
479 float slope_0[3][32], slope_1[3][32];
480 float offset_0[3][32], offset_1[3][32];
481 float sample_0[3][32], sample_1[3][32];
482 alloc_table_t * alloc_table;
491 /* get the right allocation table */
492 adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
494 /* calculate bound */
496 if ((p_adec->header & 0xc0) == 0x40) { /* intensity stereo */
498 index = (p_adec->header >> 4) & 3;
499 if (adec_bound_table[index] < sblimit)
501 bound = adec_bound_table[index];
505 /* parse allocation */
507 for (sb = 0; sb < bound; sb++)
511 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
512 allocation_0[sb] = alloc_table->alloc[sb][index];
514 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
515 allocation_1[sb] = alloc_table->alloc[sb][index];
517 i_read_bits += alloc_table->nbal[sb] * 2;
520 for (; sb < sblimit; sb++)
524 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
525 allocation_0[sb] = allocation_1[sb] = alloc_table->alloc[sb][index];
526 i_read_bits += alloc_table->nbal[sb];
531 for (sb = 0; sb < sblimit; sb++)
533 if (allocation_0[sb])
535 scfsi_0[sb] = GetBits (&p_adec->bit_stream, 2);
539 if (allocation_1[sb])
541 scfsi_1[sb] = GetBits (&p_adec->bit_stream, 2);
546 /* parse scalefactors */
548 for (sb = 0; sb < sblimit; sb++)
550 if (allocation_0[sb])
552 int index_0, index_1, index_2;
557 index_0 = GetBits(&p_adec->bit_stream,6);
558 index_1 = GetBits(&p_adec->bit_stream,6);
559 index_2 = GetBits(&p_adec->bit_stream,6);
562 if (allocation_0[sb] < 0)
564 slope_0[0][sb] = adec_scalefactor_table[index_0];
565 slope_0[1][sb] = adec_scalefactor_table[index_1];
566 slope_0[2][sb] = adec_scalefactor_table[index_2];
573 slope = adec_slope_table[allocation_0[sb]-2];
574 offset = adec_offset_table[allocation_0[sb]-2];
576 scalefactor = adec_scalefactor_table[index_0];
577 slope_0[0][sb] = slope * scalefactor;
578 offset_0[0][sb] = offset * scalefactor;
580 scalefactor = adec_scalefactor_table[index_1];
581 slope_0[1][sb] = slope * scalefactor;
582 offset_0[1][sb] = offset * scalefactor;
584 scalefactor = adec_scalefactor_table[index_2];
585 slope_0[2][sb] = slope * scalefactor;
586 offset_0[2][sb] = offset * scalefactor;
591 index_0 = GetBits(&p_adec->bit_stream,6);
592 index_1 = GetBits(&p_adec->bit_stream,6);
595 if (allocation_0[sb] < 0)
597 slope_0[0][sb] = slope_0[1][sb] =
598 adec_scalefactor_table[index_0];
599 slope_0[2][sb] = adec_scalefactor_table[index_1];
606 slope = adec_slope_table[allocation_0[sb]-2];
607 offset = adec_offset_table[allocation_0[sb]-2];
609 scalefactor = adec_scalefactor_table[index_0];
610 slope_0[0][sb] = slope_0[1][sb] = slope * scalefactor;
611 offset_0[0][sb] = offset_0[1][sb] =
612 offset * scalefactor;
614 scalefactor = adec_scalefactor_table[index_1];
615 slope_0[2][sb] = slope * scalefactor;
616 offset_0[2][sb] = offset * scalefactor;
621 index_0 = GetBits( &p_adec->bit_stream, 6 );
624 if (allocation_0[sb] < 0)
626 slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
627 adec_scalefactor_table[index_0];
634 slope = adec_slope_table[allocation_0[sb]-2];
635 offset = adec_offset_table[allocation_0[sb]-2];
637 scalefactor = adec_scalefactor_table[index_0];
638 slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
640 offset_0[0][sb] = offset_0[1][sb] = offset_0[2][sb] =
641 offset * scalefactor;
646 index_0 = GetBits(&p_adec->bit_stream,6);
647 index_1 = GetBits(&p_adec->bit_stream,6);
650 if (allocation_0[sb] < 0)
652 slope_0[0][sb] = adec_scalefactor_table[index_0];
653 slope_0[1][sb] = slope_0[2][sb] =
654 adec_scalefactor_table[index_1];
661 slope = adec_slope_table[allocation_0[sb]-2];
662 offset = adec_offset_table[allocation_0[sb]-2];
664 scalefactor = adec_scalefactor_table[index_0];
665 slope_0[0][sb] = slope * scalefactor;
666 offset_0[0][sb] = offset * scalefactor;
668 scalefactor = adec_scalefactor_table[index_1];
669 slope_0[1][sb] = slope_0[2][sb] = slope * scalefactor;
670 offset_0[1][sb] = offset_0[2][sb] =
671 offset * scalefactor;
677 if (allocation_1[sb])
679 int index_0, index_1, index_2;
684 index_0 = GetBits(&p_adec->bit_stream,6);
685 index_1 = GetBits(&p_adec->bit_stream,6);
686 index_2 = GetBits(&p_adec->bit_stream,6);
689 if (allocation_1[sb] < 0)
691 slope_1[0][sb] = adec_scalefactor_table[index_0];
692 slope_1[1][sb] = adec_scalefactor_table[index_1];
693 slope_1[2][sb] = adec_scalefactor_table[index_2];
700 slope = adec_slope_table[allocation_1[sb]-2];
701 offset = adec_offset_table[allocation_1[sb]-2];
703 scalefactor = adec_scalefactor_table[index_0];
704 slope_1[0][sb] = slope * scalefactor;
705 offset_1[0][sb] = offset * scalefactor;
707 scalefactor = adec_scalefactor_table[index_1];
708 slope_1[1][sb] = slope * scalefactor;
709 offset_1[1][sb] = offset * scalefactor;
711 scalefactor = adec_scalefactor_table[index_2];
712 slope_1[2][sb] = slope * scalefactor;
713 offset_1[2][sb] = offset * scalefactor;
718 index_0 = GetBits(&p_adec->bit_stream,6);
719 index_1 = GetBits(&p_adec->bit_stream,6);
722 if (allocation_1[sb] < 0)
724 slope_1[0][sb] = slope_1[1][sb] =
725 adec_scalefactor_table[index_0];
726 slope_1[2][sb] = adec_scalefactor_table[index_1];
733 slope = adec_slope_table[allocation_1[sb]-2];
734 offset = adec_offset_table[allocation_1[sb]-2];
736 scalefactor = adec_scalefactor_table[index_0];
737 slope_1[0][sb] = slope_1[1][sb] = slope * scalefactor;
738 offset_1[0][sb] = offset_1[1][sb] =
739 offset * scalefactor;
741 scalefactor = adec_scalefactor_table[index_1];
742 slope_1[2][sb] = slope * scalefactor;
743 offset_1[2][sb] = offset * scalefactor;
748 index_0 = GetBits( &p_adec->bit_stream, 6 );
751 if (allocation_1[sb] < 0)
753 slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
754 adec_scalefactor_table[index_0];
761 slope = adec_slope_table[allocation_1[sb]-2];
762 offset = adec_offset_table[allocation_1[sb]-2];
764 scalefactor = adec_scalefactor_table[index_0];
765 slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
767 offset_1[0][sb] = offset_1[1][sb] = offset_1[2][sb] =
768 offset * scalefactor;
773 index_0 = GetBits(&p_adec->bit_stream,6);
774 index_1 = GetBits(&p_adec->bit_stream,6);
777 if (allocation_1[sb] < 0)
779 slope_1[0][sb] = adec_scalefactor_table[index_0];
780 slope_1[1][sb] = slope_1[2][sb] =
781 adec_scalefactor_table[index_1];
788 slope = adec_slope_table[allocation_1[sb]-2];
789 offset = adec_offset_table[allocation_1[sb]-2];
791 scalefactor = adec_scalefactor_table[index_0];
792 slope_1[0][sb] = slope * scalefactor;
793 offset_1[0][sb] = offset * scalefactor;
795 scalefactor = adec_scalefactor_table[index_1];
796 slope_1[1][sb] = slope_1[2][sb] = slope * scalefactor;
797 offset_1[1][sb] = offset_1[2][sb] =
798 offset * scalefactor;
807 for (gr0 = 0; gr0 < 3; gr0++)
809 for (gr1 = 0; gr1 < 4; gr1++)
813 for (sb = 0; sb < bound; sb++)
817 switch (allocation_0[sb])
820 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
824 code = GetBits( &p_adec->bit_stream, 5 );
827 sample_0[0][sb] = slope_0[gr0][sb] * L3_table[code % 3];
829 sample_0[1][sb] = slope_0[gr0][sb] * L3_table[code % 3];
831 sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code];
835 code = GetBits( &p_adec->bit_stream, 7 );
838 sample_0[0][sb] = slope_0[gr0][sb] * L5_table[code % 5];
840 sample_0[1][sb] = slope_0[gr0][sb] * L5_table[code % 5];
842 sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code];
846 code = GetBits( &p_adec->bit_stream, 10 );
849 sample_0[0][sb] = slope_0[gr0][sb] * L9_table[code % 9];
851 sample_0[1][sb] = slope_0[gr0][sb] * L9_table[code % 9];
853 sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code];
857 for (s = 0; s < 3; s++)
859 code = GetBits( &p_adec->bit_stream,
861 i_read_bits += allocation_0[sb];
864 slope_0[gr0][sb] * code + offset_0[gr0][sb];
868 switch (allocation_1[sb])
871 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
875 code = GetBits( &p_adec->bit_stream, 5 );
878 sample_1[0][sb] = slope_1[gr0][sb] * L3_table[code % 3];
880 sample_1[1][sb] = slope_1[gr0][sb] * L3_table[code % 3];
882 sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code];
886 code = GetBits( &p_adec->bit_stream, 7 );
889 sample_1[0][sb] = slope_1[gr0][sb] * L5_table[code % 5];
891 sample_1[1][sb] = slope_1[gr0][sb] * L5_table[code % 5];
893 sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code];
897 code = GetBits( &p_adec->bit_stream, 10 );
900 sample_1[0][sb] = slope_1[gr0][sb] * L9_table[code % 9];
902 sample_1[1][sb] = slope_1[gr0][sb] * L9_table[code % 9];
904 sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code];
908 for (s = 0; s < 3; s++)
910 code = GetBits( &p_adec->bit_stream,
912 i_read_bits += allocation_1[sb];
915 slope_1[gr0][sb] * code + offset_1[gr0][sb];
920 for (; sb < sblimit; sb++)
924 switch (allocation_0[sb])
927 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
928 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
932 code = GetBits( &p_adec->bit_stream, 5 );
935 sample_0[0][sb] = slope_0[gr0][sb] * L3_table[code % 3];
936 sample_1[0][sb] = slope_1[gr0][sb] * L3_table[code % 3];
938 sample_0[1][sb] = slope_0[gr0][sb] * L3_table[code % 3];
939 sample_1[1][sb] = slope_1[gr0][sb] * L3_table[code % 3];
941 sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code];
942 sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code];
946 code = GetBits( &p_adec->bit_stream, 7 );
949 sample_0[0][sb] = slope_0[gr0][sb] * L5_table[code % 5];
950 sample_1[0][sb] = slope_1[gr0][sb] * L5_table[code % 5];
952 sample_0[1][sb] = slope_0[gr0][sb] * L5_table[code % 5];
953 sample_1[1][sb] = slope_1[gr0][sb] * L5_table[code % 5];
955 sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code];
956 sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code];
960 code = GetBits( &p_adec->bit_stream, 10 );
963 sample_0[0][sb] = slope_0[gr0][sb] * L9_table[code % 9];
964 sample_1[0][sb] = slope_1[gr0][sb] * L9_table[code % 9];
966 sample_0[1][sb] = slope_0[gr0][sb] * L9_table[code % 9];
967 sample_1[1][sb] = slope_1[gr0][sb] * L9_table[code % 9];
969 sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code];
970 sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code];
974 for (s = 0; s < 3; s++)
976 code = GetBits( &p_adec->bit_stream,
978 i_read_bits += allocation_0[sb];
981 slope_0[gr0][sb] * code + offset_0[gr0][sb];
983 slope_1[gr0][sb] * code + offset_1[gr0][sb];
988 for (; sb < 32; sb++)
990 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
991 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
994 for (s = 0; s < 3; s++)
996 DCT32 (sample_0[s], &p_adec->bank_0);
998 PCM (&p_adec->bank_0, &XXX_buf, 2);
1000 DCT32 (sample_1[s], &p_adec->bank_1);
1002 PCM (&p_adec->bank_1, &XXX_buf, 2);
1009 p_adec->i_read_bits += i_read_bits;