fix ARM build w/--disable-intrinsics --enable-asm
[opus.git] / tests / test_opus_api.c
index cab39aa..1d00950 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2011 Xiph.Org Foundation
+/* Copyright (c) 2011-2013 Xiph.Org Foundation
    Written by Gregory Maxwell */
 /*
    Redistribution and use in source and binary forms, with or without
@@ -15,8 +15,8 @@
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
-   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
@@ -49,7 +49,9 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
-#include "../include/opus.h"
+#include "arch.h"
+#include "opus_multistream.h"
+#include "opus.h"
 #include "test_opus_common.h"
 
 #ifdef VALGRIND
 #define MALLOC_FAIL
 #include "os_support.h"
 #include <malloc.h>
+
+static const opus_int32 opus_apps[3] = {OPUS_APPLICATION_VOIP,
+       OPUS_APPLICATION_AUDIO,OPUS_APPLICATION_RESTRICTED_LOWDELAY};
+
 void *malloc_hook(__attribute__((unused)) size_t size,
                   __attribute__((unused)) const void *caller)
 {
@@ -73,8 +79,6 @@ void *malloc_hook(__attribute__((unused)) size_t size,
 #endif
 
 static const opus_int32 opus_rates[5] = {48000,24000,16000,12000,8000};
-static const opus_int32 opus_apps[3] = {OPUS_APPLICATION_VOIP,
-       OPUS_APPLICATION_AUDIO,OPUS_APPLICATION_RESTRICTED_LOWDELAY};
 
 opus_int32 test_dec_api(void)
 {
@@ -88,8 +92,8 @@ opus_int32 test_dec_api(void)
 #endif
    short sbuf[960*2];
    int c,err;
-   int *nullptr;
-   nullptr=0;
+   opus_int32 *nullvalue;
+   nullvalue=0;
 
    cfgs=0;
    /*First test invalid configurations which should fail*/
@@ -99,7 +103,7 @@ opus_int32 test_dec_api(void)
    {
       i=opus_decoder_get_size(c);
       if(((c==1||c==2)&&(i<=2048||i>1<<16))||((c!=1&&c!=2)&&i!=0))test_failed();
-      fprintf(stdout,"    opus_decoder_get_size(%d)=%d ..............%s OK.\n",c,i,i>0?"":"....");
+      fprintf(stdout,"    opus_decoder_get_size(%d)=%d ...............%s OK.\n",c,i,i>0?"":"....");
       cfgs++;
    }
 
@@ -122,6 +126,9 @@ opus_int32 test_dec_api(void)
          dec = opus_decoder_create(fs, c, &err);
          if(err!=OPUS_BAD_ARG || dec!=NULL)test_failed();
          cfgs++;
+         dec = opus_decoder_create(fs, c, 0);
+         if(dec!=NULL)test_failed();
+         cfgs++;
          dec=malloc(opus_decoder_get_size(2));
          if(dec==NULL)test_failed();
          err = opus_decoder_init(dec,fs,c);
@@ -137,29 +144,41 @@ opus_int32 test_dec_api(void)
    VG_CHECK(dec,opus_decoder_get_size(2));
    cfgs++;
 
-   fprintf(stdout,"    opus_decoder_create() ....................... OK.\n");
-   fprintf(stdout,"    opus_decoder_init() ......................... OK.\n");
+   fprintf(stdout,"    opus_decoder_create() ........................ OK.\n");
+   fprintf(stdout,"    opus_decoder_init() .......................... OK.\n");
 
+   err=opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE((opus_uint32 *)NULL));
+   if(err != OPUS_BAD_ARG)test_failed();
    VG_UNDEF(&dec_final_range,sizeof(dec_final_range));
    err=opus_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range));
    if(err!=OPUS_OK)test_failed();
    VG_CHECK(&dec_final_range,sizeof(dec_final_range));
-   fprintf(stdout,"    OPUS_GET_FINAL_RANGE ........................ OK.\n");
+   fprintf(stdout,"    OPUS_GET_FINAL_RANGE ......................... OK.\n");
    cfgs++;
 
    err=opus_decoder_ctl(dec,OPUS_UNIMPLEMENTED);
    if(err!=OPUS_UNIMPLEMENTED)test_failed();
-   fprintf(stdout,"    OPUS_UNIMPLEMENTED .......................... OK.\n");
+   fprintf(stdout,"    OPUS_UNIMPLEMENTED ........................... OK.\n");
    cfgs++;
 
+   err=opus_decoder_ctl(dec, OPUS_GET_BANDWIDTH((opus_int32 *)NULL));
+   if(err != OPUS_BAD_ARG)test_failed();
    VG_UNDEF(&i,sizeof(i));
    err=opus_decoder_ctl(dec, OPUS_GET_BANDWIDTH(&i));
    if(err != OPUS_OK || i!=0)test_failed();
-   fprintf(stdout,"    OPUS_GET_BANDWIDTH .......................... OK.\n");
+   fprintf(stdout,"    OPUS_GET_BANDWIDTH ........................... OK.\n");
+   cfgs++;
+
+   err=opus_decoder_ctl(dec, OPUS_GET_SAMPLE_RATE((opus_int32 *)NULL));
+   if(err != OPUS_BAD_ARG)test_failed();
+   VG_UNDEF(&i,sizeof(i));
+   err=opus_decoder_ctl(dec, OPUS_GET_SAMPLE_RATE(&i));
+   if(err != OPUS_OK || i!=48000)test_failed();
+   fprintf(stdout,"    OPUS_GET_SAMPLE_RATE ......................... OK.\n");
    cfgs++;
 
    /*GET_PITCH has different execution paths depending on the previously decoded frame.*/
-   err=opus_decoder_ctl(dec, OPUS_GET_PITCH(nullptr));
+   err=opus_decoder_ctl(dec, OPUS_GET_PITCH(nullvalue));
    if(err!=OPUS_BAD_ARG)test_failed();
    cfgs++;
    VG_UNDEF(&i,sizeof(i));
@@ -181,7 +200,40 @@ opus_int32 test_dec_api(void)
    err=opus_decoder_ctl(dec, OPUS_GET_PITCH(&i));
    if(err != OPUS_OK || i>0 || i<-1)test_failed();
    cfgs++;
