SigProc_FLP.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /***********************************************************************
  2. Copyright (c) 2006-2011, Skype Limited. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. - Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. - Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. - Neither the name of Internet Society, IETF or IETF Trust, nor the
  12. names of specific contributors, may be used to endorse or promote
  13. products derived from this software without specific prior written
  14. permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  19. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. POSSIBILITY OF SUCH DAMAGE.
  26. ***********************************************************************/
  27. #ifndef SILK_SIGPROC_FLP_H
  28. #define SILK_SIGPROC_FLP_H
  29. #include "SigProc_FIX.h"
  30. #include "float_cast.h"
  31. #include <math.h>
  32. #ifdef __cplusplus
  33. extern "C"
  34. {
  35. #endif
  36. /********************************************************************/
  37. /* SIGNAL PROCESSING FUNCTIONS */
  38. /********************************************************************/
  39. /* Chirp (bw expand) LP AR filter */
  40. void silk_bwexpander_FLP(
  41. silk_float *ar, /* I/O AR filter to be expanded (without leading 1) */
  42. const opus_int d, /* I length of ar */
  43. const silk_float chirp /* I chirp factor (typically in range (0..1) ) */
  44. );
  45. /* compute inverse of LPC prediction gain, and */
  46. /* test if LPC coefficients are stable (all poles within unit circle) */
  47. /* this code is based on silk_FLP_a2k() */
  48. silk_float silk_LPC_inverse_pred_gain_FLP( /* O return inverse prediction gain, energy domain */
  49. const silk_float *A, /* I prediction coefficients [order] */
  50. opus_int32 order /* I prediction order */
  51. );
  52. silk_float silk_schur_FLP( /* O returns residual energy */
  53. silk_float refl_coef[], /* O reflection coefficients (length order) */
  54. const silk_float auto_corr[], /* I autocorrelation sequence (length order+1) */
  55. opus_int order /* I order */
  56. );
  57. void silk_k2a_FLP(
  58. silk_float *A, /* O prediction coefficients [order] */
  59. const silk_float *rc, /* I reflection coefficients [order] */
  60. opus_int32 order /* I prediction order */
  61. );
  62. /* Solve the normal equations using the Levinson-Durbin recursion */
  63. silk_float silk_levinsondurbin_FLP( /* O prediction error energy */
  64. silk_float A[], /* O prediction coefficients [order] */
  65. const silk_float corr[], /* I input auto-correlations [order + 1] */
  66. const opus_int order /* I prediction order */
  67. );
  68. /* compute autocorrelation */
  69. void silk_autocorrelation_FLP(
  70. silk_float *results, /* O result (length correlationCount) */
  71. const silk_float *inputData, /* I input data to correlate */
  72. opus_int inputDataSize, /* I length of input */
  73. opus_int correlationCount /* I number of correlation taps to compute */
  74. );
  75. opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced, 1 unvoiced */
  76. const silk_float *frame, /* I Signal of length PE_FRAME_LENGTH_MS*Fs_kHz */
  77. opus_int *pitch_out, /* O Pitch lag values [nb_subfr] */
  78. opus_int16 *lagIndex, /* O Lag Index */
  79. opus_int8 *contourIndex, /* O Pitch contour Index */
  80. silk_float *LTPCorr, /* I/O Normalized correlation; input: value from previous frame */
  81. opus_int prevLag, /* I Last lag of previous frame; set to zero is unvoiced */
  82. const silk_float search_thres1, /* I First stage threshold for lag candidates 0 - 1 */
  83. const silk_float search_thres2, /* I Final threshold for lag candidates 0 - 1 */
  84. const opus_int Fs_kHz, /* I sample frequency (kHz) */
  85. const opus_int complexity, /* I Complexity setting, 0-2, where 2 is highest */
  86. const opus_int nb_subfr, /* I Number of 5 ms subframes */
  87. int arch /* I Run-time architecture */
  88. );
  89. void silk_insertion_sort_decreasing_FLP(
  90. silk_float *a, /* I/O Unsorted / Sorted vector */
  91. opus_int *idx, /* O Index vector for the sorted elements */
  92. const opus_int L, /* I Vector length */
  93. const opus_int K /* I Number of correctly sorted positions */
  94. );
  95. /* Compute reflection coefficients from input signal */
  96. silk_float silk_burg_modified_FLP( /* O returns residual energy */
  97. silk_float A[], /* O prediction coefficients (length order) */
  98. const silk_float x[], /* I input signal, length: nb_subfr*(D+L_sub) */
  99. const silk_float minInvGain, /* I minimum inverse prediction gain */
  100. const opus_int subfr_length, /* I input signal subframe length (incl. D preceding samples) */
  101. const opus_int nb_subfr, /* I number of subframes stacked in x */
  102. const opus_int D /* I order */
  103. );
  104. /* multiply a vector by a constant */
  105. void silk_scale_vector_FLP(
  106. silk_float *data1,
  107. silk_float gain,
  108. opus_int dataSize
  109. );
  110. /* copy and multiply a vector by a constant */
  111. void silk_scale_copy_vector_FLP(
  112. silk_float *data_out,
  113. const silk_float *data_in,
  114. silk_float gain,
  115. opus_int dataSize
  116. );
  117. /* inner product of two silk_float arrays, with result as double */
  118. double silk_inner_product_FLP(
  119. const silk_float *data1,
  120. const silk_float *data2,
  121. opus_int dataSize
  122. );
  123. /* sum of squares of a silk_float array, with result as double */
  124. double silk_energy_FLP(
  125. const silk_float *data,
  126. opus_int dataSize
  127. );
  128. /********************************************************************/
  129. /* MACROS */
  130. /********************************************************************/
  131. #define PI (3.1415926536f)
  132. #define silk_min_float( a, b ) (((a) < (b)) ? (a) : (b))
  133. #define silk_max_float( a, b ) (((a) > (b)) ? (a) : (b))
  134. #define silk_abs_float( a ) ((silk_float)fabs(a))
  135. /* sigmoid function */
  136. static OPUS_INLINE silk_float silk_sigmoid( silk_float x )
  137. {
  138. return (silk_float)(1.0 / (1.0 + exp(-x)));
  139. }
  140. /* floating-point to integer conversion (rounding) */
  141. static OPUS_INLINE opus_int32 silk_float2int( silk_float x )
  142. {
  143. return (opus_int32)float2int( x );
  144. }
  145. /* floating-point to integer conversion (rounding) */
  146. static OPUS_INLINE void silk_float2short_array(
  147. opus_int16 *out,
  148. const silk_float *in,
  149. opus_int32 length
  150. )
  151. {
  152. opus_int32 k;
  153. for( k = length - 1; k >= 0; k-- ) {
  154. out[k] = silk_SAT16( (opus_int32)float2int( in[k] ) );
  155. }
  156. }
  157. /* integer to floating-point conversion */
  158. static OPUS_INLINE void silk_short2float_array(
  159. silk_float *out,
  160. const opus_int16 *in,
  161. opus_int32 length
  162. )
  163. {
  164. opus_int32 k;
  165. for( k = length - 1; k >= 0; k-- ) {
  166. out[k] = (silk_float)in[k];
  167. }
  168. }
  169. /* using log2() helps the fixed-point conversion */
  170. static OPUS_INLINE silk_float silk_log2( double x )
  171. {
  172. return ( silk_float )( 3.32192809488736 * log10( x ) );
  173. }
  174. #ifdef __cplusplus
  175. }
  176. #endif
  177. #endif /* SILK_SIGPROC_FLP_H */