From 74de3a580cca34a855c2846bf249eb224f6e9658 Mon Sep 17 00:00:00 2001
From: Jean-Marc Valin <jmvalin@jmvalin.ca>
Date: Thu, 16 May 2013 23:09:34 -0400
Subject: [PATCH] Saturates the last RC to 0.99 when Schur blows up

This is a follow-up on ac76b15. When Schur blows up, we set the last RC to
+/- 0.99 instead of eliminating it.
---
 silk/fixed/schur64_FIX.c | 6 ++++++
 silk/fixed/schur_FIX.c   | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/silk/fixed/schur64_FIX.c b/silk/fixed/schur64_FIX.c
index c75f96a8a..1701d5ba5 100644
--- a/silk/fixed/schur64_FIX.c
+++ b/silk/fixed/schur64_FIX.c
@@ -58,6 +58,12 @@ opus_int32 silk_schur64(                            /* O    returns residual ene
     for( k = 0; k < order; k++ ) {
         /* Check that we won't be getting an unstable rc, otherwise stop here. */
         if (silk_abs_int32(C[ k + 1 ][ 0 ]) >= C[ 0 ][ 1 ]) {
+           if ( C[ k + 1 ][ 0 ] > 0 ) {
+              rc_Q16[ k ] = -SILK_FIX_CONST( .99f, 16 );
+           } else {
+              rc_Q16[ k ] = SILK_FIX_CONST( .99f, 16 );
+           }
+           k++;
            break;
         }
 
diff --git a/silk/fixed/schur_FIX.c b/silk/fixed/schur_FIX.c
index 788ad3f3b..37dc42c66 100644
--- a/silk/fixed/schur_FIX.c
+++ b/silk/fixed/schur_FIX.c
@@ -70,6 +70,12 @@ opus_int32 silk_schur(                              /* O    Returns residual ene
     for( k = 0; k < order; k++ ) {
         /* Check that we won't be getting an unstable rc, otherwise stop here. */
         if (silk_abs_int32(C[ k + 1 ][ 0 ]) >= C[ 0 ][ 1 ]) {
+           if ( C[ k + 1 ][ 0 ] > 0 ) {
+              rc_Q15[ k ] = -SILK_FIX_CONST( .99f, 15 );
+           } else {
+              rc_Q15[ k ] = SILK_FIX_CONST( .99f, 15 );
+           }
+           k++;
            break;
         }
 
-- 
GitLab