pitch.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /* Copyright (c) 2007-2008 CSIRO
  2. Copyright (c) 2007-2009 Xiph.Org Foundation
  3. Written by Jean-Marc Valin */
  4. /**
  5. @file pitch.h
  6. @brief Pitch analysis
  7. */
  8. /*
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions
  11. are met:
  12. - Redistributions of source code must retain the above copyright
  13. notice, this list of conditions and the following disclaimer.
  14. - Redistributions in binary form must reproduce the above copyright
  15. notice, this list of conditions and the following disclaimer in the
  16. documentation and/or other materials provided with the distribution.
  17. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  21. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  25. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef PITCH_H
  30. #define PITCH_H
  31. #include "modes.h"
  32. #include "cpu_support.h"
  33. #if (defined(OPUS_X86_MAY_HAVE_SSE) && !defined(FIXED_POINT)) \
  34. || ((defined(OPUS_X86_MAY_HAVE_SSE4_1) || defined(OPUS_X86_MAY_HAVE_SSE2)) && defined(FIXED_POINT))
  35. #include "x86/pitch_sse.h"
  36. #endif
  37. #if defined(MIPSr1_ASM)
  38. #include "mips/pitch_mipsr1.h"
  39. #endif
  40. #if ((defined(OPUS_ARM_ASM) && defined(FIXED_POINT)) \
  41. || defined(OPUS_ARM_MAY_HAVE_NEON_INTR))
  42. # include "arm/pitch_arm.h"
  43. #endif
  44. void pitch_downsample(celt_sig * OPUS_RESTRICT x[], opus_val16 * OPUS_RESTRICT x_lp,
  45. int len, int C, int arch);
  46. void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTRICT y,
  47. int len, int max_pitch, int *pitch, int arch);
  48. opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod,
  49. int N, int *T0, int prev_period, opus_val16 prev_gain, int arch);
  50. /* OPT: This is the kernel you really want to optimize. It gets used a lot
  51. by the prefilter and by the PLC. */
  52. static OPUS_INLINE void xcorr_kernel_c(const opus_val16 * x, const opus_val16 * y, opus_val32 sum[4], int len)
  53. {
  54. int j;
  55. opus_val16 y_0, y_1, y_2, y_3;
  56. celt_assert(len>=3);
  57. y_3=0; /* gcc doesn't realize that y_3 can't be used uninitialized */
  58. y_0=*y++;
  59. y_1=*y++;
  60. y_2=*y++;
  61. for (j=0;j<len-3;j+=4)
  62. {
  63. opus_val16 tmp;
  64. tmp = *x++;
  65. y_3=*y++;
  66. sum[0] = MAC16_16(sum[0],tmp,y_0);
  67. sum[1] = MAC16_16(sum[1],tmp,y_1);
  68. sum[2] = MAC16_16(sum[2],tmp,y_2);
  69. sum[3] = MAC16_16(sum[3],tmp,y_3);
  70. tmp=*x++;
  71. y_0=*y++;
  72. sum[0] = MAC16_16(sum[0],tmp,y_1);
  73. sum[1] = MAC16_16(sum[1],tmp,y_2);
  74. sum[2] = MAC16_16(sum[2],tmp,y_3);
  75. sum[3] = MAC16_16(sum[3],tmp,y_0);
  76. tmp=*x++;
  77. y_1=*y++;
  78. sum[0] = MAC16_16(sum[0],tmp,y_2);
  79. sum[1] = MAC16_16(sum[1],tmp,y_3);
  80. sum[2] = MAC16_16(sum[2],tmp,y_0);
  81. sum[3] = MAC16_16(sum[3],tmp,y_1);
  82. tmp=*x++;
  83. y_2=*y++;
  84. sum[0] = MAC16_16(sum[0],tmp,y_3);
  85. sum[1] = MAC16_16(sum[1],tmp,y_0);
  86. sum[2] = MAC16_16(sum[2],tmp,y_1);
  87. sum[3] = MAC16_16(sum[3],tmp,y_2);
  88. }
  89. if (j++<len)
  90. {
  91. opus_val16 tmp = *x++;
  92. y_3=*y++;
  93. sum[0] = MAC16_16(sum[0],tmp,y_0);
  94. sum[1] = MAC16_16(sum[1],tmp,y_1);
  95. sum[2] = MAC16_16(sum[2],tmp,y_2);
  96. sum[3] = MAC16_16(sum[3],tmp,y_3);
  97. }
  98. if (j++<len)
  99. {
  100. opus_val16 tmp=*x++;
  101. y_0=*y++;
  102. sum[0] = MAC16_16(sum[0],tmp,y_1);
  103. sum[1] = MAC16_16(sum[1],tmp,y_2);
  104. sum[2] = MAC16_16(sum[2],tmp,y_3);
  105. sum[3] = MAC16_16(sum[3],tmp,y_0);
  106. }
  107. if (j<len)
  108. {
  109. opus_val16 tmp=*x++;
  110. y_1=*y++;
  111. sum[0] = MAC16_16(sum[0],tmp,y_2);
  112. sum[1] = MAC16_16(sum[1],tmp,y_3);
  113. sum[2] = MAC16_16(sum[2],tmp,y_0);
  114. sum[3] = MAC16_16(sum[3],tmp,y_1);
  115. }
  116. }
  117. #ifndef OVERRIDE_XCORR_KERNEL
  118. #define xcorr_kernel(x, y, sum, len, arch) \
  119. ((void)(arch),xcorr_kernel_c(x, y, sum, len))
  120. #endif /* OVERRIDE_XCORR_KERNEL */
  121. static OPUS_INLINE void dual_inner_prod_c(const opus_val16 *x, const opus_val16 *y01, const opus_val16 *y02,
  122. int N, opus_val32 *xy1, opus_val32 *xy2)
  123. {
  124. int i;
  125. opus_val32 xy01=0;
  126. opus_val32 xy02=0;
  127. for (i=0;i<N;i++)
  128. {
  129. xy01 = MAC16_16(xy01, x[i], y01[i]);
  130. xy02 = MAC16_16(xy02, x[i], y02[i]);
  131. }
  132. *xy1 = xy01;
  133. *xy2 = xy02;
  134. }
  135. #ifndef OVERRIDE_DUAL_INNER_PROD
  136. # define dual_inner_prod(x, y01, y02, N, xy1, xy2, arch) \
  137. ((void)(arch),dual_inner_prod_c(x, y01, y02, N, xy1, xy2))
  138. #endif
  139. /*We make sure a C version is always available for cases where the overhead of
  140. vectorization and passing around an arch flag aren't worth it.*/
  141. static OPUS_INLINE opus_val32 celt_inner_prod_c(const opus_val16 *x,
  142. const opus_val16 *y, int N)
  143. {
  144. int i;
  145. opus_val32 xy=0;
  146. for (i=0;i<N;i++)
  147. xy = MAC16_16(xy, x[i], y[i]);
  148. return xy;
  149. }
  150. #if !defined(OVERRIDE_CELT_INNER_PROD)
  151. # define celt_inner_prod(x, y, N, arch) \
  152. ((void)(arch),celt_inner_prod_c(x, y, N))
  153. #endif
  154. #ifdef NON_STATIC_COMB_FILTER_CONST_C
  155. void comb_filter_const_c(opus_val32 *y, opus_val32 *x, int T, int N,
  156. opus_val16 g10, opus_val16 g11, opus_val16 g12);
  157. #endif
  158. #ifdef FIXED_POINT
  159. opus_val32
  160. #else
  161. void
  162. #endif
  163. celt_pitch_xcorr_c(const opus_val16 *_x, const opus_val16 *_y,
  164. opus_val32 *xcorr, int len, int max_pitch);
  165. #if !defined(OVERRIDE_PITCH_XCORR)
  166. #ifdef FIXED_POINT
  167. opus_val32
  168. #else
  169. void
  170. #endif
  171. celt_pitch_xcorr(const opus_val16 *_x, const opus_val16 *_y,
  172. opus_val32 *xcorr, int len, int max_pitch, int arch);
  173. #endif
  174. #endif