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_cpe.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:     hFrameDataLeft  - handle to struct SBR_FRAME_DATA for first channel
     33                 hFrameDataRight - handle to struct SBR_FRAME_DATA for first channel
     34                 hBitBuf         - handle to struct BIT_BUF
     35 
     36  Return:        SbrFrameOK
     37 
     38 
     39 ------------------------------------------------------------------------------
     40  FUNCTION DESCRIPTION
     41 
     42 
     43 ------------------------------------------------------------------------------
     44  REQUIREMENTS
     45 
     46 
     47 ------------------------------------------------------------------------------
     48  REFERENCES
     49 
     50 SC 29 Software Copyright Licencing Disclaimer:
     51 
     52 This software module was originally developed by
     53   Coding Technologies
     54 
     55 and edited by
     56   -
     57 
     58 in the course of development of the ISO/IEC 13818-7 and ISO/IEC 14496-3
     59 standards for reference purposes and its performance may not have been
     60 optimized. This software module is an implementation of one or more tools as
     61 specified by the ISO/IEC 13818-7 and ISO/IEC 14496-3 standards.
     62 ISO/IEC gives users free license to this software module or modifications
     63 thereof for use in products claiming conformance to audiovisual and
     64 image-coding related ITU Recommendations and/or ISO/IEC International
     65 Standards. ISO/IEC gives users the same free license to this software module or
     66 modifications thereof for research purposes and further ISO/IEC standardisation.
     67 Those intending to use this software module in products are advised that its
     68 use may infringe existing patents. ISO/IEC have no liability for use of this
     69 software module or modifications thereof. Copyright is not released for
     70 products that do not conform to audiovisual and image-coding related ITU
     71 Recommendations and/or ISO/IEC International Standards.
     72 The original developer retains full right to modify and use the code for its
     73 own purpose, assign or donate the code to a third party and to inhibit third
     74 parties from using the code for products that do not conform to audiovisual and
     75 image-coding related ITU Recommendations and/or ISO/IEC International Standards.
     76 This copyright notice must be included in all copies or derivative works.
     77 Copyright (c) ISO/IEC 2002.
     78 
     79 ------------------------------------------------------------------------------
     80  PSEUDO-CODE
     81 
     82 ------------------------------------------------------------------------------
     83 */
     84 
     85 
     86 /*----------------------------------------------------------------------------
     87 ; INCLUDES
     88 ----------------------------------------------------------------------------*/
     89 
     90 #ifdef AAC_PLUS
     91 
     92 
     93 #include    "sbr_get_cpe.h"
     94 #include    "buf_getbits.h"
     95 #include    "extractframeinfo.h"
     96 #include    "sbr_get_dir_control_data.h"
     97 #include    "sbr_get_envelope.h"
     98 #include    "sbr_get_noise_floor_data.h"
     99 #include    "sbr_get_additional_data.h"
    100 #include    "sbr_extract_extended_data.h"
    101 #include    "aac_mem_funcs.h"
    102 
    103 /*----------------------------------------------------------------------------
    104 ; MACROS
    105 ; Define module specific macros here
    106 ----------------------------------------------------------------------------*/
    107 
    108 
    109 /*----------------------------------------------------------------------------
    110 ; DEFINES
    111 ; Include all pre-processor statements here. Include conditional
    112 ; compile variables also.
    113 ----------------------------------------------------------------------------*/
    114 
    115 /*----------------------------------------------------------------------------
    116 ; LOCAL FUNCTION DEFINITIONS
    117 ; Function Prototype declaration
    118 ----------------------------------------------------------------------------*/
    119 
    120 /*----------------------------------------------------------------------------
    121 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    122 ; Variable declaration - defined here and used outside this module
    123 ----------------------------------------------------------------------------*/
    124 
    125 /*----------------------------------------------------------------------------
    126 ; EXTERNAL FUNCTION REFERENCES
    127 ; Declare functions defined elsewhere and referenced in this module
    128 ----------------------------------------------------------------------------*/
    129 
    130 /*----------------------------------------------------------------------------
    131 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    132 ; Declare variables used in this module but defined elsewhere
    133 ----------------------------------------------------------------------------*/
    134 
    135 /*----------------------------------------------------------------------------
    136 ; FUNCTION CODE
    137 ----------------------------------------------------------------------------*/
    138 
    139 
    140 SBR_ERROR sbr_get_cpe(SBR_FRAME_DATA * hFrameDataLeft,
    141                       SBR_FRAME_DATA * hFrameDataRight,
    142                       BIT_BUFFER  * hBitBuf)
    143 {
    144     Int32 i;
    145     Int32 bits;
    146     SBR_ERROR err =  SBRDEC_OK;
    147 
    148     /* reserved bits */
    149     bits = buf_getbits(hBitBuf, SI_SBR_RESERVED_PRESENT);
    150 
    151     if (bits)
    152     {
    153         buf_getbits(hBitBuf, SI_SBR_RESERVED_BITS_DATA);
    154         buf_getbits(hBitBuf, SI_SBR_RESERVED_BITS_DATA);
    155     }
    156 
    157     /* Read coupling flag */
    158     bits = buf_getbits(hBitBuf, SI_SBR_COUPLING_BITS);
    159 
    160     if (bits)
    161     {
    162         hFrameDataLeft->coupling = COUPLING_LEVEL;
    163         hFrameDataRight->coupling = COUPLING_BAL;
    164     }
    165     else
    166     {
    167         hFrameDataLeft->coupling = COUPLING_OFF;
    168         hFrameDataRight->coupling = COUPLING_OFF;
    169     }
    170 
    171 
    172     err = extractFrameInfo(hBitBuf, hFrameDataLeft);
    173 
    174     if (err != SBRDEC_OK)
    175     {
    176         return err;
    177     }
    178 
    179     if (hFrameDataLeft->coupling)
    180     {
    181 
    182         pv_memcpy(hFrameDataRight->frameInfo,
    183                   hFrameDataLeft->frameInfo,
    184                   LENGTH_FRAME_INFO * sizeof(Int32));
    185 
    186         hFrameDataRight->nNoiseFloorEnvelopes = hFrameDataLeft->nNoiseFloorEnvelopes;
    187         hFrameDataRight->frameClass = hFrameDataLeft->frameClass;
    188 
    189 
    190         sbr_get_dir_control_data(hFrameDataLeft, hBitBuf);
    191         sbr_get_dir_control_data(hFrameDataRight, hBitBuf);
    192 
    193         for (i = 0; i < hFrameDataLeft->nNfb; i++)
    194         {
    195             hFrameDataLeft->sbr_invf_mode_prev[i]  = hFrameDataLeft->sbr_invf_mode[i];
    196             hFrameDataRight->sbr_invf_mode_prev[i] = hFrameDataRight->sbr_invf_mode[i];
    197 
    198             hFrameDataLeft->sbr_invf_mode[i]  = (INVF_MODE) buf_getbits(hBitBuf, SI_SBR_INVF_MODE_BITS);
    199             hFrameDataRight->sbr_invf_mode[i] = hFrameDataLeft->sbr_invf_mode[i];
    200         }
    201 
    202         sbr_get_envelope(hFrameDataLeft, hBitBuf);
    203         sbr_get_noise_floor_data(hFrameDataLeft, hBitBuf);
    204         sbr_get_envelope(hFrameDataRight, hBitBuf);
    205 
    206     }
    207     else
    208     {
    209         err = extractFrameInfo(hBitBuf, hFrameDataRight);
    210 
    211         if (err != SBRDEC_OK)
    212         {
    213             return err;
    214         }
    215 
    216 
    217         sbr_get_dir_control_data(hFrameDataLeft,  hBitBuf);
    218         sbr_get_dir_control_data(hFrameDataRight, hBitBuf);
    219 
    220         for (i = 0; i <  hFrameDataLeft->nNfb; i++)
    221         {
    222             hFrameDataLeft->sbr_invf_mode_prev[i]  = hFrameDataLeft->sbr_invf_mode[i];
    223             hFrameDataLeft->sbr_invf_mode[i]  =
    224                 (INVF_MODE) buf_getbits(hBitBuf, SI_SBR_INVF_MODE_BITS);
    225         }
    226 
    227         for (i = 0; i <  hFrameDataRight->nNfb; i++)
    228         {
    229             hFrameDataRight->sbr_invf_mode_prev[i] = hFrameDataRight->sbr_invf_mode[i];
    230 
    231             hFrameDataRight->sbr_invf_mode[i] =
    232                 (INVF_MODE) buf_getbits(hBitBuf, SI_SBR_INVF_MODE_BITS);
    233         }
    234         sbr_get_envelope(hFrameDataLeft,  hBitBuf);
    235         sbr_get_envelope(hFrameDataRight, hBitBuf);
    236 
    237         sbr_get_noise_floor_data(hFrameDataLeft,  hBitBuf);
    238 
    239     }
    240 
    241     sbr_get_noise_floor_data(hFrameDataRight, hBitBuf);
    242 
    243     pv_memset((void *)hFrameDataLeft->addHarmonics,
    244               0,
    245               hFrameDataLeft->nSfb[HI]*sizeof(Int32));
    246 
    247     pv_memset((void *)hFrameDataRight->addHarmonics,
    248               0,
    249               hFrameDataRight->nSfb[HI]*sizeof(Int32));
    250 
    251     sbr_get_additional_data(hFrameDataLeft, hBitBuf);
    252     sbr_get_additional_data(hFrameDataRight, hBitBuf);
    253 
    254     sbr_extract_extended_data(hBitBuf
    255 #ifdef PARAMETRICSTEREO
    256                               , NULL
    257 #endif
    258                              );
    259 
    260     return SBRDEC_OK;
    261 
    262 }
    263 
    264 #endif
    265 
    266 
    267