File opus-Silk-CNG-adapts-faster.patch of Package opus.14015

From 3ebf4ad86de2469572f7fa2bd6451469e7867c8f Mon Sep 17 00:00:00 2001
From: Felicia Lim <flim@google.com>
Date: Fri, 31 May 2019 13:58:44 -0700
Subject: [PATCH] Silk CNG adapts faster to received packets with lower gains

---
 silk/CNG.c    | 4 ++++
 silk/define.h | 1 +
 2 files changed, 5 insertions(+)

diff --git a/silk/CNG.c b/silk/CNG.c
index ef8e38df..2a910099 100644
--- a/silk/CNG.c
+++ b/silk/CNG.c
@@ -118,6 +118,10 @@ void silk_CNG(
         /* Smooth gains */
         for( i = 0; i < psDec->nb_subfr; i++ ) {
             psCNG->CNG_smth_Gain_Q16 += silk_SMULWB( psDecCtrl->Gains_Q16[ i ] - psCNG->CNG_smth_Gain_Q16, CNG_GAIN_SMTH_Q16 );
+            /* If the smoothed gain is 3 dB greater than this subframe's gain, use this subframe's gain to adapt faster. */
+            if( silk_SMULWW( psCNG->CNG_smth_Gain_Q16, CNG_GAIN_SMTH_THRESHOLD_Q16 ) > psDecCtrl->Gains_Q16[ i ] ) {
+                psCNG->CNG_smth_Gain_Q16 = psDecCtrl->Gains_Q16[ i ];
+            }
         }
     }
 
diff --git a/silk/define.h b/silk/define.h
index 247cb0bf..491c86f3 100644
--- a/silk/define.h
+++ b/silk/define.h
@@ -225,6 +225,7 @@ extern "C"
 /* Defines for CN generation */
 #define CNG_BUF_MASK_MAX                        255     /* 2^floor(log2(MAX_FRAME_LENGTH))-1    */
 #define CNG_GAIN_SMTH_Q16                       4634    /* 0.25^(1/4)                           */
+#define CNG_GAIN_SMTH_THRESHOLD_Q16             46396   /* -3 dB                                */
 #define CNG_NLSF_SMTH_Q16                       16348   /* 0.25                                 */
 
 #ifdef __cplusplus
-- 
2.11.0

openSUSE Build Service is sponsored by