mirror of
https://github.com/xiph/opus.git
synced 2025-05-25 20:59:13 +00:00
Hardening asserts for SILK float
This commit is contained in:
parent
7e3352ef51
commit
e69fc1995e
11 changed files with 32 additions and 32 deletions
|
@ -215,7 +215,7 @@ void silk_LPC_analysis_filter_FLP(
|
||||||
const opus_int Order /* I LPC order */
|
const opus_int Order /* I LPC order */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
silk_assert( Order <= length );
|
celt_assert( Order <= length );
|
||||||
|
|
||||||
switch( Order ) {
|
switch( Order ) {
|
||||||
case 6:
|
case 6:
|
||||||
|
@ -239,7 +239,7 @@ void silk_LPC_analysis_filter_FLP(
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
silk_assert( 0 );
|
celt_assert( 0 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,10 +45,10 @@ void silk_apply_sine_window_FLP(
|
||||||
opus_int k;
|
opus_int k;
|
||||||
silk_float freq, c, S0, S1;
|
silk_float freq, c, S0, S1;
|
||||||
|
|
||||||
silk_assert( win_type == 1 || win_type == 2 );
|
celt_assert( win_type == 1 || win_type == 2 );
|
||||||
|
|
||||||
/* Length must be multiple of 4 */
|
/* Length must be multiple of 4 */
|
||||||
silk_assert( ( length & 3 ) == 0 );
|
celt_assert( ( length & 3 ) == 0 );
|
||||||
|
|
||||||
freq = PI / ( length + 1 );
|
freq = PI / ( length + 1 );
|
||||||
|
|
||||||
|
|
|
@ -241,7 +241,7 @@ opus_int silk_encode_frame_FLP(
|
||||||
if( found_lower && ( gainsID == gainsID_lower || nBits > maxBits ) ) {
|
if( found_lower && ( gainsID == gainsID_lower || nBits > maxBits ) ) {
|
||||||
/* Restore output state from earlier iteration that did meet the bitrate budget */
|
/* Restore output state from earlier iteration that did meet the bitrate budget */
|
||||||
silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc ) );
|
silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc ) );
|
||||||
silk_assert( sRangeEnc_copy2.offs <= 1275 );
|
celt_assert( sRangeEnc_copy2.offs <= 1275 );
|
||||||
silk_memcpy( psRangeEnc->buf, ec_buf_copy, sRangeEnc_copy2.offs );
|
silk_memcpy( psRangeEnc->buf, ec_buf_copy, sRangeEnc_copy2.offs );
|
||||||
silk_memcpy( &psEnc->sCmn.sNSQ, &sNSQ_copy2, sizeof( silk_nsq_state ) );
|
silk_memcpy( &psEnc->sCmn.sNSQ, &sNSQ_copy2, sizeof( silk_nsq_state ) );
|
||||||
psEnc->sShape.LastGainIndex = LastGainIndex_copy2;
|
psEnc->sShape.LastGainIndex = LastGainIndex_copy2;
|
||||||
|
@ -271,7 +271,7 @@ opus_int silk_encode_frame_FLP(
|
||||||
gainsID_lower = gainsID;
|
gainsID_lower = gainsID;
|
||||||
/* Copy part of the output state */
|
/* Copy part of the output state */
|
||||||
silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc ) );
|
silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc ) );
|
||||||
silk_assert( psRangeEnc->offs <= 1275 );
|
celt_assert( psRangeEnc->offs <= 1275 );
|
||||||
silk_memcpy( ec_buf_copy, psRangeEnc->buf, psRangeEnc->offs );
|
silk_memcpy( ec_buf_copy, psRangeEnc->buf, psRangeEnc->offs );
|
||||||
silk_memcpy( &sNSQ_copy2, &psEnc->sCmn.sNSQ, sizeof( silk_nsq_state ) );
|
silk_memcpy( &sNSQ_copy2, &psEnc->sCmn.sNSQ, sizeof( silk_nsq_state ) );
|
||||||
LastGainIndex_copy2 = psEnc->sShape.LastGainIndex;
|
LastGainIndex_copy2 = psEnc->sShape.LastGainIndex;
|
||||||
|
|
|
@ -99,6 +99,6 @@ void silk_find_LPC_FLP(
|
||||||
silk_A2NLSF_FLP( NLSF_Q15, a, psEncC->predictLPCOrder );
|
silk_A2NLSF_FLP( NLSF_Q15, a, psEncC->predictLPCOrder );
|
||||||
}
|
}
|
||||||
|
|
||||||
silk_assert( psEncC->indices.NLSFInterpCoef_Q2 == 4 ||
|
celt_assert( psEncC->indices.NLSFInterpCoef_Q2 == 4 ||
|
||||||
( psEncC->useInterpolatedNLSFs && !psEncC->first_frame_after_reset && psEncC->nb_subfr == MAX_NB_SUBFR ) );
|
( psEncC->useInterpolatedNLSFs && !psEncC->first_frame_after_reset && psEncC->nb_subfr == MAX_NB_SUBFR ) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ void silk_find_pitch_lags_FLP(
|
||||||
buf_len = psEnc->sCmn.la_pitch + psEnc->sCmn.frame_length + psEnc->sCmn.ltp_mem_length;
|
buf_len = psEnc->sCmn.la_pitch + psEnc->sCmn.frame_length + psEnc->sCmn.ltp_mem_length;
|
||||||
|
|
||||||
/* Safety check */
|
/* Safety check */
|
||||||
silk_assert( buf_len >= psEnc->sCmn.pitch_LPC_win_length );
|
celt_assert( buf_len >= psEnc->sCmn.pitch_LPC_win_length );
|
||||||
|
|
||||||
x_buf = x - psEnc->sCmn.ltp_mem_length;
|
x_buf = x - psEnc->sCmn.ltp_mem_length;
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ void silk_find_pred_coefs_FLP(
|
||||||
/**********/
|
/**********/
|
||||||
/* VOICED */
|
/* VOICED */
|
||||||
/**********/
|
/**********/
|
||||||
silk_assert( psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->pitchL[ 0 ] + LTP_ORDER / 2 );
|
celt_assert( psEnc->sCmn.ltp_mem_length - psEnc->sCmn.predictLPCOrder >= psEncCtrl->pitchL[ 0 ] + LTP_ORDER / 2 );
|
||||||
|
|
||||||
/* LTP analysis */
|
/* LTP analysis */
|
||||||
silk_find_LTP_FLP( XXLTP, xXLTP, res_pitch, psEncCtrl->pitchL, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr );
|
silk_find_LTP_FLP( XXLTP, xXLTP, res_pitch, psEncCtrl->pitchL, psEnc->sCmn.subfr_length, psEnc->sCmn.nb_subfr );
|
||||||
|
|
|
@ -109,11 +109,11 @@ opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced,
|
||||||
const opus_int8 *Lag_CB_ptr;
|
const opus_int8 *Lag_CB_ptr;
|
||||||
|
|
||||||
/* Check for valid sampling frequency */
|
/* Check for valid sampling frequency */
|
||||||
silk_assert( Fs_kHz == 8 || Fs_kHz == 12 || Fs_kHz == 16 );
|
celt_assert( Fs_kHz == 8 || Fs_kHz == 12 || Fs_kHz == 16 );
|
||||||
|
|
||||||
/* Check for valid complexity setting */
|
/* Check for valid complexity setting */
|
||||||
silk_assert( complexity >= SILK_PE_MIN_COMPLEX );
|
celt_assert( complexity >= SILK_PE_MIN_COMPLEX );
|
||||||
silk_assert( complexity <= SILK_PE_MAX_COMPLEX );
|
celt_assert( complexity <= SILK_PE_MAX_COMPLEX );
|
||||||
|
|
||||||
silk_assert( search_thres1 >= 0.0f && search_thres1 <= 1.0f );
|
silk_assert( search_thres1 >= 0.0f && search_thres1 <= 1.0f );
|
||||||
silk_assert( search_thres2 >= 0.0f && search_thres2 <= 1.0f );
|
silk_assert( search_thres2 >= 0.0f && search_thres2 <= 1.0f );
|
||||||
|
@ -148,7 +148,7 @@ opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced,
|
||||||
silk_resampler_down2_3( filt_state, frame_8_FIX, frame_12_FIX, frame_length );
|
silk_resampler_down2_3( filt_state, frame_8_FIX, frame_12_FIX, frame_length );
|
||||||
silk_short2float_array( frame_8kHz, frame_8_FIX, frame_length_8kHz );
|
silk_short2float_array( frame_8kHz, frame_8_FIX, frame_length_8kHz );
|
||||||
} else {
|
} else {
|
||||||
silk_assert( Fs_kHz == 8 );
|
celt_assert( Fs_kHz == 8 );
|
||||||
silk_float2short_array( frame_8_FIX, frame, frame_length_8kHz );
|
silk_float2short_array( frame_8_FIX, frame, frame_length_8kHz );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,14 +169,14 @@ opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced,
|
||||||
target_ptr = &frame_4kHz[ silk_LSHIFT( sf_length_4kHz, 2 ) ];
|
target_ptr = &frame_4kHz[ silk_LSHIFT( sf_length_4kHz, 2 ) ];
|
||||||
for( k = 0; k < nb_subfr >> 1; k++ ) {
|
for( k = 0; k < nb_subfr >> 1; k++ ) {
|
||||||
/* Check that we are within range of the array */
|
/* Check that we are within range of the array */
|
||||||
silk_assert( target_ptr >= frame_4kHz );
|
celt_assert( target_ptr >= frame_4kHz );
|
||||||
silk_assert( target_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4kHz );
|
celt_assert( target_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4kHz );
|
||||||
|
|
||||||
basis_ptr = target_ptr - min_lag_4kHz;
|
basis_ptr = target_ptr - min_lag_4kHz;
|
||||||
|
|
||||||
/* Check that we are within range of the array */
|
/* Check that we are within range of the array */
|
||||||
silk_assert( basis_ptr >= frame_4kHz );
|
celt_assert( basis_ptr >= frame_4kHz );
|
||||||
silk_assert( basis_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4kHz );
|
celt_assert( basis_ptr + sf_length_8kHz <= frame_4kHz + frame_length_4kHz );
|
||||||
|
|
||||||
celt_pitch_xcorr( target_ptr, target_ptr-max_lag_4kHz, xcorr, sf_length_8kHz, max_lag_4kHz - min_lag_4kHz + 1, arch );
|
celt_pitch_xcorr( target_ptr, target_ptr-max_lag_4kHz, xcorr, sf_length_8kHz, max_lag_4kHz - min_lag_4kHz + 1, arch );
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced,
|
||||||
|
|
||||||
/* Sort */
|
/* Sort */
|
||||||
length_d_srch = 4 + 2 * complexity;
|
length_d_srch = 4 + 2 * complexity;
|
||||||
silk_assert( 3 * length_d_srch <= PE_D_SRCH_LENGTH );
|
celt_assert( 3 * length_d_srch <= PE_D_SRCH_LENGTH );
|
||||||
silk_insertion_sort_decreasing_FLP( &C[ 0 ][ min_lag_4kHz ], d_srch, max_lag_4kHz - min_lag_4kHz + 1, length_d_srch );
|
silk_insertion_sort_decreasing_FLP( &C[ 0 ][ min_lag_4kHz ], d_srch, max_lag_4kHz - min_lag_4kHz + 1, length_d_srch );
|
||||||
|
|
||||||
/* Escape if correlation is very low already here */
|
/* Escape if correlation is very low already here */
|
||||||
|
@ -238,7 +238,7 @@ opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
silk_assert( length_d_srch > 0 );
|
celt_assert( length_d_srch > 0 );
|
||||||
|
|
||||||
for( i = min_lag_8kHz - 5; i < max_lag_8kHz + 5; i++ ) {
|
for( i = min_lag_8kHz - 5; i < max_lag_8kHz + 5; i++ ) {
|
||||||
d_comp[ i ] = 0;
|
d_comp[ i ] = 0;
|
||||||
|
@ -471,7 +471,7 @@ opus_int silk_pitch_analysis_core_FLP( /* O Voicing estimate: 0 voiced,
|
||||||
*lagIndex = (opus_int16)( lag - min_lag_8kHz );
|
*lagIndex = (opus_int16)( lag - min_lag_8kHz );
|
||||||
*contourIndex = (opus_int8)CBimax;
|
*contourIndex = (opus_int8)CBimax;
|
||||||
}
|
}
|
||||||
silk_assert( *lagIndex >= 0 );
|
celt_assert( *lagIndex >= 0 );
|
||||||
/* return as voiced */
|
/* return as voiced */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -506,8 +506,8 @@ static void silk_P_Ana_calc_corr_st3(
|
||||||
opus_val32 xcorr[ SCRATCH_SIZE ];
|
opus_val32 xcorr[ SCRATCH_SIZE ];
|
||||||
const opus_int8 *Lag_range_ptr, *Lag_CB_ptr;
|
const opus_int8 *Lag_range_ptr, *Lag_CB_ptr;
|
||||||
|
|
||||||
silk_assert( complexity >= SILK_PE_MIN_COMPLEX );
|
celt_assert( complexity >= SILK_PE_MIN_COMPLEX );
|
||||||
silk_assert( complexity <= SILK_PE_MAX_COMPLEX );
|
celt_assert( complexity <= SILK_PE_MAX_COMPLEX );
|
||||||
|
|
||||||
if( nb_subfr == PE_MAX_NB_SUBFR ) {
|
if( nb_subfr == PE_MAX_NB_SUBFR ) {
|
||||||
Lag_range_ptr = &silk_Lag_range_stage3[ complexity ][ 0 ][ 0 ];
|
Lag_range_ptr = &silk_Lag_range_stage3[ complexity ][ 0 ][ 0 ];
|
||||||
|
@ -515,7 +515,7 @@ static void silk_P_Ana_calc_corr_st3(
|
||||||
nb_cbk_search = silk_nb_cbk_searchs_stage3[ complexity ];
|
nb_cbk_search = silk_nb_cbk_searchs_stage3[ complexity ];
|
||||||
cbk_size = PE_NB_CBKS_STAGE3_MAX;
|
cbk_size = PE_NB_CBKS_STAGE3_MAX;
|
||||||
} else {
|
} else {
|
||||||
silk_assert( nb_subfr == PE_MAX_NB_SUBFR >> 1);
|
celt_assert( nb_subfr == PE_MAX_NB_SUBFR >> 1);
|
||||||
Lag_range_ptr = &silk_Lag_range_stage3_10_ms[ 0 ][ 0 ];
|
Lag_range_ptr = &silk_Lag_range_stage3_10_ms[ 0 ][ 0 ];
|
||||||
Lag_CB_ptr = &silk_CB_lags_stage3_10_ms[ 0 ][ 0 ];
|
Lag_CB_ptr = &silk_CB_lags_stage3_10_ms[ 0 ][ 0 ];
|
||||||
nb_cbk_search = PE_NB_CBKS_STAGE3_10MS;
|
nb_cbk_search = PE_NB_CBKS_STAGE3_10MS;
|
||||||
|
@ -572,8 +572,8 @@ static void silk_P_Ana_calc_energy_st3(
|
||||||
silk_float scratch_mem[ SCRATCH_SIZE ];
|
silk_float scratch_mem[ SCRATCH_SIZE ];
|
||||||
const opus_int8 *Lag_range_ptr, *Lag_CB_ptr;
|
const opus_int8 *Lag_range_ptr, *Lag_CB_ptr;
|
||||||
|
|
||||||
silk_assert( complexity >= SILK_PE_MIN_COMPLEX );
|
celt_assert( complexity >= SILK_PE_MIN_COMPLEX );
|
||||||
silk_assert( complexity <= SILK_PE_MAX_COMPLEX );
|
celt_assert( complexity <= SILK_PE_MAX_COMPLEX );
|
||||||
|
|
||||||
if( nb_subfr == PE_MAX_NB_SUBFR ) {
|
if( nb_subfr == PE_MAX_NB_SUBFR ) {
|
||||||
Lag_range_ptr = &silk_Lag_range_stage3[ complexity ][ 0 ][ 0 ];
|
Lag_range_ptr = &silk_Lag_range_stage3[ complexity ][ 0 ][ 0 ];
|
||||||
|
@ -581,7 +581,7 @@ static void silk_P_Ana_calc_energy_st3(
|
||||||
nb_cbk_search = silk_nb_cbk_searchs_stage3[ complexity ];
|
nb_cbk_search = silk_nb_cbk_searchs_stage3[ complexity ];
|
||||||
cbk_size = PE_NB_CBKS_STAGE3_MAX;
|
cbk_size = PE_NB_CBKS_STAGE3_MAX;
|
||||||
} else {
|
} else {
|
||||||
silk_assert( nb_subfr == PE_MAX_NB_SUBFR >> 1);
|
celt_assert( nb_subfr == PE_MAX_NB_SUBFR >> 1);
|
||||||
Lag_range_ptr = &silk_Lag_range_stage3_10_ms[ 0 ][ 0 ];
|
Lag_range_ptr = &silk_Lag_range_stage3_10_ms[ 0 ][ 0 ];
|
||||||
Lag_CB_ptr = &silk_CB_lags_stage3_10_ms[ 0 ][ 0 ];
|
Lag_CB_ptr = &silk_CB_lags_stage3_10_ms[ 0 ][ 0 ];
|
||||||
nb_cbk_search = PE_NB_CBKS_STAGE3_10MS;
|
nb_cbk_search = PE_NB_CBKS_STAGE3_10MS;
|
||||||
|
|
|
@ -47,7 +47,7 @@ silk_float silk_residual_energy_covar_FLP( /* O
|
||||||
silk_float tmp, nrg = 0.0f, regularization;
|
silk_float tmp, nrg = 0.0f, regularization;
|
||||||
|
|
||||||
/* Safety checks */
|
/* Safety checks */
|
||||||
silk_assert( D >= 0 );
|
celt_assert( D >= 0 );
|
||||||
|
|
||||||
regularization = REGULARIZATION_FACTOR * ( wXX[ 0 ] + wXX[ D * D - 1 ] );
|
regularization = REGULARIZATION_FACTOR * ( wXX[ 0 ] + wXX[ D * D - 1 ] );
|
||||||
for( k = 0; k < MAX_ITERATIONS_RESIDUAL_NRG; k++ ) {
|
for( k = 0; k < MAX_ITERATIONS_RESIDUAL_NRG; k++ ) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ silk_float silk_schur_FLP( /* O returns residual energy
|
||||||
double C[ SILK_MAX_ORDER_LPC + 1 ][ 2 ];
|
double C[ SILK_MAX_ORDER_LPC + 1 ][ 2 ];
|
||||||
double Ctmp1, Ctmp2, rc_tmp;
|
double Ctmp1, Ctmp2, rc_tmp;
|
||||||
|
|
||||||
silk_assert( order >= 0 && order <= SILK_MAX_ORDER_LPC );
|
celt_assert( order >= 0 && order <= SILK_MAX_ORDER_LPC );
|
||||||
|
|
||||||
/* Copy correlations */
|
/* Copy correlations */
|
||||||
k = 0;
|
k = 0;
|
||||||
|
|
|
@ -47,9 +47,9 @@ void silk_insertion_sort_decreasing_FLP(
|
||||||
opus_int i, j;
|
opus_int i, j;
|
||||||
|
|
||||||
/* Safety checks */
|
/* Safety checks */
|
||||||
silk_assert( K > 0 );
|
celt_assert( K > 0 );
|
||||||
silk_assert( L > 0 );
|
celt_assert( L > 0 );
|
||||||
silk_assert( L >= K );
|
celt_assert( L >= K );
|
||||||
|
|
||||||
/* Write start indices in index vector */
|
/* Write start indices in index vector */
|
||||||
for( i = 0; i < K; i++ ) {
|
for( i = 0; i < K; i++ ) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ void silk_warped_autocorrelation_FLP(
|
||||||
double C[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
|
double C[ MAX_SHAPE_LPC_ORDER + 1 ] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
|
||||||
|
|
||||||
/* Order must be even */
|
/* Order must be even */
|
||||||
silk_assert( ( order & 1 ) == 0 );
|
celt_assert( ( order & 1 ) == 0 );
|
||||||
|
|
||||||
/* Loop over samples */
|
/* Loop over samples */
|
||||||
for( n = 0; n < length; n++ ) {
|
for( n = 0; n < length; n++ ) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue