private void LoadWaveFileIntoBuffers(out GCHandle handle, out DynSoundData sound, string filename)
        {
            sound = new DynSoundData();

            WaveFormat dataFormat;
            using (var stream = AssetManager.FileProvider.OpenStream(filename, VirtualFileMode.Open, VirtualFileAccess.Read))
            using (var memoryStream = new MemoryStream(new byte[stream.Length]))
            {
                stream.CopyTo(memoryStream);
                memoryStream.Position = 0;
                var waveStreamReader = new SoundStream(memoryStream);
                dataFormat = waveStreamReader.Format;
                sound.Data = new byte[waveStreamReader.Length];
                handle = GCHandle.Alloc(sound.Data, GCHandleType.Pinned);

                if (waveStreamReader.Read(sound.Data, 0, (int)waveStreamReader.Length) != waveStreamReader.Length)
                    throw new AudioSystemInternalException("The data length read in wave soundStream does not correspond to the stream's length.");
            }
            sound.Instance = new DynamicSoundEffectInstance(defaultEngine, dataFormat.SampleRate, (AudioChannels)dataFormat.Channels, (AudioDataEncoding)dataFormat.BitsPerSample);
        }
        public void TestPlayableInterface()
        {
            WaveFormat dataFormat;
            using (var stream = AssetManager.FileProvider.OpenStream("EffectFishLamp", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                var memoryStream = new MemoryStream((int)stream.Length);
                stream.CopyTo(memoryStream);
                memoryStream.Position = 0;

                var waveStreamReader = new SoundStream(memoryStream);
                dataFormat = waveStreamReader.Format;
                bufferData = new byte[waveStreamReader.Length];

                if (waveStreamReader.Read(bufferData, 0, (int)waveStreamReader.Length) != waveStreamReader.Length)
                    throw new AudioSystemInternalException("The data length read in wave soundStream does not correspond to the stream's length.");
            }
            dynSEInstance = new DynamicSoundEffectInstance(defaultEngine, dataFormat.SampleRate, (AudioChannels)dataFormat.Channels, (AudioDataEncoding)dataFormat.BitsPerSample);
            dynSEInstance.BufferNeeded += SubmitBuffer;

            //////////////////
            // 1. Test play
            dynSEInstance.Play();
            Utilities.Sleep(2000);
            Assert.AreEqual(SoundPlayState.Playing, dynSEInstance.PlayState, "Music is not playing");

            //////////////////
            // 2. Test Pause
            dynSEInstance.Pause();
            Utilities.Sleep(600);
            Assert.AreEqual(SoundPlayState.Paused, dynSEInstance.PlayState, "Music is not Paused");
            dynSEInstance.Play();
            Utilities.Sleep(1000);

            //////////////////
            // 2. Test Stop
            dynSEInstance.Stop();
            bufferCount = 0;
            Utilities.Sleep(600);
            Assert.AreEqual(SoundPlayState.Stopped, dynSEInstance.PlayState, "Music is not Stopped");
            dynSEInstance.Play();
            Utilities.Sleep(9000);

            ///////////////////
            // 3. Test ExitLoop
            Assert.DoesNotThrow(dynSEInstance.ExitLoop, "ExitLoop crached");

            ///////////////
            // 4. Volume
            var value = 1f;
            var sign = -1f;
            while (value <= 1f)
            {
                dynSEInstance.Volume = value;

                value += sign * 0.01f;
                Utilities.Sleep(30);

                if (value < -0.2)
                    sign = 1f;
            }
            Utilities.Sleep(2000);

            //////////////////
            // 5.Pan
            value = 0;
            sign = -1f;
            while (value <= 1f)
            {
                dynSEInstance.Pan = value;

                value += sign * 0.01f;
                Utilities.Sleep(30);

                if (value < -1.2)
                    sign = 1f;
            }
            dynSEInstance.Pan = 0;
            Utilities.Sleep(2000);
            
            ////////////////////////////////////////////////////////////////////////////
            // 7. Wait until the end of the stream to check that there are not crashes
            Utilities.Sleep(50000);

            dynSEInstance.Dispose();
        }