shithub: opus

Download patch

ref: bcea233f7541d85253d42bc98ee2e1f842c11461
parent: eff72e47eb08e646bf5d45f2aa739058723d39fd
author: Jean-Marc Valin <[email protected]>
date: Thu Jul 7 07:54:10 EDT 2016

Makes CBR calculations more accurate for 60-ms frames

--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -1052,8 +1052,11 @@
     if (!st->use_vbr)
     {
        int cbrBytes;
-       cbrBytes = IMIN( (st->bitrate_bps + 4*frame_rate)/(8*frame_rate) , max_data_bytes);
-       st->bitrate_bps = cbrBytes * (8*frame_rate);
+       /* Multiply by 3 to make sure the division is exact. */
+       int frame_rate3 = 3*st->Fs/frame_size;
+       /* We need to make sure that "int" values always fit in 16 bits. */
+       cbrBytes = IMIN( (3*st->bitrate_bps/8 + frame_rate3/2)/frame_rate3, max_data_bytes);
+       st->bitrate_bps = cbrBytes*(opus_int32)frame_rate3*8/3;
        max_data_bytes = cbrBytes;
     }
     if (max_data_bytes<3 || st->bitrate_bps < 3*frame_rate*8