Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /******************************************************************** |
michael@0 | 2 | * * |
michael@0 | 3 | * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * |
michael@0 | 4 | * * |
michael@0 | 5 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
michael@0 | 6 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
michael@0 | 7 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
michael@0 | 8 | * * |
michael@0 | 9 | * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * |
michael@0 | 10 | * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * |
michael@0 | 11 | * * |
michael@0 | 12 | ******************************************************************** |
michael@0 | 13 | |
michael@0 | 14 | function: normalized modified discrete cosine transform |
michael@0 | 15 | power of two length transform only [64 <= n ] |
michael@0 | 16 | last mod: $Id: mdct.c,v 1.9 2002/10/16 09:17:39 xiphmont Exp $ |
michael@0 | 17 | |
michael@0 | 18 | Original algorithm adapted long ago from _The use of multirate filter |
michael@0 | 19 | banks for coding of high quality digital audio_, by T. Sporer, |
michael@0 | 20 | K. Brandenburg and B. Edler, collection of the European Signal |
michael@0 | 21 | Processing Conference (EUSIPCO), Amsterdam, June 1992, Vol.1, pp |
michael@0 | 22 | 211-214 |
michael@0 | 23 | |
michael@0 | 24 | The below code implements an algorithm that no longer looks much like |
michael@0 | 25 | that presented in the paper, but the basic structure remains if you |
michael@0 | 26 | dig deep enough to see it. |
michael@0 | 27 | |
michael@0 | 28 | This module DOES NOT INCLUDE code to generate/apply the window |
michael@0 | 29 | function. Everybody has their own weird favorite including me... I |
michael@0 | 30 | happen to like the properties of y=sin(.5PI*sin^2(x)), but others may |
michael@0 | 31 | vehemently disagree. |
michael@0 | 32 | |
michael@0 | 33 | ********************************************************************/ |
michael@0 | 34 | |
michael@0 | 35 | #include "ivorbiscodec.h" |
michael@0 | 36 | #include "codebook.h" |
michael@0 | 37 | #include "misc.h" |
michael@0 | 38 | #include "mdct.h" |
michael@0 | 39 | #include "mdct_lookup.h" |
michael@0 | 40 | |
michael@0 | 41 | |
michael@0 | 42 | /* 8 point butterfly (in place) */ |
michael@0 | 43 | STIN void mdct_butterfly_8(DATA_TYPE *x){ |
michael@0 | 44 | |
michael@0 | 45 | REG_TYPE r0 = x[4] + x[0]; |
michael@0 | 46 | REG_TYPE r1 = x[4] - x[0]; |
michael@0 | 47 | REG_TYPE r2 = x[5] + x[1]; |
michael@0 | 48 | REG_TYPE r3 = x[5] - x[1]; |
michael@0 | 49 | REG_TYPE r4 = x[6] + x[2]; |
michael@0 | 50 | REG_TYPE r5 = x[6] - x[2]; |
michael@0 | 51 | REG_TYPE r6 = x[7] + x[3]; |
michael@0 | 52 | REG_TYPE r7 = x[7] - x[3]; |
michael@0 | 53 | |
michael@0 | 54 | x[0] = r5 + r3; |
michael@0 | 55 | x[1] = r7 - r1; |
michael@0 | 56 | x[2] = r5 - r3; |
michael@0 | 57 | x[3] = r7 + r1; |
michael@0 | 58 | x[4] = r4 - r0; |
michael@0 | 59 | x[5] = r6 - r2; |
michael@0 | 60 | x[6] = r4 + r0; |
michael@0 | 61 | x[7] = r6 + r2; |
michael@0 | 62 | MB(); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | /* 16 point butterfly (in place, 4 register) */ |
michael@0 | 66 | STIN void mdct_butterfly_16(DATA_TYPE *x){ |
michael@0 | 67 | |
michael@0 | 68 | REG_TYPE r0, r1; |
michael@0 | 69 | |
michael@0 | 70 | r0 = x[ 0] - x[ 8]; x[ 8] += x[ 0]; |
michael@0 | 71 | r1 = x[ 1] - x[ 9]; x[ 9] += x[ 1]; |
michael@0 | 72 | x[ 0] = MULT31((r0 + r1) , cPI2_8); |
michael@0 | 73 | x[ 1] = MULT31((r1 - r0) , cPI2_8); |
michael@0 | 74 | MB(); |
michael@0 | 75 | |
michael@0 | 76 | r0 = x[10] - x[ 2]; x[10] += x[ 2]; |
michael@0 | 77 | r1 = x[ 3] - x[11]; x[11] += x[ 3]; |
michael@0 | 78 | x[ 2] = r1; x[ 3] = r0; |
michael@0 | 79 | MB(); |
michael@0 | 80 | |
michael@0 | 81 | r0 = x[12] - x[ 4]; x[12] += x[ 4]; |
michael@0 | 82 | r1 = x[13] - x[ 5]; x[13] += x[ 5]; |
michael@0 | 83 | x[ 4] = MULT31((r0 - r1) , cPI2_8); |
michael@0 | 84 | x[ 5] = MULT31((r0 + r1) , cPI2_8); |
michael@0 | 85 | MB(); |
michael@0 | 86 | |
michael@0 | 87 | r0 = x[14] - x[ 6]; x[14] += x[ 6]; |
michael@0 | 88 | r1 = x[15] - x[ 7]; x[15] += x[ 7]; |
michael@0 | 89 | x[ 6] = r0; x[ 7] = r1; |
michael@0 | 90 | MB(); |
michael@0 | 91 | |
michael@0 | 92 | mdct_butterfly_8(x); |
michael@0 | 93 | mdct_butterfly_8(x+8); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | /* 32 point butterfly (in place, 4 register) */ |
michael@0 | 97 | STIN void mdct_butterfly_32(DATA_TYPE *x){ |
michael@0 | 98 | |
michael@0 | 99 | REG_TYPE r0, r1; |
michael@0 | 100 | |
michael@0 | 101 | r0 = x[30] - x[14]; x[30] += x[14]; |
michael@0 | 102 | r1 = x[31] - x[15]; x[31] += x[15]; |
michael@0 | 103 | x[14] = r0; x[15] = r1; |
michael@0 | 104 | MB(); |
michael@0 | 105 | |
michael@0 | 106 | r0 = x[28] - x[12]; x[28] += x[12]; |
michael@0 | 107 | r1 = x[29] - x[13]; x[29] += x[13]; |
michael@0 | 108 | XNPROD31( r0, r1, cPI1_8, cPI3_8, &x[12], &x[13] ); |
michael@0 | 109 | MB(); |
michael@0 | 110 | |
michael@0 | 111 | r0 = x[26] - x[10]; x[26] += x[10]; |
michael@0 | 112 | r1 = x[27] - x[11]; x[27] += x[11]; |
michael@0 | 113 | x[10] = MULT31((r0 - r1) , cPI2_8); |
michael@0 | 114 | x[11] = MULT31((r0 + r1) , cPI2_8); |
michael@0 | 115 | MB(); |
michael@0 | 116 | |
michael@0 | 117 | r0 = x[24] - x[ 8]; x[24] += x[ 8]; |
michael@0 | 118 | r1 = x[25] - x[ 9]; x[25] += x[ 9]; |
michael@0 | 119 | XNPROD31( r0, r1, cPI3_8, cPI1_8, &x[ 8], &x[ 9] ); |
michael@0 | 120 | MB(); |
michael@0 | 121 | |
michael@0 | 122 | r0 = x[22] - x[ 6]; x[22] += x[ 6]; |
michael@0 | 123 | r1 = x[ 7] - x[23]; x[23] += x[ 7]; |
michael@0 | 124 | x[ 6] = r1; x[ 7] = r0; |
michael@0 | 125 | MB(); |
michael@0 | 126 | |
michael@0 | 127 | r0 = x[ 4] - x[20]; x[20] += x[ 4]; |
michael@0 | 128 | r1 = x[ 5] - x[21]; x[21] += x[ 5]; |
michael@0 | 129 | XPROD31 ( r0, r1, cPI3_8, cPI1_8, &x[ 4], &x[ 5] ); |
michael@0 | 130 | MB(); |
michael@0 | 131 | |
michael@0 | 132 | r0 = x[ 2] - x[18]; x[18] += x[ 2]; |
michael@0 | 133 | r1 = x[ 3] - x[19]; x[19] += x[ 3]; |
michael@0 | 134 | x[ 2] = MULT31((r1 + r0) , cPI2_8); |
michael@0 | 135 | x[ 3] = MULT31((r1 - r0) , cPI2_8); |
michael@0 | 136 | MB(); |
michael@0 | 137 | |
michael@0 | 138 | r0 = x[ 0] - x[16]; x[16] += x[ 0]; |
michael@0 | 139 | r1 = x[ 1] - x[17]; x[17] += x[ 1]; |
michael@0 | 140 | XPROD31 ( r0, r1, cPI1_8, cPI3_8, &x[ 0], &x[ 1] ); |
michael@0 | 141 | MB(); |
michael@0 | 142 | |
michael@0 | 143 | mdct_butterfly_16(x); |
michael@0 | 144 | mdct_butterfly_16(x+16); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | /* N/stage point generic N stage butterfly (in place, 2 register) */ |
michael@0 | 148 | STIN void mdct_butterfly_generic(DATA_TYPE *x,int points,int step){ |
michael@0 | 149 | |
michael@0 | 150 | LOOKUP_T *T = sincos_lookup0; |
michael@0 | 151 | DATA_TYPE *x1 = x + points - 8; |
michael@0 | 152 | DATA_TYPE *x2 = x + (points>>1) - 8; |
michael@0 | 153 | REG_TYPE r0; |
michael@0 | 154 | REG_TYPE r1; |
michael@0 | 155 | |
michael@0 | 156 | do{ |
michael@0 | 157 | r0 = x1[6] - x2[6]; x1[6] += x2[6]; |
michael@0 | 158 | r1 = x2[7] - x1[7]; x1[7] += x2[7]; |
michael@0 | 159 | XPROD31( r1, r0, T[0], T[1], &x2[6], &x2[7] ); T+=step; |
michael@0 | 160 | |
michael@0 | 161 | r0 = x1[4] - x2[4]; x1[4] += x2[4]; |
michael@0 | 162 | r1 = x2[5] - x1[5]; x1[5] += x2[5]; |
michael@0 | 163 | XPROD31( r1, r0, T[0], T[1], &x2[4], &x2[5] ); T+=step; |
michael@0 | 164 | |
michael@0 | 165 | r0 = x1[2] - x2[2]; x1[2] += x2[2]; |
michael@0 | 166 | r1 = x2[3] - x1[3]; x1[3] += x2[3]; |
michael@0 | 167 | XPROD31( r1, r0, T[0], T[1], &x2[2], &x2[3] ); T+=step; |
michael@0 | 168 | |
michael@0 | 169 | r0 = x1[0] - x2[0]; x1[0] += x2[0]; |
michael@0 | 170 | r1 = x2[1] - x1[1]; x1[1] += x2[1]; |
michael@0 | 171 | XPROD31( r1, r0, T[0], T[1], &x2[0], &x2[1] ); T+=step; |
michael@0 | 172 | |
michael@0 | 173 | x1-=8; x2-=8; |
michael@0 | 174 | }while(T<sincos_lookup0+1024); |
michael@0 | 175 | do{ |
michael@0 | 176 | r0 = x1[6] - x2[6]; x1[6] += x2[6]; |
michael@0 | 177 | r1 = x1[7] - x2[7]; x1[7] += x2[7]; |
michael@0 | 178 | XNPROD31( r0, r1, T[0], T[1], &x2[6], &x2[7] ); T-=step; |
michael@0 | 179 | |
michael@0 | 180 | r0 = x1[4] - x2[4]; x1[4] += x2[4]; |
michael@0 | 181 | r1 = x1[5] - x2[5]; x1[5] += x2[5]; |
michael@0 | 182 | XNPROD31( r0, r1, T[0], T[1], &x2[4], &x2[5] ); T-=step; |
michael@0 | 183 | |
michael@0 | 184 | r0 = x1[2] - x2[2]; x1[2] += x2[2]; |
michael@0 | 185 | r1 = x1[3] - x2[3]; x1[3] += x2[3]; |
michael@0 | 186 | XNPROD31( r0, r1, T[0], T[1], &x2[2], &x2[3] ); T-=step; |
michael@0 | 187 | |
michael@0 | 188 | r0 = x1[0] - x2[0]; x1[0] += x2[0]; |
michael@0 | 189 | r1 = x1[1] - x2[1]; x1[1] += x2[1]; |
michael@0 | 190 | XNPROD31( r0, r1, T[0], T[1], &x2[0], &x2[1] ); T-=step; |
michael@0 | 191 | |
michael@0 | 192 | x1-=8; x2-=8; |
michael@0 | 193 | }while(T>sincos_lookup0); |
michael@0 | 194 | do{ |
michael@0 | 195 | r0 = x2[6] - x1[6]; x1[6] += x2[6]; |
michael@0 | 196 | r1 = x2[7] - x1[7]; x1[7] += x2[7]; |
michael@0 | 197 | XPROD31( r0, r1, T[0], T[1], &x2[6], &x2[7] ); T+=step; |
michael@0 | 198 | |
michael@0 | 199 | r0 = x2[4] - x1[4]; x1[4] += x2[4]; |
michael@0 | 200 | r1 = x2[5] - x1[5]; x1[5] += x2[5]; |
michael@0 | 201 | XPROD31( r0, r1, T[0], T[1], &x2[4], &x2[5] ); T+=step; |
michael@0 | 202 | |
michael@0 | 203 | r0 = x2[2] - x1[2]; x1[2] += x2[2]; |
michael@0 | 204 | r1 = x2[3] - x1[3]; x1[3] += x2[3]; |
michael@0 | 205 | XPROD31( r0, r1, T[0], T[1], &x2[2], &x2[3] ); T+=step; |
michael@0 | 206 | |
michael@0 | 207 | r0 = x2[0] - x1[0]; x1[0] += x2[0]; |
michael@0 | 208 | r1 = x2[1] - x1[1]; x1[1] += x2[1]; |
michael@0 | 209 | XPROD31( r0, r1, T[0], T[1], &x2[0], &x2[1] ); T+=step; |
michael@0 | 210 | |
michael@0 | 211 | x1-=8; x2-=8; |
michael@0 | 212 | }while(T<sincos_lookup0+1024); |
michael@0 | 213 | do{ |
michael@0 | 214 | r0 = x1[6] - x2[6]; x1[6] += x2[6]; |
michael@0 | 215 | r1 = x2[7] - x1[7]; x1[7] += x2[7]; |
michael@0 | 216 | XNPROD31( r1, r0, T[0], T[1], &x2[6], &x2[7] ); T-=step; |
michael@0 | 217 | |
michael@0 | 218 | r0 = x1[4] - x2[4]; x1[4] += x2[4]; |
michael@0 | 219 | r1 = x2[5] - x1[5]; x1[5] += x2[5]; |
michael@0 | 220 | XNPROD31( r1, r0, T[0], T[1], &x2[4], &x2[5] ); T-=step; |
michael@0 | 221 | |
michael@0 | 222 | r0 = x1[2] - x2[2]; x1[2] += x2[2]; |
michael@0 | 223 | r1 = x2[3] - x1[3]; x1[3] += x2[3]; |
michael@0 | 224 | XNPROD31( r1, r0, T[0], T[1], &x2[2], &x2[3] ); T-=step; |
michael@0 | 225 | |
michael@0 | 226 | r0 = x1[0] - x2[0]; x1[0] += x2[0]; |
michael@0 | 227 | r1 = x2[1] - x1[1]; x1[1] += x2[1]; |
michael@0 | 228 | XNPROD31( r1, r0, T[0], T[1], &x2[0], &x2[1] ); T-=step; |
michael@0 | 229 | |
michael@0 | 230 | x1-=8; x2-=8; |
michael@0 | 231 | }while(T>sincos_lookup0); |
michael@0 | 232 | } |
michael@0 | 233 | |
michael@0 | 234 | STIN void mdct_butterflies(DATA_TYPE *x,int points,int shift){ |
michael@0 | 235 | |
michael@0 | 236 | int stages=8-shift; |
michael@0 | 237 | int i,j; |
michael@0 | 238 | |
michael@0 | 239 | for(i=0;--stages>0;i++){ |
michael@0 | 240 | for(j=0;j<(1<<i);j++) |
michael@0 | 241 | mdct_butterfly_generic(x+(points>>i)*j,points>>i,4<<(i+shift)); |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | for(j=0;j<points;j+=32) |
michael@0 | 245 | mdct_butterfly_32(x+j); |
michael@0 | 246 | |
michael@0 | 247 | } |
michael@0 | 248 | |
michael@0 | 249 | static unsigned char bitrev[16]={0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15}; |
michael@0 | 250 | |
michael@0 | 251 | STIN int bitrev12(int x){ |
michael@0 | 252 | return bitrev[x>>8]|(bitrev[(x&0x0f0)>>4]<<4)|(((int)bitrev[x&0x00f])<<8); |
michael@0 | 253 | } |
michael@0 | 254 | |
michael@0 | 255 | STIN void mdct_bitreverse(DATA_TYPE *x,int n,int step,int shift){ |
michael@0 | 256 | |
michael@0 | 257 | int bit = 0; |
michael@0 | 258 | DATA_TYPE *w0 = x; |
michael@0 | 259 | DATA_TYPE *w1 = x = w0+(n>>1); |
michael@0 | 260 | LOOKUP_T *T = (step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1; |
michael@0 | 261 | LOOKUP_T *Ttop = T+1024; |
michael@0 | 262 | DATA_TYPE r2; |
michael@0 | 263 | |
michael@0 | 264 | do{ |
michael@0 | 265 | DATA_TYPE r3 = bitrev12(bit++); |
michael@0 | 266 | DATA_TYPE *x0 = x + ((r3 ^ 0xfff)>>shift) -1; |
michael@0 | 267 | DATA_TYPE *x1 = x + (r3>>shift); |
michael@0 | 268 | |
michael@0 | 269 | REG_TYPE r0 = x0[0] + x1[0]; |
michael@0 | 270 | REG_TYPE r1 = x1[1] - x0[1]; |
michael@0 | 271 | |
michael@0 | 272 | XPROD32( r0, r1, T[1], T[0], &r2, &r3 ); T+=step; |
michael@0 | 273 | |
michael@0 | 274 | w1 -= 4; |
michael@0 | 275 | |
michael@0 | 276 | r0 = (x0[1] + x1[1])>>1; |
michael@0 | 277 | r1 = (x0[0] - x1[0])>>1; |
michael@0 | 278 | w0[0] = r0 + r2; |
michael@0 | 279 | w0[1] = r1 + r3; |
michael@0 | 280 | w1[2] = r0 - r2; |
michael@0 | 281 | w1[3] = r3 - r1; |
michael@0 | 282 | |
michael@0 | 283 | r3 = bitrev12(bit++); |
michael@0 | 284 | x0 = x + ((r3 ^ 0xfff)>>shift) -1; |
michael@0 | 285 | x1 = x + (r3>>shift); |
michael@0 | 286 | |
michael@0 | 287 | r0 = x0[0] + x1[0]; |
michael@0 | 288 | r1 = x1[1] - x0[1]; |
michael@0 | 289 | |
michael@0 | 290 | XPROD32( r0, r1, T[1], T[0], &r2, &r3 ); T+=step; |
michael@0 | 291 | |
michael@0 | 292 | r0 = (x0[1] + x1[1])>>1; |
michael@0 | 293 | r1 = (x0[0] - x1[0])>>1; |
michael@0 | 294 | w0[2] = r0 + r2; |
michael@0 | 295 | w0[3] = r1 + r3; |
michael@0 | 296 | w1[0] = r0 - r2; |
michael@0 | 297 | w1[1] = r3 - r1; |
michael@0 | 298 | |
michael@0 | 299 | w0 += 4; |
michael@0 | 300 | }while(T<Ttop); |
michael@0 | 301 | do{ |
michael@0 | 302 | DATA_TYPE r3 = bitrev12(bit++); |
michael@0 | 303 | DATA_TYPE *x0 = x + ((r3 ^ 0xfff)>>shift) -1; |
michael@0 | 304 | DATA_TYPE *x1 = x + (r3>>shift); |
michael@0 | 305 | |
michael@0 | 306 | REG_TYPE r0 = x0[0] + x1[0]; |
michael@0 | 307 | REG_TYPE r1 = x1[1] - x0[1]; |
michael@0 | 308 | |
michael@0 | 309 | T-=step; XPROD32( r0, r1, T[0], T[1], &r2, &r3 ); |
michael@0 | 310 | |
michael@0 | 311 | w1 -= 4; |
michael@0 | 312 | |
michael@0 | 313 | r0 = (x0[1] + x1[1])>>1; |
michael@0 | 314 | r1 = (x0[0] - x1[0])>>1; |
michael@0 | 315 | w0[0] = r0 + r2; |
michael@0 | 316 | w0[1] = r1 + r3; |
michael@0 | 317 | w1[2] = r0 - r2; |
michael@0 | 318 | w1[3] = r3 - r1; |
michael@0 | 319 | |
michael@0 | 320 | r3 = bitrev12(bit++); |
michael@0 | 321 | x0 = x + ((r3 ^ 0xfff)>>shift) -1; |
michael@0 | 322 | x1 = x + (r3>>shift); |
michael@0 | 323 | |
michael@0 | 324 | r0 = x0[0] + x1[0]; |
michael@0 | 325 | r1 = x1[1] - x0[1]; |
michael@0 | 326 | |
michael@0 | 327 | T-=step; XPROD32( r0, r1, T[0], T[1], &r2, &r3 ); |
michael@0 | 328 | |
michael@0 | 329 | r0 = (x0[1] + x1[1])>>1; |
michael@0 | 330 | r1 = (x0[0] - x1[0])>>1; |
michael@0 | 331 | w0[2] = r0 + r2; |
michael@0 | 332 | w0[3] = r1 + r3; |
michael@0 | 333 | w1[0] = r0 - r2; |
michael@0 | 334 | w1[1] = r3 - r1; |
michael@0 | 335 | |
michael@0 | 336 | w0 += 4; |
michael@0 | 337 | }while(w0<w1); |
michael@0 | 338 | } |
michael@0 | 339 | |
michael@0 | 340 | void mdct_backward(int n, DATA_TYPE *in, DATA_TYPE *out){ |
michael@0 | 341 | int n2=n>>1; |
michael@0 | 342 | int n4=n>>2; |
michael@0 | 343 | DATA_TYPE *iX; |
michael@0 | 344 | DATA_TYPE *oX; |
michael@0 | 345 | LOOKUP_T *T; |
michael@0 | 346 | LOOKUP_T *V; |
michael@0 | 347 | int shift; |
michael@0 | 348 | int step; |
michael@0 | 349 | |
michael@0 | 350 | for (shift=6;!(n&(1<<shift));shift++); |
michael@0 | 351 | shift=13-shift; |
michael@0 | 352 | step=2<<shift; |
michael@0 | 353 | |
michael@0 | 354 | /* rotate */ |
michael@0 | 355 | |
michael@0 | 356 | iX = in+n2-7; |
michael@0 | 357 | oX = out+n2+n4; |
michael@0 | 358 | T = sincos_lookup0; |
michael@0 | 359 | |
michael@0 | 360 | do{ |
michael@0 | 361 | oX-=4; |
michael@0 | 362 | XPROD31( iX[4], iX[6], T[0], T[1], &oX[2], &oX[3] ); T+=step; |
michael@0 | 363 | XPROD31( iX[0], iX[2], T[0], T[1], &oX[0], &oX[1] ); T+=step; |
michael@0 | 364 | iX-=8; |
michael@0 | 365 | }while(iX>=in+n4); |
michael@0 | 366 | do{ |
michael@0 | 367 | oX-=4; |
michael@0 | 368 | XPROD31( iX[4], iX[6], T[1], T[0], &oX[2], &oX[3] ); T-=step; |
michael@0 | 369 | XPROD31( iX[0], iX[2], T[1], T[0], &oX[0], &oX[1] ); T-=step; |
michael@0 | 370 | iX-=8; |
michael@0 | 371 | }while(iX>=in); |
michael@0 | 372 | |
michael@0 | 373 | iX = in+n2-8; |
michael@0 | 374 | oX = out+n2+n4; |
michael@0 | 375 | T = sincos_lookup0; |
michael@0 | 376 | |
michael@0 | 377 | do{ |
michael@0 | 378 | T+=step; XNPROD31( iX[6], iX[4], T[0], T[1], &oX[0], &oX[1] ); |
michael@0 | 379 | T+=step; XNPROD31( iX[2], iX[0], T[0], T[1], &oX[2], &oX[3] ); |
michael@0 | 380 | iX-=8; |
michael@0 | 381 | oX+=4; |
michael@0 | 382 | }while(iX>=in+n4); |
michael@0 | 383 | do{ |
michael@0 | 384 | T-=step; XNPROD31( iX[6], iX[4], T[1], T[0], &oX[0], &oX[1] ); |
michael@0 | 385 | T-=step; XNPROD31( iX[2], iX[0], T[1], T[0], &oX[2], &oX[3] ); |
michael@0 | 386 | iX-=8; |
michael@0 | 387 | oX+=4; |
michael@0 | 388 | }while(iX>=in); |
michael@0 | 389 | |
michael@0 | 390 | mdct_butterflies(out+n2,n2,shift); |
michael@0 | 391 | mdct_bitreverse(out,n,step,shift); |
michael@0 | 392 | |
michael@0 | 393 | /* rotate + window */ |
michael@0 | 394 | |
michael@0 | 395 | step>>=2; |
michael@0 | 396 | { |
michael@0 | 397 | DATA_TYPE *oX1=out+n2+n4; |
michael@0 | 398 | DATA_TYPE *oX2=out+n2+n4; |
michael@0 | 399 | DATA_TYPE *iX =out; |
michael@0 | 400 | |
michael@0 | 401 | switch(step) { |
michael@0 | 402 | default: { |
michael@0 | 403 | T=(step>=4)?(sincos_lookup0+(step>>1)):sincos_lookup1; |
michael@0 | 404 | do{ |
michael@0 | 405 | oX1-=4; |
michael@0 | 406 | XPROD31( iX[0], -iX[1], T[0], T[1], &oX1[3], &oX2[0] ); T+=step; |
michael@0 | 407 | XPROD31( iX[2], -iX[3], T[0], T[1], &oX1[2], &oX2[1] ); T+=step; |
michael@0 | 408 | XPROD31( iX[4], -iX[5], T[0], T[1], &oX1[1], &oX2[2] ); T+=step; |
michael@0 | 409 | XPROD31( iX[6], -iX[7], T[0], T[1], &oX1[0], &oX2[3] ); T+=step; |
michael@0 | 410 | oX2+=4; |
michael@0 | 411 | iX+=8; |
michael@0 | 412 | }while(iX<oX1); |
michael@0 | 413 | break; |
michael@0 | 414 | } |
michael@0 | 415 | |
michael@0 | 416 | case 1: { |
michael@0 | 417 | /* linear interpolation between table values: offset=0.5, step=1 */ |
michael@0 | 418 | REG_TYPE t0,t1,v0,v1; |
michael@0 | 419 | T = sincos_lookup0; |
michael@0 | 420 | V = sincos_lookup1; |
michael@0 | 421 | t0 = (*T++)>>1; |
michael@0 | 422 | t1 = (*T++)>>1; |
michael@0 | 423 | do{ |
michael@0 | 424 | oX1-=4; |
michael@0 | 425 | |
michael@0 | 426 | t0 += (v0 = (*V++)>>1); |
michael@0 | 427 | t1 += (v1 = (*V++)>>1); |
michael@0 | 428 | XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] ); |
michael@0 | 429 | v0 += (t0 = (*T++)>>1); |
michael@0 | 430 | v1 += (t1 = (*T++)>>1); |
michael@0 | 431 | XPROD31( iX[2], -iX[3], v0, v1, &oX1[2], &oX2[1] ); |
michael@0 | 432 | t0 += (v0 = (*V++)>>1); |
michael@0 | 433 | t1 += (v1 = (*V++)>>1); |
michael@0 | 434 | XPROD31( iX[4], -iX[5], t0, t1, &oX1[1], &oX2[2] ); |
michael@0 | 435 | v0 += (t0 = (*T++)>>1); |
michael@0 | 436 | v1 += (t1 = (*T++)>>1); |
michael@0 | 437 | XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] ); |
michael@0 | 438 | |
michael@0 | 439 | oX2+=4; |
michael@0 | 440 | iX+=8; |
michael@0 | 441 | }while(iX<oX1); |
michael@0 | 442 | break; |
michael@0 | 443 | } |
michael@0 | 444 | |
michael@0 | 445 | case 0: { |
michael@0 | 446 | /* linear interpolation between table values: offset=0.25, step=0.5 */ |
michael@0 | 447 | REG_TYPE t0,t1,v0,v1,q0,q1; |
michael@0 | 448 | T = sincos_lookup0; |
michael@0 | 449 | V = sincos_lookup1; |
michael@0 | 450 | t0 = *T++; |
michael@0 | 451 | t1 = *T++; |
michael@0 | 452 | do{ |
michael@0 | 453 | oX1-=4; |
michael@0 | 454 | |
michael@0 | 455 | v0 = *V++; |
michael@0 | 456 | v1 = *V++; |
michael@0 | 457 | t0 += (q0 = (v0-t0)>>2); |
michael@0 | 458 | t1 += (q1 = (v1-t1)>>2); |
michael@0 | 459 | XPROD31( iX[0], -iX[1], t0, t1, &oX1[3], &oX2[0] ); |
michael@0 | 460 | t0 = v0-q0; |
michael@0 | 461 | t1 = v1-q1; |
michael@0 | 462 | XPROD31( iX[2], -iX[3], t0, t1, &oX1[2], &oX2[1] ); |
michael@0 | 463 | |
michael@0 | 464 | t0 = *T++; |
michael@0 | 465 | t1 = *T++; |
michael@0 | 466 | v0 += (q0 = (t0-v0)>>2); |
michael@0 | 467 | v1 += (q1 = (t1-v1)>>2); |
michael@0 | 468 | XPROD31( iX[4], -iX[5], v0, v1, &oX1[1], &oX2[2] ); |
michael@0 | 469 | v0 = t0-q0; |
michael@0 | 470 | v1 = t1-q1; |
michael@0 | 471 | XPROD31( iX[6], -iX[7], v0, v1, &oX1[0], &oX2[3] ); |
michael@0 | 472 | |
michael@0 | 473 | oX2+=4; |
michael@0 | 474 | iX+=8; |
michael@0 | 475 | }while(iX<oX1); |
michael@0 | 476 | break; |
michael@0 | 477 | } |
michael@0 | 478 | } |
michael@0 | 479 | |
michael@0 | 480 | iX=out+n2+n4; |
michael@0 | 481 | oX1=out+n4; |
michael@0 | 482 | oX2=oX1; |
michael@0 | 483 | |
michael@0 | 484 | do{ |
michael@0 | 485 | oX1-=4; |
michael@0 | 486 | iX-=4; |
michael@0 | 487 | |
michael@0 | 488 | oX2[0] = -(oX1[3] = iX[3]); |
michael@0 | 489 | oX2[1] = -(oX1[2] = iX[2]); |
michael@0 | 490 | oX2[2] = -(oX1[1] = iX[1]); |
michael@0 | 491 | oX2[3] = -(oX1[0] = iX[0]); |
michael@0 | 492 | |
michael@0 | 493 | oX2+=4; |
michael@0 | 494 | }while(oX2<iX); |
michael@0 | 495 | |
michael@0 | 496 | iX=out+n2+n4; |
michael@0 | 497 | oX1=out+n2+n4; |
michael@0 | 498 | oX2=out+n2; |
michael@0 | 499 | |
michael@0 | 500 | do{ |
michael@0 | 501 | oX1-=4; |
michael@0 | 502 | oX1[0]= iX[3]; |
michael@0 | 503 | oX1[1]= iX[2]; |
michael@0 | 504 | oX1[2]= iX[1]; |
michael@0 | 505 | oX1[3]= iX[0]; |
michael@0 | 506 | iX+=4; |
michael@0 | 507 | }while(oX1>oX2); |
michael@0 | 508 | } |
michael@0 | 509 | } |
michael@0 | 510 |