summaryrefslogtreecommitdiff
path: root/src/opus_encoder.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/opus_encoder.c')
-rw-r--r--src/opus_encoder.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/opus_encoder.c b/src/opus_encoder.c
index 0b666469..7ed05893 100644
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -1894,21 +1894,28 @@ opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_
st->silk_mode.useCBR = !st->use_vbr;
/* Call SILK encoder for the low band */
- nBytes = IMIN(1275, max_data_bytes-1-redundancy_bytes);
- st->silk_mode.maxBits = nBytes*8;
+ /* Max bits for SILK, counting ToC, redundancy bytes, and optionally redundancy. */
+ st->silk_mode.maxBits = IMIN(1275, max_data_bytes-1-redundancy_bytes)*8;
+ if (redundancy)
+ {
+ /* Counting 1 bit for redundancy position and 20 bits for flag+size (only for hybrid). */
+ st->silk_mode.maxBits -= 1;
+ if (st->mode == MODE_HYBRID)
+ st->silk_mode.maxBits -= 20;
+ }
if (st->silk_mode.useCBR)
{
if (st->mode == MODE_HYBRID)
{
- st->silk_mode.maxBits = st->silk_mode.bitRate * frame_size / st->Fs;
+ st->silk_mode.maxBits = IMIN(st->silk_mode.maxBits, st->silk_mode.bitRate * frame_size / st->Fs);
}
} else {
/* Constrained VBR. */
if (st->mode == MODE_HYBRID)
{
/* Compute SILK bitrate corresponding to the max total bits available */
- opus_int32 maxBitRate = compute_silk_rate_for_hybrid(nBytes*8*st->Fs / frame_size,
+ opus_int32 maxBitRate = compute_silk_rate_for_hybrid(st->silk_mode.maxBits*st->Fs / frame_size,
curr_bandwidth, st->Fs == 50 * frame_size, st->use_vbr, st->silk_mode.LBRR_coded);
st->silk_mode.maxBits = maxBitRate * frame_size / st->Fs;
}