public void Initialize()
        {
            Game.InitializeAssetDatabase();

            defaultEngine = AudioEngineFactory.NewAudioEngine();

            using (var monoStream = ContentManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                monoSoundEffect = SoundEffect.Load(defaultEngine, monoStream);
            }
            using (var stereoStream = ContentManager.FileProvider.OpenStream("EffectStereo", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                stereoSoundEffect = SoundEffect.Load(defaultEngine, stereoStream);
            }
            using (var contStream = ContentManager.FileProvider.OpenStream("EffectToneA", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                continousMonoSoundEffect = SoundEffect.Load(defaultEngine, contStream);
            }
            using (var contStream = ContentManager.FileProvider.OpenStream("EffectToneAE", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                continousStereoSoundEffect = SoundEffect.Load(defaultEngine, contStream);
            }
            using (var monoStream = ContentManager.FileProvider.OpenStream("Effect44100Hz", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                laugherMono = SoundEffect.Load(defaultEngine, monoStream);
            }

            monoInstance   = monoSoundEffect.CreateInstance();
            stereoInstance = stereoSoundEffect.CreateInstance();
        }
Beispiel #2
0
        public void TestState()
        {
            // test initial state
            var engine = AudioEngineFactory.NewAudioEngine();

            Assert.AreEqual(AudioEngineState.Running, engine.State);

            // test state after pause
            engine.PauseAudio();
            Assert.AreEqual(AudioEngineState.Paused, engine.State);

            // test state after resume
            engine.ResumeAudio();
            Assert.AreEqual(AudioEngineState.Running, engine.State);

            // test state after dispose
            engine.Dispose();
            Assert.AreEqual(AudioEngineState.Disposed, engine.State);

            // test that state remains dispose
            engine.PauseAudio();
            Assert.AreEqual(AudioEngineState.Disposed, engine.State);
            engine.ResumeAudio();
            Assert.AreEqual(AudioEngineState.Disposed, engine.State);
        }
Beispiel #3
0
        public void TestGetLeastSignificativeSoundEffect()
        {
            var engine = AudioEngineFactory.NewAudioEngine();

            //////////////////////////////////////////
            // 1. Test that it returns null by default
            Assert.AreEqual(null, engine.GetLeastSignificativeSoundEffect());

            // create a sound effect
            SoundEffect soundEffect;

            using (var wavStream = ContentManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
                soundEffect = SoundEffect.Load(engine, wavStream);

            /////////////////////////////////////////////////////////////////////
            // 2. Test that is returns null when there is no playing sound effect
            Assert.AreEqual(null, engine.GetLeastSignificativeSoundEffect());

            /////////////////////////////////////////////////////////////////////////////////
            // 3. Test that is returns null when there is no not looped sound effect playing
            soundEffect.IsLooped = true;
            soundEffect.Play();
            Assert.AreEqual(null, engine.GetLeastSignificativeSoundEffect());

            ////////////////////////////////////////////////////////////////////////////
            // 4. Test that the sound effect is returned if not playing and not looped
            soundEffect.Stop();
            soundEffect.IsLooped = false;
            soundEffect.Play();
            Assert.AreEqual(soundEffect, engine.GetLeastSignificativeSoundEffect());

            // create another longer sound effect
            SoundEffect longerSoundEffect;

            using (var wavStream = ContentManager.FileProvider.OpenStream("EffectStereo", VirtualFileMode.Open, VirtualFileAccess.Read))
                longerSoundEffect = SoundEffect.Load(engine, wavStream);

            ///////////////////////////////////////////////////////////////////////
            // 5. Test that the longest sound is returned if it is the only playing
            soundEffect.Stop();
            longerSoundEffect.Play();
            Assert.AreEqual(longerSoundEffect, engine.GetLeastSignificativeSoundEffect());

            //////////////////////////////////////////////////////////////
            // 6. Test that the shortest sound is returned if both playing
            longerSoundEffect.Play();
            soundEffect.Play();
            Assert.AreEqual(soundEffect, engine.GetLeastSignificativeSoundEffect());

            //////////////////////////////////////////////////////////////////////
            // 7. Test that the longest sound is returned if the other is looped
            soundEffect.Stop();
            soundEffect.IsLooped = true;
            soundEffect.Play();
            longerSoundEffect.Play();
            Assert.AreEqual(longerSoundEffect, engine.GetLeastSignificativeSoundEffect());

            engine.Dispose();
        }
Beispiel #4
0
        public void Initialize()
        {
            Game.InitializeAssetDatabase();

            defaultEngine = AudioEngineFactory.NewAudioEngine();

            validWavStream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read);
        }
Beispiel #5
0
        public void TestLoad()
        {
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // 1. Check that SoundEffect.Load throws "ArgumentNullException" when either 'engine' or 'stream' param is null
            // 1.1 Null engine
            validWavStream.Seek(0, SeekOrigin.Begin);
            Assert.Throws <ArgumentNullException>(() => SoundEffect.Load(null, validWavStream), "SoundEffect.Load did not throw 'ArgumentNullException' when called with a null engine.");
            // 1.2 Null stream
            Assert.Throws <ArgumentNullException>(() => SoundEffect.Load(defaultEngine, null), "SoundEffect.Load did not throw 'ArgumentNullException' when called with a null stream.");

            ///////////////////////////////////////////////////////////////////////////////////////////////////////
            // 2. Check that the load function throws "ObjectDisposedException" when the audio engine is disposed.
            var disposedEngine = AudioEngineFactory.NewAudioEngine();

            disposedEngine.Dispose();
            validWavStream.Seek(0, SeekOrigin.Begin);
            Assert.Throws <ObjectDisposedException>(() => SoundEffect.Load(disposedEngine, validWavStream), "SoundEffect.Load did not throw 'ObjectDisposedException' when called with a displosed audio engine.");

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // 3. Check that the load function throws "InvalidOperationException" when the audio file stream is not valid
            // 3.1 Invalid audio file format.
            var otherFileFormatStream = AssetManager.FileProvider.OpenStream("EffectStereoOgg", VirtualFileMode.Open, VirtualFileAccess.Read);

            Assert.Throws <InvalidOperationException>(() => SoundEffect.Load(defaultEngine, otherFileFormatStream), "SoundEffect.Load did not throw 'InvalidOperationException' when called with an invalid file extension.");
            otherFileFormatStream.Dispose();
            // 3.2 Corrupted Header wav file
            var corruptedWavFormatStream = AssetManager.FileProvider.OpenStream("EffectHeaderCorrupted", VirtualFileMode.Open, VirtualFileAccess.Read);

            Assert.Throws <InvalidOperationException>(() => SoundEffect.Load(defaultEngine, corruptedWavFormatStream), "SoundEffect.Load did not throw 'InvalidOperationException' when called with a corrupted wav stream.");
            corruptedWavFormatStream.Dispose();
            // 3.3 Invalid wav file format (4-channels)
            var invalidChannelWavFormatStream = AssetManager.FileProvider.OpenStream("Effect4Channels", VirtualFileMode.Open, VirtualFileAccess.Read);

            Assert.Throws <InvalidOperationException>(() => SoundEffect.Load(defaultEngine, invalidChannelWavFormatStream), "SoundEffect.Load did not throw 'InvalidOperationException' when called with an invalid 4-channels wav format.");
            invalidChannelWavFormatStream.Dispose();

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // 4. Check that the load function throws "NotSupportedException" when the audio file stream is not supported
            // 4.1 extented wav file format (5-channels)
            var extendedChannelWavFormatStream = AssetManager.FileProvider.OpenStream("EffectSurround5Dot1", VirtualFileMode.Open, VirtualFileAccess.Read);

            Assert.Throws <NotSupportedException>(() => SoundEffect.Load(defaultEngine, extendedChannelWavFormatStream), "SoundEffect.Load did not throw 'NotSupportedException' when called with an extended 5-channels wav format.");
            extendedChannelWavFormatStream.Dispose();
            // 4.2 Invalid wav file format (24bits encoding)
            var invalidEncodingWavFormatStream = AssetManager.FileProvider.OpenStream("Effect24bits", VirtualFileMode.Open, VirtualFileAccess.Read);

            Assert.Throws <NotSupportedException>(() => SoundEffect.Load(defaultEngine, invalidEncodingWavFormatStream), "SoundEffect.Load did not throw 'NotSupportedException' when called with an invalid ieeefloat encoding wav format.");
            invalidEncodingWavFormatStream.Dispose();

            ///////////////////////////////////////////////////////
            // 5. Load a valid wav file stream and try to play it
            validWavStream.Seek(0, SeekOrigin.Begin);
            Assert.DoesNotThrow(() => SoundEffect.Load(defaultEngine, validWavStream), "SoundEffect.Load have thrown an exception when called with an valid wav stream.");
        }
Beispiel #6
0
 public void ContextInitialization()
 {
     try
     {
         var engine = AudioEngineFactory.NewAudioEngine();
         engine.Dispose();
     }
     catch (Exception e)
     {
         Assert.IsTrue(e is AudioInitializationException, "Audio engine failed to initialize but did not throw AudioInitializationException");
     }
 }
Beispiel #7
0
        public void Initialize()
        {
            Game.InitializeAssetDatabase();

            defaultEngine = AudioEngineFactory.NewAudioEngine();

            monoInstance   = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicBip"));
            stereoInstance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicStereo"));
            contInstance   = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicToneA"));
            mp3Instance    = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicFishLampMp3"));
            wavInstance    = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicBip"));
        }
        public void Initialize()
        {
            Game.InitializeAssetDatabase();

            engine = AudioEngineFactory.NewAudioEngine();

            using (var stream = ContentManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                oneSound = SoundEffect.Load(engine, stream);
            }
            oneSound.IsLooped = true;

            sayuriPart          = SoundMusic.Load(engine, ContentManager.FileProvider.OpenStream("MusicFishLampMp3", VirtualFileMode.Open, VirtualFileAccess.Read));
            sayuriPart.IsLooped = true;
        }
Beispiel #9
0
        public void TestLoad()
        {
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // 1. Check that SoundMusic.Load throws "ArgumentNullException" when either 'engine' or 'filename' param is null
            // 1.1 Null engine
            Assert.Throws <ArgumentNullException>(() => SoundMusic.Load(null, new MemoryStream()), "SoundMusic.Load did not throw 'ArgumentNullException' when called with a null engine.");
            // 1.2 Null stream
            Assert.Throws <ArgumentNullException>(() => SoundMusic.Load(defaultEngine, null), "SoundMusic.Load did not throw 'ArgumentNullException' when called with a null stream.");

            ///////////////////////////////////////////////////////////////////////////////////////////////////////
            // 2. Check that the load function throws "ObjectDisposedException" when the audio engine is disposed.
            var disposedEngine = AudioEngineFactory.NewAudioEngine();

            disposedEngine.Dispose();
            Assert.Throws <ObjectDisposedException>(() => SoundMusic.Load(disposedEngine, OpenDataBaseStream("EffectToneA")), "SoundMusic.Load did not throw 'ObjectDisposedException' when called with a displosed audio engine.");

            ///////////////////////////
            // 4. Load a valid wav file
            Assert.DoesNotThrow(() => SoundMusic.Load(defaultEngine, OpenDataBaseStream("EffectToneA")), "SoundMusic.Load have thrown an exception when called with an valid wav file.");

            ///////////////////////////
            // 5. Load a valid mp3 file
            Assert.DoesNotThrow(() => SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicFishLampMp3")), "SoundMusic.Load have thrown an exception when called with an valid wav file.");
        }
Beispiel #10
0
        public void Initialize()
        {
            Game.InitializeAssetDatabase();

            defaultEngine = AudioEngineFactory.NewAudioEngine();
        }
Beispiel #11
0
        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 = ContentManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                soundEffect = SoundEffect.Load(engine, wavStream);
            }
            SoundEffect dispSoundEffect;

            using (var wavStream = ContentManager.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, ContentManager.FileProvider.OpenStream("MusicBip", VirtualFileMode.Open, VirtualFileAccess.Read));
            var soundMusic2 = SoundMusic.Load(engine, ContentManager.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.");
        }
Beispiel #12
0
        public void TestResumeAudio()
        {
            var engine = AudioEngineFactory.NewAudioEngine();

            // create a sound effect instance
            SoundEffect soundEffect;

            using (var wavStream = ContentManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
                soundEffect = SoundEffect.Load(engine, wavStream);
            var wave1Instance = soundEffect.CreateInstance();

            // create a music instance
            var music = SoundMusic.Load(engine, ContentManager.FileProvider.OpenStream("MusicFishLampMp3", VirtualFileMode.Open, VirtualFileAccess.Read));

            // check that resume do not play stopped instances
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, music.PlayState);
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that user paused music does not resume
            wave1Instance.Play();
            wave1Instance.Pause();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Paused, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that sounds paused by PauseAudio are correctly restarted
            wave1Instance.Play();
            music.Play();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Playing, wave1Instance.PlayState);
            Assert.AreEqual(SoundPlayState.Playing, music.PlayState);
            TestAudioUtilities.ActiveAudioEngineUpdate(engine, 3000); // listen that the sound comes out
            music.Stop();
            TestAudioUtilities.ActiveAudioEngineUpdate(engine, 100);  // stop the music

            // check that a sound stopped during the pause does not play during the resume
            wave1Instance.Play();
            engine.PauseAudio();
            wave1Instance.Stop();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a sound played during the pause do not play during the resume
            engine.PauseAudio();
            wave1Instance.Play();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a two calls to resume do not have side effects (1)
            wave1Instance.Play();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Playing, wave1Instance.PlayState);
            Utilities.Sleep(2000); // wait that the sound is finished
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a two calls to resume do not have side effects (2)
            wave1Instance.Play();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Playing, wave1Instance.PlayState);
            wave1Instance.Pause();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Paused, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a several calls to pause/play do not have side effects
            wave1Instance.Play();
            engine.PauseAudio();
            engine.ResumeAudio();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Playing, wave1Instance.PlayState);
            Utilities.Sleep(2000); // listen that the sound comes out

            // check that the sound is not played if disposed
            wave1Instance.Play();
            engine.PauseAudio();
            wave1Instance.Dispose();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            music.Dispose();
            soundEffect.Dispose();
        }
