diff options
author | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2016-06-03 16:27:48 -0400 |
---|---|---|
committer | Jean-Marc Valin <jmvalin@jmvalin.ca> | 2016-06-29 15:21:31 -0400 |
commit | 1858b002dec8753caf8d5f2a080b8f4c728bfca3 (patch) | |
tree | 99178cb9ab9935f52280743df7fd6b13c6577825 | |
parent | 8b958f4f72fb98cea99d42da19bf056cd15baf7a (diff) | |
download | opus-1858b002dec8753caf8d5f2a080b8f4c728bfca3.tar.gz |
CBR: set gains to their previons values where we're busting the budget
-rw-r--r-- | silk/fixed/encode_frame_FIX.c | 22 | ||||
-rw-r--r-- | silk/float/encode_frame_FLP.c | 22 |
2 files changed, 38 insertions, 6 deletions
diff --git a/silk/fixed/encode_frame_FIX.c b/silk/fixed/encode_frame_FIX.c index 5bc94c34..55064c53 100644 --- a/silk/fixed/encode_frame_FIX.c +++ b/silk/fixed/encode_frame_FIX.c @@ -201,14 +201,15 @@ opus_int silk_encode_frame_FIX( psEnc->sCmn.arch); } + if ( iter == maxIter && !found_lower ) { + silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc ) ); + } + /****************************************/ /* Encode Parameters */ /****************************************/ silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0, condCoding ); - if ( iter == maxIter && !found_lower ) { - silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc ) ); - } /****************************************/ /* Encode Excitation Signal */ /****************************************/ @@ -217,13 +218,28 @@ opus_int silk_encode_frame_FIX( nBits = ec_tell( psRangeEnc ); + /* If we still bust after the last iteration, do some damage control. */ if ( iter == maxIter && !found_lower && nBits > maxBits ) { silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc ) ); + + /* Keep gains the same as the last frame. */ + psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; + for ( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { + psEnc->sCmn.indices.GainsIndices[ i ] = 4; + } + if (condCoding != CODE_CONDITIONALLY) { + psEnc->sCmn.indices.GainsIndices[ 0 ] = sEncCtrl.lastGainIndexPrev; + } + /* Clear all pulses. */ for ( i = 0; i < psEnc->sCmn.frame_length; i++ ) { psEnc->sCmn.pulses[ i ] = 0; } + + silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0, condCoding ); + silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType, psEnc->sCmn.indices.quantOffsetType, psEnc->sCmn.pulses, psEnc->sCmn.frame_length ); + nBits = ec_tell( psRangeEnc ); } diff --git a/silk/float/encode_frame_FLP.c b/silk/float/encode_frame_FLP.c index 59efcb44..dccd271d 100644 --- a/silk/float/encode_frame_FLP.c +++ b/silk/float/encode_frame_FLP.c @@ -187,14 +187,15 @@ opus_int silk_encode_frame_FLP( /*****************************************/ silk_NSQ_wrapper_FLP( psEnc, &sEncCtrl, &psEnc->sCmn.indices, &psEnc->sCmn.sNSQ, psEnc->sCmn.pulses, x_frame ); + if ( iter == maxIter && !found_lower ) { + silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc ) ); + } + /****************************************/ /* Encode Parameters */ /****************************************/ silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0, condCoding ); - if ( iter == maxIter && !found_lower ) { - silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc ) ); - } /****************************************/ /* Encode Excitation Signal */ /****************************************/ @@ -203,13 +204,28 @@ opus_int silk_encode_frame_FLP( nBits = ec_tell( psRangeEnc ); + /* If we still bust after the last iteration, do some damage control. */ if ( iter == maxIter && !found_lower && nBits > maxBits ) { silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc ) ); + + /* Keep gains the same as the last frame. */ + psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; + for ( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { + psEnc->sCmn.indices.GainsIndices[ i ] = 4; + } + if (condCoding != CODE_CONDITIONALLY) { + psEnc->sCmn.indices.GainsIndices[ 0 ] = sEncCtrl.lastGainIndexPrev; + } + /* Clear all pulses. */ for ( i = 0; i < psEnc->sCmn.frame_length; i++ ) { psEnc->sCmn.pulses[ i ] = 0; } + + silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0, condCoding ); + silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType, psEnc->sCmn.indices.quantOffsetType, psEnc->sCmn.pulses, psEnc->sCmn.frame_length ); + nBits = ec_tell( psRangeEnc ); } |