shithub: opus

Download patch

ref: 9fd13d60656a54d8e2b04f350b2cd84c6d1c4382
parent: 1e22a4b7e9fa23997b45d6b455051a3fa35900b2
author: Jean-Marc Valin <[email protected]>
date: Fri Oct 7 18:50:49 EDT 2011

Not delaying stereo->mono transitions to/from CELT

Also not fuzzing the mode when it's forced

--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -487,30 +487,6 @@
 #endif
     }
 
-    if (st->stream_channels == 1 && st->prev_channels ==2 && st->silk_mode.toMono==0)
-    {
-       /* Delay stereo->mono transition by two frames so that SILK can do a smooth downmix */
-       st->silk_mode.toMono = 1;
-       st->stream_channels = 2;
-    } else {
-       st->silk_mode.toMono = 0;
-    }
-
-#ifdef FUZZING
-    /* Random mode switching */
-    if ((rand()&0xF)==0)
-    {
-       if ((rand()&0x1)==0)
-          st->mode = MODE_CELT_ONLY;
-       else
-          st->mode = MODE_SILK_ONLY;
-    } else {
-       if (st->prev_mode==MODE_CELT_ONLY)
-          st->mode = MODE_CELT_ONLY;
-       else
-          st->mode = MODE_SILK_ONLY;
-    }
-#else
     /* Mode selection depending on application and signal type */
     if (st->application == OPUS_APPLICATION_RESTRICTED_LOWDELAY)
     {
@@ -517,6 +493,21 @@
        st->mode = MODE_CELT_ONLY;
     } else if (st->user_forced_mode == OPUS_AUTO)
     {
+#ifdef FUZZING
+       /* Random mode switching */
+       if ((rand()&0xF)==0)
+       {
+          if ((rand()&0x1)==0)
+             st->mode = MODE_CELT_ONLY;
+          else
+             st->mode = MODE_SILK_ONLY;
+       } else {
+          if (st->prev_mode==MODE_CELT_ONLY)
+             st->mode = MODE_CELT_ONLY;
+          else
+             st->mode = MODE_SILK_ONLY;
+       }
+#else
        int chan;
        opus_int32 mode_voice, mode_music;
        opus_int32 threshold;
@@ -533,14 +524,24 @@
            threshold += 4000;
 
        st->mode = (equiv_rate >= threshold) ? MODE_CELT_ONLY: MODE_SILK_ONLY;
+#endif
     } else {
        st->mode = st->user_forced_mode;
     }
-#endif
 
     /* Override the chosen mode to make sure we meet the requested frame size */
     if (st->mode != MODE_CELT_ONLY && frame_size < st->Fs/100)
        st->mode = MODE_CELT_ONLY;
+
+    if (st->stream_channels == 1 && st->prev_channels ==2 && st->silk_mode.toMono==0
+          && st->mode != MODE_CELT_ONLY && st->prev_mode != MODE_CELT_ONLY)
+    {
+       /* Delay stereo->mono transition by two frames so that SILK can do a smooth downmix */
+       st->silk_mode.toMono = 1;
+       st->stream_channels = 2;
+    } else {
+       st->silk_mode.toMono = 0;
+    }
 
     if (st->prev_mode > 0 &&
         ((st->mode != MODE_CELT_ONLY && st->prev_mode == MODE_CELT_ONLY) ||