1 /*****************************************************************************
2 * audio_decoder.c: MPEG1 Layer I-II audio decoder
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 *****************************************************************************/
27 * - optimiser les NeedBits() et les GetBits() du code là où c'est possible ;
31 #include "int_types.h"
32 #include "audio_constants.h"
33 #include "audio_decoder.h"
34 #include "audio_math.h" /* DCT32(), PCM() */
35 #include "audio_bit_stream.h"
37 #define NULL ((void *)0)
39 /*****************************************************************************
40 * adec_Layer`L'_`M': decodes an mpeg 1, layer `L', mode `M', audio frame
41 *****************************************************************************
42 * These functions decode the audio frame which has already its header loaded
43 * in the i_header member of the audio decoder thread structure and its first
44 * byte of data described by the bit stream structure of the audio decoder
45 * thread (there is no bit available in the bit buffer yet)
46 *****************************************************************************/
48 /*****************************************************************************
50 *****************************************************************************/
51 static __inline__ int adec_Layer1_Mono (audiodec_t * p_adec)
53 p_adec->bit_stream.buffer = 0;
54 p_adec->bit_stream.i_available = 0;
58 /*****************************************************************************
60 *****************************************************************************/
61 static __inline__ int adec_Layer1_Stereo (audiodec_t * p_adec)
63 p_adec->bit_stream.buffer = 0;
64 p_adec->bit_stream.i_available = 0;
68 /*****************************************************************************
70 *****************************************************************************/
71 static __inline__ int adec_Layer2_Mono (audiodec_t * p_adec)
73 p_adec->bit_stream.buffer = 0;
74 p_adec->bit_stream.i_available = 0;
78 /*****************************************************************************
80 *****************************************************************************/
81 static __inline__ int adec_Layer2_Stereo (audiodec_t * p_adec, s16 * buffer)
83 typedef struct requantization_s
85 u8 i_bits_per_codeword;
86 const float * pf_ungroup;
91 static const float pf_scalefactor[64] = ADEC_SCALE_FACTOR;
94 static int i_sampling_frequency, i_mode, i_bound;
95 static int pi_allocation_0[32], pi_allocation_1[32]; /* see ISO/IEC 11172-3 2.4.1.6 */
97 float f_scalefactor_0, f_scalefactor_1;
99 static const u8 ppi_bitrate_per_channel_index[4][15] = ADEC_LAYER2_BITRATE_PER_CHANNEL_INDEX;
100 static const u8 ppi_sblimit[3][11] = ADEC_LAYER2_SBLIMIT;
101 static const u8 ppi_nbal[2][32] = ADEC_LAYER2_NBAL;
103 static const float pf_ungroup3[3*3*3 * 3] = ADEC_LAYER2_UNGROUP3;
104 static const float pf_ungroup5[5*5*5 * 3] = ADEC_LAYER2_UNGROUP5;
105 static const float pf_ungroup9[9*9*9 * 3] = ADEC_LAYER2_UNGROUP9;
107 static const requantization_t p_requantization_cd[16] = ADEC_LAYER2_REQUANTIZATION_CD;
108 static const requantization_t p_requantization_ab1[16] = ADEC_LAYER2_REQUANTIZATION_AB1;
109 static const requantization_t p_requantization_ab2[16] = ADEC_LAYER2_REQUANTIZATION_AB2;
110 static const requantization_t p_requantization_ab3[16] = ADEC_LAYER2_REQUANTIZATION_AB3;
111 static const requantization_t p_requantization_ab4[16] = ADEC_LAYER2_REQUANTIZATION_AB4;
112 static const requantization_t * pp_requantization_ab[30] = ADEC_LAYER2_REQUANTIZATION_AB;
114 static int i_sblimit, i_bitrate_per_channel_index;
115 static int pi_scfsi_0[30], pi_scfsi_1[30];
116 static const u8 * pi_nbal;
117 static float ppf_sample_0[3][32], ppf_sample_1[3][32];
118 static const requantization_t * pp_requantization_0[30];
119 static const requantization_t * pp_requantization_1[30];
120 static requantization_t requantization;
121 static const float * pf_ungroup;
123 static float pf_scalefactor_0_0[30], pf_scalefactor_0_1[30], pf_scalefactor_0_2[30];
124 static float pf_scalefactor_1_0[30], pf_scalefactor_1_1[30], pf_scalefactor_1_2[30];
131 int i_need = 0, i_dump = 0;
133 static const int pi_framesize[512] = ADEC_FRAME_SIZE;
136 /* Read the audio frame header and flush the bit buffer */
137 i_header = p_adec->header;
138 /* Read the sampling frequency (see ISO/IEC 11172-3 2.4.2.3) */
139 i_sampling_frequency = (int)((i_header & ADEC_HEADER_SAMPLING_FREQUENCY_MASK)
140 >> ADEC_HEADER_SAMPLING_FREQUENCY_SHIFT);
141 /* Read the mode (see ISO/IEC 11172-3 2.4.2.3) */
142 i_mode = (int)((i_header & ADEC_HEADER_MODE_MASK) >> ADEC_HEADER_MODE_SHIFT);
143 /* If a CRC can be found in the frame, get rid of it */
144 if ((i_header & ADEC_HEADER_PROTECTION_BIT_MASK) == 0)
146 NeedBits (&p_adec->bit_stream, 16);
147 DumpBits (&p_adec->bit_stream, 16);
150 /* Find out the bitrate per channel index */
151 i_bitrate_per_channel_index = (int)ppi_bitrate_per_channel_index[i_mode]
152 [(i_header & ADEC_HEADER_BITRATE_INDEX_MASK) >> ADEC_HEADER_BITRATE_INDEX_SHIFT];
153 /* Find out the number of subbands */
154 i_sblimit = (int)ppi_sblimit[i_sampling_frequency][i_bitrate_per_channel_index];
155 /* Check if the frame is valid or not */
158 return (0); /* the frame is invalid */
160 /* Find out the number of bits allocated */
161 pi_nbal = ppi_nbal[ (i_bitrate_per_channel_index <= 2) ? 0 : 1 ];
163 /* Find out the `bound' subband (see ISO/IEC 11172-3 2.4.2.3) */
166 i_bound = (int)(((i_header & ADEC_HEADER_MODE_EXTENSION_MASK) >> (ADEC_HEADER_MODE_EXTENSION_SHIFT - 2)) + 4);
167 if (i_bound > i_sblimit)
177 /* Read the allocation information (see ISO/IEC 11172-3 2.4.1.6) */
178 for (i_sb = 0; i_sb < i_bound; i_sb++)
180 i_2nbal = 2 * (i_nbal = (int)pi_nbal[ i_sb ]);
181 NeedBits (&p_adec->bit_stream, i_2nbal);
183 pi_allocation_0[ i_sb ] = (int)(p_adec->bit_stream.buffer >> (32 - i_nbal));
184 p_adec->bit_stream.buffer <<= i_nbal;
185 pi_allocation_1[ i_sb ] = (int)(p_adec->bit_stream.buffer >> (32 - i_nbal));
186 p_adec->bit_stream.buffer <<= i_nbal;
187 p_adec->bit_stream.i_available -= i_2nbal;
190 for (; i_sb < i_sblimit; i_sb++)
192 i_nbal = (int)pi_nbal[ i_sb ];
193 NeedBits (&p_adec->bit_stream, i_nbal);
195 pi_allocation_0[ i_sb ] = (int)(p_adec->bit_stream.buffer >> (32 - i_nbal));
196 DumpBits (&p_adec->bit_stream, i_nbal);
200 #define MACRO(p_requantization) \
201 for (i_sb = 0; i_sb < i_bound; i_sb++) \
203 if (pi_allocation_0[i_sb]) \
205 pp_requantization_0[i_sb] = &((p_requantization)[pi_allocation_0[i_sb]]); \
206 NeedBits (&p_adec->bit_stream, 2); \
208 pi_scfsi_0[i_sb] = (int)(p_adec->bit_stream.buffer >> (32 - 2)); \
209 DumpBits (&p_adec->bit_stream, 2); \
214 ppf_sample_0[0][i_sb] = .0; \
215 ppf_sample_0[1][i_sb] = .0; \
216 ppf_sample_0[2][i_sb] = .0; \
219 if (pi_allocation_1[i_sb]) \
221 pp_requantization_1[i_sb] = &((p_requantization)[pi_allocation_1[i_sb]]); \
222 NeedBits (&p_adec->bit_stream, 2); \
224 pi_scfsi_1[i_sb] = (int)(p_adec->bit_stream.buffer >> (32 - 2)); \
225 DumpBits (&p_adec->bit_stream, 2); \
230 ppf_sample_1[0][i_sb] = .0; \
231 ppf_sample_1[1][i_sb] = .0; \
232 ppf_sample_1[2][i_sb] = .0; \
236 for (; i_sb < i_sblimit; i_sb++) \
238 if (pi_allocation_0[i_sb]) \
240 pp_requantization_0[i_sb] = &((p_requantization)[pi_allocation_0[i_sb]]); \
241 NeedBits (&p_adec->bit_stream, 4); \
243 pi_scfsi_0[i_sb] = (int)(p_adec->bit_stream.buffer >> (32 - 2)); \
244 p_adec->bit_stream.buffer <<= 2; \
245 pi_scfsi_1[i_sb] = (int)(p_adec->bit_stream.buffer >> (32 - 2)); \
246 p_adec->bit_stream.buffer <<= 2; \
247 p_adec->bit_stream.i_available -= 4; \
252 ppf_sample_0[0][i_sb] = .0; \
253 ppf_sample_0[1][i_sb] = .0; \
254 ppf_sample_0[2][i_sb] = .0; \
255 ppf_sample_1[0][i_sb] = .0; \
256 ppf_sample_1[1][i_sb] = .0; \
257 ppf_sample_1[2][i_sb] = .0; \
262 if (i_bitrate_per_channel_index <= 2)
264 MACRO (p_requantization_cd)
268 MACRO (pp_requantization_ab[i_sb])
271 #define SWITCH(pi_scfsi,pf_scalefactor_0,pf_scalefactor_1,pf_scalefactor_2) \
272 switch ((pi_scfsi)[i_sb]) \
275 NeedBits (&p_adec->bit_stream, (3*6)); \
277 (pf_scalefactor_0)[i_sb] = pf_scalefactor[p_adec->bit_stream.buffer >> (32 - 6)]; \
278 p_adec->bit_stream.buffer <<= 6; \
279 (pf_scalefactor_1)[i_sb] = pf_scalefactor[p_adec->bit_stream.buffer >> (32 - 6)]; \
280 p_adec->bit_stream.buffer <<= 6; \
281 (pf_scalefactor_2)[i_sb] = pf_scalefactor[p_adec->bit_stream.buffer >> (32 - 6)]; \
282 p_adec->bit_stream.buffer <<= 6; \
283 p_adec->bit_stream.i_available -= (3*6); \
288 NeedBits (&p_adec->bit_stream, (2*6)); \
290 (pf_scalefactor_0)[i_sb] = \
291 (pf_scalefactor_1)[i_sb] = pf_scalefactor[p_adec->bit_stream.buffer >> (32 - 6)]; \
292 p_adec->bit_stream.buffer <<= 6; \
293 (pf_scalefactor_2)[i_sb] = pf_scalefactor[p_adec->bit_stream.buffer >> (32 - 6)]; \
294 p_adec->bit_stream.buffer <<= 6; \
295 p_adec->bit_stream.i_available -= (2*6); \
300 NeedBits (&p_adec->bit_stream, (1*6)); \
302 (pf_scalefactor_0)[i_sb] = \
303 (pf_scalefactor_1)[i_sb] = \
304 (pf_scalefactor_2)[i_sb] = pf_scalefactor[p_adec->bit_stream.buffer >> (32 - 6)]; \
305 DumpBits (&p_adec->bit_stream, (1*6)); \
310 NeedBits (&p_adec->bit_stream, (2*6)); \
312 (pf_scalefactor_0)[i_sb] = pf_scalefactor[p_adec->bit_stream.buffer >> (32 - 6)]; \
313 p_adec->bit_stream.buffer <<= 6; \
314 (pf_scalefactor_1)[i_sb] = \
315 (pf_scalefactor_2)[i_sb] = pf_scalefactor[p_adec->bit_stream.buffer >> (32 - 6)]; \
316 p_adec->bit_stream.buffer <<= 6; \
317 p_adec->bit_stream.i_available -= (2*6); \
323 for (i_sb = 0; i_sb < i_bound; i_sb++)
325 if (pi_allocation_0[i_sb])
327 SWITCH (pi_scfsi_0, pf_scalefactor_0_0, pf_scalefactor_0_1, pf_scalefactor_0_2)
329 if (pi_allocation_1[i_sb])
331 SWITCH (pi_scfsi_1, pf_scalefactor_1_0, pf_scalefactor_1_1, pf_scalefactor_1_2)
334 for (; i_sb < i_sblimit; i_sb++)
336 if (pi_allocation_0[i_sb])
338 SWITCH (pi_scfsi_0, pf_scalefactor_0_0, pf_scalefactor_0_1, pf_scalefactor_0_2)
339 SWITCH (pi_scfsi_1, pf_scalefactor_1_0, pf_scalefactor_1_1, pf_scalefactor_1_2)
342 for (; i_sb < 32; i_sb++)
344 ppf_sample_0[0][i_sb] = .0;
345 ppf_sample_0[1][i_sb] = .0;
346 ppf_sample_0[2][i_sb] = .0;
347 ppf_sample_1[0][i_sb] = .0;
348 ppf_sample_1[1][i_sb] = .0;
349 ppf_sample_1[2][i_sb] = .0;
352 #define GROUPTEST(pp_requantization,ppf_sample,pf_sf) \
353 requantization = *((pp_requantization)[i_sb]); \
354 if (requantization.pf_ungroup == NULL) \
356 NeedBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
357 i_need += requantization.i_bits_per_codeword; \
358 (ppf_sample)[0][i_sb] = (f_scalefactor_0 = (pf_sf)[i_sb]) * (requantization.f_slope * \
359 (p_adec->bit_stream.buffer >> (32 - requantization.i_bits_per_codeword)) + requantization.f_offset); \
360 DumpBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
361 i_dump += requantization.i_bits_per_codeword; \
363 NeedBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
364 i_need += requantization.i_bits_per_codeword; \
365 (ppf_sample)[1][i_sb] = f_scalefactor_0 * (requantization.f_slope * \
366 (p_adec->bit_stream.buffer >> (32 - requantization.i_bits_per_codeword)) + requantization.f_offset); \
367 DumpBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
368 i_dump += requantization.i_bits_per_codeword; \
370 NeedBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
371 i_need += requantization.i_bits_per_codeword; \
372 (ppf_sample)[2][i_sb] = f_scalefactor_0 * (requantization.f_slope * \
373 (p_adec->bit_stream.buffer >> (32 - requantization.i_bits_per_codeword)) + requantization.f_offset); \
374 DumpBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
375 i_dump += requantization.i_bits_per_codeword; \
379 NeedBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
380 i_need += requantization.i_bits_per_codeword; \
381 pf_ungroup = requantization.pf_ungroup + 3 * \
382 (p_adec->bit_stream.buffer >> (32 - requantization.i_bits_per_codeword)); \
383 DumpBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
384 i_dump += requantization.i_bits_per_codeword; \
385 (ppf_sample)[0][i_sb] = (f_scalefactor_0 = (pf_sf)[i_sb]) * pf_ungroup[0]; \
386 (ppf_sample)[1][i_sb] = f_scalefactor_0 * pf_ungroup[1]; \
387 (ppf_sample)[2][i_sb] = f_scalefactor_0 * pf_ungroup[2]; \
389 /* #define GROUPTEST */
391 #define READ_SAMPLE_L2S(pf_scalefactor_0,pf_scalefactor_1,i_grlimit) \
392 for (; i_gr < (i_grlimit); i_gr++) \
394 for (i_sb = 0; i_sb < i_bound; i_sb++) \
396 if (pi_allocation_0[i_sb]) \
398 GROUPTEST (pp_requantization_0, ppf_sample_0, (pf_scalefactor_0)) \
400 if (pi_allocation_1[i_sb]) \
402 GROUPTEST (pp_requantization_1, ppf_sample_1, (pf_scalefactor_1)) \
405 for (; i_sb < i_sblimit; i_sb++) \
407 if (pi_allocation_0[i_sb]) \
409 requantization = *(pp_requantization_0[i_sb]); \
410 if (requantization.pf_ungroup == NULL) \
412 NeedBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
413 i_need += requantization.i_bits_per_codeword; \
414 ppf_sample_0[0][i_sb] = (f_scalefactor_0 = (pf_scalefactor_0)[i_sb]) * \
415 (requantization.f_slope * (f_dummy = \
416 (float)(p_adec->bit_stream.buffer >> (32 - requantization.i_bits_per_codeword))) + \
417 requantization.f_offset); \
418 DumpBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
419 i_dump += requantization.i_bits_per_codeword; \
420 ppf_sample_1[0][i_sb] = (f_scalefactor_1 = (pf_scalefactor_1)[i_sb]) * \
421 (requantization.f_slope * f_dummy + requantization.f_offset); \
423 NeedBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
424 i_need += requantization.i_bits_per_codeword; \
425 ppf_sample_0[1][i_sb] = f_scalefactor_0 * \
426 (requantization.f_slope * (f_dummy = \
427 (float)(p_adec->bit_stream.buffer >> (32 - requantization.i_bits_per_codeword))) + \
428 requantization.f_offset); \
429 DumpBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
430 i_dump += requantization.i_bits_per_codeword; \
431 ppf_sample_1[1][i_sb] = f_scalefactor_1 * \
432 (requantization.f_slope * f_dummy + requantization.f_offset); \
434 NeedBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
435 i_need += requantization.i_bits_per_codeword; \
436 ppf_sample_0[2][i_sb] = f_scalefactor_0 * \
437 (requantization.f_slope * (f_dummy = \
438 (float)(p_adec->bit_stream.buffer >> (32 - requantization.i_bits_per_codeword))) + \
439 requantization.f_offset); \
440 DumpBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
441 i_dump += requantization.i_bits_per_codeword; \
442 ppf_sample_1[2][i_sb] = f_scalefactor_1 * \
443 (requantization.f_slope * f_dummy + requantization.f_offset); \
447 NeedBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
448 i_need += requantization.i_bits_per_codeword; \
449 pf_ungroup = requantization.pf_ungroup + 3 * \
450 (p_adec->bit_stream.buffer >> (32 - requantization.i_bits_per_codeword)); \
451 DumpBits (&p_adec->bit_stream, requantization.i_bits_per_codeword); \
452 i_dump += requantization.i_bits_per_codeword; \
454 ppf_sample_0[0][i_sb] = (f_scalefactor_0 = (pf_scalefactor_0)[i_sb]) * pf_ungroup[0]; \
455 ppf_sample_0[1][i_sb] = f_scalefactor_0 * pf_ungroup[1]; \
456 ppf_sample_0[2][i_sb] = f_scalefactor_0 * pf_ungroup[2]; \
458 ppf_sample_1[0][i_sb] = (f_scalefactor_1 = (pf_scalefactor_1)[i_sb]) * pf_ungroup[0]; \
459 ppf_sample_1[1][i_sb] = f_scalefactor_1 * pf_ungroup[1]; \
460 ppf_sample_1[2][i_sb] = f_scalefactor_1 * pf_ungroup[2]; \
465 DCT32 (ppf_sample_0[0], &p_adec->bank_0); \
466 PCM (&p_adec->bank_0, &p_s16, 2); \
469 DCT32 (ppf_sample_1[0], &p_adec->bank_1); \
470 PCM (&p_adec->bank_1, &p_s16, 2); \
473 DCT32 (ppf_sample_0[1], &p_adec->bank_0); \
474 PCM (&p_adec->bank_0, &p_s16, 2); \
477 DCT32 (ppf_sample_1[1], &p_adec->bank_1); \
478 PCM (&p_adec->bank_1, &p_s16, 2); \
481 DCT32 (ppf_sample_0[2], &p_adec->bank_0); \
482 PCM (&p_adec->bank_0, &p_s16, 2); \
485 DCT32 (ppf_sample_1[2], &p_adec->bank_1); \
486 PCM (&p_adec->bank_1, &p_s16, 2); \
489 /* #define READ_SAMPLE_L2S */
494 READ_SAMPLE_L2S (pf_scalefactor_0_0, pf_scalefactor_1_0, 4)
495 READ_SAMPLE_L2S (pf_scalefactor_0_1, pf_scalefactor_1_1, 8)
496 READ_SAMPLE_L2S (pf_scalefactor_0_2, pf_scalefactor_1_2, 12)
498 p_adec->bit_stream.buffer = 0;
499 p_adec->bit_stream.i_available = 0;
505 int adec_init (audiodec_t * p_adec)
507 p_adec->bank_0.actual = p_adec->bank_0.v1;
508 p_adec->bank_0.pos = 0;
509 p_adec->bank_1.actual = p_adec->bank_1.v1;
510 p_adec->bank_1.pos = 0;
514 int adec_sync_frame (audiodec_t * p_adec, adec_sync_info_t * p_sync_info)
516 static int mpeg1_sample_rate[3] = {44100, 48000, 32000};
517 static int mpeg1_layer1_bit_rate[15] = {
518 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448
520 static int mpeg1_layer2_bit_rate[15] = {
521 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384
523 static int mpeg2_layer1_bit_rate[15] = {
524 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256
526 static int mpeg2_layer2_bit_rate[15] = {
527 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160
531 int * bit_rate_table;
536 p_adec->bit_stream.total_bytes_read = 0;
537 header = GetByte (&p_adec->bit_stream) << 24;
538 header |= GetByte (&p_adec->bit_stream) << 16;
539 header |= GetByte (&p_adec->bit_stream) << 8;
540 header |= GetByte (&p_adec->bit_stream);
542 p_adec->header = header;
544 /* basic header check : sync word, no emphasis */
545 if ((header & 0xfff00003) != 0xfff00000)
548 index = (header >> 10) & 3; /* sample rate index */
551 sample_rate = mpeg1_sample_rate[index];
553 switch ((header >> 17) & 7) {
554 case 2: /* mpeg 2, layer 2 */
555 sample_rate >>= 1; /* half sample rate for mpeg2 */
556 bit_rate_table = mpeg2_layer2_bit_rate;
558 case 3: /* mpeg 2, layer 1 */
559 sample_rate >>= 1; /* half sample rate for mpeg2 */
560 bit_rate_table = mpeg2_layer1_bit_rate;
562 case 6: /* mpeg1, layer 2 */
563 bit_rate_table = mpeg1_layer2_bit_rate;
565 case 7: /* mpeg1, layer 1 */
566 bit_rate_table = mpeg1_layer1_bit_rate;
568 default: /* invalid layer */
572 index = (header >> 12) & 15; /* bit rate index */
575 bit_rate = bit_rate_table[index];
577 p_sync_info->sample_rate = sample_rate;
578 p_sync_info->bit_rate = bit_rate;
580 if ((header & 0x60000) == 0x60000) { /* layer 1 */
581 frame_size = 48000 * bit_rate / sample_rate;
582 if (header & 0x200) /* padding */
584 } else { /* layer >1 */
585 frame_size = 144000 * bit_rate / sample_rate;
586 if (header & 0x200) /* padding */
590 p_sync_info->frame_size = frame_size;
591 p_adec->frame_size = frame_size;
596 int adec_decode_frame (audiodec_t * p_adec, s16 * buffer)
598 p_adec->bit_stream.i_available = 0;
600 adec_Layer2_Stereo (p_adec, buffer);
602 if (p_adec->bit_stream.total_bytes_read > p_adec->frame_size)
605 while (p_adec->bit_stream.total_bytes_read < p_adec->frame_size)
606 GetByte (&p_adec->bit_stream);