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