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_allocate_decoder.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     Reuses AAC+ HQ right channel, which is not used when PS is enabled
     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 HQ_SBR
     89 
     90 #ifdef PARAMETRICSTEREO
     91 
     92 #include    "s_sbr_channel.h"
     93 #include    "aac_mem_funcs.h"
     94 #include    "ps_hybrid_filter_bank_allocation.h"
     95 #include    "s_ps_dec.h"
     96 #include    "ps_all_pass_filter_coeff.h"
     97 #include    "ps_allocate_decoder.h"
     98 /*----------------------------------------------------------------------------
     99 ; MACROS
    100 ; Define module specific macros here
    101 ----------------------------------------------------------------------------*/
    102 
    103 
    104 /*----------------------------------------------------------------------------
    105 ; DEFINES
    106 ; Include all pre-processor statements here. Include conditional
    107 ; compile variables also.
    108 ----------------------------------------------------------------------------*/
    109 
    110 #define R_SHIFT     30
    111 #define Q30_fmt(x)   (Int32)(x*((Int32)1<<R_SHIFT) + (x>=0?0.5F:-0.5F))
    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 const Int32  aRevLinkDelaySer[] = {3,  4,  5};
    123 
    124 /*----------------------------------------------------------------------------
    125 ; EXTERNAL FUNCTION REFERENCES
    126 ; Declare functions defined elsewhere and referenced in this module
    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 ps_allocate_decoder(SBRDECODER_DATA *self,
    139                           UInt32  noSubSamples)
    140 {
    141     Int32 i, j;
    142     Int32 status;
    143 
    144     Int32 *ptr1;
    145     Int32 *ptr2;
    146     Int32 *ptr3;
    147     Int32 *ptr4;
    148     Int32 *ptr5;
    149     Int32 *ptr6;
    150     Int32 *ptr7;
    151 
    152     const Int32 pHybridResolution[] = { HYBRID_8_CPLX,
    153                                         HYBRID_2_REAL,
    154                                         HYBRID_2_REAL
    155                                       };
    156 
    157     STRUCT_PS_DEC *h_ps_dec = self->hParametricStereoDec;
    158 
    159     /* initialisation */
    160     h_ps_dec->noSubSamples = noSubSamples;
    161 
    162     h_ps_dec->invNoSubSamples = Q30_fmt(1.0f) / noSubSamples;
    163 
    164     /*
    165      *  Reuse AAC+ HQ right channel, which is not used when PS is enabled
    166      */
    167     ptr1 = (Int32 *)(self->SbrChannel[1].frameData.codecQmfBufferReal[0]);   /*  reuse un-used right channel QMF_FILTER Synthesis buffer */
    168 
    169     ptr2 = (&ptr1[658]);  /*  reuse un-used right channel QMF_FILTER Synthesis buffer */
    170     /* 1162 - 658 = 504
    171      *            = NO_QMF_ALLPASS_CHANNELS*2 (Re&Im)*( 3 + 4 + 5) + ( 3 + 4 + 5)*2 (Re&Im)
    172      */
    173 
    174     ptr3 = (&ptr1[1162]);  /*  reuse un-used right channel QMF_FILTER Synthesis buffer */
    175     /* 1426 - 1162 = 264
    176      *            = SUBQMF_GROUPS*2 (Re&Im)*( 3 + 4 + 5) + ( 3 + 4 + 5)*2 (Re&Im)
    177      */
    178 
    179     ptr4 = (&ptr1[1426]);  /*  high freq generation buffers */
    180 
    181     ptr5 = (&ptr1[1490]);  /*  high freq generation buffers */
    182 
    183     ptr6 = (&ptr1[1618]);  /*  high freq generation buffers */
    184 
    185     ptr7 = (&ptr1[1810]);  /*  high freq generation buffers */
    186 
    187     /*  whole allocation requires 1871 words, sbrQmfBufferImag has 1920 words */
    188 
    189 
    190     h_ps_dec->aPeakDecayFast =  ptr1;
    191     ptr1 += NO_BINS;
    192 
    193     h_ps_dec->aPrevNrg =  ptr1;
    194     ptr1 += NO_BINS;
    195 
    196     h_ps_dec->aPrevPeakDiff = ptr1;
    197     ptr1 += NO_BINS;
    198 
    199 
    200 
    201     status = ps_hybrid_filter_bank_allocation(&h_ps_dec->hHybrid,
    202              NO_QMF_CHANNELS_IN_HYBRID,
    203              pHybridResolution,
    204              &ptr1);
    205     h_ps_dec->mHybridRealLeft = ptr1;
    206     ptr1 += SUBQMF_GROUPS;
    207 
    208     h_ps_dec->mHybridImagLeft = ptr1;
    209     ptr1 += SUBQMF_GROUPS;
    210 
    211     h_ps_dec->mHybridRealRight = ptr1;
    212     ptr1 += SUBQMF_GROUPS;
    213 
    214     h_ps_dec->mHybridImagRight = ptr1;
    215     ptr1 += SUBQMF_GROUPS;
    216 
    217 
    218     h_ps_dec->delayBufIndex   = 0;
    219 
    220 
    221 
    222     for (i = 0 ; i < NO_DELAY_CHANNELS ; i++)   /* 41  */
    223     {
    224         if (i < SHORT_DELAY_START)              /* 12  */
    225         {
    226             h_ps_dec->aNoSampleDelay[i] = LONG_DELAY;
    227         }
    228         else
    229         {
    230             h_ps_dec->aNoSampleDelay[i] = SHORT_DELAY;
    231         }
    232     }
    233 
    234 
    235     h_ps_dec->aaRealDelayBufferQmf = (Int32 **)ptr6;
    236     ptr6 += NO_QMF_ICC_CHANNELS * sizeof(Int32 *) / sizeof(Int32);
    237 
    238     h_ps_dec->aaImagDelayBufferQmf = (Int32 **)ptr7;
    239     ptr7 += NO_QMF_ICC_CHANNELS * sizeof(Int32 *) / sizeof(Int32);
    240 
    241     h_ps_dec->aaRealDelayBufferSubQmf = (Int32 **)ptr1;
    242     ptr1 += SUBQMF_GROUPS * sizeof(Int32 *) / sizeof(Int32);
    243 
    244     h_ps_dec->aaImagDelayBufferSubQmf = (Int32 **)ptr1;
    245     ptr1 += SUBQMF_GROUPS * sizeof(Int32 *) / sizeof(Int32);
    246 
    247     for (i = 0; i < NO_QMF_ICC_CHANNELS; i++)   /* 61 */
    248     {
    249         int delay;
    250 
    251         if (i < NO_QMF_ALLPASS_CHANNELS)    /* 20 */
    252         {
    253             delay = 2;
    254             h_ps_dec->aaRealDelayBufferQmf[i] = (Int32 *)ptr4;
    255             ptr4 += delay;
    256 
    257             h_ps_dec->aaImagDelayBufferQmf[i] = (Int32 *)ptr5;
    258             ptr5 += delay;
    259         }
    260         else
    261         {
    262 
    263             if (i >= (NO_QMF_ALLPASS_CHANNELS + SHORT_DELAY_START))
    264             {
    265                 delay = SHORT_DELAY;
    266             }
    267             else
    268             {
    269                 delay = LONG_DELAY;
    270             }
    271 
    272             h_ps_dec->aaRealDelayBufferQmf[i] = (Int32 *)ptr1;
    273             ptr1 += delay;
    274 
    275             h_ps_dec->aaImagDelayBufferQmf[i] = (Int32 *)ptr1;
    276             ptr1 += delay;
    277         }
    278     }
    279 
    280     for (i = 0; i < SUBQMF_GROUPS; i++)
    281     {
    282         h_ps_dec->aaRealDelayBufferSubQmf[i] = (Int32 *)ptr1;
    283         ptr1 += DELAY_ALLPASS;
    284 
    285         h_ps_dec->aaImagDelayBufferSubQmf[i] = (Int32 *)ptr1;
    286         ptr1 += DELAY_ALLPASS;
    287 
    288     }
    289 
    290     for (i = 0 ; i < NO_SERIAL_ALLPASS_LINKS ; i++) /*  NO_SERIAL_ALLPASS_LINKS == 3 */
    291     {
    292 
    293         h_ps_dec->aDelayRBufIndexSer[i] = 0;
    294 
    295         h_ps_dec->aaaRealDelayRBufferSerQmf[i] = (Int32 **)ptr2;
    296         ptr2 += aRevLinkDelaySer[i];
    297 
    298         h_ps_dec->aaaImagDelayRBufferSerQmf[i] = (Int32 **)ptr2;
    299         ptr2 += aRevLinkDelaySer[i];
    300 
    301         h_ps_dec->aaaRealDelayRBufferSerSubQmf[i] = (Int32 **)ptr3;
    302         ptr3 += aRevLinkDelaySer[i];
    303 
    304         h_ps_dec->aaaImagDelayRBufferSerSubQmf[i] = (Int32 **)ptr3;
    305         ptr3 += aRevLinkDelaySer[i];
    306 
    307         for (j = 0; j < aRevLinkDelaySer[i]; j++)
    308         {
    309             h_ps_dec->aaaRealDelayRBufferSerQmf[i][j] = ptr2;
    310             ptr2 += NO_QMF_ALLPASS_CHANNELS;    /* NO_QMF_ALLPASS_CHANNELS == 20 */
    311 
    312             h_ps_dec->aaaImagDelayRBufferSerQmf[i][j] = ptr2;
    313             ptr2 += NO_QMF_ALLPASS_CHANNELS;
    314 
    315             h_ps_dec->aaaRealDelayRBufferSerSubQmf[i][j] = ptr3;
    316             ptr3 += SUBQMF_GROUPS;
    317 
    318             h_ps_dec->aaaImagDelayRBufferSerSubQmf[i][j] = ptr3;
    319             ptr3 += SUBQMF_GROUPS;
    320 
    321         }
    322     }
    323 
    324 
    325     for (i = 0; i < NO_IID_GROUPS; i++)         /*  NO_IID_GROUPS == 22   */
    326     {
    327         h_ps_dec->h11Prev[i] = Q30_fmt(1.0f);
    328         h_ps_dec->h12Prev[i] = Q30_fmt(1.0f);
    329     }
    330 
    331 
    332 
    333     return status;
    334 } /*END CreatePsDec*/
    335 #endif
    336 
    337 #endif
    338 
    339 
    340 #endif
    341 
    342