-   fprintf(stdout,"    OPUS_GET_PITCH .............................. OK.\n");
+   fprintf(stdout,"    OPUS_GET_PITCH ............................... OK.\n");
+
+   err=opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION((opus_int32 *)NULL));
+   if(err != OPUS_BAD_ARG)test_failed();
+   VG_UNDEF(&i,sizeof(i));
+   err=opus_decoder_ctl(dec, OPUS_GET_LAST_PACKET_DURATION(&i));
+   if(err != OPUS_OK || i!=960)test_failed();
+   cfgs++;
+   fprintf(stdout,"    OPUS_GET_LAST_PACKET_DURATION ................ OK.\n");
+
+   VG_UNDEF(&i,sizeof(i));
+   err=opus_decoder_ctl(dec, OPUS_GET_GAIN(&i));
+   VG_CHECK(&i,sizeof(i));
+   if(err != OPUS_OK || i!=0)test_failed();
+   cfgs++;
+   err=opus_decoder_ctl(dec, OPUS_GET_GAIN(nullvalue));
+   if(err != OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   err=opus_decoder_ctl(dec, OPUS_SET_GAIN(-32769));
+   if(err != OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   err=opus_decoder_ctl(dec, OPUS_SET_GAIN(32768));
+   if(err != OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   err=opus_decoder_ctl(dec, OPUS_SET_GAIN(-15));
+   if(err != OPUS_OK)test_failed();
+   cfgs++;
+   VG_UNDEF(&i,sizeof(i));
+   err=opus_decoder_ctl(dec, OPUS_GET_GAIN(&i));
+   VG_CHECK(&i,sizeof(i));
+   if(err != OPUS_OK || i!=-15)test_failed();
+   cfgs++;
+   fprintf(stdout,"    OPUS_SET_GAIN ................................ OK.\n");
+   fprintf(stdout,"    OPUS_GET_GAIN ................................ OK.\n");
 
    /*Reset the decoder*/
    dec2=malloc(opus_decoder_get_size(2));
@@ -189,18 +241,25 @@ opus_int32 test_dec_api(void)
    if(opus_decoder_ctl(dec, OPUS_RESET_STATE)!=OPUS_OK)test_failed();
    if(memcmp(dec2,dec,opus_decoder_get_size(2))==0)test_failed();
    free(dec2);
-   fprintf(stdout,"    OPUS_RESET_STATE ............................ OK.\n");
+   fprintf(stdout,"    OPUS_RESET_STATE ............................. OK.\n");
    cfgs++;
 
    VG_UNDEF(packet,sizeof(packet));
    packet[0]=0;
    if(opus_decoder_get_nb_samples(dec,packet,1)!=480)test_failed();
-   cfgs++;
+   if(opus_packet_get_nb_samples(packet,1,48000)!=480)test_failed();
+   if(opus_packet_get_nb_samples(packet,1,96000)!=960)test_failed();
+   if(opus_packet_get_nb_samples(packet,1,32000)!=320)test_failed();
+   if(opus_packet_get_nb_samples(packet,1,8000)!=80)test_failed();
+   packet[0]=3;
+   if(opus_packet_get_nb_samples(packet,1,24000)!=OPUS_INVALID_PACKET)test_failed();
    packet[0]=(63<<2)|3;
    packet[1]=63;
+   if(opus_packet_get_nb_samples(packet,0,24000)!=OPUS_BAD_ARG)test_failed();
+   if(opus_packet_get_nb_samples(packet,2,48000)!=OPUS_INVALID_PACKET)test_failed();
    if(opus_decoder_get_nb_samples(dec,packet,2)!=OPUS_INVALID_PACKET)test_failed();
-   fprintf(stdout,"    opus_decoder_get_nb_samples() ............... OK.\n");
-   cfgs++;
+   fprintf(stdout,"    opus_{packet,decoder}_get_nb_samples() ....... OK.\n");
+   cfgs+=9;
 
    if(OPUS_BAD_ARG!=opus_packet_get_nb_frames(packet,0))test_failed();
    for(i=0;i<256;i++) {
@@ -214,7 +273,7 @@ opus_int32 test_dec_api(void)
        cfgs++;
      }
    }
-   fprintf(stdout,"    opus_packet_get_nb_frames() ................. OK.\n");
+   fprintf(stdout,"    opus_packet_get_nb_frames() .................. OK.\n");
 
    for(i=0;i<256;i++) {
      int bw;
@@ -224,7 +283,7 @@ opus_int32 test_dec_api(void)
      if(bw!=opus_packet_get_bandwidth(packet))test_failed();
      cfgs++;
    }
-   fprintf(stdout,"    opus_packet_get_bandwidth() ................. OK.\n");
+   fprintf(stdout,"    opus_packet_get_bandwidth() .................. OK.\n");
 
    for(i=0;i<256;i++) {
      int fp3s,rate;
@@ -236,7 +295,7 @@ opus_int32 test_dec_api(void)
        cfgs++;
      }
    }
-   fprintf(stdout,"    opus_packet_get_samples_per_frame() ......... OK.\n");
+   fprintf(stdout,"    opus_packet_get_samples_per_frame() .......... OK.\n");
 
    packet[0]=(63<<2)+3;
    packet[1]=49;
@@ -254,12 +313,12 @@ opus_int32 test_dec_api(void)
    cfgs++;
    if(opus_decode(dec, packet, 3, sbuf, 960, 0)!=960)test_failed();
    cfgs++;
-   fprintf(stdout,"    opus_decode() ............................... OK.\n");
+   fprintf(stdout,"    opus_decode() ................................ OK.\n");
 #ifndef DISABLE_FLOAT_API
    VG_UNDEF(fbuf,sizeof(fbuf));
    if(opus_decode_float(dec, packet, 3, fbuf, 960, 0)!=960)test_failed();
    cfgs++;
-   fprintf(stdout,"    opus_decode_float() ......................... OK.\n");
+   fprintf(stdout,"    opus_decode_float() .......................... OK.\n");
 #endif
 
 #if 0
@@ -280,6 +339,353 @@ opus_int32 test_dec_api(void)
    return cfgs;
 }
 
