SHARE
TWEET

Audio transport logic example

a guest Jan 22nd, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. enum TransportState
  2. {
  3.     NONE,
  4.     PREPARING,
  5.     PREPARED,
  6.     PLAYING,
  7.     STOPPING,
  8.     STOPPED
  9. };
  10.  
  11. void AudioTransport::Update(const float fElapsedTime)
  12. {
  13.     switch(m_currentState)
  14.     {
  15.     case TransportState::NONE:
  16.         if(bPrepareToPlayRequested)
  17.             m_currentState = TransportState::PREPARING;
  18.         break;
  19.     case TransportState::PREPARING:
  20.         if(!IsPreparedToPlay())
  21.             PrepareToPlay();
  22.         else
  23.             m_currentState = TransportState::PREPARED;
  24.         break;
  25.     case TransportState::PREPARED:
  26.         if(bPlayRequested)
  27.         {
  28.             Play();
  29.             m_currentState = TransportState::PLAYING;
  30.         }
  31.         break;
  32.     case TransportState::PLAYING:
  33.         if(!IsPlaying() || bStopRequested)
  34.             m_currentState = TransportState::STOPPING;
  35.         break;
  36.     case TransportState::STOPPING:
  37.         UpdateFadeout(fElapsedTime);
  38.         if(FadedOut())
  39.         {
  40.             Stop();
  41.             m_currentState == TransportState::STOPPED;
  42.         }
  43.         break;
  44.     case default:
  45.         LogError(“Invalid AudioTransport state\n”);
  46.         break;
  47.     }
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top