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_header_data.c
     21 
     22 ------------------------------------------------------------------------------
     23  REVISION HISTORY
     24 
     25 
     26  Who:                                   Date: MM/DD/YYYY
     27  Description:
     28 
     29 ------------------------------------------------------------------------------
     30  INPUT AND OUTPUT DEFINITIONS
     31 
     32  Arguments:     h_sbr_header - handle to struct SBR_HEADER_DATA
     33                 hBitBuf      - handle to struct BIT_BUFFER
     34                 id_sbr       - SBR_ELEMENT_ID
     35 
     36  Return:        error status - 0 if ok
     37 
     38 
     39 ------------------------------------------------------------------------------
     40  FUNCTION DESCRIPTION
     41 
     42     Reads header 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_header_data.h"
     95 #include    "sbr_constants.h"
     96 #include    "buf_getbits.h"
     97 #include    "aac_mem_funcs.h"
     98 
     99 /*----------------------------------------------------------------------------
    100 ; MACROS
    101 ; Define module specific macros here
    102 ----------------------------------------------------------------------------*/
    103 
    104 
    105 /*----------------------------------------------------------------------------
    106 ; DEFINES
    107 ; Include all pre-processor statements here. Include conditional
    108 ; compile variables also.
    109 ----------------------------------------------------------------------------*/
    110 
    111 /*----------------------------------------------------------------------------
    112 ; LOCAL FUNCTION DEFINITIONS
    113 ; Function Prototype declaration
    114 ----------------------------------------------------------------------------*/
    115 
    116 /*----------------------------------------------------------------------------
    117 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    118 ; Variable declaration - defined here and used outside this module
    119 ----------------------------------------------------------------------------*/
    120 
    121 /*----------------------------------------------------------------------------
    122 ; EXTERNAL FUNCTION REFERENCES
    123 ; Declare functions defined elsewhere and referenced in this module
    124 ----------------------------------------------------------------------------*/
    125 
    126 /*----------------------------------------------------------------------------
    127 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    128 ; Declare variables used in this module but defined elsewhere
    129 ----------------------------------------------------------------------------*/
    130 
    131 /*----------------------------------------------------------------------------
    132 ; FUNCTION CODE
    133 ----------------------------------------------------------------------------*/
    134 
    135 SBR_HEADER_STATUS sbr_get_header_data(SBR_HEADER_DATA   * h_sbr_header,
    136                                       BIT_BUFFER          * hBitBuf,
    137                                       SBR_SYNC_STATE     syncState)
    138 {
    139     SBR_HEADER_DATA lastHeader;
    140     Int32 headerExtra1, headerExtra2;
    141 
    142 
    143     /* Copy header to temporary header */
    144     if (syncState == SBR_ACTIVE)
    145     {
    146         pv_memcpy(&lastHeader, h_sbr_header, sizeof(SBR_HEADER_DATA));
    147     }
    148     else
    149     {
    150         pv_memset((void *)&lastHeader, 0, sizeof(SBR_HEADER_DATA));
    151     }
    152 
    153 
    154     /* Read new header from bitstream */
    155     h_sbr_header->ampResolution   = buf_getbits(hBitBuf, SI_SBR_AMP_RES_BITS);
    156     h_sbr_header->startFreq       = buf_getbits(hBitBuf, SI_SBR_START_FREQ_BITS);
    157     h_sbr_header->stopFreq        = buf_getbits(hBitBuf, SI_SBR_STOP_FREQ_BITS);
    158     h_sbr_header->xover_band      = buf_getbits(hBitBuf, SI_SBR_XOVER_BAND_BITS);
    159 
    160     buf_getbits(hBitBuf, SI_SBR_RESERVED_BITS_HDR);
    161 
    162     headerExtra1    = buf_getbits(hBitBuf, SI_SBR_HEADER_EXTRA_1_BITS);
    163     headerExtra2    = buf_getbits(hBitBuf, SI_SBR_HEADER_EXTRA_2_BITS);
    164 
    165     /* handle extra header information */
    166     if (headerExtra1)
    167     {
    168         h_sbr_header->freqScale   = buf_getbits(hBitBuf, SI_SBR_FREQ_SCALE_BITS);
    169         h_sbr_header->alterScale  = buf_getbits(hBitBuf, SI_SBR_ALTER_SCALE_BITS);
    170         h_sbr_header->noise_bands = buf_getbits(hBitBuf, SI_SBR_NOISE_BANDS_BITS);
    171     }
    172     else
    173     { /* Set default values.*/
    174         h_sbr_header->freqScale   = SBR_FREQ_SCALE_DEFAULT;
    175         h_sbr_header->alterScale  = SBR_ALTER_SCALE_DEFAULT;
    176         h_sbr_header->noise_bands = SBR_NOISE_BANDS_DEFAULT;
    177     }
    178 
    179 
    180     if (headerExtra2)
    181     {
    182         h_sbr_header->limiterBands    = buf_getbits(hBitBuf, SI_SBR_LIMITER_BANDS_BITS);
    183         h_sbr_header->limiterGains    = buf_getbits(hBitBuf, SI_SBR_LIMITER_GAINS_BITS);
    184         h_sbr_header->interpolFreq    = buf_getbits(hBitBuf, SI_SBR_INTERPOL_FREQ_BITS);
    185         h_sbr_header->smoothingLength = buf_getbits(hBitBuf, SI_SBR_SMOOTHING_LENGTH_BITS);
    186     }
    187     else
    188     { /* Set default values.*/
    189         h_sbr_header->limiterBands    = SBR_LIMITER_BANDS_DEFAULT;
    190         h_sbr_header->limiterGains    = SBR_LIMITER_GAINS_DEFAULT;
    191         h_sbr_header->interpolFreq    = SBR_INTERPOL_FREQ_DEFAULT;
    192         h_sbr_header->smoothingLength = SBR_SMOOTHING_LENGTH_DEFAULT;
    193     }
    194 
    195     if (syncState == SBR_ACTIVE)
    196     {
    197         h_sbr_header->status = HEADER_OK;
    198 
    199         /* look for new settings */
    200         if (lastHeader.startFreq   != h_sbr_header->startFreq   ||
    201                 lastHeader.stopFreq    != h_sbr_header->stopFreq    ||
    202                 lastHeader.xover_band  != h_sbr_header->xover_band  ||
    203                 lastHeader.freqScale   != h_sbr_header->freqScale   ||
    204                 lastHeader.alterScale  != h_sbr_header->alterScale  ||
    205                 lastHeader.noise_bands != h_sbr_header->noise_bands)
    206         {
    207             h_sbr_header->status = HEADER_RESET;
    208         }
    209     }
    210     else
    211     {
    212         h_sbr_header->status = HEADER_RESET;
    213     }
    214 
    215     return h_sbr_header->status;
    216 }
    217 
    218 #endif
    219 
    220 
    221 
    222