+opus_int32 test_msdec_api(void)
+{
+   opus_uint32 dec_final_range;
+   OpusMSDecoder *dec;
+   OpusDecoder *streamdec;
+   opus_int32 i,j,cfgs;
+   unsigned char packet[1276];
+   unsigned char mapping[256];
+#ifndef DISABLE_FLOAT_API
+   float fbuf[960*2];
+#endif
+   short sbuf[960*2];
+   int a,b,c,err;
+#if 0
+   /*Relevant test not enabled for multistream*/
+   int *nullvalue;
+   nullvalue=0;
+#endif
+
+   mapping[0]=0;
+   mapping[1]=1;
+   for(i=2;i<256;i++)VG_UNDEF(&mapping[i],sizeof(unsigned char));
+
+   cfgs=0;
+   /*First test invalid configurations which should fail*/
+   fprintf(stdout,"\n  Multistream decoder basic API tests\n");
+   fprintf(stdout,"  ---------------------------------------------------\n");
+   for(a=-1;a<4;a++)
+   {
+      for(b=-1;b<4;b++)
+      {
+         i=opus_multistream_decoder_get_size(a,b);
+         if(((a>0&&b<=a&&b>=0)&&(i<=2048||i>((1<<16)*a)))||((a<1||b>a||b<0)&&i!=0))test_failed();
+         fprintf(stdout,"    opus_multistream_decoder_get_size(%2d,%2d)=%d %sOK.\n",a,b,i,i>0?"":"... ");
+         cfgs++;
+      }
+   }
+
+   /*Test with unsupported sample rates*/
+   for(c=1;c<3;c++)
+   {
+      for(i=-7;i<=96000;i++)
+      {
+         int fs;
+         if((i==8000||i==12000||i==16000||i==24000||i==48000)&&(c==1||c==2))continue;
+         switch(i)
+         {
+           case(-5):fs=-8000;break;
+           case(-6):fs=INT32_MAX;break;
+           case(-7):fs=INT32_MIN;break;
+           default:fs=i;
+         }
+         err = OPUS_OK;
+         VG_UNDEF(&err,sizeof(err));
+         dec = opus_multistream_decoder_create(fs, c, 1, c-1, mapping, &err);
+         if(err!=OPUS_BAD_ARG || dec!=NULL)test_failed();
+         cfgs++;
+         dec = opus_multistream_decoder_create(fs, c, 1, c-1, mapping, 0);
+         if(dec!=NULL)test_failed();
+         cfgs++;
+         dec=malloc(opus_multistream_decoder_get_size(1,1));
+         if(dec==NULL)test_failed();
+         err = opus_multistream_decoder_init(dec,fs,c,1,c-1, mapping);
+         if(err!=OPUS_BAD_ARG)test_failed();
+         cfgs++;
+         free(dec);
+      }
+   }
+
+   for(c=0;c<2;c++)
+   {
+      int *ret_err;
+      ret_err = c?0:&err;
+
+      mapping[0]=0;
+      mapping[1]=1;
+      for(i=2;i<256;i++)VG_UNDEF(&mapping[i],sizeof(unsigned char));
+
+      VG_UNDEF(ret_err,sizeof(*ret_err));
+      dec = opus_multistream_decoder_create(48000, 2, 1, 0, mapping, ret_err);
+      if(ret_err){VG_CHECK(ret_err,sizeof(*ret_err));}
+      if((ret_err && *ret_err!=OPUS_BAD_ARG) || dec!=NULL)test_failed();
+      cfgs++;
+
+      VG_UNDEF(ret_err,sizeof(*ret_err));
+      mapping[0]=mapping[1]=0;
+      dec = opus_multistream_decoder_create(48000, 2, 1, 0, mapping, ret_err);
+      if(ret_err){VG_CHECK(ret_err,sizeof(*ret_err));}
+      if((ret_err && *ret_err!=OPUS_OK) || dec==NULL)test_failed();
+      cfgs++;
+      opus_multistream_decoder_destroy(dec);
+      cfgs++;
+
+      VG_UNDEF(ret_err,sizeof(*ret_err));
+      dec = opus_multistream_decoder_create(48000, 1, 4, 1, mapping, ret_err);
+      if(ret_err){VG_CHECK(ret_err,sizeof(*ret_err));}
+      if((ret_err && *ret_err!=OPUS_OK) || dec==NULL)test_failed();
+      cfgs++;
+
+      err = opus_multistream_decoder_init(dec,48000, 1, 0, 0, mapping);
+      if(err!=OPUS_BAD_ARG)test_failed();
+      cfgs++;
+
+      err = opus_multistream_decoder_init(dec,48000, 1, 1, -1, mapping);
+      if(err!=OPUS_BAD_ARG)test_failed();
+      cfgs++;
+
+      opus_multistream_decoder_destroy(dec);
+      cfgs++;
+
+      VG_UNDEF(ret_err,sizeof(*ret_err));
+      dec = opus_multistream_decoder_create(48000, 2, 1, 1, mapping, ret_err);
+      if(ret_err){VG_CHECK(ret_err,sizeof(*ret_err));}
+      if((ret_err && *ret_err!=OPUS_OK) || dec==NULL)test_failed();
+      cfgs++;
+      opus_multistream_decoder_destroy(dec);
+      cfgs++;
+
+      VG_UNDEF(ret_err,sizeof(*ret_err));
+      dec = opus_multistream_decoder_create(48000, 255, 255, 1, mapping, ret_err);
+      if(ret_err){VG_CHECK(ret_err,sizeof(*ret_err));}
+      if((ret_err && *ret_err!=OPUS_BAD_ARG) || dec!=NULL)test_failed();
+      cfgs++;
+
+      VG_UNDEF(ret_err,sizeof(*ret_err));
+      dec = opus_multistream_decoder_create(48000, -1, 1, 1, mapping, ret_err);
+      if(ret_err){VG_CHECK(ret_err,sizeof(*ret_err));}
+      if((ret_err && *ret_err!=OPUS_BAD_ARG) || dec!=NULL)test_failed();
+      cfgs++;
+
+      VG_UNDEF(ret_err,sizeof(*ret_err));
+      dec = opus_multistream_decoder_create(48000, 0, 1, 1, mapping, ret_err);
+      if(ret_err){VG_CHECK(ret_err,sizeof(*ret_err));}
+      if((ret_err && *ret_err!=OPUS_BAD_ARG) || dec!=NULL)test_failed();
+      cfgs++;
+
+      VG_UNDEF(ret_err,sizeof(*ret_err));
+      dec = opus_multistream_decoder_create(48000, 1, -1, 2, mapping, ret_err);
+      if(ret_err){VG_CHECK(ret_err,sizeof(*ret_err));}
+      if((ret_err && *ret_err!=OPUS_BAD_ARG) || dec!=NULL)test_failed();
+      cfgs++;
+
+      VG_UNDEF(ret_err,sizeof(*ret_err));
+      dec = opus_multistream_decoder_create(48000, 1, -1, -1, mapping, ret_err);
+      if(ret_err){VG_CHECK(ret_err,sizeof(*ret_err));}
+      if((ret_err && *ret_err!=OPUS_BAD_ARG) || dec!=NULL)test_failed();
+      cfgs++;
+
+      VG_UNDEF(ret_err,sizeof(*ret_err));
+      dec = opus_multistream_decoder_create(48000, 256, 255, 1, mapping, ret_err);
+      if(ret_err){VG_CHECK(ret_err,sizeof(*ret_err));}
+      if((ret_err && *ret_err!=OPUS_BAD_ARG) || dec!=NULL)test_failed();
+      cfgs++;
+
+      VG_UNDEF(ret_err,sizeof(*ret_err));
+      dec = opus_multistream_decoder_create(48000, 256, 255, 0, mapping, ret_err);
+      if(ret_err){VG_CHECK(ret_err,sizeof(*ret_err));}
+      if((ret_err && *ret_err!=OPUS_BAD_ARG) || dec!=NULL)test_failed();
+      cfgs++;
+
+      VG_UNDEF(ret_err,sizeof(*ret_err));
+      mapping[0]=255;
+      mapping[1]=1;
+      mapping[2]=2;
+      dec = opus_multistream_decoder_create(48000, 3, 2, 0, mapping, ret_err);
+      if(ret_err){VG_CHECK(ret_err,sizeof(*ret_err));}
+      if((ret_err && *ret_err!=OPUS_BAD_ARG) || dec!=NULL)test_failed();
+      cfgs++;
+
+      VG_UNDEF(ret_err,sizeof(*ret_err));
+      mapping[0]=0;
+      mapping[1]=0;
+      mapping[2]=0;
+      dec = opus_multistream_decoder_create(48000, 3, 2, 1, mapping, ret_err);
+      if(ret_err){VG_CHECK(ret_err,sizeof(*ret_err));}
+      if((ret_err && *ret_err!=OPUS_OK) || dec==NULL)test_failed();
+      cfgs++;
+      opus_multistream_decoder_destroy(dec);
+      cfgs++;
+
+      VG_UNDEF(ret_err,sizeof(*ret_err));
+      mapping[0]=0;
+      mapping[1]=255;
+      mapping[2]=1;
+      mapping[3]=2;
+      mapping[4]=3;
+      dec = opus_multistream_decoder_create(48001, 5, 4, 1, mapping, ret_err);
+      if(ret_err){VG_CHECK(ret_err,sizeof(*ret_err));}
+      if((ret_err && *ret_err!=OPUS_BAD_ARG) || dec!=NULL)test_failed();
+      cfgs++;
+   }
+
+   VG_UNDEF(&err,sizeof(err));
+   mapping[0]=0;
+   mapping[1]=255;
+   mapping[2]=1;
+   mapping[3]=2;
+   dec = opus_multistream_decoder_create(48000, 4, 2, 1, mapping, &err);
+   VG_CHECK(&err,sizeof(err));
+   if(err!=OPUS_OK || dec==NULL)test_failed();
+   cfgs++;
+
+   fprintf(stdout,"    opus_multistream_decoder_create() ............ OK.\n");
+   fprintf(stdout,"    opus_multistream_decoder_init() .............. OK.\n");
+
+   VG_UNDEF(&dec_final_range,sizeof(dec_final_range));
+   err=opus_multistream_decoder_ctl(dec, OPUS_GET_FINAL_RANGE(&dec_final_range));
+   if(err!=OPUS_OK)test_failed();
+   VG_CHECK(&dec_final_range,sizeof(dec_final_range));
+   fprintf(stdout,"    OPUS_GET_FINAL_RANGE ......................... OK.\n");
+   cfgs++;
+
+   streamdec=0;
+   VG_UNDEF(&streamdec,sizeof(streamdec));
+   err=opus_multistream_decoder_ctl(dec, OPUS_MULTISTREAM_GET_DECODER_STATE(-1,&streamdec));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   err=opus_multistream_decoder_ctl(dec, OPUS_MULTISTREAM_GET_DECODER_STATE(1,&streamdec));
+   if(err!=OPUS_OK||streamdec==NULL)test_failed();
+   VG_CHECK(streamdec,opus_decoder_get_size(1));
+   cfgs++;
+   err=opus_multistream_decoder_ctl(dec, OPUS_MULTISTREAM_GET_DECODER_STATE(2,&streamdec));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   err=opus_multistream_decoder_ctl(dec, OPUS_MULTISTREAM_GET_DECODER_STATE(0,&streamdec));
+   if(err!=OPUS_OK||streamdec==NULL)test_failed();
+   VG_CHECK(streamdec,opus_decoder_get_size(1));
+   fprintf(stdout,"    OPUS_MULTISTREAM_GET_DECODER_STATE ........... OK.\n");
+   cfgs++;
+
+   for(j=0;j<2;j++)
+   {
+      OpusDecoder *od;
+      err=opus_multistream_decoder_ctl(dec,OPUS_MULTISTREAM_GET_DECODER_STATE(j,&od));
+      if(err != OPUS_OK)test_failed();
+      VG_UNDEF(&i,sizeof(i));
+      err=opus_decoder_ctl(od, OPUS_GET_GAIN(&i));
+      VG_CHECK(&i,sizeof(i));
+      if(err != OPUS_OK || i!=0)test_failed();
+      cfgs++;
+   }
+   err=opus_multistream_decoder_ctl(dec,OPUS_SET_GAIN(15));
+   if(err!=OPUS_OK)test_failed();
+   fprintf(stdout,"    OPUS_SET_GAIN ................................ OK.\n");
+   for(j=0;j<2;j++)
+   {
+      OpusDecoder *od;
+      err=opus_multistream_decoder_ctl(dec,OPUS_MULTISTREAM_GET_DECODER_STATE(j,&od));
+      if(err != OPUS_OK)test_failed();
+      VG_UNDEF(&i,sizeof(i));
+      err=opus_decoder_ctl(od, OPUS_GET_GAIN(&i));
+      VG_CHECK(&i,sizeof(i));
+      if(err != OPUS_OK || i!=15)test_failed();
+      cfgs++;
+   }
+   fprintf(stdout,"    OPUS_GET_GAIN ................................ OK.\n");
+
+   VG_UNDEF(&i,sizeof(i));
+   err=opus_multistream_decoder_ctl(dec, OPUS_GET_BANDWIDTH(&i));
+   if(err != OPUS_OK || i!=0)test_failed();
+   fprintf(stdout,"    OPUS_GET_BANDWIDTH ........................... OK.\n");
+   cfgs++;
+
+   err=opus_multistream_decoder_ctl(dec,OPUS_UNIMPLEMENTED);
+   if(err!=OPUS_UNIMPLEMENTED)test_failed();
+   fprintf(stdout,"    OPUS_UNIMPLEMENTED ........................... OK.\n");
+   cfgs++;
+
+#if 0
+   /*Currently unimplemented for multistream*/
+   /*GET_PITCH has different execution paths depending on the previously decoded frame.*/
+   err=opus_multistream_decoder_ctl(dec, OPUS_GET_PITCH(nullvalue));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   VG_UNDEF(&i,sizeof(i));
+   err=opus_multistream_decoder_ctl(dec, OPUS_GET_PITCH(&i));
+   if(err != OPUS_OK || i>0 || i<-1)test_failed();
+   cfgs++;
+   VG_UNDEF(packet,sizeof(packet));
+   packet[0]=63<<2;packet[1]=packet[2]=0;
+   if(opus_multistream_decode(dec, packet, 3, sbuf, 960, 0)!=960)test_failed();
+   cfgs++;
+   VG_UNDEF(&i,sizeof(i));
+   err=opus_multistream_decoder_ctl(dec, OPUS_GET_PITCH(&i));
+   if(err != OPUS_OK || i>0 || i<-1)test_failed();
+   cfgs++;
+   packet[0]=1;
+   if(opus_multistream_decode(dec, packet, 1, sbuf, 960, 0)!=960)test_failed();
+   cfgs++;
+   VG_UNDEF(&i,sizeof(i));
+   err=opus_multistream_decoder_ctl(dec, OPUS_GET_PITCH(&i));
+   if(err != OPUS_OK || i>0 || i<-1)test_failed();
+   cfgs++;
+   fprintf(stdout,"    OPUS_GET_PITCH ............................... OK.\n");
+#endif
+
+   /*Reset the decoder*/
+   if(opus_multistream_decoder_ctl(dec, OPUS_RESET_STATE)!=OPUS_OK)test_failed();
+   fprintf(stdout,"    OPUS_RESET_STATE ............................. OK.\n");
+   cfgs++;
+
+   opus_multistream_decoder_destroy(dec);
+   cfgs++;
+   VG_UNDEF(&err,sizeof(err));
+   dec = opus_multistream_decoder_create(48000, 2, 1, 1, mapping, &err);
+   if(err!=OPUS_OK || dec==NULL)test_failed();
+   cfgs++;
+
+   packet[0]=(63<<2)+3;
+   packet[1]=49;
+   for(j=2;j<51;j++)packet[j]=0;
+   VG_UNDEF(sbuf,sizeof(sbuf));
+   if(opus_multistream_decode(dec, packet, 51, sbuf, 960, 0)!=OPUS_INVALID_PACKET)test_failed();
+   cfgs++;
+   packet[0]=(63<<2);
+   packet[1]=packet[2]=0;
+   if(opus_multistream_decode(dec, packet, -1, sbuf, 960, 0)!=OPUS_BAD_ARG){printf("%d\n",opus_multistream_decode(dec, packet, -1, sbuf, 960, 0));test_failed();}
+   cfgs++;
+   if(opus_multistream_decode(dec, packet, 3, sbuf, 60, 0)!=OPUS_BUFFER_TOO_SMALL)test_failed();
+   cfgs++;
+   if(opus_multistream_decode(dec, packet, 3, sbuf, 480, 0)!=OPUS_BUFFER_TOO_SMALL)test_failed();
+   cfgs++;
+   if(opus_multistream_decode(dec, packet, 3, sbuf, 960, 0)!=960)test_failed();
+   cfgs++;
+   fprintf(stdout,"    opus_multistream_decode() .................... OK.\n");
+#ifndef DISABLE_FLOAT_API
+   VG_UNDEF(fbuf,sizeof(fbuf));
+   if(opus_multistream_decode_float(dec, packet, 3, fbuf, 960, 0)!=960)test_failed();
+   cfgs++;
+   fprintf(stdout,"    opus_multistream_decode_float() .............. OK.\n");
+#endif
+
+#if 0
+   /*These tests are disabled because the library crashes with null states*/
+   if(opus_multistream_decoder_ctl(0,OPUS_RESET_STATE)         !=OPUS_INVALID_STATE)test_failed();
+   if(opus_multistream_decoder_init(0,48000,1)                 !=OPUS_INVALID_STATE)test_failed();
+   if(opus_multistream_decode(0,packet,1,outbuf,2880,0)        !=OPUS_INVALID_STATE)test_failed();
+   if(opus_multistream_decode_float(0,packet,1,0,2880,0)       !=OPUS_INVALID_STATE)test_failed();
+   if(opus_multistream_decoder_get_nb_samples(0,packet,1)      !=OPUS_INVALID_STATE)test_failed();
+#endif
+   opus_multistream_decoder_destroy(dec);
+   cfgs++;
+   fprintf(stdout,"       All multistream decoder interface tests passed\n");
+   fprintf(stdout,"                             (%6d API invocations)\n",cfgs);
+   return cfgs;
+}
+
 #ifdef VALGRIND
 #define UNDEFINE_FOR_PARSE  toc=-1; \
    frames[0]=(unsigned char *)0; \
