OLD | NEW |
1 /*********************************************************************** | 1 /*********************************************************************** |
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. | 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. |
3 Redistribution and use in source and binary forms, with or without | 3 Redistribution and use in source and binary forms, with or without |
4 modification, are permitted provided that the following conditions | 4 modification, are permitted provided that the following conditions |
5 are met: | 5 are met: |
6 - Redistributions of source code must retain the above copyright notice, | 6 - Redistributions of source code must retain the above copyright notice, |
7 this list of conditions and the following disclaimer. | 7 this list of conditions and the following disclaimer. |
8 - Redistributions in binary form must reproduce the above copyright | 8 - Redistributions in binary form must reproduce the above copyright |
9 notice, this list of conditions and the following disclaimer in the | 9 notice, this list of conditions and the following disclaimer in the |
10 documentation and/or other materials provided with the distribution. | 10 documentation and/or other materials provided with the distribution. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 opus_int PacketSize_ms /* I
*/ | 50 opus_int PacketSize_ms /* I
*/ |
51 ); | 51 ); |
52 | 52 |
53 static opus_int silk_setup_complexity( | 53 static opus_int silk_setup_complexity( |
54 silk_encoder_state *psEncC, /* I/O
*/ | 54 silk_encoder_state *psEncC, /* I/O
*/ |
55 opus_int Complexity /* I
*/ | 55 opus_int Complexity /* I
*/ |
56 ); | 56 ); |
57 | 57 |
58 static OPUS_INLINE opus_int silk_setup_LBRR( | 58 static OPUS_INLINE opus_int silk_setup_LBRR( |
59 silk_encoder_state *psEncC, /* I/O
*/ | 59 silk_encoder_state *psEncC, /* I/O
*/ |
60 const opus_int32 TargetRate_bps /* I
*/ | 60 const silk_EncControlStruct *encControl /* I
*/ |
61 ); | 61 ); |
62 | 62 |
63 | 63 |
64 /* Control encoder */ | 64 /* Control encoder */ |
65 opus_int silk_control_encoder( | 65 opus_int silk_control_encoder( |
66 silk_encoder_state_Fxx *psEnc, /* I
/O Pointer to Silk encoder state
*/ | 66 silk_encoder_state_Fxx *psEnc, /* I
/O Pointer to Silk encoder state
*/ |
67 silk_EncControlStruct *encControl, /* I
Control structure
*/ | 67 silk_EncControlStruct *encControl, /* I
Control structure
*/ |
68 const opus_int32 TargetRate_bps, /* I
Target max bitrate (bps)
*/ | |
69 const opus_int allow_bw_switch, /* I
Flag to allow switching audio bandwidth
*/ | 68 const opus_int allow_bw_switch, /* I
Flag to allow switching audio bandwidth
*/ |
70 const opus_int channelNb, /* I
Channel number
*/ | 69 const opus_int channelNb, /* I
Channel number
*/ |
71 const opus_int force_fs_kHz | 70 const opus_int force_fs_kHz |
72 ) | 71 ) |
73 { | 72 { |
74 opus_int fs_kHz, ret = 0; | 73 opus_int fs_kHz, ret = 0; |
75 | 74 |
76 psEnc->sCmn.useDTX = encControl->useDTX; | 75 psEnc->sCmn.useDTX = encControl->useDTX; |
77 psEnc->sCmn.useCBR = encControl->useCBR; | 76 psEnc->sCmn.useCBR = encControl->useCBR; |
78 psEnc->sCmn.API_fs_Hz = encControl->API_sampleRate; | 77 psEnc->sCmn.API_fs_Hz = encControl->API_sampleRate; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 ret += silk_setup_complexity( &psEnc->sCmn, encControl->complexity ); | 117 ret += silk_setup_complexity( &psEnc->sCmn, encControl->complexity ); |
119 | 118 |
120 /********************************************/ | 119 /********************************************/ |
121 /* Set packet loss rate measured by farend */ | 120 /* Set packet loss rate measured by farend */ |
122 /********************************************/ | 121 /********************************************/ |
123 psEnc->sCmn.PacketLoss_perc = encControl->packetLossPercentage; | 122 psEnc->sCmn.PacketLoss_perc = encControl->packetLossPercentage; |
124 | 123 |
125 /********************************************/ | 124 /********************************************/ |
126 /* Set LBRR usage */ | 125 /* Set LBRR usage */ |
127 /********************************************/ | 126 /********************************************/ |
128 ret += silk_setup_LBRR( &psEnc->sCmn, TargetRate_bps ); | 127 ret += silk_setup_LBRR( &psEnc->sCmn, encControl ); |
129 | 128 |
130 psEnc->sCmn.controlled_since_last_payload = 1; | 129 psEnc->sCmn.controlled_since_last_payload = 1; |
131 | 130 |
132 return ret; | 131 return ret; |
133 } | 132 } |
134 | 133 |
135 static opus_int silk_setup_resamplers( | 134 static opus_int silk_setup_resamplers( |
136 silk_encoder_state_Fxx *psEnc, /* I/O
*/ | 135 silk_encoder_state_Fxx *psEnc, /* I/O
*/ |
137 opus_int fs_kHz /* I
*/ | 136 opus_int fs_kHz /* I
*/ |
138 ) | 137 ) |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 psEnc->sCmn.PacketSize_ms = PacketSize_ms; | 236 psEnc->sCmn.PacketSize_ms = PacketSize_ms; |
238 psEnc->sCmn.TargetRate_bps = 0; /* trigger new SNR computation *
/ | 237 psEnc->sCmn.TargetRate_bps = 0; /* trigger new SNR computation *
/ |
239 } | 238 } |
240 | 239 |
241 /* Set internal sampling frequency */ | 240 /* Set internal sampling frequency */ |
242 silk_assert( fs_kHz == 8 || fs_kHz == 12 || fs_kHz == 16 ); | 241 silk_assert( fs_kHz == 8 || fs_kHz == 12 || fs_kHz == 16 ); |
243 silk_assert( psEnc->sCmn.nb_subfr == 2 || psEnc->sCmn.nb_subfr == 4 ); | 242 silk_assert( psEnc->sCmn.nb_subfr == 2 || psEnc->sCmn.nb_subfr == 4 ); |
244 if( psEnc->sCmn.fs_kHz != fs_kHz ) { | 243 if( psEnc->sCmn.fs_kHz != fs_kHz ) { |
245 /* reset part of the state */ | 244 /* reset part of the state */ |
246 silk_memset( &psEnc->sShape, 0, sizeof( psEnc->sShape ) ); | 245 silk_memset( &psEnc->sShape, 0, sizeof( psEnc->sShape ) ); |
247 silk_memset( &psEnc->sPrefilt, 0, sizeof( psEnc->sPrefilt )
); | |
248 silk_memset( &psEnc->sCmn.sNSQ, 0, sizeof( psEnc->sCmn.sNSQ )
); | 246 silk_memset( &psEnc->sCmn.sNSQ, 0, sizeof( psEnc->sCmn.sNSQ )
); |
249 silk_memset( psEnc->sCmn.prev_NLSFq_Q15, 0, sizeof( psEnc->sCmn.prev_N
LSFq_Q15 ) ); | 247 silk_memset( psEnc->sCmn.prev_NLSFq_Q15, 0, sizeof( psEnc->sCmn.prev_N
LSFq_Q15 ) ); |
250 silk_memset( &psEnc->sCmn.sLP.In_LP_State, 0, sizeof( psEnc->sCmn.sLP.In
_LP_State ) ); | 248 silk_memset( &psEnc->sCmn.sLP.In_LP_State, 0, sizeof( psEnc->sCmn.sLP.In
_LP_State ) ); |
251 psEnc->sCmn.inputBufIx = 0; | 249 psEnc->sCmn.inputBufIx = 0; |
252 psEnc->sCmn.nFramesEncoded = 0; | 250 psEnc->sCmn.nFramesEncoded = 0; |
253 psEnc->sCmn.TargetRate_bps = 0; /* trigger new SNR comp
utation */ | 251 psEnc->sCmn.TargetRate_bps = 0; /* trigger new SNR comp
utation */ |
254 | 252 |
255 /* Initialize non-zero parameters */ | 253 /* Initialize non-zero parameters */ |
256 psEnc->sCmn.prevLag = 100; | 254 psEnc->sCmn.prevLag = 100; |
257 psEnc->sCmn.first_frame_after_reset = 1; | 255 psEnc->sCmn.first_frame_after_reset = 1; |
258 psEnc->sPrefilt.lagPrev = 100; | |
259 psEnc->sShape.LastGainIndex = 10; | 256 psEnc->sShape.LastGainIndex = 10; |
260 psEnc->sCmn.sNSQ.lagPrev = 100; | 257 psEnc->sCmn.sNSQ.lagPrev = 100; |
261 psEnc->sCmn.sNSQ.prev_gain_Q16 = 65536; | 258 psEnc->sCmn.sNSQ.prev_gain_Q16 = 65536; |
262 psEnc->sCmn.prevSignalType = TYPE_NO_VOICE_ACTIVITY; | 259 psEnc->sCmn.prevSignalType = TYPE_NO_VOICE_ACTIVITY; |
263 | 260 |
264 psEnc->sCmn.fs_kHz = fs_kHz; | 261 psEnc->sCmn.fs_kHz = fs_kHz; |
265 if( psEnc->sCmn.fs_kHz == 8 ) { | 262 if( psEnc->sCmn.fs_kHz == 8 ) { |
266 if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) { | 263 if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) { |
267 psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_NB_iCDF; | 264 psEnc->sCmn.pitch_contour_iCDF = silk_pitch_contour_NB_iCDF; |
268 } else { | 265 } else { |
(...skipping 17 matching lines...) Expand all Loading... |
286 psEnc->sCmn.frame_length = silk_SMULBB( psEnc->sCmn.subfr_length, psEn
c->sCmn.nb_subfr ); | 283 psEnc->sCmn.frame_length = silk_SMULBB( psEnc->sCmn.subfr_length, psEn
c->sCmn.nb_subfr ); |
287 psEnc->sCmn.ltp_mem_length = silk_SMULBB( LTP_MEM_LENGTH_MS, fs_kHz ); | 284 psEnc->sCmn.ltp_mem_length = silk_SMULBB( LTP_MEM_LENGTH_MS, fs_kHz ); |
288 psEnc->sCmn.la_pitch = silk_SMULBB( LA_PITCH_MS, fs_kHz ); | 285 psEnc->sCmn.la_pitch = silk_SMULBB( LA_PITCH_MS, fs_kHz ); |
289 psEnc->sCmn.max_pitch_lag = silk_SMULBB( 18, fs_kHz ); | 286 psEnc->sCmn.max_pitch_lag = silk_SMULBB( 18, fs_kHz ); |
290 if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) { | 287 if( psEnc->sCmn.nb_subfr == MAX_NB_SUBFR ) { |
291 psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB( FIND_PITCH_LPC_WIN_M
S, fs_kHz ); | 288 psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB( FIND_PITCH_LPC_WIN_M
S, fs_kHz ); |
292 } else { | 289 } else { |
293 psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB( FIND_PITCH_LPC_WIN_M
S_2_SF, fs_kHz ); | 290 psEnc->sCmn.pitch_LPC_win_length = silk_SMULBB( FIND_PITCH_LPC_WIN_M
S_2_SF, fs_kHz ); |
294 } | 291 } |
295 if( psEnc->sCmn.fs_kHz == 16 ) { | 292 if( psEnc->sCmn.fs_kHz == 16 ) { |
296 psEnc->sCmn.mu_LTP_Q9 = SILK_FIX_CONST( MU_LTP_QUANT_WB, 9 ); | |
297 psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform8_iCDF; | 293 psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform8_iCDF; |
298 } else if( psEnc->sCmn.fs_kHz == 12 ) { | 294 } else if( psEnc->sCmn.fs_kHz == 12 ) { |
299 psEnc->sCmn.mu_LTP_Q9 = SILK_FIX_CONST( MU_LTP_QUANT_MB, 9 ); | |
300 psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform6_iCDF; | 295 psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform6_iCDF; |
301 } else { | 296 } else { |
302 psEnc->sCmn.mu_LTP_Q9 = SILK_FIX_CONST( MU_LTP_QUANT_NB, 9 ); | |
303 psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform4_iCDF; | 297 psEnc->sCmn.pitch_lag_low_bits_iCDF = silk_uniform4_iCDF; |
304 } | 298 } |
305 } | 299 } |
306 | 300 |
307 /* Check that settings are valid */ | 301 /* Check that settings are valid */ |
308 silk_assert( ( psEnc->sCmn.subfr_length * psEnc->sCmn.nb_subfr ) == psEnc->s
Cmn.frame_length ); | 302 silk_assert( ( psEnc->sCmn.subfr_length * psEnc->sCmn.nb_subfr ) == psEnc->s
Cmn.frame_length ); |
309 | 303 |
310 return ret; | 304 return ret; |
311 } | 305 } |
312 | 306 |
313 static opus_int silk_setup_complexity( | 307 static opus_int silk_setup_complexity( |
314 silk_encoder_state *psEncC, /* I/O
*/ | 308 silk_encoder_state *psEncC, /* I/O
*/ |
315 opus_int Complexity /* I
*/ | 309 opus_int Complexity /* I
*/ |
316 ) | 310 ) |
317 { | 311 { |
318 opus_int ret = 0; | 312 opus_int ret = 0; |
319 | 313 |
320 /* Set encoding complexity */ | 314 /* Set encoding complexity */ |
321 silk_assert( Complexity >= 0 && Complexity <= 10 ); | 315 silk_assert( Complexity >= 0 && Complexity <= 10 ); |
322 if( Complexity < 2 ) { | 316 if( Complexity < 1 ) { |
323 psEncC->pitchEstimationComplexity = SILK_PE_MIN_COMPLEX; | 317 psEncC->pitchEstimationComplexity = SILK_PE_MIN_COMPLEX; |
324 psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.8, 16 ); | 318 psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.8, 16 ); |
325 psEncC->pitchEstimationLPCOrder = 6; | 319 psEncC->pitchEstimationLPCOrder = 6; |
326 psEncC->shapingLPCOrder = 8; | 320 psEncC->shapingLPCOrder = 12; |
327 psEncC->la_shape = 3 * psEncC->fs_kHz; | 321 psEncC->la_shape = 3 * psEncC->fs_kHz; |
328 psEncC->nStatesDelayedDecision = 1; | 322 psEncC->nStatesDelayedDecision = 1; |
329 psEncC->useInterpolatedNLSFs = 0; | 323 psEncC->useInterpolatedNLSFs = 0; |
330 psEncC->LTPQuantLowComplexity = 1; | 324 psEncC->NLSF_MSVQ_Survivors = 2; |
| 325 psEncC->warping_Q16 = 0; |
| 326 } else if( Complexity < 2 ) { |
| 327 psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; |
| 328 psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.76, 16 ); |
| 329 psEncC->pitchEstimationLPCOrder = 8; |
| 330 psEncC->shapingLPCOrder = 14; |
| 331 psEncC->la_shape = 5 * psEncC->fs_kHz; |
| 332 psEncC->nStatesDelayedDecision = 1; |
| 333 psEncC->useInterpolatedNLSFs = 0; |
| 334 psEncC->NLSF_MSVQ_Survivors = 3; |
| 335 psEncC->warping_Q16 = 0; |
| 336 } else if( Complexity < 3 ) { |
| 337 psEncC->pitchEstimationComplexity = SILK_PE_MIN_COMPLEX; |
| 338 psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.8, 16 ); |
| 339 psEncC->pitchEstimationLPCOrder = 6; |
| 340 psEncC->shapingLPCOrder = 12; |
| 341 psEncC->la_shape = 3 * psEncC->fs_kHz; |
| 342 psEncC->nStatesDelayedDecision = 2; |
| 343 psEncC->useInterpolatedNLSFs = 0; |
331 psEncC->NLSF_MSVQ_Survivors = 2; | 344 psEncC->NLSF_MSVQ_Survivors = 2; |
332 psEncC->warping_Q16 = 0; | 345 psEncC->warping_Q16 = 0; |
333 } else if( Complexity < 4 ) { | 346 } else if( Complexity < 4 ) { |
334 psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; | 347 psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; |
335 psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.76, 16 ); | 348 psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.76, 16 ); |
336 psEncC->pitchEstimationLPCOrder = 8; | 349 psEncC->pitchEstimationLPCOrder = 8; |
337 psEncC->shapingLPCOrder = 10; | 350 psEncC->shapingLPCOrder = 14; |
338 psEncC->la_shape = 5 * psEncC->fs_kHz; | 351 psEncC->la_shape = 5 * psEncC->fs_kHz; |
339 psEncC->nStatesDelayedDecision = 1; | 352 psEncC->nStatesDelayedDecision = 2; |
340 psEncC->useInterpolatedNLSFs = 0; | 353 psEncC->useInterpolatedNLSFs = 0; |
341 psEncC->LTPQuantLowComplexity = 0; | |
342 psEncC->NLSF_MSVQ_Survivors = 4; | 354 psEncC->NLSF_MSVQ_Survivors = 4; |
343 psEncC->warping_Q16 = 0; | 355 psEncC->warping_Q16 = 0; |
344 } else if( Complexity < 6 ) { | 356 } else if( Complexity < 6 ) { |
345 psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; | 357 psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; |
346 psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.74, 16 ); | 358 psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.74, 16 ); |
347 psEncC->pitchEstimationLPCOrder = 10; | 359 psEncC->pitchEstimationLPCOrder = 10; |
348 psEncC->shapingLPCOrder = 12; | 360 psEncC->shapingLPCOrder = 16; |
349 psEncC->la_shape = 5 * psEncC->fs_kHz; | 361 psEncC->la_shape = 5 * psEncC->fs_kHz; |
350 psEncC->nStatesDelayedDecision = 2; | 362 psEncC->nStatesDelayedDecision = 2; |
351 psEncC->useInterpolatedNLSFs = 1; | 363 psEncC->useInterpolatedNLSFs = 1; |
352 psEncC->LTPQuantLowComplexity = 0; | 364 psEncC->NLSF_MSVQ_Survivors = 6; |
353 psEncC->NLSF_MSVQ_Survivors = 8; | |
354 psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONS
T( WARPING_MULTIPLIER, 16 ); | 365 psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONS
T( WARPING_MULTIPLIER, 16 ); |
355 } else if( Complexity < 8 ) { | 366 } else if( Complexity < 8 ) { |
356 psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; | 367 psEncC->pitchEstimationComplexity = SILK_PE_MID_COMPLEX; |
357 psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.72, 16 ); | 368 psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.72, 16 ); |
358 psEncC->pitchEstimationLPCOrder = 12; | 369 psEncC->pitchEstimationLPCOrder = 12; |
359 psEncC->shapingLPCOrder = 14; | 370 psEncC->shapingLPCOrder = 20; |
360 psEncC->la_shape = 5 * psEncC->fs_kHz; | 371 psEncC->la_shape = 5 * psEncC->fs_kHz; |
361 psEncC->nStatesDelayedDecision = 3; | 372 psEncC->nStatesDelayedDecision = 3; |
362 psEncC->useInterpolatedNLSFs = 1; | 373 psEncC->useInterpolatedNLSFs = 1; |
363 psEncC->LTPQuantLowComplexity = 0; | 374 psEncC->NLSF_MSVQ_Survivors = 8; |
364 psEncC->NLSF_MSVQ_Survivors = 16; | |
365 psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONS
T( WARPING_MULTIPLIER, 16 ); | 375 psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONS
T( WARPING_MULTIPLIER, 16 ); |
366 } else { | 376 } else { |
367 psEncC->pitchEstimationComplexity = SILK_PE_MAX_COMPLEX; | 377 psEncC->pitchEstimationComplexity = SILK_PE_MAX_COMPLEX; |
368 psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.7, 16 ); | 378 psEncC->pitchEstimationThreshold_Q16 = SILK_FIX_CONST( 0.7, 16 ); |
369 psEncC->pitchEstimationLPCOrder = 16; | 379 psEncC->pitchEstimationLPCOrder = 16; |
370 psEncC->shapingLPCOrder = 16; | 380 psEncC->shapingLPCOrder = 24; |
371 psEncC->la_shape = 5 * psEncC->fs_kHz; | 381 psEncC->la_shape = 5 * psEncC->fs_kHz; |
372 psEncC->nStatesDelayedDecision = MAX_DEL_DEC_STATES; | 382 psEncC->nStatesDelayedDecision = MAX_DEL_DEC_STATES; |
373 psEncC->useInterpolatedNLSFs = 1; | 383 psEncC->useInterpolatedNLSFs = 1; |
374 psEncC->LTPQuantLowComplexity = 0; | 384 psEncC->NLSF_MSVQ_Survivors = 16; |
375 psEncC->NLSF_MSVQ_Survivors = 32; | |
376 psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONS
T( WARPING_MULTIPLIER, 16 ); | 385 psEncC->warping_Q16 = psEncC->fs_kHz * SILK_FIX_CONS
T( WARPING_MULTIPLIER, 16 ); |
377 } | 386 } |
378 | 387 |
379 /* Do not allow higher pitch estimation LPC order than predict LPC order */ | 388 /* Do not allow higher pitch estimation LPC order than predict LPC order */ |
380 psEncC->pitchEstimationLPCOrder = silk_min_int( psEncC->pitchEstimationLPCOr
der, psEncC->predictLPCOrder ); | 389 psEncC->pitchEstimationLPCOrder = silk_min_int( psEncC->pitchEstimationLPCOr
der, psEncC->predictLPCOrder ); |
381 psEncC->shapeWinLength = SUB_FRAME_LENGTH_MS * psEncC->fs_kHz + 2 *
psEncC->la_shape; | 390 psEncC->shapeWinLength = SUB_FRAME_LENGTH_MS * psEncC->fs_kHz + 2 *
psEncC->la_shape; |
382 psEncC->Complexity = Complexity; | 391 psEncC->Complexity = Complexity; |
383 | 392 |
384 silk_assert( psEncC->pitchEstimationLPCOrder <= MAX_FIND_PITCH_LPC_ORDER ); | 393 silk_assert( psEncC->pitchEstimationLPCOrder <= MAX_FIND_PITCH_LPC_ORDER ); |
385 silk_assert( psEncC->shapingLPCOrder <= MAX_SHAPE_LPC_ORDER ); | 394 silk_assert( psEncC->shapingLPCOrder <= MAX_SHAPE_LPC_ORDER ); |
386 silk_assert( psEncC->nStatesDelayedDecision <= MAX_DEL_DEC_STATES ); | 395 silk_assert( psEncC->nStatesDelayedDecision <= MAX_DEL_DEC_STATES ); |
387 silk_assert( psEncC->warping_Q16 <= 32767 ); | 396 silk_assert( psEncC->warping_Q16 <= 32767 ); |
388 silk_assert( psEncC->la_shape <= LA_SHAPE_MAX ); | 397 silk_assert( psEncC->la_shape <= LA_SHAPE_MAX ); |
389 silk_assert( psEncC->shapeWinLength <= SHAPE_LPC_WIN_MAX ); | 398 silk_assert( psEncC->shapeWinLength <= SHAPE_LPC_WIN_MAX ); |
390 silk_assert( psEncC->NLSF_MSVQ_Survivors <= NLSF_VQ_MAX_SURVIVORS ); | |
391 | 399 |
392 return ret; | 400 return ret; |
393 } | 401 } |
394 | 402 |
395 static OPUS_INLINE opus_int silk_setup_LBRR( | 403 static OPUS_INLINE opus_int silk_setup_LBRR( |
396 silk_encoder_state *psEncC, /* I/O
*/ | 404 silk_encoder_state *psEncC, /* I/O
*/ |
397 const opus_int32 TargetRate_bps /* I
*/ | 405 const silk_EncControlStruct *encControl /* I
*/ |
398 ) | 406 ) |
399 { | 407 { |
400 opus_int LBRR_in_previous_packet, ret = SILK_NO_ERROR; | 408 opus_int LBRR_in_previous_packet, ret = SILK_NO_ERROR; |
401 opus_int32 LBRR_rate_thres_bps; | |
402 | 409 |
403 LBRR_in_previous_packet = psEncC->LBRR_enabled; | 410 LBRR_in_previous_packet = psEncC->LBRR_enabled; |
404 psEncC->LBRR_enabled = 0; | 411 psEncC->LBRR_enabled = encControl->LBRR_coded; |
405 if( psEncC->useInBandFEC && psEncC->PacketLoss_perc > 0 ) { | 412 if( psEncC->LBRR_enabled ) { |
406 if( psEncC->fs_kHz == 8 ) { | 413 /* Set gain increase for coding LBRR excitation */ |
407 LBRR_rate_thres_bps = LBRR_NB_MIN_RATE_BPS; | 414 if( LBRR_in_previous_packet == 0 ) { |
408 } else if( psEncC->fs_kHz == 12 ) { | 415 /* Previous packet did not have LBRR, and was therefore coded at a h
igher bitrate */ |
409 LBRR_rate_thres_bps = LBRR_MB_MIN_RATE_BPS; | 416 psEncC->LBRR_GainIncreases = 7; |
410 } else { | 417 } else { |
411 LBRR_rate_thres_bps = LBRR_WB_MIN_RATE_BPS; | 418 psEncC->LBRR_GainIncreases = silk_max_int( 7 - silk_SMULWB( (opus_in
t32)psEncC->PacketLoss_perc, SILK_FIX_CONST( 0.4, 16 ) ), 2 ); |
412 } | |
413 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 ) ); | |
414 | |
415 if( TargetRate_bps > LBRR_rate_thres_bps ) { | |
416 /* Set gain increase for coding LBRR excitation */ | |
417 if( LBRR_in_previous_packet == 0 ) { | |
418 /* Previous packet did not have LBRR, and was therefore coded at
a higher bitrate */ | |
419 psEncC->LBRR_GainIncreases = 7; | |
420 } else { | |
421 psEncC->LBRR_GainIncreases = silk_max_int( 7 - silk_SMULWB( (opu
s_int32)psEncC->PacketLoss_perc, SILK_FIX_CONST( 0.4, 16 ) ), 2 ); | |
422 } | |
423 psEncC->LBRR_enabled = 1; | |
424 } | 419 } |
425 } | 420 } |
426 | 421 |
427 return ret; | 422 return ret; |
428 } | 423 } |
OLD | NEW |