summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/mp3dec/src/pvmp3_mdct_18.cpp
blob: 09a735bf2740aa36f63795f5f2b4e93ed7c3ef95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/* ------------------------------------------------------------------
 * Copyright (C) 1998-2009 PacketVideo
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 * -------------------------------------------------------------------
 */
/*
------------------------------------------------------------------------------

   PacketVideo Corp.
   MP3 Decoder Library

   Filename: mdct_18.cpp

     Date: 09/21/2007

------------------------------------------------------------------------------
 REVISION HISTORY


 Description:

------------------------------------------------------------------------------
 INPUT AND OUTPUT DEFINITIONS

Input
    int32 vec[],        input vector of length 18
    int32 *history      input for overlap and add, vector updated with
                        next overlap and add values
    const int32 *window sine window used in the mdct, three types are allowed
                        noraml, start and stop
Returns
    none                mdct computation in-place


------------------------------------------------------------------------------
 FUNCTION DESCRIPTION

    Returns the mdct of length 18 of the input vector, as well as the overlap
    vector for next iteration ( on history[])

------------------------------------------------------------------------------
 REQUIREMENTS


------------------------------------------------------------------------------
 REFERENCES

------------------------------------------------------------------------------
 PSEUDO-CODE

------------------------------------------------------------------------------
*/

#if ( !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) && !defined(PV_ARM_V5) && !defined(PV_ARM_V4) )
/*----------------------------------------------------------------------------
; INCLUDES
----------------------------------------------------------------------------*/

#include "pv_mp3dec_fxd_op.h"
#include "pvmp3_mdct_18.h"


/*----------------------------------------------------------------------------
; MACROS
; Define module specific macros here
----------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------
; DEFINES
; Include all pre-processor statements here. Include conditional
; compile variables also.
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; LOCAL FUNCTION DEFINITIONS
; Function Prototype declaration
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; LOCAL STORE/BUFFER/POINTER DEFINITIONS
; Variable declaration - defined here and used outside this module
----------------------------------------------------------------------------*/
const int32 cosTerms_dct18[9] =
{
    Qfmt(0.50190991877167f),   Qfmt(0.51763809020504f),   Qfmt(0.55168895948125f),
    Qfmt(0.61038729438073f),   Qfmt(0.70710678118655f),   Qfmt(0.87172339781055f),
    Qfmt(1.18310079157625f),   Qfmt(1.93185165257814f),   Qfmt(5.73685662283493f)
};


const int32 cosTerms_1_ov_cos_phi[18] =
{

    Qfmt1(0.50047634258166f),  Qfmt1(0.50431448029008f),  Qfmt1(0.51213975715725f),
    Qfmt1(0.52426456257041f),  Qfmt1(0.54119610014620f),  Qfmt1(0.56369097343317f),
    Qfmt1(0.59284452371708f),  Qfmt1(0.63023620700513f),  Qfmt1(0.67817085245463f),

    Qfmt2(0.74009361646113f),  Qfmt2(0.82133981585229f),  Qfmt2(0.93057949835179f),
    Qfmt2(1.08284028510010f),  Qfmt2(1.30656296487638f),  Qfmt2(1.66275476171152f),
    Qfmt2(2.31011315767265f),  Qfmt2(3.83064878777019f),  Qfmt2(11.46279281302667f)
};

/*----------------------------------------------------------------------------
; EXTERNAL FUNCTION REFERENCES
; Declare functions defined elsewhere and referenced in this module
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
; Declare variables used in this module but defined elsewhere
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
; FUNCTION CODE
----------------------------------------------------------------------------*/



