blob: 93455d4d9a47d73b42b5005cc9b5fda200aa7c88 [file] [log] [blame]
Alexandre Lision744f7422013-09-25 11:39:37 -04001/***********************************************************************
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.
11- Neither the name of Internet Society, IETF or IETF Trust, nor the
12names of specific contributors, may be used to endorse or promote
13products derived from this software without specific prior written
14permission.
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
16AND 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_FLP_H
29#define SILK_MAIN_FLP_H
30
31#include "SigProc_FLP.h"
32#include "SigProc_FIX.h"
33#include "structs_FLP.h"
34#include "main.h"
35#include "define.h"
36#include "debug.h"
37#include "entenc.h"
38
39#ifdef __cplusplus
40extern "C"
41{
42#endif
43
44#define silk_encoder_state_Fxx silk_encoder_state_FLP
45#define silk_encode_do_VAD_Fxx silk_encode_do_VAD_FLP
46#define silk_encode_frame_Fxx silk_encode_frame_FLP
47
48/*********************/
49/* Encoder Functions */
50/*********************/
51
52/* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */
53void silk_HP_variable_cutoff(
54 silk_encoder_state_Fxx state_Fxx[] /* I/O Encoder states */
55);
56
57/* Encoder main function */
58void silk_encode_do_VAD_FLP(
59 silk_encoder_state_FLP *psEnc /* I/O Encoder state FLP */
60);
61
62/* Encoder main function */
63opus_int silk_encode_frame_FLP(
64 silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
65 opus_int32 *pnBytesOut, /* O Number of payload bytes; */
66 ec_enc *psRangeEnc, /* I/O compressor data structure */
67 opus_int condCoding, /* I The type of conditional coding to use */
68 opus_int maxBits, /* I If > 0: maximum number of output bits */
69 opus_int useCBR /* I Flag to force constant-bitrate operation */
70);
71
72/* Initializes the Silk encoder state */
73opus_int silk_init_encoder(
74 silk_encoder_state_FLP *psEnc /* I/O Encoder state FLP */
75);
76
77/* Control the Silk encoder */
78opus_int silk_control_encoder(
79 silk_encoder_state_FLP *psEnc, /* I/O Pointer to Silk encoder state FLP */
80 silk_EncControlStruct *encControl, /* I Control structure */
81 const opus_int32 TargetRate_bps, /* I Target max bitrate (bps) */
82 const opus_int allow_bw_switch, /* I Flag to allow switching audio bandwidth */
83 const opus_int channelNb, /* I Channel number */
84 const opus_int force_fs_kHz
85);
86
87/****************/
88/* Prefiltering */
89/****************/
90void silk_prefilter_FLP(
91 silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
92 const silk_encoder_control_FLP *psEncCtrl, /* I Encoder control FLP */
93 silk_float xw[], /* O Weighted signal */
94 const silk_float x[] /* I Speech signal */
95);
96
97/**************************/
98/* Noise shaping analysis */
99/**************************/
100/* Compute noise shaping coefficients and initial gain values */
101void silk_noise_shape_analysis_FLP(
102 silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
103 silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */
104 const silk_float *pitch_res, /* I LPC residual from pitch analysis */
105 const silk_float *x /* I Input signal [frame_length + la_shape] */
106);
107
108/* Autocorrelations for a warped frequency axis */
109void silk_warped_autocorrelation_FLP(
110 silk_float *corr, /* O Result [order + 1] */
111 const silk_float *input, /* I Input data to correlate */
112 const silk_float warping, /* I Warping coefficient */
113 const opus_int length, /* I Length of input */
114 const opus_int order /* I Correlation order (even) */
115);
116
117/* Calculation of LTP state scaling */
118void silk_LTP_scale_ctrl_FLP(
119 silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
120 silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */
121 opus_int condCoding /* I The type of conditional coding to use */
122);
123
124/**********************************************/
125/* Prediction Analysis */
126/**********************************************/
127/* Find pitch lags */
128void silk_find_pitch_lags_FLP(
129 silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
130 silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */
131 silk_float res[], /* O Residual */
132 const silk_float x[] /* I Speech signal */
133);
134
135/* Find LPC and LTP coefficients */
136void silk_find_pred_coefs_FLP(
137 silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
138 silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */
139 const silk_float res_pitch[], /* I Residual from pitch analysis */
140 const silk_float x[], /* I Speech signal */
141 opus_int condCoding /* I The type of conditional coding to use */
142);
143
144/* LPC analysis */
145void silk_find_LPC_FLP(
146 silk_encoder_state *psEncC, /* I/O Encoder state */
147 opus_int16 NLSF_Q15[], /* O NLSFs */
148 const silk_float x[], /* I Input signal */
149 const silk_float minInvGain /* I Prediction gain from LTP (dB) */
150);
151
152/* LTP analysis */
153void silk_find_LTP_FLP(
154 silk_float b[ MAX_NB_SUBFR * LTP_ORDER ], /* O LTP coefs */
155 silk_float WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */
156 silk_float *LTPredCodGain, /* O LTP coding gain */
157 const silk_float r_lpc[], /* I LPC residual */
158 const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */
159 const silk_float Wght[ MAX_NB_SUBFR ], /* I Weights */
160 const opus_int subfr_length, /* I Subframe length */
161 const opus_int nb_subfr, /* I number of subframes */
162 const opus_int mem_offset /* I Number of samples in LTP memory */
163);
164
165void silk_LTP_analysis_filter_FLP(
166 silk_float *LTP_res, /* O LTP res MAX_NB_SUBFR*(pre_lgth+subfr_lngth) */
167 const silk_float *x, /* I Input signal, with preceding samples */
168 const silk_float B[ LTP_ORDER * MAX_NB_SUBFR ], /* I LTP coefficients for each subframe */
169 const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lags */
170 const silk_float invGains[ MAX_NB_SUBFR ], /* I Inverse quantization gains */
171 const opus_int subfr_length, /* I Length of each subframe */
172 const opus_int nb_subfr, /* I number of subframes */
173 const opus_int pre_length /* I Preceding samples for each subframe */
174);
175
176/* Calculates residual energies of input subframes where all subframes have LPC_order */
177/* of preceding samples */
178void silk_residual_energy_FLP(
179 silk_float nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */
180 const silk_float x[], /* I Input signal */
181 silk_float a[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */
182 const silk_float gains[], /* I Quantization gains */
183 const opus_int subfr_length, /* I Subframe length */
184 const opus_int nb_subfr, /* I number of subframes */
185 const opus_int LPC_order /* I LPC order */
186);
187
188/* 16th order LPC analysis filter */
189void silk_LPC_analysis_filter_FLP(
190 silk_float r_LPC[], /* O LPC residual signal */
191 const silk_float PredCoef[], /* I LPC coefficients */
192 const silk_float s[], /* I Input signal */
193 const opus_int length, /* I Length of input signal */
194 const opus_int Order /* I LPC order */
195);
196
197/* LTP tap quantizer */
198void silk_quant_LTP_gains_FLP(
199 silk_float B[ MAX_NB_SUBFR * LTP_ORDER ], /* I/O (Un-)quantized LTP gains */
200 opus_int8 cbk_index[ MAX_NB_SUBFR ], /* O Codebook index */
201 opus_int8 *periodicity_index, /* O Periodicity index */
202 const silk_float W[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* I Error weights */
203 const opus_int mu_Q10, /* I Mu value (R/D tradeoff) */
204 const opus_int lowComplexity, /* I Flag for low complexity */
205 const opus_int nb_subfr /* I number of subframes */
206);
207
208/* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */
209silk_float silk_residual_energy_covar_FLP( /* O Weighted residual energy */
210 const silk_float *c, /* I Filter coefficients */
211 silk_float *wXX, /* I/O Weighted correlation matrix, reg. out */
212 const silk_float *wXx, /* I Weighted correlation vector */
213 const silk_float wxx, /* I Weighted correlation value */
214 const opus_int D /* I Dimension */
215);
216
217/* Processing of gains */
218void silk_process_gains_FLP(
219 silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
220 silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */
221 opus_int condCoding /* I The type of conditional coding to use */
222);
223
224/******************/
225/* Linear Algebra */
226/******************/
227/* Calculates correlation matrix X'*X */
228void silk_corrMatrix_FLP(
229 const silk_float *x, /* I x vector [ L+order-1 ] used to create X */
230 const opus_int L, /* I Length of vectors */
231 const opus_int Order, /* I Max lag for correlation */
232 silk_float *XX /* O X'*X correlation matrix [order x order] */
233);
234
235/* Calculates correlation vector X'*t */
236void silk_corrVector_FLP(
237 const silk_float *x, /* I x vector [L+order-1] used to create X */
238 const silk_float *t, /* I Target vector [L] */
239 const opus_int L, /* I Length of vecors */
240 const opus_int Order, /* I Max lag for correlation */
241 silk_float *Xt /* O X'*t correlation vector [order] */
242);
243
244/* Add noise to matrix diagonal */
245void silk_regularize_correlations_FLP(
246 silk_float *XX, /* I/O Correlation matrices */
247 silk_float *xx, /* I/O Correlation values */
248 const silk_float noise, /* I Noise energy to add */
249 const opus_int D /* I Dimension of XX */
250);
251
252/* Function to solve linear equation Ax = b, where A is an MxM symmetric matrix */
253void silk_solve_LDL_FLP(
254 silk_float *A, /* I/O Symmetric square matrix, out: reg. */
255 const opus_int M, /* I Size of matrix */
256 const silk_float *b, /* I Pointer to b vector */
257 silk_float *x /* O Pointer to x solution vector */
258);
259
260/* Apply sine window to signal vector. */
261/* Window types: */
262/* 1 -> sine window from 0 to pi/2 */
263/* 2 -> sine window from pi/2 to pi */
264void silk_apply_sine_window_FLP(
265 silk_float px_win[], /* O Pointer to windowed signal */
266 const silk_float px[], /* I Pointer to input signal */
267 const opus_int win_type, /* I Selects a window type */
268 const opus_int length /* I Window length, multiple of 4 */
269);
270
271/* Wrapper functions. Call flp / fix code */
272
273/* Convert AR filter coefficients to NLSF parameters */
274void silk_A2NLSF_FLP(
275 opus_int16 *NLSF_Q15, /* O NLSF vector [ LPC_order ] */
276 const silk_float *pAR, /* I LPC coefficients [ LPC_order ] */
277 const opus_int LPC_order /* I LPC order */
278);
279
280/* Convert NLSF parameters to AR prediction filter coefficients */
281void silk_NLSF2A_FLP(
282 silk_float *pAR, /* O LPC coefficients [ LPC_order ] */
283 const opus_int16 *NLSF_Q15, /* I NLSF vector [ LPC_order ] */
284 const opus_int LPC_order /* I LPC order */
285);
286
287/* Limit, stabilize, and quantize NLSFs */
288void silk_process_NLSFs_FLP(
289 silk_encoder_state *psEncC, /* I/O Encoder state */
290 silk_float PredCoef[ 2 ][ MAX_LPC_ORDER ], /* O Prediction coefficients */
291 opus_int16 NLSF_Q15[ MAX_LPC_ORDER ], /* I/O Normalized LSFs (quant out) (0 - (2^15-1)) */
292 const opus_int16 prev_NLSF_Q15[ MAX_LPC_ORDER ] /* I Previous Normalized LSFs (0 - (2^15-1)) */
293);
294
295/* Floating-point Silk NSQ wrapper */
296void silk_NSQ_wrapper_FLP(
297 silk_encoder_state_FLP *psEnc, /* I/O Encoder state FLP */
298 silk_encoder_control_FLP *psEncCtrl, /* I/O Encoder control FLP */
299 SideInfoIndices *psIndices, /* I/O Quantization indices */
300 silk_nsq_state *psNSQ, /* I/O Noise Shaping Quantzation state */
301 opus_int8 pulses[], /* O Quantized pulse signal */
302 const silk_float x[] /* I Prefiltered input signal */
303);
304
305#ifdef __cplusplus
306}
307#endif
308
309#endif