@@ -318,6 +724,7 @@ opus_int32 test_parse(void)
    /*code 0*/
    for(i=0;i<64;i++)
    {
+      packet[0]=i<<2;
       UNDEFINE_FOR_PARSE
       ret=opus_packet_parse(packet,4,&toc,frames,size,&payload_offset);
       cfgs++;
@@ -325,7 +732,7 @@ opus_int32 test_parse(void)
       if(size[0]!=3)test_failed();
       if(frames[0]!=packet+1)test_failed();
    }
-   fprintf(stdout,"    code 0 (%2d cases) ........................... OK.\n",cfgs);
+   fprintf(stdout,"    code 0 (%2d cases) ............................ OK.\n",cfgs);
    cfgs_total+=cfgs;cfgs=0;
 
    /*code 1, two frames of the same size*/
@@ -349,7 +756,7 @@ opus_int32 test_parse(void)
          } else if(ret!=OPUS_INVALID_PACKET)test_failed();
       }
    }
-   fprintf(stdout,"    code 1 (%6d cases) ....................... OK.\n",cfgs);
+   fprintf(stdout,"    code 1 (%6d cases) ........................ OK.\n",cfgs);
    cfgs_total+=cfgs;cfgs=0;
 
    for(i=0;i<64;i++)
@@ -397,7 +804,7 @@ opus_int32 test_parse(void)
          if((toc>>2)!=i)test_failed();
       }
    }
-   fprintf(stdout,"    code 2 (%6d cases) ....................... OK.\n",cfgs);
+   fprintf(stdout,"    code 2 (%6d cases) ........................ OK.\n",cfgs);
    cfgs_total+=cfgs;cfgs=0;
 
    for(i=0;i<64;i++)
@@ -409,7 +816,7 @@ opus_int32 test_parse(void)
       cfgs++;
       if(ret!=OPUS_INVALID_PACKET)test_failed();
    }
-   fprintf(stdout,"    code 3 m-truncation (%2d cases) .............. OK.\n",cfgs);
+   fprintf(stdout,"    code 3 m-truncation (%2d cases) ............... OK.\n",cfgs);
    cfgs_total+=cfgs;cfgs=0;
 
    for(i=0;i<64;i++)
@@ -440,7 +847,7 @@ opus_int32 test_parse(void)
         if(ret!=OPUS_INVALID_PACKET)test_failed();
       }
    }
-   fprintf(stdout,"    code 3 m=0,49-64 (%2d cases) ............... OK.\n",cfgs);
+   fprintf(stdout,"    code 3 m=0,49-64 (%2d cases) ................ OK.\n",cfgs);
    cfgs_total+=cfgs;cfgs=0;
 
    for(i=0;i<64;i++)
