The Emp^W realPlayPos strikes back. Respect audio latency.

Originally committed to SVN as r351.
This commit is contained in:
David Lamparter 2006-04-20 12:02:38 +00:00
parent 66e988ff86
commit cc8022f629
2 changed files with 8 additions and 2 deletions

View File

@ -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);

View File

@ -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; }