BeagleRescue/libsdl2_mixer/external/opus-1.0.3/001-opus.git-9c7193e4.patch

116 lines
5.4 KiB
Diff

From 9c7193e4f956e230d919f604df27ea4b13b62370 Mon Sep 17 00:00:00 2001
From: Koen Vos <koenvos74@gmail.com>
Date: Thu, 19 Jun 2014 20:07:55 -0400
Subject: [PATCH] Fixes CNG to address the DTX issue reported by Gonzalo Mariano
- Bug fix: the CNG synthesis filter output consisted of only the prediction
values, now added the input to that.
- CNG excitation level now takes into account the level from the PLC (since
both PLC and CNG can be active at the same time).
- CNG is now called before PLC_glue() to smoothen the transition out of CNG.
Signed-off-by: Jean-Marc Valin <jmvalin@jmvalin.ca>
---
silk/CNG.c | 15 ++++++++++-----
silk/decode_frame.c | 10 +++++-----
2 files changed, 15 insertions(+), 10 deletions(-)
From f662fd42eba24a3f3ba4a4f0a0f238516aa44221 Mon Sep 17 00:00:00 2001
From: Koen Vos <koenvos74@gmail.com>
Date: Fri, 20 Jun 2014 01:42:49 -0400
Subject: [PATCH] Fixes CNG overflows from the previous commit
Signed-off-by: Jean-Marc Valin <jmvalin@jmvalin.ca>
---
silk/CNG.c | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/silk/CNG.c b/silk/CNG.c
index 8481d95..cd15001 100644
--- a/silk/CNG.c
+++ b/silk/CNG.c
@@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
/* Generates excitation for CNG LPC synthesis */
static inline void silk_CNG_exc(
- opus_int32 residual_Q10[], /* O CNG residual signal Q10 */
+ opus_int32 exc_Q10[], /* O CNG excitation signal Q10 */
opus_int32 exc_buf_Q14[], /* I Random samples buffer Q10 */
opus_int32 Gain_Q16, /* I Gain to apply */
opus_int length, /* I Length */
@@ -54,7 +54,7 @@ static inline void silk_CNG_exc(
idx = (opus_int)( silk_RSHIFT( seed, 24 ) & exc_mask );
silk_assert( idx >= 0 );
silk_assert( idx <= CNG_BUF_MASK_MAX );
- residual_Q10[ i ] = (opus_int16)silk_SAT16( silk_SMULWW( exc_buf_Q14[ idx ], Gain_Q16 >> 4 ) );
+ exc_Q10[ i ] = (opus_int16)silk_SAT16( silk_SMULWW( exc_buf_Q14[ idx ], Gain_Q16 >> 4 ) );
}
*rand_seed = seed;
}
@@ -84,7 +84,7 @@ void silk_CNG(
)
{
opus_int i, subfr;
- opus_int32 sum_Q6, max_Gain_Q16;
+ opus_int32 sum_Q6, max_Gain_Q16, gain_Q16;
opus_int16 A_Q12[ MAX_LPC_ORDER ];
opus_int32 CNG_sig_Q10[ MAX_FRAME_LENGTH + MAX_LPC_ORDER ];
silk_CNG_struct *psCNG = &psDec->sCNG;
@@ -125,7 +125,17 @@ void silk_CNG(
if( psDec->lossCnt ) {
/* Generate CNG excitation */
- silk_CNG_exc( CNG_sig_Q10 + MAX_LPC_ORDER, psCNG->CNG_exc_buf_Q14, psCNG->CNG_smth_Gain_Q16, length, &psCNG->rand_seed );
+ gain_Q16 = silk_SMULWW( psDec->sPLC.randScale_Q14, psDec->sPLC.prevGain_Q16[1] );
+ if( gain_Q16 >= (1 << 21) || psCNG->CNG_smth_Gain_Q16 > (1 << 23) ) {
+ gain_Q16 = silk_SMULTT( gain_Q16, gain_Q16 );
+ gain_Q16 = silk_SUB_LSHIFT32(silk_SMULTT( psCNG->CNG_smth_Gain_Q16, psCNG->CNG_smth_Gain_Q16 ), gain_Q16, 5 );
+ gain_Q16 = silk_LSHIFT32( silk_SQRT_APPROX( gain_Q16 ), 16 );
+ } else {
+ gain_Q16 = silk_SMULWW( gain_Q16, gain_Q16 );
+ gain_Q16 = silk_SUB_LSHIFT32(silk_SMULWW( psCNG->CNG_smth_Gain_Q16, psCNG->CNG_smth_Gain_Q16 ), gain_Q16, 5 );
+ gain_Q16 = silk_LSHIFT32( silk_SQRT_APPROX( gain_Q16 ), 8 );
+ }
+ silk_CNG_exc( CNG_sig_Q10 + MAX_LPC_ORDER, psCNG->CNG_exc_buf_Q14, gain_Q16, length, &psCNG->rand_seed );
/* Convert CNG NLSF to filter representation */
silk_NLSF2A( A_Q12, psCNG->CNG_smth_NLSF_Q15, psDec->LPC_order );
@@ -158,7 +168,7 @@ void silk_CNG(
/* Update states */
CNG_sig_Q10[ MAX_LPC_ORDER + i ] = silk_ADD_LSHIFT( CNG_sig_Q10[ MAX_LPC_ORDER + i ], sum_Q6, 4 );
- frame[ i ] = silk_ADD_SAT16( frame[ i ], silk_RSHIFT_ROUND( sum_Q6, 6 ) );
+ frame[ i ] = silk_ADD_SAT16( frame[ i ], silk_RSHIFT_ROUND( CNG_sig_Q10[ MAX_LPC_ORDER + i ], 10 ) );
}
silk_memcpy( psCNG->CNG_synth_state, &CNG_sig_Q10[ length ], MAX_LPC_ORDER * sizeof( opus_int32 ) );
} else {
diff --git a/silk/decode_frame.c b/silk/decode_frame.c
index 37459a3..6a7cffb 100644
--- a/silk/decode_frame.c
+++ b/silk/decode_frame.c
@@ -107,16 +107,16 @@ opus_int silk_decode_frame(
silk_memmove( psDec->outBuf, &psDec->outBuf[ psDec->frame_length ], mv_len * sizeof(opus_int16) );
silk_memcpy( &psDec->outBuf[ mv_len ], pOut, psDec->frame_length * sizeof( opus_int16 ) );
- /****************************************************************/
- /* Ensure smooth connection of extrapolated and good frames */
- /****************************************************************/
- silk_PLC_glue_frames( psDec, pOut, L );
-
/************************************************/
/* Comfort noise generation / estimation */
/************************************************/
silk_CNG( psDec, psDecCtrl, pOut, L );
+ /****************************************************************/
+ /* Ensure smooth connection of extrapolated and good frames */
+ /****************************************************************/
+ silk_PLC_glue_frames( psDec, pOut, L );
+
/* Update some decoder state variables */
psDec->lagPrev = psDecCtrl->pitchL[ psDec->nb_subfr - 1 ];
--
1.7.2.5