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 Filename: idct16.c 21 22 ------------------------------------------------------------------------------ 23 REVISION HISTORY 24 25 26 Who: Date: MM/DD/YYYY 27 Description: 28 29 ------------------------------------------------------------------------------ 30 INPUT AND OUTPUT DEFINITIONS 31 32 Int32 x 32-bit integer input length 16 33 34 35 ------------------------------------------------------------------------------ 36 FUNCTION DESCRIPTION 37 38 Implement inverse discrete cosine transform of lenght 16 39 40 ------------------------------------------------------------------------------ 41 REQUIREMENTS 42 43 44 ------------------------------------------------------------------------------ 45 REFERENCES 46 47 ------------------------------------------------------------------------------ 48 PSEUDO-CODE 49 50 ------------------------------------------------------------------------------ 51 */ 52 53 54 /*---------------------------------------------------------------------------- 55 ; INCLUDES 56 ----------------------------------------------------------------------------*/ 57 58 #ifdef AAC_PLUS 59 60 61 #include "idct16.h" 62 #include "idct8.h" 63 64 #include "fxp_mul32.h" 65 66 /*---------------------------------------------------------------------------- 67 ; MACROS 68 ; Define module specific macros here 69 ----------------------------------------------------------------------------*/ 70 71 72 /*---------------------------------------------------------------------------- 73 ; DEFINES 74 ; Include all pre-processor statements here. Include conditional 75 ; compile variables also. 76 ----------------------------------------------------------------------------*/ 77 78 79 #define R_SHIFT 28 80 #define Qfmt(x) (Int32)(x*((Int32)1<<R_SHIFT) + (x>=0?0.5F:-0.5F)) 81 #define Qfmt31(x) (Int32)(x*(0x7FFFFFFF) + (x>=0?0.5F:-0.5F)) 82 83 const Int32 CosTable_8i[8] = 84 { 85 Qfmt31(0.50241928618816F), Qfmt31(0.52249861493969F), 86 Qfmt31(0.56694403481636F), Qfmt31(0.64682178335999F), 87 Qfmt(0.78815462345125F), Qfmt(1.06067768599035F), 88 Qfmt(1.72244709823833F), Qfmt(5.10114861868916F) 89 }; 90 91 92 93 /*---------------------------------------------------------------------------- 94 ; LOCAL FUNCTION DEFINITIONS 95 ; Function Prototype declaration 96 ----------------------------------------------------------------------------*/ 97 98 /*---------------------------------------------------------------------------- 99 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS 100 ; Variable declaration - defined here and used outside this module 101 ----------------------------------------------------------------------------*/ 102 103 /*---------------------------------------------------------------------------- 104 ; EXTERNAL FUNCTION REFERENCES 105 ; Declare functions defined elsewhere and referenced in this module 106 ----------------------------------------------------------------------------*/ 107 108 /*---------------------------------------------------------------------------- 109 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES 110 ; Declare variables used in this module but defined elsewhere 111 ----------------------------------------------------------------------------*/ 112 113 /*---------------------------------------------------------------------------- 114 ; FUNCTION CODE 115 ----------------------------------------------------------------------------*/ 116 117 118 void idct_16(Int32 vec[], Int32 scratch_mem[]) /* scratch_mem size 8 */ 119 { 120 Int32 *temp_even = scratch_mem; 121 122 Int32 i; 123 const Int32 *pt_cos = CosTable_8i; 124 Int32 tmp1, tmp2; 125 Int32 *pt_even = temp_even; 126 Int32 *pt_odd = vec; 127 Int32 *pt_vec = vec; 128 129 Int32 tmp3; 130 Int32 *pt_vecN_1; 131 132 133 *(pt_even++) = *(pt_vec++); 134 tmp1 = *(pt_vec++); 135 *(pt_odd++) = tmp1; 136 137 for (i = 2; i != 0; i--) 138 { 139 *(pt_even++) = *(pt_vec++); 140 tmp2 = *(pt_vec++); 141 *(pt_even++) = *(pt_vec++); 142 tmp3 = *(pt_vec++); 143 *(pt_odd++) = tmp2 + tmp1; 144 *(pt_odd++) = tmp3 + tmp2; 145 tmp1 = tmp3; 146 } 147 148 *(pt_even++) = *(pt_vec++); 149 tmp2 = *(pt_vec++); 150 *(pt_even++) = *(pt_vec++); 151 tmp3 = *(pt_vec++); 152 *(pt_odd++) = tmp2 + tmp1; 153 *(pt_odd++) = tmp3 + tmp2; 154 155 156 *(pt_even) = *(pt_vec++); 157 *(pt_odd++) = *(pt_vec) + tmp3; 158 159 160 idct_8(temp_even); 161 idct_8(vec); 162 163 164 pt_cos = &CosTable_8i[7]; 165 166 pt_vec = &vec[7]; 167 168 pt_even = &temp_even[7]; 169 pt_vecN_1 = &vec[8]; 170 171 tmp1 = *(pt_even--); 172 173 for (i = 2; i != 0; i--) 174 { 175 tmp3 = fxp_mul32_Q28(*(pt_vec), *(pt_cos--)); 176 tmp2 = *(pt_even--); 177 *(pt_vecN_1++) = tmp1 - tmp3; 178 *(pt_vec--) = tmp1 + tmp3; 179 tmp3 = fxp_mul32_Q28(*(pt_vec), *(pt_cos--)); 180 tmp1 = *(pt_even--); 181 *(pt_vecN_1++) = tmp2 - tmp3; 182 *(pt_vec--) = tmp2 + tmp3; 183 } 184 185 tmp3 = fxp_mul32_Q31(*(pt_vec), *(pt_cos--)) << 1; 186 tmp2 = *(pt_even--); 187 *(pt_vecN_1++) = tmp1 - tmp3; 188 *(pt_vec--) = tmp1 + tmp3; 189 tmp3 = fxp_mul32_Q31(*(pt_vec), *(pt_cos--)) << 1; 190 tmp1 = *(pt_even--); 191 *(pt_vecN_1++) = tmp2 - tmp3; 192 *(pt_vec--) = tmp2 + tmp3; 193 tmp3 = fxp_mul32_Q31(*(pt_vec), *(pt_cos--)) << 1; 194 tmp2 = *(pt_even--); 195 *(pt_vecN_1++) = tmp1 - tmp3; 196 *(pt_vec--) = tmp1 + tmp3; 197 tmp3 = fxp_mul32_Q31(*(pt_vec), *(pt_cos)) << 1; 198 *(pt_vecN_1) = tmp2 - tmp3; 199 *(pt_vec) = tmp2 + tmp3; 200 201 } 202 203 204 #endif 205