Beispiel #13
0
        public void TestPauseAudio()
        {
            var engine = AudioEngineFactory.NewAudioEngine();

            // create a sound effect instance
            SoundEffect soundEffect;

            using (var wavStream = ContentManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
                soundEffect = SoundEffect.Load(engine, wavStream);
            var wave1Instance = soundEffect.CreateInstance();

            // create a music instance
            var music = SoundMusic.Load(engine, ContentManager.FileProvider.OpenStream("MusicFishLampMp3", VirtualFileMode.Open, VirtualFileAccess.Read));

            // check state
            engine.PauseAudio();
            Assert.AreEqual(AudioEngineState.Paused, engine.State);

            // check that existing instance can not be played
            wave1Instance.Play();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            music.Play();
            Assert.AreEqual(SoundPlayState.Stopped, music.PlayState);
            TestAudioUtilities.ActiveAudioEngineUpdate(engine, 1000); // listen that nothing comes out

            // create a new sound effect
            SoundEffect soundEffectStereo;

            using (var wavStream = ContentManager.FileProvider.OpenStream("EffectStereo", VirtualFileMode.Open, VirtualFileAccess.Read))
                soundEffectStereo = SoundEffect.Load(engine, wavStream);

            // check that a new instance can not be played
            soundEffectStereo.Play();
            Assert.AreEqual(SoundPlayState.Stopped, soundEffectStereo.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a stopped sound stay stopped
            engine.ResumeAudio();
            soundEffectStereo.Stop();
            engine.PauseAudio();
            Assert.AreEqual(SoundPlayState.Stopped, soundEffectStereo.PlayState);

            // check that a paused sound stay paused
            engine.ResumeAudio();
            soundEffectStereo.Play();
            soundEffectStereo.Pause();
            engine.PauseAudio();
            Assert.AreEqual(SoundPlayState.Paused, soundEffectStereo.PlayState);

            // check that a playing sound is paused
            engine.ResumeAudio();
            wave1Instance.Play();
            soundEffectStereo.Play();
            music.Play();
            engine.PauseAudio();
            Assert.AreEqual(SoundPlayState.Paused, wave1Instance.PlayState);
            Assert.AreEqual(SoundPlayState.Paused, soundEffectStereo.PlayState);
            Assert.AreEqual(SoundPlayState.Paused, music.PlayState);
            TestAudioUtilities.ActiveAudioEngineUpdate(engine, 1000); // listen that nothing comes out

            // check that stopping a sound while paused is possible
            engine.PauseAudio();
            soundEffectStereo.Stop();
            Assert.AreEqual(SoundPlayState.Stopped, soundEffectStereo.PlayState);

            // check that disposing a sound while paused is possible
            engine.PauseAudio();
            music.Dispose();
            Assert.IsTrue(music.IsDisposed);

            soundEffect.Dispose();
            soundEffectStereo.Dispose();
        }