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:
parent
f5a9af6a6c
commit
2df6b2fd38
2 changed files with 17 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue