_kiss_fft_guts_tm.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* Copyright (C) 2007 Hong Zhiqian */
  2. /**
  3. @file _kiss_fft_guts_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. #ifndef _KISS_FFT_GUTS_TM_
  32. #define _KISS_FFT_GUTS_TM_
  33. #ifdef TM_ASM
  34. #include <ops/custom_defs.h>
  35. #ifdef FIXED_POINT
  36. #undef sround
  37. #define sround(x) sex16(((x) + (1<<(FRACBITS-1)) ) >> FRACBITS)
  38. #undef MIN
  39. #undef MAX
  40. #define MIN(a,b) imin(a,b)
  41. #define MAX(a,b) imax(a,b)
  42. #define TM_MUL(res,a,b) \
  43. { register int a0, a1, b0, b1; \
  44. \
  45. a0 = sex16((a)); \
  46. a1 = asri(16,(a)); \
  47. b0 = sex16((b)); \
  48. b1 = asri(16,(b)); \
  49. (res)= pack16lsb( \
  50. sround(ifir16((a),funshift2((b),(b)))), \
  51. sround(a0*b0-a1*b1)); \
  52. } \
  53. #define TM_ADD(res,a,b) \
  54. { (res)=dspidualadd((a),(b)); \
  55. } \
  56. #define TM_SUB(res,a,b) \
  57. { (res)=dspidualsub((a),(b)); \
  58. } \
  59. #define TM_SHR(res,a,shift) \
  60. { (res)=dualasr((a),(shift)); \
  61. } \
  62. #define TM_DIV(res,c,frac) \
  63. { register int c1, c0; \
  64. \
  65. c1 = asri(16,(c)); \
  66. c0 = sex16((c)); \
  67. (res) = pack16lsb(sround(c1 * (32767/(frac))), sround(c0 * (32767/(frac))));\
  68. } \
  69. #define TM_NEGMSB(res, a) \
  70. { (res) = pack16lsb((ineg(asri(16,(a)))), (a)); \
  71. } \
  72. #else
  73. #undef MIN
  74. #undef MAX
  75. #define MIN(a,b) fmin(a,b)
  76. #define MAX(a,b) fmax(a,b)
  77. #endif
  78. #endif
  79. #undef CHECKBUF
  80. #define CHECKBUF(buf,nbuf,n) \
  81. { \
  82. if ( nbuf < (size_t)(n) ) { \
  83. speex_free(buf); \
  84. buf = (kiss_fft_cpx*)KISS_FFT_MALLOC(sizeof(kiss_fft_cpx)*(n)); \
  85. nbuf = (size_t)(n); \
  86. } \
  87. } \
  88. #undef C_ADD
  89. #define C_ADD( res, a,b) \
  90. { \
  91. CHECK_OVERFLOW_OP((a).r,+,(b).r) \
  92. CHECK_OVERFLOW_OP((a).i,+,(b).i) \
  93. (res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \
  94. } \
  95. #undef C_SUB
  96. #define C_SUB( res, a,b) \
  97. { \
  98. CHECK_OVERFLOW_OP((a).r,-,(b).r) \
  99. CHECK_OVERFLOW_OP((a).i,-,(b).i) \
  100. (res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \
  101. } \
  102. #undef C_ADDTO
  103. #define C_ADDTO( res , a) \
  104. { \
  105. CHECK_OVERFLOW_OP((res).r,+,(a).r) \
  106. CHECK_OVERFLOW_OP((res).i,+,(a).i) \
  107. (res).r += (a).r; (res).i += (a).i; \
  108. } \
  109. #undef C_SUBFROM
  110. #define C_SUBFROM( res, a) \
  111. { \
  112. CHECK_OVERFLOW_OP((res).r,-,(a).r) \
  113. CHECK_OVERFLOW_OP((res).i,-,(a).i) \
  114. (res).r -= (a).r; (res).i -= (a).i; \
  115. } \
  116. #undef kf_cexp
  117. #define kf_cexp(x,phase) \
  118. { (x)->r = KISS_FFT_COS(phase); \
  119. (x)->i = KISS_FFT_SIN(phase); } \
  120. #undef kf_cexp2
  121. #define kf_cexp2(x,phase) \
  122. { (x)->r = spx_cos_norm((phase)); \
  123. (x)->i = spx_cos_norm((phase)-32768); } \
  124. #ifdef FIXED_POINT
  125. #undef C_MUL
  126. #define C_MUL(m,a,b) \
  127. { (m).r = sround( smul((a).r,(b).r) - smul((a).i,(b).i) ); \
  128. (m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); } \
  129. #undef C_FIXDIV
  130. #define C_FIXDIV(c,div) \
  131. { DIVSCALAR( (c).r , div); \
  132. DIVSCALAR( (c).i , div); } \
  133. #undef C_MULBYSCALAR
  134. #define C_MULBYSCALAR( c, s ) \
  135. { (c).r = sround( smul( (c).r , s ) ) ; \
  136. (c).i = sround( smul( (c).i , s ) ) ; } \
  137. #else
  138. #undef C_MUL
  139. #define C_MUL(m,a,b) \
  140. { (m).r = (a).r*(b).r - (a).i*(b).i; \
  141. (m).i = (a).r*(b).i + (a).i*(b).r; } \
  142. #undef C_MULBYSCALAR
  143. #define C_MULBYSCALAR( c, s ) \
  144. { (c).r *= (s); \
  145. (c).i *= (s); } \
  146. #endif
  147. #endif