Dispose() 공개 메소드

Releases the resources held by this Microsoft.Xna.Framework.Audio.SoundEffectInstance.
public Dispose ( ) : void
리턴 void
        /// <summary>
        /// Iterates the list of playing instances, returning them to the pool if they
        /// have stopped playing.
        /// </summary>
        internal static void Update()
        {
#if OPENAL
            OpenALSoundController.GetInstance.Update();
#endif

            SoundEffectInstance inst = null;
            // Cleanup instances which have finished playing.
            for (var x = 0; x < _playingInstances.Count;)
            {
                inst = _playingInstances[x];

                if (inst.State == SoundState.Stopped || inst.IsDisposed || inst._effect == null)
                {
                    Add(inst);
                    continue;
                }
                else if (inst._effect.IsDisposed)
                {
                    Add(inst);
                    // Instances created through SoundEffect.CreateInstance need to be disposed when
                    // their owner SoundEffect is disposed.
                    if (!inst._isPooled)
                    {
                        inst.Dispose();
                    }
                    continue;
                }

                x++;
            }
        }
예제 #2
0
        public void DestroySoundEffect(SoundEffect soundEffect)
        {
            OpenALSoundController.BufferAllocation bufferAllocation;
            if (!this.allocatedBuffers.TryGetValue(soundEffect, out bufferAllocation))
            {
                return;
            }
            bool flag = false;

            for (int index = this.activeSoundEffects.Count - 1; index >= 0; --index)
            {
                SoundEffectInstance soundEffectInstance = this.activeSoundEffects[index];
                if (soundEffectInstance.SoundEffect == soundEffect)
                {
                    if (!soundEffectInstance.IsDisposed)
                    {
                        flag = true;
                        soundEffectInstance.Stop(false);
                        soundEffectInstance.Dispose();
                    }
                    this.activeSoundEffects.RemoveAt(index);
                }
            }
            if (flag)
            {
                Trace.WriteLine("[OpenAL] Delete active sources & buffer for " + soundEffect.Name);
            }
            this.allocatedBuffers.Remove(soundEffect);
            this.freeBuffers.Push(bufferAllocation.BufferId);
        }
예제 #3
0
        public override void Play()
        {
            if (_wav != null)
            {
                if (_wav.State != SoundState.Stopped)
                {
                    _wav.Stop();
                }
                if (_streaming)
                {
                    _wav.Dispose();
                }
                else
                {
                    _wav._isXAct = false;
                }
                _wav = null;
            }

            Play(true);
        }
예제 #4
0
 public static void Play(ref SoundEffectInstance _playInstance, string sound)
 {
     if (_playInstance == null)
     {
         _playInstance = AudioManager.SoundEffects[sound].CreateInstance();
         _playInstance.Play();
     }
     else if (_playInstance != null)
     {
         if (_playInstance.State == SoundState.Stopped)
         {
             _playInstance.Dispose();
             _playInstance = null;
         }
     }
 }
예제 #5
0
        public bool Play(float volume, float pitch, float pan)
        {
            SoundEffectInstance instance = new SoundEffectInstance(this);

            instance.Volume = volume;
            instance.Pitch  = pitch;
            instance.Pan    = pan;
            instance.Play();
            if (instance.State != SoundState.Playing)
            {
                // Ran out of AL sources, probably.
                instance.Dispose();
                return(false);
            }
            return(true);
        }
예제 #6
0
        public bool Play(float volume, float pitch, float pan)
        {
            SoundEffectInstance instance = CreateInstance();

            instance.Volume = volume;
            instance.Pitch  = pitch;
            instance.Pan    = pan;
            instance.Play();
            if (instance.State != SoundState.Playing)
            {
                // Ran out of AL sources, probably.
                instance.Dispose();
                return(false);
            }
            OpenALDevice.Instance.instancePool.Add(instance);
            return(true);
        }
