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_dec.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     sbr decoder core function
     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 2002.
     74 
     75 ------------------------------------------------------------------------------
     76  PSEUDO-CODE
     77 
     78 ------------------------------------------------------------------------------
     79 */
     80 
     81 
     82 /*----------------------------------------------------------------------------
     83 ; INCLUDES
     84 ----------------------------------------------------------------------------*/
     85 #ifdef AAC_PLUS
     86 
     87 
     88 #include    "s_sbr_frame_data.h"
     89 #include    "calc_sbr_synfilterbank.h"
     90 #include    "calc_sbr_anafilterbank.h"
     91 #include    "calc_sbr_envelope.h"
     92 #include    "sbr_generate_high_freq.h"
     93 #include    "sbr_dec.h"
     94 #include    "decode_noise_floorlevels.h"
     95 #include    "aac_mem_funcs.h"
     96 #include    "fxp_mul32.h"
     97 
     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 /*----------------------------------------------------------------------------
    111 ; LOCAL FUNCTION DEFINITIONS
    112 ; Function Prototype declaration
    113 ----------------------------------------------------------------------------*/
    114 /*----------------------------------------------------------------------------
    115 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    116 ; Variable declaration - defined here and used outside this module
    117 ----------------------------------------------------------------------------*/
    118 
    119 
    120 /*----------------------------------------------------------------------------
    121 ; EXTERNAL FUNCTION REFERENCES
    122 ; Declare functions defined elsewhere and referenced in this module
    123 ----------------------------------------------------------------------------*/
    124 #include "pv_audio_type_defs.h"
    125 
    126 #ifdef PARAMETRICSTEREO
    127 
    128 #include   "ps_applied.h"
    129 #include   "ps_init_stereo_mixing.h"
    130 
    131 #endif
    132 
    133 /*----------------------------------------------------------------------------
    134 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    135 ; Declare variables used in this module but defined elsewhere
    136 ----------------------------------------------------------------------------*/
    137 
    138 /*----------------------------------------------------------------------------
    139 ; FUNCTION CODE
    140 ----------------------------------------------------------------------------*/
    141 
    142 void sbr_dec(Int16 *inPcmData,
    143              Int16 *ftimeOutPtr,
    144              SBR_FRAME_DATA * hFrameData,
    145              int32_t applyProcessing,
    146              SBR_DEC *sbrDec,
    147 #ifdef HQ_SBR
    148 #ifdef PARAMETRICSTEREO
    149              Int16 * ftimeOutPtrPS,
    150              HANDLE_PS_DEC hParametricStereoDec,
    151 #endif
    152 #endif
    153              tDec_Int_File  *pVars)
    154 {
    155     int32_t   i;
    156     int32_t   j;
    157     int32_t   m;
    158 
    159     int32_t  *frameInfo = hFrameData->frameInfo;
    160     Int  num_qmf_bands;
    161 
    162 #ifdef HQ_SBR
    163 #ifdef PARAMETRICSTEREO
    164 
    165     int32_t env;
    166 
    167     int32_t *qmf_PS_generated_Real;
    168     int32_t *qmf_PS_generated_Imag;
    169 
    170     int32_t *Sr_x;
    171     int32_t *Si_x;
    172 
    173 
    174 #endif
    175 #endif
    176 
    177     int32_t(*scratch_mem)[64];
    178     Int16 *circular_buffer_s;
    179 
    180     int32_t   k;
    181     int32_t *Sr;
    182     int32_t *Si;
    183     int32_t *ptr_tmp1;
    184     int32_t *ptr_tmp2;
    185     scratch_mem = pVars->scratch.scratch_mem;
    186 
    187 
    188     if (applyProcessing)
    189     {
    190         num_qmf_bands = sbrDec->lowSubband;
    191     }
    192     else
    193     {
    194         num_qmf_bands = 32;     /* becomes a resampler by 2  */
    195     }
    196 
    197     /* -------------------------------------------------- */
    198     /*
    199      *    Re-Load Buffers
    200      */
    201     pv_memmove(&hFrameData->sbrQmfBufferReal[0],
    202                &hFrameData->HistsbrQmfBufferReal[0],
    203                6*SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferReal));
    204 #ifdef HQ_SBR
    205 
    206 
    207     if (sbrDec->LC_aacP_DecoderFlag == OFF)
    208     {
    209         pv_memmove(&hFrameData->sbrQmfBufferImag[0],
    210                    &hFrameData->HistsbrQmfBufferImag[0],
    211                    6*SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferImag));
    212     }
    213 #endif
    214     /* -------------------------------------------------- */
    215 
    216 
    217     /*
    218      *    low band codec signal subband filtering
    219      */
    220 
    221     for (i = 0; i < 32; i++)
    222     {
    223 
    224         if (sbrDec->LC_aacP_DecoderFlag == ON)
    225         {
    226 
    227             calc_sbr_anafilterbank_LC(hFrameData->codecQmfBufferReal[sbrDec->bufWriteOffs + i],
    228                                       &inPcmData[319] + (i << 5),
    229                                       scratch_mem,
    230                                       num_qmf_bands);
    231 
    232         }
    233 #ifdef HQ_SBR
    234         else
    235         {
    236 
    237             calc_sbr_anafilterbank(hFrameData->codecQmfBufferReal[sbrDec->bufWriteOffs + i],
    238                                    hFrameData->codecQmfBufferImag[sbrDec->bufWriteOffs + i],
    239                                    &inPcmData[319] + (i << 5),
    240                                    scratch_mem,
    241                                    num_qmf_bands);
    242         }
    243 #endif
    244 
    245     }
    246 
    247     if (pVars->ltp_buffer_state)
    248     {
    249         pv_memcpy(&inPcmData[-1024-288], &inPcmData[1024], 288*sizeof(*inPcmData));
    250     }
    251     else
    252     {
    253         pv_memcpy(&inPcmData[1024 + 288], &inPcmData[1024], 288*sizeof(*inPcmData));
    254     }
    255 
    256 
    257     if (applyProcessing)
    258     {
    259 
    260         /*
    261          *  Inverse filtering of lowband + HF generation
    262          */
    263 
    264         if (sbrDec->LC_aacP_DecoderFlag == ON)
    265         {
    266 
    267             sbr_generate_high_freq((int32_t(*)[32])(hFrameData->codecQmfBufferReal + sbrDec->bufReadOffs),
    268                                    NULL,
    269                                    (int32_t *)(hFrameData->sbrQmfBufferReal),
    270                                    NULL,
    271                                    hFrameData->sbr_invf_mode,
    272                                    hFrameData->sbr_invf_mode_prev,
    273                                    &(sbrDec->FreqBandTableNoise[1]),
    274                                    sbrDec->NoNoiseBands,
    275                                    sbrDec->lowSubband,
    276                                    sbrDec->V_k_master,
    277                                    sbrDec->Num_Master,
    278                                    sbrDec->outSampleRate,
    279                                    frameInfo,
    280                                    hFrameData->degreeAlias,
    281                                    scratch_mem,
    282                                    hFrameData->BwVector,/* */
    283                                    hFrameData->BwVectorOld,
    284                                    &(sbrDec->Patch),
    285                                    sbrDec->LC_aacP_DecoderFlag,
    286                                    &(sbrDec->highSubband));
    287 
    288 
    289             /*
    290              *      Adjust envelope of current frame.
    291              */
    292 
    293             calc_sbr_envelope(hFrameData,
    294                               (int32_t *)(hFrameData->sbrQmfBufferReal),
    295                               NULL,
    296                               sbrDec->FreqBandTable,
    297                               sbrDec->NSfb,
    298                               sbrDec->FreqBandTableNoise,
    299                               sbrDec->NoNoiseBands,
    300                               hFrameData->reset_flag,
    301                               hFrameData->degreeAlias,
    302                               &(hFrameData->harm_index),
    303                               &(hFrameData->phase_index),
    304                               hFrameData->hFp,
    305                               &(hFrameData->sUp),
    306                               sbrDec->limSbc,
    307                               sbrDec->gateMode,
    308 #ifdef HQ_SBR
    309                               NULL,
    310                               NULL,
    311                               NULL,
    312                               NULL,
    313 #endif
    314                               scratch_mem,
    315                               sbrDec->Patch,
    316                               sbrDec->sqrt_cache,
    317                               sbrDec->LC_aacP_DecoderFlag);
    318         }
    319 #ifdef HQ_SBR
    320         else
    321         {
    322 
    323             sbr_generate_high_freq((int32_t(*)[32])(hFrameData->codecQmfBufferReal + sbrDec->bufReadOffs),
    324                                    (int32_t(*)[32])(hFrameData->codecQmfBufferImag + sbrDec->bufReadOffs),
    325                                    (int32_t *)(hFrameData->sbrQmfBufferReal),
    326                                    (int32_t *)(hFrameData->sbrQmfBufferImag),
    327                                    hFrameData->sbr_invf_mode,
    328                                    hFrameData->sbr_invf_mode_prev,
    329                                    &(sbrDec->FreqBandTableNoise[1]),
    330                                    sbrDec->NoNoiseBands,
    331                                    sbrDec->lowSubband,
    332                                    sbrDec->V_k_master,
    333                                    sbrDec->Num_Master,
    334                                    sbrDec->outSampleRate,
    335                                    frameInfo,
    336                                    NULL,
    337                                    scratch_mem,
    338                                    hFrameData->BwVector,
    339                                    hFrameData->BwVectorOld,
    340                                    &(sbrDec->Patch),
    341                                    sbrDec->LC_aacP_DecoderFlag,
    342                                    &(sbrDec->highSubband));
    343 
    344             /*
    345              *      Adjust envelope of current frame.
    346              */
    347 
    348             calc_sbr_envelope(hFrameData,
    349                               (int32_t *)(hFrameData->sbrQmfBufferReal),
    350                               (int32_t *)(hFrameData->sbrQmfBufferImag),
    351                               sbrDec->FreqBandTable,
    352                               sbrDec->NSfb,
    353                               sbrDec->FreqBandTableNoise,
    354                               sbrDec->NoNoiseBands,
    355                               hFrameData->reset_flag,
    356                               NULL,
    357                               &(hFrameData->harm_index),
    358                               &(hFrameData->phase_index),
    359                               hFrameData->hFp,
    360                               &(hFrameData->sUp),
    361                               sbrDec->limSbc,
    362                               sbrDec->gateMode,
    363                               hFrameData->fBuf_man,
    364                               hFrameData->fBuf_exp,
    365                               hFrameData->fBufN_man,
    366                               hFrameData->fBufN_exp,
    367                               scratch_mem,
    368                               sbrDec->Patch,
    369                               sbrDec->sqrt_cache,
    370                               sbrDec->LC_aacP_DecoderFlag);
    371 
    372         }
    373 #endif
    374 
    375 
    376     }
    377     else   /*  else for applyProcessing */
    378     {
    379         /* no sbr, set high band buffers to zero */
    380 
    381         for (i = 0; i < SBR_NUM_COLUMNS; i++)
    382         {
    383             pv_memset((void *)&hFrameData->sbrQmfBufferReal[i*SBR_NUM_BANDS],
    384                       0,
    385                       SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferReal));
    386 
    387 #ifdef HQ_SBR
    388             pv_memset((void *)&hFrameData->sbrQmfBufferImag[i*SBR_NUM_BANDS],
    389                       0,
    390                       SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferImag));
    391 
    392 #endif
    393         }
    394 
    395     }
    396 
    397 
    398     /*
    399      *  Synthesis subband filtering.
    400      */
    401 
    402 #ifdef HQ_SBR
    403 
    404 #ifdef PARAMETRICSTEREO
    405 
    406 
    407     /*
    408      * psPresentFlag set implies hParametricStereoDec !=NULL, second condition is
    409      * is just here to prevent CodeSonar warnings.
    410      */
    411     if ((pVars->mc_info.psPresentFlag) && (applyProcessing) &&
    412             (hParametricStereoDec != NULL))
    413     {
    414 
    415         /*
    416          *  qmfBufferReal uses the rigth aac channel ( perChan[1] is not used)
    417          *  followed by the buffer fxpCoef[2][2048]  which makes a total of
    418          *  2349 + 2048*2 = 6445
    419          *  These  2 matrices (qmfBufferReal & qmfBufferImag) are
    420          *  [2][38][64] == 4864 int32_t
    421          */
    422 
    423 
    424         tDec_Int_Chan *tmpx = &pVars->perChan[1];
    425         /*
    426          *  dereferencing type-punned pointer avoid
    427          *  breaking strict-aliasing rules
    428          */
    429         int32_t *tmp = (int32_t *)tmpx;
    430         hParametricStereoDec->qmfBufferReal = (int32_t(*)[64]) tmp;
    431 
    432         tmp = (int32_t *) & hParametricStereoDec->qmfBufferReal[38][0];
    433         hParametricStereoDec->qmfBufferImag = (int32_t(*)[64]) tmp;
    434 
    435         for (i = 0; i < 32; i++)
    436         {
    437             Int   xoverBand;
    438 
    439             if (i < ((hFrameData->frameInfo[1]) << 1))
    440             {
    441                 xoverBand = sbrDec->prevLowSubband;
    442             }
    443             else
    444             {
    445                 xoverBand = sbrDec->lowSubband;
    446             }
    447 
    448             if (xoverBand > sbrDec->highSubband)
    449             {
    450                 xoverBand = 32; /* error condition, default to upsampling mode */
    451             }
    452 
    453             m = sbrDec->bufReadOffs + i;    /*  2 + i */
    454 
    455             Sr_x = hParametricStereoDec->qmfBufferReal[i];
    456             Si_x = hParametricStereoDec->qmfBufferImag[i];
    457 
    458 
    459 
    460             for (int32_t j = 0; j < xoverBand; j++)
    461             {
    462                 Sr_x[j] = shft_lft_1(hFrameData->codecQmfBufferReal[m][j]);
    463                 Si_x[j] = shft_lft_1(hFrameData->codecQmfBufferImag[m][j]);
    464             }
    465 
    466 
    467 
    468 
    469             pv_memcpy(&Sr_x[xoverBand],
    470                       &hFrameData->sbrQmfBufferReal[i*SBR_NUM_BANDS],
    471                       (sbrDec->highSubband - xoverBand)*sizeof(*Sr_x));
    472 
    473             pv_memcpy(&Si_x[xoverBand],
    474                       &hFrameData->sbrQmfBufferImag[i*SBR_NUM_BANDS],
    475                       (sbrDec->highSubband - xoverBand)*sizeof(*Si_x));
    476 
    477             pv_memset((void *)&Sr_x[sbrDec->highSubband],
    478                       0,
    479                       (64 - sbrDec->highSubband)*sizeof(*Sr_x));
    480 
    481             pv_memset((void *)&Si_x[sbrDec->highSubband],
    482                       0,
    483                       (64 - sbrDec->highSubband)*sizeof(*Si_x));
    484 
    485 
    486         }
    487 
    488         for (i = 32; i < 32 + 6; i++)
    489         {
    490             m = sbrDec->bufReadOffs + i;     /*  2 + i */
    491 
    492             for (int32_t j = 0; j < 5; j++)
    493             {
    494                 hParametricStereoDec->qmfBufferReal[i][j] = shft_lft_1(hFrameData->codecQmfBufferReal[m][j]);
    495                 hParametricStereoDec->qmfBufferImag[i][j] = shft_lft_1(hFrameData->codecQmfBufferImag[m][j]);
    496             }
    497 
    498         }
    499 
    500 
    501         /*
    502          *    Update Buffers
    503          */
    504         for (i = 0; i < sbrDec->bufWriteOffs; i++)     /* sbrDec->bufWriteOffs set to 8 and unchanged */
    505         {
    506             j = sbrDec->noCols + i;                    /* sbrDec->noCols set to 32 and unchanged */
    507 
    508             pv_memmove(hFrameData->codecQmfBufferReal[i],         /* to    */
    509                        hFrameData->codecQmfBufferReal[j],        /* from  */
    510                        sizeof(*hFrameData->codecQmfBufferReal[i]) << 5);
    511 
    512             pv_memmove(hFrameData->codecQmfBufferImag[i],
    513                        hFrameData->codecQmfBufferImag[j],
    514                        sizeof(*hFrameData->codecQmfBufferImag[i]) << 5);
    515         }
    516 
    517 
    518         pv_memmove(&hFrameData->HistsbrQmfBufferReal[0],
    519                    &hFrameData->sbrQmfBufferReal[32*SBR_NUM_BANDS],
    520                    6*SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferReal));
    521 
    522         pv_memmove(&hFrameData->HistsbrQmfBufferImag[0],
    523                    &hFrameData->sbrQmfBufferImag[32*SBR_NUM_BANDS],
    524                    6*SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferImag));
    525 
    526 
    527         /*
    528          *   Needs whole QMF matrix formed before applying
    529          *   Parametric stereo processing.
    530          */
    531 
    532         qmf_PS_generated_Real = scratch_mem[0];
    533         qmf_PS_generated_Imag = scratch_mem[1];
    534         env = 0;
    535 
    536         /*
    537          *  Set circular buffer for Left channel
    538          */
    539 
    540         circular_buffer_s = (Int16 *)scratch_mem[7];
    541 
    542 
    543         if (pVars->mc_info.bDownSampledSbr)
    544         {
    545             pv_memmove(&circular_buffer_s[2048],
    546                        hFrameData->V,
    547                        640*sizeof(*circular_buffer_s));
    548         }
    549         else
    550         {
    551             pv_memmove(&circular_buffer_s[4096],
    552                        hFrameData->V,
    553                        1152*sizeof(*circular_buffer_s));
    554 
    555         }
    556 
    557 
    558         /*
    559          *  Set Circular buffer for PS hybrid analysis
    560          */
    561         for (i = 0, j = 0; i < 3; i++)
    562         {
    563 
    564             pv_memmove(&scratch_mem[2][32 + j     ],
    565                        hParametricStereoDec->hHybrid->mQmfBufferReal[i],
    566                        HYBRID_FILTER_LENGTH_m_1*sizeof(*hParametricStereoDec->hHybrid->mQmfBufferReal));
    567             pv_memmove(&scratch_mem[2][32 + j + 44],
    568                        hParametricStereoDec->hHybrid->mQmfBufferImag[i],
    569                        HYBRID_FILTER_LENGTH_m_1*sizeof(*hParametricStereoDec->hHybrid->mQmfBufferImag));
    570             j += 88;
    571         }
    572 
    573         pv_memset((void *)&qmf_PS_generated_Real[hParametricStereoDec->usb],
    574                   0,
    575                   (64 - hParametricStereoDec->usb)*sizeof(*qmf_PS_generated_Real));
    576 
    577         pv_memset((void *)&qmf_PS_generated_Imag[hParametricStereoDec->usb],
    578                   0,
    579                   (64 - hParametricStereoDec->usb)*sizeof(*qmf_PS_generated_Imag));
    580 
    581 
    582         for (i = 0; i < 32; i++)
    583         {
    584             if (i == (Int)hParametricStereoDec-> aEnvStartStop[env])
    585             {
    586                 ps_init_stereo_mixing(hParametricStereoDec, env, sbrDec->highSubband);
    587                 env++;
    588             }
    589 
    590 
    591             ps_applied(hParametricStereoDec,
    592                        &hParametricStereoDec->qmfBufferReal[i],
    593                        &hParametricStereoDec->qmfBufferImag[i],
    594                        qmf_PS_generated_Real,
    595                        qmf_PS_generated_Imag,
    596                        scratch_mem[2],
    597                        i);
    598 
    599             /* Create time samples for regular mono channel */
    600 
    601             if (pVars->mc_info.bDownSampledSbr)
    602             {
    603                 calc_sbr_synfilterbank(hParametricStereoDec->qmfBufferReal[i],  /* realSamples  */
    604                                        hParametricStereoDec->qmfBufferImag[i], /* imagSamples  */
    605                                        ftimeOutPtr + (i << 6),
    606                                        &circular_buffer_s[1984 - (i<<6)],
    607                                        pVars->mc_info.bDownSampledSbr);
    608             }
    609             else
    610             {
    611                 calc_sbr_synfilterbank(hParametricStereoDec->qmfBufferReal[i],  /* realSamples  */
    612                                        hParametricStereoDec->qmfBufferImag[i], /* imagSamples  */
    613                                        ftimeOutPtr + (i << 7),
    614                                        &circular_buffer_s[3968 - (i<<7)],
    615                                        pVars->mc_info.bDownSampledSbr);
    616 
    617             }
    618 
    619             pv_memmove(hParametricStereoDec->qmfBufferReal[i], qmf_PS_generated_Real, 64*sizeof(*qmf_PS_generated_Real));
    620             pv_memmove(hParametricStereoDec->qmfBufferImag[i], qmf_PS_generated_Imag, 64*sizeof(*qmf_PS_generated_Real));
    621 
    622         }
    623 
    624 
    625         /*
    626          *  Save Circular buffer history used on PS hybrid analysis
    627          */
    628 
    629         for (i = 0, j = 0; i < 3; i++)
    630         {
    631             pv_memmove(hParametricStereoDec->hHybrid->mQmfBufferReal[i],
    632                        &scratch_mem[2][ 64 + j     ],
    633                        HYBRID_FILTER_LENGTH_m_1*sizeof(*hParametricStereoDec->hHybrid->mQmfBufferReal));
    634 
    635             pv_memmove(hParametricStereoDec->hHybrid->mQmfBufferImag[i],
    636                        &scratch_mem[2][ 64 + j + 44],
    637                        HYBRID_FILTER_LENGTH_m_1*sizeof(*hParametricStereoDec->hHybrid->mQmfBufferImag));
    638 
    639             j += 88;
    640         }
    641 
    642         pv_memmove(hFrameData->V, &circular_buffer_s[0], 1152*sizeof(*circular_buffer_s));
    643 
    644         /*
    645          *  Set circular buffer for Right channel
    646          */
    647 
    648         circular_buffer_s = (Int16 *)scratch_mem[5];
    649 
    650         if (pVars->mc_info.bDownSampledSbr)
    651         {
    652             pv_memmove(&circular_buffer_s[2048],
    653                        (int32_t *)hParametricStereoDec->R_ch_qmf_filter_history,
    654                        640*sizeof(*circular_buffer_s));
    655         }
    656         else
    657         {
    658             pv_memmove(&circular_buffer_s[4096],
    659                        (int32_t *)hParametricStereoDec->R_ch_qmf_filter_history,
    660                        1152*sizeof(*circular_buffer_s));
    661 
    662         }
    663 
    664 
    665         for (i = 0; i < 32; i++)
    666         {
    667             if (pVars->mc_info.bDownSampledSbr)
    668             {
    669 
    670                 calc_sbr_synfilterbank(hParametricStereoDec->qmfBufferReal[i],  /* realSamples  */
    671                                        hParametricStereoDec->qmfBufferImag[i], /* imagSamples  */
    672                                        ftimeOutPtrPS + (i << 6),
    673                                        &circular_buffer_s[1984 - (i<<6)],
    674                                        pVars->mc_info.bDownSampledSbr);
    675             }
    676             else
    677             {
    678                 calc_sbr_synfilterbank(hParametricStereoDec->qmfBufferReal[i],  /* realSamples  */
    679                                        hParametricStereoDec->qmfBufferImag[i], /* imagSamples  */
    680                                        ftimeOutPtrPS + (i << 7),
    681                                        &circular_buffer_s[3968 - (i<<7)],
    682                                        pVars->mc_info.bDownSampledSbr);
    683             }
    684 
    685         }
    686 
    687         if (pVars->mc_info.bDownSampledSbr)
    688         {
    689             pv_memmove((int32_t *)hParametricStereoDec->R_ch_qmf_filter_history, &circular_buffer_s[0], 640*sizeof(*circular_buffer_s));
    690         }
    691         else
    692         {
    693             pv_memmove((int32_t *)hParametricStereoDec->R_ch_qmf_filter_history, &circular_buffer_s[0], 1152*sizeof(*circular_buffer_s));
    694         }
    695 
    696 
    697 
    698 
    699 
    700     }
    701     else    /*  else -- sbrEnablePS  */
    702     {
    703 
    704 #endif      /*   PARAMETRICSTEREO */
    705 #endif      /*   HQ_SBR */
    706 
    707         /*
    708          *  Use shared aac memory as continuous buffer
    709          */
    710 
    711 
    712         Sr  = scratch_mem[0];
    713         Si  = scratch_mem[1];
    714 
    715         circular_buffer_s = (Int16*)scratch_mem[2];
    716 
    717         if (pVars->mc_info.bDownSampledSbr)
    718         {
    719 
    720             pv_memmove(&circular_buffer_s[2048],
    721                        hFrameData->V,
    722                        640*sizeof(*circular_buffer_s));
    723         }
    724         else
    725         {
    726             pv_memmove(&circular_buffer_s[4096],
    727                        hFrameData->V,
    728                        1152*sizeof(*circular_buffer_s));
    729         }
    730 
    731         for (i = 0; i < 32; i++)
    732         {
    733             Int   xoverBand;
    734 
    735             if (applyProcessing)
    736             {
    737                 if (i < ((hFrameData->frameInfo[1]) << 1))
    738                 {
    739                     xoverBand = sbrDec->prevLowSubband;
    740 
    741                 }
    742                 else
    743                 {
    744                     xoverBand = sbrDec->lowSubband;
    745                 }
    746 
    747                 if (xoverBand > sbrDec->highSubband)
    748                 {
    749                     xoverBand = 32; /* error condition, default to upsampling mode */
    750                 }
    751             }
    752             else
    753             {
    754                 xoverBand = 32;
    755                 sbrDec->highSubband = 32;
    756             }
    757 
    758 
    759             m = sbrDec->bufReadOffs + i;    /* sbrDec->bufReadOffs == 2 */
    760 
    761 
    762             ptr_tmp1 = (hFrameData->codecQmfBufferReal[m]);
    763             ptr_tmp2 = Sr;
    764 
    765             if (sbrDec->LC_aacP_DecoderFlag == ON)
    766             {
    767 
    768                 for (k = (xoverBand >> 1); k != 0; k--)
    769                 {
    770                     *(ptr_tmp2++) = (*(ptr_tmp1++)) >> 9;
    771                     *(ptr_tmp2++) = (*(ptr_tmp1++)) >> 9;
    772                 }
    773                 if (xoverBand & 1)
    774                 {
    775                     *(ptr_tmp2++) = (*(ptr_tmp1)) >> 9;
    776                 }
    777 
    778                 ptr_tmp1 = &hFrameData->sbrQmfBufferReal[i*SBR_NUM_BANDS];
    779 
    780 
    781                 for (k = xoverBand; k < sbrDec->highSubband; k++)
    782                 {
    783                     *(ptr_tmp2++) = (*(ptr_tmp1++)) << 1;
    784                 }
    785 
    786                 pv_memset((void *)ptr_tmp2,
    787                           0,
    788                           (64 - sbrDec->highSubband)*sizeof(*ptr_tmp2));
    789 
    790 
    791                 if (pVars->mc_info.bDownSampledSbr)
    792                 {
    793                     calc_sbr_synfilterbank_LC(Sr,               /* realSamples  */
    794                                               ftimeOutPtr + (i << 6),
    795                                               &circular_buffer_s[1984 - (i<<6)],
    796                                               pVars->mc_info.bDownSampledSbr);
    797                 }
    798                 else
    799                 {
    800                     calc_sbr_synfilterbank_LC(Sr,               /* realSamples  */
    801                                               ftimeOutPtr + (i << 7),
    802                                               &circular_buffer_s[3968 - (i<<7)],
    803                                               pVars->mc_info.bDownSampledSbr);
    804                 }
    805             }
    806 #ifdef HQ_SBR
    807             else
    808             {
    809 
    810                 for (k = xoverBand; k != 0; k--)
    811                 {
    812                     *(ptr_tmp2++) = shft_lft_1(*(ptr_tmp1++));
    813                 }
    814 
    815                 ptr_tmp1 = &hFrameData->sbrQmfBufferReal[i*SBR_NUM_BANDS];
    816                 ptr_tmp2 = &Sr[xoverBand];
    817 
    818 
    819                 for (k = xoverBand; k < sbrDec->highSubband; k++)
    820                 {
    821                     *(ptr_tmp2++) = (*(ptr_tmp1++));
    822                 }
    823 
    824                 pv_memset((void *)ptr_tmp2,
    825                           0,
    826                           (64 - sbrDec->highSubband)*sizeof(*ptr_tmp2));
    827 
    828 
    829                 ptr_tmp1 = (hFrameData->codecQmfBufferImag[m]);
    830                 ptr_tmp2 = Si;
    831 
    832                 for (k = (xoverBand >> 1); k != 0; k--)
    833                 {
    834                     *(ptr_tmp2++) = shft_lft_1(*(ptr_tmp1++));
    835                     *(ptr_tmp2++) = shft_lft_1(*(ptr_tmp1++));
    836                 }
    837                 if (xoverBand & 1)
    838                 {
    839                     *(ptr_tmp2) = shft_lft_1(*(ptr_tmp1));
    840                 }
    841 
    842                 ptr_tmp1 = &hFrameData->sbrQmfBufferImag[i*SBR_NUM_BANDS];
    843                 ptr_tmp2 = &Si[xoverBand];
    844 
    845                 for (k = xoverBand; k < sbrDec->highSubband; k++)
    846                 {
    847                     *(ptr_tmp2++) = (*(ptr_tmp1++));
    848                 }
    849 
    850                 pv_memset((void *)ptr_tmp2,
    851                           0,
    852                           (64 - sbrDec->highSubband)*sizeof(*ptr_tmp2));
    853 
    854 
    855                 if (pVars->mc_info.bDownSampledSbr)
    856                 {
    857                     calc_sbr_synfilterbank(Sr,              /* realSamples  */
    858                                            Si,             /* imagSamples  */
    859                                            ftimeOutPtr + (i << 6),
    860                                            &circular_buffer_s[1984 - (i<<6)],
    861                                            pVars->mc_info.bDownSampledSbr);
    862                 }
    863                 else
    864                 {
    865                     calc_sbr_synfilterbank(Sr,              /* realSamples  */
    866                                            Si,             /* imagSamples  */
    867                                            ftimeOutPtr + (i << 7),
    868                                            &circular_buffer_s[3968 - (i<<7)],
    869                                            pVars->mc_info.bDownSampledSbr);
    870                 }
    871             }
    872 #endif
    873 
    874         }
    875 
    876         if (pVars->mc_info.bDownSampledSbr)
    877         {
    878             pv_memmove(hFrameData->V, &circular_buffer_s[0], 640*sizeof(*circular_buffer_s));
    879         }
    880         else
    881         {
    882             pv_memmove(hFrameData->V, &circular_buffer_s[0], 1152*sizeof(*circular_buffer_s));
    883         }
    884 
    885 
    886 
    887 
    888         /*
    889          *    Update Buffers
    890          */
    891         for (i = 0; i < sbrDec->bufWriteOffs; i++)     /* sbrDec->bufWriteOffs set to 8 and unchanged */
    892         {
    893             j = sbrDec->noCols + i;                    /* sbrDec->noCols set to 32 and unchanged */
    894 
    895             pv_memmove(hFrameData->codecQmfBufferReal[i],         /* to    */
    896                        hFrameData->codecQmfBufferReal[j],        /* from  */
    897                        sizeof(*hFrameData->codecQmfBufferReal[i]) << 5);
    898         }
    899 
    900 
    901         pv_memmove(&hFrameData->HistsbrQmfBufferReal[0],
    902                    &hFrameData->sbrQmfBufferReal[32*SBR_NUM_BANDS],
    903                    6*SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferReal));
    904 
    905 #ifdef HQ_SBR
    906         if (sbrDec->LC_aacP_DecoderFlag == OFF)
    907         {
    908             for (i = 0; i < sbrDec->bufWriteOffs; i++)     /* sbrDec->bufWriteOffs set to 6 and unchanged */
    909             {
    910                 j = sbrDec->noCols + i;                    /* sbrDec->noCols set to 32 and unchanged */
    911 
    912 
    913                 pv_memmove(hFrameData->codecQmfBufferImag[i],
    914                            hFrameData->codecQmfBufferImag[j],
    915                            sizeof(*hFrameData->codecQmfBufferImag[i]) << 5);
    916 
    917             }
    918 
    919             pv_memmove(&hFrameData->HistsbrQmfBufferImag[0],
    920                        &hFrameData->sbrQmfBufferImag[32*SBR_NUM_BANDS],
    921                        6*SBR_NUM_BANDS*sizeof(*hFrameData->sbrQmfBufferImag));
    922         }
    923 #endif
    924 
    925 
    926 #ifdef HQ_SBR
    927 #ifdef PARAMETRICSTEREO
    928     }
    929 #endif
    930 #endif
    931 
    932 
    933     hFrameData->reset_flag = 0;
    934     if (applyProcessing)
    935     {
    936         sbrDec->prevLowSubband = sbrDec->lowSubband;
    937     }
    938 
    939 }
    940 
    941 
    942 #endif      /*  AAC_PLUS */
    943