media/libopus/silk/float/main_FLP.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial