1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
19 ------------------------------------------------------------------------------
24 Filename: pvmp3_huffman_decoding.cpp
27 pvmp3_huffman_quad_decoding
28 pvmp3_huffman_pair_decoding
29 pvmp3_huffman_pair_decoding_linbits
33 ------------------------------------------------------------------------------
39 ------------------------------------------------------------------------------
40 INPUT AND OUTPUT DEFINITIONS
43 struct huffcodetab *h, pointer to huffman code record
44 int32 *x, returns decoded x value
45 int32 *y, returns decoded y value
46 int32 *v, returns decoded v value (only in quad function)
47 int32 *w, returns decoded w value (only in quad function)
48 tbits *pMainData bit stream
53 ------------------------------------------------------------------------------
56 These functions are used to decode huffman codewords from the input
57 bitstream using combined binary search and look-up table approach.
59 ------------------------------------------------------------------------------
63 ------------------------------------------------------------------------------
65 [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
66 ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
69 ------------------------------------------------------------------------------
72 ------------------------------------------------------------------------------
76 /*----------------------------------------------------------------------------
78 ----------------------------------------------------------------------------*/
79 #include "pvmp3_dec_defs.h"
80 #include "pv_mp3_huffman.h"
81 #include "pvmp3_getbits.h"
84 /*----------------------------------------------------------------------------
86 ; Define module specific macros here
87 ----------------------------------------------------------------------------*/
90 /*----------------------------------------------------------------------------
92 ; Include all pre-processor statements here. Include conditional
93 ; compile variables also.
94 ----------------------------------------------------------------------------*/
97 /*----------------------------------------------------------------------------
98 ; LOCAL FUNCTION DEFINITIONS
99 ; Function Prototype declaration
100 ----------------------------------------------------------------------------*/
102 /*----------------------------------------------------------------------------
103 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
104 ; Variable declaration - defined here and used outside this module
105 ----------------------------------------------------------------------------*/
107 /*----------------------------------------------------------------------------
108 ; EXTERNAL FUNCTION REFERENCES
109 ; Declare functions defined elsewhere and referenced in this module
110 ----------------------------------------------------------------------------*/
112 /*----------------------------------------------------------------------------
113 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
114 ; Declare variables used in this module but defined elsewhere
115 ----------------------------------------------------------------------------*/
117 /*----------------------------------------------------------------------------
119 ----------------------------------------------------------------------------*/
122 void pvmp3_huffman_quad_decoding(struct huffcodetab *h,
132 y = (*h->pdec_huff_tab)(pMainData);
141 if (get1bit(pMainData))
149 if (get1bit(pMainData))
157 if (get1bit(pMainData))
165 if (get1bit(pMainData))
189 void pvmp3_huffman_pair_decoding(struct huffcodetab *h, /* pointer to huffman code record */
193 /* Lookup in Huffman table. */
197 uint16 cw = (*h->pdec_huff_tab)(pMainData);
199 /* Process sign and escape encodings for dual tables. */
208 if (get1bit(pMainData))
213 if (y && get1bit(pMainData))
222 if (get1bit(pMainData))
244 void pvmp3_huffman_pair_decoding_linbits(struct huffcodetab *h, /* pointer to huffman code record */
252 /* Lookup in Huffman table. */
255 cw = (*h->pdec_huff_tab)(pMainData);
258 /* Process sign and escape encodings for dual tables. */
263 int32 tmp = getUpTo17bits(pMainData, (h->linbits + 1));
272 if (get1bit(pMainData))
281 int32 tmp = getUpTo17bits(pMainData, (h->linbits + 1));
290 if (get1bit(pMainData))