www.pudn.com > av3dec_20050318.zip > intMDCT.c
/* *********************************************************************** * COPYRIGHT AND WARRANTY INFORMATION * * Copyright 2004, Audio Video Coding Standard, Part III * * This software module was originally developed by * edited by * * DISCLAIMER OF WARRANTY * * These software programs are available to the users without any * license fee or royalty on an "as is" basis. The AVS disclaims * any and all warranties, whether express, implied, or statutory, * including any implied warranties of merchantability or of fitness * for a particular purpose. In no event shall the contributors or * the AVS be liable for any incidental, punitive, or consequential * damages of any kind whatsoever arising from the use of this program. * * This disclaimer of warranty extends to the user of this program * and user's customers, employees, agents, transferees, successors, * and assigns. * * The AVS does not represent or warrant that the program furnished * hereunder are free of infringement of any third-party patents. * Commercial implementations of AVS, including shareware, may be * subject to royalty fees to patent holders. Information regarding * the AVS patent policy is available from the AVS Web site at * http://www.avs.org.cn * * THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE AVS PATENT POLICY. ************************************************************************ */ #include#include #include #include "common.h" #include "av3dec.h" #include "intMDCT.h" #ifdef _WIN32_WCE #define assert(x) #else #include #endif int log2int(int x) { int m; if (x<0) x = -x; for (m=0; x>1; x>>=1) m++; return (m); } int msbHeadroomINT32(int *x, int len) { int i,max; max = 0; for (i=0; i 0) for (i=0; i 0) for (i=0; i >(shift-1))+1)>>1); } int calPreShiftINT32(int *x, int len) { int m; m = msbHeadroomINT32(x,len); if (m>8) return (m-6); else return (2); } int multiINT32 (int x, int y) { return ((int)((((__int64)x*y)>>(SHIFT-1))+1)>>1); } void hardamard(int* u0, int* u1, int* u2, int* u3) { *u2 = *u2 + *u0; *u0 = -*u0; *u3 = *u3 - *u1; *u1 = -*u1; *u0 = *u0 + ((*u2+*u3+1)>>1); *u1 = *u1 + ((*u2-*u3+1)>>1); *u2 = *u2 - *u1; *u3 = *u3 - *u0; *u0 = -*u0; } void dctII_4p(int *x) { int tmp; hardamard(&x[0],&x[1],&x[2],&x[3]); // Lifting rotation // angle = pi/8 // | c -s | = | 1 0 | | 1 -s | | 1 0 | // | s c | | t 1 | | 0 1 | | t 1 | x[0] = x[0] + multiINT32(TAN_PI_16,x[1]); x[1] = x[1] - multiINT32(SIN_PI_8,x[0]); x[0] = x[0] + multiINT32(TAN_PI_16,x[1]); tmp = x[0]; x[0] = x[2]; x[2] = x[3]; x[3] = x[1]; x[1] = tmp; } void dctII_8p(int *x) { int u[8]; int tmp,tmp1; u[0] = x[0]; u[1] = x[7]; u[2] = x[3]; u[3] = x[4]; u[4] = x[1]; u[5] = x[6]; u[6] = x[2]; u[7] = x[5]; hardamard(&u[0],&u[1],&u[2],&u[3]); hardamard(&u[4],&u[5],&u[6],&u[7]); // Rotation A1 // sin(pi/4) * | 1 -1 | // | 1 1 | tmp = multiINT32((u[1]-u[3]),SIN_PI_4); tmp1 = multiINT32((u[1]+u[3]),SIN_PI_4); u[1] = tmp; u[3] = tmp1; hardamard(&u[1],&u[7],&u[5],&u[3]); // Rotation A2 // sin(pi/4) * | 1 1 | // | 1 -1 | x[0] = multiINT32((u[2]+u[6]),SIN_PI_4); x[4] = multiINT32((u[2]-u[6]),SIN_PI_4); // Lifting rotation B // angle = pi/8 // | s c | = |-t 1 | |-1 s | | 1 0 | // |-c s | | 1 0 | | 0 1 | | t 1 | u[0] = u[0] + multiINT32(TAN_PI_16,u[4]); x[6] = multiINT32(SIN_PI_8,u[0]) - u[4]; x[2] = u[0] - multiINT32(TAN_PI_16,x[6]); // Lifting rotation C // angle = 3pi/16 // | c -s | = | t 1 | |-1 -s | | 0 1 | // |-s -c | | 1 0 | | 0 1 | | 1 -t | u[5] = u[5] - multiINT32(TAN_3PI_32,u[1]); x[7] = -u[1] - multiINT32(SIN_3PI_16,u[5]); x[1] = u[5] + multiINT32(TAN_3PI_32,x[7]); // Lifting rotation D // angle = pi/16 // | c s | = |-t 1 | |-1 s | | 0 1 | // | s -c | | 1 0 | | 0 1 | | 1 t | u[3] = u[3] + multiINT32(TAN_PI_32,u[7]); x[3] = multiINT32(SIN_PI_16,u[3]) - u[7]; x[5] = u[3] - multiINT32(TAN_PI_32,x[3]); } void flipud(int *u, int len) { int i,len1,tmp; len1 = len>>1; for (i=0; i >1; for (i=0; i >1; len2 = len>>2; for (i=0; i >1; // Matrix T - Rotation step = 1<<(LOG2_N_MDCT-logm); for (i=0; i >1; // Matrix P - alternative implementation flipud(&u[m2],m2); permute(u,logm,1); // Transpose of matrix B for (i=1; i >1; // Matrix A2 for (i=0; i >1; // Matrix J flipud(&u[m2],m2); // Matrix P - alternative implementation flipud(&u[m2],m2); permute(u,logm,1); } void MDCT_window(int *signal, int len, int dir) { int i,len1,step; len1 = (len>>1); if (len==N_MDCT) step = 1; // Long block else step = 8; // Short block // Sine window for (i=0; i >1; len2 = len>>2; for (i=0; i >1; len2 = len>>2; for (i=0; i >1; len2 = len>>2; if (len==N_MDCT) step = 1; // Long block else step = 8; // Short block v1 = &liftBuffer[len1]; v2 = &liftBuffer[len]; for (i=0; i >1; len2 = len>>2; if (len==N_MDCT) step = 1; // Long block else step = 8; // Short block // Forward integer DCT-IV // C4 = R1*R2*S*T1*T2*Peo // Step(1) Even-odd permutation matrix Peo permute(signal0,log2int(len),-1); // Step(2) Lifting matrix T2 liftingStepT2(signal0,signal1,liftBuffer,len); for (i=0; i >1; len2 = len>>2; if (len==N_MDCT) step = 1; // Long block else step = 8; // Short block // Integer inverse DCT-IV // Inv(C4) = Inv(R1*R2*S*T1*T2*Peo) // Inverse step(6) Lifting matrix R1 for (i=0; i