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 132__attribute__((no_sanitize("integer"))) 133void pvmp3_mdct_18(int32 vec[], int32 *history, const int32 *window) 134{ 135 int32 i; 136 int32 tmp; 137 int32 tmp1; 138 int32 tmp2; 139 int32 tmp3; 140 int32 tmp4; 141 142 143 144 const int32 *pt_cos_split = cosTerms_dct18; 145 const int32 *pt_cos = cosTerms_1_ov_cos_phi; 146 const int32 *pt_cos_x = &cosTerms_1_ov_cos_phi[17]; 147 int32 *pt_vec = vec; 148 int32 *pt_vec_o = &vec[17]; 149 150 151 for (i = 9; i != 0; i--) 152 { 153 tmp = *(pt_vec); 154 tmp1 = *(pt_vec_o); 155 tmp = fxp_mul32_Q32(tmp << 1, *(pt_cos++)); 156 tmp1 = fxp_mul32_Q27(tmp1, *(pt_cos_x--)); 157 *(pt_vec++) = tmp + tmp1 ; 158 *(pt_vec_o--) = fxp_mul32_Q28((tmp - tmp1), *(pt_cos_split++)); 159 } 160 161 162 pvmp3_dct_9(vec); // Even terms 163 pvmp3_dct_9(&vec[9]); // Odd terms 164 165 166 tmp3 = vec[16]; // 167 vec[16] = vec[ 8]; 168 tmp4 = vec[14]; // 169 vec[14] = vec[ 7]; 170 tmp = vec[12]; 171 vec[12] = vec[ 6]; 172 tmp2 = vec[10]; // vec[10] 173 vec[10] = vec[ 5]; 174 vec[ 8] = vec[ 4]; 175 vec[ 6] = vec[ 3]; 176 vec[ 4] = vec[ 2]; 177 vec[ 2] = vec[ 1]; 178 vec[ 1] = vec[ 9] - tmp2; // vec[9] + vec[10] 179 vec[ 3] = vec[11] - tmp2; 180 vec[ 5] = vec[11] - tmp; 181 vec[ 7] = vec[13] - tmp; 182 vec[ 9] = vec[13] - tmp4; 183 vec[11] = vec[15] - tmp4; 184 vec[13] = vec[15] - tmp3; 185 vec[15] = vec[17] - tmp3; 186 187 188 /* overlap and add */ 189 190 tmp2 = vec[0]; 191 tmp3 = vec[9]; 192 193 for (i = 0; i < 6; i++) 194 { 195 tmp = history[ i]; 196 tmp4 = vec[i+10]; 197 vec[i+10] = tmp3 + tmp4; 198 tmp1 = vec[i+1]; 199 vec[ i] = fxp_mac32_Q32(tmp, (vec[i+10]), window[ i]); 200 tmp3 = tmp4; 201 history[i ] = -(tmp2 + tmp1); 202 tmp2 = tmp1; 203 } 204 205 tmp = history[ 6]; 206 tmp4 = vec[16]; 207 vec[16] = tmp3 + tmp4; 208 tmp1 = vec[7]; 209 vec[ 6] = fxp_mac32_Q32(tmp, vec[16] << 1, window[ i]); 210 tmp = history[ 7]; 211 history[6] = -(tmp2 + tmp1); 212 history[7] = -(tmp1 + vec[8]); 213 214 tmp1 = history[ 8]; 215 tmp4 = vec[17] + tmp4; 216 vec[ 7] = fxp_mac32_Q32(tmp, tmp4 << 1, window[ 7]); 217 history[8] = -(vec[8] + vec[9]); 218 vec[ 8] = fxp_mac32_Q32(tmp1, vec[17] << 1, window[ 8]); 219 220 tmp = history[9]; 221 tmp1 = history[17]; 222 tmp2 = history[16]; 223 vec[ 9] = fxp_mac32_Q32(tmp, vec[17] << 1, window[ 9]); 224 225 vec[17] = fxp_mac32_Q32(tmp1, vec[10] << 1, window[17]); 226 vec[10] = -vec[ 16]; 227 vec[16] = fxp_mac32_Q32(tmp2, vec[11] << 1, window[16]); 228 tmp1 = history[15]; 229 tmp2 = history[14]; 230 vec[11] = -vec[ 15]; 231 vec[15] = fxp_mac32_Q32(tmp1, vec[12] << 1, window[15]); 232 vec[12] = -vec[ 14]; 233 vec[14] = fxp_mac32_Q32(tmp2, vec[13] << 1, window[14]); 234 235 tmp = history[13]; 236 tmp1 = history[12]; 237 tmp2 = history[11]; 238 tmp3 = history[10]; 239 vec[13] = fxp_mac32_Q32(tmp, vec[12] << 1, window[13]); 240 vec[12] = fxp_mac32_Q32(tmp1, vec[11] << 1, window[12]); 241 vec[11] = fxp_mac32_Q32(tmp2, vec[10] << 1, window[11]); 242 vec[10] = fxp_mac32_Q32(tmp3, tmp4 << 1, window[10]); 243 244 245 /* next iteration overlap */ 246 247 tmp1 = history[ 8]; 248 tmp3 = history[ 7]; 249 tmp2 = history[ 1]; 250 tmp = history[ 0]; 251 tmp1 <<= 1; 252 tmp3 <<= 1; 253 254 history[ 0] = fxp_mul32_Q32(tmp1, window[18]); 255 history[17] = fxp_mul32_Q32(tmp1, window[35]); 256 history[ 1] = fxp_mul32_Q32(tmp3, window[19]); 257 history[16] = fxp_mul32_Q32(tmp3, window[34]); 258 259 tmp2 <<= 1; 260 tmp <<= 1; 261 history[ 7] = fxp_mul32_Q32(tmp2, window[25]); 262 history[10] = fxp_mul32_Q32(tmp2, window[28]); 263 history[ 8] = fxp_mul32_Q32(tmp, window[26]); 264 history[ 9] = fxp_mul32_Q32(tmp, window[27]); 265 266 tmp1 = history[ 6]; 267 tmp3 = history[ 5]; 268 tmp4 = history[ 4]; 269 tmp2 = history[ 3]; 270 tmp = history[ 2]; 271 272 tmp1 <<= 1; 273 tmp3 <<= 1; 274 tmp4 <<= 1; 275 276 history[ 2] = fxp_mul32_Q32(tmp1, window[20]); 277 history[15] = fxp_mul32_Q32(tmp1, window[33]); 278 history[ 3] = fxp_mul32_Q32(tmp3, window[21]); 279 history[14] = fxp_mul32_Q32(tmp3, window[32]); 280 history[ 4] = fxp_mul32_Q32(tmp4, window[22]); 281 history[13] = fxp_mul32_Q32(tmp4, window[31]); 282 tmp2 <<= 1; 283 tmp <<= 1; 284 history[ 5] = fxp_mul32_Q32(tmp2, window[23]); 285 history[12] = fxp_mul32_Q32(tmp2, window[30]); 286 history[ 6] = fxp_mul32_Q32(tmp, window[24]); 287 history[11] = fxp_mul32_Q32(tmp, window[29]); 288} 289 290#endif // If not assembly 291