Skip to content
Snippets Groups Projects
Unverified Commit ab04fbb1 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Smooth out the LBRR rate estimate

Reduces fluctuations in the non-FEC target bitrate.
parent fd9c0f1e
No related branches found
No related tags found
No related merge requests found
......@@ -270,6 +270,7 @@ opus_int silk_Encode( /* O Returns error co
psEnc->state_Fxx[ 0 ].sCmn.fs_kHz * 1000 );
ALLOC( buf, nSamplesFromInputMax, opus_int16 );
while( 1 ) {
int curr_nBitsUsedLBRR = 0;
nSamplesToBuffer = psEnc->state_Fxx[ 0 ].sCmn.frame_length - psEnc->state_Fxx[ 0 ].sCmn.inputBufIx;
nSamplesToBuffer = silk_min( nSamplesToBuffer, nSamplesToBufferMax );
nSamplesFromInput = silk_DIV32_16( nSamplesToBuffer * psEnc->state_Fxx[ 0 ].sCmn.API_fs_Hz, psEnc->state_Fxx[ 0 ].sCmn.fs_kHz * 1000 );
......@@ -342,6 +343,7 @@ opus_int silk_Encode( /* O Returns error co
opus_uint8 iCDF[ 2 ] = { 0, 0 };
iCDF[ 0 ] = 256 - silk_RSHIFT( 256, ( psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket + 1 ) * encControl->nChannelsInternal );
ec_enc_icdf( psRangeEnc, 0, iCDF, 8 );
curr_nBitsUsedLBRR = ec_tell( psRangeEnc );
/* Encode any LBRR data from previous packet */
/* Encode LBRR flags */
......@@ -386,8 +388,7 @@ opus_int silk_Encode( /* O Returns error co
for( n = 0; n < encControl->nChannelsInternal; n++ ) {
silk_memset( psEnc->state_Fxx[ n ].sCmn.LBRR_flags, 0, sizeof( psEnc->state_Fxx[ n ].sCmn.LBRR_flags ) );
}
psEnc->nBitsUsedLBRR = ec_tell( psRangeEnc );
curr_nBitsUsedLBRR = ec_tell( psRangeEnc ) - curr_nBitsUsedLBRR;
}
silk_HP_variable_cutoff( psEnc->state_Fxx );
......@@ -396,6 +397,16 @@ opus_int silk_Encode( /* O Returns error co
nBits = silk_DIV32_16( silk_MUL( encControl->bitRate, encControl->payloadSize_ms ), 1000 );
/* Subtract bits used for LBRR */
if( !prefillFlag ) {
/* psEnc->nBitsUsedLBRR is an exponential moving average of the LBRR usage,
except that for the first LBRR frame it does no averaging and for the first
frame after after LBRR, it goes back to zero immediately. */
if ( curr_nBitsUsedLBRR < 10 ) {
psEnc->nBitsUsedLBRR = 0;
} else if ( psEnc->nBitsUsedLBRR < 10) {
psEnc->nBitsUsedLBRR = curr_nBitsUsedLBRR;
} else {
psEnc->nBitsUsedLBRR = ( psEnc->nBitsUsedLBRR + curr_nBitsUsedLBRR ) / 2;
}
nBits -= psEnc->nBitsUsedLBRR;
}
/* Divide by number of uncoded frames left in packet */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment