From 8ba5aa27be08cfbb2fb9183cf15bff738ac8cb2b Mon Sep 17 00:00:00 2001 From: Amar Takhar Date: Fri, 21 Aug 2009 21:40:18 +0000 Subject: [PATCH] Move stream position info into it's own struct.. Looks like a few globals can't be helped due to how the AudioPlayer class is designed. If I have to use globals I'll atleast make them easier to manage.. Updates #997. Originally committed to SVN as r3434. --- aegisub/src/audio_player_portaudio.cpp | 30 +++++++++++------------ aegisub/src/audio_player_portaudio.h | 34 ++++++++++---------------- 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/aegisub/src/audio_player_portaudio.cpp b/aegisub/src/audio_player_portaudio.cpp index e15468d8f..17c9b0fad 100644 --- a/aegisub/src/audio_player_portaudio.cpp +++ b/aegisub/src/audio_player_portaudio.cpp @@ -73,7 +73,7 @@ PortAudioPlayer::PortAudioPlayer() { // Variables volume = 1.0f; - paStart = 0.0; + pos.pa_start = 0.0; } @@ -153,9 +153,9 @@ void PortAudioPlayer::Play(int64_t start,int64_t count) { PaError err; // Set values - endPos = start + count; - playPos = start; - startPos = start; + pos.end = start + count; + pos.current = start; + pos.start = start; // Start playing if (!IsPlaying()) { @@ -173,7 +173,7 @@ void PortAudioPlayer::Play(int64_t start,int64_t count) { return; } } - paStart = Pa_GetStreamTime(stream); + pos.pa_start = Pa_GetStreamTime(stream); // Update timer if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15); @@ -218,21 +218,21 @@ int PortAudioPlayer::paCallback( AudioProvider *provider = player->GetProvider(); #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), + printf("paCallBack: pos.current: %lld pos.start: %lld paStart: %f Pa_GetStreamTime: %f AdcTime: %f DacTime: %f framesPerBuffer: %lu CPU: %f\n", + player->pos.current, player->pos.start, player->paStart, Pa_GetStreamTime(player->stream), timeInfo->inputBufferAdcTime, timeInfo->outputBufferDacTime, framesPerBuffer, Pa_GetStreamCpuLoad(player->stream)); #endif // Calculate how much left - int64_t lenAvailable = (player->endPos - player->playPos) > 0 ? framesPerBuffer : 0; + int64_t lenAvailable = (player->pos.end - player->pos.current) > 0 ? framesPerBuffer : 0; // Play something if (lenAvailable > 0) { - provider->GetAudioWithVolume(outputBuffer, player->playPos, lenAvailable, player->GetVolume()); + provider->GetAudioWithVolume(outputBuffer, player->pos.current, lenAvailable, player->GetVolume()); // Set play position - player->playPos += framesPerBuffer; + player->pos.current += framesPerBuffer; // Continue as normal return 0; @@ -255,15 +255,15 @@ int64_t PortAudioPlayer::GetCurrentPosition() #ifdef PORTAUDIO_DEBUG PaTime pa_getstream = Pa_GetStreamTime(stream); - int64_t real = ((pa_getstream - paStart) * streamInfo->sampleRate) + startPos; - printf("GetCurrentPosition: Pa_GetStreamTime: %f startPos: %lld playPos: %lld paStart: %f real: %lld diff: %f\n", - pa_getstream, startPos, playPos, paStart, real, pa_getstream-paStart); + int64_t real = ((pa_getstream - paStart) * streamInfo->sampleRate) + pos.start; + printf("GetCurrentPosition: Pa_GetStreamTime: %f pos.start: %lld pos.current: %lld paStart: %f real: %lld diff: %f\n", + pa_getstream, pos.start, pos.current, paStart, real, pa_getstream-paStart); return real; -#else - return ((Pa_GetStreamTime(stream) - paStart) * streamInfo->sampleRate) + startPos; #endif + return ((Pa_GetStreamTime(stream) - pos.pa_start) * streamInfo->sampleRate) + pos.start; + } diff --git a/aegisub/src/audio_player_portaudio.h b/aegisub/src/audio_player_portaudio.h index 80fe11838..78ee6824a 100644 --- a/aegisub/src/audio_player_portaudio.h +++ b/aegisub/src/audio_player_portaudio.h @@ -47,36 +47,29 @@ extern "C" { #include } - - - /// @class PortAudioPlayer /// @brief PortAudio Player /// class PortAudioPlayer : public AudioPlayer { private: - /// DOCME + /// Initialisation reference counter. static int pa_refcount; /// Current volume level. float volume; - /// Playback position. - volatile int64_t playPos; + /// @brief Stream playback position info. + typedef struct PositionInfo { + volatile int64_t current; /// Current position. + volatile int64_t start; /// Start position. + volatile int64_t end; /// End position. + PaTime pa_start; /// PortAudio internal start position. + }; + PositionInfo pos; - /// Playback start position. - volatile int64_t startPos; - - /// Playback end position. - volatile int64_t endPos; - - /// Audio Stream void *stream; - /// PortAudio internal start position. - PaTime paStart; - static int paCallback( const void *inputBuffer, void *outputBuffer, @@ -105,20 +98,20 @@ public: /// @brief Position audio will be played from. /// @return Start position. - int64_t GetStartPosition() { return startPos; } + int64_t GetStartPosition() { return pos.start; } /// @brief End position playback will stop at. /// @return End position. - int64_t GetEndPosition() { return endPos; } + int64_t GetEndPosition() { return pos.end; } int64_t GetCurrentPosition(); /// @brief Set end position of playback /// @param pos End position - void SetEndPosition(int64_t pos) { endPos = pos; } + void SetEndPosition(int64_t position) { pos.end = position; } /// @brief Set current position of playback. /// @param pos Current position - void SetCurrentPosition(int64_t pos) { playPos = pos; } + void SetCurrentPosition(int64_t position) { pos.current = position; } /// @brief Set volume level @@ -133,7 +126,6 @@ public: }; - /// @class PortAudioPlayerFactory /// @brief PortAudio Player Factory class PortAudioPlayerFactory : public AudioPlayerFactory {