Home | History | Annotate | Download | only in src
      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 
     21    PacketVideo Corp.
     22    MP3 Decoder Library
     23 
     24    Filename: pvmp3_dct_16.cpp
     25 
     26    Functions:
     27     dct_16
     28     pv_merge_in_place_N32
     29     pv_split
     30 
     31      Date: 09/21/2007
     32 
     33 ------------------------------------------------------------------------------
     34  REVISION HISTORY
     35 
     36 
     37  Description:
     38 
     39 ------------------------------------------------------------------------------
     40  INPUT AND OUTPUT DEFINITIONS
     41 
     42     dct_16
     43 
     44 Input
     45     int32 vec[],        input vector length 16
     46     Int flag            processing direction: forward (1), backward ( 0)
     47  Returns
     48 
     49     int32 vec[],        dct length 16
     50 
     51 ------------------------------------------------------------------------------
     52  INPUT AND OUTPUT DEFINITIONS
     53 
     54     pv_merge_in_place_N32
     55 
     56 Input
     57     int32 vec[],        input vector length 16
     58 
     59  Returns
     60 
     61     int32 vec[],        merged  output of two dct 16 to create a dct 32
     62 
     63 ------------------------------------------------------------------------------
     64  INPUT AND OUTPUT DEFINITIONS
     65 
     66     pv_split
     67 
     68 Input
     69     int32 vec[],        input vector length 16
     70 
     71  Returns
     72 
     73     int32 vec[],        splitted even/odd and pre processing rotation
     74 
     75 ------------------------------------------------------------------------------
     76  FUNCTION DESCRIPTION
     77 
     78     dct 16 and tools to assemble a dct32 output
     79 
     80 ------------------------------------------------------------------------------
     81  REQUIREMENTS
     82 
     83 
     84 ------------------------------------------------------------------------------
     85  REFERENCES
     86 
     87 ------------------------------------------------------------------------------
     88  PSEUDO-CODE
     89 
     90 ------------------------------------------------------------------------------
     91 */
     92 
     93 #if ( !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) )
     94 /*----------------------------------------------------------------------------
     95 ; INCLUDES
     96 ----------------------------------------------------------------------------*/
     97 
     98 #include "pvmp3_dct_16.h"
     99 #include "pv_mp3dec_fxd_op.h"
    100 
    101 /*----------------------------------------------------------------------------
    102 ; MACROS
    103 ; Define module specific macros here
    104 ----------------------------------------------------------------------------*/
    105 
    106 
    107 /*----------------------------------------------------------------------------
    108 ; DEFINES
    109 ; Include all pre-processor statements here. Include conditional
    110 ; compile variables also.
    111 ----------------------------------------------------------------------------*/
    112 #define Qfmt(a)   (int32)(a*((int32)1<<27))
    113 
    114 /*----------------------------------------------------------------------------
    115 ; LOCAL FUNCTION DEFINITIONS
    116 ; Function Prototype declaration
    117 ----------------------------------------------------------------------------*/
    118 
    119 /*----------------------------------------------------------------------------
    120 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    121 ; Variable declaration - defined here and used outside this module
    122 ----------------------------------------------------------------------------*/
    123 const int32 CosTable_dct32[16] =
    124 {
    125     Qfmt_31(0.50060299823520F) ,  Qfmt_31(0.50547095989754F) ,
    126     Qfmt_31(0.51544730992262F) ,  Qfmt_31(0.53104259108978F) ,
    127     Qfmt_31(0.55310389603444F) ,  Qfmt_31(0.58293496820613F) ,
    128     Qfmt_31(0.62250412303566F) ,  Qfmt_31(0.67480834145501F) ,
    129     Qfmt_31(0.74453627100230F) ,  Qfmt_31(0.83934964541553F) ,
    130 
    131     Qfmt(0.97256823786196F) ,  Qfmt(1.16943993343288F) ,
    132     Qfmt(1.48416461631417F) ,  Qfmt(2.05778100995341F) ,
    133     Qfmt(3.40760841846872F) ,  Qfmt(10.19000812354803F)
    134 };
    135 
    136 
    137 /*----------------------------------------------------------------------------
    138 ; EXTERNAL FUNCTION REFERENCES
    139 ; Declare functions defined elsewhere and referenced in this module
    140 ----------------------------------------------------------------------------*/
    141 
    142 /*----------------------------------------------------------------------------
    143 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    144 ; Declare variables used in this module but defined elsewhere
    145 ----------------------------------------------------------------------------*/
    146 
    147 
    148 /*----------------------------------------------------------------------------
    149 ; FUNCTION CODE
    150 ----------------------------------------------------------------------------*/
    151 
    152 void pvmp3_dct_16(int32 vec[], int32 flag)
    153 {
    154     int32 tmp0;
    155     int32 tmp1;
    156     int32 tmp2;
    157     int32 tmp3;
    158     int32 tmp4;
    159     int32 tmp5;
    160     int32 tmp6;
    161     int32 tmp7;
    162     int32 tmp_o0;
    163     int32 tmp_o1;
    164     int32 tmp_o2;
    165     int32 tmp_o3;
    166     int32 tmp_o4;
    167     int32 tmp_o5;
    168     int32 tmp_o6;
    169     int32 tmp_o7;
    170     int32 itmp_e0;
    171     int32 itmp_e1;
    172     int32 itmp_e2;
    173 
    174     /*  split input vector */
    175 
    176     tmp_o0 = fxp_mul32_Q32((vec[ 0] - vec[15]), Qfmt_31(0.50241928618816F));
    177     tmp0   =  vec[ 0] + vec[15];
    178 
    179     tmp_o7 = fxp_mul32_Q32((vec[ 7] - vec[ 8]) << 3, Qfmt_31(0.63764357733614F));
    180     tmp7   =  vec[ 7] + vec[ 8];
    181 
    182     itmp_e0    = fxp_mul32_Q32((tmp0 - tmp7), Qfmt_31(0.50979557910416F));
    183     tmp7 = (tmp0 + tmp7);
    184 
    185     tmp_o1 = fxp_mul32_Q32((vec[ 1] - vec[14]), Qfmt_31(0.52249861493969F));
    186     tmp1   =  vec[ 1] + vec[14];
    187 
    188     tmp_o6 = fxp_mul32_Q32((vec[ 6] - vec[ 9]) << 1, Qfmt_31(0.86122354911916F));
    189     tmp6   =  vec[ 6] + vec[ 9];
    190 
    191 
    192 
    193     itmp_e1 = (tmp1 + tmp6);
    194     tmp6    = fxp_mul32_Q32((tmp1 - tmp6), Qfmt_31(0.60134488693505F));
    195 
    196 
    197 
    198     tmp_o2 = fxp_mul32_Q32((vec[ 2] - vec[13]), Qfmt_31(0.56694403481636F));
    199     tmp2   =  vec[ 2] + vec[13];
    200     tmp_o5 = fxp_mul32_Q32((vec[ 5] - vec[10]) << 1, Qfmt_31(0.53033884299517F));
    201     tmp5   =  vec[ 5] + vec[10];
    202 
    203     itmp_e2 = (tmp2 + tmp5);
    204     tmp5    = fxp_mul32_Q32((tmp2 - tmp5), Qfmt_31(0.89997622313642F));
    205 
    206     tmp_o3 = fxp_mul32_Q32((vec[ 3] - vec[12]), Qfmt_31(0.64682178335999F));
    207     tmp3   =  vec[ 3] + vec[12];
    208     tmp_o4 = fxp_mul32_Q32((vec[ 4] - vec[11]), Qfmt_31(0.78815462345125F));
    209     tmp4   =  vec[ 4] + vec[11];
    210 
    211     tmp1   = (tmp3 + tmp4);
    212     tmp4   =  fxp_mul32_Q32((tmp3 - tmp4) << 2, Qfmt_31(0.64072886193538F));
    213 
    214     /*  split even part of tmp_e */
    215 
    216     tmp0 = (tmp7 + tmp1);
    217     tmp1 = fxp_mul32_Q32((tmp7 - tmp1), Qfmt_31(0.54119610014620F));
    218 
    219     tmp3 = fxp_mul32_Q32((itmp_e1 - itmp_e2) << 1, Qfmt_31(0.65328148243819F));
    220     tmp7 = (itmp_e1 + itmp_e2);
    221 
    222     vec[ 0]  = (tmp0 + tmp7) >> 1;
    223     vec[ 8]  = fxp_mul32_Q32((tmp0 - tmp7), Qfmt_31(0.70710678118655F));
    224     tmp0     = fxp_mul32_Q32((tmp1 - tmp3) << 1, Qfmt_31(0.70710678118655F));
    225     vec[ 4]  =  tmp1 + tmp3 + tmp0;
    226     vec[12]  =  tmp0;
    227 
    228     /*  split odd part of tmp_e */
    229 
    230     tmp1 = fxp_mul32_Q32((itmp_e0 - tmp4) << 1, Qfmt_31(0.54119610014620F));
    231     tmp7 = itmp_e0 + tmp4;
    232 
    233     tmp3  = fxp_mul32_Q32((tmp6 - tmp5) << 2, Qfmt_31(0.65328148243819F));
    234     tmp6 += tmp5;
    235 
    236     tmp4  = fxp_mul32_Q32((tmp7 - tmp6) << 1, Qfmt_31(0.70710678118655F));
    237     tmp6 += tmp7;
    238     tmp7  = fxp_mul32_Q32((tmp1 - tmp3) << 1, Qfmt_31(0.70710678118655F));
    239 
    240     tmp1    +=  tmp3 + tmp7;
    241     vec[ 2]  =  tmp1 + tmp6;
    242     vec[ 6]  =  tmp1 + tmp4;
    243     vec[10]  =  tmp7 + tmp4;
    244     vec[14]  =  tmp7;
    245 
    246 
    247     // dct8;
    248 
    249     tmp1 = fxp_mul32_Q32((tmp_o0 - tmp_o7) << 1, Qfmt_31(0.50979557910416F));
    250     tmp7 = tmp_o0 + tmp_o7;
    251 
    252     tmp6   = tmp_o1 + tmp_o6;
    253     tmp_o1 = fxp_mul32_Q32((tmp_o1 - tmp_o6) << 1, Qfmt_31(0.60134488693505F));
    254 
    255     tmp5   = tmp_o2 + tmp_o5;
    256     tmp_o5 = fxp_mul32_Q32((tmp_o2 - tmp_o5) << 1, Qfmt_31(0.89997622313642F));
    257 
    258     tmp0 = fxp_mul32_Q32((tmp_o3 - tmp_o4) << 3, Qfmt_31(0.6407288619354F));
    259     tmp4 = tmp_o3 + tmp_o4;
    260 
    261     if (!flag)
    262     {
    263         tmp7   = -tmp7;
    264         tmp1   = -tmp1;
    265         tmp6   = -tmp6;
    266         tmp_o1 = -tmp_o1;
    267         tmp5   = -tmp5;
    268         tmp_o5 = -tmp_o5;
    269         tmp4   = -tmp4;
    270         tmp0   = -tmp0;
    271     }
    272 
    273 
    274     tmp2     =  fxp_mul32_Q32((tmp1 -   tmp0) << 1, Qfmt_31(0.54119610014620F));
    275     tmp0    +=  tmp1;
    276     tmp1     =  fxp_mul32_Q32((tmp7 -   tmp4) << 1, Qfmt_31(0.54119610014620F));
    277     tmp7    +=  tmp4;
    278     tmp4     =  fxp_mul32_Q32((tmp6 -   tmp5) << 2, Qfmt_31(0.65328148243819F));
    279     tmp6    +=  tmp5;
    280     tmp5     =  fxp_mul32_Q32((tmp_o1 - tmp_o5) << 2, Qfmt_31(0.65328148243819F));
    281     tmp_o1  += tmp_o5;
    282 
    283 
    284     vec[13]  =  fxp_mul32_Q32((tmp1 -   tmp4) << 1, Qfmt_31(0.70710678118655F));
    285     vec[ 5]  =  tmp1 + tmp4 + vec[13];
    286 
    287     vec[ 9]  =  fxp_mul32_Q32((tmp7 -   tmp6) << 1, Qfmt_31(0.70710678118655F));
    288     vec[ 1]  =  tmp7 + tmp6;
    289 
    290     tmp4     =  fxp_mul32_Q32((tmp0 - tmp_o1) << 1, Qfmt_31(0.70710678118655F));
    291     tmp0    +=  tmp_o1;
    292     tmp6     =  fxp_mul32_Q32((tmp2 -   tmp5) << 1, Qfmt_31(0.70710678118655F));
    293     tmp2    +=  tmp5 + tmp6;
    294     tmp0    +=  tmp2;
    295 
    296     vec[ 1] += tmp0;
    297     vec[ 3]  = tmp0 + vec[ 5];
    298     tmp2    += tmp4;
    299     vec[ 5]  = tmp2 + vec[ 5];
    300     vec[ 7]  = tmp2 + vec[ 9];
    301     tmp4    += tmp6;
    302     vec[ 9]  = tmp4 + vec[ 9];
    303     vec[11]  = tmp4 + vec[13];
    304     vec[13]  = tmp6 + vec[13];
    305     vec[15]  = tmp6;
    306 
    307 }
    308 /*----------------------------------------------------------------------------
    309 ; FUNCTION CODE
    310 ----------------------------------------------------------------------------*/
    311 void pvmp3_merge_in_place_N32(int32 vec[])
    312 {
    313 
    314 
    315     int32 temp0;
    316     int32 temp1;
    317     int32 temp2;
    318     int32 temp3;
    319 
    320     temp0   = vec[14];
    321     vec[14] = vec[ 7];
    322     temp1   = vec[12];
    323     vec[12] = vec[ 6];
    324     temp2   = vec[10];
    325     vec[10] = vec[ 5];
    326     temp3   = vec[ 8];
    327     vec[ 8] = vec[ 4];
    328     vec[ 6] = vec[ 3];
    329     vec[ 4] = vec[ 2];
    330     vec[ 2] = vec[ 1];
    331 
    332     vec[ 1] = (vec[16] + vec[17]);
    333     vec[16] = temp3;
    334     vec[ 3] = (vec[18] + vec[17]);
    335     vec[ 5] = (vec[19] + vec[18]);
    336     vec[18] = vec[9];
    337 
    338     vec[ 7] = (vec[20] + vec[19]);
    339     vec[ 9] = (vec[21] + vec[20]);
    340     vec[20] = temp2;
    341     temp2   = vec[13];
    342     temp3   = vec[11];
    343     vec[11] = (vec[22] + vec[21]);
    344     vec[13] = (vec[23] + vec[22]);
    345     vec[22] = temp3;
    346     temp3   = vec[15];
    347 
    348     vec[15] = (vec[24] + vec[23]);
    349     vec[17] = (vec[25] + vec[24]);
    350     vec[19] = (vec[26] + vec[25]);
    351     vec[21] = (vec[27] + vec[26]);
    352     vec[23] = (vec[28] + vec[27]);
    353     vec[24] = temp1;
    354     vec[25] = (vec[29] + vec[28]);
    355     vec[26] = temp2;
    356     vec[27] = (vec[30] + vec[29]);
    357     vec[28] = temp0;
    358     vec[29] = (vec[30] + vec[31]);
    359     vec[30] = temp3;
    360 }
    361 
    362 
    363 /*----------------------------------------------------------------------------
    364 ; FUNCTION CODE
    365 ----------------------------------------------------------------------------*/
    366 
    367 
    368 
    369 void pvmp3_split(int32 *vect)
    370 {
    371 
    372     int32 i;
    373     const int32 *pt_cosTerms = &CosTable_dct32[15];
    374     int32 *pt_vect   = vect;
    375     int32 *pt_vect_2 = pt_vect - 1;
    376 
    377     for (i = 3; i != 0; i--)
    378     {
    379         int32 tmp2 = *(pt_vect);
    380         int32 tmp1 = *(pt_vect_2);
    381         int32 cosx = *(pt_cosTerms--);
    382         *(pt_vect_2--) = (tmp1  + tmp2);
    383         *(pt_vect++)   = fxp_mul32_Q27((tmp1 - tmp2), cosx);
    384 
    385         tmp2 = *(pt_vect);
    386         tmp1 = *(pt_vect_2);
    387         cosx = *(pt_cosTerms--);
    388         *(pt_vect_2--) = (tmp1  + tmp2);
    389         *(pt_vect++)   = fxp_mul32_Q27((tmp1 - tmp2), cosx);
    390 
    391     }
    392 
    393     for (i = 5; i != 0; i--)
    394     {
    395         int32 tmp2 = *(pt_vect);
    396         int32 tmp1 = *(pt_vect_2);
    397         int32 cosx = *(pt_cosTerms--);
    398         *(pt_vect_2--) = (tmp1  + tmp2);
    399         *(pt_vect++) = fxp_mul32_Q32((tmp1 - tmp2) << 1, cosx);
    400 
    401         tmp2 = *(pt_vect);
    402         tmp1 = *(pt_vect_2);
    403         cosx = *(pt_cosTerms--);
    404         *(pt_vect_2--) = (tmp1  + tmp2);
    405         *(pt_vect++) = fxp_mul32_Q32((tmp1 - tmp2) << 1, cosx);
    406     }
    407 
    408 }
    409 
    410 #endif
    411