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: mdst.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     Int32 x             32-bit integer input length 64
     33 
     34 
     35 ------------------------------------------------------------------------------
     36  FUNCTION DESCRIPTION
     37 
     38     mdst
     39 
     40 ------------------------------------------------------------------------------
     41  REQUIREMENTS
     42 
     43 
     44 ------------------------------------------------------------------------------
     45  REFERENCES
     46 
     47 ------------------------------------------------------------------------------
     48  PSEUDO-CODE
     49 
     50 ------------------------------------------------------------------------------
     51 */
     52 
     53 
     54 /*----------------------------------------------------------------------------
     55 ; INCLUDES
     56 ----------------------------------------------------------------------------*/
     57 
     58 #ifdef AAC_PLUS
     59 
     60 #include "pv_audio_type_defs.h"
     61 #include "synthesis_sub_band.h"
     62 #include "dct16.h"
     63 #include "dct64.h"
     64 #include "mdst.h"
     65 
     66 #ifdef HQ_SBR
     67 
     68 
     69 /*----------------------------------------------------------------------------
     70 ; MACROS
     71 ; Define module specific macros here
     72 ----------------------------------------------------------------------------*/
     73 
     74 
     75 /*----------------------------------------------------------------------------
     76 ; DEFINES
     77 ; Include all pre-processor statements here. Include conditional
     78 ; compile variables also.
     79 ----------------------------------------------------------------------------*/
     80 
     81 #include "fxp_mul32.h"
     82 #include "dst32.h"
     83 
     84 
     85 #define Qfmt1(a)   (Int32)(a*0x7FFFFFFF + (a>=0?0.5F:-0.5F))
     86 #define Qfmt(a)   (Int32)(a*((Int32)1<<27) + (a>=0?0.5F:-0.5F))
     87 
     88 const Int32 CosTable_32[32] =
     89 {
     90     Qfmt1(0.50015063602065F),  Qfmt1(0.50135845244641F),
     91     Qfmt1(0.50378872568104F),  Qfmt1(0.50747117207256F),
     92     Qfmt1(0.51245147940822F),  Qfmt1(0.51879271310533F),
     93     Qfmt1(0.52657731515427F),  Qfmt1(0.53590981690799F),
     94     Qfmt1(0.54692043798551F),  Qfmt1(0.55976981294708F),
     95     Qfmt1(0.57465518403266F),  Qfmt1(0.59181853585742F),
     96     Qfmt1(0.61155734788251F),  Qfmt1(0.63423893668840F),
     97     Qfmt1(0.66031980781371F),  Qfmt1(0.69037212820021F),
     98     Qfmt1(0.72512052237720F),  Qfmt1(0.76549416497309F),
     99     Qfmt1(0.81270209081449F),  Qfmt1(0.86834471522335F),
    100     Qfmt(0.93458359703641F),  Qfmt(1.01440826499705F),
    101     Qfmt(1.11207162057972F),  Qfmt(1.23383273797657F),
    102     Qfmt(1.38929395863283F),  Qfmt(1.59397228338563F),
    103     Qfmt(1.87467598000841F),  Qfmt(2.28205006800516F),
    104     Qfmt(2.92462842815822F),  Qfmt(4.08461107812925F),
    105     Qfmt(6.79675071167363F),  Qfmt(10.18693908361573F)
    106 };
    107 
    108 
    109 
    110 /*----------------------------------------------------------------------------
    111 ; LOCAL FUNCTION DEFINITIONS
    112 ; Function Prototype declaration
    113 ----------------------------------------------------------------------------*/
    114 
    115 /*----------------------------------------------------------------------------
    116 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    117 ; Variable declaration - defined here and used outside this module
    118 ----------------------------------------------------------------------------*/
    119 
    120 /*----------------------------------------------------------------------------
    121 ; EXTERNAL FUNCTION REFERENCES
    122 ; Declare functions defined elsewhere and referenced in this module
    123 ----------------------------------------------------------------------------*/
    124 
    125 /*----------------------------------------------------------------------------
    126 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    127 ; Declare variables used in this module but defined elsewhere
    128 ----------------------------------------------------------------------------*/
    129 
    130 /*----------------------------------------------------------------------------
    131 ; FUNCTION CODE
    132 ----------------------------------------------------------------------------*/
    133 
    134 /*----------------------------------------------------------------------------
    135 ; mdst_32
    136 ----------------------------------------------------------------------------*/
    137 
    138 void mdst_32(Int32 vec[], Int32 scratch_mem[])
    139 {
    140 
    141     Int i;
    142     const Int32 *pt_cos = CosTable_32;
    143     Int32 *pt_vec = vec;
    144     Int32 tmp1;
    145     Int32 tmp2;
    146 
    147 
    148 
    149     Int32 tmp3;
    150 
    151     tmp3 = *(pt_vec++);
    152     tmp2 = *(pt_vec);
    153 
    154     for (i = 5; i != 0; i--)
    155     {
    156         *(pt_vec++)  += tmp3;
    157         tmp1 = *(pt_vec);
    158         *(pt_vec++)  += tmp2;
    159         tmp3 = *(pt_vec);
    160         *(pt_vec++)  += tmp1;
    161         tmp2 = *(pt_vec);
    162         *(pt_vec++)  += tmp3;
    163         tmp1 = *(pt_vec);
    164         *(pt_vec++)  += tmp2;
    165         tmp3 = *(pt_vec);
    166         *(pt_vec++)  += tmp1;
    167         tmp2 = *(pt_vec);
    168     }
    169 
    170     *(pt_vec)  += tmp3;
    171 
    172     dst_32(vec, scratch_mem);
    173 
    174     pt_vec = vec;
    175 
    176     for (i = 5; i != 0; i--)
    177     {
    178         *(pt_vec)   = fxp_mul32_Q31((*(pt_vec) << 1) + tmp2, *(pt_cos++));
    179         pt_vec++;
    180         *(pt_vec)   = fxp_mul32_Q31((*(pt_vec) << 1) - tmp2, *(pt_cos++));
    181         pt_vec++;
    182         *(pt_vec)   = fxp_mul32_Q31((*(pt_vec) << 1) + tmp2, *(pt_cos++));
    183         pt_vec++;
    184         *(pt_vec)   = fxp_mul32_Q31((*(pt_vec) << 1) - tmp2, *(pt_cos++));
    185         pt_vec++;
    186     }
    187 
    188     tmp2 >>= 1;
    189     for (i = 3; i != 0; i--)
    190     {
    191         *(pt_vec)   = fxp_mul32_Q27((*(pt_vec) + tmp2), *(pt_cos++));
    192         pt_vec++;
    193         *(pt_vec)   = fxp_mul32_Q27((*(pt_vec) - tmp2), *(pt_cos++));
    194         pt_vec++;
    195         *(pt_vec)   = fxp_mul32_Q27((*(pt_vec) + tmp2), *(pt_cos++));
    196         pt_vec++;
    197         *(pt_vec)   = fxp_mul32_Q27((*(pt_vec) - tmp2), *(pt_cos++));
    198         pt_vec++;
    199     }
    200 
    201     *(pt_vec - 1)   <<= 1;
    202 
    203 }
    204 
    205 
    206 
    207 /*----------------------------------------------------------------------------
    208 ; mdct_32
    209 ----------------------------------------------------------------------------*/
    210 
    211 void mdct_32(Int32 vec[])
    212 {
    213     Int i;
    214     Int32 *pt_vec  = vec;
    215     Int32 tmp1, tmp2;
    216 
    217 
    218     const Int32 *pt_CosTable = CosTable_32;
    219 
    220 
    221     for (i = 5; i != 0; i--)
    222     {
    223         *(pt_vec) = fxp_mul32_Q31(*(pt_vec) << 1, *(pt_CosTable++));
    224         pt_vec++;
    225         *(pt_vec) = fxp_mul32_Q31(*(pt_vec) << 1, *(pt_CosTable++));
    226         pt_vec++;
    227         *(pt_vec) = fxp_mul32_Q31(*(pt_vec) << 1, *(pt_CosTable++));
    228         pt_vec++;
    229         *(pt_vec) = fxp_mul32_Q31(*(pt_vec) << 1, *(pt_CosTable++));
    230         pt_vec++;
    231     }
    232     for (i = 3; i != 0; i--)
    233     {
    234         *(pt_vec) = fxp_mul32_Q27(*(pt_vec), *(pt_CosTable++));
    235         pt_vec++;
    236         *(pt_vec) = fxp_mul32_Q27(*(pt_vec), *(pt_CosTable++));
    237         pt_vec++;
    238         *(pt_vec) = fxp_mul32_Q27(*(pt_vec), *(pt_CosTable++));
    239         pt_vec++;
    240         *(pt_vec) = fxp_mul32_Q27(*(pt_vec), *(pt_CosTable++));
    241         pt_vec++;
    242     }
    243     *(pt_vec - 1)   <<= 1;
    244 
    245 
    246     dct_32(vec);
    247 
    248 
    249     pt_vec  = &vec[31];
    250 
    251     tmp1 = *(pt_vec--);
    252 
    253     for (i = 5; i != 0; i--)
    254     {
    255         tmp2 = *(pt_vec);
    256         *(pt_vec--)  += tmp1;
    257         tmp1 = *(pt_vec);
    258         *(pt_vec--)  += tmp2;
    259         tmp2 = *(pt_vec);
    260         *(pt_vec--)  += tmp1;
    261         tmp1 = *(pt_vec);
    262         *(pt_vec--)  += tmp2;
    263         tmp2 = *(pt_vec);
    264         *(pt_vec--)  += tmp1;
    265         tmp1 = *(pt_vec);
    266         *(pt_vec--)  += tmp2;
    267     }
    268 
    269     *(pt_vec)  += tmp1;
    270 
    271 }
    272 
    273 #endif /*  HQ_SBR  */
    274 
    275 
    276 /*----------------------------------------------------------------------------
    277 ; dct_32
    278 ----------------------------------------------------------------------------*/
    279 
    280 
    281 void dct_32(Int32 vec[])
    282 {
    283 
    284     pv_split(&vec[16]);
    285 
    286     dct_16(&vec[16], 0);
    287     dct_16(vec, 1);     // Even terms
    288 
    289     pv_merge_in_place_N32(vec);
    290 }
    291 
    292 #endif  /* AAC_PLUS */
    293 
    294 
    295