From 53ea87fb96bc7eb550d1f60b3136e32857a4f9d9 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Mon, 10 Oct 2011 01:57:22 -0400 Subject: [PATCH] Cheap early detection of unstable filters We check the DC gain before doing the full RC calculations --- silk/LPC_inv_pred_gain.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/silk/LPC_inv_pred_gain.c b/silk/LPC_inv_pred_gain.c index 93c95705..3a2ff665 100644 --- a/silk/LPC_inv_pred_gain.c +++ b/silk/LPC_inv_pred_gain.c @@ -117,14 +117,19 @@ opus_int silk_LPC_inverse_pred_gain( /* O: Returns 1 if unstable, opus_int k; opus_int32 Atmp_QA[ 2 ][ SILK_MAX_ORDER_LPC ]; opus_int32 *Anew_QA; + opus_int32 DC_resp=0; Anew_QA = Atmp_QA[ order & 1 ]; /* Increase Q domain of the AR coefficients */ for( k = 0; k < order; k++ ) { + DC_resp += (opus_int32)A_Q12[ k ]; Anew_QA[ k ] = silk_LSHIFT( (opus_int32)A_Q12[ k ], QA - 12 ); } - + /* If the DC is unstable, we don't even need to do the full calculations */ + if ( DC_resp >= 4096 ) { + return 1; + } return LPC_inverse_pred_gain_QA( invGain_Q30, Atmp_QA, order ); }