diff --git a/core/audio_player_portaudio.cpp b/core/audio_player_portaudio.cpp index 2eaee8f75..d095f7944 100644 --- a/core/audio_player_portaudio.cpp +++ b/core/audio_player_portaudio.cpp @@ -64,6 +64,7 @@ PortAudioPlayer::PortAudioPlayer() { playing = false; stopping = false; volume = 1.0f; + paStart = 0.0; } @@ -120,6 +121,7 @@ int PortAudioPlayer::paCallback(void *inputBuffer, void *outputBuffer, unsigned // Set play position (and real one) player->playPos += framesPerBuffer; + player->realPlayPos = (__int64)(Pa_StreamTime(player->stream) - player->paStart) + player->startPos; // Cap to start if lower return end; @@ -135,6 +137,7 @@ void PortAudioPlayer::Play(__int64 start,__int64 count) { // Set values endPos = start + count; playPos = start; + realPlayPos = start; startPos = start; // Start playing @@ -145,6 +148,7 @@ void PortAudioPlayer::Play(__int64 start,__int64 count) { } } playing = true; + paStart = Pa_StreamTime(stream); // Update timer if (displayTimer && !displayTimer->IsRunning()) displayTimer->Start(15); diff --git a/core/audio_player_portaudio.h b/core/audio_player_portaudio.h index 538e9f3fa..49af0b780 100644 --- a/core/audio_player_portaudio.h +++ b/core/audio_player_portaudio.h @@ -60,6 +60,8 @@ private: volatile __int64 startPos; volatile __int64 endPos; void *stream; + PaTimestamp paStart; + volatile __int64 realPlayPos; static int paCallback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, PaTimestamp outTime, void *userData); @@ -76,9 +78,9 @@ public: __int64 GetStartPosition() { return startPos; } __int64 GetEndPosition() { return endPos; } - __int64 GetCurrentPosition() { return playPos; } + __int64 GetCurrentPosition() { return realPlayPos; } void SetEndPosition(__int64 pos) { endPos = pos; } - void SetCurrentPosition(__int64 pos) { playPos = pos; } + void SetCurrentPosition(__int64 pos) { playPos = pos; realPlayPos = pos; } void SetVolume(double vol) { volume = vol; } double GetVolume() { return volume; }