123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- /* ------------------------------------------------------------------
- * Copyright (C) 1998-2009 PacketVideo
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
- * express or implied.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- * -------------------------------------------------------------------
- */
- /*
- ------------------------------------------------------------------------------
- PacketVideo Corp.
- MP3 Decoder Library
- Filename: pvmp3_huffman_decoding.cpp
- Funtions:
- pvmp3_huffman_quad_decoding
- pvmp3_huffman_pair_decoding
- pvmp3_huffman_pair_decoding_linbits
- Date: 09/21/2007
- ------------------------------------------------------------------------------
- REVISION HISTORY
- Description:
- ------------------------------------------------------------------------------
- INPUT AND OUTPUT DEFINITIONS
- Inputs:
- struct huffcodetab *h, pointer to huffman code record
- int32 *x, returns decoded x value
- int32 *y, returns decoded y value
- int32 *v, returns decoded v value (only in quad function)
- int32 *w, returns decoded w value (only in quad function)
- tbits *pMainData bit stream
- Outputs:
- ------------------------------------------------------------------------------
- FUNCTION DESCRIPTION
- These functions are used to decode huffman codewords from the input
- bitstream using combined binary search and look-up table approach.
- ------------------------------------------------------------------------------
- REQUIREMENTS
- ------------------------------------------------------------------------------
- REFERENCES
- [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
- ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
- ------------------------------------------------------------------------------
- PSEUDO-CODE
- ------------------------------------------------------------------------------
- */
- /*----------------------------------------------------------------------------
- ; INCLUDES
- ----------------------------------------------------------------------------*/
- #include "pvmp3_dec_defs.h"
- #include "pv_mp3_huffman.h"
- #include "pvmp3_getbits.h"
- /*----------------------------------------------------------------------------
- ; MACROS
- ; Define module specific macros here
- ----------------------------------------------------------------------------*/
- /*----------------------------------------------------------------------------
- ; DEFINES
- ; Include all pre-processor statements here. Include conditional
- ; compile variables also.
- ----------------------------------------------------------------------------*/
- /*----------------------------------------------------------------------------
- ; LOCAL FUNCTION DEFINITIONS
- ; Function Prototype declaration
- ----------------------------------------------------------------------------*/
- /*----------------------------------------------------------------------------
- ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
- ; Variable declaration - defined here and used outside this module
- ----------------------------------------------------------------------------*/
- /*----------------------------------------------------------------------------
- ; EXTERNAL FUNCTION REFERENCES
- ; Declare functions defined elsewhere and referenced in this module
- ----------------------------------------------------------------------------*/
- /*----------------------------------------------------------------------------
- ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
- ; Declare variables used in this module but defined elsewhere
- ----------------------------------------------------------------------------*/
- /*----------------------------------------------------------------------------
- ; FUNCTION CODE
- ----------------------------------------------------------------------------*/
- void pvmp3_huffman_quad_decoding(struct huffcodetab *h,
- int32 *is,
- tmp3Bits *pMainData)
- {
- int32 x;
- int32 y;
- int32 v;
- int32 w;
- y = (*h->pdec_huff_tab)(pMainData);
- if (y)
- {
- v = (y >> 3);
- if (v)
- {
- if (get1bit(pMainData))
- {
- v = -v;
- }
- }
- w = (y >> 2) & 1;
- if (w)
- {
- if (get1bit(pMainData))
- {
- w = -w;
- }
- }
- x = (y >> 1) & 1;
- if (x)
- {
- if (get1bit(pMainData))
- {
- x = -x;
- }
- }
- y = y & 1;
- if (y)
- {
- if (get1bit(pMainData))
- {
- y = -y;
- }
- }
- }
- else
- {
- v = 0;
- w = 0;
- x = 0;
- }
- *is = v;
- *(is + 1) = w;
- *(is + 2) = x;
- *(is + 3) = y;
- }
- void pvmp3_huffman_pair_decoding(struct huffcodetab *h, /* pointer to huffman code record */
- int32 *is,
- tmp3Bits *pMainData)
- {
- /* Lookup in Huffman table. */
- int32 x;
- int32 y;
- uint16 cw = (*h->pdec_huff_tab)(pMainData);
- /* Process sign and escape encodings for dual tables. */
- if (cw)
- {
- x = cw >> 4;
- if (x)
- {
- if (get1bit(pMainData))
- {
- x = -x;
- }
- y = cw & 0xf;
- if (y && get1bit(pMainData))
- {
- y = -y;
- }
- }
- else
- {
- y = cw & 0xf;
- if (get1bit(pMainData))
- {
- y = -y;
- }
- }
- *is = x;
- *(is + 1) = y;
- }
- else
- {
- *is = 0;
- *(is + 1) = 0;
- }
- }
- void pvmp3_huffman_pair_decoding_linbits(struct huffcodetab *h, /* pointer to huffman code record */
- int32 *is,
- tmp3Bits *pMainData)
- {
- int32 x;
- int32 y;
- uint16 cw;
- /* Lookup in Huffman table. */
- cw = (*h->pdec_huff_tab)(pMainData);
- x = cw >> 4;
- /* Process sign and escape encodings for dual tables. */
- if (15 == (uint32)x)
- {
- int32 tmp = getUpTo17bits(pMainData, (h->linbits + 1));
- x += tmp >> 1;
- if (tmp&1)
- {
- x = -x;
- }
- }
- else if (x)
- {
- if (get1bit(pMainData))
- {
- x = -x;
- }
- }
- y = cw & 0xf;
- if (15 == (uint32)y)
- {
- int32 tmp = getUpTo17bits(pMainData, (h->linbits + 1));
- y += tmp >> 1;
- if (tmp&1)
- {
- y = -y;
- }
- }
- else if (y)
- {
- if (get1bit(pMainData))
- {
- y = -y;
- }
- }
- *is = x;
- *(is + 1) = y;
- }
|