예제 #7
0
        public void Update(GameTime gameTime)
        {
            OpenALSoundController.ActiveLock.EnterUpgradeableReadLock();
            for (int index = this.activeSoundEffects.Count - 1; index >= 0; --index)
            {
                SoundEffectInstance soundEffectInstance = this.activeSoundEffects[index];
                if (soundEffectInstance.RefreshState() || soundEffectInstance.IsDisposed)
                {
                    OpenALSoundController.ActiveLock.EnterWriteLock();
                    if (!soundEffectInstance.IsDisposed)
                    {
                        soundEffectInstance.Dispose();
                    }
                    this.activeSoundEffects.RemoveAt(index);
                    OpenALSoundController.ActiveLock.ExitWriteLock();
                }
            }
            OpenALSoundController.ActiveLock.ExitUpgradeableReadLock();
            float num = (float)gameTime.ElapsedGameTime.TotalSeconds;

            OpenALSoundController.AllocationsLock.EnterUpgradeableReadLock();
            foreach (KeyValuePair <SoundEffect, OpenALSoundController.BufferAllocation> keyValuePair in this.allocatedBuffers)
            {
                if (keyValuePair.Value.SourceCount == 0)
                {
                    keyValuePair.Value.SinceUnused += num;
                    if ((double)keyValuePair.Value.SinceUnused >= 10.0)
                    {
                        this.staleAllocations.Add(keyValuePair);
                    }
                }
            }
            foreach (KeyValuePair <SoundEffect, OpenALSoundController.BufferAllocation> keyValuePair in this.staleAllocations)
            {
                OpenALSoundController.AllocationsLock.EnterWriteLock();
                this.allocatedBuffers.Remove(keyValuePair.Key);
                OpenALSoundController.AllocationsLock.ExitWriteLock();
                this.freeBuffers.Push(keyValuePair.Value.BufferId);
            }
            OpenALSoundController.AllocationsLock.ExitUpgradeableReadLock();
            this.TidySources();
            this.TidyBuffers();
            this.staleAllocations.Clear();
        }
예제 #8
0
파일: Sound.cs 프로젝트: cryophobia/exen
 public static void StopMusic(SoundEffectInstance instance)
 {
     if(instance != null)
     {
         instance.Stop();
         instance.Dispose();
     }
 }
예제 #9
0
        public bool Play(float volume, float pitch, float pan)
        {
#if DIRECTX
            if (MasterVolume > 0.0f)
            {
                if (_playingInstances == null)
                {
                    // Allocate lists first time we need them.
                    _playingInstances      = new List <SoundEffectInstance>();
                    _availableInstances    = new List <SoundEffectInstance>();
                    _toBeRecycledInstances = new List <SoundEffectInstance>();
                }
                else
                {
                    // Cleanup instances which have finished playing.
                    foreach (var inst in _playingInstances)
                    {
                        if (inst.State == SoundState.Stopped)
                        {
                            _toBeRecycledInstances.Add(inst);
                        }
                    }
                }

                // Locate a SoundEffectInstance either one already
                // allocated and not in use or allocate a new one.
                SoundEffectInstance instance = null;
                if (_toBeRecycledInstances.Count > 0)
                {
                    foreach (var inst in _toBeRecycledInstances)
                    {
                        _availableInstances.Add(inst);
                        _playingInstances.Remove(inst);
                    }
                    _toBeRecycledInstances.Clear();
                }
                if (_availableInstances.Count > 0)
                {
                    instance = _availableInstances[0];
                    _playingInstances.Add(instance);
                    _availableInstances.Remove(instance);
                }
                else
                {
                    instance = CreateInstance();
                    _playingInstances.Add(instance);
                }

                instance.Volume = volume;
                instance.Pitch  = pitch;
                instance.Pan    = pan;
                instance.Play();
            }

            // XNA documentation says this method returns false if the sound limit
            // has been reached. However, there is no limit on PC.
            return(true);
#elif SDL2
            SoundEffectInstance instance = CreateInstance();
            instance.Volume = volume;
            instance.Pitch  = pitch;
            instance.Pan    = pan;
            instance.Play();
            if (instance.State != SoundState.Playing)
            {
                // Ran out of AL sources, probably.
                instance.Dispose();
                return(false);
            }
            OpenALSoundController.GetInstance.instancePool.Add(instance);
            return(true);
#else
            if (MasterVolume > 0.0f)
            {
                if (_instance == null)
                {
                    _instance = CreateInstance();
                }
                _instance.Volume = volume;
                _instance.Pitch  = pitch;
                _instance.Pan    = pan;
                _instance.Play();
                return(_instance.Sound.Playing);
            }
            return(false);
#endif
        }
예제 #10
0
 public static void StopSfx(SoundEffectInstance soundCue)
 {
     soundCue.Stop(true);
     soundCue.Dispose();
 }
