blob: a56ca07a224164d8d57d2126623fe114540499dd [file] [log] [blame]
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +00001/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions
5are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
tlegrand@chromium.orge3ea0492013-10-23 09:13:50 +000011- Neither the name of Internet Society, IETF or IETF Trust, nor the
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +000012names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
tlegrand@chromium.orge3ea0492013-10-23 09:13:50 +000015THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +000016AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28#ifndef SILK_MAIN_FIX_H
29#define SILK_MAIN_FIX_H
30
31#include "SigProc_FIX.h"
32#include "structs_FIX.h"
33#include "control.h"
34#include "main.h"
35#include "PLC.h"
36#include "debug.h"
37#include "entenc.h"
38
39#ifndef FORCE_CPP_BUILD
40#ifdef __cplusplus
41extern "C"
42{
43#endif
44#endif
45
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
50/*********************/
51/* Encoder Functions */
52/*********************/
53
54/* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */
55void silk_HP_variable_cutoff(
56 silk_encoder_state_Fxx state_Fxx[] /* I/O Encoder states */
57);
58
59/* Encoder main function */
60void silk_encode_do_VAD_FIX(
61 silk_encoder_state_FIX *psEnc /* I/O Pointer to Silk FIX encoder state */
62);
63
64/* Encoder main function */
65opus_int silk_encode_frame_FIX(
66 silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */
67 opus_int32 *pnBytesOut, /* O Pointer to number of payload bytes; */
68 ec_enc *psRangeEnc, /* I/O compressor data structure */
69 opus_int condCoding, /* I The type of conditional coding to use */
70 opus_int maxBits, /* I If > 0: maximum number of output bits */
71 opus_int useCBR /* I Flag to force constant-bitrate operation */
72);
73
74/* Initializes the Silk encoder state */
75opus_int silk_init_encoder(
tlegrand@google.com3c3902f2013-12-09 08:35:25 +000076 silk_encoder_state_Fxx *psEnc, /* I/O Pointer to Silk FIX encoder state */
77 int arch /* I Run-time architecture */
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +000078);
79
80/* Control the Silk encoder */
81opus_int silk_control_encoder(
82 silk_encoder_state_Fxx *psEnc, /* I/O Pointer to Silk encoder state */
83 silk_EncControlStruct *encControl, /* I Control structure */
84 const opus_int32 TargetRate_bps, /* I Target max bitrate (bps) */
85 const opus_int allow_bw_switch, /* I Flag to allow switching audio bandwidth */
86 const opus_int channelNb, /* I Channel number */
87 const opus_int force_fs_kHz
88);
89
90/****************/
91/* Prefiltering */
92/****************/
93void silk_prefilter_FIX(
94 silk_encoder_state_FIX *psEnc, /* I/O Encoder state */
95 const silk_encoder_control_FIX *psEncCtrl, /* I Encoder control */
96 opus_int32 xw_Q10[], /* O Weighted signal */
97 const opus_int16 x[] /* I Speech signal */
98);
99
100/**************************/
101/* Noise shaping analysis */
102/**************************/
103/* Compute noise shaping coefficients and initial gain values */
104void silk_noise_shape_analysis_FIX(
105 silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */
106 silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control FIX */
107 const opus_int16 *pitch_res, /* I LPC residual from pitch analysis */
tlegrand@google.com3c3902f2013-12-09 08:35:25 +0000108 const opus_int16 *x, /* I Input signal [ frame_length + la_shape ] */
109 int arch /* I Run-time architecture */
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000110);
111
112/* Autocorrelations for a warped frequency axis */
113void silk_warped_autocorrelation_FIX(
114 opus_int32 *corr, /* O Result [order + 1] */
115 opus_int *scale, /* O Scaling of the correlation vector */
116 const opus_int16 *input, /* I Input data to correlate */
117 const opus_int warping_Q16, /* I Warping coefficient */
118 const opus_int length, /* I Length of input */
119 const opus_int order /* I Correlation order (even) */
120);
121
122/* Calculation of LTP state scaling */
123void silk_LTP_scale_ctrl_FIX(
124 silk_encoder_state_FIX *psEnc, /* I/O encoder state */
125 silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */
126 opus_int condCoding /* I The type of conditional coding to use */
127);
128
129/**********************************************/
130/* Prediction Analysis */
131/**********************************************/
132/* Find pitch lags */
133void silk_find_pitch_lags_FIX(
134 silk_encoder_state_FIX *psEnc, /* I/O encoder state */
135 silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */
136 opus_int16 res[], /* O residual */
tlegrand@google.com3c3902f2013-12-09 08:35:25 +0000137 const opus_int16 x[], /* I Speech signal */
138 int arch /* I Run-time architecture */
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000139);
140
141/* Find LPC and LTP coefficients */
142void silk_find_pred_coefs_FIX(
143 silk_encoder_state_FIX *psEnc, /* I/O encoder state */
144 silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */
145 const opus_int16 res_pitch[], /* I Residual from pitch analysis */
146 const opus_int16 x[], /* I Speech signal */
147 opus_int condCoding /* I The type of conditional coding to use */
148);
149
150/* LPC analysis */
151void silk_find_LPC_FIX(
152 silk_encoder_state *psEncC, /* I/O Encoder state */
153 opus_int16 NLSF_Q15[], /* O NLSFs */
154 const opus_int16 x[], /* I Input signal */
155 const opus_int32 minInvGain_Q30 /* I Inverse of max prediction gain */
156);
157
158/* LTP analysis */
159void silk_find_LTP_FIX(
160 opus_int16 b_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* O LTP coefs */
161 opus_int32 WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */
162 opus_int *LTPredCodGain_Q7, /* O LTP coding gain */
163 const opus_int16 r_lpc[], /* I residual signal after LPC signal + state for first 10 ms */
164 const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */
165 const opus_int32 Wght_Q15[ MAX_NB_SUBFR ], /* I weights */
166 const opus_int subfr_length, /* I subframe length */
167 const opus_int nb_subfr, /* I number of subframes */
168 const opus_int mem_offset, /* I number of samples in LTP memory */
169 opus_int corr_rshifts[ MAX_NB_SUBFR ] /* O right shifts applied to correlations */
170);
171
172void silk_LTP_analysis_filter_FIX(
173 opus_int16 *LTP_res, /* O LTP residual signal of length MAX_NB_SUBFR * ( pre_length + subfr_length ) */
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000174 const opus_int16 *x, /* I Pointer to input signal with at least max( pitchL ) preceding samples */
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000175 const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ],/* I LTP_ORDER LTP coefficients for each MAX_NB_SUBFR subframe */
176 const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lag, one for each subframe */
177 const opus_int32 invGains_Q16[ MAX_NB_SUBFR ], /* I Inverse quantization gains, one for each subframe */
178 const opus_int subfr_length, /* I Length of each subframe */
179 const opus_int nb_subfr, /* I Number of subframes */
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000180 const opus_int pre_length /* I Length of the preceding samples starting at &x[0] for each subframe */
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000181);
182
183/* Calculates residual energies of input subframes where all subframes have LPC_order */
sergeyu@chromium.org6b6bee22013-02-28 21:17:26 +0000184/* of preceding samples */
sergeyu@chromium.org885f2ff2012-10-17 22:31:52 +0000185void silk_residual_energy_FIX(
186 opus_int32 nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */
187 opus_int nrgsQ[ MAX_NB_SUBFR ], /* O Q value per subframe */
188 const opus_int16 x[], /* I Input signal */
189 opus_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */
190 const opus_int32 gains[ MAX_NB_SUBFR ], /* I Quantization gains */
191 const opus_int subfr_length, /* I Subframe length */
192 const opus_int nb_subfr, /* I Number of subframes */
193 const opus_int LPC_order /* I LPC order */
194);
195
196/* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */
197opus_int32 silk_residual_energy16_covar_FIX(
198 const opus_int16 *c, /* I Prediction vector */
199 const opus_int32 *wXX, /* I Correlation matrix */
200 const opus_int32 *wXx, /* I Correlation vector */
201 opus_int32 wxx, /* I Signal energy */
202 opus_int D, /* I Dimension */
203 opus_int cQ /* I Q value for c vector 0 - 15 */
204);
205
206/* Processing of gains */
207void silk_process_gains_FIX(
208 silk_encoder_state_FIX *psEnc, /* I/O Encoder state */
209 silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control */
210 opus_int condCoding /* I The type of conditional coding to use */
211);
212
213/******************/
214/* Linear Algebra */
215/******************/
216/* Calculates correlation matrix X'*X */
217void silk_corrMatrix_FIX(
218 const opus_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */
219 const opus_int L, /* I Length of vectors */
220 const opus_int order, /* I Max lag for correlation */
221 const opus_int head_room, /* I Desired headroom */
222 opus_int32 *XX, /* O Pointer to X'*X correlation matrix [ order x order ] */
223 opus_int *rshifts /* I/O Right shifts of correlations */
224);
225
226/* Calculates correlation vector X'*t */
227void silk_corrVector_FIX(
228 const opus_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */
229 const opus_int16 *t, /* I Target vector [L] */
230 const opus_int L, /* I Length of vectors */
231 const opus_int order, /* I Max lag for correlation */
232 opus_int32 *Xt, /* O Pointer to X'*t correlation vector [order] */
233 const opus_int rshifts /* I Right shifts of correlations */
234);
235
236/* Add noise to matrix diagonal */
237void silk_regularize_correlations_FIX(
238 opus_int32 *XX, /* I/O Correlation matrices */
239 opus_int32 *xx, /* I/O Correlation values */
240 opus_int32 noise, /* I Noise to add */
241 opus_int D /* I Dimension of XX */
242);
243
244/* Solves Ax = b, assuming A is symmetric */
245void silk_solve_LDL_FIX(
246 opus_int32 *A, /* I Pointer to symetric square matrix A */
247 opus_int M, /* I Size of matrix */
248 const opus_int32 *b, /* I Pointer to b vector */
249 opus_int32 *x_Q16 /* O Pointer to x solution vector */
250);
251
252#ifndef FORCE_CPP_BUILD
253#ifdef __cplusplus
254}
255#endif /* __cplusplus */
256#endif /* FORCE_CPP_BUILD */
257#endif /* SILK_MAIN_FIX_H */