From fe84c3bceeb9536725d5500cb984c165f52b8b25 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Sun, 9 Jul 2023 13:05:08 -0400 Subject: Make "VBR with cap" less aggressive The bits we don't use won't be wasted, so it's less important to get exactly the optimal number of bits below the cap. --- silk/fixed/encode_frame_FIX.c | 7 +++++-- silk/float/encode_frame_FLP.c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/silk/fixed/encode_frame_FIX.c b/silk/fixed/encode_frame_FIX.c index 31a64f6c..7c83360b 100644 --- a/silk/fixed/encode_frame_FIX.c +++ b/silk/fixed/encode_frame_FIX.c @@ -105,8 +105,11 @@ opus_int silk_encode_frame_FIX( opus_int gain_lock[ MAX_NB_SUBFR ] = {0}; opus_int16 best_gain_mult[ MAX_NB_SUBFR ]; opus_int best_sum[ MAX_NB_SUBFR ]; + opus_int bits_margin; SAVE_STACK; + /* For CBR, 5 bits below budget is close enough. For VBR, allow up to 25% below the cap if we initially busted the budget. */ + bits_margin = useCBR ? 5 : maxBits/4; /* This is totally unnecessary but many compilers (including gcc) are too dumb to realise it */ LastGainIndex_copy2 = nBits_lower = nBits_upper = gainMult_lower = gainMult_upper = 0; @@ -282,7 +285,7 @@ opus_int silk_encode_frame_FIX( gainMult_upper = gainMult_Q8; gainsID_upper = gainsID; } - } else if( nBits < maxBits - 5 ) { + } else if( nBits < maxBits - bits_margin ) { found_lower = 1; nBits_lower = nBits; gainMult_lower = gainMult_Q8; @@ -296,7 +299,7 @@ opus_int silk_encode_frame_FIX( LastGainIndex_copy2 = psEnc->sShape.LastGainIndex; } } else { - /* Within 5 bits of budget: close enough */ + /* Close enough */ break; } diff --git a/silk/float/encode_frame_FLP.c b/silk/float/encode_frame_FLP.c index 9e96bf7a..8a327c56 100644 --- a/silk/float/encode_frame_FLP.c +++ b/silk/float/encode_frame_FLP.c @@ -107,7 +107,10 @@ opus_int silk_encode_frame_FLP( opus_int gain_lock[ MAX_NB_SUBFR ] = {0}; opus_int16 best_gain_mult[ MAX_NB_SUBFR ]; opus_int best_sum[ MAX_NB_SUBFR ]; + opus_int bits_margin; + /* For CBR, 5 bits below budget is close enough. For VBR, allow up to 25% below the cap if we initially busted the budget. */ + bits_margin = useCBR ? 5 : maxBits/4; /* This is totally unnecessary but many compilers (including gcc) are too dumb to realise it */ LastGainIndex_copy2 = nBits_lower = nBits_upper = gainMult_lower = gainMult_upper = 0; @@ -270,7 +273,7 @@ opus_int silk_encode_frame_FLP( gainMult_upper = gainMult_Q8; gainsID_upper = gainsID; } - } else if( nBits < maxBits - 5 ) { + } else if( nBits < maxBits - bits_margin ) { found_lower = 1; nBits_lower = nBits; gainMult_lower = gainMult_Q8; @@ -284,7 +287,7 @@ opus_int silk_encode_frame_FLP( LastGainIndex_copy2 = psEnc->sShape.LastGainIndex; } } else { - /* Within 5 bits of budget: close enough */ + /* Close enough */ break; } -- cgit v1.2.3