kiss_fftr_tm.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* Copyright (C) 2007 Hong Zhiqian */
  2. /**
  3. @file kiss_fftr_tm.h
  4. @author Hong Zhiqian
  5. @brief Various compatibility routines for Speex (TriMedia version)
  6. */
  7. /*
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions
  10. are met:
  11. - Redistributions of source code must retain the above copyright
  12. notice, this list of conditions and the following disclaimer.
  13. - Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in the
  15. documentation and/or other materials provided with the distribution.
  16. - Neither the name of the Xiph.org Foundation nor the names of its
  17. contributors may be used to endorse or promote products derived from
  18. this software without specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  23. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #include "_kiss_fft_guts_tm.h"
  32. #ifdef TM_ASM
  33. #include "profile_tm.h"
  34. #ifdef FIXED_POINT
  35. #define TM_NDIV(res,c,frac) \
  36. { register int c1, c0; \
  37. \
  38. c1 = -asri(16,(c)); \
  39. c0 = sex16((c)); \
  40. (res) = pack16lsb(sround(c1 * (32767/(frac))), sround(c0 * (32767/(frac))));\
  41. }
  42. #define OVERRIDE_KISS_FFTR
  43. void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar * restrict timedata, kiss_fft_cpx * restrict freqdata)
  44. {
  45. register int ncfft, ncfft2, k;
  46. register int * restrict tmpbuf;
  47. register int * restrict twiddles;
  48. ncfft = st->substate->nfft;
  49. ncfft2 = ncfft >> 1;
  50. tmpbuf = (int*)st->tmpbuf;
  51. twiddles = (int*)st->super_twiddles;
  52. TMDEBUG_ALIGNMEM(timedata);
  53. TMDEBUG_ALIGNMEM(freqdata);
  54. TMDEBUG_ALIGNMEM(tmpbuf);
  55. TMDEBUG_ALIGNMEM(twiddles);
  56. kiss_fft(st->substate , (const kiss_fft_cpx*)timedata, st->tmpbuf);
  57. {
  58. register int tdcr, tdci;
  59. tdcr = sround(st->tmpbuf[0].r * (32767/2));
  60. tdci = sround(st->tmpbuf[0].i * (32767/2));
  61. freqdata[0].r = tdcr + tdci;
  62. freqdata[ncfft].r = tdcr - tdci;
  63. freqdata[ncfft].i = freqdata[0].i = 0;
  64. }
  65. for ( k=1 ; k <= ncfft2 ; ++k )
  66. {
  67. register int fpk, fpnk, i, tw, f1k, f2k;
  68. register int fq1, fq2;
  69. i = ncfft-k;
  70. fpk = ld32x(tmpbuf,k);
  71. tw = ld32x(twiddles,k);
  72. fpnk = ld32x(tmpbuf,i);
  73. TM_DIV(fpk, fpk, 2);
  74. TM_NDIV(fpnk,fpnk,2);
  75. TM_ADD( f1k, fpk , fpnk );
  76. TM_SUB( f2k, fpk , fpnk );
  77. TM_MUL( tw , f2k, tw );
  78. TM_ADD( fq1, f1k, tw );
  79. TM_SHR( fq1, fq1, 1 );
  80. TM_SUB( fq2, f1k, tw );
  81. TM_NEGMSB( fq2, fq2 );
  82. TM_SHR( fq2, fq2, 1 );
  83. st32d( k<<2, freqdata, fq1 );
  84. st32d( i<<2, freqdata, fq2 );
  85. }
  86. }
  87. #define OVERRIDE_KISS_FFTRI
  88. void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx * restrict freqdata,kiss_fft_scalar * restrict timedata)
  89. {
  90. register int k, ncfft, ncfft2;
  91. register int * restrict tmpbuf;
  92. register int * restrict twiddles;
  93. ncfft = st->substate->nfft;
  94. ncfft2 = ncfft >> 1;
  95. tmpbuf = (int*)st->tmpbuf;
  96. twiddles = (int*)st->super_twiddles;
  97. TMDEBUG_ALIGNMEM(freqdata);
  98. TMDEBUG_ALIGNMEM(timedata);
  99. TMDEBUG_ALIGNMEM(tmpbuf);
  100. TMDEBUG_ALIGNMEM(twiddles);
  101. {
  102. register int fqr, fqnr;
  103. fqr = freqdata[0].r;
  104. fqnr = freqdata[ncfft].r;
  105. st->tmpbuf[0].r = fqr + fqnr;
  106. st->tmpbuf[0].i = fqr - fqnr;
  107. }
  108. for ( k=1 ; k <= ncfft2 ; ++k )
  109. {
  110. register int fk, fnkc, i, tw, fek, fok, tmp;
  111. register int tbk, tbn;
  112. i = ncfft-k;
  113. fk = ld32x(freqdata,k);
  114. tw = ld32x(twiddles,k);
  115. fnkc = pack16lsb(-freqdata[i].i, freqdata[i].r);
  116. TM_ADD (fek, fk, fnkc);
  117. TM_SUB (tmp, fk, fnkc);
  118. TM_MUL (fok, tmp, tw );
  119. TM_ADD (tbk, fek, fok);
  120. TM_SUB (tbn, fek, fok);
  121. TM_NEGMSB(tbn, tbn);
  122. st32d(k<<2, tmpbuf, tbk);
  123. st32d(i<<2, tmpbuf, tbn);
  124. }
  125. kiss_fft (st->substate, st->tmpbuf, (kiss_fft_cpx *) timedata);
  126. }
  127. #else
  128. #define OVERRIDE_KISS_FFTR
  129. void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar * restrict timedata,kiss_fft_cpx * restrict freqdata)
  130. {
  131. register kiss_fft_cpx fpnk, fpk, f1k, f2k, twk;
  132. register int k, ncfft;
  133. register kiss_fft_cpx * restrict tmpbuf, * restrict tw;
  134. register float tdcr, tdci;
  135. ncfft = st->substate->nfft;
  136. tmpbuf= st->tmpbuf;
  137. tw = st->super_twiddles;
  138. kiss_fft( st->substate , (const kiss_fft_cpx*)timedata, tmpbuf );
  139. tdcr = tmpbuf[0].r;
  140. tdci = tmpbuf[0].i;
  141. freqdata[0].r = tdcr + tdci;
  142. freqdata[ncfft].r = tdcr - tdci;
  143. freqdata[ncfft].i = freqdata[0].i = 0;
  144. for ( k=1;k <= ncfft/2 ; ++k )
  145. {
  146. fpk = tmpbuf[k];
  147. fpnk.r = tmpbuf[ncfft-k].r;
  148. fpnk.i = -tmpbuf[ncfft-k].i;
  149. C_ADD( f1k, fpk , fpnk );
  150. C_SUB( f2k, fpk , fpnk );
  151. C_MUL( twk, f2k , tw[k]);
  152. freqdata[k].r = HALF_OF(f1k.r + twk.r);
  153. freqdata[k].i = HALF_OF(f1k.i + twk.i);
  154. freqdata[ncfft-k].r = HALF_OF(f1k.r - twk.r);
  155. freqdata[ncfft-k].i = HALF_OF(twk.i - f1k.i);
  156. }
  157. }
  158. #define OVERRIDE_KISS_FFTRI
  159. void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx * restrict freqdata,kiss_fft_scalar * restrict timedata)
  160. {
  161. register int k, ncfft;
  162. register kiss_fft_cpx * restrict tmpbuf, * restrict tw;
  163. ncfft = st->substate->nfft;
  164. tmpbuf= st->tmpbuf;
  165. tw = st->super_twiddles;
  166. tmpbuf[0].r = freqdata[0].r + freqdata[ncfft].r;
  167. tmpbuf[0].i = freqdata[0].r - freqdata[ncfft].r;
  168. for (k = 1; k <= ncfft / 2; ++k)
  169. {
  170. register kiss_fft_cpx fk, fnkc, fek, fok, tmp;
  171. fk = freqdata[k];
  172. fnkc.r = freqdata[ncfft - k].r;
  173. fnkc.i = -freqdata[ncfft - k].i;
  174. C_ADD (fek, fk, fnkc);
  175. C_SUB (tmp, fk, fnkc);
  176. C_MUL (fok,tmp,tw[k]);
  177. C_ADD (tmpbuf[k],fek, fok);
  178. C_SUB (tmp, fek, fok);
  179. tmpbuf[ncfft - k].r = tmp.r;
  180. tmpbuf[ncfft - k].i = -tmp.i;
  181. }
  182. kiss_fft (st->substate, st->tmpbuf, (kiss_fft_cpx *) timedata);
  183. }
  184. #endif
  185. #endif