main.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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_H
  28. #define SILK_MAIN_H
  29. #include "SigProc_FIX.h"
  30. #include "define.h"
  31. #include "structs.h"
  32. #include "tables.h"
  33. #include "PLC.h"
  34. #include "control.h"
  35. #include "debug.h"
  36. #include "entenc.h"
  37. #include "entdec.h"
  38. #if defined(OPUS_X86_MAY_HAVE_SSE4_1)
  39. #include "x86/main_sse.h"
  40. #endif
  41. #if (defined(OPUS_ARM_ASM) || defined(OPUS_ARM_MAY_HAVE_NEON_INTR))
  42. #include "arm/NSQ_del_dec_arm.h"
  43. #endif
  44. /* Convert Left/Right stereo signal to adaptive Mid/Side representation */
  45. void silk_stereo_LR_to_MS(
  46. stereo_enc_state *state, /* I/O State */
  47. opus_int16 x1[], /* I/O Left input signal, becomes mid signal */
  48. opus_int16 x2[], /* I/O Right input signal, becomes side signal */
  49. opus_int8 ix[ 2 ][ 3 ], /* O Quantization indices */
  50. opus_int8 *mid_only_flag, /* O Flag: only mid signal coded */
  51. opus_int32 mid_side_rates_bps[], /* O Bitrates for mid and side signals */
  52. opus_int32 total_rate_bps, /* I Total bitrate */
  53. opus_int prev_speech_act_Q8, /* I Speech activity level in previous frame */
  54. opus_int toMono, /* I Last frame before a stereo->mono transition */
  55. opus_int fs_kHz, /* I Sample rate (kHz) */
  56. opus_int frame_length /* I Number of samples */
  57. );
  58. /* Convert adaptive Mid/Side representation to Left/Right stereo signal */
  59. void silk_stereo_MS_to_LR(
  60. stereo_dec_state *state, /* I/O State */
  61. opus_int16 x1[], /* I/O Left input signal, becomes mid signal */
  62. opus_int16 x2[], /* I/O Right input signal, becomes side signal */
  63. const opus_int32 pred_Q13[], /* I Predictors */
  64. opus_int fs_kHz, /* I Samples rate (kHz) */
  65. opus_int frame_length /* I Number of samples */
  66. );
  67. /* Find least-squares prediction gain for one signal based on another and quantize it */
  68. opus_int32 silk_stereo_find_predictor( /* O Returns predictor in Q13 */
  69. opus_int32 *ratio_Q14, /* O Ratio of residual and mid energies */
  70. const opus_int16 x[], /* I Basis signal */
  71. const opus_int16 y[], /* I Target signal */
  72. opus_int32 mid_res_amp_Q0[], /* I/O Smoothed mid, residual norms */
  73. opus_int length, /* I Number of samples */
  74. opus_int smooth_coef_Q16 /* I Smoothing coefficient */
  75. );
  76. /* Quantize mid/side predictors */
  77. void silk_stereo_quant_pred(
  78. opus_int32 pred_Q13[], /* I/O Predictors (out: quantized) */
  79. opus_int8 ix[ 2 ][ 3 ] /* O Quantization indices */
  80. );
  81. /* Entropy code the mid/side quantization indices */
  82. void silk_stereo_encode_pred(
  83. ec_enc *psRangeEnc, /* I/O Compressor data structure */
  84. opus_int8 ix[ 2 ][ 3 ] /* I Quantization indices */
  85. );
  86. /* Entropy code the mid-only flag */
  87. void silk_stereo_encode_mid_only(
  88. ec_enc *psRangeEnc, /* I/O Compressor data structure */
  89. opus_int8 mid_only_flag
  90. );
  91. /* Decode mid/side predictors */
  92. void silk_stereo_decode_pred(
  93. ec_dec *psRangeDec, /* I/O Compressor data structure */
  94. opus_int32 pred_Q13[] /* O Predictors */
  95. );
  96. /* Decode mid-only flag */
  97. void silk_stereo_decode_mid_only(
  98. ec_dec *psRangeDec, /* I/O Compressor data structure */
  99. opus_int *decode_only_mid /* O Flag that only mid channel has been coded */
  100. );
  101. /* Encodes signs of excitation */
  102. void silk_encode_signs(
  103. ec_enc *psRangeEnc, /* I/O Compressor data structure */
  104. const opus_int8 pulses[], /* I pulse signal */
  105. opus_int length, /* I length of input */
  106. const opus_int signalType, /* I Signal type */
  107. const opus_int quantOffsetType, /* I Quantization offset type */
  108. const opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ] /* I Sum of absolute pulses per block */
  109. );
  110. /* Decodes signs of excitation */
  111. void silk_decode_signs(
  112. ec_dec *psRangeDec, /* I/O Compressor data structure */
  113. opus_int16 pulses[], /* I/O pulse signal */
  114. opus_int length, /* I length of input */
  115. const opus_int signalType, /* I Signal type */
  116. const opus_int quantOffsetType, /* I Quantization offset type */
  117. const opus_int sum_pulses[ MAX_NB_SHELL_BLOCKS ] /* I Sum of absolute pulses per block */
  118. );
  119. /* Check encoder control struct */
  120. opus_int check_control_input(
  121. silk_EncControlStruct *encControl /* I Control structure */
  122. );
  123. /* Control internal sampling rate */
  124. opus_int silk_control_audio_bandwidth(
  125. silk_encoder_state *psEncC, /* I/O Pointer to Silk encoder state */
  126. silk_EncControlStruct *encControl /* I Control structure */
  127. );
  128. /* Control SNR of redidual quantizer */
  129. opus_int silk_control_SNR(
  130. silk_encoder_state *psEncC, /* I/O Pointer to Silk encoder state */
  131. opus_int32 TargetRate_bps /* I Target max bitrate (bps) */
  132. );
  133. /***************/
  134. /* Shell coder */
  135. /***************/
  136. /* Encode quantization indices of excitation */
  137. void silk_encode_pulses(
  138. ec_enc *psRangeEnc, /* I/O compressor data structure */
  139. const opus_int signalType, /* I Signal type */
  140. const opus_int quantOffsetType, /* I quantOffsetType */
  141. opus_int8 pulses[], /* I quantization indices */
  142. const opus_int frame_length /* I Frame length */
  143. );
  144. /* Shell encoder, operates on one shell code frame of 16 pulses */
  145. void silk_shell_encoder(
  146. ec_enc *psRangeEnc, /* I/O compressor data structure */
  147. const opus_int *pulses0 /* I data: nonnegative pulse amplitudes */
  148. );
  149. /* Shell decoder, operates on one shell code frame of 16 pulses */
  150. void silk_shell_decoder(
  151. opus_int16 *pulses0, /* O data: nonnegative pulse amplitudes */
  152. ec_dec *psRangeDec, /* I/O Compressor data structure */
  153. const opus_int pulses4 /* I number of pulses per pulse-subframe */
  154. );
  155. /* Gain scalar quantization with hysteresis, uniform on log scale */
  156. void silk_gains_quant(
  157. opus_int8 ind[ MAX_NB_SUBFR ], /* O gain indices */
  158. opus_int32 gain_Q16[ MAX_NB_SUBFR ], /* I/O gains (quantized out) */
  159. opus_int8 *prev_ind, /* I/O last index in previous frame */
  160. const opus_int conditional, /* I first gain is delta coded if 1 */
  161. const opus_int nb_subfr /* I number of subframes */
  162. );
  163. /* Gains scalar dequantization, uniform on log scale */
  164. void silk_gains_dequant(
  165. opus_int32 gain_Q16[ MAX_NB_SUBFR ], /* O quantized gains */
  166. const opus_int8 ind[ MAX_NB_SUBFR ], /* I gain indices */
  167. opus_int8 *prev_ind, /* I/O last index in previous frame */
  168. const opus_int conditional, /* I first gain is delta coded if 1 */
  169. const opus_int nb_subfr /* I number of subframes */
  170. );
  171. /* Compute unique identifier of gain indices vector */
  172. opus_int32 silk_gains_ID( /* O returns unique identifier of gains */
  173. const opus_int8 ind[ MAX_NB_SUBFR ], /* I gain indices */
  174. const opus_int nb_subfr /* I number of subframes */
  175. );
  176. /* Interpolate two vectors */
  177. void silk_interpolate(
  178. opus_int16 xi[ MAX_LPC_ORDER ], /* O interpolated vector */
  179. const opus_int16 x0[ MAX_LPC_ORDER ], /* I first vector */
  180. const opus_int16 x1[ MAX_LPC_ORDER ], /* I second vector */
  181. const opus_int ifact_Q2, /* I interp. factor, weight on 2nd vector */
  182. const opus_int d /* I number of parameters */
  183. );
  184. /* LTP tap quantizer */
  185. void silk_quant_LTP_gains(
  186. opus_int16 B_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* O Quantized LTP gains */
  187. opus_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook Index */
  188. opus_int8 *periodicity_index, /* O Periodicity Index */
  189. opus_int32 *sum_gain_dB_Q7, /* I/O Cumulative max prediction gain */
  190. opus_int *pred_gain_dB_Q7, /* O LTP prediction gain */
  191. const opus_int32 XX_Q17[ MAX_NB_SUBFR*LTP_ORDER*LTP_ORDER ], /* I Correlation matrix in Q18 */
  192. const opus_int32 xX_Q17[ MAX_NB_SUBFR*LTP_ORDER ], /* I Correlation vector in Q18 */
  193. const opus_int subfr_len, /* I Number of samples per subframe */
  194. const opus_int nb_subfr, /* I Number of subframes */
  195. int arch /* I Run-time architecture */
  196. );
  197. /* Entropy constrained matrix-weighted VQ, for a single input data vector */
  198. void silk_VQ_WMat_EC_c(
  199. opus_int8 *ind, /* O index of best codebook vector */
  200. opus_int32 *res_nrg_Q15, /* O best residual energy */
  201. opus_int32 *rate_dist_Q8, /* O best total bitrate */
  202. opus_int *gain_Q7, /* O sum of absolute LTP coefficients */
  203. const opus_int32 *XX_Q17, /* I correlation matrix */
  204. const opus_int32 *xX_Q17, /* I correlation vector */
  205. const opus_int8 *cb_Q7, /* I codebook */
  206. const opus_uint8 *cb_gain_Q7, /* I codebook effective gain */
  207. const opus_uint8 *cl_Q5, /* I code length for each codebook vector */
  208. const opus_int subfr_len, /* I number of samples per subframe */
  209. const opus_int32 max_gain_Q7, /* I maximum sum of absolute LTP coefficients */
  210. const opus_int L /* I number of vectors in codebook */
  211. );
  212. #if !defined(OVERRIDE_silk_VQ_WMat_EC)
  213. #define silk_VQ_WMat_EC(ind, res_nrg_Q15, rate_dist_Q8, gain_Q7, XX_Q17, xX_Q17, cb_Q7, cb_gain_Q7, cl_Q5, subfr_len, max_gain_Q7, L, arch) \
  214. ((void)(arch),silk_VQ_WMat_EC_c(ind, res_nrg_Q15, rate_dist_Q8, gain_Q7, XX_Q17, xX_Q17, cb_Q7, cb_gain_Q7, cl_Q5, subfr_len, max_gain_Q7, L))
  215. #endif
  216. /************************************/
  217. /* Noise shaping quantization (NSQ) */
  218. /************************************/
  219. void silk_NSQ_c(
  220. const silk_encoder_state *psEncC, /* I Encoder State */
  221. silk_nsq_state *NSQ, /* I/O NSQ state */
  222. SideInfoIndices *psIndices, /* I/O Quantization Indices */
  223. const opus_int16 x16[], /* I Input */
  224. opus_int8 pulses[], /* O Quantized pulse signal */
  225. const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */
  226. const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */
  227. const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */
  228. const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */
  229. const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */
  230. const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */
  231. const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */
  232. const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */
  233. const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */
  234. const opus_int LTP_scale_Q14 /* I LTP state scaling */
  235. );
  236. #if !defined(OVERRIDE_silk_NSQ)
  237. #define silk_NSQ(psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, LTPCoef_Q14, AR_Q13, \
  238. HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14, arch) \
  239. ((void)(arch),silk_NSQ_c(psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, LTPCoef_Q14, AR_Q13, \
  240. HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14))
  241. #endif
  242. /* Noise shaping using delayed decision */
  243. void silk_NSQ_del_dec_c(
  244. const silk_encoder_state *psEncC, /* I Encoder State */
  245. silk_nsq_state *NSQ, /* I/O NSQ state */
  246. SideInfoIndices *psIndices, /* I/O Quantization Indices */
  247. const opus_int16 x16[], /* I Input */
  248. opus_int8 pulses[], /* O Quantized pulse signal */
  249. const opus_int16 PredCoef_Q12[ 2 * MAX_LPC_ORDER ], /* I Short term prediction coefs */
  250. const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ], /* I Long term prediction coefs */
  251. const opus_int16 AR_Q13[ MAX_NB_SUBFR * MAX_SHAPE_LPC_ORDER ], /* I Noise shaping coefs */
  252. const opus_int HarmShapeGain_Q14[ MAX_NB_SUBFR ], /* I Long term shaping coefs */
  253. const opus_int Tilt_Q14[ MAX_NB_SUBFR ], /* I Spectral tilt */
  254. const opus_int32 LF_shp_Q14[ MAX_NB_SUBFR ], /* I Low frequency shaping coefs */
  255. const opus_int32 Gains_Q16[ MAX_NB_SUBFR ], /* I Quantization step sizes */
  256. const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */
  257. const opus_int Lambda_Q10, /* I Rate/distortion tradeoff */
  258. const opus_int LTP_scale_Q14 /* I LTP state scaling */
  259. );
  260. #if !defined(OVERRIDE_silk_NSQ_del_dec)
  261. #define silk_NSQ_del_dec(psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, LTPCoef_Q14, AR_Q13, \
  262. HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14, arch) \
  263. ((void)(arch),silk_NSQ_del_dec_c(psEncC, NSQ, psIndices, x16, pulses, PredCoef_Q12, LTPCoef_Q14, AR_Q13, \
  264. HarmShapeGain_Q14, Tilt_Q14, LF_shp_Q14, Gains_Q16, pitchL, Lambda_Q10, LTP_scale_Q14))
  265. #endif
  266. /************/
  267. /* Silk VAD */
  268. /************/
  269. /* Initialize the Silk VAD */
  270. opus_int silk_VAD_Init( /* O Return value, 0 if success */
  271. silk_VAD_state *psSilk_VAD /* I/O Pointer to Silk VAD state */
  272. );
  273. /* Get speech activity level in Q8 */
  274. opus_int silk_VAD_GetSA_Q8_c( /* O Return value, 0 if success */
  275. silk_encoder_state *psEncC, /* I/O Encoder state */
  276. const opus_int16 pIn[] /* I PCM input */
  277. );
  278. #if !defined(OVERRIDE_silk_VAD_GetSA_Q8)
  279. #define silk_VAD_GetSA_Q8(psEnC, pIn, arch) ((void)(arch),silk_VAD_GetSA_Q8_c(psEnC, pIn))
  280. #endif
  281. /* Low-pass filter with variable cutoff frequency based on */
  282. /* piece-wise linear interpolation between elliptic filters */
  283. /* Start by setting transition_frame_no = 1; */
  284. void silk_LP_variable_cutoff(
  285. silk_LP_state *psLP, /* I/O LP filter state */
  286. opus_int16 *frame, /* I/O Low-pass filtered output signal */
  287. const opus_int frame_length /* I Frame length */
  288. );
  289. /******************/
  290. /* NLSF Quantizer */
  291. /******************/
  292. /* Limit, stabilize, convert and quantize NLSFs */
  293. void silk_process_NLSFs(
  294. silk_encoder_state *psEncC, /* I/O Encoder state */
  295. opus_int16 PredCoef_Q12[ 2 ][ MAX_LPC_ORDER ], /* O Prediction coefficients */
  296. opus_int16 pNLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
  297. const opus_int16 prev_NLSFq_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */
  298. );
  299. opus_int32 silk_NLSF_encode( /* O Returns RD value in Q25 */
  300. opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */
  301. opus_int16 *pNLSF_Q15, /* I/O Quantized NLSF vector [ LPC_ORDER ] */
  302. const silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */
  303. const opus_int16 *pW_QW, /* I NLSF weight vector [ LPC_ORDER ] */
  304. const opus_int NLSF_mu_Q20, /* I Rate weight for the RD optimization */
  305. const opus_int nSurvivors, /* I Max survivors after first stage */
  306. const opus_int signalType /* I Signal type: 0/1/2 */
  307. );
  308. /* Compute quantization errors for an LPC_order element input vector for a VQ codebook */
  309. void silk_NLSF_VQ(
  310. opus_int32 err_Q26[], /* O Quantization errors [K] */
  311. const opus_int16 in_Q15[], /* I Input vectors to be quantized [LPC_order] */
  312. const opus_uint8 pCB_Q8[], /* I Codebook vectors [K*LPC_order] */
  313. const opus_int16 pWght_Q9[], /* I Codebook weights [K*LPC_order] */
  314. const opus_int K, /* I Number of codebook vectors */
  315. const opus_int LPC_order /* I Number of LPCs */
  316. );
  317. /* Delayed-decision quantizer for NLSF residuals */
  318. opus_int32 silk_NLSF_del_dec_quant( /* O Returns RD value in Q25 */
  319. opus_int8 indices[], /* O Quantization indices [ order ] */
  320. const opus_int16 x_Q10[], /* I Input [ order ] */
  321. const opus_int16 w_Q5[], /* I Weights [ order ] */
  322. const opus_uint8 pred_coef_Q8[], /* I Backward predictor coefs [ order ] */
  323. const opus_int16 ec_ix[], /* I Indices to entropy coding tables [ order ] */
  324. const opus_uint8 ec_rates_Q5[], /* I Rates [] */
  325. const opus_int quant_step_size_Q16, /* I Quantization step size */
  326. const opus_int16 inv_quant_step_size_Q6, /* I Inverse quantization step size */
  327. const opus_int32 mu_Q20, /* I R/D tradeoff */
  328. const opus_int16 order /* I Number of input values */
  329. );
  330. /* Unpack predictor values and indices for entropy coding tables */
  331. void silk_NLSF_unpack(
  332. opus_int16 ec_ix[], /* O Indices to entropy tables [ LPC_ORDER ] */
  333. opus_uint8 pred_Q8[], /* O LSF predictor [ LPC_ORDER ] */
  334. const silk_NLSF_CB_struct *psNLSF_CB, /* I Codebook object */
  335. const opus_int CB1_index /* I Index of vector in first LSF codebook */
  336. );
  337. /***********************/
  338. /* NLSF vector decoder */
  339. /***********************/
  340. void silk_NLSF_decode(
  341. opus_int16 *pNLSF_Q15, /* O Quantized NLSF vector [ LPC_ORDER ] */
  342. opus_int8 *NLSFIndices, /* I Codebook path vector [ LPC_ORDER + 1 ] */
  343. const silk_NLSF_CB_struct *psNLSF_CB /* I Codebook object */
  344. );
  345. /****************************************************/
  346. /* Decoder Functions */
  347. /****************************************************/
  348. opus_int silk_init_decoder(
  349. silk_decoder_state *psDec /* I/O Decoder state pointer */
  350. );
  351. /* Set decoder sampling rate */
  352. opus_int silk_decoder_set_fs(
  353. silk_decoder_state *psDec, /* I/O Decoder state pointer */
  354. opus_int fs_kHz, /* I Sampling frequency (kHz) */
  355. opus_int32 fs_API_Hz /* I API Sampling frequency (Hz) */
  356. );
  357. /****************/
  358. /* Decode frame */
  359. /****************/
  360. opus_int silk_decode_frame(
  361. silk_decoder_state *psDec, /* I/O Pointer to Silk decoder state */
  362. ec_dec *psRangeDec, /* I/O Compressor data structure */
  363. opus_int16 pOut[], /* O Pointer to output speech frame */
  364. opus_int32 *pN, /* O Pointer to size of output frame */
  365. opus_int lostFlag, /* I 0: no loss, 1 loss, 2 decode fec */
  366. opus_int condCoding, /* I The type of conditional coding to use */
  367. int arch /* I Run-time architecture */
  368. );
  369. /* Decode indices from bitstream */
  370. void silk_decode_indices(
  371. silk_decoder_state *psDec, /* I/O State */
  372. ec_dec *psRangeDec, /* I/O Compressor data structure */
  373. opus_int FrameIndex, /* I Frame number */
  374. opus_int decode_LBRR, /* I Flag indicating LBRR data is being decoded */
  375. opus_int condCoding /* I The type of conditional coding to use */
  376. );
  377. /* Decode parameters from payload */
  378. void silk_decode_parameters(
  379. silk_decoder_state *psDec, /* I/O State */
  380. silk_decoder_control *psDecCtrl, /* I/O Decoder control */
  381. opus_int condCoding /* I The type of conditional coding to use */
  382. );
  383. /* Core decoder. Performs inverse NSQ operation LTP + LPC */
  384. void silk_decode_core(
  385. silk_decoder_state *psDec, /* I/O Decoder state */
  386. silk_decoder_control *psDecCtrl, /* I Decoder control */
  387. opus_int16 xq[], /* O Decoded speech */
  388. const opus_int16 pulses[ MAX_FRAME_LENGTH ], /* I Pulse signal */
  389. int arch /* I Run-time architecture */
  390. );
  391. /* Decode quantization indices of excitation (Shell coding) */
  392. void silk_decode_pulses(
  393. ec_dec *psRangeDec, /* I/O Compressor data structure */
  394. opus_int16 pulses[], /* O Excitation signal */
  395. const opus_int signalType, /* I Sigtype */
  396. const opus_int quantOffsetType, /* I quantOffsetType */
  397. const opus_int frame_length /* I Frame length */
  398. );
  399. /******************/
  400. /* CNG */
  401. /******************/
  402. /* Reset CNG */
  403. void silk_CNG_Reset(
  404. silk_decoder_state *psDec /* I/O Decoder state */
  405. );
  406. /* Updates CNG estimate, and applies the CNG when packet was lost */
  407. void silk_CNG(
  408. silk_decoder_state *psDec, /* I/O Decoder state */
  409. silk_decoder_control *psDecCtrl, /* I/O Decoder control */
  410. opus_int16 frame[], /* I/O Signal */
  411. opus_int length /* I Length of residual */
  412. );
  413. /* Encoding of various parameters */
  414. void silk_encode_indices(
  415. silk_encoder_state *psEncC, /* I/O Encoder state */
  416. ec_enc *psRangeEnc, /* I/O Compressor data structure */
  417. opus_int FrameIndex, /* I Frame number */
  418. opus_int encode_LBRR, /* I Flag indicating LBRR data is being encoded */
  419. opus_int condCoding /* I The type of conditional coding to use */
  420. );
  421. #endif