aboutsummaryrefslogtreecommitdiff
path: root/silk/enc_API.c
diff options
context:
space:
mode:
authorflim <flim@google.com>2016-01-26 14:33:44 +0100
committerflim <flim@google.com>2016-03-04 17:40:32 +0100
commitc91ee5b5642fcc4969150f73d5f6848f88bf1638 (patch)
tree900cb39b975dfed729e37e5810fef61fd92d7a70 /silk/enc_API.c
parent1391dbf0ccd121ce7a49d30e2142d36c8d404990 (diff)
downloadlibopus-c91ee5b5642fcc4969150f73d5f6848f88bf1638.tar.gz
Change-Id: I8211751bab026ab236a612c6e0873f8bdbcd6c98
Diffstat (limited to 'silk/enc_API.c')
-rw-r--r--silk/enc_API.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/silk/enc_API.c b/silk/enc_API.c
index 43739efc..f8060286 100644
--- a/silk/enc_API.c
+++ b/silk/enc_API.c
@@ -165,7 +165,7 @@ opus_int silk_Encode( /* O Returns error co
psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded = psEnc->state_Fxx[ 1 ].sCmn.nFramesEncoded = 0;
/* Check values in encoder control structure */
- if( ( ret = check_control_input( encControl ) != 0 ) ) {
+ if( ( ret = check_control_input( encControl ) ) != 0 ) {
silk_assert( 0 );
RESTORE_STACK;
return ret;
@@ -376,26 +376,33 @@ 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 );
}
silk_HP_variable_cutoff( psEnc->state_Fxx );
/* Total target bits for packet */
nBits = silk_DIV32_16( silk_MUL( encControl->bitRate, encControl->payloadSize_ms ), 1000 );
- /* Subtract half of the bits already used */
+ /* Subtract bits used for LBRR */
if( !prefillFlag ) {
- nBits -= ec_tell( psRangeEnc ) >> 1;
+ nBits -= psEnc->nBitsUsedLBRR;
}
/* Divide by number of uncoded frames left in packet */
- nBits = silk_DIV32_16( nBits, psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket - psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded );
+ nBits = silk_DIV32_16( nBits, psEnc->state_Fxx[ 0 ].sCmn.nFramesPerPacket );
/* Convert to bits/second */
if( encControl->payloadSize_ms == 10 ) {
TargetRate_bps = silk_SMULBB( nBits, 100 );
} else {
TargetRate_bps = silk_SMULBB( nBits, 50 );
}
- /* Subtract fraction of bits in excess of target in previous packets */
+ /* Subtract fraction of bits in excess of target in previous frames and packets */
TargetRate_bps -= silk_DIV32_16( silk_MUL( psEnc->nBitsExceeded, 1000 ), BITRESERVOIR_DECAY_TIME_MS );
+ if( !prefillFlag && psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded > 0 ) {
+ /* Compare actual vs target bits so far in this packet */
+ opus_int32 bitsBalance = ec_tell( psRangeEnc ) - psEnc->nBitsUsedLBRR - nBits * psEnc->state_Fxx[ 0 ].sCmn.nFramesEncoded;
+ TargetRate_bps -= silk_DIV32_16( silk_MUL( bitsBalance, 1000 ), BITRESERVOIR_DECAY_TIME_MS );
+ }
/* Never exceed input bitrate */
TargetRate_bps = silk_LIMIT( TargetRate_bps, encControl->bitRate, 5000 );