1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libopus/silk/control_codec.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,422 @@ 1.4 +/*********************************************************************** 1.5 +Copyright (c) 2006-2011, Skype Limited. All rights reserved. 1.6 +Redistribution and use in source and binary forms, with or without 1.7 +modification, are permitted provided that the following conditions 1.8 +are met: 1.9 +- Redistributions of source code must retain the above copyright notice, 1.10 +this list of conditions and the following disclaimer. 1.11 +- Redistributions in binary form must reproduce the above copyright 1.12 +notice, this list of conditions and the following disclaimer in the 1.13 +documentation and/or other materials provided with the distribution. 1.14 +- Neither the name of Internet Society, IETF or IETF Trust, nor the 1.15 +names of specific contributors, may be used to endorse or promote 1.16 +products derived from this software without specific prior written 1.17 +permission. 1.18 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1.19 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.20 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.21 +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 1.22 +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.23 +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.24 +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.25 +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.26 +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.27 +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1.28 +POSSIBILITY OF SUCH DAMAGE. 1.29 +***********************************************************************/ 1.30 + 1.31 +#ifdef HAVE_CONFIG_H 1.32 +#include "config.h" 1.33 +#endif 1.34 +#ifdef FIXED_POINT 1.35 +#include "main_FIX.h" 1.36 +#define silk_encoder_state_Fxx silk_encoder_state_FIX 1.37 +#else 1.38 +#include "main_FLP.h" 1.39 +#define silk_encoder_state_Fxx silk_encoder_state_FLP 1.40 +#endif 1.41 +#include "stack_alloc.h" 1.42 +#include "tuning_parameters.h" 1.43 +#include "pitch_est_defines.h" 1.44 + 1.45 +static opus_int silk_setup_resamplers( 1.46 + silk_encoder_state_Fxx *psEnc, /* I/O */ 1.47 + opus_int fs_kHz /* I */ 1.48 +); 1.49 + 1.50 +static opus_int silk_setup_fs( 1.51 + silk_encoder_state_Fxx *psEnc, /* I/O */ 1.52 + opus_int fs_kHz, /* I */ 1.53 + opus_int PacketSize_ms /* I */ 1.54 +); 1.55 + 1.56 +static opus_int silk_setup_complexity( 1.57 + silk_encoder_state *psEncC, /* I/O */ 1.58 + opus_int Complexity /* I */ 1.59 +); 1.60 + 1.61 +static OPUS_INLINE opus_int silk_setup_LBRR( 1.62 + silk_encoder_state *psEncC, /* I/O */ 1.63 + const opus_int32 TargetRate_bps /* I */ 1.64 +); 1.65 + 1.66 + 1.67 +/* Control encoder */ 1.68 +opus_int silk_control_encoder( 1.69 + silk_encoder_state_Fxx *psEnc, /* I/O Pointer to Silk encoder state */ 1.70 + silk_EncControlStruct *encControl, /* I Control structure */ 1.71 + const opus_int32 TargetRate_bps, /* I Target max bitrate (bps) */ 1.72 + const opus_int allow_bw_switch, /* I Flag to allow switching audio bandwidth */ 1.73 + const opus_int channelNb, /* I Channel number */ 1.74 + const opus_int force_fs_kHz 1.75 +) 1.76 +{ 1.77 + opus_int fs_kHz, ret = 0; 1.78 + 1.79 + psEnc->sCmn.useDTX = encControl->useDTX; 1.80 + psEnc->sCmn.useCBR = encControl->useCBR; 1.81 + psEnc->sCmn.API_fs_Hz = encControl->API_sampleRate; 1.82 + psEnc->sCmn.maxInternal_fs_Hz = encControl->maxInternalSampleRate; 1.83 + psEnc->sCmn.minInternal_fs_Hz = encControl->minInternalSampleRate; 1.84 + psEnc->sCmn.desiredInternal_fs_Hz = encControl->desiredInternalSampleRate; 1.85 + psEnc->sCmn.useInBandFEC = encControl->useInBandFEC; 1.86 + psEnc->sCmn.nChannelsAPI = encControl->nChannelsAPI; 1.87 + psEnc->sCmn.nChannelsInternal = encControl->nChannelsInternal; 1.88 + psEnc->sCmn.allow_bandwidth_switch = allow_bw_switch; 1.89 + psEnc->sCmn.channelNb = channelNb; 1.90 + 1.91 + if( psEnc->sCmn.controlled_since_last_payload != 0 && psEnc->sCmn.prefillFlag == 0 ) { 1.92 + if( psEnc->sCmn.API_fs_Hz != psEnc->sCmn.prev_API_fs_Hz && psEnc->sCmn.fs_kHz > 0 ) { 1.93 + /* Change in API sampling rate in the middle of encoding a packet */ 1.94 + ret += silk_setup_resamplers( psEnc, psEnc->sCmn.fs_kHz ); 1.95 + } 1.96 + return ret; 1.97 + } 1.98 + 1.99 + /* Beyond this point we know that there are no previously coded frames in the payload buffer */ 1.100 + 1.101 + /********************************************/ 1.102 + /* Determine internal sampling rate */ 1.103 + /********************************************/ 1.104 + fs_kHz = silk_control_audio_bandwidth( &psEnc->sCmn, encControl ); 1.105 + if( force_fs_kHz ) { 1.106 + fs_kHz = force_fs_kHz; 1.107 + } 1.108 + /********************************************/ 1.109 + /* Prepare resampler and buffered data */ 1.110 + /********************************************/ 1.111 + ret += silk_setup_resamplers( psEnc, fs_kHz ); 1.112 + 1.113 + /********************************************/ 1.114 + /* Set internal sampling frequency */ 1.115 + /********************************************/ 1.116 + ret += silk_setup_fs( psEnc, fs_kHz, encControl->payloadSize_ms ); 1.117 + 1.118 + /********************************************/ 1.119 + /* Set encoding complexity */ 1.120 + /********************************************/ 1.121 + ret += silk_setup_complexity( &psEnc->sCmn, encControl->complexity ); 1.122 + 1.123 + /********************************************/ 1.124 + /* Set packet loss rate measured by farend */ 1.125 + /********************************************/ 1.126 + psEnc->sCmn.PacketLoss_perc = encControl->packetLossPercentage; 1.127 + 1.128 + /********************************************/ 1.129 + /* Set LBRR usage */ 1.130 + /********************************************/ 1.131 + ret += silk_setup_LBRR( &psEnc->sCmn, TargetRate_bps ); 1.132 + 1.133 + psEnc->sCmn.controlled_since_last_payload = 1; 1.134 + 1.135 + return ret; 1.136 +} 1.137 + 1.138 +static opus_int silk_setup_resamplers( 1.139 + silk_encoder_state_Fxx *psEnc, /* I/O */ 1.140 + opus_int fs_kHz /* I */ 1.141 +) 1.142 +{ 1.143 + opus_int ret = SILK_NO_ERROR; 1.144 + SAVE_STACK; 1.145 + 1.146 + if( psEnc->sCmn.fs_kHz != fs_kHz || psEnc->sCmn.prev_API_fs_Hz != psEnc->sCmn.API_fs_Hz ) 1.147 + { 1.148 + if( psEnc->sCmn.fs_kHz == 0 ) { 1.149 + /* Initialize the resampler for enc_API.c preparing resampling from API_fs_Hz to fs_kHz */ 1.150 + ret += silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCmn.API_fs_Hz, fs_kHz * 1000, 1 ); 1.151 + } else { 1.152 + VARDECL( opus_int16, x_buf_API_fs_Hz ); 1.153 + VARDECL( silk_resampler_state_struct, temp_resampler_state ); 1.154 +#ifdef FIXED_POINT 1.155 + opus_int16 *x_bufFIX = psEnc->x_buf; 1.156 +#else 1.157 + VARDECL( opus_int16, x_bufFIX ); 1.158 + opus_int32 new_buf_samples; 1.159 +#endif 1.160 + opus_int32 api_buf_samples; 1.161 + opus_int32 old_buf_samples; 1.162 + opus_int32 buf_length_ms; 1.163 + 1.164 + buf_length_ms = silk_LSHIFT( psEnc->sCmn.nb_subfr * 5, 1 ) + LA_SHAPE_MS; 1.165 + old_buf_samples = buf_length_ms * psEnc->sCmn.fs_kHz; 1.166 + 1.167 +#ifndef FIXED_POINT 1.168 + new_buf_samples = buf_length_ms * fs_kHz; 1.169 + ALLOC( x_bufFIX, silk_max( old_buf_samples, new_buf_samples ), 1.170 + opus_int16 ); 1.171 + silk_float2short_array( x_bufFIX, psEnc->x_buf, old_buf_samples ); 1.172 +#endif 1.173 + 1.174 + /* Initialize resampler for temporary resampling of x_buf data to API_fs_Hz */ 1.175 + ALLOC( temp_resampler_state, 1, silk_resampler_state_struct ); 1.176 + ret += silk_resampler_init( temp_resampler_state, silk_SMULBB( psEnc->sCmn.fs_kHz, 1000 ), psEnc->sCmn.API_fs_Hz, 0 ); 1.177 + 1.178 + /* Calculate number of samples to temporarily upsample */ 1.179 + api_buf_samples = buf_length_ms * silk_DIV32_16( psEnc->sCmn.API_fs_Hz, 1000 ); 1.180 + 1.181 + /* Temporary resampling of x_buf data to API_fs_Hz */ 1.182 + ALLOC( x_buf_API_fs_Hz, api_buf_samples, opus_int16 ); 1.183 + ret += silk_resampler( temp_resampler_state, x_buf_API_fs_Hz, x_bufFIX, old_buf_samples ); 1.184 + 1.185 + /* Initialize the resampler for enc_API.c preparing resampling from API_fs_Hz to fs_kHz */ 1.186 + ret += silk_resampler_init( &psEnc->sCmn.resampler_state, psEnc->sCmn.API_fs_Hz, silk_SMULBB( fs_kHz, 1000 ), 1 ); 1.187 + 1.188 + /* Correct resampler state by resampling buffered data from API_fs_Hz to fs_kHz */ 1.189 + ret += silk_resampler( &psEnc->sCmn.resampler_state, x_bufFIX, x_buf_API_fs_Hz, api_buf_samples ); 1.190 + 1.191 +#ifndef FIXED_POINT 1.192 + silk_short2float_array( psEnc->x_buf, x_bufFIX, new_buf_samples); 1.193 +#endif 1.194 + } 1.195 + } 1.196 + 1.197 + psEnc->sCmn.prev_API_fs_Hz = psEnc->sCmn.API_fs_Hz; 1.198 + 1.199 + RESTORE_STACK; 1.200 + return ret; 1.201 +} 1.202 + 1.203 +static opus_int silk_setup_fs( 1.204 + silk_encoder_state_Fxx *psEnc, /* I/O */ 1.205 + opus_int fs_kHz, /* I */ 1.206 + opus_int PacketSize_ms /* I */ 1.207 +) 1.208 +{ 1.209 + opus_int ret = SILK_NO_ERROR; 1.210 + 1.211 + /* Set packet size */ 1.212 + if( PacketSize_ms != psEnc->sCmn.PacketSize_ms ) { 1.213 + if( ( PacketSize_ms != 10 ) && 1.214 + ( PacketSize_ms != 20 ) && 1.215 + ( PacketSize_ms != 40 ) && 1.216 + ( PacketSize_ms != 60 ) ) { 1.217 + ret = SILK_ENC_PACKET_SIZE_NOT_SUPPORTED; 1.218 + } 1.219 + if( PacketSize_ms <= 10 ) { 1.220 + psEnc->sCmn.nFramesPerPacket = 1; 1.221 + psEnc->sCmn.nb_subfr = PacketSize_ms == 10 ? 2 : 1; 1.222 + psEnc->sCmn.frame_length = silk_SMULBB( PacketSize_ms, fs_kHz ); 1.223 + psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz ); 1.224 + if( psEnc->sCmn.fs_kHz == 8 ) { 1.225 + psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_10_ms_NB_iCDF; 1.226 + } else { 1.227 + psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_10_ms_iCDF; 1.228 + } 1.229 + } else { 1.230 + psEnc->sCmn.nFramesPerPacket = silk_DIV32_16( PacketSize_ms, MAX_FRAME_LENGTH_MS ); 1.231 + psEnc->sCmn.nb_subfr = MAX_NB_SUBFR; 1.232 + psEnc->sCmn.frame_length = silk_SMULBB( 20, fs_kHz ); 1.233 + psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz ); 1.234 + if( psEnc->sCmn.fs_kHz == 8 ) { 1.235 + psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_NB_iCDF; 1.236 + } else { 1.237 + psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_iCDF; 1.238 + } 1.239 + } 1.240 + psEnc->sCmn.PacketSize_ms = PacketSize_ms; 1.241 + psEnc->sCmn.TargetRate_bps = 0; /* trigger new SNR computation */ 1.242 + } 1.243 + 1.244 + /* Set internal sampling frequency */ 1.245 + silk_assert( fs_kHz == 8 || fs_kHz == 12 || fs_kHz == 16 ); 1.246 + silk_assert( psEnc->sCmn.nb_subfr == 2 || psEnc->sCmn.nb_subfr == 4 ); 1.247 + if( psEnc->sCmn.fs_kHz != fs_kHz ) { 1.248 + /* reset part of the state */ 1.249 + silk_memset( &psEnc->sShape, 0, sizeof( psEnc->sShape ) ); 1.250 + silk_memset( &psEnc->sPrefilt, 0, sizeof( psEnc->sPrefilt ) ); 1.251 + silk_memset( &psEnc->sCmn.sNSQ, 0, sizeof( psEnc->sCmn.sNSQ ) ); 1.252 + silk_memset( psEnc->sCmn.prev_NLSFq_Q15, 0, sizeof( psEnc->sCmn.prev_NLSFq_Q15 ) ); 1.253 + silk_memset( &psEnc->sCmn.sLP.In_LP_State, 0, sizeof( psEnc->sCmn.sLP.In_LP_State ) ); 1.254 + psEnc->sCmn.inputBufIx = 0; 1.255 + psEnc->sCmn.nFramesEncoded = 0; 1.256 + psEnc->sCmn.TargetRate_bps = 0; /* trigger new SNR computation */ 1.257 + 1.258 + /* Initialize non-zero parameters */ 1.259 + psEnc->sCmn.prevLag = 100; 1.260 + psEnc->sCmn.first_frame_after_reset = 1; 1.261 + psEnc->sPrefilt.lagPrev = 100; 1.262 + psEnc->sShape.LastGainIndex = 10; 1.263 + psEnc->sCmn.sNSQ.lagPrev = 100; 1.264 + psEnc->sCmn.sNSQ.prev_gain_Q16 = 65536; 1.265 + psEnc->sCmn.prevSignalType = TYPE_NO_VOICE_ACTIVITY; 1.266 + 1.267 + psEnc->sCmn.fs_kHz = fs_kHz; 1.268 + if( psEnc->sCmn.fs_kHz == 8 ) { 1.269 + if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) { 1.270 + psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_NB_iCDF; 1.271 + } else { 1.272 + psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_10_ms_NB_iCDF; 1.273 + } 1.274 + } else { 1.275 + if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) { 1.276 + psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_iCDF; 1.277 + } else { 1.278 + psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_10_ms_iCDF; 1.279 + } 1.280 + } 1.281 + if( psEnc->sCmn.fs_kHz == 8 || psEnc->sCmn.fs_kHz == 12 ) { 1.282 + psEnc->sCmn.predictLPCOrder = MIN_LPC_ORDER; 1.283 + psEnc->sCmn.psNLSF_CB = &silk_NLSF_CB_NB_MB; 1.284 + } else { 1.285 + psEnc->sCmn.predictLPCOrder = MAX_LPC_ORDER; 1.286 + psEnc->sCmn.psNLSF_CB = &silk_NLSF_CB_WB; 1.287 + } 1.288 + psEnc->sCmn.subfr_length = SUB_FRAME_LENGTH_MS * fs_kHz; 1.289 + psEnc->sCmn.frame_length = silk_SMULBB( psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr ); 1.290 + psEnc->sCmn.ltp_mem_length = silk_SMULBB( LTP_MEM_LENGTH_MS, fs_kHz ); 1.291 + psEnc->sCmn.la_pitch = silk_SMULBB( LA_PITCH_MS, fs_kHz ); 1.292 + psEnc->sCmn.max_pitch_lag = silk_SMULBB( 18, fs_kHz ); 1.293 + if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) { 1.294 + psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB( FIND_PITCH_LPC_WIN_MS, fs_kHz ); 1.295 + } else { 1.296 + psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB( FIND_PITCH_LPC_WIN_MS_2_SF, fs_kHz ); 1.297 + } 1.298 + if( psEnc->sCmn.fs_kHz == 16 ) { 1.299 + psEnc->sCmn.mu_LTP_Q9 = SILK_FIX_CONST( MU_LTP_QUANT_WB, 9 ); 1.300 + psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform8_iCDF; 1.301 + } else if( psEnc->sCmn.fs_kHz == 12 ) { 1.302 + psEnc->sCmn.mu_LTP_Q9 = SILK_FIX_CONST( MU_LTP_QUANT_MB, 9 ); 1.303 + psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform6_iCDF; 1.304 + } else { 1.305 + psEnc->sCmn.mu_LTP_Q9 = SILK_FIX_CONST( MU_LTP_QUANT_NB, 9 ); 1.306 + psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform4_iCDF; 1.307 + } 1.308 + } 1.309 + 1.310 + /* Check that settings are valid */ 1.311 + silk_assert( ( psEnc->sCmn.subfr_length * psEnc->sCmn.nb_subfr ) == psEnc->sCmn.frame_length ); 1.312 + 1.313 + return ret; 1.314 +} 1.315 + 1.316 +static opus_int silk_setup_complexity( 1.317 + silk_encoder_state *psEncC, /* I/O */ 1.318 + opus_int Complexity /* I */ 1.319 +) 1.320 +{ 1.321 + opus_int ret = 0; 1.322 + 1.323 + /* Set encoding complexity */ 1.324 + silk_assert( Complexity >= 0 && Complexity <= 10 ); 1.325 + if( Complexity < 2 ) { 1.326 + psEncC->pitchEstimationComplexity = SILK_PE_MIN_COMPLEX; 1.327 + psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.8, 16 ); 1.328 + psEncC->pitchEstimationLPCOrder = 6; 1.329 + psEncC->shapingLPCOrder = 8; 1.330 + psEncC->la_shape = 3 * psEncC->fs_kHz; 1.331 + psEncC->nStatesDelayedDecision = 1; 1.332 + psEncC->useInterpolatedNLSFs = 0; 1.333 + psEncC->LTPQuantLowComplexity = 1; 1.334 + psEncC->NLSF_MSVQ_Survivors = 2; 1.335 + psEncC->warping_Q16 = 0; 1.336 + } else if( Complexity < 4 ) { 1.337 + psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; 1.338 + psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.76, 16 ); 1.339 + psEncC->pitchEstimationLPCOrder = 8; 1.340 + psEncC->shapingLPCOrder = 10; 1.341 + psEncC->la_shape = 5 * psEncC->fs_kHz; 1.342 + psEncC->nStatesDelayedDecision = 1; 1.343 + psEncC->useInterpolatedNLSFs = 0; 1.344 + psEncC->LTPQuantLowComplexity = 0; 1.345 + psEncC->NLSF_MSVQ_Survivors = 4; 1.346 + psEncC->warping_Q16 = 0; 1.347 + } else if( Complexity < 6 ) { 1.348 + psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; 1.349 + psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.74, 16 ); 1.350 + psEncC->pitchEstimationLPCOrder = 10; 1.351 + psEncC->shapingLPCOrder = 12; 1.352 + psEncC->la_shape = 5 * psEncC->fs_kHz; 1.353 + psEncC->nStatesDelayedDecision = 2; 1.354 + psEncC->useInterpolatedNLSFs = 1; 1.355 + psEncC->LTPQuantLowComplexity = 0; 1.356 + psEncC->NLSF_MSVQ_Survivors = 8; 1.357 + psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONST( WARPING_MULTIPLIER, 16 ); 1.358 + } else if( Complexity < 8 ) { 1.359 + psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; 1.360 + psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.72, 16 ); 1.361 + psEncC->pitchEstimationLPCOrder = 12; 1.362 + psEncC->shapingLPCOrder = 14; 1.363 + psEncC->la_shape = 5 * psEncC->fs_kHz; 1.364 + psEncC->nStatesDelayedDecision = 3; 1.365 + psEncC->useInterpolatedNLSFs = 1; 1.366 + psEncC->LTPQuantLowComplexity = 0; 1.367 + psEncC->NLSF_MSVQ_Survivors = 16; 1.368 + psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONST( WARPING_MULTIPLIER, 16 ); 1.369 + } else { 1.370 + psEncC->pitchEstimationComplexity = SILK_PE_MAX_COMPLEX; 1.371 + psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.7, 16 ); 1.372 + psEncC->pitchEstimationLPCOrder = 16; 1.373 + psEncC->shapingLPCOrder = 16; 1.374 + psEncC->la_shape = 5 * psEncC->fs_kHz; 1.375 + psEncC->nStatesDelayedDecision = MAX_DEL_DEC_STATES; 1.376 + psEncC->useInterpolatedNLSFs = 1; 1.377 + psEncC->LTPQuantLowComplexity = 0; 1.378 + psEncC->NLSF_MSVQ_Survivors = 32; 1.379 + psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONST( WARPING_MULTIPLIER, 16 ); 1.380 + } 1.381 + 1.382 + /* Do not allow higher pitch estimation LPC order than predict LPC order */ 1.383 + psEncC->pitchEstimationLPCOrder = silk_min_int( psEncC->pitchEstimationLPCOrder, psEncC->predictLPCOrder ); 1.384 + psEncC->shapeWinLength = SUB_FRAME_LENGTH_MS * psEncC->fs_kHz + 2 * psEncC->la_shape; 1.385 + psEncC->Complexity = Complexity; 1.386 + 1.387 + silk_assert( psEncC->pitchEstimationLPCOrder <= MAX_FIND_PITCH_LPC_ORDER ); 1.388 + silk_assert( psEncC->shapingLPCOrder <= MAX_SHAPE_LPC_ORDER ); 1.389 + silk_assert( psEncC->nStatesDelayedDecision <= MAX_DEL_DEC_STATES ); 1.390 + silk_assert( psEncC->warping_Q16 <= 32767 ); 1.391 + silk_assert( psEncC->la_shape <= LA_SHAPE_MAX ); 1.392 + silk_assert( psEncC->shapeWinLength <= SHAPE_LPC_WIN_MAX ); 1.393 + silk_assert( psEncC->NLSF_MSVQ_Survivors <= NLSF_VQ_MAX_SURVIVORS ); 1.394 + 1.395 + return ret; 1.396 +} 1.397 + 1.398 +static OPUS_INLINE opus_int silk_setup_LBRR( 1.399 + silk_encoder_state *psEncC, /* I/O */ 1.400 + const opus_int32 TargetRate_bps /* I */ 1.401 +) 1.402 +{ 1.403 + opus_int ret = SILK_NO_ERROR; 1.404 + opus_int32 LBRR_rate_thres_bps; 1.405 + 1.406 + psEncC->LBRR_enabled = 0; 1.407 + if( psEncC->useInBandFEC && psEncC->PacketLoss_perc > 0 ) { 1.408 + if( psEncC->fs_kHz == 8 ) { 1.409 + LBRR_rate_thres_bps = LBRR_NB_MIN_RATE_BPS; 1.410 + } else if( psEncC->fs_kHz == 12 ) { 1.411 + LBRR_rate_thres_bps = LBRR_MB_MIN_RATE_BPS; 1.412 + } else { 1.413 + LBRR_rate_thres_bps = LBRR_WB_MIN_RATE_BPS; 1.414 + } 1.415 + LBRR_rate_thres_bps = silk_SMULWB( silk_MUL( LBRR_rate_thres_bps, 125 - silk_min( psEncC->PacketLoss_perc, 25 ) ), SILK_FIX_CONST( 0.01, 16 ) ); 1.416 + 1.417 + if( TargetRate_bps > LBRR_rate_thres_bps ) { 1.418 + /* Set gain increase for coding LBRR excitation */ 1.419 + psEncC->LBRR_enabled = 1; 1.420 + psEncC->LBRR_GainIncreases = silk_max_int( 7 - silk_SMULWB( (opus_int32)psEncC->PacketLoss_perc, SILK_FIX_CONST( 0.4, 16 ) ), 2 ); 1.421 + } 1.422 + } 1.423 + 1.424 + return ret; 1.425 +}