/// <summary> /// Triggers a new 3D sound. /// </summary> public Cue Play3DCue(string cueName, IPhysicObject emitter) { Cue3D cue3D; if (this.m_CuePool.Count > 0) { // If possible, reuse an existing Cue3D instance. cue3D = this.m_CuePool.Pop(); } else { // Otherwise we have to allocate a new one. cue3D = new Cue3D(); } // Fill in the cue and emitter fields. cue3D.Cue = this.m_SoundBank.GetCue(cueName); cue3D.Emitter = emitter; // Set the 3D position of this cue, and then play it. Apply3D(cue3D); cue3D.Cue.Play(); // Remember that this cue is now active. this.m_ActiveCues.Add(cue3D); return(cue3D.Cue); }
/// <summary> /// Updates the position and velocity settings of a 3D cue. /// </summary> private void Apply3D(Cue3D cue3D) { if (emitter == null || cue3D == null || cue3D.Emitter == null) { return; } if (cue3D.Cue.IsDisposed) { return; } try { emitter.Position = cue3D.Emitter.Position; emitter.Forward = cue3D.Emitter.Forward; emitter.Up = cue3D.Emitter.Up; emitter.Velocity = cue3D.Emitter.Velocity; cue3D.Cue.Apply3D(FrameworkCore.audio.nearestListener(emitter.Position), emitter); } catch { } }
/// <summary> /// Triggers a new 3D sound /// </summary> /// <remarks> /// In order to free up unnecessary memory usage, the played cue is automatically destroyed /// when it stops playing. /// </remarks> /// <exception cref="GoblinException">Throws exception if this is called before Initialize(..)</exception> /// <param name="cueName">The name of the cue of a sound</param> /// <param name="emitter">An IAudioEmitter object that defines the properties of the sound /// including position, and velocity.</param> /// <returns></returns> public Cue Play3D(String cueName, IAudioEmitter emitter) { if (!initialized) { throw new GoblinException("Sound engine is not initialized. Call Sound.Initialize(..) first"); } Cue3D cue3D; if (cuePool.Count > 0) { // If possible, reuse an existing Cue3D instance. cue3D = cuePool.Pop(); } else { // Otherwise we have to allocate a new one. cue3D = new Cue3D(); } // Fill in the cue and emitter fields. cue3D.Cue = soundBank.GetCue(cueName); cue3D.Emitter = emitter; // Set the 3D position of this cue, and then play it. Apply3D(cue3D); cue3D.Cue.Play(); // Remember that this cue is now active. activeCues.Add(cue3D); return(cue3D.Cue); }
public override void Update(GameTime gameTime) { Listener.Position = new Vector3(DefenderWorld.Instance.Interface.Camera.Position.X, DefenderWorld.Instance.Interface.Camera.Position.Y, 100 / DefenderWorld.Instance.Interface.Camera.Zoom); int index = 0; while (index < mActiveCues.Count) { Cue3D cue3D = mActiveCues[index]; if (cue3D.Cue.IsStopped) { cue3D.Cue.Dispose(); mCuePool.Push(cue3D); mActiveCues.RemoveAt(index); } else { Apply3D(cue3D); index++; } } Engine.Update(); base.Update(gameTime); }
/// <summary> /// Updates the state of the 3D audio system. /// </summary> public override void Update(GameTime gameTime) { // Loop over all the currently playing 3D sounds. int index = 0; while (index < this.m_ActiveCues.Count) { Cue3D cue3D = this.m_ActiveCues[index]; if (cue3D.Cue.IsStopped) { // If the cue has stopped playing, dispose it. cue3D.Cue.Dispose(); // Store the Cue3D instance for future reuse. this.m_CuePool.Push(cue3D); // Remove it from the active list. this.m_ActiveCues.RemoveAt(index); } else { // If the cue is still playing, update its 3D settings. Apply3D(cue3D); index++; } } // Update the XACT engine. this.m_AudioEngine.Update(); base.Update(gameTime); }
/// <summary> /// Updates the position and velocity settings of a 3D cue. /// </summary> private void Apply3D(Cue3D cue3D) { this.m_Emitter.Position = cue3D.Emitter.Position; this.m_Emitter.Forward = Vector3.Forward; this.m_Emitter.Up = Vector3.Up; this.m_Emitter.Velocity = Vector3.Zero; cue3D.Cue.Apply3D(this.Listener, this.m_Emitter); }
/// <summary> /// Updates the position and velocity settings of a 3D cue. /// </summary> private void Apply3D(Cue3D cue3D) { emitter.Position = cue3D.Emitter.Position; emitter.Forward = cue3D.Emitter.Forward; emitter.Up = cue3D.Emitter.Up; emitter.Velocity = cue3D.Emitter.Velocity; cue3D.Cue.Apply3D(listener, emitter); }
/// <summary> /// Triggers a new 3D sound. /// </summary> public Cue Play3DCue(string cueName, IAudioEmitter emitter) { if (FrameworkCore.gameState != GameState.Play || FrameworkCore.soundbank == null) { return(null); } Cue3D cue3D; if (cuePool.Count > 0) { // If possible, reuse an existing Cue3D instance. cue3D = cuePool.Pop(); } else { // Otherwise we have to allocate a new one. cue3D = new Cue3D(); } // Fill in the cue and emitter fields. try { cue3D.Cue = FrameworkCore.soundbank.GetCue(cueName); } catch { } cue3D.Emitter = emitter; // Set the 3D position of this cue, and then play it. Apply3D(cue3D); try { cue3D.Cue.Play(); } catch { } // Remember that this cue is now active. activeCues.Add(cue3D); return(cue3D.Cue); }
/// <summary> /// pauses a cue. /// </summary> /// <param name="sound">playing sound element</param> private bool PauseSound(Cue3D cue3D) { //sanity check. if (cue3D.Cue == null || cue3D.Emitter == null || cue3D == null) { return(false); } if (cue3D.Cue.IsPlaying) { cue3D.Cue.Pause(); return(true); } return(false); }
/// <summary> /// resumes a cue. /// </summary> /// <param name="sound">paused sound element</param> private bool ResumeSound(Cue3D cue3D) { //sanity check. if (cue3D.Cue == null || cue3D.Emitter == null || cue3D == null) { return(false); } if (cue3D.Cue.IsPaused) { cue3D.Cue.Resume(); return(true); } return(false); }
public Cue Play3DCue(string cueName, Vector2 position) { Cue3D cue3D; if (mCuePool.Count > 0) { cue3D = mCuePool.Pop(); } else { cue3D = new Cue3D(); } cue3D.Cue = SoundBank.GetCue(cueName); cue3D.Position = new Vector3(position.X, position.Y, 0); Apply3D(cue3D); cue3D.Cue.Play(); mActiveCues.Add(cue3D); return cue3D.Cue; }
/// <summary> /// Updates the state of the 3D audio system. /// </summary> public void Update(GameTime gameTime) { soundUpdateTimer -= (int)gameTime.ElapsedGameTime.TotalMilliseconds; if (soundUpdateTimer > 0) { return; } soundUpdateTimer = 150; //update sound at this interval. // Loop over all the currently playing 3D sounds. int index = 0; while (index < activeCues.Count) { Cue3D cue3D = activeCues[index]; if (cue3D.Cue.IsStopped) { // If the cue has stopped playing, dispose it. cue3D.Cue.Dispose(); // Store the Cue3D instance for future reuse. cuePool.Push(cue3D); // Remove it from the active list. activeCues.RemoveAt(index); } else { // If the cue is still playing, update its 3D settings. Apply3D(cue3D); index++; } } // Update the XACT engine. //audioEngine.Update(); }
public Cue Play3DCue(string cueName, Vector2 position) { Cue3D cue3D; if (mCuePool.Count > 0) { cue3D = mCuePool.Pop(); } else { cue3D = new Cue3D(); } cue3D.Cue = SoundBank.GetCue(cueName); cue3D.Position = new Vector3(position.X, position.Y, 0); Apply3D(cue3D); cue3D.Cue.Play(); mActiveCues.Add(cue3D); return(cue3D.Cue); }
/// <summary> /// Triggers a new 3D sound. /// </summary> public Cue Play3DCue( string cueName, IAudioEmitter emitter, float volume ) { Cue3D cue3D; if ( cuePool.Count > 0 ) { // If possible, reuse an existing Cue3D instance. cue3D = cuePool.Pop(); } else { // Otherwise we have to allocate a new one. cue3D = new Cue3D(); } // Fill in the cue and emitter fields. cue3D.Cue = soundBank.GetCue( cueName ); cue3D.Emitter = emitter; // Set the 3D position of this cue, and then play it. Apply3D( cue3D ); float volScale = GameCore.Instance.SoundEffectsVolume; // Set volume of cue /**/ if ( volume <= 0 ) cue3D.Cue.SetVariable( VarVolume, -96 ); else cue3D.Cue.SetVariable( VarVolume, MathHelper.Clamp( 10f * (float)Math.Log10( volume * volScale ), -96, 6 ) ); /*/ cue3D.Cue.SetVariable( varVolume, XACTHelper.GetDecibels( volume * volScale ) ); /**/ cue3D.Cue.Play(); // Remember that this cue is now active. activeCues.Add( cue3D ); return cue3D.Cue; }
private void Apply3D(Cue3D cue3D) { mEmitter.Position = cue3D.Position; cue3D.Cue.Apply3D(Listener, mEmitter); }
/// <summary> /// Updates the XNA audio engine /// </summary> /// <param name="elapsedTime"></param> internal void Update(TimeSpan elapsedTime) { #if WINDOWS_PHONE // Update our timer gameHasControlTimer += (float)elapsedTime.TotalSeconds; // If we've passed our poll delay, we want to handle our update if (gameHasControlTimer >= PollDelay) { // Reset the timer back to zero gameHasControlTimer = 0f; // Check to see if we have control of the media player gameHasControl = MediaPlayer.GameHasControl; // Get the current state and song from the MediaPlayer MediaState currentState = MediaPlayer.State; Song activeSong = MediaPlayer.Queue.ActiveSong; // If we have control of the music... if (gameHasControl) { // If we have a song that we want playing... if (backgroundMusic != null) { // If the media player isn't playing anything... if (currentState != MediaState.Playing) { // If the song is paused, for example because the headphones // were removed, we call Resume() to continue playback. if (currentState == MediaState.Paused) { ResumeSongSafe(); } // Otherwise we play our desired song. else { PlaySongSafe(); } } } // If we don't have a song we want playing, we want to make sure we stop // any music we may have previously had playing. else { if (currentState != MediaState.Stopped) { MediaPlayer.Stop(); } } } } #else if (initialized) { // Loop over all the currently playing 3D sounds. int index = 0; while (index < activeCues.Count) { Cue3D cue3D = activeCues[index]; if (cue3D.Cue.IsStopped) { // If the cue has stopped playing, dispose it. cue3D.Cue.Dispose(); // Store the Cue3D instance for future reuse. cuePool.Push(cue3D); // Remove it from the active list. activeCues.RemoveAt(index); } else { // If the cue is still playing and it's 3D, update its 3D settings. if (cue3D.Emitter != null) { Apply3D(cue3D); } index++; } } // Update the XACT engine. audioEngine.Update(); } #endif List <Sound3D> removeList = new List <Sound3D>(); foreach (Sound3D sound3d in sound3Ds) { if (sound3d.Sound.State == SoundState.Stopped) { removeList.Add(sound3d); } else { Apply3D(sound3d); } } foreach (Sound3D sound3d in removeList) { sound3d.Sound.Dispose(); sound3Ds.Remove(sound3d); } }
/// <summary> /// Updates the position and velocity settings of a 3D cue. /// </summary> private void Apply3D( Cue3D cue3D ) { emitter.Position = cue3D.Emitter.Position; emitter.Forward = cue3D.Emitter.Forward; emitter.Up = cue3D.Emitter.Up; emitter.Velocity = cue3D.Emitter.Velocity; cue3D.Cue.Apply3D( listener, emitter ); }
private void Apply3D(Cue3D cue3D) { emitter.Position = cue3D.Position; cue3D.Cue.Apply3D(listener, emitter); }