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: ps_decode_bs_utils.c
     21 
     22   Functions:
     23         GetNrBitsAvailable
     24         differential_Decoding
     25         map34IndexTo20
     26         limitMinMax
     27 
     28 ------------------------------------------------------------------------------
     29  REVISION HISTORY
     30 
     31 
     32  Who:                                   Date: MM/DD/YYYY
     33  Description:
     34 
     35 ------------------------------------------------------------------------------
     36  INPUT AND OUTPUT DEFINITIONS
     37 
     38 
     39 
     40 ------------------------------------------------------------------------------
     41  FUNCTION DESCRIPTION
     42 
     43         Decode bitstream parametric stereo's utilities
     44 
     45 ------------------------------------------------------------------------------
     46  REQUIREMENTS
     47 
     48 
     49 ------------------------------------------------------------------------------
     50  REFERENCES
     51 
     52 SC 29 Software Copyright Licencing Disclaimer:
     53 
     54 This software module was originally developed by
     55   Coding Technologies
     56 
     57 and edited by
     58   -
     59 
     60 in the course of development of the ISO/IEC 13818-7 and ISO/IEC 14496-3
     61 standards for reference purposes and its performance may not have been
     62 optimized. This software module is an implementation of one or more tools as
     63 specified by the ISO/IEC 13818-7 and ISO/IEC 14496-3 standards.
     64 ISO/IEC gives users free license to this software module or modifications
     65 thereof for use in products claiming conformance to audiovisual and
     66 image-coding related ITU Recommendations and/or ISO/IEC International
     67 Standards. ISO/IEC gives users the same free license to this software module or
     68 modifications thereof for research purposes and further ISO/IEC standardisation.
     69 Those intending to use this software module in products are advised that its
     70 use may infringe existing patents. ISO/IEC have no liability for use of this
     71 software module or modifications thereof. Copyright is not released for
     72 products that do not conform to audiovisual and image-coding related ITU
     73 Recommendations and/or ISO/IEC International Standards.
     74 The original developer retains full right to modify and use the code for its
     75 own purpose, assign or donate the code to a third party and to inhibit third
     76 parties from using the code for products that do not conform to audiovisual and
     77 image-coding related ITU Recommendations and/or ISO/IEC International Standards.
     78 This copyright notice must be included in all copies or derivative works.
     79 Copyright (c) ISO/IEC 2003.
     80 
     81 ------------------------------------------------------------------------------
     82  PSEUDO-CODE
     83 
     84 ------------------------------------------------------------------------------
     85 */
     86 
     87 
     88 /*----------------------------------------------------------------------------
     89 ; INCLUDES
     90 ----------------------------------------------------------------------------*/
     91 
     92 #ifdef AAC_PLUS
     93 
     94 #ifdef PARAMETRICSTEREO
     95 
     96 #include "aac_mem_funcs.h"
     97 #include "s_ps_dec.h"
     98 #include "ps_decode_bs_utils.h"
     99 
    100 /*----------------------------------------------------------------------------
    101 ; MACROS
    102 ; Define module specific macros here
    103 ----------------------------------------------------------------------------*/
    104 
    105 
    106 /*----------------------------------------------------------------------------
    107 ; DEFINES
    108 ; Include all pre-processor statements here. Include conditional
    109 ; compile variables also.
    110 ----------------------------------------------------------------------------*/
    111 
    112 /*----------------------------------------------------------------------------
    113 ; LOCAL FUNCTION DEFINITIONS
    114 ; Function Prototype declaration
    115 ----------------------------------------------------------------------------*/
    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 /*----------------------------------------------------------------------------
    130 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    131 ; Declare variables used in this module but defined elsewhere
    132 ----------------------------------------------------------------------------*/
    133 
    134 /*----------------------------------------------------------------------------
    135 ; FUNCTION CODE
    136 ----------------------------------------------------------------------------*/
    137 
    138 Int32 GetNrBitsAvailable(HANDLE_BIT_BUFFER hBitBuf)
    139 {
    140 
    141     return (hBitBuf->bufferLen - hBitBuf->nrBitsRead);
    142 }
    143 
    144 /*----------------------------------------------------------------------------
    145 ; FUNCTION CODE
    146 ;
    147 ;   Differential Decoding of parameters over time/frequency
    148 ----------------------------------------------------------------------------*/
    149 
    150 void differential_Decoding(Int32 enable,
    151                            Int32 *aIndex,
    152                            Int32 *aPrevFrameIndex,
    153                            Int32 DtDf,
    154                            Int32 nrElements,
    155                            Int32 stride,
    156                            Int32 minIdx,
    157                            Int32 maxIdx)
    158 {
    159     Int32 i;
    160     Int32 *ptr_aIndex;
    161 
    162     if (enable == 1)
    163     {
    164         ptr_aIndex = aIndex;
    165 
    166         if (DtDf == 0)
    167         {
    168             *(ptr_aIndex) = limitMinMax(*ptr_aIndex, minIdx, maxIdx);
    169             ptr_aIndex++;
    170 
    171             for (i = 1; i < nrElements; i++)
    172             {
    173                 *(ptr_aIndex) = limitMinMax(aIndex[i-1] + *ptr_aIndex, minIdx, maxIdx);
    174                 ptr_aIndex++;
    175             }
    176         }
    177         else
    178         {
    179             if (stride == 1)
    180             {
    181                 for (i = 0; i < nrElements; i++)
    182                 {
    183                     *(ptr_aIndex) = limitMinMax(aPrevFrameIndex[i] + *ptr_aIndex, minIdx, maxIdx);
    184                     ptr_aIndex++;
    185                 }
    186             }
    187             else
    188             {
    189                 for (i = 0; i < nrElements; i++)
    190                 {
    191                     *(ptr_aIndex) = limitMinMax(aPrevFrameIndex[(i<<1)] + *ptr_aIndex, minIdx, maxIdx);
    192                     ptr_aIndex++;
    193                 }
    194             }
    195         }
    196     }
    197     else
    198     {
    199         pv_memset((void *)aIndex, 0, nrElements*sizeof(*aIndex));
    200     }
    201     if (stride == 2)
    202     {
    203         for (i = (nrElements << 1) - 1; i > 0; i--)
    204         {
    205             aIndex[i] = aIndex[(i>>1)];
    206         }
    207     }
    208 }
    209 
    210 
    211 /*----------------------------------------------------------------------------
    212 ; FUNCTION CODE
    213         map34IndexTo20
    214 ----------------------------------------------------------------------------*/
    215 
    216 void map34IndexTo20(Int32 *aIndex)
    217 {
    218 
    219     aIndex[ 0] = ((aIndex[0] << 1) +  aIndex[1]) / 3;
    220     aIndex[ 1] = (aIndex[1] + (aIndex[2] << 1)) / 3;
    221     aIndex[ 2] = ((aIndex[3] << 1) +  aIndex[4]) / 3;
    222     aIndex[ 3] = (aIndex[4] + (aIndex[5] << 1)) / 3;
    223     aIndex[ 4] = (aIndex[ 6] +  aIndex[7]) >> 1;
    224     aIndex[ 5] = (aIndex[ 8] +  aIndex[9]) >> 1;
    225     aIndex[ 6] =   aIndex[10];
    226     aIndex[ 7] =   aIndex[11];
    227     aIndex[ 8] = (aIndex[12] +  aIndex[13]) >> 1;
    228     aIndex[ 9] = (aIndex[14] +  aIndex[15]) >> 1;
    229     aIndex[10] =   aIndex[16];
    230     aIndex[11] =   aIndex[17];
    231     aIndex[12] =   aIndex[18];
    232     aIndex[13] =   aIndex[19];
    233     aIndex[14] = (aIndex[20] +  aIndex[21]) >> 1;
    234     aIndex[15] = (aIndex[22] +  aIndex[23]) >> 1;
    235     aIndex[16] = (aIndex[24] +  aIndex[25]) >> 1;
    236     aIndex[17] = (aIndex[26] +  aIndex[27]) >> 1;
    237     aIndex[18] = (aIndex[28] +  aIndex[29] + aIndex[30] + aIndex[31]) >> 2;
    238     aIndex[19] = (aIndex[32] +  aIndex[33]) >> 1;
    239 }
    240 
    241 
    242 /*----------------------------------------------------------------------------
    243 ; FUNCTION CODE
    244         limitMinMax
    245 ----------------------------------------------------------------------------*/
    246 
    247 
    248 Int32 limitMinMax(Int32 i,
    249                   Int32 min,
    250                   Int32 max)
    251 {
    252     if (i < max)
    253     {
    254         if (i > min)
    255         {
    256             return i;
    257         }
    258         else
    259         {
    260             return min;
    261         }
    262     }
    263     else
    264     {
    265         return max;
    266     }
    267 }
    268 
    269 
    270 #endif
    271 
    272 
    273 #endif
    274 
    275