예제 #11
0
        public void Play(float volume, AudioEngine engine)
        {
            _cueVolume = volume;
            var category = engine.Categories[_categoryID];

            var curInstances = category.GetPlayingInstanceCount();

            if (curInstances >= category.maxInstances)
            {
                var prevSound = category.GetOldestInstance();

                if (prevSound != null)
                {
                    prevSound.SetFade(0.0f, category.fadeOut);
                    prevSound.Stop(AudioStopOptions.Immediate);
                    SetFade(category.fadeIn, 0.0f);
                }
            }

            float finalVolume = _volume * _cueVolume * category._volume[0];
            float finalPitch  = _pitch + _cuePitch;
            float finalMix    = _useReverb ? _cueReverbMix : 0.0f;

            if (_complexSound)
            {
                foreach (XactClip clip in _soundClips)
                {
                    clip.UpdateState(finalVolume, finalPitch, finalMix, _cueFilterFrequency, _cueFilterQFactor);
                    clip.Play();
                }
            }
            else
            {
                if (_wave != null)
                {
                    if (_streaming)
                    {
                        _wave.Dispose();
                    }
                    else
                    {
                        _wave._isXAct = false;
                    }
                    _wave = null;
                }

                _wave = _soundBank.GetSoundEffectInstance(_waveBankIndex, _trackIndex, out _streaming);

                if (_wave == null)
                {
                    // We couldn't create a sound effect instance, most likely
                    // because we've reached the sound pool limits.
                    return;
                }

                _wave.Pitch  = finalPitch;
                _wave.Volume = finalVolume;
                _wave.PlatformSetReverbMix(finalMix);
                _wave.Play();
            }
        }
예제 #12
0
 private void PlaySound(SoundEffect soundEffect, SoundEffectInstance soundEffectInstance, float volume = 1.0F)
 {
     if (soundEffectInstance != null &&
         !soundEffectInstance.IsDisposed)
     {
         soundEffectInstance.Dispose();
     }
     soundEffectInstance = soundEffect.CreateInstance();
     soundEffectInstance.Play();
 }
예제 #13
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // load texture and contents
            messageFont = this.Content.Load<SpriteFont>(MessageFontContentName);
            scoreFont = this.Content.Load<SpriteFont>(ScoreFontContentName);

            laserTexture = this.Content.Load<Texture2D>(LaserContentName);
            spaceshipTexture = this.Content.Load<Texture2D>(SpaceshipContentName);
            enemy4Texture = this.Content.Load<Texture2D>(Enemy4ContentName);
            explosionTexture = this.Content.Load<Texture2D>(ExplosionsContentName);
            backgroundTexture = this.Content.Load<Texture2D>(BackgroundContentName);
            starTexture = this.Content.Load<Texture2D>(ParallaxStarContentName);
            //bgmEffect = this.Content.Load<SoundEffect>(BgmContentName);
            bgmEffect = this.Content.Load<SoundEffect>(this.settings.BgmSoundEffect);
            explosionSoundEffect = this.Content.Load<SoundEffect>(ExplosionSoundContentName);
            explosionSound = explosionSoundEffect.CreateInstance();
            explosionSound.Volume = 1.0F;

            laserSoundEffect = this.Content.Load<SoundEffect>(LaserSoundContentName);
            laserSound = laserSoundEffect.CreateInstance();
            laserSound.Volume = 1.0F;

            // create sprites
            spaceshipSprite = new SpaceshipSprite(spaceshipTexture);
            backgroundSprite = new BackgroundSprite(backgroundTexture, graphics);

            // create sprite generators
            enemyGenerator =
                new SpriteGenerator<EnemySprite>(
                    () =>
                        new EnemySprite(enemy4Texture,
                            new Vector2(Utils.GetRandomNumber(1, GraphicsDevice.Viewport.Width - enemy4Texture.Width), 1),
                            Utils.GetRandomNumber(5, 10)), enemyPool, TimeSpan.FromMilliseconds(1000.0F/settings.NumOfEnemiesPerSecond));

            starGenerator =
                new SpriteGenerator<ParallaxStarSprite>(() => new ParallaxStarSprite(starTexture, new Vector2(
                    Utils.GetRandomNumber(1,
                        GraphicsDevice.Viewport.Width - starTexture.Width), 1), Utils.GetRandomNumber(5, 20)), starPool,
                    TimeSpan.FromMilliseconds(100));

            gameOverScene = new GameOverScene(this, () => !spaceshipSprite.IsActive, () =>
            {
                this.enemyPool.Clear();
                this.laserPool.Clear();
                this.explosionPool.Clear();

                this.enemyGenerator.IsActive = false;

                if (explosionSound != null && !explosionSound.IsDisposed)
                {
                    explosionSound.Stop(true);
                    explosionSound.Dispose();
                }
                if (laserSound != null && !laserSound.IsDisposed)
                {
                    laserSound.Stop(true);
                    laserSound.Dispose();
                }
                bgmEffect.Dispose();
            }) {IsActive = !settings.LiveForever};

            var bgm = bgmEffect.CreateInstance();
            bgm.IsLooped = true;
            bgm.Play();
        }