Home | History | Annotate | Download | only in aacdec
      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  Filename: sbr_get_noise_floor_data.c
     21 
     22 
     23 ------------------------------------------------------------------------------
     24  REVISION HISTORY
     25 
     26 
     27  Who:                                   Date: MM/DD/YYYY
     28  Description:
     29 
     30 ------------------------------------------------------------------------------
     31  INPUT AND OUTPUT DEFINITIONS
     32 
     33  Arguments:     h_frame_data - handle to struct SBR_FRAME_DATA
     34                 hBitBuf      - handle to struct BIT_BUF
     35 
     36  Return:        void
     37 
     38 
     39 ------------------------------------------------------------------------------
     40  FUNCTION DESCRIPTION
     41 
     42     Reads noise-floor-level data from bitstream
     43 
     44 ------------------------------------------------------------------------------
     45  REQUIREMENTS
     46 
     47 
     48 ------------------------------------------------------------------------------
     49  REFERENCES
     50 
     51 SC 29 Software Copyright Licencing Disclaimer:
     52 
     53 This software module was originally developed by
     54   Coding Technologies
     55 
     56 and edited by
     57   -
     58 
     59 in the course of development of the ISO/IEC 13818-7 and ISO/IEC 14496-3
     60 standards for reference purposes and its performance may not have been
     61 optimized. This software module is an implementation of one or more tools as
     62 specified by the ISO/IEC 13818-7 and ISO/IEC 14496-3 standards.
     63 ISO/IEC gives users free license to this software module or modifications
     64 thereof for use in products claiming conformance to audiovisual and
     65 image-coding related ITU Recommendations and/or ISO/IEC International
     66 Standards. ISO/IEC gives users the same free license to this software module or
     67 modifications thereof for research purposes and further ISO/IEC standardisation.
     68 Those intending to use this software module in products are advised that its
     69 use may infringe existing patents. ISO/IEC have no liability for use of this
     70 software module or modifications thereof. Copyright is not released for
     71 products that do not conform to audiovisual and image-coding related ITU
     72 Recommendations and/or ISO/IEC International Standards.
     73 The original developer retains full right to modify and use the code for its
     74 own purpose, assign or donate the code to a third party and to inhibit third
     75 parties from using the code for products that do not conform to audiovisual and
     76 image-coding related ITU Recommendations and/or ISO/IEC International Standards.
     77 This copyright notice must be included in all copies or derivative works.
     78 Copyright (c) ISO/IEC 2002.
     79 
     80 ------------------------------------------------------------------------------
     81  PSEUDO-CODE
     82 
     83 ------------------------------------------------------------------------------
     84 */
     85 
     86 
     87 /*----------------------------------------------------------------------------
     88 ; INCLUDES
     89 ----------------------------------------------------------------------------*/
     90 
     91 #ifdef AAC_PLUS
     92 
     93 
     94 #include    "sbr_get_noise_floor_data.h"
     95 #include    "e_coupling_mode.h"
     96 #include    "buf_getbits.h"
     97 #include    "sbr_code_book_envlevel.h"
     98 #include    "s_huffman.h"
     99 #include    "sbr_decode_huff_cw.h"
    100 
    101 /*----------------------------------------------------------------------------
    102 ; MACROS
    103 ; Define module specific macros here
    104 ----------------------------------------------------------------------------*/
    105 
    106 
    107 /*----------------------------------------------------------------------------
    108 ; DEFINES
    109 ; Include all pre-processor statements here. Include conditional
    110 ; compile variables also.
    111 ----------------------------------------------------------------------------*/
    112 
    113 /*----------------------------------------------------------------------------
    114 ; LOCAL FUNCTION DEFINITIONS
    115 ; Function Prototype declaration
    116 ----------------------------------------------------------------------------*/
    117 
    118 /*----------------------------------------------------------------------------
    119 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    120 ; Variable declaration - defined here and used outside this module
    121 ----------------------------------------------------------------------------*/
    122 
    123 /*----------------------------------------------------------------------------
    124 ; EXTERNAL FUNCTION REFERENCES
    125 ; Declare functions defined elsewhere and referenced in this module
    126 ----------------------------------------------------------------------------*/
    127 
    128 /*----------------------------------------------------------------------------
    129 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    130 ; Declare variables used in this module but defined elsewhere
    131 ----------------------------------------------------------------------------*/
    132 
    133 /*----------------------------------------------------------------------------
    134 ; FUNCTION CODE
    135 ----------------------------------------------------------------------------*/
    136 
    137 void sbr_get_noise_floor_data(SBR_FRAME_DATA * h_frame_data,
    138                               BIT_BUFFER * hBitBuf)
    139 {
    140     Int32 i;
    141     Int32 j;
    142     Int32 k;
    143     Int32 tmp;
    144     Int32 delta;
    145     Int32 noNoiseBands = h_frame_data->nNfb;
    146     Int32 envDataTableCompFactor;
    147 
    148     COUPLING_MODE coupling = h_frame_data->coupling;
    149 
    150     SbrHuffman hcb_noiseF;
    151     SbrHuffman hcb_noise;
    152 
    153 
    154     if (coupling == COUPLING_BAL)
    155     {
    156         hcb_noise  = bookSbrNoiseBalance11T;
    157         hcb_noiseF = bookSbrEnvBalance11F;  /* "bookSbrNoiseBalance11F" */
    158         envDataTableCompFactor = 1;
    159     }
    160     else
    161     {
    162         hcb_noise  = bookSbrNoiseLevel11T;
    163         hcb_noiseF = bookSbrEnvLevel11F;  /* "bookSbrNoiseLevel11F" */
    164         envDataTableCompFactor = 0;
    165     }
    166 
    167     /*
    168      *  Calculate number of values alltogether
    169      */
    170     h_frame_data->nNoiseFactors = h_frame_data->frameInfo[((h_frame_data->frameInfo[0]) << 1) + 3] * noNoiseBands;
    171 
    172 
    173     for (i = 0; i < h_frame_data->nNoiseFloorEnvelopes; i++)
    174     {
    175         k = i * noNoiseBands;
    176         if (h_frame_data->domain_vec2[i] == FREQ)
    177         {
    178             if (coupling == COUPLING_BAL)
    179             {
    180                 tmp = buf_getbits(hBitBuf, SI_SBR_START_NOISE_BITS_BALANCE_AMP_RES_3_0) << 1;  /*  max. 62  */
    181                 h_frame_data->sbrNoiseFloorLevel_man[k] = tmp;
    182                 h_frame_data->sbrNoiseFloorLevel_exp[k] =   0;
    183             }
    184             else
    185             {
    186                 tmp = buf_getbits(hBitBuf, SI_SBR_START_NOISE_BITS_AMP_RES_3_0);  /*  max. 31  */
    187                 h_frame_data->sbrNoiseFloorLevel_man[k] = tmp;
    188                 h_frame_data->sbrNoiseFloorLevel_exp[k] =   0;
    189             }
    190 
    191             for (j = 1; j < noNoiseBands; j++)
    192             {
    193                 delta = sbr_decode_huff_cw(hcb_noiseF, hBitBuf); /*
    194                                                                   *  -31 < delta < 31
    195                                                                   *  -24 < delta < 24   COUPLING_BAL (incl. <<1)
    196                                                                   */
    197                 h_frame_data->sbrNoiseFloorLevel_man[k+j] = delta << envDataTableCompFactor;
    198                 h_frame_data->sbrNoiseFloorLevel_exp[k+j] =   0;
    199             }
    200         }
    201         else
    202         {
    203             for (j = 0; j < noNoiseBands; j++)
    204             {
    205                 delta = sbr_decode_huff_cw(hcb_noise, hBitBuf);  /*
    206                                                                   *  -31 < delta < 31
    207                                                                   *  -24 < delta < 24   COUPLING_BAL (incl. <<1)
    208                                                                   */
    209                 h_frame_data->sbrNoiseFloorLevel_man[k+j] = delta << envDataTableCompFactor;
    210                 h_frame_data->sbrNoiseFloorLevel_exp[k+j] =   0;
    211             }
    212         }
    213     }
    214 }
    215 
    216 #endif
    217 
    218 
    219