sbc_dct.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 1999-2012 Broadcom Corporation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at:
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. ******************************************************************************/
  18. /******************************************************************************
  19. *
  20. * source file for fast dct operations
  21. *
  22. ******************************************************************************/
  23. #include "sbc_encoder.h"
  24. #include "sbc_enc_func_declare.h"
  25. #include "sbc_dct.h"
  26. /*******************************************************************************
  27. **
  28. ** Function SBC_FastIDCT8
  29. **
  30. ** Description implementation of fast DCT algorithm by Feig and Winograd
  31. **
  32. **
  33. ** Returns y = dct(pInVect)
  34. **
  35. **
  36. *******************************************************************************/
  37. #if (SBC_IS_64_MULT_IN_IDCT == FALSE)
  38. #define SBC_COS_PI_SUR_4 (0x00005a82) /* ((0x8000) * 0.7071) = cos(pi/4) */
  39. #define SBC_COS_PI_SUR_8 (0x00007641) /* ((0x8000) * 0.9239) = (cos(pi/8)) */
  40. #define SBC_COS_3PI_SUR_8 (0x000030fb) /* ((0x8000) * 0.3827) = (cos(3*pi/8)) */
  41. #define SBC_COS_PI_SUR_16 (0x00007d8a) /* ((0x8000) * 0.9808)) = (cos(pi/16)) */
  42. #define SBC_COS_3PI_SUR_16 (0x00006a6d) /* ((0x8000) * 0.8315)) = (cos(3*pi/16)) */
  43. #define SBC_COS_5PI_SUR_16 (0x0000471c) /* ((0x8000) * 0.5556)) = (cos(5*pi/16)) */
  44. #define SBC_COS_7PI_SUR_16 (0x000018f8) /* ((0x8000) * 0.1951)) = (cos(7*pi/16)) */
  45. #define SBC_IDCT_MULT(a,b,c) SBC_MULT_32_16_SIMPLIFIED(a,b,c)
  46. #else
  47. #define SBC_COS_PI_SUR_4 (0x5A827999) /* ((0x80000000) * 0.707106781) = (cos(pi/4) ) */
  48. #define SBC_COS_PI_SUR_8 (0x7641AF3C) /* ((0x80000000) * 0.923879533) = (cos(pi/8) ) */
  49. #define SBC_COS_3PI_SUR_8 (0x30FBC54D) /* ((0x80000000) * 0.382683432) = (cos(3*pi/8) ) */
  50. #define SBC_COS_PI_SUR_16 (0x7D8A5F3F) /* ((0x80000000) * 0.98078528 )) = (cos(pi/16) ) */
  51. #define SBC_COS_3PI_SUR_16 (0x6A6D98A4) /* ((0x80000000) * 0.831469612)) = (cos(3*pi/16)) */
  52. #define SBC_COS_5PI_SUR_16 (0x471CECE6) /* ((0x80000000) * 0.555570233)) = (cos(5*pi/16)) */
  53. #define SBC_COS_7PI_SUR_16 (0x18F8B83C) /* ((0x80000000) * 0.195090322)) = (cos(7*pi/16)) */
  54. #define SBC_IDCT_MULT(a,b,c) SBC_MULT_32_32(a,b,c)
  55. #endif /* SBC_IS_64_MULT_IN_IDCT */
  56. #if (SBC_FAST_DCT == FALSE)
  57. extern const SINT16 gas16AnalDCTcoeff8[];
  58. extern const SINT16 gas16AnalDCTcoeff4[];
  59. #endif
  60. void SBC_FastIDCT8(SINT32 *pInVect, SINT32 *pOutVect)
  61. {
  62. #if (SBC_FAST_DCT == TRUE)
  63. #if (SBC_ARM_ASM_OPT==TRUE)
  64. #else
  65. #if (SBC_IPAQ_OPT==TRUE)
  66. #if (SBC_IS_64_MULT_IN_IDCT == TRUE)
  67. SINT64 s64Temp;
  68. #endif
  69. #else
  70. #if (SBC_IS_64_MULT_IN_IDCT == TRUE)
  71. SINT32 s32HiTemp;
  72. #else
  73. SINT32 s32In2Temp;
  74. register SINT32 s32In1Temp;
  75. #endif
  76. #endif
  77. #endif
  78. register SINT32 x0, x1, x2, x3, x4, x5, x6, x7,temp;
  79. SINT32 res_even[4], res_odd[4];
  80. /*x0= (pInVect[4])/2 ;*/
  81. SBC_IDCT_MULT(SBC_COS_PI_SUR_4,pInVect[4], x0);
  82. /*printf("x0 0x%x = %d = %d * %d\n", x0, x0, SBC_COS_PI_SUR_4, pInVect[4]);*/
  83. x1 = (pInVect[3] + pInVect[5]) >>1;
  84. x2 = (pInVect[2] + pInVect[6]) >>1;
  85. x3 = (pInVect[1] + pInVect[7]) >>1;
  86. x4 = (pInVect[0] + pInVect[8]) >>1;
  87. x5 = (pInVect[9] - pInVect[15]) >>1;
  88. x6 = (pInVect[10] - pInVect[14])>>1;
  89. x7 = (pInVect[11] - pInVect[13])>>1;
  90. /* 2-point IDCT of x0 and x4 as in (11) */
  91. temp = x0 ;
  92. SBC_IDCT_MULT(SBC_COS_PI_SUR_4, ( x0 + x4 ), x0); /*x0 = ( x0 + x4 ) * cos(1*pi/4) ; */
  93. SBC_IDCT_MULT(SBC_COS_PI_SUR_4, ( temp - x4 ), x4); /*x4 = ( temp - x4 ) * cos(1*pi/4) ; */
  94. /* rearrangement of x2 and x6 as in (15) */
  95. x2 -=x6;
  96. x6 <<= 1 ;
  97. /* 2-point IDCT of x2 and x6 and post-multiplication as in (15) */
  98. SBC_IDCT_MULT(SBC_COS_PI_SUR_4,x6, x6); /*x6 = x6 * cos(1*pi/4) ; */
  99. temp = x2 ;
  100. SBC_IDCT_MULT(SBC_COS_PI_SUR_8,( x2 + x6 ), x2); /*x2 = ( x2 + x6 ) * cos(1*pi/8) ; */
  101. SBC_IDCT_MULT(SBC_COS_3PI_SUR_8,( temp - x6 ), x6); /*x6 = ( temp - x6 ) * cos(3*pi/8) ;*/
  102. /* 4-point IDCT of x0,x2,x4 and x6 as in (11) */
  103. res_even[ 0 ] = x0 + x2 ;
  104. res_even[ 1 ] = x4 + x6 ;
  105. res_even[ 2 ] = x4 - x6 ;
  106. res_even[ 3 ] = x0 - x2 ;
  107. /* rearrangement of x1,x3,x5,x7 as in (15) */
  108. x7 <<= 1 ;
  109. x5 = ( x5 <<1 ) - x7 ;
  110. x3 = ( x3 <<1 ) - x5 ;
  111. x1 -= x3 >>1 ;
  112. /* two-dimensional IDCT of x1 and x5 */
  113. SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x5, x5); /*x5 = x5 * cos(1*pi/4) ; */
  114. temp = x1 ;
  115. x1 = x1 + x5 ;
  116. x5 = temp - x5 ;
  117. /* rearrangement of x3 and x7 as in (15) */
  118. x3 -= x7;
  119. x7 <<= 1 ;
  120. SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x7, x7); /*x7 = x7 * cos(1*pi/4) ; */
  121. /* 2-point IDCT of x3 and x7 and post-multiplication as in (15) */
  122. temp = x3 ;
  123. SBC_IDCT_MULT( SBC_COS_PI_SUR_8,( x3 + x7 ), x3); /*x3 = ( x3 + x7 ) * cos(1*pi/8) ; */
  124. SBC_IDCT_MULT( SBC_COS_3PI_SUR_8,( temp - x7 ), x7); /*x7 = ( temp - x7 ) * cos(3*pi/8) ;*/
  125. /* 4-point IDCT of x1,x3,x5 and x7 and post multiplication by diagonal matrix as in (14) */
  126. SBC_IDCT_MULT((SBC_COS_PI_SUR_16), ( x1 + x3 ) , res_odd[0]); /*res_odd[ 0 ] = ( x1 + x3 ) * cos(1*pi/16) ; */
  127. SBC_IDCT_MULT((SBC_COS_3PI_SUR_16), ( x5 + x7 ) , res_odd[1]); /*res_odd[ 1 ] = ( x5 + x7 ) * cos(3*pi/16) ; */
  128. SBC_IDCT_MULT((SBC_COS_5PI_SUR_16), ( x5 - x7 ) , res_odd[2]); /*res_odd[ 2 ] = ( x5 - x7 ) * cos(5*pi/16) ; */
  129. SBC_IDCT_MULT((SBC_COS_7PI_SUR_16), ( x1 - x3 ) , res_odd[3]); /*res_odd[ 3 ] = ( x1 - x3 ) * cos(7*pi/16) ; */
  130. /* additions and subtractions as in (9) */
  131. pOutVect[0] = (res_even[ 0 ] + res_odd[ 0 ]) ;
  132. pOutVect[1] = (res_even[ 1 ] + res_odd[ 1 ]) ;
  133. pOutVect[2] = (res_even[ 2 ] + res_odd[ 2 ]) ;
  134. pOutVect[3] = (res_even[ 3 ] + res_odd[ 3 ]) ;
  135. pOutVect[7] = (res_even[ 0 ] - res_odd[ 0 ]) ;
  136. pOutVect[6] = (res_even[ 1 ] - res_odd[ 1 ]) ;
  137. pOutVect[5] = (res_even[ 2 ] - res_odd[ 2 ]) ;
  138. pOutVect[4] = (res_even[ 3 ] - res_odd[ 3 ]) ;
  139. #else
  140. UINT8 Index, k;
  141. SINT32 temp;
  142. /*Calculate 4 subband samples by matrixing*/
  143. for(Index=0; Index<8; Index++)
  144. {
  145. temp = 0;
  146. for(k=0; k<16; k++)
  147. {
  148. /*temp += (SINT32)(((SINT64)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 );*/
  149. temp += (gas16AnalDCTcoeff8[(Index*8*2)+k] * (pInVect[k] >> 16));
  150. temp += ((gas16AnalDCTcoeff8[(Index*8*2)+k] * (pInVect[k] & 0xFFFF)) >> 16);
  151. }
  152. pOutVect[Index] = temp;
  153. }
  154. #endif
  155. /* printf("pOutVect: 0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x;0x%x\n",\
  156. pOutVect[0],pOutVect[1],pOutVect[2],pOutVect[3],pOutVect[4],pOutVect[5],pOutVect[6],pOutVect[7]);*/
  157. }
  158. /*******************************************************************************
  159. **
  160. ** Function SBC_FastIDCT4
  161. **
  162. ** Description implementation of fast DCT algorithm by Feig and Winograd
  163. **
  164. **
  165. ** Returns y = dct(x0)
  166. **
  167. **
  168. *******************************************************************************/
  169. void SBC_FastIDCT4(SINT32 *pInVect, SINT32 *pOutVect)
  170. {
  171. #if (SBC_FAST_DCT == TRUE)
  172. #if (SBC_ARM_ASM_OPT==TRUE)
  173. #else
  174. #if (SBC_IPAQ_OPT==TRUE)
  175. #if (SBC_IS_64_MULT_IN_IDCT == TRUE)
  176. SINT64 s64Temp;
  177. #endif
  178. #else
  179. #if (SBC_IS_64_MULT_IN_IDCT == TRUE)
  180. SINT32 s32HiTemp;
  181. #else
  182. UINT16 s32In2Temp;
  183. SINT32 s32In1Temp;
  184. #endif
  185. #endif
  186. #endif
  187. SINT32 temp,x2;
  188. SINT32 tmp[8];
  189. x2=pInVect[2]>>1;
  190. temp=(pInVect[0]+pInVect[4]);
  191. SBC_IDCT_MULT((SBC_COS_PI_SUR_4>>1), temp , tmp[0]);
  192. tmp[1]=x2-tmp[0];
  193. tmp[0]+=x2;
  194. temp=(pInVect[1]+pInVect[3]);
  195. SBC_IDCT_MULT((SBC_COS_3PI_SUR_8>>1), temp , tmp[3]);
  196. SBC_IDCT_MULT((SBC_COS_PI_SUR_8>>1), temp , tmp[2]);
  197. temp=(pInVect[5]-pInVect[7]);
  198. SBC_IDCT_MULT((SBC_COS_3PI_SUR_8>>1), temp , tmp[5]);
  199. SBC_IDCT_MULT((SBC_COS_PI_SUR_8>>1), temp , tmp[4]);
  200. tmp[6]=tmp[2]+tmp[5];
  201. tmp[7]=tmp[3]-tmp[4];
  202. pOutVect[0] = (tmp[0]+tmp[6]);
  203. pOutVect[1] = (tmp[1]+tmp[7]);
  204. pOutVect[2] = (tmp[1]-tmp[7]);
  205. pOutVect[3] = (tmp[0]-tmp[6]);
  206. #else
  207. UINT8 Index, k;
  208. SINT32 temp;
  209. /*Calculate 4 subband samples by matrixing*/
  210. for(Index=0; Index<4; Index++)
  211. {
  212. temp = 0;
  213. for(k=0; k<8; k++)
  214. {
  215. /*temp += (SINT32)(((SINT64)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 ); */
  216. temp += (gas16AnalDCTcoeff4[(Index*4*2)+k] * (pInVect[k] >> 16));
  217. temp += ((gas16AnalDCTcoeff4[(Index*4*2)+k] * (pInVect[k] & 0xFFFF)) >> 16);
  218. }
  219. pOutVect[Index] = temp;
  220. }
  221. #endif
  222. }