diff --git a/aegisub/src/audio_player_portaudio2.cpp b/aegisub/src/audio_player_portaudio2.cpp index a150b266f..929aa7d18 100644 --- a/aegisub/src/audio_player_portaudio2.cpp +++ b/aegisub/src/audio_player_portaudio2.cpp @@ -130,7 +130,6 @@ int PortAudioPlayer::paCallback(const void *inputBuffer, void *outputBuffer, uns player->playPos += framesPerBuffer; const PaStreamInfo* streamInfo = Pa_GetStreamInfo(player->stream); - player->realPlayPos = (timeInfo->inputBufferAdcTime * streamInfo->sampleRate) + player->startPos; /* printf("playPos: %lld startPos: %lld paStart: %f currentTime: %f realPlayPos: %lld Pa_GetStreamTime: %f AdcTime: %f DacTime: %f\n", @@ -152,7 +151,6 @@ void PortAudioPlayer::Play(int64_t start,int64_t count) { // Set values endPos = start + count; playPos = start; - realPlayPos = start; startPos = start; // Start playing @@ -235,6 +233,23 @@ void PortAudioPlayer::CloseStream() { } catch (...) {} } +//////////////////////// +/// Get current stream position. +int64_t PortAudioPlayer::GetCurrentPosition() +{ + + if (!playing) return 0; + + const PaStreamInfo* streamInfo = Pa_GetStreamInfo(stream); +/* +int64_t real = ((Pa_GetStreamTime(stream) - paStart) * streamInfo->sampleRate) + startPos; +printf("GetCurrentPosition Pa_GetStreamTime: %f startPos: %lld playPos: %lld paStart: %f real: %lld\n", +Pa_GetStreamTime(stream), startPos, playPos, paStart, real); +*/ + return ((Pa_GetStreamTime(stream) - paStart) * streamInfo->sampleRate) + startPos; +} + + /////////////// /// Return a list of available output devices. diff --git a/aegisub/src/audio_player_portaudio2.h b/aegisub/src/audio_player_portaudio2.h index 7cde462ab..c7f049bf9 100644 --- a/aegisub/src/audio_player_portaudio2.h +++ b/aegisub/src/audio_player_portaudio2.h @@ -64,7 +64,6 @@ private: volatile int64_t endPos; void *stream; PaTime paStart; - volatile int64_t realPlayPos; static int paCallback( const void *inputBuffer, @@ -89,9 +88,9 @@ public: int64_t GetStartPosition() { return startPos; } int64_t GetEndPosition() { return endPos; } - int64_t GetCurrentPosition() { return realPlayPos; } + int64_t GetCurrentPosition(); void SetEndPosition(int64_t pos) { endPos = pos; } - void SetCurrentPosition(int64_t pos) { playPos = pos; realPlayPos = pos; } + void SetCurrentPosition(int64_t pos) { playPos = pos; } void SetVolume(double vol) { volume = vol; } double GetVolume() { return volume; }