shithub: opus

Download patch

ref: 3120e225c24e1be35df9a76dd4bf9ce57e8111ca
parent: b288c5078adaa364c01c078f17b2c916517056e7
author: Jean-Marc Valin <[email protected]>
date: Fri Aug 12 12:17:27 EDT 2011

Fixes a stereo rate mismatch bug

This is a tentative fix for a bug found in fuzzing where the encoder
switched from mono to stereo while in the process of changing bandwidth.
The result was that the newly added side would use the new sampling
rate, while the mid hadn't switched yet, causing an encoder/decoder
mismatch. The fix is that the side rate selection gets overridden
to use the mid rate.
The bug would occur when compiling with fuzzing enabled and using:
./test_opus 0 48000 2 24000 input.sw output.sw

--- a/silk/fixed/silk_main_FIX.h
+++ b/silk/fixed/silk_main_FIX.h
@@ -81,7 +81,8 @@
     silk_EncControlStruct           *encControl,        /* I:   Control structure                       */
     const opus_int32                 TargetRate_bps,     /* I    Target max bitrate (bps)                */
     const opus_int                   allow_bw_switch,    /* I    Flag to allow switching audio bandwidth */
-    const opus_int                   channelNb           /* I    Channel number                          */
+    const opus_int                   channelNb,           /* I    Channel number                          */
+    const opus_int                   force_fs_kHz
 );
 
 /****************/
--- a/silk/float/silk_main_FLP.h
+++ b/silk/float/silk_main_FLP.h
@@ -79,7 +79,8 @@
     silk_EncControlStruct           *encControl,        /* I:   Control structure                       */
     const opus_int32                 TargetRate_bps,     /* I    Target max bitrate (bps)                */
     const opus_int                   allow_bw_switch,    /* I    Flag to allow switching audio bandwidth */
-    const opus_int                   channelNb           /* I    Channel number                          */
+    const opus_int                   channelNb,           /* I    Channel number                          */
+    const opus_int                   force_fs_kHz
 );
 
 /****************/
--- a/silk/silk_control_codec.c
+++ b/silk/silk_control_codec.c
@@ -65,7 +65,8 @@
     silk_EncControlStruct           *encControl,        /* I:   Control structure                       */
     const opus_int32                 TargetRate_bps,     /* I    Target max bitrate (bps)                */
     const opus_int                   allow_bw_switch,    /* I    Flag to allow switching audio bandwidth */
-    const opus_int                   channelNb           /* I    Channel number                          */
+    const opus_int                   channelNb,           /* I    Channel number                          */
+    const opus_int                   force_fs_kHz
 )
 {
     opus_int   fs_kHz, ret = 0;
@@ -96,7 +97,8 @@
     /* Determine internal sampling rate         */
     /********************************************/
     fs_kHz = silk_control_audio_bandwidth( &psEnc->sCmn );
-
+    if (force_fs_kHz)
+       fs_kHz = force_fs_kHz;
     /********************************************/
     /* Prepare resampler and buffered data      */
     /********************************************/
--- a/silk/silk_enc_API.c
+++ b/silk/silk_enc_API.c
@@ -201,7 +201,9 @@
 
     TargetRate_bps = SKP_RSHIFT32( encControl->bitRate, encControl->nChannelsInternal - 1 );
     for( n = 0; n < encControl->nChannelsInternal; n++ ) {
-        if( ( ret = silk_control_encoder( &psEnc->state_Fxx[ n ], encControl, TargetRate_bps, psEnc->allowBandwidthSwitch, n ) ) != 0 ) {
+        /* JMV: Force the side channel to the same rate as the mid. Is this the right way? */
+        int force_fs_kHz = (n==1) ? psEnc->state_Fxx[0].sCmn.fs_kHz : 0;
+        if( ( ret = silk_control_encoder( &psEnc->state_Fxx[ n ], encControl, TargetRate_bps, psEnc->allowBandwidthSwitch, n, force_fs_kHz ) ) != 0 ) {
             SKP_assert( 0 );
             return ret;
         }