void pvmp3_mdct_18(int32 vec[], int32 *history, const int32 *window)
{
    int32 i;
    int32 tmp;
    int32 tmp1;
    int32 tmp2;
    int32 tmp3;
    int32 tmp4;



    const int32 *pt_cos_split = cosTerms_dct18;
    const int32 *pt_cos       = cosTerms_1_ov_cos_phi;
    const int32 *pt_cos_x     = &cosTerms_1_ov_cos_phi[17];
    int32 *pt_vec   =  vec;
    int32 *pt_vec_o = &vec[17];


    for (i = 9; i != 0; i--)
    {
        tmp  = *(pt_vec);
        tmp1 = *(pt_vec_o);
        tmp  = fxp_mul32_Q32(tmp << 1,  *(pt_cos++));
        tmp1 = fxp_mul32_Q27(tmp1, *(pt_cos_x--));
        *(pt_vec++)   =   tmp + tmp1 ;
        *(pt_vec_o--) = fxp_mul32_Q28((tmp - tmp1), *(pt_cos_split++));
    }


    pvmp3_dct_9(vec);         // Even terms
    pvmp3_dct_9(&vec[9]);     // Odd  terms


    tmp3     = vec[16];  //
    vec[16]  = vec[ 8];
    tmp4     = vec[14];  //
    vec[14]  = vec[ 7];
    tmp      = vec[12];
    vec[12]  = vec[ 6];
    tmp2     = vec[10];  // vec[10]
    vec[10]  = vec[ 5];
    vec[ 8]  = vec[ 4];
    vec[ 6]  = vec[ 3];
    vec[ 4]  = vec[ 2];
    vec[ 2]  = vec[ 1];
    vec[ 1]  = vec[ 9] - tmp2; //  vec[9] +  vec[10]
    vec[ 3]  = vec[11] - tmp2;
    vec[ 5]  = vec[11] - tmp;
    vec[ 7]  = vec[13] - tmp;
    vec[ 9]  = vec[13] - tmp4;
    vec[11]  = vec[15] - tmp4;
    vec[13]  = vec[15] - tmp3;
    vec[15]  = vec[17] - tmp3;


    /* overlap and add */

    tmp2 = vec[0];
    tmp3 = vec[9];

    for (i = 0; i < 6; i++)
    {
        tmp  = history[ i];
        tmp4 = vec[i+10];
        vec[i+10] = tmp3 + tmp4;
        tmp1 = vec[i+1];
        vec[ i] =  fxp_mac32_Q32(tmp, (vec[i+10]), window[ i]);
        tmp3 = tmp4;
        history[i  ] = -(tmp2 + tmp1);
        tmp2 = tmp1;
    }

    tmp  = history[ 6];
    tmp4 = vec[16];
    vec[16] = tmp3 + tmp4;
    tmp1 = vec[7];
    vec[ 6] =  fxp_mac32_Q32(tmp, vec[16] << 1, window[ i]);
    tmp  = history[ 7];
    history[6] = -(tmp2 + tmp1);
    history[7] = -(tmp1 + vec[8]);

    tmp1  = history[ 8];
    tmp4    = vec[17] + tmp4;
    vec[ 7] =  fxp_mac32_Q32(tmp, tmp4 << 1, window[ 7]);
    history[8] = -(vec[8] + vec[9]);
    vec[ 8] =  fxp_mac32_Q32(tmp1, vec[17] << 1, window[ 8]);

    tmp  = history[9];
    tmp1 = history[17];
    tmp2 = history[16];
    vec[ 9] =  fxp_mac32_Q32(tmp,  vec[17] << 1, window[ 9]);

    vec[17] =  fxp_mac32_Q32(tmp1, vec[10] << 1, window[17]);
    vec[10] = -vec[ 16];
    vec[16] =  fxp_mac32_Q32(tmp2, vec[11] << 1, window[16]);
    tmp1 = history[15];
    tmp2 = history[14];
    vec[11] = -vec[ 15];
    vec[15] =  fxp_mac32_Q32(tmp1, vec[12] << 1, window[15]);
    vec[12] = -vec[ 14];
    vec[14] =  fxp_mac32_Q32(tmp2, vec[13] << 1, window[14]);

    tmp  = history[13];
    tmp1 = history[12];
    tmp2 = history[11];
    tmp3 = history[10];
    vec[13] =  fxp_mac32_Q32(tmp,  vec[12] << 1, window[13]);
    vec[12] =  fxp_mac32_Q32(tmp1, vec[11] << 1, window[12]);
    vec[11] =  fxp_mac32_Q32(tmp2, vec[10] << 1, window[11]);
    vec[10] =  fxp_mac32_Q32(tmp3,    tmp4 << 1, window[10]);


    /* next iteration overlap */

    tmp1 = history[ 8];
    tmp3 = history[ 7];
    tmp2 = history[ 1];
    tmp  = history[ 0];
    tmp1 <<= 1;
    tmp3 <<= 1;

    history[ 0] = fxp_mul32_Q32(tmp1, window[18]);
    history[17] = fxp_mul32_Q32(tmp1, window[35]);
    history[ 1] = fxp_mul32_Q32(tmp3, window[19]);
    history[16] = fxp_mul32_Q32(tmp3, window[34]);

    tmp2 <<= 1;
    tmp  <<= 1;
    history[ 7] = fxp_mul32_Q32(tmp2, window[25]);
    history[10] = fxp_mul32_Q32(tmp2, window[28]);
    history[ 8] = fxp_mul32_Q32(tmp,  window[26]);
    history[ 9] = fxp_mul32_Q32(tmp,  window[27]);

    tmp1 = history[ 6];
    tmp3 = history[ 5];
    tmp4 = history[ 4];
    tmp2 = history[ 3];
    tmp  = history[ 2];

    tmp1 <<= 1;
    tmp3 <<= 1;
    tmp4 <<= 1;

    history[ 2] = fxp_mul32_Q32(tmp1, window[20]);
    history[15] = fxp_mul32_Q32(tmp1, window[33]);
    history[ 3] = fxp_mul32_Q32(tmp3, window[21]);
    history[14] = fxp_mul32_Q32(tmp3, window[32]);
    history[ 4] = fxp_mul32_Q32(tmp4, window[22]);
    history[13] = fxp_mul32_Q32(tmp4, window[31]);
    tmp2 <<= 1;
    tmp  <<= 1;
    history[ 5] = fxp_mul32_Q32(tmp2, window[23]);
    history[12] = fxp_mul32_Q32(tmp2, window[30]);
    history[ 6] = fxp_mul32_Q32(tmp,  window[24]);
    history[11] = fxp_mul32_Q32(tmp,  window[29]);
}

#endif // If not assembly