Implements OPUS_RESET_STATE for multi-stream encoder
authorJean-Marc Valin <jmvalin@jmvalin.ca>
Mon, 28 Oct 2013 20:11:53 +0000 (16:11 -0400)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Mon, 28 Oct 2013 20:12:24 +0000 (16:12 -0400)
src/opus_multistream_encoder.c

index 82594eb..f711e26 100644 (file)
@@ -1131,6 +1131,29 @@ int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...)
        *value = st->variable_duration;
    }
    break;
+   case OPUS_RESET_STATE:
+   {
+      int s;
+      st->subframe_mem[0] = st->subframe_mem[1] = st->subframe_mem[2] = 0;
+      if (st->surround)
+      {
+         OPUS_CLEAR(ms_get_preemph_mem(st), st->layout.nb_channels);
+         OPUS_CLEAR(ms_get_window_mem(st), st->layout.nb_channels*120);
+      }
+      for (s=0;s<st->layout.nb_streams;s++)
+      {
+         OpusEncoder *enc;
+         enc = (OpusEncoder*)ptr;
+         if (s < st->layout.nb_coupled_streams)
+            ptr += align(coupled_size);
+         else
+            ptr += align(mono_size);
+         ret = opus_encoder_ctl(enc, OPUS_RESET_STATE);
+         if (ret != OPUS_OK)
+            break;
+      }
+   }
+   break;
    default:
       ret = OPUS_UNIMPLEMENTED;
       break;