filterbank_tm.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /* Copyright (C) 2007 Hong Zhiqian */
  2. /**
  3. @file filterbank_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 <ops/custom_defs.h>
  32. #include "profile_tm.h"
  33. #ifdef FIXED_POINT
  34. #define OVERRIDE_FILTERBANK_COMPUTE_BANK32
  35. void filterbank_compute_bank32(FilterBank * restrict bank, spx_word32_t * restrict ps, spx_word32_t * restrict mel)
  36. {
  37. register int i, j, k, banks, len, zero, s;
  38. register int * restrict left;
  39. register int * restrict right;
  40. register int * restrict bleft;
  41. register int * restrict bright;
  42. left = (int*)bank->filter_left;
  43. right = (int*)bank->filter_right;
  44. bleft = (int*)bank->bank_left;
  45. bright = (int*)bank->bank_right;
  46. TMDEBUG_ALIGNMEM(ps);
  47. TMDEBUG_ALIGNMEM(mel);
  48. TMDEBUG_ALIGNMEM(left);
  49. TMDEBUG_ALIGNMEM(right);
  50. TMDEBUG_ALIGNMEM(bleft);
  51. TMDEBUG_ALIGNMEM(bright);
  52. FILTERBANKCOMPUTEBANK32_START();
  53. banks = bank->nb_banks << 2;
  54. zero = 0;
  55. len = bank->len;
  56. s = (1<<((15))>>1);
  57. #if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEBANK32)
  58. #pragma TCS_unroll=2
  59. #pragma TCS_unrollexact=1
  60. #endif
  61. for ( i=0 ; i<banks ; i+=4 )
  62. { st32d(i, mel, zero);
  63. }
  64. #if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEBANK32)
  65. #pragma TCS_unrollexact=0
  66. #pragma TCS_unroll=0
  67. #endif
  68. #if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEBANK32)
  69. #pragma TCS_unroll=2
  70. #pragma TCS_unrollexact=1
  71. #endif
  72. for ( i=0,j=1,k=0 ; i<len ; i+=2,j+=2,++k )
  73. { register int ps1, ps0, _mel, ps0_msb, ps0_lsb, ps1_msb, ps1_lsb;
  74. register int left10, right10, left1, left0, right1, right0;
  75. register int il1, ir1, il0, ir0;
  76. ps0 = ld32x(ps,i);
  77. il0 = ld32x(bleft,i);
  78. _mel = ld32x(mel,il0);
  79. left10 = ld32x(left,k);
  80. ir0 = ld32x(bright,i);
  81. right10 = ld32x(right,k);
  82. ps0_msb = ps0 >> 15;
  83. ps0_lsb = ps0 & 0x00007fff;
  84. left0 = sex16(left10);
  85. right0 = sex16(right10);
  86. _mel += left0 * ps0_msb + ((left0 * ps0_lsb + s ) >> 15);
  87. mel[il0]= _mel;
  88. _mel = ld32x(mel,ir0);
  89. _mel += right0 * ps0_msb + ((right0 * ps0_lsb + s ) >> 15);
  90. mel[ir0]= _mel;
  91. ps1 = ld32x(ps,j);
  92. il1 = ld32x(bleft,j);
  93. _mel = ld32x(mel,il1);
  94. ir1 = ld32x(bright,j);
  95. left1 = asri(16,left10);
  96. right1 = asri(16,right10);
  97. ps1_msb = ps1 >> 15;
  98. ps1_lsb = ps1 & 0x00007fff;
  99. _mel += left1 * ps1_msb + ((left1 * ps1_lsb + s ) >> 15);
  100. mel[il1]= _mel;
  101. _mel = ld32x(mel,ir1);
  102. _mel += right1 * ps1_msb + ((right1 * ps1_lsb + s ) >> 15);
  103. mel[ir1]= _mel;
  104. }
  105. #if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEBANK32)
  106. #pragma TCS_unrollexact=0
  107. #pragma TCS_unroll=0
  108. #endif
  109. FILTERBANKCOMPUTEBANK32_STOP();
  110. }
  111. #define OVERRIDE_FILTERBANK_COMPUTE_PSD16
  112. void filterbank_compute_psd16(FilterBank * restrict bank, spx_word16_t * restrict mel, spx_word16_t * restrict ps)
  113. {
  114. register int i, j, k, len, s;
  115. register int * restrict left;
  116. register int * restrict right;
  117. register int * restrict bleft;
  118. register int * restrict bright;
  119. left = (int*)bank->filter_left;
  120. right = (int*)bank->filter_right;
  121. bleft = (int*)bank->bank_left;
  122. bright = (int*)bank->bank_right;
  123. TMDEBUG_ALIGNMEM(ps);
  124. TMDEBUG_ALIGNMEM(mel);
  125. TMDEBUG_ALIGNMEM(left);
  126. TMDEBUG_ALIGNMEM(right);
  127. TMDEBUG_ALIGNMEM(bleft);
  128. TMDEBUG_ALIGNMEM(bright);
  129. FILTERBANKCOMPUTEPSD16_START();
  130. len = bank->len;
  131. s = (1<<((15))>>1);
  132. #if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEPSD16)
  133. #pragma TCS_unroll=2
  134. #pragma TCS_unrollexact=1
  135. #endif
  136. for ( i=0,j=0,k=0 ; i<len ; i+=2,j+=4,++k )
  137. {
  138. register int mell0, melr0, mel1, mel0, mell1, melr1;
  139. register int il1, ir1, il0, ir0;
  140. register int left10, right10, lr1, lr0;
  141. register int acc0, acc1, ps10;
  142. acc0 = acc1 = s;
  143. il0 = ld32x(bleft, i);
  144. ir0 = ld32x(bright,i);
  145. mell0 = mel[il0];
  146. melr0 = mel[ir0];
  147. left10 = ld32x(left, k);
  148. right10 = ld32x(right, k);
  149. mel0 = pack16lsb(mell0, melr0);
  150. lr0 = pack16lsb(left10, right10);
  151. acc0 += ifir16(mel0, lr0);
  152. acc0 >>= 15;
  153. il1 = ld32x(bleft, i+1);
  154. ir1 = ld32x(bright,i+1);
  155. mell1 = mel[il1];
  156. melr1 = mel[ir1];
  157. mel1 = pack16lsb(mell1, melr1);
  158. lr1 = pack16msb(left10, right10);
  159. acc1 += ifir16(mel1, lr1);
  160. acc1 >>= 15;
  161. ps10 = pack16lsb(acc1, acc0);
  162. st32d(j, ps, ps10);
  163. }
  164. #if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEPSD16)
  165. #pragma TCS_unrollexact=0
  166. #pragma TCS_unroll=0
  167. #endif
  168. FILTERBANKCOMPUTEPSD16_STOP();
  169. }
  170. #else
  171. #define OVERRIDE_FILTERBANK_COMPUTE_BANK32
  172. void filterbank_compute_bank32(FilterBank * restrict bank, float * restrict ps, float * restrict mel)
  173. {
  174. register int i, banks, len;
  175. register int * restrict bleft, * restrict bright;
  176. register float * restrict left, * restrict right;
  177. banks = bank->nb_banks;
  178. len = bank->len;
  179. bleft = bank->bank_left;
  180. bright= bank->bank_right;
  181. left = bank->filter_left;
  182. right = bank->filter_right;
  183. FILTERBANKCOMPUTEBANK32_START();
  184. memset(mel, 0, banks * sizeof(float));
  185. #if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEBANK32)
  186. #pragma TCS_unroll=4
  187. #pragma TCS_unrollexact=1
  188. #endif
  189. for ( i=0 ; i<len ; ++i)
  190. {
  191. register int id1, id2;
  192. register float psi;
  193. id1 = bleft[i];
  194. id2 = bright[i];
  195. psi = ps[i];
  196. mel[id1] += left[i] * psi;
  197. mel[id2] += right[i] * psi;
  198. }
  199. #if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEBANK32)
  200. #pragma TCS_unrollexact=0
  201. #pragma TCS_unroll=0
  202. #endif
  203. FILTERBANKCOMPUTEBANK32_STOP();
  204. }
  205. #define OVERRIDE_FILTERBANK_COMPUTE_PSD16
  206. void filterbank_compute_psd16(FilterBank * restrict bank, float * restrict mel, float * restrict ps)
  207. {
  208. register int i, len;
  209. register int * restrict bleft, * restrict bright;
  210. register float * restrict left, * restrict right;
  211. len = bank->len;
  212. bleft = bank->bank_left;
  213. bright= bank->bank_right;
  214. left = bank->filter_left;
  215. right = bank->filter_right;
  216. FILTERBANKCOMPUTEPSD16_START();
  217. #if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEPSD16)
  218. #pragma TCS_unroll=4
  219. #pragma TCS_unrollexact=1
  220. #endif
  221. for ( i=0 ; i<len ; ++i )
  222. {
  223. register float acc;
  224. register int id1, id2;
  225. id1 = bleft[i];
  226. id2 = bright[i];
  227. acc = mel[id1] * left[i];
  228. acc += mel[id2] * right[i];
  229. ps[i] = acc;
  230. }
  231. #if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEPSD16)
  232. #pragma TCS_unrollexact=0
  233. #pragma TCS_unroll=0
  234. #endif
  235. FILTERBANKCOMPUTEPSD16_STOP();
  236. }
  237. #endif