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_bstr_decoding.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 
     33 
     34 ------------------------------------------------------------------------------
     35  FUNCTION DESCRIPTION
     36 
     37         Decodes parametric stereo
     38 
     39 ------------------------------------------------------------------------------
     40  REQUIREMENTS
     41 
     42 
     43 ------------------------------------------------------------------------------
     44  REFERENCES
     45 
     46 SC 29 Software Copyright Licencing Disclaimer:
     47 
     48 This software module was originally developed by
     49   Coding Technologies
     50 
     51 and edited by
     52   -
     53 
     54 in the course of development of the ISO/IEC 13818-7 and ISO/IEC 14496-3
     55 standards for reference purposes and its performance may not have been
     56 optimized. This software module is an implementation of one or more tools as
     57 specified by the ISO/IEC 13818-7 and ISO/IEC 14496-3 standards.
     58 ISO/IEC gives users free license to this software module or modifications
     59 thereof for use in products claiming conformance to audiovisual and
     60 image-coding related ITU Recommendations and/or ISO/IEC International
     61 Standards. ISO/IEC gives users the same free license to this software module or
     62 modifications thereof for research purposes and further ISO/IEC standardisation.
     63 Those intending to use this software module in products are advised that its
     64 use may infringe existing patents. ISO/IEC have no liability for use of this
     65 software module or modifications thereof. Copyright is not released for
     66 products that do not conform to audiovisual and image-coding related ITU
     67 Recommendations and/or ISO/IEC International Standards.
     68 The original developer retains full right to modify and use the code for its
     69 own purpose, assign or donate the code to a third party and to inhibit third
     70 parties from using the code for products that do not conform to audiovisual and
     71 image-coding related ITU Recommendations and/or ISO/IEC International Standards.
     72 This copyright notice must be included in all copies or derivative works.
     73 Copyright (c) ISO/IEC 2003.
     74 
     75 ------------------------------------------------------------------------------
     76  PSEUDO-CODE
     77 
     78 ------------------------------------------------------------------------------
     79 */
     80 
     81 
     82 /*----------------------------------------------------------------------------
     83 ; INCLUDES
     84 ----------------------------------------------------------------------------*/
     85 
     86 #ifdef AAC_PLUS
     87 
     88 #ifdef PARAMETRICSTEREO
     89 
     90 #include "pv_audio_type_defs.h"
     91 #include "aac_mem_funcs.h"
     92 #include "ps_bstr_decoding.h"
     93 #include "ps_decode_bs_utils.h"
     94 
     95 /*----------------------------------------------------------------------------
     96 ; MACROS
     97 ; Define module specific macros here
     98 ----------------------------------------------------------------------------*/
     99 
    100 
    101 /*----------------------------------------------------------------------------
    102 ; DEFINES
    103 ; Include all pre-processor statements here. Include conditional
    104 ; compile variables also.
    105 ----------------------------------------------------------------------------*/
    106 
    107 /*----------------------------------------------------------------------------
    108 ; LOCAL FUNCTION DEFINITIONS
    109 ; Function Prototype declaration
    110 ----------------------------------------------------------------------------*/
    111 
    112 /*----------------------------------------------------------------------------
    113 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    114 ; Variable declaration - defined here and used outside this module
    115 ----------------------------------------------------------------------------*/
    116 
    117 const Int32 aNoIidBins[3] = {NO_LOW_RES_IID_BINS, NO_IID_BINS, NO_HI_RES_BINS};
    118 const Int32 aNoIccBins[3] = {NO_LOW_RES_ICC_BINS, NO_ICC_BINS, NO_HI_RES_BINS};
    119 const Int32 aFixNoEnvDecode[4] = {0, 1, 2, 4};
    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 void ps_bstr_decoding(STRUCT_PS_DEC *ps_dec)
    136 {
    137     UInt32 env;
    138     Int32 noIidSteps;
    139 
    140     if (!ps_dec->bPsDataAvail)
    141     {
    142         ps_dec->noEnv = 0;
    143     }
    144 
    145     noIidSteps = ps_dec->bFineIidQ ? NO_IID_STEPS_FINE : NO_IID_STEPS;
    146 
    147     for (env = 0; env < ps_dec->noEnv; env++)
    148     {
    149         Int32 *aPrevIidIndex;
    150         Int32 *aPrevIccIndex;
    151         if (env == 0)
    152         {
    153             aPrevIidIndex = ps_dec->aIidPrevFrameIndex;
    154             aPrevIccIndex = ps_dec->aIccPrevFrameIndex;
    155         }
    156         else
    157         {
    158             aPrevIidIndex = ps_dec->aaIidIndex[env-1];
    159             aPrevIccIndex = ps_dec->aaIccIndex[env-1];
    160         }
    161 
    162         /*
    163          * Differential Decoding of IID parameters over time/frequency
    164          */
    165         differential_Decoding(ps_dec->bEnableIid,
    166                               ps_dec->aaIidIndex[env],
    167                               aPrevIidIndex,
    168                               ps_dec->abIidDtFlag[env],
    169                               aNoIidBins[ps_dec->freqResIid],
    170                               (ps_dec->freqResIid) ? 1 : 2,
    171                               -noIidSteps,
    172                               noIidSteps);
    173 
    174         /*
    175          * Differential Decoding of ICC parameters over time/frequency
    176          */
    177         differential_Decoding(ps_dec->bEnableIcc,
    178                               ps_dec->aaIccIndex[env],
    179                               aPrevIccIndex,
    180                               ps_dec->abIccDtFlag[env],
    181                               aNoIccBins[ps_dec->freqResIcc],
    182                               (ps_dec->freqResIcc) ? 1 : 2,
    183                               0,
    184                               NO_ICC_STEPS - 1);
    185 
    186 
    187     }   /* for (env=0; env<ps_dec->noEnv; env++) */
    188 
    189     if (ps_dec->noEnv == 0)
    190     {
    191         ps_dec->noEnv = 1;
    192 
    193         if (ps_dec->bEnableIid)
    194         {   /*  NO_HI_RES_BINS == 34 */
    195             pv_memmove(ps_dec->aaIidIndex[ps_dec->noEnv-1],
    196                        ps_dec->aIidPrevFrameIndex,
    197                        NO_HI_RES_BINS*sizeof(*ps_dec->aIidPrevFrameIndex));
    198 
    199         }
    200         else
    201         {
    202             pv_memset((void *)ps_dec->aaIidIndex[ps_dec->noEnv-1],
    203                       0,
    204                       NO_HI_RES_BINS*sizeof(**ps_dec->aaIidIndex));
    205         }
    206         if (ps_dec->bEnableIcc)
    207         {
    208             pv_memmove(ps_dec->aaIccIndex[ps_dec->noEnv-1],
    209                        ps_dec->aIccPrevFrameIndex,
    210                        NO_HI_RES_BINS*sizeof(*ps_dec->aIccPrevFrameIndex));
    211         }
    212         else
    213         {
    214             pv_memset((void *)ps_dec->aaIccIndex[ps_dec->noEnv-1],
    215                       0,
    216                       NO_HI_RES_BINS*sizeof(**ps_dec->aaIccIndex));
    217         }
    218     }
    219 
    220     pv_memmove(ps_dec->aIidPrevFrameIndex,
    221                ps_dec->aaIidIndex[ps_dec->noEnv-1],
    222                NO_HI_RES_BINS*sizeof(*ps_dec->aIidPrevFrameIndex));
    223 
    224     pv_memmove(ps_dec->aIccPrevFrameIndex,
    225                ps_dec->aaIccIndex[ps_dec->noEnv-1],
    226                NO_HI_RES_BINS*sizeof(*ps_dec->aIccPrevFrameIndex));
    227 
    228     ps_dec->bPsDataAvail = 0;
    229 
    230     if (ps_dec->bFrameClass == 0)
    231     {
    232         Int32 shift;
    233 
    234         shift = ps_dec->noEnv >> 1;
    235 
    236         ps_dec->aEnvStartStop[0] = 0;
    237 
    238         for (env = 1; env < ps_dec->noEnv; env++)
    239         {
    240             ps_dec->aEnvStartStop[env] =
    241                 (env * ps_dec->noSubSamples) >> shift;
    242         }
    243 
    244         ps_dec->aEnvStartStop[ps_dec->noEnv] = ps_dec->noSubSamples;
    245     }
    246     else
    247     {   /* if (ps_dec->bFrameClass != 0) */
    248         ps_dec->aEnvStartStop[0] = 0;
    249 
    250         if (ps_dec->aEnvStartStop[ps_dec->noEnv] < ps_dec->noSubSamples)
    251         {
    252             ps_dec->noEnv++;
    253             ps_dec->aEnvStartStop[ps_dec->noEnv] = ps_dec->noSubSamples;
    254 
    255             pv_memmove(ps_dec->aaIidIndex[ps_dec->noEnv],
    256                        ps_dec->aaIidIndex[ps_dec->noEnv-1],
    257                        NO_HI_RES_BINS*sizeof(**ps_dec->aaIidIndex));
    258 
    259             pv_memmove(ps_dec->aaIccIndex[ps_dec->noEnv],
    260                        ps_dec->aaIccIndex[ps_dec->noEnv-1],
    261                        NO_HI_RES_BINS*sizeof(**ps_dec->aaIccIndex));
    262         }
    263 
    264         for (env = 1; env < ps_dec->noEnv; env++)
    265         {
    266             UInt32 thr;
    267             thr = ps_dec->noSubSamples - ps_dec->noEnv + env;
    268 
    269             if (ps_dec->aEnvStartStop[env] > thr)
    270             {
    271                 ps_dec->aEnvStartStop[env] = thr;
    272             }
    273             else
    274             {
    275                 thr = ps_dec->aEnvStartStop[env-1] + 1;
    276 
    277                 if (ps_dec->aEnvStartStop[env] < thr)
    278                 {
    279                     ps_dec->aEnvStartStop[env] = thr;
    280                 }
    281             }
    282         }
    283     }   /* if (ps_dec->bFrameClass == 0) ... else */
    284 
    285     for (env = 0; env < ps_dec->noEnv; env++)
    286     {
    287         if (ps_dec->freqResIid == 2)
    288         {
    289             map34IndexTo20(ps_dec->aaIidIndex[env]);
    290         }
    291         if (ps_dec->freqResIcc == 2)
    292         {
    293             map34IndexTo20(ps_dec->aaIccIndex[env]);
    294         }
    295     }
    296 
    297 
    298 }
    299 
    300 #endif
    301 
    302 
    303 #endif
    304 
    305