Пример #1
0
        /// <summary>Plays or resumes a SoundEffectInstance.</summary>
        /// <remarks>Throws an exception if more sounds are playing than the platform allows.</remarks>
        public virtual void Play()
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException("SoundEffectInstance");
            }

            if (State == SoundState.Playing)
            {
                return;
            }

            // We don't need to check if we're at the instance play limit
            // if we're resuming from a paused state.
            if (State != SoundState.Paused)
            {
                if (!SoundEffectInstancePool.SoundsAvailable)
                {
                    throw new InstancePlayLimitException();
                }

                SoundEffectInstancePool.Remove(this);
            }

            // For non-XAct sounds we need to be sure the latest
            // master volume level is applied before playback.
            if (!_isXAct)
            {
                PlatformSetVolume(_volume * SoundEffect.MasterVolume);
            }

            PlatformPlay();
        }
Пример #2
0
        internal static void PlatformShutdown()
        {
            SoundEffectInstancePool.Shutdown();

            if (_reverbVoice != null)
            {
                _reverbVoice.DestroyVoice();
                _reverbVoice.Dispose();
                _reverbVoice = null;
            }

            if (MasterVoice != null)
            {
                MasterVoice.DestroyVoice();
                MasterVoice.Dispose();
                MasterVoice = null;
            }

            if (Device != null)
            {
                Device.StopEngine();
                Device.Dispose();
                Device = null;
            }

            _device3DDirty = true;
            _speakers      = Speakers.Stereo;
        }
Пример #3
0
 /// <summary>
 /// Releases the resources held by this <see cref="Microsoft.Xna.Framework.Audio.SoundEffect"/>.
 /// </summary>
 /// <param name="disposing">If set to <c>true</c>, Dispose was called explicitly.</param>
 /// <remarks>If the disposing parameter is true, the Dispose method was called explicitly. This
 /// means that managed objects referenced by this instance should be disposed or released as
 /// required.  If the disposing parameter is false, Dispose was called by the finalizer and
 /// no managed objects should be touched because we do not know if they are still valid or
 /// not at that time.  Unmanaged resources should always be released.</remarks>
 void Dispose(bool disposing)
 {
     if (!_isDisposed)
     {
         SoundEffectInstancePool.StopPooledInstances(this);
         PlatformDispose(disposing);
         _isDisposed = true;
     }
 }
 private void PlatformStop(bool immediate)
 {
     if (_source)
     {
         _source.Stop();
         pool.Restore(_source);
         _source = null;
         SoundEffectInstancePool.Add(this);
     }
 }
Пример #5
0
        /// <summary>
        /// Returns a sound effect instance from the pool or null if none are available.
        /// </summary>
        internal SoundEffectInstance GetPooledInstance(bool forXAct)
        {
            if (!SoundEffectInstancePool.SoundsAvailable)
            {
                return(null);
            }

            var inst = SoundEffectInstancePool.GetInstance(forXAct);

            inst._effect = this;
            PlatformSetupInstance(inst);

            return(inst);
        }
        /// <summary>
        /// Stops playing the DynamicSoundEffectInstance.
        /// If the <paramref name="immediate"/> parameter is false, this call has no effect.
        /// </summary>
        /// <remarks>
        /// Calling this also releases all queued buffers.
        /// </remarks>
        /// <param name="immediate">When set to false, this call has no effect.</param>
        public override void Stop(bool immediate)
        {
            AssertNotDisposed();

            if (immediate)
            {
                DynamicSoundEffectInstanceManager.RemoveInstance(this);

                PlatformStop();
                _state = SoundState.Stopped;

                SoundEffectInstancePool.Add(this);
            }
        }
        /// <summary>
        /// Resumes playback of the DynamicSoundEffectInstance.
        /// </summary>
        public override void Resume()
        {
            AssertNotDisposed();

            if (_state != SoundState.Playing)
            {
                Volume = Volume;

                // Add the instance to the pool
                if (!SoundEffectInstancePool.SoundsAvailable)
                {
                    throw new InstancePlayLimitException();
                }
                SoundEffectInstancePool.Remove(this);
            }

            PlatformResume();
            _state = SoundState.Playing;
        }
Пример #8
0
        /// <summary>Plays or resumes a SoundEffectInstance.</summary>
        /// <remarks>Throws an exception if more sounds are playing than the platform allows.</remarks>
        public void Play()
        {
            if (State == SoundState.Playing)
            {
                return;
            }

            // We don't need to check if we're at the instance play limit
            // if we're resuming from a paused state.
            if (State != SoundState.Paused)
            {
                SoundEffectInstancePool.Remove(this);

                if (!SoundEffectInstancePool.SoundsAvailable)
                {
                    throw new InstancePlayLimitException();
                }
            }

            PlatformPlay();
        }
        /// <summary>
        /// Plays or resumes the DynamicSoundEffectInstance.
        /// </summary>
        public override void Play()
        {
            AssertNotDisposed();

            if (_state != SoundState.Playing)
            {
                // Ensure that the volume reflects master volume, which is done by the setter.
                Volume = Volume;

                // Add the instance to the pool
                if (!SoundEffectInstancePool.SoundsAvailable)
                {
                    throw new InstancePlayLimitException();
                }
                SoundEffectInstancePool.Remove(this);

                PlatformPlay();
                _state = SoundState.Playing;

                CheckBufferCount();
                DynamicSoundEffectInstanceManager.AddInstance(this);
            }
        }
 private static void PlatformSetMasterVolume()
 {
     SoundEffectInstancePool.UpdateVolumes();
 }