Esempio n. 1
0
    /// <summary>
    /// Allows the game component to update itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    public override void Update(GameTime gameTime)
    {
        // Update the XACT engine.
        m_audioEngine.Update();

        // Go through all the AudioCues looking for any that are finished
#if AUDIO_DEBUG
        int numPlaying = 0;
#endif
        for (UInt16 i = 0; i < MAX_AUDIO_CUE; ++i)
        {
            AudioHandle handle = m_cuePool.GetHandleByIndex(i);
            AudioCue    cue    = m_cuePool.GetItem(handle);
            if (null != cue)
            {         // this cue is alive
                if (AudioCue.State.PLAYING == cue.m_state)
                {     // it thinks it is playing
                    if (false == cue.m_cue.IsPlaying)
                    { // the sound isn't playing anymore - must have stopped
                        cue.Free();
                        cue.m_state = AudioCue.State.AVAILABLE;
                        m_cuePool.Free(handle);
#if AUDIO_DEBUG
                        --m_numPlaying;
                        ++m_numStopped;
                    }
                    else
                    {
                        ++numPlaying;
#endif
                    }
                }
            } //if (null != cue)
        }     //for (UInt16 i = 0; i < MAX_AUDIO_CUE; ++i)

#if AUDIO_DEBUG
        System.Diagnostics.Debug.Assert(numPlaying == m_numPlaying);
        System.Diagnostics.Debug.Assert(numPlaying == m_numPlayed - m_numStopped);
#endif

        base.Update(gameTime);
    }