dct.c
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:9k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #include "statname.h"
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. void fdct32(float x[], float c[]);
  40. #ifdef __cplusplus
  41. }
  42. #endif
  43. /* JR - converted to ROM table */
  44. extern const float coef32[31];            /* 32 pt dct coefs */
  45. /* JR - made coef[] const */
  46. static void forward_bf(int m, int n, float x[], float f[], const float coef[])
  47. {
  48. int i, j, n2;
  49. int p, q, p0, k;
  50. p0 = 0;
  51. n2 = n >> 1;
  52. for(i=0; i<m; i++, p0+=n) {
  53.    k = 0;
  54.    p = p0;
  55.    q = p+n-1;
  56.    for(j=0; j<n2; j++, p++, q--, k++) {
  57.         f[p] = x[p]+x[q];
  58.         f[n2+p] = coef[k]*(x[p]-x[q]);
  59.         }
  60. }
  61. }
  62. /*------------------------------------------------------------*/
  63. static void back_bf(int m, int n, float x[], float f[])
  64. {
  65. int i, j, n2, n21;
  66. int p, q, p0;
  67. p0 = 0;
  68. n2 = n >> 1;
  69. n21 = n2-1;
  70. for(i=0; i<m; i++, p0+=n) {
  71.    p = p0;
  72.    q = p0;
  73.    for(j=0; j<n2; j++, p+=2, q++) f[p] = x[q];
  74.    p = p0+1;
  75.    for(j=0; j<n21; j++, p+=2, q++) f[p] = x[q] + x[q+1];
  76.    f[p] = x[q];
  77. }
  78. }
  79. /*------------------------------------------------------------*/
  80. void fdct32(float x[], float c[])
  81. {
  82. float a[32];        /* ping pong buffers */
  83. float b[32];
  84. int p, q;
  85. /* special first stage */
  86. for(p=0, q=31; p<16; p++, q--) {
  87.      a[p] = x[p]+x[q];
  88.      a[16+p] = coef32[p]*(x[p]-x[q]);
  89.      }
  90. forward_bf(2, 16, a, b, coef32+16);
  91. forward_bf(4,  8, b, a, coef32+16+8);
  92. forward_bf(8,  4, a, b, coef32+16+8+4);
  93. forward_bf(16, 2, b, a, coef32+16+8+4+2);
  94. back_bf(8, 4, a, b);
  95. back_bf(4, 8, b, a);
  96. back_bf(2, 16, a, b);
  97. back_bf(1, 32, b, c);
  98. }
  99. /*------------------------------------------------------------*/
  100. void fdct32_dual(float x[], float c[])
  101. {
  102. float a[32];        /* ping pong buffers */
  103. float b[32];
  104. int p, pp, qq;
  105. /* special first stage for dual chan (interleaved x) */
  106. pp = 0;
  107. qq = 2*31;
  108. for(p=0; p<16; p++, pp+=2, qq-=2) {
  109.      a[p] = x[pp]+x[qq];
  110.      a[16+p] = coef32[p]*(x[pp]-x[qq]);
  111.      }
  112. forward_bf(2, 16, a, b, coef32+16);
  113. forward_bf(4,  8, b, a, coef32+16+8);
  114. forward_bf(8,  4, a, b, coef32+16+8+4);
  115. forward_bf(16, 2, b, a, coef32+16+8+4+2);
  116. back_bf(8, 4, a, b);
  117. back_bf(4, 8, b, a);
  118. back_bf(2, 16, a, b);
  119. back_bf(1, 32, b, c);
  120. }
  121. /*---------------convert dual to mono------------------------------*/
  122. void fdct32_dual_mono(float x[], float c[])
  123. {
  124. float a[32];        /* ping pong buffers */
  125. float b[32];
  126. float t1, t2;
  127. int p, pp, qq;
  128. /* special first stage  */
  129. pp = 0;
  130. qq = 2*31;
  131. for(p=0; p<16; p++, pp+=2, qq-=2) {
  132.      t1 = 0.5F*(x[pp]+x[pp+1]);
  133.      t2 = 0.5F*(x[qq]+x[qq+1]);
  134.      a[p] = t1+t2;
  135.      a[16+p] = coef32[p]*(t1-t2);
  136.      }
  137. forward_bf(2, 16, a, b, coef32+16);
  138. forward_bf(4,  8, b, a, coef32+16+8);
  139. forward_bf(8,  4, a, b, coef32+16+8+4);
  140. forward_bf(16, 2, b, a, coef32+16+8+4+2);
  141. back_bf(8, 4, a, b);
  142. back_bf(4, 8, b, a);
  143. back_bf(2, 16, a, b);
  144. back_bf(1, 32, b, c);
  145. }
  146. /*------------------------------------------------------------*/
  147. #ifdef REDUCTION
  148. /*------------------------------------------------------------*/
  149. /*---------------- 16 pt fdct -------------------------------*/
  150. void fdct16(float x[], float c[])
  151. {
  152. float a[16];        /* ping pong buffers */
  153. float b[16];
  154. int p, q;
  155. /* special first stage (drop highest sb) */
  156. a[0] = x[0];
  157. a[8] = coef32[16]*x[0];
  158. for(p=1, q=14; p<8; p++, q--) {
  159.      a[p] = x[p]+x[q];
  160.      a[8+p] = coef32[16+p]*(x[p]-x[q]);
  161.      }
  162. forward_bf(2,  8, a, b, coef32+16+8);
  163. forward_bf(4,  4, b, a, coef32+16+8+4);
  164. forward_bf(8,  2, a, b, coef32+16+8+4+2);
  165. back_bf(4,  4, b, a);
  166. back_bf(2,  8, a, b);
  167. back_bf(1, 16, b, c);
  168. }
  169. /*------------------------------------------------------------*/
  170. /*---------------- 16 pt fdct dual chan---------------------*/
  171. void fdct16_dual(float x[], float c[])
  172. {
  173. float a[16];        /* ping pong buffers */
  174. float b[16];
  175. int p, pp, qq;
  176. /* special first stage for interleaved input */
  177. a[0] = x[0];
  178. a[8] = coef32[16]*x[0];
  179. pp = 2;
  180. qq = 2*14;
  181. for(p=1; p<8; p++, pp+=2, qq-=2) {
  182.      a[p] = x[pp]+x[qq];
  183.      a[8+p] = coef32[16+p]*(x[pp]-x[qq]);
  184.      }
  185. forward_bf(2,  8, a, b, coef32+16+8);
  186. forward_bf(4,  4, b, a, coef32+16+8+4);
  187. forward_bf(8,  2, a, b, coef32+16+8+4+2);
  188. back_bf(4,  4, b, a);
  189. back_bf(2,  8, a, b);
  190. back_bf(1, 16, b, c);
  191. }
  192. /*------------------------------------------------------------*/
  193. /*---------------- 16 pt fdct dual to mono-------------------*/
  194. void fdct16_dual_mono(float x[], float c[])
  195. {
  196. float a[16];        /* ping pong buffers */
  197. float b[16];
  198. float t1, t2;
  199. int p, pp, qq;
  200. /* special first stage  */
  201. a[0] = 0.5F*(x[0]+x[1]);
  202. a[8] = coef32[16]*a[0];
  203. pp = 2;
  204. qq = 2*14;
  205. for(p=1; p<8; p++, pp+=2, qq-=2) {
  206.      t1 = 0.5F*(x[pp]+x[pp+1]);
  207.      t2 = 0.5F*(x[qq]+x[qq+1]);
  208.      a[p] = t1 + t2;
  209.      a[8+p] = coef32[16+p]*(t1-t2);
  210.      }
  211. forward_bf(2,  8, a, b, coef32+16+8);
  212. forward_bf(4,  4, b, a, coef32+16+8+4);
  213. forward_bf(8,  2, a, b, coef32+16+8+4+2);
  214. back_bf(4,  4, b, a);
  215. back_bf(2,  8, a, b);
  216. back_bf(1, 16, b, c);
  217. }
  218. /*------------------------------------------------------------*/
  219. /*---------------- 8 pt fdct -------------------------------*/
  220. void fdct8(float x[], float c[])
  221. {
  222. float a[8];        /* ping pong buffers */
  223. float b[8];
  224. int p, q;
  225. /* special first stage  */
  226. b[0] = x[0]+x[7];
  227. b[4] = coef32[16+8]*(x[0]-x[7]);
  228. for(p=1, q=6; p<4; p++, q--) {
  229.      b[p] = x[p]+x[q];
  230.      b[4+p] = coef32[16+8+p]*(x[p]-x[q]);
  231.      }
  232. forward_bf(2,  4, b, a, coef32+16+8+4);
  233. forward_bf(4,  2, a, b, coef32+16+8+4+2);
  234. back_bf(2,  4, b, a);
  235. back_bf(1,  8, a, c);
  236. }
  237. /*------------------------------------------------------------*/
  238. /*---------------- 8 pt fdct dual chan---------------------*/
  239. void fdct8_dual(float x[], float c[])
  240. {
  241. float a[8];        /* ping pong buffers */
  242. float b[8];
  243. int p, pp, qq;
  244. /* special first stage for interleaved input */
  245. b[0] = x[0]+x[14];
  246. b[4] = coef32[16+8]*(x[0]-x[14]);
  247. pp = 2;
  248. qq = 2*6;
  249. for(p=1; p<4; p++, pp+=2, qq-=2) {
  250.      b[p] = x[pp]+x[qq];
  251.      b[4+p] = coef32[16+8+p]*(x[pp]-x[qq]);
  252.      }
  253. forward_bf(2,  4, b, a, coef32+16+8+4);
  254. forward_bf(4,  2, a, b, coef32+16+8+4+2);
  255. back_bf(2,  4, b, a);
  256. back_bf(1,  8, a, c);
  257. }
  258. /*------------------------------------------------------------*/
  259. /*---------------- 8 pt fdct dual to mono---------------------*/
  260. void fdct8_dual_mono(float x[], float c[])
  261. {
  262. float a[8];        /* ping pong buffers */
  263. float b[8];
  264. float t1, t2;
  265. int p, pp, qq;
  266. /* special first stage  */
  267. t1 = 0.5F*(x[0]+x[1]);
  268. t2 = 0.5F*(x[14]+x[15]);
  269. b[0] = t1+t2;
  270. b[4] = coef32[16+8]*(t1-t2);
  271. pp = 2;
  272. qq = 2*6;
  273. for(p=1; p<4; p++, pp+=2, qq-=2) {
  274.      t1 = 0.5F*(x[pp]+x[pp+1]);
  275.      t2 = 0.5F*(x[qq]+x[qq+1]);
  276.      b[p] = t1 + t2;
  277.      b[4+p] = coef32[16+8+p]*(t1 - t2);
  278.      }
  279. forward_bf(2,  4, b, a, coef32+16+8+4);
  280. forward_bf(4,  2, a, b, coef32+16+8+4+2);
  281. back_bf(2,  4, b, a);
  282. back_bf(1,  8, a, c);
  283. }
  284. /*------------------------------------------------------------*/
  285. #endif      // end conditional reduction