cb_search_tm.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* Copyright (C) 2007 Hong Zhiqian */
  2. /**
  3. @file cb_search_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_COMPUTE_WEIGHTED_CODEBOOK
  35. static void compute_weighted_codebook(
  36. const signed char * restrict shape_cb,
  37. const Int16 * restrict r,
  38. Int16 * restrict resp,
  39. Int16 * restrict resp2,
  40. Int32 * restrict E,
  41. int shape_cb_size, int subvect_size, char *stack)
  42. {
  43. register int i, j;
  44. register int quadsize;
  45. TMDEBUG_ALIGNMEM(r);
  46. TMDEBUG_ALIGNMEM(resp);
  47. TMDEBUG_ALIGNMEM(resp2);
  48. COMPUTEWEIGHTEDCODEBOOK_START();
  49. quadsize = subvect_size << 2;
  50. for ( i=0 ; i<shape_cb_size ; i+=4 )
  51. { register int e0, e1, e2, e3;
  52. e0 = e1 = e2 = e3 = 0;
  53. for( j=0 ; j<subvect_size ; ++j )
  54. {
  55. register int k, rr;
  56. register int resj0, resj1, resj2, resj3;
  57. resj0 = resj1 = resj2 = resj3 = 0;
  58. for ( k=0 ; k<=j ; ++k )
  59. { rr = r[j-k];
  60. resj0 += shape_cb[k] * rr;
  61. resj1 += shape_cb[k+subvect_size] * rr;
  62. resj2 += shape_cb[k+2*subvect_size] * rr;
  63. resj3 += shape_cb[k+3*subvect_size] * rr;
  64. }
  65. resj0 >>= 13;
  66. resj1 >>= 13;
  67. resj2 >>= 13;
  68. resj3 >>= 13;
  69. e0 += resj0 * resj0;
  70. e1 += resj1 * resj1;
  71. e2 += resj2 * resj2;
  72. e3 += resj3 * resj3;
  73. resp[j] = resj0;
  74. resp[j+subvect_size] = resj1;
  75. resp[j+2*subvect_size] = resj2;
  76. resp[j+3*subvect_size] = resj3;
  77. }
  78. E[i] = e0;
  79. E[i+1] = e1;
  80. E[i+2] = e2;
  81. E[i+3] = e3;
  82. resp += quadsize;
  83. shape_cb += quadsize;
  84. }
  85. #ifndef REMARK_ON
  86. (void)resp2;
  87. (void)stack;
  88. #endif
  89. COMPUTEWEIGHTEDCODEBOOK_STOP();
  90. }
  91. #define OVERRIDE_TARGET_UPDATE
  92. static inline void target_update(Int16 * restrict t, Int16 g, Int16 * restrict r, int len)
  93. {
  94. register int n;
  95. register int gr1, gr2, t1, t2, r1, r2;
  96. register int quadsize;
  97. TARGETUPDATE_START();
  98. quadsize = len & 0xFFFFFFFC;
  99. for ( n=0; n<quadsize ; n+=4 )
  100. { gr1 = pack16lsb(PSHR32((g * r[n]),13) , PSHR32((g * r[n+1]),13));
  101. gr2 = pack16lsb(PSHR32((g * r[n+2]),13), PSHR32((g * r[n+3]),13));
  102. t1 = pack16lsb(t[n], t[n+1]);
  103. t2 = pack16lsb(t[n+2],t[n+3]);
  104. r1 = dspidualsub(t1, gr1);
  105. r2 = dspidualsub(t2, gr2);
  106. t[n] = asri(16,r1);
  107. t[n+1] = sex16(r1);
  108. t[n+2] = asri(16,r2);
  109. t[n+3] = sex16(r2);
  110. }
  111. for ( n=quadsize ; n<len ; ++n )
  112. { t[n] = SUB16(t[n],PSHR32(MULT16_16(g,r[n]),13));
  113. }
  114. TARGETUPDATE_STOP();
  115. }
  116. #endif