Remove 'playing' global in favour of an IsPlaying function that uses Pa_IsStreamActive(). Updates #997.

Originally committed to SVN as r3432.
This commit is contained in:
Amar Takhar 2009-08-21 20:08:58 +00:00
parent f5a9af6a6c
commit 2df6b2fd38
2 changed files with 17 additions and 19 deletions

View File

@ -72,7 +72,6 @@ PortAudioPlayer::PortAudioPlayer() {
} }
// Variables // Variables
playing = false;
stopping = false; stopping = false;
volume = 1.0f; volume = 1.0f;
paStart = 0.0; paStart = 0.0;
@ -129,10 +128,8 @@ void PortAudioPlayer::OpenStream() {
/// @brief Close stream /// @brief Close stream
void PortAudioPlayer::CloseStream() { void PortAudioPlayer::CloseStream() {
try { Stop(false);
Stop(false); Pa_CloseStream(stream);
Pa_CloseStream(stream);
} catch (...) {}
} }
@ -141,8 +138,6 @@ void PortAudioPlayer::CloseStream() {
void PortAudioPlayer::paStreamFinishedCallback(void *userData) { void PortAudioPlayer::paStreamFinishedCallback(void *userData) {
PortAudioPlayer *player = (PortAudioPlayer *) userData; PortAudioPlayer *player = (PortAudioPlayer *) userData;
player->playing = false;
if (player->displayTimer) { if (player->displayTimer) {
player->displayTimer->Stop(); player->displayTimer->Stop();
} }
@ -167,7 +162,7 @@ void PortAudioPlayer::Play(int64_t start,int64_t count) {
startPos = start; startPos = start;
// Start playing // Start playing
if (!playing) { if (!IsPlaying()) {
err = Pa_SetStreamFinishedCallback(stream, paStreamFinishedCallback); err = Pa_SetStreamFinishedCallback(stream, paStreamFinishedCallback);
@ -182,7 +177,6 @@ void PortAudioPlayer::Play(int64_t start,int64_t count) {
return; return;
} }
} }
playing = true;
paStart = Pa_GetStreamTime(stream); paStart = Pa_GetStreamTime(stream);
// Update timer // Update timer
@ -199,7 +193,6 @@ void PortAudioPlayer::Stop(bool timerToo) {
//softStop = false; //softStop = false;
// Stop stream // Stop stream
playing = false;
Pa_StopStream (stream); Pa_StopStream (stream);
// Stop timer // Stop timer
@ -219,7 +212,13 @@ void PortAudioPlayer::Stop(bool timerToo) {
/// @param userData Local data to hand callback /// @param userData Local data to hand callback
/// @return Whether to stop playback. /// @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 // Get provider
PortAudioPlayer *player = (PortAudioPlayer *) userData; PortAudioPlayer *player = (PortAudioPlayer *) userData;
@ -257,7 +256,7 @@ int PortAudioPlayer::paCallback(const void *inputBuffer, void *outputBuffer, uns
int64_t PortAudioPlayer::GetCurrentPosition() int64_t PortAudioPlayer::GetCurrentPosition()
{ {
if (!playing) return 0; if (!IsPlaying()) return 0;
const PaStreamInfo* streamInfo = Pa_GetStreamInfo(stream); const PaStreamInfo* streamInfo = Pa_GetStreamInfo(stream);
@ -297,4 +296,8 @@ wxArrayString PortAudioPlayer::GetOutputDevices(wxString favorite) {
return list; return list;
} }
bool PortAudioPlayer::IsPlaying() {
return Pa_IsStreamActive(stream);
}
#endif // WITH_PORTAUDIO #endif // WITH_PORTAUDIO

View File

@ -65,13 +65,9 @@ private:
/// Is playback being stopped? /// Is playback being stopped?
volatile bool stopping; volatile bool stopping;
/// Currently Playing?
bool playing;
/// Current volume level. /// Current volume level.
float volume; float volume;
/// Playback position. /// Playback position.
volatile int64_t playPos; volatile int64_t playPos;
@ -111,8 +107,7 @@ public:
/// @brief Whether audio is currently being played. /// @brief Whether audio is currently being played.
/// @return Status /// @return Status
bool IsPlaying() { return playing; } bool IsPlaying();
/// @brief Position audio will be played from. /// @brief Position audio will be played from.
/// @return Start position. /// @return Start position.