public void TestDispose() { var crossDisposedEngine = AudioEngineFactory.NewAudioEngine(); var engine = AudioEngineFactory.NewAudioEngine(); crossDisposedEngine.Dispose(); // Check there no Dispose problems with sereval cross-disposed instances. // Create some SoundEffects SoundEffect soundEffect; using (var wavStream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read)) { soundEffect = SoundEffect.Load(engine, wavStream); } SoundEffect dispSoundEffect; using (var wavStream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read)) { dispSoundEffect = SoundEffect.Load(engine, wavStream); } dispSoundEffect.Dispose(); var soundEffectInstance = soundEffect.CreateInstance(); var dispInstance = soundEffect.CreateInstance(); dispInstance.Dispose(); // Create some SoundMusics. var soundMusic1 = SoundMusic.Load(engine, AssetManager.FileProvider.OpenStream("MusicBip", VirtualFileMode.Open, VirtualFileAccess.Read)); var soundMusic2 = SoundMusic.Load(engine, AssetManager.FileProvider.OpenStream("MusicToneA", VirtualFileMode.Open, VirtualFileAccess.Read)); soundMusic2.Dispose(); // Create some dynamicSounds. var generator = new SoundGenerator(); var dynSound1 = new DynamicSoundEffectInstance(engine, 44100, AudioChannels.Mono, AudioDataEncoding.PCM_8Bits); var dynSound2 = new DynamicSoundEffectInstance(engine, 20000, AudioChannels.Mono, AudioDataEncoding.PCM_8Bits); dynSound1.Play(); dynSound1.SubmitBuffer(generator.Generate(44100, new[]{ 1000f }, 1, 120000)); dynSound2.Dispose(); // Start playing some soundEffectInstance.Play(); soundMusic1.Play(); for (int i = 0; i < 10; i++) { engine.Update(); Utilities.Sleep(5); } Assert.DoesNotThrow(engine.Dispose, "AudioEngine crashed during disposal."); Assert.IsTrue(soundEffect.IsDisposed, "SoundEffect is not disposed."); Assert.Throws<InvalidOperationException>(engine.Dispose, "AudioEngine did not threw invalid operation exception."); Assert.AreEqual(SoundPlayState.Stopped, soundEffectInstance.PlayState, "SoundEffectInstance has not been stopped properly."); Assert.IsTrue(soundEffectInstance.IsDisposed, "SoundEffectInstance has not been disposed properly."); Assert.AreEqual(SoundPlayState.Stopped, soundMusic1.PlayState, "soundMusic1 has not been stopped properly."); Assert.IsTrue(soundMusic1.IsDisposed, "soundMusic1 has not been disposed properly."); //Assert.AreEqual(SoundPlayState.Stopped, dynSound1.PlayState, "The dynamic sound 1 has not been stopped correctly."); //Assert.IsTrue(dynSound1.IsDisposed, "The dynamic sound 1 has not been disposed correctly."); }
public void TestPendingBufferCount() { mono8Bits = new DynamicSoundEffectInstance(defaultEngine, 44100, AudioChannels.Mono, AudioDataEncoding.PCM_8Bits); var dispInstance = new DynamicSoundEffectInstance(defaultEngine, 44100, AudioChannels.Stereo, AudioDataEncoding.PCM_16Bits); dispInstance.Dispose(); var pendingCount = 0; /////////////////////////////////////////////////////////////////////////// // 1. Test that it throws ObjectDisposedException with disposed instance Assert.Throws <ObjectDisposedException>(() => pendingCount = dispInstance.PendingBufferCount, "PendingBufferCount did not throw ObjectDisposedException"); ////////////////////////////////// // 2. Test that it does not crash Assert.DoesNotThrow(() => pendingCount = mono8Bits.PendingBufferCount, "PendingBufferCount crashed with valid instance"); //////////////////////////// // 3. Test the default value mono8Bits.Stop(); Assert.AreEqual(0, mono8Bits.PendingBufferCount, "PendingBufferCount default value is not 0"); ////////////////////////////////////////////////// // 4. Check the value after adding some buffers mono8Bits.SubmitBuffer(generator.Generate(44100, new[] { 0f }, 1, 10000)); mono8Bits.SubmitBuffer(generator.Generate(44100, new[] { 0f }, 1, 10000)); mono8Bits.SubmitBuffer(generator.Generate(44100, new[] { 0f }, 1, 10000)); Assert.AreEqual(3, mono8Bits.PendingBufferCount, "PendingBufferCount value is not 3 after adding buffers"); ////////////////////////////////// // 5. Check the value after stop mono8Bits.Stop(); Assert.AreEqual(0, mono8Bits.PendingBufferCount, "PendingBufferCount default value is not 0"); ////////////////////////////////// // 6 Check the value after play mono8Bits.SubmitBuffer(generator.Generate(44100, new[] { 0f }, 1, 1000)); mono8Bits.SubmitBuffer(generator.Generate(44100, new[] { 0f }, 1, 1000)); mono8Bits.Play(); Utilities.Sleep(1000); Assert.AreEqual(0, mono8Bits.PendingBufferCount, "PendingBufferCount value is not 0 after play"); mono8Bits.Stop(); mono8Bits.Dispose(); }
public void TestDispose() { var crossDisposedEngine = new AudioEngine(); var engine = new AudioEngine(); crossDisposedEngine.Dispose(); // Check there no Dispose problems with sereval cross-disposed instances. // Create some SoundEffects SoundEffect soundEffect; using (var wavStream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read)) { soundEffect = SoundEffect.Load(engine, wavStream); } SoundEffect dispSoundEffect; using (var wavStream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read)) { dispSoundEffect = SoundEffect.Load(engine, wavStream); } dispSoundEffect.Dispose(); var soundEffectInstance = soundEffect.CreateInstance(); var dispInstance = soundEffect.CreateInstance(); dispInstance.Dispose(); // Create some SoundMusics. var soundMusic1 = SoundMusic.Load(engine, AssetManager.FileProvider.OpenStream("MusicBip", VirtualFileMode.Open, VirtualFileAccess.Read)); var soundMusic2 = SoundMusic.Load(engine, AssetManager.FileProvider.OpenStream("MusicToneA", VirtualFileMode.Open, VirtualFileAccess.Read)); soundMusic2.Dispose(); // Create some dynamicSounds. var generator = new SoundGenerator(); var dynSound1 = new DynamicSoundEffectInstance(engine, 44100, AudioChannels.Mono, AudioDataEncoding.PCM_8Bits); var dynSound2 = new DynamicSoundEffectInstance(engine, 20000, AudioChannels.Mono, AudioDataEncoding.PCM_8Bits); dynSound1.Play(); dynSound1.SubmitBuffer(generator.Generate(44100, new[] { 1000f }, 1, 120000)); dynSound2.Dispose(); // Start playing some soundEffectInstance.Play(); soundMusic1.Play(); for (int i = 0; i < 10; i++) { engine.Update(); Utilities.Sleep(5); } Assert.DoesNotThrow(engine.Dispose, "AudioEngine crashed during disposal."); Assert.IsTrue(soundEffect.IsDisposed, "SoundEffect is not disposed."); Assert.Throws <InvalidOperationException>(engine.Dispose, "AudioEngine did not threw invalid operation exception."); Assert.AreEqual(SoundPlayState.Stopped, soundEffectInstance.PlayState, "SoundEffectInstance has not been stopped properly."); Assert.IsTrue(soundEffectInstance.IsDisposed, "SoundEffectInstance has not been disposed properly."); Assert.AreEqual(SoundPlayState.Stopped, soundMusic1.PlayState, "soundMusic1 has not been stopped properly."); Assert.IsTrue(soundMusic1.IsDisposed, "soundMusic1 has not been disposed properly."); //Assert.AreEqual(SoundPlayState.Stopped, dynSound1.PlayState, "The dynamic sound 1 has not been stopped correctly."); //Assert.IsTrue(dynSound1.IsDisposed, "The dynamic sound 1 has not been disposed correctly."); }