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: mdct_18.cpp
25
26     Date: 09/21/2007
27
28------------------------------------------------------------------------------
29 REVISION HISTORY
30
31
32 Description:
33
34------------------------------------------------------------------------------
35 INPUT AND OUTPUT DEFINITIONS
36
37Input
38    int32 vec[],        input vector of length 18
39    int32 *history      input for overlap and add, vector updated with
40                        next overlap and add values
41    const int32 *window sine window used in the mdct, three types are allowed
42                        noraml, start and stop
43Returns
44    none                mdct computation in-place
45
46
47------------------------------------------------------------------------------
48 FUNCTION DESCRIPTION
49
50    Returns the mdct of length 18 of the input vector, as well as the overlap
51    vector for next iteration ( on history[])
52
53------------------------------------------------------------------------------
54 REQUIREMENTS
55
56
57------------------------------------------------------------------------------
58 REFERENCES
59
60------------------------------------------------------------------------------
61 PSEUDO-CODE
62
63------------------------------------------------------------------------------
64*/
65
66#if ( !defined(PV_ARM_GCC_V5) && !defined(PV_ARM_GCC_V4) && !defined(PV_ARM_V5) && !defined(PV_ARM_V4) )
67/*----------------------------------------------------------------------------
68; INCLUDES
69----------------------------------------------------------------------------*/
70
71#include "pv_mp3dec_fxd_op.h"
72#include "pvmp3_mdct_18.h"
73
74
75/*----------------------------------------------------------------------------
76; MACROS
77; Define module specific macros here
78----------------------------------------------------------------------------*/
79
80
81/*----------------------------------------------------------------------------
82; DEFINES
83; Include all pre-processor statements here. Include conditional
84; compile variables also.
85----------------------------------------------------------------------------*/
86
87/*----------------------------------------------------------------------------
88; LOCAL FUNCTION DEFINITIONS
89; Function Prototype declaration
90----------------------------------------------------------------------------*/
91
92/*----------------------------------------------------------------------------
93; LOCAL STORE/BUFFER/POINTER DEFINITIONS
94; Variable declaration - defined here and used outside this module
95----------------------------------------------------------------------------*/
96const int32 cosTerms_dct18[9] =
97{
98    Qfmt(0.50190991877167f),   Qfmt(0.51763809020504f),   Qfmt(0.55168895948125f),
99    Qfmt(0.61038729438073f),   Qfmt(0.70710678118655f),   Qfmt(0.87172339781055f),
100    Qfmt(1.18310079157625f),   Qfmt(1.93185165257814f),   Qfmt(5.73685662283493f)
101};
102
103
104const int32 cosTerms_1_ov_cos_phi[18] =
105{
106
107    Qfmt1(0.50047634258166f),  Qfmt1(0.50431448029008f),  Qfmt1(0.51213975715725f),
108    Qfmt1(0.52426456257041f),  Qfmt1(0.54119610014620f),  Qfmt1(0.56369097343317f),
109    Qfmt1(0.59284452371708f),  Qfmt1(0.63023620700513f),  Qfmt1(0.67817085245463f),
110
111    Qfmt2(0.74009361646113f),  Qfmt2(0.82133981585229f),  Qfmt2(0.93057949835179f),
112    Qfmt2(1.08284028510010f),  Qfmt2(1.30656296487638f),  Qfmt2(1.66275476171152f),
113    Qfmt2(2.31011315767265f),  Qfmt2(3.83064878777019f),  Qfmt2(11.46279281302667f)
114};
115
116/*----------------------------------------------------------------------------
117; EXTERNAL FUNCTION REFERENCES
118; Declare functions defined elsewhere and referenced in this module
119----------------------------------------------------------------------------*/
120
121/*----------------------------------------------------------------------------
122; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
123; Declare variables used in this module but defined elsewhere
124----------------------------------------------------------------------------*/
125
126/*----------------------------------------------------------------------------
127; FUNCTION CODE
128----------------------------------------------------------------------------*/
129
130
131
132void pvmp3_mdct_18(int32 vec[], int32 *history, const int32 *window)
133{
134    int32 i;
135    int32 tmp;
136    int32 tmp1;
137    int32 tmp2;
138    int32 tmp3;
139    int32 tmp4;
140
141
142
143    const int32 *pt_cos_split = cosTerms_dct18;
144    const int32 *pt_cos       = cosTerms_1_ov_cos_phi;
145    const int32 *pt_cos_x     = &cosTerms_1_ov_cos_phi[17];
146    int32 *pt_vec   =  vec;
147    int32 *pt_vec_o = &vec[17];
148
149
150    for (i = 9; i != 0; i--)
151    {
152        tmp  = *(pt_vec);
153        tmp1 = *(pt_vec_o);
154        tmp  = fxp_mul32_Q32(tmp << 1,  *(pt_cos++));
155        tmp1 = fxp_mul32_Q27(tmp1, *(pt_cos_x--));
156        *(pt_vec++)   =   tmp + tmp1 ;
157        *(pt_vec_o--) = fxp_mul32_Q28((tmp - tmp1), *(pt_cos_split++));
158    }
159
160
161    pvmp3_dct_9(vec);         // Even terms
162    pvmp3_dct_9(&vec[9]);     // Odd  terms
163
164
165    tmp3     = vec[16];  //
166    vec[16]  = vec[ 8];
167    tmp4     = vec[14];  //
168    vec[14]  = vec[ 7];
169    tmp      = vec[12];
170    vec[12]  = vec[ 6];
171    tmp2     = vec[10];  // vec[10]
172    vec[10]  = vec[ 5];
173    vec[ 8]  = vec[ 4];
174    vec[ 6]  = vec[ 3];
175    vec[ 4]  = vec[ 2];
176    vec[ 2]  = vec[ 1];
177    vec[ 1]  = vec[ 9] - tmp2; //  vec[9] +  vec[10]
178    vec[ 3]  = vec[11] - tmp2;
179    vec[ 5]  = vec[11] - tmp;
180    vec[ 7]  = vec[13] - tmp;
181    vec[ 9]  = vec[13] - tmp4;
182    vec[11]  = vec[15] - tmp4;
183    vec[13]  = vec[15] - tmp3;
184    vec[15]  = vec[17] - tmp3;
185
186
187    /* overlap and add */
188
189    tmp2 = vec[0];
190    tmp3 = vec[9];
191
192    for (i = 0; i < 6; i++)
193    {
194        tmp  = history[ i];
195        tmp4 = vec[i+10];
196        vec[i+10] = tmp3 + tmp4;
197        tmp1 = vec[i+1];
198        vec[ i] =  fxp_mac32_Q32(tmp, (vec[i+10]), window[ i]);
199        tmp3 = tmp4;
200        history[i  ] = -(tmp2 + tmp1);
201        tmp2 = tmp1;
202    }
203
204    tmp  = history[ 6];
205    tmp4 = vec[16];
206    vec[16] = tmp3 + tmp4;
207    tmp1 = vec[7];
208    vec[ 6] =  fxp_mac32_Q32(tmp, vec[16] << 1, window[ i]);
209    tmp  = history[ 7];
210    history[6] = -(tmp2 + tmp1);
211    history[7] = -(tmp1 + vec[8]);
212
213    tmp1  = history[ 8];
214    tmp4    = vec[17] + tmp4;
215    vec[ 7] =  fxp_mac32_Q32(tmp, tmp4 << 1, window[ 7]);
216    history[8] = -(vec[8] + vec[9]);
217    vec[ 8] =  fxp_mac32_Q32(tmp1, vec[17] << 1, window[ 8]);
218
219    tmp  = history[9];
220    tmp1 = history[17];
221    tmp2 = history[16];
222    vec[ 9] =  fxp_mac32_Q32(tmp,  vec[17] << 1, window[ 9]);
223
224    vec[17] =  fxp_mac32_Q32(tmp1, vec[10] << 1, window[17]);
225    vec[10] = -vec[ 16];
226    vec[16] =  fxp_mac32_Q32(tmp2, vec[11] << 1, window[16]);
227    tmp1 = history[15];
228    tmp2 = history[14];
229    vec[11] = -vec[ 15];
230    vec[15] =  fxp_mac32_Q32(tmp1, vec[12] << 1, window[15]);
231    vec[12] = -vec[ 14];
232    vec[14] =  fxp_mac32_Q32(tmp2, vec[13] << 1, window[14]);
233
234    tmp  = history[13];
235    tmp1 = history[12];
236    tmp2 = history[11];
237    tmp3 = history[10];
238    vec[13] =  fxp_mac32_Q32(tmp,  vec[12] << 1, window[13]);
239    vec[12] =  fxp_mac32_Q32(tmp1, vec[11] << 1, window[12]);
240    vec[11] =  fxp_mac32_Q32(tmp2, vec[10] << 1, window[11]);
241    vec[10] =  fxp_mac32_Q32(tmp3,    tmp4 << 1, window[10]);
242
243
244    /* next iteration overlap */
245
246    tmp1 = history[ 8];
247    tmp3 = history[ 7];
248    tmp2 = history[ 1];
249    tmp  = history[ 0];
250    tmp1 <<= 1;
251    tmp3 <<= 1;
252
253    history[ 0] = fxp_mul32_Q32(tmp1, window[18]);
254    history[17] = fxp_mul32_Q32(tmp1, window[35]);
255    history[ 1] = fxp_mul32_Q32(tmp3, window[19]);
256    history[16] = fxp_mul32_Q32(tmp3, window[34]);
257
258    tmp2 <<= 1;
259    tmp  <<= 1;
260    history[ 7] = fxp_mul32_Q32(tmp2, window[25]);
261    history[10] = fxp_mul32_Q32(tmp2, window[28]);
262    history[ 8] = fxp_mul32_Q32(tmp,  window[26]);
263    history[ 9] = fxp_mul32_Q32(tmp,  window[27]);
264
265    tmp1 = history[ 6];
266    tmp3 = history[ 5];
267    tmp4 = history[ 4];
268    tmp2 = history[ 3];
269    tmp  = history[ 2];
270
271    tmp1 <<= 1;
272    tmp3 <<= 1;
273    tmp4 <<= 1;
274
275    history[ 2] = fxp_mul32_Q32(tmp1, window[20]);
276    history[15] = fxp_mul32_Q32(tmp1, window[33]);
277    history[ 3] = fxp_mul32_Q32(tmp3, window[21]);
278    history[14] = fxp_mul32_Q32(tmp3, window[32]);
279    history[ 4] = fxp_mul32_Q32(tmp4, window[22]);
280    history[13] = fxp_mul32_Q32(tmp4, window[31]);
281    tmp2 <<= 1;
282    tmp  <<= 1;
283    history[ 5] = fxp_mul32_Q32(tmp2, window[23]);
284    history[12] = fxp_mul32_Q32(tmp2, window[30]);
285    history[ 6] = fxp_mul32_Q32(tmp,  window[24]);
286    history[11] = fxp_mul32_Q32(tmp,  window[29]);
287}
288
289#endif // If not assembly
290