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_imdct_synth.cpp
     25 
     26      Date: 09/21/2007
     27 
     28 ------------------------------------------------------------------------------
     29  REVISION HISTORY
     30 
     31 
     32  Description:
     33 
     34 ------------------------------------------------------------------------------
     35  INPUT AND OUTPUT DEFINITIONS
     36 
     37  Input
     38     int32 in[],         Pointer to spec values of current channel
     39     int32 overlap[],    Pointer to overlap values of current channel
     40     uint32 blk_type,    Block type
     41     int16 mx_band,      In case of mixed blocks, # of bands with long
     42                         blocks (2 or 4) else 0
     43     int32 *Scratch_mem
     44   Returns
     45 
     46     int32 in[],
     47 
     48 ------------------------------------------------------------------------------
     49  FUNCTION DESCRIPTION
     50 
     51     The frequency lines are preprocessed by the "alias reduction" scheme
     52     and fed into the IMDCT matrix, each 18 into one transform block.
     53     The first half of the output values are added to the stored overlap
     54     values from the last block. These values are new output values and
     55     are input values for the polyphase filterbank. The second half of the
     56     output values is stored for overlap with the next data granule.
     57     The number of windowed samples is 12 for short blocks, and 36 for long
     58     blocks
     59 
     60 Windowing
     61 
     62     Depending on window_switching_flag[gr][ch], block_type[gr][ch] and
     63     mixed_block_flag[gr][ch] different shapes of windows are used.
     64         normal window
     65         start window
     66         stop window
     67         short windows
     68             Each of the three short blocks is windowed separately.
     69             The windowed short blocks must be overlapped and concatenated.
     70 
     71 Overlapping and adding with previous block
     72 
     73     The first half (18 values) of the current block (36 values) has to be
     74     overlapped with the second half of the previous block. The second half
     75     of the current block has to be stored for overlapping with the next block
     76 
     77 ------------------------------------------------------------------------------
     78  REQUIREMENTS
     79 
     80 
     81 ------------------------------------------------------------------------------
     82  REFERENCES
     83 
     84  [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
     85      ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
     86 
     87 ------------------------------------------------------------------------------
     88  PSEUDO-CODE
     89 
     90 ------------------------------------------------------------------------------
     91 */
     92 
     93 
     94 /*----------------------------------------------------------------------------
     95 ; INCLUDES
     96 ----------------------------------------------------------------------------*/
     97 
     98 #include "pvmp3_imdct_synth.h"
     99 #include "pv_mp3dec_fxd_op.h"
    100 #include "pvmp3_dec_defs.h"
    101 #include "pvmp3_mdct_18.h"
    102 #include "pvmp3_mdct_6.h"
    103 #include "mp3_mem_funcs.h"
    104 
    105 
    106 
    107 /*----------------------------------------------------------------------------
    108 ; MACROS
    109 ; Define module specific macros here
    110 ----------------------------------------------------------------------------*/
    111 
    112 
    113 /*----------------------------------------------------------------------------
    114 ; DEFINES
    115 ; Include all pre-processor statements here. Include conditional
    116 ; compile variables also.
    117 ----------------------------------------------------------------------------*/
    118 #define LONG        0
    119 #define START       1
    120 #define SHORT       2
    121 #define STOP        3
    122 
    123 /*----------------------------------------------------------------------------
    124 ; LOCAL FUNCTION DEFINITIONS
    125 ; Function Prototype declaration
    126 ----------------------------------------------------------------------------*/
    127 
    128 /*----------------------------------------------------------------------------
    129 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    130 ; Variable declaration - defined here and used outside this module
    131 ----------------------------------------------------------------------------*/
    132 /*
    133  *   sin(pi/36*(k+0.5)),k=0..35
    134  */
    135 
    136 const int32 normal_win[36] =
    137 {
    138     Qfmt_31(0.08723877473068f),   Qfmt_31(0.26105238444010f),   Qfmt_31(0.43287922787620f),
    139     Qfmt_31(0.60141159900854f),   Qfmt_31(0.76536686473018f),   Qfmt_31(0.92349722647006f),
    140     Qfmt_31(0.53729960834682f),   Qfmt_31(0.60876142900872f),   Qfmt_31(0.67559020761566f),
    141     Qfmt_31(-0.73727733681012f),   Qfmt_31(-0.79335334029124f),   Qfmt_31(0.84339144581289f),
    142     Qfmt_31(0.88701083317822f),   Qfmt_31(0.92387953251129f),   Qfmt_31(-0.95371695074823f),
    143     Qfmt_31(-0.97629600711993f),   Qfmt_31(-0.99144486137381f),   Qfmt_31(-0.99904822158186f),
    144     Qfmt_31(0.99904822158186f),   Qfmt_31(0.99144486137381f),   Qfmt_31(0.97629600711993f),
    145     Qfmt_31(0.95371695074823f),   Qfmt_31(0.92387953251129f),   Qfmt_31(0.88701083317822f),
    146     Qfmt_31(0.84339144581289f),   Qfmt_31(0.79335334029124f),   Qfmt_31(0.73727733681012f),
    147     Qfmt_31(0.67559020761566f),   Qfmt_31(0.60876142900872f),   Qfmt_31(0.53729960834682f),
    148     Qfmt_31(0.46174861323503f),   Qfmt_31(0.38268343236509f),   Qfmt_31(0.30070579950427f),
    149     Qfmt_31(0.21643961393810f),   Qfmt_31(0.13052619222005f),   Qfmt_31(0.04361938736534f)
    150 };
    151 
    152 
    153 const int32 start_win[36] =
    154 {
    155     /*   k=0..17  sin(pi/36*(k+0.5)),  */
    156     Qfmt_31(0.08723877473068f),   Qfmt_31(0.26105238444010f),   Qfmt_31(0.43287922787620f),
    157     Qfmt_31(0.60141159900854f),   Qfmt_31(0.76536686473018f),   Qfmt_31(0.92349722647006f),
    158     Qfmt_31(0.53729960834682f),   Qfmt_31(0.60876142900872f),   Qfmt_31(0.67559020761566f),
    159     Qfmt_31(-0.73727733681012f),   Qfmt_31(-0.79335334029124f),   Qfmt_31(0.84339144581289f),
    160     Qfmt_31(0.88701083317822f),   Qfmt_31(0.92387953251129f),   Qfmt_31(-0.95371695074823f),
    161     Qfmt_31(-0.97629600711993f),   Qfmt_31(-0.99144486137381f),   Qfmt_31(-0.99904822158186f),
    162 
    163     Qfmt_31(0.99999990000000f),   Qfmt_31(0.99999990000000f),   Qfmt_31(0.99999990000000f),
    164     Qfmt_31(0.99999990000000f),   Qfmt_31(0.99999990000000f),   Qfmt_31(0.99999990000000f),
    165     /*    k=24..29; sin(pi/12*(k-18+0.5)) */
    166     Qfmt_31(0.99144486137381f),   Qfmt_31(0.92387953251129f),   Qfmt_31(0.79335334029124f),
    167     Qfmt_31(0.60876142900872f),   Qfmt_31(0.38268343236509f),   Qfmt_31(0.13052619222005f),
    168 
    169     Qfmt_31(0.00000000000000f),   Qfmt_31(0.00000000000000f),   Qfmt_31(0.00000000000000f),
    170     Qfmt_31(0.00000000000000f),   Qfmt_31(0.00000000000000f),   Qfmt_31(0.00000000000000f)
    171 };
    172 
    173 
    174 const int32 stop_win[36] =
    175 {
    176     Qfmt_31(0.00000000000000f),   Qfmt_31(0.00000000000000f),   Qfmt_31(0.00000000000000f),
    177     Qfmt_31(0.00000000000000f),   Qfmt_31(0.00000000000000f),   Qfmt_31(0.00000000000000f),
    178     /*    k=6..11; sin(pi/12*(k-6+0.5)) */
    179     Qfmt_31(0.13052619222005f),   Qfmt_31(0.38268343236509f),   Qfmt_31(0.60876142900872f),
    180     Qfmt_31(-0.79335334029124f),   Qfmt_31(-0.92387953251129f),   Qfmt_31(0.99144486137381f),
    181 
    182     Qfmt_31(0.99999990000000f),   Qfmt_31(0.99999990000000f),   Qfmt_31(-0.99999990000000f),
    183     Qfmt_31(-0.99999990000000f),   Qfmt_31(-0.99999990000000f),   Qfmt_31(-0.99999990000000f),
    184     /*   k=18..35  sin(pi/36*(k+0.5)),  */
    185     Qfmt_31(0.99904822158186f),   Qfmt_31(0.99144486137381f),   Qfmt_31(0.97629600711993f),
    186     Qfmt_31(0.95371695074823f),   Qfmt_31(0.92387953251129f),   Qfmt_31(0.88701083317822f),
    187     Qfmt_31(0.84339144581289f),   Qfmt_31(0.79335334029124f),   Qfmt_31(0.73727733681012f),
    188     Qfmt_31(0.67559020761566f),   Qfmt_31(0.60876142900872f),   Qfmt_31(0.53729960834682f),
    189     Qfmt_31(0.46174861323503f),   Qfmt_31(0.38268343236509f),   Qfmt_31(0.30070579950427f),
    190     Qfmt_31(0.21643961393810f),   Qfmt_31(0.13052619222005f),   Qfmt_31(0.04361938736534f)
    191 };
    192 
    193 
    194 const int32 short_win[12] =
    195 {
    196     /*    k=0..11; sin(pi/12*(k+0.5)) */
    197     Qfmt_31(0.13052619222005f),   Qfmt_31(0.38268343236509f),   Qfmt_31(0.60876142900872f),
    198     Qfmt_31(0.79335334029124f),   Qfmt_31(0.92387953251129f),   Qfmt_31(0.99144486137381f),
    199     Qfmt_31(0.99144486137381f),   Qfmt_31(0.92387953251129f),   Qfmt_31(0.79335334029124f),
    200     Qfmt_31(0.60876142900872f),   Qfmt_31(0.38268343236509f),   Qfmt_31(0.13052619222005f),
    201 };
    202 /*----------------------------------------------------------------------------
    203 ; EXTERNAL FUNCTION REFERENCES
    204 ; Declare functions defined elsewhere and referenced in this module
    205 ----------------------------------------------------------------------------*/
    206 
    207 /*----------------------------------------------------------------------------
    208 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    209 ; Declare variables used in this module but defined elsewhere
    210 ----------------------------------------------------------------------------*/
    211 
    212 /*----------------------------------------------------------------------------
    213 ; FUNCTION CODE
    214 ----------------------------------------------------------------------------*/
    215 
    216 void pvmp3_imdct_synth(int32  in[SUBBANDS_NUMBER*FILTERBANK_BANDS],
    217                        int32  overlap[SUBBANDS_NUMBER*FILTERBANK_BANDS],
    218                        uint32 blk_type,
    219                        int16  mx_band,
    220                        int32  used_freq_lines,
    221                        int32  *Scratch_mem)
    222 {
    223 
    224     int32 band;
    225     int32 bands2process = used_freq_lines + 2;
    226 
    227     if (bands2process > SUBBANDS_NUMBER)
    228     {
    229         bands2process = SUBBANDS_NUMBER;  /* default */
    230     }
    231 
    232 
    233     /*
    234      *  in case of mx_poly_band> 0, do
    235      *  long transforms
    236      */
    237 
    238 
    239     for (band = 0; band < bands2process; band++)
    240     {
    241         uint32 current_blk_type = (band < mx_band) ? LONG : blk_type;
    242 
    243         int32 * out     = in      + (band * FILTERBANK_BANDS);
    244         int32 * history = overlap + (band * FILTERBANK_BANDS);
    245 
    246         switch (current_blk_type)
    247         {
    248             case LONG:
    249 
    250                 pvmp3_mdct_18(out, history, normal_win);
    251 
    252                 break;
    253 
    254             case START:
    255 
    256                 pvmp3_mdct_18(out, history, start_win);
    257 
    258                 break;
    259 
    260             case STOP:
    261 
    262                 pvmp3_mdct_18(out, history, stop_win);
    263 
    264                 break;
    265 
    266             case SHORT:
    267             {
    268                 int32 *tmp_prev_ovr = &Scratch_mem[FILTERBANK_BANDS];
    269                 int32 i;
    270 
    271                 for (i = 0; i < 6; i++)
    272                 {
    273                     Scratch_mem[i    ] = out[(i*3)];
    274                     Scratch_mem[6  +i] = out[(i*3) + 1];
    275                     Scratch_mem[12 +i] = out[(i*3) + 2];
    276                 }
    277 
    278                 pvmp3_mdct_6(&Scratch_mem[ 0], &tmp_prev_ovr[ 0]);
    279                 pvmp3_mdct_6(&Scratch_mem[ 6], &tmp_prev_ovr[ 6]);
    280                 pvmp3_mdct_6(&Scratch_mem[12], &tmp_prev_ovr[12]);
    281 
    282                 for (i = 0; i < 6; i++)
    283                 {
    284                     int32 temp  =  history[i];
    285                     /* next iteration overlap */
    286                     history[i]  =  fxp_mul32_Q32(tmp_prev_ovr[ 6+i] << 1, short_win[6+i]);
    287                     history[i] +=  fxp_mul32_Q32(Scratch_mem[12+i] << 1, short_win[  i]);
    288                     out[i]  =  temp;
    289                 }
    290 
    291                 for (i = 0; i < 6; i++)
    292                 {
    293                     out[i+6]   =  fxp_mul32_Q32(Scratch_mem[i] << 1, short_win[i]);
    294                     out[i+6]  +=  history[i+6];
    295                     /* next iteration overlap */
    296                     history[i+6]  =  fxp_mul32_Q32(tmp_prev_ovr[12+i] << 1, short_win[6+i]);
    297 
    298                 }
    299                 for (i = 0; i < 6; i++)
    300                 {
    301                     out[i+12]  =  fxp_mul32_Q32(tmp_prev_ovr[  i] << 1, short_win[6+i]);
    302                     out[i+12] +=  fxp_mul32_Q32(Scratch_mem[6+i] << 1, short_win[  i]);
    303                     out[i+12] +=  history[i+12];
    304                     history[12+i]  =  0;
    305                 }
    306             }
    307 
    308             break;
    309         }
    310 
    311         /*
    312          *     Compensation for frequency inversion of polyphase filterbank
    313          *     every odd time sample of every odd odd subband is mulitplied by -1  before
    314          *     processing by the polyphase filter
    315          */
    316 
    317         if (band & 1)
    318         {
    319             for (int32 slot = 1; slot < FILTERBANK_BANDS; slot += 6)
    320             {
    321                 int32 temp1 = out[slot  ];
    322                 int32 temp2 = out[slot+2];
    323                 int32 temp3 = out[slot+4];
    324                 out[slot  ] = -temp1;
    325                 out[slot+2] = -temp2;
    326                 out[slot+4] = -temp3;
    327             }
    328         }
    329     }
    330 
    331 
    332     for (band = bands2process; band < SUBBANDS_NUMBER; band++)
    333     {
    334         int32 * out     = in      + (band * FILTERBANK_BANDS);
    335         int32 * history = overlap + (band * FILTERBANK_BANDS);
    336         int32 slot;
    337 
    338         if (band & 1)
    339         {
    340             for (slot = 0; slot < FILTERBANK_BANDS; slot += 6)
    341             {
    342                 int32 temp1 =  history[slot  ];
    343                 int32 temp2 =  history[slot+1];
    344                 int32 temp3 =  history[slot+2];
    345                 out[slot  ] =  temp1;
    346                 out[slot+1] = -temp2;
    347                 out[slot+2] =  temp3;
    348 
    349                 temp1 =  history[slot+3];
    350                 temp2 =  history[slot+4];
    351                 temp3 =  history[slot+5];
    352                 out[slot+3] = -temp1;
    353                 out[slot+4] =  temp2;
    354                 out[slot+5] = -temp3;
    355             }
    356         }
    357         else
    358         {
    359             for (slot = 0; slot < FILTERBANK_BANDS; slot += 3)
    360             {
    361                 int32 temp1 =  history[slot  ];
    362                 int32 temp2 =  history[slot+1];
    363                 int32 temp3 =  history[slot+2];
    364                 out[slot  ] =  temp1;
    365                 out[slot+1] =  temp2;
    366                 out[slot+2] =  temp3;
    367             }
    368         }
    369 
    370         pv_memset(history, 0, FILTERBANK_BANDS*sizeof(*overlap));
    371     }
    372 }
    373 
    374 
    375 
    376 
    377