summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Marc Valin <jmvalin@amazon.com>2022-07-24 02:12:03 -0400
committerJean-Marc Valin <jmvalin@amazon.com>2022-07-24 02:12:03 -0400
commit5413ef784941652448e703688fbe3b96ef6d7e86 (patch)
tree8fa2dbd5c2d4c60ff1d2d22a2f72246f008d50f0
parent378b4e5fc31b63c1f1a9f6a87a62609c5a083724 (diff)
downloadopus-5413ef784941652448e703688fbe3b96ef6d7e86.tar.gz
Re-tuning the use of LTP scaling
Making LTP scaling depend on the bitrate and whether FEC is on. The thresholds for scaling 1 and 2 are now independent.
-rw-r--r--silk/fixed/LTP_scale_ctrl_FIX.c9
-rw-r--r--silk/float/LTP_scale_ctrl_FLP.c8
2 files changed, 14 insertions, 3 deletions
diff --git a/silk/fixed/LTP_scale_ctrl_FIX.c b/silk/fixed/LTP_scale_ctrl_FIX.c
index 3dcedef8..b3afb70b 100644
--- a/silk/fixed/LTP_scale_ctrl_FIX.c
+++ b/silk/fixed/LTP_scale_ctrl_FIX.c
@@ -43,8 +43,13 @@ void silk_LTP_scale_ctrl_FIX(
if( condCoding == CODE_INDEPENDENTLY ) {
/* Only scale if first frame in packet */
round_loss = psEnc->sCmn.PacketLoss_perc + psEnc->sCmn.nFramesPerPacket;
- psEnc->sCmn.indices.LTP_scaleIndex = (opus_int8)silk_LIMIT(
- silk_SMULWB( silk_SMULBB( round_loss, psEncCtrl->LTPredCodGain_Q7 ), SILK_FIX_CONST( 0.1, 9 ) ), 0, 2 );
+ if ( psEnc->sCmn.LBRR_flag ) {
+ /* LBRR reduces the effective loss. In practice, it does not square the loss because
+ losses aren't independent, but that still seems to work best. We also never go below 2%. */
+ round_loss = 2 + silk_SMULBB( round_loss, round_loss ) / 100;
+ }
+ psEnc->sCmn.indices.LTP_scaleIndex = silk_SMULBB( psEncCtrl->LTPredCodGain_Q7, round_loss ) > silk_log2lin( 128*7 + 2900-psEnc->sCmn.SNR_dB_Q7 );
+ psEnc->sCmn.indices.LTP_scaleIndex += silk_SMULBB( psEncCtrl->LTPredCodGain_Q7, round_loss ) > silk_log2lin( 128*7 + 3900-psEnc->sCmn.SNR_dB_Q7 );
} else {
/* Default is minimum scaling */
psEnc->sCmn.indices.LTP_scaleIndex = 0;
diff --git a/silk/float/LTP_scale_ctrl_FLP.c b/silk/float/LTP_scale_ctrl_FLP.c
index 8dbe29d0..1fed0993 100644
--- a/silk/float/LTP_scale_ctrl_FLP.c
+++ b/silk/float/LTP_scale_ctrl_FLP.c
@@ -42,7 +42,13 @@ void silk_LTP_scale_ctrl_FLP(
if( condCoding == CODE_INDEPENDENTLY ) {
/* Only scale if first frame in packet */
round_loss = psEnc->sCmn.PacketLoss_perc + psEnc->sCmn.nFramesPerPacket;
- psEnc->sCmn.indices.LTP_scaleIndex = (opus_int8)silk_LIMIT( round_loss * psEncCtrl->LTPredCodGain * 0.1f, 0.0f, 2.0f );
+ if ( psEnc->sCmn.LBRR_flag ) {
+ /* LBRR reduces the effective loss. In practice, it does not square the loss because
+ losses aren't independent, but that still seems to work best. We also never go below 2%. */
+ round_loss = 2 + silk_SMULBB( round_loss, round_loss) / 100;
+ }
+ psEnc->sCmn.indices.LTP_scaleIndex = silk_SMULBB( psEncCtrl->LTPredCodGain, round_loss ) > silk_log2lin( 2900 - psEnc->sCmn.SNR_dB_Q7 );
+ psEnc->sCmn.indices.LTP_scaleIndex += silk_SMULBB( psEncCtrl->LTPredCodGain, round_loss ) > silk_log2lin( 3900 - psEnc->sCmn.SNR_dB_Q7 );
} else {
/* Default is minimum scaling */
psEnc->sCmn.indices.LTP_scaleIndex = 0;