main_FIX.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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_MAIN_FIX_H
  28. #define SILK_MAIN_FIX_H
  29. #include "SigProc_FIX.h"
  30. #include "structs_FIX.h"
  31. #include "control.h"
  32. #include "main.h"
  33. #include "PLC.h"
  34. #include "debug.h"
  35. #include "entenc.h"
  36. #if ((defined(OPUS_ARM_ASM) && defined(FIXED_POINT)) \
  37. || defined(OPUS_ARM_MAY_HAVE_NEON_INTR))
  38. #include "fixed/arm/warped_autocorrelation_FIX_arm.h"
  39. #endif
  40. #ifndef FORCE_CPP_BUILD
  41. #ifdef __cplusplus
  42. extern "C"
  43. {
  44. #endif
  45. #endif
  46. #define silk_encoder_state_Fxx silk_encoder_state_FIX
  47. #define silk_encode_do_VAD_Fxx silk_encode_do_VAD_FIX
  48. #define silk_encode_frame_Fxx silk_encode_frame_FIX
  49. #define QC 10
  50. #define QS 13
  51. /*********************/
  52. /* Encoder Functions */
  53. /*********************/
  54. /* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */
  55. void silk_HP_variable_cutoff(
  56. silk_encoder_state_Fxx state_Fxx[] /* I/O Encoder states */
  57. );
  58. /* Encoder main function */
  59. void silk_encode_do_VAD_FIX(
  60. silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */
  61. opus_int activity /* I Decision of Opus voice activity detector */
  62. );
  63. /* Encoder main function */
  64. opus_int silk_encode_frame_FIX(
  65. silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */
  66. opus_int32 *pnBytesOut, /* O Pointer to number of payload bytes; */
  67. ec_enc *psRangeEnc, /* I/O compressor data structure */
  68. opus_int condCoding, /* I The type of conditional coding to use */
  69. opus_int maxBits, /* I If > 0: maximum number of output bits */
  70. opus_int useCBR /* I Flag to force constant-bitrate operation */
  71. );
  72. /* Initializes the Silk encoder state */
  73. opus_int silk_init_encoder(
  74. silk_encoder_state_Fxx *psEnc, /* I/O Pointer to Silk FIX encoder state */
  75. int arch /* I Run-time architecture */
  76. );
  77. /* Control the Silk encoder */
  78. opus_int silk_control_encoder(
  79. silk_encoder_state_Fxx *psEnc, /* I/O Pointer to Silk encoder state */
  80. silk_EncControlStruct *encControl, /* I Control structure */
  81. const opus_int allow_bw_switch, /* I Flag to allow switching audio bandwidth */
  82. const opus_int channelNb, /* I Channel number */
  83. const opus_int force_fs_kHz
  84. );
  85. /**************************/
  86. /* Noise shaping analysis */
  87. /**************************/
  88. /* Compute noise shaping coefficients and initial gain values */
  89. void silk_noise_shape_analysis_FIX(
  90. silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */
  91. silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control FIX */
  92. const opus_int16 *pitch_res, /* I LPC residual from pitch analysis */
  93. const opus_int16 *x, /* I Input signal [ frame_length + la_shape ] */
  94. int arch /* I Run-time architecture */
  95. );
  96. /* Autocorrelations for a warped frequency axis */
  97. void silk_warped_autocorrelation_FIX_c(
  98. opus_int32 *corr, /* O Result [order + 1] */
  99. opus_int *scale, /* O Scaling of the correlation vector */
  100. const opus_int16 *input, /* I Input data to correlate */
  101. const opus_int warping_Q16, /* I Warping coefficient */
  102. const opus_int length, /* I Length of input */
  103. const opus_int order /* I Correlation order (even) */
  104. );
  105. #if !defined(OVERRIDE_silk_warped_autocorrelation_FIX)
  106. #define silk_warped_autocorrelation_FIX(corr, scale, input, warping_Q16, length, order, arch) \
  107. ((void)(arch), silk_warped_autocorrelation_FIX_c(corr, scale, input, warping_Q16, length, order))
  108. #endif
  109. /* Calculation of LTP state scaling */
  110. void silk_LTP_scale_ctrl_FIX(
  111. silk_encoder_state_FIX *psEnc, /* I/O encoder state */
  112. silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */
  113. opus_int condCoding /* I The type of conditional coding to use */
  114. );
  115. /**********************************************/
  116. /* Prediction Analysis */
  117. /**********************************************/
  118. /* Find pitch lags */
  119. void silk_find_pitch_lags_FIX(
  120. silk_encoder_state_FIX *psEnc, /* I/O encoder state */
  121. silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */
  122. opus_int16 res[], /* O residual */
  123. const opus_int16 x[], /* I Speech signal */
  124. int arch /* I Run-time architecture */
  125. );
  126. /* Find LPC and LTP coefficients */
  127. void silk_find_pred_coefs_FIX(
  128. silk_encoder_state_FIX *psEnc, /* I/O encoder state */
  129. silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */
  130. const opus_int16 res_pitch[], /* I Residual from pitch analysis */
  131. const opus_int16 x[], /* I Speech signal */
  132. opus_int condCoding /* I The type of conditional coding to use */
  133. );
  134. /* LPC analysis */
  135. void silk_find_LPC_FIX(
  136. silk_encoder_state *psEncC, /* I/O Encoder state */
  137. opus_int16 NLSF_Q15[], /* O NLSFs */
  138. const opus_int16 x[], /* I Input signal */
  139. const opus_int32 minInvGain_Q30 /* I Inverse of max prediction gain */
  140. );
  141. /* LTP analysis */
  142. void silk_find_LTP_FIX(
  143. opus_int32 XXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Correlation matrix */
  144. opus_int32 xXLTP_Q17[ MAX_NB_SUBFR * LTP_ORDER ], /* O Correlation vector */
  145. const opus_int16 r_lpc[], /* I Residual signal after LPC */
  146. const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */
  147. const opus_int subfr_length, /* I Subframe length */
  148. const opus_int nb_subfr, /* I Number of subframes */
  149. int arch /* I Run-time architecture */
  150. );
  151. void silk_LTP_analysis_filter_FIX(
  152. opus_int16 *LTP_res, /* O LTP residual signal of length MAX_NB_SUBFR * ( pre_length + subfr_length ) */
  153. const opus_int16 *x, /* I Pointer to input signal with at least max( pitchL ) preceding samples */
  154. const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ],/* I LTP_ORDER LTP coefficients for each MAX_NB_SUBFR subframe */
  155. const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lag, one for each subframe */
  156. const opus_int32 invGains_Q16[ MAX_NB_SUBFR ], /* I Inverse quantization gains, one for each subframe */
  157. const opus_int subfr_length, /* I Length of each subframe */
  158. const opus_int nb_subfr, /* I Number of subframes */
  159. const opus_int pre_length /* I Length of the preceding samples starting at &x[0] for each subframe */
  160. );
  161. /* Calculates residual energies of input subframes where all subframes have LPC_order */
  162. /* of preceding samples */
  163. void silk_residual_energy_FIX(
  164. opus_int32 nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */
  165. opus_int nrgsQ[ MAX_NB_SUBFR ], /* O Q value per subframe */
  166. const opus_int16 x[], /* I Input signal */
  167. opus_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */
  168. const opus_int32 gains[ MAX_NB_SUBFR ], /* I Quantization gains */
  169. const opus_int subfr_length, /* I Subframe length */
  170. const opus_int nb_subfr, /* I Number of subframes */
  171. const opus_int LPC_order, /* I LPC order */
  172. int arch /* I Run-time architecture */
  173. );
  174. /* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */
  175. opus_int32 silk_residual_energy16_covar_FIX(
  176. const opus_int16 *c, /* I Prediction vector */
  177. const opus_int32 *wXX, /* I Correlation matrix */
  178. const opus_int32 *wXx, /* I Correlation vector */
  179. opus_int32 wxx, /* I Signal energy */
  180. opus_int D, /* I Dimension */
  181. opus_int cQ /* I Q value for c vector 0 - 15 */
  182. );
  183. /* Processing of gains */
  184. void silk_process_gains_FIX(
  185. silk_encoder_state_FIX *psEnc, /* I/O Encoder state */
  186. silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control */
  187. opus_int condCoding /* I The type of conditional coding to use */
  188. );
  189. /******************/
  190. /* Linear Algebra */
  191. /******************/
  192. /* Calculates correlation matrix X'*X */
  193. void silk_corrMatrix_FIX(
  194. const opus_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */
  195. const opus_int L, /* I Length of vectors */
  196. const opus_int order, /* I Max lag for correlation */
  197. opus_int32 *XX, /* O Pointer to X'*X correlation matrix [ order x order ] */
  198. opus_int32 *nrg, /* O Energy of x vector */
  199. opus_int *rshifts, /* O Right shifts of correlations */
  200. int arch /* I Run-time architecture */
  201. );
  202. /* Calculates correlation vector X'*t */
  203. void silk_corrVector_FIX(
  204. const opus_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */
  205. const opus_int16 *t, /* I Target vector [L] */
  206. const opus_int L, /* I Length of vectors */
  207. const opus_int order, /* I Max lag for correlation */
  208. opus_int32 *Xt, /* O Pointer to X'*t correlation vector [order] */
  209. const opus_int rshifts, /* I Right shifts of correlations */
  210. int arch /* I Run-time architecture */
  211. );
  212. #ifndef FORCE_CPP_BUILD
  213. #ifdef __cplusplus
  214. }
  215. #endif /* __cplusplus */
  216. #endif /* FORCE_CPP_BUILD */
  217. #endif /* SILK_MAIN_FIX_H */