@@ -462,7 +869,7 @@ opus_int32 test_parse(void)
       cfgs++;
       if(ret!=OPUS_INVALID_PACKET)test_failed();
    }
-   fprintf(stdout,"    code 3 m=1 CBR (%2d cases) ................ OK.\n",cfgs);
+   fprintf(stdout,"    code 3 m=1 CBR (%2d cases) ................. OK.\n",cfgs);
    cfgs_total+=cfgs;cfgs=0;
 
    for(i=0;i<64;i++)
@@ -496,7 +903,7 @@ opus_int32 test_parse(void)
       if(ret!=packet[1])test_failed();
       for(jj=0;jj<ret;jj++)if(size[jj]!=1275)test_failed();
    }
-   fprintf(stdout,"    code 3 m=1-48 CBR (%2d cases) ......... OK.\n",cfgs);
+   fprintf(stdout,"    code 3 m=1-48 CBR (%2d cases) .......... OK.\n",cfgs);
    cfgs_total+=cfgs;cfgs=0;
 
    for(i=0;i<64;i++)
@@ -581,7 +988,7 @@ opus_int32 test_parse(void)
          }
       }
    }
-   fprintf(stdout,"    code 3 m=1-48 VBR (%2d cases) ............ OK.\n",cfgs);
+   fprintf(stdout,"    code 3 m=1-48 VBR (%2d cases) ............. OK.\n",cfgs);
    cfgs_total+=cfgs;cfgs=0;
 
    for(i=0;i<64;i++)
@@ -625,9 +1032,9 @@ opus_int32 test_parse(void)
          }
       }
    }
-   fprintf(stdout,"    code 3 padding (%2d cases) .............. OK.\n",cfgs);
-   cfgs_total+=cfgs;cfgs=0;
-   fprintf(stdout,"    opus_packet_parse ........................... OK.\n");
+   fprintf(stdout,"    code 3 padding (%2d cases) ............... OK.\n",cfgs);
+   cfgs_total+=cfgs;
+   fprintf(stdout,"    opus_packet_parse ............................ OK.\n");
    fprintf(stdout,"                      All packet parsing tests passed\n");
    fprintf(stdout,"                          (%d API invocations)\n",cfgs_total);
    return cfgs_total;
@@ -677,7 +1084,7 @@ opus_int32 test_enc_api(void)
    {
       i=opus_encoder_get_size(c);
       if(((c==1||c==2)&&(i<=2048||i>1<<17))||((c!=1&&c!=2)&&i!=0))test_failed();
-      fprintf(stdout,"    opus_encoder_get_size(%d)=%d ..............%s OK.\n",c,i,i>0?"":"....");
+      fprintf(stdout,"    opus_encoder_get_size(%d)=%d ...............%s OK.\n",c,i,i>0?"":"....");
       cfgs++;
    }
 
@@ -700,6 +1107,9 @@ opus_int32 test_enc_api(void)
          enc = opus_encoder_create(fs, c, OPUS_APPLICATION_VOIP, &err);
          if(err!=OPUS_BAD_ARG || enc!=NULL)test_failed();
          cfgs++;
+         enc = opus_encoder_create(fs, c, OPUS_APPLICATION_VOIP, 0);
+         if(enc!=NULL)test_failed();
+         cfgs++;
          opus_encoder_destroy(enc);
          enc=malloc(opus_encoder_get_size(2));
          if(enc==NULL)test_failed();
@@ -731,8 +1141,8 @@ opus_int32 test_enc_api(void)
    cfgs++;
    err=opus_encoder_ctl(enc,OPUS_GET_LOOKAHEAD(&i));
    if(err!=OPUS_OK || i<0 || i>32766)test_failed();
-   opus_encoder_destroy(enc);
    cfgs++;
+   opus_encoder_destroy(enc);
 
    VG_UNDEF(&err,sizeof(err));
    enc = opus_encoder_create(48000, 2, OPUS_APPLICATION_AUDIO, &err);
@@ -748,25 +1158,42 @@ opus_int32 test_enc_api(void)
    if(err!=OPUS_OK || enc==NULL)test_failed();
    cfgs++;
 
-   fprintf(stdout,"    opus_encoder_create() ....................... OK.\n");
-   fprintf(stdout,"    opus_encoder_init() ......................... OK.\n");
+   fprintf(stdout,"    opus_encoder_create() ........................ OK.\n");
+   fprintf(stdout,"    opus_encoder_init() .......................... OK.\n");
 
    i=-12345;
    VG_UNDEF(&i,sizeof(i));
    err=opus_encoder_ctl(enc,OPUS_GET_LOOKAHEAD(&i));
    if(err!=OPUS_OK || i<0 || i>32766)test_failed();
    cfgs++;
