1 /*****************************************************************************
2 * adec_layer2.c: MPEG Layer II audio decoder
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: adec_layer2.c,v 1.4 2001/12/10 04:53:11 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 *****************************************************************************/
27 #include <stdlib.h> /* NULL */
28 #include <string.h> /* memcpy(), memset() */
34 #include "stream_control.h"
35 #include "input_ext-dec.h"
37 #include "mpeg_adec_generic.h"
38 #include "mpeg_adec.h"
39 #include "adec_math.h" /* DCT32(), PCM() */
41 #include "modules_export.h"
45 static float adec_scalefactor_table[64] =
47 2.0000000000000000, 1.5874010519681994, 1.2599210498948732,
48 1.0000000000000000, 0.7937005259840998, 0.6299605249474366,
49 0.5000000000000000, 0.3968502629920499, 0.3149802624737183,
50 0.2500000000000000, 0.1984251314960249, 0.1574901312368591,
51 0.1250000000000000, 0.0992125657480125, 0.0787450656184296,
52 0.0625000000000000, 0.0496062828740062, 0.0393725328092148,
53 0.0312500000000000, 0.0248031414370031, 0.0196862664046074,
54 0.0156250000000000, 0.0124015707185016, 0.0098431332023037,
55 0.0078125000000000, 0.0062007853592508, 0.0049215666011518,
56 0.0039062500000000, 0.0031003926796254, 0.0024607833005759,
57 0.0019531250000000, 0.0015501963398127, 0.0012303916502880,
58 0.0009765625000000, 0.0007750981699063, 0.0006151958251440,
59 0.0004882812500000, 0.0003875490849532, 0.0003075979125720,
60 0.0002441406250000, 0.0001937745424766, 0.0001537989562860,
61 0.0001220703125000, 0.0000968872712383, 0.0000768994781430,
62 0.0000610351562500, 0.0000484436356191, 0.0000384497390715,
63 0.0000305175781250, 0.0000242218178096, 0.0000192248695357,
64 0.0000152587890625, 0.0000121109089048, 0.0000096124347679,
65 0.0000076293945312, 0.0000060554544524, 0.0000048062173839,
66 0.0000038146972656, 0.0000030277272262, 0.0000024031086920,
67 0.0000019073486328, 0.0000015138636131, 0.0000012015543460,
68 0.0000009536743164 /* last element is not in the standard... invalid ??? */
71 static float adec_slope_table[15] =
73 0.6666666666666666, 0.2857142857142857, 0.1333333333333333,
74 0.0645161290322581, 0.0317460317460317, 0.0157480314960630,
75 0.0078431372549020, 0.0039138943248532, 0.0019550342130987,
76 0.0009770395701026, 0.0004884004884005, 0.0002441704309608,
77 0.0001220777635354, 0.0000610370189520, 0.0000305180437934
80 static float adec_offset_table[15] =
82 -0.6666666666666666, -0.8571428571428571, -0.9333333333333333,
83 -0.9677419354838710, -0.9841269841269841, -0.9921259842519685,
84 -0.9960784313725490, -0.9980430528375733, -0.9990224828934506,
85 -0.9995114802149487, -0.9997557997557998, -0.9998779147845196,
86 -0.9999389611182323, -0.9999694814905240, -0.9999847409781033
89 static int adec_bound_table[4] = { 4, 8, 12, 16 };
101 static void adec_layer2_get_table( u32 header, u8 freq_table[15],
102 alloc_table_t ** alloc, int * sblimit )
104 static s8 table_ab0[16] =
106 0, L3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
108 static s8 table_ab3[16] =
110 0, L3, L5, 3, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16
112 static s8 table_ab11[8] =
114 0, L3, L5, 3, L9, 4, 5, 16
116 static s8 table_ab23[8] =
120 static alloc_table_t mpeg1_ab =
122 {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},
123 {table_ab0, table_ab0, table_ab0, table_ab3,
124 table_ab3, table_ab3, table_ab3, table_ab3,
125 table_ab3, table_ab3, table_ab3, table_ab11,
126 table_ab11, table_ab11, table_ab11, table_ab11,
127 table_ab11, table_ab11, table_ab11, table_ab11,
128 table_ab11, table_ab11, table_ab11, table_ab23,
129 table_ab23, table_ab23, table_ab23, table_ab23,
130 table_ab23, table_ab23, NULL, NULL}
133 static s8 table_cd[16] =
135 0, L3, L5, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
137 static alloc_table_t mpeg1_cd =
139 {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},
140 {table_cd, table_cd, table_cd, table_cd,
141 table_cd, table_cd, table_cd, table_cd,
142 table_cd, table_cd, table_cd, table_cd,
143 NULL, NULL, NULL, NULL,
144 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
145 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
148 static s8 table_0[16] =
150 0, L3, L5, 3, L9, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
152 static s8 table_4[8] =
154 0, L3, L5, L9, 4, 5, 6, 7
156 static alloc_table_t mpeg2 =
158 {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},
159 {table_0, table_0, table_0, table_0,
160 table_4, table_4, table_4, table_4,
161 table_4, table_4, table_4, table_4,
162 table_4, table_4, table_4, table_4,
163 table_4, table_4, table_4, table_4,
164 table_4, table_4, table_4, table_4,
165 table_4, table_4, table_4, table_4,
166 table_4, table_4, NULL, NULL}
169 static alloc_table_t * alloc_table [4] =
171 &mpeg2, &mpeg1_cd, &mpeg1_ab, &mpeg1_ab
173 static int sblimit_table[12] =
175 30, 8, 27, 30, 30, 8, 27, 27, 30, 12, 27, 30
180 if (!(header & 0x80000))
182 index = 0; /* mpeg2 */
186 index = (header >> 12) & 15; /* mpeg1, bitrate */
187 index = freq_table [index];
190 *alloc = alloc_table[index];
191 index |= (header >> 8) & 12;
192 *sblimit = sblimit_table[index];
195 int adec_layer2_mono( adec_thread_t * p_adec, s16 * buffer )
197 static u8 freq_table[15] = {2, 1, 1, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2};
198 static float L3_table[3] = {-2/3.0, 0, 2/3.0};
199 static float L5_table[5] = {-4/5.0, -2/5.0, 0, 2/5.0, 4/5.0};
200 static float L9_table[9] = {-8/9.0, -6/9.0, -4/9.0, -2/9.0, 0,
201 2/9.0, 4/9.0, 6/9.0, 8/9.0};
208 alloc_table_t * alloc_table;
216 /* get the right allocation table */
217 adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
219 /* parse allocation */
222 for (sb = 0; sb < sblimit; sb++)
226 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
227 i_read_bits += alloc_table->nbal[sb];
229 allocation[sb] = alloc_table->alloc[sb][index];
234 for (sb = 0; sb < sblimit; sb++)
238 scfsi[sb] = GetBits (&p_adec->bit_stream, 2);
243 /* parse scalefactors */
245 for (sb = 0; sb < sblimit; sb++)
249 int index_0, index_1, index_2;
254 index_0 = GetBits(&p_adec->bit_stream,6);
255 index_1 = GetBits(&p_adec->bit_stream,6);
256 index_2 = GetBits(&p_adec->bit_stream,6);
259 if (allocation[sb] < 0)
261 slope[0][sb] = adec_scalefactor_table[index_0];
262 slope[1][sb] = adec_scalefactor_table[index_1];
263 slope[2][sb] = adec_scalefactor_table[index_2];
268 float r_slope, r_offset;
270 r_slope = adec_slope_table[allocation[sb]-2];
271 r_offset = adec_offset_table[allocation[sb]-2];
273 r_scalefactor = adec_scalefactor_table[index_0];
274 slope[0][sb] = r_slope * r_scalefactor;
275 offset[0][sb] = r_offset * r_scalefactor;
277 r_scalefactor = adec_scalefactor_table[index_1];
278 slope[1][sb] = r_slope * r_scalefactor;
279 offset[1][sb] = r_offset * r_scalefactor;
281 r_scalefactor = adec_scalefactor_table[index_2];
282 slope[2][sb] = r_slope * r_scalefactor;
283 offset[2][sb] = r_offset * r_scalefactor;
288 index_0 = GetBits(&p_adec->bit_stream,6);
289 index_1 = GetBits(&p_adec->bit_stream,6);
292 if (allocation[sb] < 0)
294 slope[0][sb] = slope[1][sb] =
295 adec_scalefactor_table[index_0];
296 slope[2][sb] = adec_scalefactor_table[index_1];
301 float r_slope, r_offset;
303 r_slope = adec_slope_table[allocation[sb]-2];
304 r_offset = adec_offset_table[allocation[sb]-2];
306 r_scalefactor = adec_scalefactor_table[index_0];
307 slope[0][sb] = slope[1][sb] = r_slope * r_scalefactor;
308 offset[0][sb] = offset[1][sb] =
309 r_offset * r_scalefactor;
311 r_scalefactor = adec_scalefactor_table[index_1];
312 slope[2][sb] = r_slope * r_scalefactor;
313 offset[2][sb] = r_offset * r_scalefactor;
318 index_0 = GetBits( &p_adec->bit_stream, 6 );
321 if (allocation[sb] < 0)
323 slope[0][sb] = slope[1][sb] = slope[2][sb] =
324 adec_scalefactor_table[index_0];
329 float r_slope, r_offset;
331 r_slope = adec_slope_table[allocation[sb]-2];
332 r_offset = adec_offset_table[allocation[sb]-2];
334 r_scalefactor = adec_scalefactor_table[index_0];
335 slope[0][sb] = slope[1][sb] = slope[2][sb] =
336 r_slope * r_scalefactor;
337 offset[0][sb] = offset[1][sb] = offset[2][sb] =
338 r_offset * r_scalefactor;
343 index_0 = GetBits(&p_adec->bit_stream,6);
344 index_1 = GetBits(&p_adec->bit_stream,6);
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 code = GetBits( &p_adec->bit_stream, 5 );
397 sample[0][sb] = slope[gr0][sb] * L3_table[code % 3];
399 sample[1][sb] = slope[gr0][sb] * L3_table[code % 3];
401 sample[2][sb] = slope[gr0][sb] * L3_table[code];
405 code = GetBits( &p_adec->bit_stream, 7 );
408 sample[0][sb] = slope[gr0][sb] * L5_table[code % 5];
410 sample[1][sb] = slope[gr0][sb] * L5_table[code % 5];
412 sample[2][sb] = slope[gr0][sb] * L5_table[code];
416 code = GetBits( &p_adec->bit_stream, 10 );
419 sample[0][sb] = slope[gr0][sb] * L9_table[code % 9];
421 sample[1][sb] = slope[gr0][sb] * L9_table[code % 9];
423 sample[2][sb] = slope[gr0][sb] * L9_table[code];
427 for (s = 0; s < 3; s++)
429 code = GetBits( &p_adec->bit_stream,
431 i_read_bits += allocation[sb];
434 slope[gr0][sb] * code + offset[gr0][sb];
439 for (; sb < 32; sb++)
441 sample[0][sb] = sample[1][sb] = sample[2][sb] = 0;
444 for (s = 0; s < 3; s++)
446 DCT32 (sample[s], &p_adec->bank_0);
448 PCM (&p_adec->bank_0, &XXX_buf, 2);
450 /* FIXME: one shouldn't have to do it twice ! */
451 DCT32 (sample[s], &p_adec->bank_1);
453 PCM (&p_adec->bank_1, &XXX_buf, 2);
460 p_adec->i_read_bits += i_read_bits;
465 int adec_layer2_stereo( adec_thread_t * p_adec, s16 * buffer )
467 static u8 freq_table[15] = {3, 0, 0, 0, 1, 0, 1, 2, 2, 2, 3, 3, 3, 3, 3};
468 static float L3_table[3] = {-2/3.0, 0, 2/3.0};
469 static float L5_table[5] = {-4/5.0, -2/5.0, 0, 2/5.0, 4/5.0};
470 static float L9_table[9] = {-8/9.0, -6/9.0, -4/9.0, -2/9.0, 0,
471 2/9.0, 4/9.0, 6/9.0, 8/9.0};
473 s8 allocation_0[32], allocation_1[32];
474 u8 scfsi_0[32], scfsi_1[32];
475 float slope_0[3][32], slope_1[3][32];
476 float offset_0[3][32], offset_1[3][32];
477 float sample_0[3][32], sample_1[3][32];
478 alloc_table_t * alloc_table;
487 /* get the right allocation table */
488 adec_layer2_get_table (p_adec->header, freq_table, &alloc_table, &sblimit);
490 /* calculate bound */
492 if ((p_adec->header & 0xc0) == 0x40) { /* intensity stereo */
494 index = (p_adec->header >> 4) & 3;
495 if (adec_bound_table[index] < sblimit)
497 bound = adec_bound_table[index];
501 /* parse allocation */
503 for (sb = 0; sb < bound; sb++)
507 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
508 allocation_0[sb] = alloc_table->alloc[sb][index];
510 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
511 allocation_1[sb] = alloc_table->alloc[sb][index];
513 i_read_bits += alloc_table->nbal[sb] * 2;
516 for (; sb < sblimit; sb++)
520 index = GetBits( &p_adec->bit_stream, alloc_table->nbal[sb] );
521 allocation_0[sb] = allocation_1[sb] = alloc_table->alloc[sb][index];
522 i_read_bits += alloc_table->nbal[sb];
527 for (sb = 0; sb < sblimit; sb++)
529 if (allocation_0[sb])
531 scfsi_0[sb] = GetBits (&p_adec->bit_stream, 2);
535 if (allocation_1[sb])
537 scfsi_1[sb] = GetBits (&p_adec->bit_stream, 2);
542 /* parse scalefactors */
544 for (sb = 0; sb < sblimit; sb++)
546 if (allocation_0[sb])
548 int index_0, index_1, index_2;
553 index_0 = GetBits(&p_adec->bit_stream,6);
554 index_1 = GetBits(&p_adec->bit_stream,6);
555 index_2 = GetBits(&p_adec->bit_stream,6);
558 if (allocation_0[sb] < 0)
560 slope_0[0][sb] = adec_scalefactor_table[index_0];
561 slope_0[1][sb] = adec_scalefactor_table[index_1];
562 slope_0[2][sb] = adec_scalefactor_table[index_2];
569 slope = adec_slope_table[allocation_0[sb]-2];
570 offset = adec_offset_table[allocation_0[sb]-2];
572 scalefactor = adec_scalefactor_table[index_0];
573 slope_0[0][sb] = slope * scalefactor;
574 offset_0[0][sb] = offset * scalefactor;
576 scalefactor = adec_scalefactor_table[index_1];
577 slope_0[1][sb] = slope * scalefactor;
578 offset_0[1][sb] = offset * scalefactor;
580 scalefactor = adec_scalefactor_table[index_2];
581 slope_0[2][sb] = slope * scalefactor;
582 offset_0[2][sb] = offset * scalefactor;
587 index_0 = GetBits(&p_adec->bit_stream,6);
588 index_1 = GetBits(&p_adec->bit_stream,6);
591 if (allocation_0[sb] < 0)
593 slope_0[0][sb] = slope_0[1][sb] =
594 adec_scalefactor_table[index_0];
595 slope_0[2][sb] = adec_scalefactor_table[index_1];
602 slope = adec_slope_table[allocation_0[sb]-2];
603 offset = adec_offset_table[allocation_0[sb]-2];
605 scalefactor = adec_scalefactor_table[index_0];
606 slope_0[0][sb] = slope_0[1][sb] = slope * scalefactor;
607 offset_0[0][sb] = offset_0[1][sb] =
608 offset * scalefactor;
610 scalefactor = adec_scalefactor_table[index_1];
611 slope_0[2][sb] = slope * scalefactor;
612 offset_0[2][sb] = offset * scalefactor;
617 index_0 = GetBits( &p_adec->bit_stream, 6 );
620 if (allocation_0[sb] < 0)
622 slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
623 adec_scalefactor_table[index_0];
630 slope = adec_slope_table[allocation_0[sb]-2];
631 offset = adec_offset_table[allocation_0[sb]-2];
633 scalefactor = adec_scalefactor_table[index_0];
634 slope_0[0][sb] = slope_0[1][sb] = slope_0[2][sb] =
636 offset_0[0][sb] = offset_0[1][sb] = offset_0[2][sb] =
637 offset * scalefactor;
642 index_0 = GetBits(&p_adec->bit_stream,6);
643 index_1 = GetBits(&p_adec->bit_stream,6);
646 if (allocation_0[sb] < 0)
648 slope_0[0][sb] = adec_scalefactor_table[index_0];
649 slope_0[1][sb] = slope_0[2][sb] =
650 adec_scalefactor_table[index_1];
657 slope = adec_slope_table[allocation_0[sb]-2];
658 offset = adec_offset_table[allocation_0[sb]-2];
660 scalefactor = adec_scalefactor_table[index_0];
661 slope_0[0][sb] = slope * scalefactor;
662 offset_0[0][sb] = offset * scalefactor;
664 scalefactor = adec_scalefactor_table[index_1];
665 slope_0[1][sb] = slope_0[2][sb] = slope * scalefactor;
666 offset_0[1][sb] = offset_0[2][sb] =
667 offset * scalefactor;
673 if (allocation_1[sb])
675 int index_0, index_1, index_2;
680 index_0 = GetBits(&p_adec->bit_stream,6);
681 index_1 = GetBits(&p_adec->bit_stream,6);
682 index_2 = GetBits(&p_adec->bit_stream,6);
685 if (allocation_1[sb] < 0)
687 slope_1[0][sb] = adec_scalefactor_table[index_0];
688 slope_1[1][sb] = adec_scalefactor_table[index_1];
689 slope_1[2][sb] = adec_scalefactor_table[index_2];
696 slope = adec_slope_table[allocation_1[sb]-2];
697 offset = adec_offset_table[allocation_1[sb]-2];
699 scalefactor = adec_scalefactor_table[index_0];
700 slope_1[0][sb] = slope * scalefactor;
701 offset_1[0][sb] = offset * scalefactor;
703 scalefactor = adec_scalefactor_table[index_1];
704 slope_1[1][sb] = slope * scalefactor;
705 offset_1[1][sb] = offset * scalefactor;
707 scalefactor = adec_scalefactor_table[index_2];
708 slope_1[2][sb] = slope * scalefactor;
709 offset_1[2][sb] = offset * scalefactor;
714 index_0 = GetBits(&p_adec->bit_stream,6);
715 index_1 = GetBits(&p_adec->bit_stream,6);
718 if (allocation_1[sb] < 0)
720 slope_1[0][sb] = slope_1[1][sb] =
721 adec_scalefactor_table[index_0];
722 slope_1[2][sb] = adec_scalefactor_table[index_1];
729 slope = adec_slope_table[allocation_1[sb]-2];
730 offset = adec_offset_table[allocation_1[sb]-2];
732 scalefactor = adec_scalefactor_table[index_0];
733 slope_1[0][sb] = slope_1[1][sb] = slope * scalefactor;
734 offset_1[0][sb] = offset_1[1][sb] =
735 offset * scalefactor;
737 scalefactor = adec_scalefactor_table[index_1];
738 slope_1[2][sb] = slope * scalefactor;
739 offset_1[2][sb] = offset * scalefactor;
744 index_0 = GetBits( &p_adec->bit_stream, 6 );
747 if (allocation_1[sb] < 0)
749 slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
750 adec_scalefactor_table[index_0];
757 slope = adec_slope_table[allocation_1[sb]-2];
758 offset = adec_offset_table[allocation_1[sb]-2];
760 scalefactor = adec_scalefactor_table[index_0];
761 slope_1[0][sb] = slope_1[1][sb] = slope_1[2][sb] =
763 offset_1[0][sb] = offset_1[1][sb] = offset_1[2][sb] =
764 offset * scalefactor;
769 index_0 = GetBits(&p_adec->bit_stream,6);
770 index_1 = GetBits(&p_adec->bit_stream,6);
773 if (allocation_1[sb] < 0)
775 slope_1[0][sb] = adec_scalefactor_table[index_0];
776 slope_1[1][sb] = slope_1[2][sb] =
777 adec_scalefactor_table[index_1];
784 slope = adec_slope_table[allocation_1[sb]-2];
785 offset = adec_offset_table[allocation_1[sb]-2];
787 scalefactor = adec_scalefactor_table[index_0];
788 slope_1[0][sb] = slope * scalefactor;
789 offset_1[0][sb] = offset * scalefactor;
791 scalefactor = adec_scalefactor_table[index_1];
792 slope_1[1][sb] = slope_1[2][sb] = slope * scalefactor;
793 offset_1[1][sb] = offset_1[2][sb] =
794 offset * scalefactor;
803 for (gr0 = 0; gr0 < 3; gr0++)
805 for (gr1 = 0; gr1 < 4; gr1++)
809 for (sb = 0; sb < bound; sb++)
813 switch (allocation_0[sb])
816 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
820 code = GetBits( &p_adec->bit_stream, 5 );
823 sample_0[0][sb] = slope_0[gr0][sb] * L3_table[code % 3];
825 sample_0[1][sb] = slope_0[gr0][sb] * L3_table[code % 3];
827 sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code];
831 code = GetBits( &p_adec->bit_stream, 7 );
834 sample_0[0][sb] = slope_0[gr0][sb] * L5_table[code % 5];
836 sample_0[1][sb] = slope_0[gr0][sb] * L5_table[code % 5];
838 sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code];
842 code = GetBits( &p_adec->bit_stream, 10 );
845 sample_0[0][sb] = slope_0[gr0][sb] * L9_table[code % 9];
847 sample_0[1][sb] = slope_0[gr0][sb] * L9_table[code % 9];
849 sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code];
853 for (s = 0; s < 3; s++)
855 code = GetBits( &p_adec->bit_stream,
857 i_read_bits += allocation_0[sb];
860 slope_0[gr0][sb] * code + offset_0[gr0][sb];
864 switch (allocation_1[sb])
867 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
871 code = GetBits( &p_adec->bit_stream, 5 );
874 sample_1[0][sb] = slope_1[gr0][sb] * L3_table[code % 3];
876 sample_1[1][sb] = slope_1[gr0][sb] * L3_table[code % 3];
878 sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code];
882 code = GetBits( &p_adec->bit_stream, 7 );
885 sample_1[0][sb] = slope_1[gr0][sb] * L5_table[code % 5];
887 sample_1[1][sb] = slope_1[gr0][sb] * L5_table[code % 5];
889 sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code];
893 code = GetBits( &p_adec->bit_stream, 10 );
896 sample_1[0][sb] = slope_1[gr0][sb] * L9_table[code % 9];
898 sample_1[1][sb] = slope_1[gr0][sb] * L9_table[code % 9];
900 sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code];
904 for (s = 0; s < 3; s++)
906 code = GetBits( &p_adec->bit_stream,
908 i_read_bits += allocation_1[sb];
911 slope_1[gr0][sb] * code + offset_1[gr0][sb];
916 for (; sb < sblimit; sb++)
920 switch (allocation_0[sb])
923 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
924 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
928 code = GetBits( &p_adec->bit_stream, 5 );
931 sample_0[0][sb] = slope_0[gr0][sb] * L3_table[code % 3];
932 sample_1[0][sb] = slope_1[gr0][sb] * L3_table[code % 3];
934 sample_0[1][sb] = slope_0[gr0][sb] * L3_table[code % 3];
935 sample_1[1][sb] = slope_1[gr0][sb] * L3_table[code % 3];
937 sample_0[2][sb] = slope_0[gr0][sb] * L3_table[code];
938 sample_1[2][sb] = slope_1[gr0][sb] * L3_table[code];
942 code = GetBits( &p_adec->bit_stream, 7 );
945 sample_0[0][sb] = slope_0[gr0][sb] * L5_table[code % 5];
946 sample_1[0][sb] = slope_1[gr0][sb] * L5_table[code % 5];
948 sample_0[1][sb] = slope_0[gr0][sb] * L5_table[code % 5];
949 sample_1[1][sb] = slope_1[gr0][sb] * L5_table[code % 5];
951 sample_0[2][sb] = slope_0[gr0][sb] * L5_table[code];
952 sample_1[2][sb] = slope_1[gr0][sb] * L5_table[code];
956 code = GetBits( &p_adec->bit_stream, 10 );
959 sample_0[0][sb] = slope_0[gr0][sb] * L9_table[code % 9];
960 sample_1[0][sb] = slope_1[gr0][sb] * L9_table[code % 9];
962 sample_0[1][sb] = slope_0[gr0][sb] * L9_table[code % 9];
963 sample_1[1][sb] = slope_1[gr0][sb] * L9_table[code % 9];
965 sample_0[2][sb] = slope_0[gr0][sb] * L9_table[code];
966 sample_1[2][sb] = slope_1[gr0][sb] * L9_table[code];
970 for (s = 0; s < 3; s++)
972 code = GetBits( &p_adec->bit_stream,
974 i_read_bits += allocation_0[sb];
977 slope_0[gr0][sb] * code + offset_0[gr0][sb];
979 slope_1[gr0][sb] * code + offset_1[gr0][sb];
984 for (; sb < 32; sb++)
986 sample_0[0][sb] = sample_0[1][sb] = sample_0[2][sb] = 0;
987 sample_1[0][sb] = sample_1[1][sb] = sample_1[2][sb] = 0;
990 for (s = 0; s < 3; s++)
992 DCT32 (sample_0[s], &p_adec->bank_0);
994 PCM (&p_adec->bank_0, &XXX_buf, 2);
996 DCT32 (sample_1[s], &p_adec->bank_1);
998 PCM (&p_adec->bank_1, &XXX_buf, 2);
1005 p_adec->i_read_bits += i_read_bits;