1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18 /*
19 ------------------------------------------------------------------------------
20
21 PacketVideo Corp.
22 MP3 Decoder Library
23
24 Filename: pvmp3_framedecoder.cpp
25
26 Functions:
27 pvmp3_framedecoder
28 pvmp3_InitDecoder
29 pvmp3_resetDecoder
30
31 Date: 09/21/2007
32
33 ------------------------------------------------------------------------------
34 REVISION HISTORY
35
36
37 Description:
38
39 ------------------------------------------------------------------------------
40 INPUT AND OUTPUT DEFINITIONS
41
42 Input
43 pExt = pointer to the external interface structure. See the file
44 pvmp3decoder_api.h for a description of each field.
45 Data type of pointer to a tPVMP3DecoderExternal
46 structure.
47
48 pMem = void pointer to hide the internal implementation of the library
49 It is cast back to a tmp3dec_file structure. This structure
50 contains information that needs to persist between calls to
51 this function, or is too big to be placed on the stack, even
52 though the data is only needed during execution of this function
53 Data type void pointer, internally pointer to a tmp3dec_file
54 structure.
55
56
57 Outputs:
58 status = ERROR condition. see structure ERROR_CODE
59
60 Pointers and Buffers Modified:
61 pMem contents are modified.
62 pExt: (more detail in the file pvmp3decoder_api.h)
63 inputBufferUsedLength - number of array elements used up by the stream.
64 samplingRate - sampling rate in samples per sec
65 bitRate - bit rate in bits per second, varies frame to frame.
66
67
68
69 ------------------------------------------------------------------------------
70 FUNCTIONS DESCRIPTION
71
72 pvmp3_framedecoder
73 frame decoder library driver
74 pvmp3_InitDecoder
75 Decoder Initialization
76 pvmp3_resetDecoder
77 Reset Decoder
78
79 ------------------------------------------------------------------------------
80 REQUIREMENTS
81
82
83 ------------------------------------------------------------------------------
84 REFERENCES
85
86 [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
87 ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
88
89 ------------------------------------------------------------------------------
90 PSEUDO-CODE
91
92 ------------------------------------------------------------------------------
93 */
94
95
96 /*----------------------------------------------------------------------------
97 ; INCLUDES
98 ----------------------------------------------------------------------------*/
99
100
101 #include "pvmp3_framedecoder.h"
102 #include "pvmp3_dec_defs.h"
103 #include "pvmp3_poly_phase_synthesis.h"
104 #include "pvmp3_tables.h"
105 #include "pvmp3_imdct_synth.h"
106 #include "pvmp3_alias_reduction.h"
107 #include "pvmp3_reorder.h"
108 #include "pvmp3_dequantize_sample.h"
109 #include "pvmp3_stereo_proc.h"
110 #include "pvmp3_mpeg2_stereo_proc.h"
111 #include "pvmp3_get_side_info.h"
112 #include "pvmp3_get_scale_factors.h"
113 #include "pvmp3_mpeg2_get_scale_factors.h"
114 #include "pvmp3_decode_header.h"
115 #include "pvmp3_get_main_data_size.h"
116 #include "s_tmp3dec_file.h"
117 #include "pvmp3_getbits.h"
118 #include "mp3_mem_funcs.h"
119
120
121 /*----------------------------------------------------------------------------
122 ; MACROS
123 ; Define module specific macros here
124 ----------------------------------------------------------------------------*/
125
126
127 /*----------------------------------------------------------------------------
128 ; DEFINES
129 ; Include all pre-processor statements here. Include conditional
130 ; compile variables also.
131 ----------------------------------------------------------------------------*/
132
133 /*----------------------------------------------------------------------------
134 ; LOCAL FUNCTION DEFINITIONS
135 ; Function Prototype declaration
136 ----------------------------------------------------------------------------*/
137
138 /*----------------------------------------------------------------------------
139 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
140 ; Variable declaration - defined here and used outside this module
141 ----------------------------------------------------------------------------*/
142
143 /*----------------------------------------------------------------------------
144 ; EXTERNAL FUNCTION REFERENCES
145 ; Declare functions defined elsewhere and referenced in this module
146 ----------------------------------------------------------------------------*/
147
148 /*----------------------------------------------------------------------------
149 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
150 ; Declare variables used in this module but defined elsewhere
151 ----------------------------------------------------------------------------*/
152
153 /*----------------------------------------------------------------------------
154 ; FUNCTION CODE
155 ----------------------------------------------------------------------------*/
156
pvmp3_framedecoder(tPVMP3DecoderExternal * pExt,void * pMem)157 ERROR_CODE pvmp3_framedecoder(tPVMP3DecoderExternal *pExt,
158 void *pMem)
159 {
160
161 ERROR_CODE errorCode = NO_DECODING_ERROR;
162
163 int32 crc_error_count = 0;
164 uint32 sent_crc = 0;
165 uint32 computed_crc = 0;
166
167 tmp3dec_chan *pChVars[CHAN];
168 tmp3dec_file *pVars = (tmp3dec_file *)pMem;
169
170 mp3Header info_data;
171 mp3Header *info = &info_data;
172
173 pVars->inputStream.pBuffer = pExt->pInputBuffer;
174
175
176 pVars->inputStream.usedBits = pExt->inputBufferUsedLength << 3;
177 pVars->inputStream.inputBufferCurrentLength = pExt->inputBufferCurrentLength;
178
179
180 errorCode = pvmp3_decode_header(&pVars->inputStream,
181 info,
182 &computed_crc);
183
184 if (errorCode != NO_DECODING_ERROR)
185 {
186 pExt->outputFrameSize = 0;
187 return errorCode;
188 }
189
190 pVars->num_channels = (info->mode == MPG_MD_MONO) ? 1 : 2;
191 pExt->num_channels = pVars->num_channels;
192
193 int32 outputFrameSize = (info->version_x == MPEG_1) ?
194 2 * SUBBANDS_NUMBER * FILTERBANK_BANDS :
195 SUBBANDS_NUMBER * FILTERBANK_BANDS;
196
197 outputFrameSize = (info->mode == MPG_MD_MONO) ? outputFrameSize : outputFrameSize << 1;
198
199
200 /*
201 * Check if output buffer has enough room to hold output PCM
202 */
203 if (pExt->outputFrameSize >= outputFrameSize)
204 {
205 pExt->outputFrameSize = outputFrameSize;
206 }
207 else
208 {
209 pExt->outputFrameSize = 0;
210 return OUTPUT_BUFFER_TOO_SMALL;
211 }
212
213
214 pChVars[ LEFT] = &pVars->perChan[ LEFT];
215 pChVars[RIGHT] = &pVars->perChan[RIGHT];
216
217
218
219
220 if (info->error_protection)
221 {
222 if (!bitsAvailable(&pVars->inputStream, 16))
223 {
224 return SIDE_INFO_ERROR;
225 }
226
227 /*
228 * Get crc content
229 */
230 sent_crc = getUpTo17bits(&pVars->inputStream, 16);
231 }
232
233
234 if (info->layer_description == 3)
235 {
236 int32 gr;
237 int32 ch;
238 uint32 main_data_end;
239 int32 bytes_to_discard;
240 int16 *ptrOutBuffer = pExt->pOutputBuffer;
241
242 /*
243 * Side Information must be extracted from the bitstream and store for use
244 * during the decoded of the associated frame
245 */
246
247 errorCode = pvmp3_get_side_info(&pVars->inputStream,
248 &pVars->sideInfo,
249 info,
250 &computed_crc);
251
252 if (errorCode != NO_DECODING_ERROR)
253 {
254 pExt->outputFrameSize = 0;
255 return errorCode;
256 }
257
258 /*
259 * If CRC was sent, check that matches the one got while parsing data
260 * disable crc if this is the desired mode
261 */
262 if (info->error_protection)
263 {
264 if ((computed_crc != sent_crc) && pExt->crcEnabled)
265 {
266 crc_error_count++;
267 }
268 }
269
270 /*
271 * main data (scalefactors, Huffman coded, etc,) are not necessarily located
272 * adjacent to the side-info. Beginning of main data is located using
273 * field "main_data_begin" of the current frame. The length does not include
274 * header and side info.
275 * "main_data_begin" points to the first bit of main data of a frame. It is a negative
276 * offset in bytes from the first byte of the sync word
277 * main_data_begin = 0 <===> main data start rigth after side info.
278 */
279
280 int32 temp = pvmp3_get_main_data_size(info, pVars);
281
282
283 /*
284 * Check if available data holds a full frame, if not flag an error
285 */
286
287 if ((uint32)pVars->predicted_frame_size > pVars->inputStream.inputBufferCurrentLength)
288 {
289 pExt->outputFrameSize = 0;
290 return NO_ENOUGH_MAIN_DATA_ERROR;
291 }
292
293 /*
294 * Fill in internal circular buffer
295 */
296 fillMainDataBuf(pVars, temp);
297
298
299 main_data_end = pVars->mainDataStream.usedBits >> 3; /* in bytes */
300 if ((main_data_end << 3) < pVars->mainDataStream.usedBits)
301 {
302 main_data_end++;
303 pVars->mainDataStream.usedBits = main_data_end << 3;
304 }
305
306
307 // force signed computation; buffer sizes and offsets are all going to be
308 // well within the constraints of 32-bit signed math.
309 bytes_to_discard = pVars->frame_start
310 - ((int32)pVars->sideInfo.main_data_begin)
311 - ((int32)main_data_end);
312
313
314 if (main_data_end > BUFSIZE) /* check overflow on the buffer */
315 {
316 pVars->frame_start -= BUFSIZE;
317
318 pVars->mainDataStream.usedBits -= (BUFSIZE << 3);
319 }
320
321 pVars->frame_start += temp;
322
323
324 if (bytes_to_discard < 0 || crc_error_count)
325 {
326 /*
327 * Not enough data to decode, then we should avoid reading this
328 * data ( getting/ignoring sido info and scale data)
329 * Main data could be located in the previous frame, so an unaccounted
330 * frame can cause incorrect processing
331 * Just run the polyphase filter to "clean" the history buffer
332 */
333 errorCode = NO_ENOUGH_MAIN_DATA_ERROR;
334
335 /*
336 * Clear the input to these filters
337 */
338
339 pv_memset((void*)pChVars[RIGHT]->work_buf_int32,
340 0,
341 SUBBANDS_NUMBER*FILTERBANK_BANDS*sizeof(pChVars[RIGHT]->work_buf_int32[0]));
342
343 pv_memset((void*)pChVars[LEFT]->work_buf_int32,
344 0,
345 SUBBANDS_NUMBER*FILTERBANK_BANDS*sizeof(pChVars[LEFT]->work_buf_int32[0]));
346
347 /* clear circular buffers, to avoid any glitch */
348 pv_memset((void*)&pChVars[ LEFT]->circ_buffer[576],
349 0,
350 480*sizeof(pChVars[ LEFT]->circ_buffer[0]));
351 pv_memset((void*)&pChVars[RIGHT]->circ_buffer[576],
352 0,
353 480*sizeof(pChVars[RIGHT]->circ_buffer[0]));
354
355 pChVars[ LEFT]->used_freq_lines = 575;
356 pChVars[RIGHT]->used_freq_lines = 575;
357
358 }
359 else
360 {
361 pVars->mainDataStream.usedBits += (bytes_to_discard << 3);
362 }
363
364 /*
365 * if (fr_ps->header->version_x == MPEG_1), use 2 granules, otherwise just 1
366 */
367 for (gr = 0; gr < (1 + !(info->version_x)); gr++)
368 {
369 if (errorCode != NO_ENOUGH_MAIN_DATA_ERROR)
370 {
371 for (ch = 0; ch < pVars->num_channels; ch++)
372 {
373 int32 part2_start = pVars->mainDataStream.usedBits;
374
375 if (info->version_x == MPEG_1)
376 {
377
378 pvmp3_get_scale_factors(&pVars->scaleFactors[ch],
379 &pVars->sideInfo,
380 gr,
381 ch,
382 &pVars->mainDataStream);
383 }
384 else
385 {
386 int32 * tmp = pVars->Scratch_mem;
387 pvmp3_mpeg2_get_scale_factors(&pVars->scaleFactors[ch],
388 &pVars->sideInfo,
389 gr,
390 ch,
391 info,
392 (uint32 *)tmp,
393 &pVars->mainDataStream);
394 }
395
396 pChVars[ch]->used_freq_lines = pvmp3_huffman_parsing(pChVars[ch]->work_buf_int32,
397 &pVars->sideInfo.ch[ch].gran[gr],
398 pVars,
399 part2_start,
400 info);
401
402
403 pvmp3_dequantize_sample(pChVars[ch]->work_buf_int32,
404 &pVars->scaleFactors[ch],
405 &pVars->sideInfo.ch[ch].gran[gr],
406 pChVars[ch]->used_freq_lines,
407 info);
408
409
410
411
412 } /* for (ch=0; ch<stereo; ch++) */
413
414 if (pVars->num_channels == 2)
415 {
416
417 int32 used_freq_lines = (pChVars[ LEFT]->used_freq_lines >
418 pChVars[RIGHT]->used_freq_lines) ?
419 pChVars[ LEFT]->used_freq_lines :
420 pChVars[RIGHT]->used_freq_lines;
421
422 pChVars[ LEFT]->used_freq_lines = used_freq_lines;
423 pChVars[RIGHT]->used_freq_lines = used_freq_lines;
424
425 if (info->version_x == MPEG_1)
426 {
427 pvmp3_stereo_proc(pChVars[ LEFT]->work_buf_int32,
428 pChVars[RIGHT]->work_buf_int32,
429 &pVars->scaleFactors[RIGHT],
430 &pVars->sideInfo.ch[LEFT].gran[gr],
431 used_freq_lines,
432 info);
433 }
434 else
435 {
436 int32 * tmp = pVars->Scratch_mem;
437 pvmp3_mpeg2_stereo_proc(pChVars[ LEFT]->work_buf_int32,
438 pChVars[RIGHT]->work_buf_int32,
439 &pVars->scaleFactors[RIGHT],
440 &pVars->sideInfo.ch[ LEFT].gran[gr],
441 &pVars->sideInfo.ch[RIGHT].gran[gr],
442 (uint32 *)tmp,
443 used_freq_lines,
444 info);
445 }
446 }
447
448 } /* if ( errorCode != NO_ENOUGH_MAIN_DATA_ERROR) */
449
450 for (ch = 0; ch < pVars->num_channels; ch++)
451 {
452
453 pvmp3_reorder(pChVars[ch]->work_buf_int32,
454 &pVars->sideInfo.ch[ch].gran[gr],
455 &pChVars[ ch]->used_freq_lines,
456 info,
457 pVars->Scratch_mem);
458
459 pvmp3_alias_reduction(pChVars[ch]->work_buf_int32,
460 &pVars->sideInfo.ch[ch].gran[gr],
461 &pChVars[ ch]->used_freq_lines,
462 info);
463
464
465 /*
466 * IMDCT
467 */
468 /* set mxposition
469 * In case of mixed blocks, # of bands with long
470 * blocks (2 or 4) else 0
471 */
472 uint16 mixedBlocksLongBlocks = 0; /* 0 = long or short, 2=mixed, 4=mixed 2.5@8000 */
473 if (pVars->sideInfo.ch[ch].gran[gr].mixed_block_flag &&
474 pVars->sideInfo.ch[ch].gran[gr].window_switching_flag)
475 {
476 if ((info->version_x == MPEG_2_5) && (info->sampling_frequency == 2))
477 {
478 mixedBlocksLongBlocks = 4; /* mpeg2.5 @ 8 KHz */
479 }
480 else
481 {
482 mixedBlocksLongBlocks = 2;
483 }
484 }
485
486 pvmp3_imdct_synth(pChVars[ch]->work_buf_int32,
487 pChVars[ch]->overlap,
488 pVars->sideInfo.ch[ch].gran[gr].block_type,
489 mixedBlocksLongBlocks,
490 pChVars[ ch]->used_freq_lines,
491 pVars->Scratch_mem);
492
493
494 /*
495 * Polyphase synthesis
496 */
497
498 pvmp3_poly_phase_synthesis(pChVars[ch],
499 pVars->num_channels,
500 pExt->equalizerType,
501 &ptrOutBuffer[ch]);
502
503
504 }/* end ch loop */
505
506 ptrOutBuffer += pVars->num_channels * SUBBANDS_NUMBER * FILTERBANK_BANDS;
507 } /* for (gr=0;gr<Max_gr;gr++) */
508
509 /* skip ancillary data */
510 if (info->bitrate_index > 0)
511 { /* if not free-format */
512
513 int32 ancillary_data_lenght = pVars->predicted_frame_size << 3;
514
515 ancillary_data_lenght -= pVars->inputStream.usedBits;
516
517 /* skip ancillary data */
518 if (ancillary_data_lenght > 0)
519 {
520 pVars->inputStream.usedBits += ancillary_data_lenght;
521 }
522
523 }
524
525 /*
526 * This overrides a possible NO_ENOUGH_MAIN_DATA_ERROR
527 */
528 errorCode = NO_DECODING_ERROR;
529
530 }
531 else
532 {
533 /*
534 * The info on the header leads to an unsupported layer, more data
535 * will not fix this, so this is a bad frame,
536 */
537
538 pExt->outputFrameSize = 0;
539 return UNSUPPORTED_LAYER;
540 }
541
542 pExt->inputBufferUsedLength = pVars->inputStream.usedBits >> 3;
543 pExt->totalNumberOfBitsUsed += pVars->inputStream.usedBits;
544 pExt->version = info->version_x;
545 pExt->samplingRate = mp3_s_freq[info->version_x][info->sampling_frequency];
546 pExt->bitRate = mp3_bitrate[pExt->version][info->bitrate_index];
547
548
549 /*
550 * Always verify buffer overrun condition
551 */
552
553 if (pExt->inputBufferUsedLength > pExt->inputBufferCurrentLength)
554 {
555 pExt->outputFrameSize = 0;
556 errorCode = NO_ENOUGH_MAIN_DATA_ERROR;
557 }
558
559 return errorCode;
560
561 }
562
563
564 /*----------------------------------------------------------------------------
565 ; FUNCTION CODE
566 ----------------------------------------------------------------------------*/
567
fillDataBuf(tmp3Bits * pMainData,uint32 val)568 __inline void fillDataBuf(tmp3Bits *pMainData,
569 uint32 val) /* val to write into the buffer */
570 {
571 pMainData->pBuffer[module(pMainData->offset++, BUFSIZE)] = (uint8)val;
572 }
573
574
fillMainDataBuf(void * pMem,int32 temp)575 void fillMainDataBuf(void *pMem, int32 temp)
576 {
577 tmp3dec_file *pVars = (tmp3dec_file *)pMem;
578
579
580 int32 offset = (pVars->inputStream.usedBits) >> INBUF_ARRAY_INDEX_SHIFT;
581
582 /*
583 * Check if input circular buffer boundaries need to be enforced
584 */
585 if ((offset + temp) < BUFSIZE)
586 {
587 uint8 * ptr = pVars->inputStream.pBuffer + offset;
588
589 offset = pVars->mainDataStream.offset;
590
591 /*
592 * Check if main data circular buffer boundaries need to be enforced
593 */
594 if ((offset + temp) < BUFSIZE)
595 {
596 pv_memcpy((pVars->mainDataStream.pBuffer + offset), ptr, temp*sizeof(uint8));
597 pVars->mainDataStream.offset += temp;
598 }
599 else
600 {
601 for (int32 nBytes = temp; nBytes != 0; nBytes--) /* read main data. */
602 {
603 int32 tmp = *(ptr++);
604 fillDataBuf(&pVars->mainDataStream, tmp);
605 }
606
607 /* adjust circular buffer counter */
608 pVars->mainDataStream.offset = module(pVars->mainDataStream.offset, BUFSIZE);
609 }
610 }
611 else
612 {
613 for (int32 nBytes = temp; nBytes != 0; nBytes--) /* read main data. */
614 {
615 fillDataBuf(&pVars->mainDataStream, *(pVars->inputStream.pBuffer + module(offset++ , BUFSIZE)));
616 }
617 }
618
619
620 pVars->inputStream.usedBits += (temp) << INBUF_ARRAY_INDEX_SHIFT;
621 }
622
623
624
625
626 /*----------------------------------------------------------------------------
627 ; FUNCTION CODE
628 ----------------------------------------------------------------------------*/
629
pvmp3_decoderMemRequirements(void)630 uint32 pvmp3_decoderMemRequirements(void)
631 {
632 uint32 size;
633
634 size = (uint32) sizeof(tmp3dec_file);
635 return (size);
636 }
637
638
639
640 /*----------------------------------------------------------------------------
641 ; FUNCTION CODE
642 ----------------------------------------------------------------------------*/
643
644 #include "pvmp3_decode_huff_cw.h"
645
pvmp3_InitDecoder(tPVMP3DecoderExternal * pExt,void * pMem)646 void pvmp3_InitDecoder(tPVMP3DecoderExternal *pExt,
647 void *pMem)
648 {
649
650 tmp3dec_file *pVars;
651 huffcodetab *pHuff;
652
653 pVars = (tmp3dec_file *)pMem;
654 memset(pVars, 0, sizeof(*pVars));
655
656 pExt->totalNumberOfBitsUsed = 0;
657 pExt->inputBufferCurrentLength = 0;
658 pExt->inputBufferUsedLength = 0;
659
660 pVars->inputStream.pBuffer = pExt->pInputBuffer;
661
662 /*
663 * Initialize huffman decoding table
664 */
665
666 pHuff = pVars->ht;
667 pHuff[0].linbits = 0;
668 pHuff[0].pdec_huff_tab = pvmp3_decode_huff_cw_tab0;
669 pHuff[1].linbits = 0;
670 pHuff[1].pdec_huff_tab = pvmp3_decode_huff_cw_tab1;
671 pHuff[2].linbits = 0;
672 pHuff[2].pdec_huff_tab = pvmp3_decode_huff_cw_tab2;
673 pHuff[3].linbits = 0;
674 pHuff[3].pdec_huff_tab = pvmp3_decode_huff_cw_tab3;
675 pHuff[4].linbits = 0;
676 pHuff[4].pdec_huff_tab = pvmp3_decode_huff_cw_tab0; /* tbl 4 is not used */
677 pHuff[5].linbits = 4;
678 pHuff[5].pdec_huff_tab = pvmp3_decode_huff_cw_tab5;
679 pHuff[6].linbits = 0;
680 pHuff[6].pdec_huff_tab = pvmp3_decode_huff_cw_tab6;
681 pHuff[7].linbits = 0;
682 pHuff[7].pdec_huff_tab = pvmp3_decode_huff_cw_tab7;
683 pHuff[8].linbits = 0;
684 pHuff[8].pdec_huff_tab = pvmp3_decode_huff_cw_tab8;
685 pHuff[9].linbits = 0;
686 pHuff[9].pdec_huff_tab = pvmp3_decode_huff_cw_tab9;
687 pHuff[10].linbits = 0;
688 pHuff[10].pdec_huff_tab = pvmp3_decode_huff_cw_tab10;
689 pHuff[11].linbits = 0;
690 pHuff[11].pdec_huff_tab = pvmp3_decode_huff_cw_tab11;
691 pHuff[12].linbits = 0;
692 pHuff[12].pdec_huff_tab = pvmp3_decode_huff_cw_tab12;
693 pHuff[13].linbits = 0;
694 pHuff[13].pdec_huff_tab = pvmp3_decode_huff_cw_tab13;
695 pHuff[14].linbits = 0;
696 pHuff[14].pdec_huff_tab = pvmp3_decode_huff_cw_tab0; /* tbl 14 is not used */
697 pHuff[15].linbits = 0;
698 pHuff[15].pdec_huff_tab = pvmp3_decode_huff_cw_tab15;
699 pHuff[16].linbits = 1;
700 pHuff[16].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
701 pHuff[17].linbits = 2;
702 pHuff[17].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
703 pHuff[18].linbits = 3;
704 pHuff[18].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
705 pHuff[19].linbits = 4;
706 pHuff[19].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
707 pHuff[20].linbits = 6;
708 pHuff[20].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
709 pHuff[21].linbits = 8;
710 pHuff[21].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
711 pHuff[22].linbits = 10;
712 pHuff[22].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
713 pHuff[23].linbits = 13;
714 pHuff[23].pdec_huff_tab = pvmp3_decode_huff_cw_tab16;
715 pHuff[24].linbits = 4;
716 pHuff[24].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
717 pHuff[25].linbits = 5;
718 pHuff[25].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
719 pHuff[26].linbits = 6;
720 pHuff[26].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
721 pHuff[27].linbits = 7;
722 pHuff[27].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
723 pHuff[28].linbits = 8;
724 pHuff[28].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
725 pHuff[29].linbits = 9;
726 pHuff[29].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
727 pHuff[30].linbits = 11;
728 pHuff[30].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
729 pHuff[31].linbits = 13;
730 pHuff[31].pdec_huff_tab = pvmp3_decode_huff_cw_tab24;
731 pHuff[32].linbits = 0;
732 pHuff[32].pdec_huff_tab = pvmp3_decode_huff_cw_tab32;
733 pHuff[33].linbits = 0;
734 pHuff[33].pdec_huff_tab = pvmp3_decode_huff_cw_tab33;
735
736 /*
737 * Initialize polysynthesis circular buffer mechanism
738 */
739 /* clear buffers */
740
741 pvmp3_resetDecoder(pMem);
742
743 }
744
745
746 /*----------------------------------------------------------------------------
747 ; FUNCTION CODE
748 ----------------------------------------------------------------------------*/
749
750
pvmp3_resetDecoder(void * pMem)751 void pvmp3_resetDecoder(void *pMem)
752 {
753
754 tmp3dec_file *pVars;
755 tmp3dec_chan *pChVars[CHAN];
756
757 pVars = (tmp3dec_file *)pMem;
758 pChVars[ LEFT] = &pVars->perChan[ LEFT];
759 pChVars[RIGHT] = &pVars->perChan[RIGHT];
760
761 pVars->frame_start = 0;
762
763 pVars->mainDataStream.offset = 0;
764
765 pVars->mainDataStream.pBuffer = pVars->mainDataBuffer;
766 pVars->mainDataStream.usedBits = 0;
767
768
769 pVars->inputStream.usedBits = 0; // in bits
770
771
772 pChVars[ LEFT]->used_freq_lines = 575;
773 pChVars[RIGHT]->used_freq_lines = 575;
774
775
776 /*
777 * Initialize polysynthesis circular buffer mechanism
778 */
779
780 pv_memset((void*)&pChVars[ LEFT]->circ_buffer[576],
781 0,
782 480*sizeof(pChVars[ LEFT]->circ_buffer[0]));
783 pv_memset((void*)&pChVars[RIGHT]->circ_buffer[576],
784 0,
785 480*sizeof(pChVars[RIGHT]->circ_buffer[0]));
786
787
788 pv_memset((void*)pChVars[ LEFT]->overlap,
789 0,
790 SUBBANDS_NUMBER*FILTERBANK_BANDS*sizeof(pChVars[ LEFT]->overlap[0]));
791
792
793 pv_memset((void*)pChVars[ RIGHT]->overlap,
794 0,
795 SUBBANDS_NUMBER*FILTERBANK_BANDS*sizeof(pChVars[ RIGHT]->overlap[0]));
796
797
798
799
800
801 /*
802 * Clear all the structures
803 */
804
805
806 pv_memset((void*)&pVars->scaleFactors[RIGHT],
807 0,
808 sizeof(mp3ScaleFactors));
809
810 pv_memset((void*)&pVars->scaleFactors[LEFT],
811 0,
812 sizeof(mp3ScaleFactors));
813
814 pv_memset((void*)&pVars->sideInfo,
815 0,
816 sizeof(mp3SideInfo));
817
818 pv_memset((void*)&pVars->sideInfo,
819 0,
820 sizeof(mp3SideInfo));
821
822 }
823