lpc_tm.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* Copyright (C) 2007 Hong Zhiqian */
  2. /**
  3. @file lpc_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_SPEEX_AUTOCORR
  35. void _spx_autocorr(const Int16 *x, Int16 *ac, int lag, int n)
  36. {
  37. register int i, j;
  38. register int shift, ac_shift;
  39. register int n_2;
  40. register int ac0;
  41. TMDEBUG_ALIGNMEM(x);
  42. TMDEBUG_ALIGNMEM(ac);
  43. _SPX_AUTOCORR_START();
  44. n_2 = n >> 1;
  45. ac0 = n + 1;
  46. #if (TM_UNROLL && TM_UNROLL__SPXAUTOCORR)
  47. #pragma TCS_unroll=5
  48. #pragma TCS_unrollexact=1
  49. #endif
  50. for ( j=0 ; j<n_2 ; j+=4 )
  51. { register int x10, x32, x54, x76;
  52. x10 = ld32x(x,j);
  53. x32 = ld32x(x,j+1);
  54. x54 = ld32x(x,j+2);
  55. x76 = ld32x(x,j+3);
  56. ac0 += ifir16(x10, x10) >> 8;
  57. ac0 += ifir16(x32, x32) >> 8;
  58. ac0 += ifir16(x54, x54) >> 8;
  59. ac0 += ifir16(x76, x76) >> 8;
  60. }
  61. #if (TM_UNROLL && TM_UNROLL__SPXAUTOCORR)
  62. #pragma TCS_unrollexact=0
  63. #pragma TCS_unroll=0
  64. #endif
  65. shift = 8;
  66. while (shift && ac0<0x40000000)
  67. { shift--;
  68. ac0 <<= 1;
  69. }
  70. ac_shift = 18;
  71. while (ac_shift && ac0<0x40000000)
  72. { ac_shift--;
  73. ac0 <<= 1;
  74. }
  75. if ( shift == 0 )
  76. {
  77. for ( i=0 ; i<lag ; ++i )
  78. {
  79. register int acc0, acc1, acc2;
  80. register int k, l, m;
  81. register int x10, x32, y10, y32;
  82. acc2 = acc1 = acc0 = 0;
  83. for ( j=i ; j<16 ; ++j )
  84. { acc0 += (x[j] * x[j-i]);
  85. }
  86. for ( k=16,l=8,m=16-i ; k<n ; k+=4,l+=2,m+=4 )
  87. {
  88. x10 = ld32x(x,l);
  89. y10 = pack16lsb(x[m+1],x[m]);
  90. x32 = ld32x(x,l+1);
  91. y32 = pack16lsb(x[m+3],x[m+2]);
  92. acc1 += ifir16(x10,y10);
  93. acc2 += ifir16(x32,y32);
  94. }
  95. ac[i] = (acc0 + acc1 + acc2) >> ac_shift;
  96. }
  97. } else
  98. {
  99. for ( i=0 ; i<lag ; ++i )
  100. {
  101. register int acc0, acc1, acc2;
  102. register int k, l, m;
  103. register int x10, x32, y10, y32;
  104. acc2 = acc1 = acc0 = 0;
  105. for ( j=i ; j<16 ; ++j )
  106. { acc0 += (x[j] * x[j-i]) >> shift;
  107. }
  108. for ( k=16,l=8,m=16-i ; k<n ; k+=4,l+=2,m+=4 )
  109. {
  110. x10 = ld32x(x,l);
  111. y10 = pack16lsb(x[m+1],x[m]);
  112. x32 = ld32x(x,l+1);
  113. y32 = pack16lsb(x[m+3],x[m+2]);
  114. acc1 += ifir16(x10,y10) >> shift;
  115. acc2 += ifir16(x32,y32) >> shift;
  116. }
  117. ac[i] = (acc0 + acc1 + acc2) >> ac_shift;
  118. }
  119. }
  120. _SPX_AUTOCORR_STOP();
  121. }
  122. #endif