pitch.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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(OPUS_ARM_MAY_HAVE_NEON_INTR))
  41. # include "arm/pitch_arm.h"
  42. #endif
  43. void pitch_downsample(celt_sig * OPUS_RESTRICT x[], opus_val16 * OPUS_RESTRICT x_lp,
  44. int len, int C, int arch);
  45. void pitch_search(const opus_val16 * OPUS_RESTRICT x_lp, opus_val16 * OPUS_RESTRICT y,
  46. int len, int max_pitch, int *pitch, int arch);
  47. opus_val16 remove_doubling(opus_val16 *x, int maxperiod, int minperiod,
  48. int N, int *T0, int prev_period, opus_val16 prev_gain, int arch);
  49. /* OPT: This is the kernel you really want to optimize. It gets used a lot
  50. by the prefilter and by the PLC. */
  51. static OPUS_INLINE void xcorr_kernel_c(const opus_val16 * x, const opus_val16 * y, opus_val32 sum[4], int len)
  52. {
  53. int j;
  54. opus_val16 y_0, y_1, y_2, y_3;
  55. celt_assert(len>=3);
  56. y_3=0; /* gcc doesn't realize that y_3 can't be used uninitialized */
  57. y_0=*y++;
  58. y_1=*y++;
  59. y_2=*y++;
  60. for (j=0;j<len-3;j+=4)
  61. {
  62. opus_val16 tmp;
  63. tmp = *x++;
  64. y_3=*y++;
  65. sum[0] = MAC16_16(sum[0],tmp,y_0);
  66. sum[1] = MAC16_16(sum[1],tmp,y_1);
  67. sum[2] = MAC16_16(sum[2],tmp,y_2);
  68. sum[3] = MAC16_16(sum[3],tmp,y_3);
  69. tmp=*x++;
  70. y_0=*y++;
  71. sum[0] = MAC16_16(sum[0],tmp,y_1);
  72. sum[1] = MAC16_16(sum[1],tmp,y_2);
  73. sum[2] = MAC16_16(sum[2],tmp,y_3);
  74. sum[3] = MAC16_16(sum[3],tmp,y_0);
  75. tmp=*x++;
  76. y_1=*y++;
  77. sum[0] = MAC16_16(sum[0],tmp,y_2);
  78. sum[1] = MAC16_16(sum[1],tmp,y_3);
  79. sum[2] = MAC16_16(sum[2],tmp,y_0);
  80. sum[3] = MAC16_16(sum[3],tmp,y_1);
  81. tmp=*x++;
  82. y_2=*y++;
  83. sum[0] = MAC16_16(sum[0],tmp,y_3);
  84. sum[1] = MAC16_16(sum[1],tmp,y_0);
  85. sum[2] = MAC16_16(sum[2],tmp,y_1);
  86. sum[3] = MAC16_16(sum[3],tmp,y_2);
  87. }
  88. if (j++<len)
  89. {
  90. opus_val16 tmp = *x++;
  91. y_3=*y++;
  92. sum[0] = MAC16_16(sum[0],tmp,y_0);
  93. sum[1] = MAC16_16(sum[1],tmp,y_1);
  94. sum[2] = MAC16_16(sum[2],tmp,y_2);
  95. sum[3] = MAC16_16(sum[3],tmp,y_3);
  96. }
  97. if (j++<len)
  98. {
  99. opus_val16 tmp=*x++;
  100. y_0=*y++;
  101. sum[0] = MAC16_16(sum[0],tmp,y_1);
  102. sum[1] = MAC16_16(sum[1],tmp,y_2);
  103. sum[2] = MAC16_16(sum[2],tmp,y_3);
  104. sum[3] = MAC16_16(sum[3],tmp,y_0);
  105. }
  106. if (j<len)
  107. {
  108. opus_val16 tmp=*x++;
  109. y_1=*y++;
  110. sum[0] = MAC16_16(sum[0],tmp,y_2);
  111. sum[1] = MAC16_16(sum[1],tmp,y_3);
  112. sum[2] = MAC16_16(sum[2],tmp,y_0);
  113. sum[3] = MAC16_16(sum[3],tmp,y_1);
  114. }
  115. }
  116. #ifndef OVERRIDE_XCORR_KERNEL
  117. #define xcorr_kernel(x, y, sum, len, arch) \
  118. ((void)(arch),xcorr_kernel_c(x, y, sum, len))
  119. #endif /* OVERRIDE_XCORR_KERNEL */
  120. static OPUS_INLINE void dual_inner_prod_c(const opus_val16 *x, const opus_val16 *y01, const opus_val16 *y02,
  121. int N, opus_val32 *xy1, opus_val32 *xy2)
  122. {
  123. int i;
  124. opus_val32 xy01=0;
  125. opus_val32 xy02=0;
  126. for (i=0;i<N;i++)
  127. {
  128. xy01 = MAC16_16(xy01, x[i], y01[i]);
  129. xy02 = MAC16_16(xy02, x[i], y02[i]);
  130. }
  131. *xy1 = xy01;
  132. *xy2 = xy02;
  133. }
  134. #ifndef OVERRIDE_DUAL_INNER_PROD
  135. # define dual_inner_prod(x, y01, y02, N, xy1, xy2, arch) \
  136. ((void)(arch),dual_inner_prod_c(x, y01, y02, N, xy1, xy2))
  137. #endif
  138. /*We make sure a C version is always available for cases where the overhead of
  139. vectorization and passing around an arch flag aren't worth it.*/
  140. static OPUS_INLINE opus_val32 celt_inner_prod_c(const opus_val16 *x,
  141. const opus_val16 *y, int N)
  142. {
  143. int i;
  144. opus_val32 xy=0;
  145. for (i=0;i<N;i++)
  146. xy = MAC16_16(xy, x[i], y[i]);
  147. return xy;
  148. }
  149. #if !defined(OVERRIDE_CELT_INNER_PROD)
  150. # define celt_inner_prod(x, y, N, arch) \
  151. ((void)(arch),celt_inner_prod_c(x, y, N))
  152. #endif
  153. #ifdef NON_STATIC_COMB_FILTER_CONST_C
  154. void comb_filter_const_c(opus_val32 *y, opus_val32 *x, int T, int N,
  155. opus_val16 g10, opus_val16 g11, opus_val16 g12);
  156. #endif
  157. #ifdef FIXED_POINT
  158. opus_val32
  159. #else
  160. void
  161. #endif
  162. celt_pitch_xcorr_c(const opus_val16 *_x, const opus_val16 *_y,
  163. opus_val32 *xcorr, int len, int max_pitch, int arch);
  164. #ifndef OVERRIDE_PITCH_XCORR
  165. # define celt_pitch_xcorr celt_pitch_xcorr_c
  166. #endif
  167. #endif