internal static int RunTest2(bool no_fuzz)
        {
            byte[]        mapping /*[256]*/ = { 0, 1, 255 };
            byte[]        db62 = new byte[36];
            int           i;
            int           rc, j;
            BoxedValueInt err = new BoxedValueInt(0);
            OpusMSEncoder MSenc;
            OpusMSDecoder MSdec;
            OpusMSDecoder MSdec_err;

            OpusDecoder[] dec_err = new OpusDecoder[10];
            short[]       inbuf;
            short[]       out2buf;
            byte[]        packet = new byte[MAX_PACKET + 257];
            uint          enc_final_range;
            uint          dec_final_range;
            int           count;

            inbuf   = new short[SAMPLES * 2];
            out2buf = new short[MAX_FRAME_SAMP * 3];
            if (inbuf == null || out2buf == null)
            {
                TestFailed();
            }

            GenerateMusic(inbuf.GetPointer(), SAMPLES);

            for (i = 0; i < 2; i++)
            {
                try
                {
                    MSenc = OpusMSEncoder.Create(8000, 2, 2, 0, mapping, OpusApplication.OPUS_APPLICATION_UNIMPLEMENTED); TestFailed();
                }
                catch (ArgumentException) { }
                try
                {
                    MSenc = OpusMSEncoder.Create(8000, 0, 1, 0, mapping, OpusApplication.VOIP); TestFailed();
                }
                catch (ArgumentException) { }
                try
                {
                    MSenc = OpusMSEncoder.Create(44100, 2, 2, 0, mapping, OpusApplication.VOIP); TestFailed();
                }
                catch (ArgumentException) { }
                try
                {
                    MSenc = OpusMSEncoder.Create(8000, 2, 2, 3, mapping, OpusApplication.VOIP); TestFailed();
                }
                catch (ArgumentException) { }
                try
                {
                    MSenc = OpusMSEncoder.Create(8000, 2, -1, 0, mapping, OpusApplication.VOIP); TestFailed();
                }
                catch (ArgumentException) { }
                try
                {
                    MSenc = OpusMSEncoder.Create(8000, 256, 2, 0, mapping, OpusApplication.VOIP); TestFailed();
                }
                catch (ArgumentException) { }
            }

            MSenc = OpusMSEncoder.Create(8000, 2, 2, 0, mapping, OpusApplication.AUDIO);
            if (err.Val != OpusError.OPUS_OK || MSenc == null)
            {
                TestFailed();
            }

            MSdec = new OpusMSDecoder(48000, 2, 2, 0, mapping);
            if (err.Val != OpusError.OPUS_OK || MSdec == null)
            {
                TestFailed();
            }

            MSdec_err = new OpusMSDecoder(48000, 3, 2, 0, mapping);
            if (err.Val != OpusError.OPUS_OK || MSdec_err == null)
            {
                TestFailed();
            }

            /*Some multistream encoder API tests*/
            i = MSenc.Bitrate;
            i = MSenc.LSBDepth;
            if (i < 16)
            {
                TestFailed();
            }

            {
                OpusEncoder tmp_enc;
                tmp_enc = MSenc.GetMultistreamEncoderState(1);
                if (tmp_enc == null)
                {
                    TestFailed();
                }
                j = tmp_enc.LSBDepth;
                if (i != j)
                {
                    TestFailed();
                }
                try
                {
                    MSenc.GetMultistreamEncoderState(2);
                    TestFailed();
                }
                catch (ArgumentException) { }
            }

            OpusMode[] modes = { OpusMode.MODE_SILK_ONLY, OpusMode.MODE_SILK_ONLY, OpusMode.MODE_SILK_ONLY, OpusMode.MODE_SILK_ONLY, OpusMode.MODE_SILK_ONLY, OpusMode.MODE_SILK_ONLY, OpusMode.MODE_SILK_ONLY, OpusMode.MODE_SILK_ONLY, OpusMode.MODE_CELT_ONLY, OpusMode.MODE_CELT_ONLY, OpusMode.MODE_CELT_ONLY, OpusMode.MODE_CELT_ONLY, OpusMode.MODE_CELT_ONLY, OpusMode.MODE_CELT_ONLY, OpusMode.MODE_CELT_ONLY, OpusMode.MODE_CELT_ONLY };
            int[]      rates = { 4000, 12000, 32000, 8000, 16000, 32000, 48000, 88000, 4000, 12000, 32000, 8000, 16000, 32000, 48000, 88000 };
            int[]      frame = { 160 * 1, 160, 80, 160, 160, 80, 40, 20, 160 * 1, 160, 80, 160, 160, 80, 40, 20 };

            for (rc = 0; rc < 3; rc++)
            {
                MSenc.UseVBR            = (rc < 2);
                MSenc.UseConstrainedVBR = (rc == 1);
                MSenc.UseInbandFEC      = (rc == 0);
                for (j = 0; j < 16; j++)
                {
                    int rate;
                    MSenc.UseInbandFEC = (rc == 0 && j == 1);
                    MSenc.ForceMode    = (modes[j]);
                    rate          = rates[j] + ((int)FastRand() % rates[j]);
                    MSenc.UseDTX  = ((FastRand() & 1U) != 0);
                    MSenc.Bitrate = (rate);
                    count         = i = 0;
                    do
                    {
                        int  len, out_samples, frame_size;
                        bool loss;
                        bool pred = MSenc.PredictionDisabled;
                        MSenc.PredictionDisabled = ((int)(FastRand() & 15) < (pred ? 11 : 4));
                        frame_size              = frame[j];
                        MSenc.Complexity        = ((count >> 2) % 11);
                        MSenc.PacketLossPercent = (((int)FastRand() & 15) & ((int)FastRand() % 15));
                        if ((FastRand() & 255) == 0)
                        {
                            MSenc.ResetState();
                            MSdec.ResetState();
                            if ((FastRand() & 3) != 0)
                            {
                                MSdec_err.ResetState();
                            }
                        }
                        if ((FastRand() & 255) == 0)
                        {
                            MSdec_err.ResetState();
                        }
                        len = MSenc.EncodeMultistream(inbuf, i << 1, frame_size, packet, 0, MAX_PACKET);
                        if (len < 0 || len > MAX_PACKET)
                        {
                            TestFailed();
                        }
                        enc_final_range = MSenc.FinalRange;
                        if ((FastRand() & 3) == 0)
                        {
                            if (OpusRepacketizer.PadMultistreamPacket(packet, 0, len, len + 1, 2) != OpusError.OPUS_OK)
                            {
                                TestFailed();
                            }
                            len++;
                        }
                        if ((FastRand() & 7) == 0)
                        {
                            if (OpusRepacketizer.PadMultistreamPacket(packet, 0, len, len + 256, 2) != OpusError.OPUS_OK)
                            {
                                TestFailed();
                            }
                            len += 256;
                        }
                        //if ((fast_rand() & 3) == 0)
                        //{
                        //    len = Repacketizer.opus_multistream_packet_unpad(packet, len, 2);
                        //    if (len < 1) test_failed();
                        //}
                        out_samples = MSdec.DecodeMultistream(packet, 0, len, out2buf, 0, MAX_FRAME_SAMP, 0);
                        if (out_samples != frame_size * 6)
                        {
                            TestFailed();
                        }
                        dec_final_range = MSdec.FinalRange;
                        if (enc_final_range != dec_final_range)
                        {
                            TestFailed();
                        }
                        /*LBRR decode*/
                        loss        = (FastRand() & 63) == 0;
                        out_samples = MSdec_err.DecodeMultistream(packet, 0, loss ? 0 : len, out2buf, 0, frame_size * 6, ((FastRand() & 3) != 0) ? 1 : 0);
                        if (out_samples != (frame_size * 6))
                        {
                            TestFailed();
                        }
                        i += frame_size;
                        count++;
                    } while (i < (SSAMPLES / 12 - MAX_FRAME_SAMP));
                    Console.WriteLine("    Mode {0} NB dual-mono MS encode {1}, {2} bps OK.", mstrings[(int)modes[j] - (int)OpusMode.MODE_SILK_ONLY], rc == 0 ? " VBR" : rc == 1 ? "CVBR" : " CBR", rate);
                }
            }

            return(0);
        }
 public MultiSampleDecoder(int sampleRate, int channelsCount, int streams, int coupledStreams, byte[] mapping)
 {
     ChannelsCount = channelsCount;
     _decoder      = new OpusMSDecoder(sampleRate, channelsCount, streams, coupledStreams, mapping);
 }