Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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_FIX_H |
michael@0 | 29 | #define SILK_MAIN_FIX_H |
michael@0 | 30 | |
michael@0 | 31 | #include "SigProc_FIX.h" |
michael@0 | 32 | #include "structs_FIX.h" |
michael@0 | 33 | #include "control.h" |
michael@0 | 34 | #include "main.h" |
michael@0 | 35 | #include "PLC.h" |
michael@0 | 36 | #include "debug.h" |
michael@0 | 37 | #include "entenc.h" |
michael@0 | 38 | |
michael@0 | 39 | #ifndef FORCE_CPP_BUILD |
michael@0 | 40 | #ifdef __cplusplus |
michael@0 | 41 | extern "C" |
michael@0 | 42 | { |
michael@0 | 43 | #endif |
michael@0 | 44 | #endif |
michael@0 | 45 | |
michael@0 | 46 | #define silk_encoder_state_Fxx silk_encoder_state_FIX |
michael@0 | 47 | #define silk_encode_do_VAD_Fxx silk_encode_do_VAD_FIX |
michael@0 | 48 | #define silk_encode_frame_Fxx silk_encode_frame_FIX |
michael@0 | 49 | |
michael@0 | 50 | /*********************/ |
michael@0 | 51 | /* Encoder Functions */ |
michael@0 | 52 | /*********************/ |
michael@0 | 53 | |
michael@0 | 54 | /* High-pass filter with cutoff frequency adaptation based on pitch lag statistics */ |
michael@0 | 55 | void silk_HP_variable_cutoff( |
michael@0 | 56 | silk_encoder_state_Fxx state_Fxx[] /* I/O Encoder states */ |
michael@0 | 57 | ); |
michael@0 | 58 | |
michael@0 | 59 | /* Encoder main function */ |
michael@0 | 60 | void silk_encode_do_VAD_FIX( |
michael@0 | 61 | silk_encoder_state_FIX *psEnc /* I/O Pointer to Silk FIX encoder state */ |
michael@0 | 62 | ); |
michael@0 | 63 | |
michael@0 | 64 | /* Encoder main function */ |
michael@0 | 65 | opus_int silk_encode_frame_FIX( |
michael@0 | 66 | silk_encoder_state_FIX *psEnc, /* I/O Pointer to Silk FIX encoder state */ |
michael@0 | 67 | opus_int32 *pnBytesOut, /* O Pointer to number of payload bytes; */ |
michael@0 | 68 | ec_enc *psRangeEnc, /* I/O compressor data structure */ |
michael@0 | 69 | opus_int condCoding, /* I The type of conditional coding to use */ |
michael@0 | 70 | opus_int maxBits, /* I If > 0: maximum number of output bits */ |
michael@0 | 71 | opus_int useCBR /* I Flag to force constant-bitrate operation */ |
michael@0 | 72 | ); |
michael@0 | 73 | |
michael@0 | 74 | /* Initializes the Silk encoder state */ |
michael@0 | 75 | opus_int silk_init_encoder( |
michael@0 | 76 | silk_encoder_state_Fxx *psEnc, /* I/O Pointer to Silk FIX encoder state */ |
michael@0 | 77 | int arch /* I Run-time architecture */ |
michael@0 | 78 | ); |
michael@0 | 79 | |
michael@0 | 80 | /* Control the Silk encoder */ |
michael@0 | 81 | opus_int silk_control_encoder( |
michael@0 | 82 | silk_encoder_state_Fxx *psEnc, /* I/O Pointer to Silk encoder state */ |
michael@0 | 83 | silk_EncControlStruct *encControl, /* I Control structure */ |
michael@0 | 84 | const opus_int32 TargetRate_bps, /* I Target max bitrate (bps) */ |
michael@0 | 85 | const opus_int allow_bw_switch, /* I Flag to allow switching audio bandwidth */ |
michael@0 | 86 | const opus_int channelNb, /* I Channel number */ |
michael@0 | 87 | const opus_int force_fs_kHz |
michael@0 | 88 | ); |
michael@0 | 89 | |
michael@0 | 90 | /****************/ |
michael@0 | 91 | /* Prefiltering */ |
michael@0 | 92 | /****************/ |
michael@0 | 93 | void silk_prefilter_FIX( |
michael@0 | 94 | silk_encoder_state_FIX *psEnc, /* I/O Encoder state */ |
michael@0 | 95 | const silk_encoder_control_FIX *psEncCtrl, /* I Encoder control */ |
michael@0 | 96 | opus_int32 xw_Q10[], /* O Weighted signal */ |
michael@0 | 97 | const opus_int16 x[] /* I Speech signal */ |
michael@0 | 98 | ); |
michael@0 | 99 | |
michael@0 | 100 | /**************************/ |
michael@0 | 101 | /* Noise shaping analysis */ |
michael@0 | 102 | /**************************/ |
michael@0 | 103 | /* Compute noise shaping coefficients and initial gain values */ |
michael@0 | 104 | void silk_noise_shape_analysis_FIX( |
michael@0 | 105 | silk_encoder_state_FIX *psEnc, /* I/O Encoder state FIX */ |
michael@0 | 106 | silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control FIX */ |
michael@0 | 107 | const opus_int16 *pitch_res, /* I LPC residual from pitch analysis */ |
michael@0 | 108 | const opus_int16 *x, /* I Input signal [ frame_length + la_shape ] */ |
michael@0 | 109 | int arch /* I Run-time architecture */ |
michael@0 | 110 | ); |
michael@0 | 111 | |
michael@0 | 112 | /* Autocorrelations for a warped frequency axis */ |
michael@0 | 113 | void silk_warped_autocorrelation_FIX( |
michael@0 | 114 | opus_int32 *corr, /* O Result [order + 1] */ |
michael@0 | 115 | opus_int *scale, /* O Scaling of the correlation vector */ |
michael@0 | 116 | const opus_int16 *input, /* I Input data to correlate */ |
michael@0 | 117 | const opus_int warping_Q16, /* I Warping coefficient */ |
michael@0 | 118 | const opus_int length, /* I Length of input */ |
michael@0 | 119 | const opus_int order /* I Correlation order (even) */ |
michael@0 | 120 | ); |
michael@0 | 121 | |
michael@0 | 122 | /* Calculation of LTP state scaling */ |
michael@0 | 123 | void silk_LTP_scale_ctrl_FIX( |
michael@0 | 124 | silk_encoder_state_FIX *psEnc, /* I/O encoder state */ |
michael@0 | 125 | silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */ |
michael@0 | 126 | opus_int condCoding /* I The type of conditional coding to use */ |
michael@0 | 127 | ); |
michael@0 | 128 | |
michael@0 | 129 | /**********************************************/ |
michael@0 | 130 | /* Prediction Analysis */ |
michael@0 | 131 | /**********************************************/ |
michael@0 | 132 | /* Find pitch lags */ |
michael@0 | 133 | void silk_find_pitch_lags_FIX( |
michael@0 | 134 | silk_encoder_state_FIX *psEnc, /* I/O encoder state */ |
michael@0 | 135 | silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */ |
michael@0 | 136 | opus_int16 res[], /* O residual */ |
michael@0 | 137 | const opus_int16 x[], /* I Speech signal */ |
michael@0 | 138 | int arch /* I Run-time architecture */ |
michael@0 | 139 | ); |
michael@0 | 140 | |
michael@0 | 141 | /* Find LPC and LTP coefficients */ |
michael@0 | 142 | void silk_find_pred_coefs_FIX( |
michael@0 | 143 | silk_encoder_state_FIX *psEnc, /* I/O encoder state */ |
michael@0 | 144 | silk_encoder_control_FIX *psEncCtrl, /* I/O encoder control */ |
michael@0 | 145 | const opus_int16 res_pitch[], /* I Residual from pitch analysis */ |
michael@0 | 146 | const opus_int16 x[], /* I Speech signal */ |
michael@0 | 147 | opus_int condCoding /* I The type of conditional coding to use */ |
michael@0 | 148 | ); |
michael@0 | 149 | |
michael@0 | 150 | /* LPC analysis */ |
michael@0 | 151 | void silk_find_LPC_FIX( |
michael@0 | 152 | silk_encoder_state *psEncC, /* I/O Encoder state */ |
michael@0 | 153 | opus_int16 NLSF_Q15[], /* O NLSFs */ |
michael@0 | 154 | const opus_int16 x[], /* I Input signal */ |
michael@0 | 155 | const opus_int32 minInvGain_Q30 /* I Inverse of max prediction gain */ |
michael@0 | 156 | ); |
michael@0 | 157 | |
michael@0 | 158 | /* LTP analysis */ |
michael@0 | 159 | void silk_find_LTP_FIX( |
michael@0 | 160 | opus_int16 b_Q14[ MAX_NB_SUBFR * LTP_ORDER ], /* O LTP coefs */ |
michael@0 | 161 | opus_int32 WLTP[ MAX_NB_SUBFR * LTP_ORDER * LTP_ORDER ], /* O Weight for LTP quantization */ |
michael@0 | 162 | opus_int *LTPredCodGain_Q7, /* O LTP coding gain */ |
michael@0 | 163 | const opus_int16 r_lpc[], /* I residual signal after LPC signal + state for first 10 ms */ |
michael@0 | 164 | const opus_int lag[ MAX_NB_SUBFR ], /* I LTP lags */ |
michael@0 | 165 | const opus_int32 Wght_Q15[ MAX_NB_SUBFR ], /* I weights */ |
michael@0 | 166 | const opus_int subfr_length, /* I subframe length */ |
michael@0 | 167 | const opus_int nb_subfr, /* I number of subframes */ |
michael@0 | 168 | const opus_int mem_offset, /* I number of samples in LTP memory */ |
michael@0 | 169 | opus_int corr_rshifts[ MAX_NB_SUBFR ] /* O right shifts applied to correlations */ |
michael@0 | 170 | ); |
michael@0 | 171 | |
michael@0 | 172 | void silk_LTP_analysis_filter_FIX( |
michael@0 | 173 | opus_int16 *LTP_res, /* O LTP residual signal of length MAX_NB_SUBFR * ( pre_length + subfr_length ) */ |
michael@0 | 174 | const opus_int16 *x, /* I Pointer to input signal with at least max( pitchL ) preceding samples */ |
michael@0 | 175 | const opus_int16 LTPCoef_Q14[ LTP_ORDER * MAX_NB_SUBFR ],/* I LTP_ORDER LTP coefficients for each MAX_NB_SUBFR subframe */ |
michael@0 | 176 | const opus_int pitchL[ MAX_NB_SUBFR ], /* I Pitch lag, one for each subframe */ |
michael@0 | 177 | const opus_int32 invGains_Q16[ MAX_NB_SUBFR ], /* I Inverse quantization gains, one for each subframe */ |
michael@0 | 178 | const opus_int subfr_length, /* I Length of each subframe */ |
michael@0 | 179 | const opus_int nb_subfr, /* I Number of subframes */ |
michael@0 | 180 | const opus_int pre_length /* I Length of the preceding samples starting at &x[0] for each subframe */ |
michael@0 | 181 | ); |
michael@0 | 182 | |
michael@0 | 183 | /* Calculates residual energies of input subframes where all subframes have LPC_order */ |
michael@0 | 184 | /* of preceding samples */ |
michael@0 | 185 | void silk_residual_energy_FIX( |
michael@0 | 186 | opus_int32 nrgs[ MAX_NB_SUBFR ], /* O Residual energy per subframe */ |
michael@0 | 187 | opus_int nrgsQ[ MAX_NB_SUBFR ], /* O Q value per subframe */ |
michael@0 | 188 | const opus_int16 x[], /* I Input signal */ |
michael@0 | 189 | opus_int16 a_Q12[ 2 ][ MAX_LPC_ORDER ], /* I AR coefs for each frame half */ |
michael@0 | 190 | const opus_int32 gains[ MAX_NB_SUBFR ], /* I Quantization gains */ |
michael@0 | 191 | const opus_int subfr_length, /* I Subframe length */ |
michael@0 | 192 | const opus_int nb_subfr, /* I Number of subframes */ |
michael@0 | 193 | const opus_int LPC_order /* I LPC order */ |
michael@0 | 194 | ); |
michael@0 | 195 | |
michael@0 | 196 | /* Residual energy: nrg = wxx - 2 * wXx * c + c' * wXX * c */ |
michael@0 | 197 | opus_int32 silk_residual_energy16_covar_FIX( |
michael@0 | 198 | const opus_int16 *c, /* I Prediction vector */ |
michael@0 | 199 | const opus_int32 *wXX, /* I Correlation matrix */ |
michael@0 | 200 | const opus_int32 *wXx, /* I Correlation vector */ |
michael@0 | 201 | opus_int32 wxx, /* I Signal energy */ |
michael@0 | 202 | opus_int D, /* I Dimension */ |
michael@0 | 203 | opus_int cQ /* I Q value for c vector 0 - 15 */ |
michael@0 | 204 | ); |
michael@0 | 205 | |
michael@0 | 206 | /* Processing of gains */ |
michael@0 | 207 | void silk_process_gains_FIX( |
michael@0 | 208 | silk_encoder_state_FIX *psEnc, /* I/O Encoder state */ |
michael@0 | 209 | silk_encoder_control_FIX *psEncCtrl, /* I/O Encoder control */ |
michael@0 | 210 | opus_int condCoding /* I The type of conditional coding to use */ |
michael@0 | 211 | ); |
michael@0 | 212 | |
michael@0 | 213 | /******************/ |
michael@0 | 214 | /* Linear Algebra */ |
michael@0 | 215 | /******************/ |
michael@0 | 216 | /* Calculates correlation matrix X'*X */ |
michael@0 | 217 | void silk_corrMatrix_FIX( |
michael@0 | 218 | const opus_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */ |
michael@0 | 219 | const opus_int L, /* I Length of vectors */ |
michael@0 | 220 | const opus_int order, /* I Max lag for correlation */ |
michael@0 | 221 | const opus_int head_room, /* I Desired headroom */ |
michael@0 | 222 | opus_int32 *XX, /* O Pointer to X'*X correlation matrix [ order x order ] */ |
michael@0 | 223 | opus_int *rshifts /* I/O Right shifts of correlations */ |
michael@0 | 224 | ); |
michael@0 | 225 | |
michael@0 | 226 | /* Calculates correlation vector X'*t */ |
michael@0 | 227 | void silk_corrVector_FIX( |
michael@0 | 228 | const opus_int16 *x, /* I x vector [L + order - 1] used to form data matrix X */ |
michael@0 | 229 | const opus_int16 *t, /* I Target vector [L] */ |
michael@0 | 230 | const opus_int L, /* I Length of vectors */ |
michael@0 | 231 | const opus_int order, /* I Max lag for correlation */ |
michael@0 | 232 | opus_int32 *Xt, /* O Pointer to X'*t correlation vector [order] */ |
michael@0 | 233 | const opus_int rshifts /* I Right shifts of correlations */ |
michael@0 | 234 | ); |
michael@0 | 235 | |
michael@0 | 236 | /* Add noise to matrix diagonal */ |
michael@0 | 237 | void silk_regularize_correlations_FIX( |
michael@0 | 238 | opus_int32 *XX, /* I/O Correlation matrices */ |
michael@0 | 239 | opus_int32 *xx, /* I/O Correlation values */ |
michael@0 | 240 | opus_int32 noise, /* I Noise to add */ |
michael@0 | 241 | opus_int D /* I Dimension of XX */ |
michael@0 | 242 | ); |
michael@0 | 243 | |
michael@0 | 244 | /* Solves Ax = b, assuming A is symmetric */ |
michael@0 | 245 | void silk_solve_LDL_FIX( |
michael@0 | 246 | opus_int32 *A, /* I Pointer to symetric square matrix A */ |
michael@0 | 247 | opus_int M, /* I Size of matrix */ |
michael@0 | 248 | const opus_int32 *b, /* I Pointer to b vector */ |
michael@0 | 249 | opus_int32 *x_Q16 /* O Pointer to x solution vector */ |
michael@0 | 250 | ); |
michael@0 | 251 | |
michael@0 | 252 | #ifndef FORCE_CPP_BUILD |
michael@0 | 253 | #ifdef __cplusplus |
michael@0 | 254 | } |
michael@0 | 255 | #endif /* __cplusplus */ |
michael@0 | 256 | #endif /* FORCE_CPP_BUILD */ |
michael@0 | 257 | #endif /* SILK_MAIN_FIX_H */ |