-   fprintf(stdout,"    OPUS_GET_LOOKAHEAD .......................... OK.\n");
+   err=opus_encoder_ctl(enc,OPUS_GET_LOOKAHEAD((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   fprintf(stdout,"    OPUS_GET_LOOKAHEAD ........................... OK.\n");
+
+   err=opus_encoder_ctl(enc,OPUS_GET_SAMPLE_RATE(&i));
+   if(err!=OPUS_OK || i!=48000)test_failed();
+   cfgs++;
+   err=opus_encoder_ctl(enc,OPUS_GET_SAMPLE_RATE((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   fprintf(stdout,"    OPUS_GET_SAMPLE_RATE ......................... OK.\n");
 
    if(opus_encoder_ctl(enc,OPUS_UNIMPLEMENTED)!=OPUS_UNIMPLEMENTED)test_failed();
-   fprintf(stdout,"    OPUS_UNIMPLEMENTED .......................... OK.\n");
+   fprintf(stdout,"    OPUS_UNIMPLEMENTED ........................... OK.\n");
    cfgs++;
 
+   err=opus_encoder_ctl(enc,OPUS_GET_APPLICATION((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
    CHECK_SETGET(OPUS_SET_APPLICATION(i),OPUS_GET_APPLICATION(&i),-1,OPUS_AUTO,
      OPUS_APPLICATION_AUDIO,OPUS_APPLICATION_RESTRICTED_LOWDELAY,
-     "    OPUS_SET_APPLICATION ........................ OK.\n",
-     "    OPUS_GET_APPLICATION ........................ OK.\n")
+     "    OPUS_SET_APPLICATION ......................... OK.\n",
+     "    OPUS_GET_APPLICATION ......................... OK.\n")
 
+   err=opus_encoder_ctl(enc,OPUS_GET_BITRATE((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
    if(opus_encoder_ctl(enc,OPUS_SET_BITRATE(1073741832))!=OPUS_OK)test_failed();
    cfgs++;
    VG_UNDEF(&i,sizeof(i));
@@ -775,13 +1202,16 @@ opus_int32 test_enc_api(void)
    cfgs++;
    CHECK_SETGET(OPUS_SET_BITRATE(i),OPUS_GET_BITRATE(&i),-12345,0,
      500,256000,
-     "    OPUS_SET_BITRATE ............................ OK.\n",
-     "    OPUS_GET_BITRATE ............................ OK.\n")
+     "    OPUS_SET_BITRATE ............................. OK.\n",
+     "    OPUS_GET_BITRATE ............................. OK.\n")
 
+   err=opus_encoder_ctl(enc,OPUS_GET_FORCE_CHANNELS((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
    CHECK_SETGET(OPUS_SET_FORCE_CHANNELS(i),OPUS_GET_FORCE_CHANNELS(&i),-1,3,
      1,OPUS_AUTO,
-     "    OPUS_SET_FORCE_CHANNELS ..................... OK.\n",
-     "    OPUS_GET_FORCE_CHANNELS ..................... OK.\n")
+     "    OPUS_SET_FORCE_CHANNELS ...................... OK.\n",
+     "    OPUS_GET_FORCE_CHANNELS ...................... OK.\n")
 
    i=-2;
    if(opus_encoder_ctl(enc,OPUS_SET_BANDWIDTH(i))==OPUS_OK)test_failed();
@@ -801,7 +1231,7 @@ opus_int32 test_enc_api(void)
    i=OPUS_BANDWIDTH_MEDIUMBAND;
    if(opus_encoder_ctl(enc,OPUS_SET_BANDWIDTH(i))!=OPUS_OK)test_failed();
    cfgs++;
-   fprintf(stdout,"    OPUS_SET_BANDWIDTH .......................... OK.\n");
+   fprintf(stdout,"    OPUS_SET_BANDWIDTH ........................... OK.\n");
    /*We don't test if the bandwidth has actually changed.
      because the change may be delayed until the encoder is advanced.*/
    i=-12345;
@@ -813,7 +1243,10 @@ opus_int32 test_enc_api(void)
    cfgs++;
    if(opus_encoder_ctl(enc,OPUS_SET_BANDWIDTH(OPUS_AUTO))!=OPUS_OK)test_failed();
    cfgs++;
-   fprintf(stdout,"    OPUS_GET_BANDWIDTH .......................... OK.\n");
+   err=opus_encoder_ctl(enc,OPUS_GET_BANDWIDTH((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   fprintf(stdout,"    OPUS_GET_BANDWIDTH ........................... OK.\n");
 
    i=-2;
    if(opus_encoder_ctl(enc,OPUS_SET_MAX_BANDWIDTH(i))==OPUS_OK)test_failed();
@@ -833,7 +1266,7 @@ opus_int32 test_enc_api(void)
    i=OPUS_BANDWIDTH_MEDIUMBAND;
    if(opus_encoder_ctl(enc,OPUS_SET_MAX_BANDWIDTH(i))!=OPUS_OK)test_failed();
    cfgs++;
-   fprintf(stdout,"    OPUS_SET_MAX_BANDWIDTH ...................... OK.\n");
+   fprintf(stdout,"    OPUS_SET_MAX_BANDWIDTH ....................... OK.\n");
    /*We don't test if the bandwidth has actually changed.
      because the change may be delayed until the encoder is advanced.*/
    i=-12345;
@@ -843,59 +1276,140 @@ opus_int32 test_enc_api(void)
       i!=OPUS_BANDWIDTH_MEDIUMBAND&&i!=OPUS_BANDWIDTH_WIDEBAND&&
       i!=OPUS_BANDWIDTH_FULLBAND))test_failed();
    cfgs++;
-   fprintf(stdout,"    OPUS_GET_MAX_BANDWIDTH ...................... OK.\n");
+   err=opus_encoder_ctl(enc,OPUS_GET_MAX_BANDWIDTH((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   fprintf(stdout,"    OPUS_GET_MAX_BANDWIDTH ....................... OK.\n");
 
+   err=opus_encoder_ctl(enc,OPUS_GET_DTX((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
    CHECK_SETGET(OPUS_SET_DTX(i),OPUS_GET_DTX(&i),-1,2,
      1,0,
-     "    OPUS_SET_DTX ................................ OK.\n",
-     "    OPUS_GET_DTX ................................ OK.\n")
+     "    OPUS_SET_DTX ................................. OK.\n",
+     "    OPUS_GET_DTX ................................. OK.\n")
 
+   err=opus_encoder_ctl(enc,OPUS_GET_COMPLEXITY((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
    CHECK_SETGET(OPUS_SET_COMPLEXITY(i),OPUS_GET_COMPLEXITY(&i),-1,11,
      0,10,
-     "    OPUS_SET_COMPLEXITY ......................... OK.\n",
-     "    OPUS_GET_COMPLEXITY ......................... OK.\n")
+     "    OPUS_SET_COMPLEXITY .......................... OK.\n",
+     "    OPUS_GET_COMPLEXITY .......................... OK.\n")
 
+   err=opus_encoder_ctl(enc,OPUS_GET_INBAND_FEC((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
    CHECK_SETGET(OPUS_SET_INBAND_FEC(i),OPUS_GET_INBAND_FEC(&i),-1,2,
      1,0,
-     "    OPUS_SET_INBAND_FEC ......................... OK.\n",
-     "    OPUS_GET_INBAND_FEC ......................... OK.\n")
+     "    OPUS_SET_INBAND_FEC .......................... OK.\n",
+     "    OPUS_GET_INBAND_FEC .......................... OK.\n")
 
+   err=opus_encoder_ctl(enc,OPUS_GET_PACKET_LOSS_PERC((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
    CHECK_SETGET(OPUS_SET_PACKET_LOSS_PERC(i),OPUS_GET_PACKET_LOSS_PERC(&i),-1,101,
      100,0,
-     "    OPUS_SET_PACKET_LOSS_PERC ................... OK.\n",
-     "    OPUS_GET_PACKET_LOSS_PERC ................... OK.\n")
+     "    OPUS_SET_PACKET_LOSS_PERC .................... OK.\n",
+     "    OPUS_GET_PACKET_LOSS_PERC .................... OK.\n")
 
+   err=opus_encoder_ctl(enc,OPUS_GET_VBR((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
    CHECK_SETGET(OPUS_SET_VBR(i),OPUS_GET_VBR(&i),-1,2,
      1,0,
-     "    OPUS_SET_VBR ................................ OK.\n",
-     "    OPUS_GET_VBR ................................ OK.\n")
+     "    OPUS_SET_VBR ................................. OK.\n",
+     "    OPUS_GET_VBR ................................. OK.\n")
 
-   /*CHECK_SETGET(OPUS_SET_VOICE_RATIO(i),OPUS_GET_VOICE_RATIO(&i),-2,101,
+/*   err=opus_encoder_ctl(enc,OPUS_GET_VOICE_RATIO((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   CHECK_SETGET(OPUS_SET_VOICE_RATIO(i),OPUS_GET_VOICE_RATIO(&i),-2,101,
      0,50,
-     "    OPUS_SET_VOICE_RATIO ........................ OK.\n",
-     "    OPUS_GET_VOICE_RATIO ........................ OK.\n")
-   */
+     "    OPUS_SET_VOICE_RATIO ......................... OK.\n",
+     "    OPUS_GET_VOICE_RATIO ......................... OK.\n")*/
 
+   err=opus_encoder_ctl(enc,OPUS_GET_VBR_CONSTRAINT((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
    CHECK_SETGET(OPUS_SET_VBR_CONSTRAINT(i),OPUS_GET_VBR_CONSTRAINT(&i),-1,2,
      1,0,
-     "    OPUS_SET_VBR_CONSTRAINT ..................... OK.\n",
-     "    OPUS_GET_VBR_CONSTRAINT ..................... OK.\n")
+     "    OPUS_SET_VBR_CONSTRAINT ...................... OK.\n",
+     "    OPUS_GET_VBR_CONSTRAINT ...................... OK.\n")
 
+   err=opus_encoder_ctl(enc,OPUS_GET_SIGNAL((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
    CHECK_SETGET(OPUS_SET_SIGNAL(i),OPUS_GET_SIGNAL(&i),-12345,0x7FFFFFFF,
      OPUS_SIGNAL_MUSIC,OPUS_AUTO,
-     "    OPUS_SET_SIGNAL ............................. OK.\n",
-     "    OPUS_GET_SIGNAL ............................. OK.\n")
+     "    OPUS_SET_SIGNAL .............................. OK.\n",
+     "    OPUS_GET_SIGNAL .............................. OK.\n")
+
+   err=opus_encoder_ctl(enc,OPUS_GET_LSB_DEPTH((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   CHECK_SETGET(OPUS_SET_LSB_DEPTH(i),OPUS_GET_LSB_DEPTH(&i),7,25,16,24,
+     "    OPUS_SET_LSB_DEPTH ........................... OK.\n",
+     "    OPUS_GET_LSB_DEPTH ........................... OK.\n")
+
+   err=opus_encoder_ctl(enc,OPUS_GET_PREDICTION_DISABLED(&i));
+   if(i!=0)test_failed();
+   cfgs++;
+   err=opus_encoder_ctl(enc,OPUS_GET_PREDICTION_DISABLED((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   CHECK_SETGET(OPUS_SET_PREDICTION_DISABLED(i),OPUS_GET_PREDICTION_DISABLED(&i),-1,2,1,0,
+     "    OPUS_SET_PREDICTION_DISABLED ................. OK.\n",
+     "    OPUS_GET_PREDICTION_DISABLED ................. OK.\n")
+
+   err=opus_encoder_ctl(enc,OPUS_GET_EXPERT_FRAME_DURATION((opus_int32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_2_5_MS));
+   if(err!=OPUS_OK)test_failed();
+   cfgs++;
+   err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_5_MS));
+   if(err!=OPUS_OK)test_failed();
+   cfgs++;
+   err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_10_MS));
+   if(err!=OPUS_OK)test_failed();
+   cfgs++;
+   err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_20_MS));
+   if(err!=OPUS_OK)test_failed();
+   cfgs++;
+   err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_40_MS));
+   if(err!=OPUS_OK)test_failed();
+   cfgs++;
+   err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_60_MS));
+   if(err!=OPUS_OK)test_failed();
+   cfgs++;
+   err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_80_MS));
+   if(err!=OPUS_OK)test_failed();
+   cfgs++;
+   err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_100_MS));
+   if(err!=OPUS_OK)test_failed();
+   cfgs++;
+   err=opus_encoder_ctl(enc,OPUS_SET_EXPERT_FRAME_DURATION(OPUS_FRAMESIZE_120_MS));
+   if(err!=OPUS_OK)test_failed();
+   cfgs++;
+   CHECK_SETGET(OPUS_SET_EXPERT_FRAME_DURATION(i),OPUS_GET_EXPERT_FRAME_DURATION(&i),0,-1,
+         OPUS_FRAMESIZE_60_MS,OPUS_FRAMESIZE_ARG,
+     "    OPUS_SET_EXPERT_FRAME_DURATION ............... OK.\n",
+     "    OPUS_GET_EXPERT_FRAME_DURATION ............... OK.\n")
 
    /*OPUS_SET_FORCE_MODE is not tested here because it's not a public API, however the encoder tests use it*/
 
+   err=opus_encoder_ctl(enc,OPUS_GET_FINAL_RANGE((opus_uint32 *)NULL));
+   if(err!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
    if(opus_encoder_ctl(enc,OPUS_GET_FINAL_RANGE(&enc_final_range))!=OPUS_OK)test_failed();
    cfgs++;
-   fprintf(stdout,"    OPUS_GET_FINAL_RANGE ........................ OK.\n");
+   fprintf(stdout,"    OPUS_GET_FINAL_RANGE ......................... OK.\n");
 
    /*Reset the encoder*/
    if(opus_encoder_ctl(enc, OPUS_RESET_STATE)!=OPUS_OK)test_failed();
    cfgs++;
-   fprintf(stdout,"    OPUS_RESET_STATE ............................ OK.\n");
+   fprintf(stdout,"    OPUS_RESET_STATE ............................. OK.\n");
 
    memset(sbuf,0,sizeof(short)*2*960);
    VG_UNDEF(packet,sizeof(packet));
@@ -903,7 +1417,7 @@ opus_int32 test_enc_api(void)
    if(i<1 || (i>(opus_int32)sizeof(packet)))test_failed();
    VG_CHECK(packet,i);
    cfgs++;
-   fprintf(stdout,"    opus_encode() ............................... OK.\n");
+   fprintf(stdout,"    opus_encode() ................................ OK.\n");
 #ifndef DISABLE_FLOAT_API
    memset(fbuf,0,sizeof(float)*2*960);
    VG_UNDEF(packet,sizeof(packet));
@@ -911,7 +1425,7 @@ opus_int32 test_enc_api(void)
    if(i<1 || (i>(opus_int32)sizeof(packet)))test_failed();
    VG_CHECK(packet,i);
    cfgs++;
-   fprintf(stdout,"    opus_encode_float() ......................... OK.\n");
+   fprintf(stdout,"    opus_encode_float() .......................... OK.\n");
 #endif
 
 #if 0
@@ -941,30 +1455,30 @@ int test_repacketizer_api(void)
 
    packet=malloc(max_out);
    if(packet==NULL)test_failed();
-   po=malloc(max_out);
-   if(po==NULL)test_failed();
    memset(packet,0,max_out);
+   po=malloc(max_out+256);
+   if(po==NULL)test_failed();
 
    i=opus_repacketizer_get_size();
    if(i<=0)test_failed();
    cfgs++;
-   fprintf(stdout,"    opus_repacketizer_get_size()=%d ............ OK.\n",i);
+   fprintf(stdout,"    opus_repacketizer_get_size()=%d ............. OK.\n",i);
 
    rp=malloc(i);
    rp=opus_repacketizer_init(rp);
    if(rp==NULL)test_failed();
    cfgs++;
    free(rp);
-   fprintf(stdout,"    opus_repacketizer_init ...................... OK.\n");
+   fprintf(stdout,"    opus_repacketizer_init ....................... OK.\n");
 
    rp=opus_repacketizer_create();
    if(rp==NULL)test_failed();
    cfgs++;
-   fprintf(stdout,"    opus_repacketizer_create .................... OK.\n");
+   fprintf(stdout,"    opus_repacketizer_create ..................... OK.\n");
 
    if(opus_repacketizer_get_nb_frames(rp)!=0)test_failed();
    cfgs++;
-   fprintf(stdout,"    opus_repacketizer_get_nb_frames ............. OK.\n");
+   fprintf(stdout,"    opus_repacketizer_get_nb_frames .............. OK.\n");
 
    /*Length overflows*/
    VG_UNDEF(packet,4);
@@ -1033,7 +1547,7 @@ int test_repacketizer_api(void)
                rcnt=k<=(1275*i)?(cnt<maxp?cnt:maxp):0;
                if(opus_repacketizer_get_nb_frames(rp)!=rcnt*i)test_failed();
                cfgs++;
-               ret=opus_repacketizer_out(rp,po,max_out);
+               ret=opus_repacketizer_out_range(rp,0,rcnt*i,po,max_out);
                if(rcnt>0)
                {
                   int len;
@@ -1045,6 +1559,22 @@ int test_repacketizer_api(void)
                   cfgs++;
                   if(opus_repacketizer_out(rp,po,len)!=len)test_failed();
                   cfgs++;
+                  if(opus_packet_unpad(po,len)!=len)test_failed();
+                  cfgs++;
+                  if(opus_packet_pad(po,len,len+1)!=OPUS_OK)test_failed();
+                  cfgs++;
+                  if(opus_packet_pad(po,len+1,len+256)!=OPUS_OK)test_failed();
+                  cfgs++;
+                  if(opus_packet_unpad(po,len+256)!=len)test_failed();
+                  cfgs++;
+                  if(opus_multistream_packet_unpad(po,len,1)!=len)test_failed();
+                  cfgs++;
+                  if(opus_multistream_packet_pad(po,len,len+1,1)!=OPUS_OK)test_failed();
+                  cfgs++;
+                  if(opus_multistream_packet_pad(po,len+1,len+256,1)!=OPUS_OK)test_failed();
+                  cfgs++;
+                  if(opus_multistream_packet_unpad(po,len+256,1)!=len)test_failed();
+                  cfgs++;
                   if(opus_repacketizer_out(rp,po,len-1)!=OPUS_BUFFER_TOO_SMALL)test_failed();
                   cfgs++;
                   if(len>1)
@@ -1071,6 +1601,13 @@ int test_repacketizer_api(void)
    cfgs++;
    i=opus_repacketizer_out(rp,po,max_out);
    if((i!=(4+8+2))||((po[0]&3)!=3)||((po[1]&63)!=3)||((po[1]>>7)!=0))test_failed();
+   cfgs++;
+   i=opus_repacketizer_out_range(rp,0,1,po,max_out);
+   if(i!=5||(po[0]&3)!=0)test_failed();
+   cfgs++;
+   i=opus_repacketizer_out_range(rp,1,2,po,max_out);
+   if(i!=5||(po[0]&3)!=0)test_failed();
+   cfgs++;
 
    /*Change in input count code, VBR out*/
    opus_repacketizer_init(rp);
@@ -1082,6 +1619,7 @@ int test_repacketizer_api(void)
    cfgs++;
    i=opus_repacketizer_out(rp,po,max_out);
    if((i!=(2+8+2+2))||((po[0]&3)!=3)||((po[1]&63)!=3)||((po[1]>>7)!=1))test_failed();
+   cfgs++;
 
    /*VBR in, VBR out*/
    opus_repacketizer_init(rp);
@@ -1093,6 +1631,7 @@ int test_repacketizer_api(void)
    cfgs++;
    i=opus_repacketizer_out(rp,po,max_out);
    if((i!=(2+1+1+1+4+2+4+2))||((po[0]&3)!=3)||((po[1]&63)!=4)||((po[1]>>7)!=1))test_failed();
+   cfgs++;
 
    /*VBR in, CBR out*/
    opus_repacketizer_init(rp);
@@ -1104,6 +1643,7 @@ int test_repacketizer_api(void)
    cfgs++;
    i=opus_repacketizer_out(rp,po,max_out);
    if((i!=(2+4+4+4+4))||((po[0]&3)!=3)||((po[1]&63)!=4)||((po[1]>>7)!=0))test_failed();
+   cfgs++;
 
    /*Count 0 in, VBR out*/
    for(j=0;j<32;j++)
@@ -1134,6 +1674,22 @@ int test_repacketizer_api(void)
          cfgs++;
          if(opus_repacketizer_out(rp,po,len)!=len)test_failed();
          cfgs++;
+         if(opus_packet_unpad(po,len)!=len)test_failed();
+         cfgs++;
+         if(opus_packet_pad(po,len,len+1)!=OPUS_OK)test_failed();
+         cfgs++;
+         if(opus_packet_pad(po,len+1,len+256)!=OPUS_OK)test_failed();
+         cfgs++;
+         if(opus_packet_unpad(po,len+256)!=len)test_failed();
+         cfgs++;
+         if(opus_multistream_packet_unpad(po,len,1)!=len)test_failed();
+         cfgs++;
+         if(opus_multistream_packet_pad(po,len,len+1,1)!=OPUS_OK)test_failed();
+         cfgs++;
+         if(opus_multistream_packet_pad(po,len+1,len+256,1)!=OPUS_OK)test_failed();
+         cfgs++;
+         if(opus_multistream_packet_unpad(po,len+256,1)!=len)test_failed();
+         cfgs++;
          if(opus_repacketizer_out(rp,po,len-1)!=OPUS_BUFFER_TOO_SMALL)test_failed();
          cfgs++;
          if(len>1)
@@ -1146,8 +1702,43 @@ int test_repacketizer_api(void)
       }
    }
 
-   fprintf(stdout,"    opus_repacketizer_cat ....................... OK.\n");
-   fprintf(stdout,"    opus_repacketizer_out ....................... OK.\n");
+   po[0]='O';
+   po[1]='p';
+   if(opus_packet_pad(po,4,4)!=OPUS_OK)test_failed();
+   cfgs++;
+   if(opus_multistream_packet_pad(po,4,4,1)!=OPUS_OK)test_failed();
+   cfgs++;
+   if(opus_packet_pad(po,4,5)!=OPUS_INVALID_PACKET)test_failed();
+   cfgs++;
+   if(opus_multistream_packet_pad(po,4,5,1)!=OPUS_INVALID_PACKET)test_failed();
+   cfgs++;
+   if(opus_packet_pad(po,0,5)!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   if(opus_multistream_packet_pad(po,0,5,1)!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   if(opus_packet_unpad(po,0)!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   if(opus_multistream_packet_unpad(po,0,1)!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   if(opus_packet_unpad(po,4)!=OPUS_INVALID_PACKET)test_failed();
+   cfgs++;
+   if(opus_multistream_packet_unpad(po,4,1)!=OPUS_INVALID_PACKET)test_failed();
+   cfgs++;
+   po[0]=0;
+   po[1]=0;
+   po[2]=0;
+   if(opus_packet_pad(po,5,4)!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+   if(opus_multistream_packet_pad(po,5,4,1)!=OPUS_BAD_ARG)test_failed();
+   cfgs++;
+
+   fprintf(stdout,"    opus_repacketizer_cat ........................ OK.\n");
+   fprintf(stdout,"    opus_repacketizer_out ........................ OK.\n");
+   fprintf(stdout,"    opus_repacketizer_out_range .................. OK.\n");
+   fprintf(stdout,"    opus_packet_pad .............................. OK.\n");
+   fprintf(stdout,"    opus_packet_unpad ............................ OK.\n");
+   fprintf(stdout,"    opus_multistream_packet_pad .................. OK.\n");
+   fprintf(stdout,"    opus_multistream_packet_unpad ................ OK.\n");
 
    opus_repacketizer_destroy(rp);
    cfgs++;
@@ -1162,16 +1753,16 @@ int test_repacketizer_api(void)
 #ifdef MALLOC_FAIL
 /* GLIBC 2.14 declares __malloc_hook as deprecated, generating a warning
  * under GCC. However, this is the cleanest way to test malloc failure
- * handling in our codebase, and the lack of thread saftey isn't an
+ * handling in our codebase, and the lack of thread safety isn't an
  * issue here. We therefore disable the warning for this function.
  */
-#if defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 6
+#if OPUS_GNUC_PREREQ(4,6)
 /* Save the current warning settings */
 #pragma GCC diagnostic push
 #endif
 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 
-typedef void *(*mhook)(size_t __size, __const __malloc_ptr_t);
+typedef void *(*mhook)(size_t __size, __const void *);
 #endif
 
 int test_malloc_fail(void)
@@ -1180,6 +1771,9 @@ int test_malloc_fail(void)
    OpusDecoder *dec;
    OpusEncoder *enc;
    OpusRepacketizer *rp;
+   unsigned char mapping[256] = {0,1};
+   OpusMSDecoder *msdec;
+   OpusMSEncoder *msenc;
    int rate,c,app,cfgs,err,useerr;
    int *ep;
    mhook orig_malloc;
@@ -1196,9 +1790,11 @@ int test_malloc_fail(void)
       if(ep)free(ep);
       __malloc_hook=orig_malloc;
 #endif
-      fprintf(stdout,"    opus_decoder_create() .................. SKIPPED.\n");
-      fprintf(stdout,"    opus_encoder_create() .................. SKIPPED.\n");
-      fprintf(stdout,"    opus_repacketizer_create() ............. SKIPPED.\n");
+      fprintf(stdout,"    opus_decoder_create() ................... SKIPPED.\n");
+      fprintf(stdout,"    opus_encoder_create() ................... SKIPPED.\n");
+      fprintf(stdout,"    opus_repacketizer_create() .............. SKIPPED.\n");
+      fprintf(stdout,"    opus_multistream_decoder_create() ....... SKIPPED.\n");
+      fprintf(stdout,"    opus_multistream_encoder_create() ....... SKIPPED.\n");
       fprintf(stdout,"(Test only supported with GLIBC and without valgrind)\n");
       return 0;
 #ifdef MALLOC_FAIL
@@ -1222,6 +1818,13 @@ int test_malloc_fail(void)
               test_failed();
            }
            cfgs++;
+           msdec=opus_multistream_decoder_create(opus_rates[rate], c, 1, c-1, mapping, ep);
+           if(msdec!=NULL||(useerr&&err!=OPUS_ALLOC_FAIL))
+           {
+              __malloc_hook=orig_malloc;
+              test_failed();
+           }
+           cfgs++;
            for(app=0;app<3;app++)
            {
               if(useerr)
@@ -1235,6 +1838,13 @@ int test_malloc_fail(void)
                  test_failed();
               }
               cfgs++;
+              msenc=opus_multistream_encoder_create(opus_rates[rate], c, 1, c-1, mapping, opus_apps[app],ep);
+              if(msenc!=NULL||(useerr&&err!=OPUS_ALLOC_FAIL))
+              {
+                 __malloc_hook=orig_malloc;
+                 test_failed();
+              }
+              cfgs++;
            }
         }
      }
@@ -1247,9 +1857,11 @@ int test_malloc_fail(void)
    }
    cfgs++;
    __malloc_hook=orig_malloc;
-   fprintf(stdout,"    opus_decoder_create() ....................... OK.\n");
-   fprintf(stdout,"    opus_encoder_create() ....................... OK.\n");
-   fprintf(stdout,"    opus_repacketizer_create() .................. OK.\n");
+   fprintf(stdout,"    opus_decoder_create() ........................ OK.\n");
+   fprintf(stdout,"    opus_encoder_create() ........................ OK.\n");
+   fprintf(stdout,"    opus_repacketizer_create() ................... OK.\n");
+   fprintf(stdout,"    opus_multistream_decoder_create() ............ OK.\n");
+   fprintf(stdout,"    opus_multistream_encoder_create() ............ OK.\n");
    fprintf(stdout,"                      All malloc failure tests passed\n");
    fprintf(stdout,"                                 (%2d API invocations)\n",cfgs);
    return cfgs;
@@ -1257,8 +1869,7 @@ int test_malloc_fail(void)
 }
 
 #ifdef MALLOC_FAIL
-#if defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 6
-/* Restore the previous warning settings */
+#if __GNUC_PREREQ(4,6)
 #pragma GCC diagnostic pop /* restore -Wdeprecated-declarations */
 #endif
 #endif
@@ -1283,6 +1894,7 @@ int main(int _argc, char **_argv)
    total=4;
 
    total+=test_dec_api();
+   total+=test_msdec_api();
    total+=test_parse();
    total+=test_enc_api();
    total+=test_repacketizer_api();