From 2df6b2fd385824e0f7bf24091aef00220c271d87 Mon Sep 17 00:00:00 2001 From: Amar Takhar Date: Fri, 21 Aug 2009 20:08:58 +0000 Subject: [PATCH] Remove 'playing' global in favour of an IsPlaying function that uses Pa_IsStreamActive(). Updates #997. Originally committed to SVN as r3432. --- aegisub/src/audio_player_portaudio.cpp | 29 ++++++++++++++------------ aegisub/src/audio_player_portaudio.h | 7 +------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/aegisub/src/audio_player_portaudio.cpp b/aegisub/src/audio_player_portaudio.cpp index 7963d69f8..51d576843 100644 --- a/aegisub/src/audio_player_portaudio.cpp +++ b/aegisub/src/audio_player_portaudio.cpp @@ -72,7 +72,6 @@ PortAudioPlayer::PortAudioPlayer() { } // Variables - playing = false; stopping = false; volume = 1.0f; paStart = 0.0; @@ -129,10 +128,8 @@ void PortAudioPlayer::OpenStream() { /// @brief Close stream void PortAudioPlayer::CloseStream() { - try { - Stop(false); - Pa_CloseStream(stream); - } catch (...) {} + Stop(false); + Pa_CloseStream(stream); } @@ -141,8 +138,6 @@ void PortAudioPlayer::CloseStream() { void PortAudioPlayer::paStreamFinishedCallback(void *userData) { PortAudioPlayer *player = (PortAudioPlayer *) userData; - player->playing = false; - if (player->displayTimer) { player->displayTimer->Stop(); } @@ -167,7 +162,7 @@ void PortAudioPlayer::Play(int64_t start,int64_t count) { startPos = start; // Start playing - if (!playing) { + if (!IsPlaying()) { err = Pa_SetStreamFinishedCallback(stream, paStreamFinishedCallback); @@ -182,7 +177,6 @@ void PortAudioPlayer::Play(int64_t start,int64_t count) { return; } } - playing = true; paStart = Pa_GetStreamTime(stream); // Update timer @@ -199,7 +193,6 @@ void PortAudioPlayer::Stop(bool timerToo) { //softStop = false; // Stop stream - playing = false; Pa_StopStream (stream); // Stop timer @@ -219,7 +212,13 @@ void PortAudioPlayer::Stop(bool timerToo) { /// @param userData Local data to hand callback /// @return Whether to stop playback. /// -int PortAudioPlayer::paCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags, void *userData) { +int PortAudioPlayer::paCallback( + const void *inputBuffer, + void *outputBuffer, + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void *userData) { // Get provider PortAudioPlayer *player = (PortAudioPlayer *) userData; @@ -227,7 +226,7 @@ int PortAudioPlayer::paCallback(const void *inputBuffer, void *outputBuffer, uns #ifdef PORTAUDIO_DEBUG printf("paCallBack: playPos: %lld startPos: %lld paStart: %f Pa_GetStreamTime: %f AdcTime: %f DacTime: %f framesPerBuffer: %lu CPU: %f\n", - player->playPos, player->startPos, player->paStart, Pa_GetStreamTime(player->stream), + player->playPos, player->startPos, player->paStart, Pa_GetStreamTime(player->stream), timeInfo->inputBufferAdcTime, timeInfo->outputBufferDacTime, framesPerBuffer, Pa_GetStreamCpuLoad(player->stream)); #endif @@ -257,7 +256,7 @@ int PortAudioPlayer::paCallback(const void *inputBuffer, void *outputBuffer, uns int64_t PortAudioPlayer::GetCurrentPosition() { - if (!playing) return 0; + if (!IsPlaying()) return 0; const PaStreamInfo* streamInfo = Pa_GetStreamInfo(stream); @@ -297,4 +296,8 @@ wxArrayString PortAudioPlayer::GetOutputDevices(wxString favorite) { return list; } +bool PortAudioPlayer::IsPlaying() { + return Pa_IsStreamActive(stream); +} + #endif // WITH_PORTAUDIO diff --git a/aegisub/src/audio_player_portaudio.h b/aegisub/src/audio_player_portaudio.h index 9b1cb67c6..b3a6be382 100644 --- a/aegisub/src/audio_player_portaudio.h +++ b/aegisub/src/audio_player_portaudio.h @@ -65,13 +65,9 @@ private: /// Is playback being stopped? volatile bool stopping; - /// Currently Playing? - bool playing; - /// Current volume level. float volume; - /// Playback position. volatile int64_t playPos; @@ -111,8 +107,7 @@ public: /// @brief Whether audio is currently being played. /// @return Status - bool IsPlaying() { return playing; } - + bool IsPlaying(); /// @brief Position audio will be played from. /// @return Start position.