Exemplo n.º 1
0
        /// <summary>
        /// Perform necessary audio updates/cleaning on the audio manager.
        /// </summary>
        /// <param name="newSoundPosition"></param>
        /// <param name="newPlayerPosition"></param>
        public void Update(Vector3 newPlayerPosition)
        {
            listener.Position = newPlayerPosition;
            Stack <SoundCue> removableItems = new Stack <SoundCue>(activeSounds.Count);
            Stack <SoundCue> loopingItems   = new Stack <SoundCue>();

            for (int i = 0; i < activeSounds.Count; i++)
            {
                SoundCue cue = activeSounds[i];

                if (cue.Cue.IsStopped)
                {
                    if (cue.Loop)
                    {
                        loopingItems.Push(cue);
                    }

                    removableItems.Push(cue);
                }
                else
                {
                    if (cue.Listener.Position != newPlayerPosition)
                    {
                        cue.Listener.Position = newPlayerPosition;
                        //cue.Apply3DEffects(cue.Listener);
                    }
                }
            }

            // Remove expired items.
            while (removableItems.Count > 0)
            {
                SoundCue cue = removableItems.Pop();
                activeSounds.Remove(cue);
                try
                {
                    cue.Dispose();
                }
                catch (Exception e) { Console.WriteLine(e); }
            }

            // Re-play items that are looping.
            while (loopingItems.Count > 0)
            {
                SoundCue cue = loopingItems.Pop();
                Play3DSound(cue.Name, newPlayerPosition,
                            cue.Position, cue.Velocity, true);
            }

            audioEngine.Update();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Plays a sound based on location in a 3D world.
        /// </summary>
        /// <param name="_soundName">Name of the sound cue.</param>
        /// <param name="_playerPosition">Position of the player.</param>
        /// <param name="_position">Position of the sound -- basically, the position of the
        /// object which emits sound.</param>
        /// <param name="_velocity">Speed/direction in which the sound is moving.</param>
        /// <param name="_loop">True to loop the sound over and over; false otherwise.</param>
        public SoundCue Play3DSound(String _soundName, Vector3 _playerPosition,
                                    Vector3 _position, Vector3 _velocity, bool _loop)
        {
            SoundCue newCue = new SoundCue(soundBank.GetCue(_soundName), _soundName);

            newCue.Loop = _loop;

            listener.Position       = _playerPosition;
            newCue.Emitter.Velocity = _velocity;
            newCue.Emitter.Position = _position;
            newCue.Apply3DEffects(listener);

            activeSounds.Add(newCue);

            if (!muted)
            {
                newCue.Play();
            }

            return(newCue);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Stop a sound.
        /// </summary>
        /// <param name="sound">Sound cue to stop.</param>
        public void StopSound(String _soundName)
        {
            lock (this)
            {
                if (muted)
                {
                    return;
                }

                for (int i = 0; i < activeSounds.Count; i++)
                {
                    SoundCue cue = activeSounds[i];
                    if (cue.Name == _soundName)
                    {
                        cue.Stop();
                    }
                }

                throw new KeyNotFoundException(
                          "The sound cue " + _soundName + " does not exist.");
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Check to see if a sound is currently playing.
 /// </summary>
 /// <param name="cue"></param>
 /// <returns></returns>
 public bool SoundIsPlaying(SoundCue cue)
 {
     return(activeSounds.Contains(cue));
 }
Exemplo n.º 5
0
 public void PlaySoundEffect(SoundCue cue)
 {
     AudioManager.PlayEffectSafe(cue);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Check to see if a sound is currently playing.
 /// </summary>
 /// <param name="cue"></param>
 /// <returns></returns>
 public bool SoundIsPlaying(SoundCue cue)
 {
     return activeSounds.Contains(cue);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Plays a sound based on location in a 3D world.
        /// </summary>
        /// <param name="_soundName">Name of the sound cue.</param>
        /// <param name="_playerPosition">Position of the player.</param>
        /// <param name="_position">Position of the sound -- basically, the position of the
        /// object which emits sound.</param>
        /// <param name="_velocity">Speed/direction in which the sound is moving.</param>
        /// <param name="_loop">True to loop the sound over and over; false otherwise.</param>
        public SoundCue Play3DSound(String _soundName, Vector3 _playerPosition,
            Vector3 _position, Vector3 _velocity, bool _loop)
        {
            SoundCue newCue = new SoundCue(soundBank.GetCue(_soundName), _soundName);
            newCue.Loop = _loop;

            listener.Position = _playerPosition;
            newCue.Emitter.Velocity = _velocity;
            newCue.Emitter.Position = _position;
            newCue.Apply3DEffects(listener);

            activeSounds.Add(newCue);

            if (!muted)
            {
                newCue.Play();
            }

            return newCue;
        }