Don't set the current position via the PortAudio callback, instead set

GetCurrentPosition() to return the correct value using Pa_GetStreamTime().  Not
only does it not work on every platform, there is no point in setting it during
the callback as GetCurrentPosition() isn't called very often (in comparison)
when updating the play bar.  Eventually this should be changed to update the
playbar via a callback to get a position that's a lot more accurate.

Originally committed to SVN as r2798.
This commit is contained in:
Amar Takhar 2009-04-15 17:50:16 +00:00
parent b63c2ea27c
commit 918945e03b
2 changed files with 19 additions and 5 deletions

View file

@ -130,7 +130,6 @@ int PortAudioPlayer::paCallback(const void *inputBuffer, void *outputBuffer, uns
player->playPos += framesPerBuffer; player->playPos += framesPerBuffer;
const PaStreamInfo* streamInfo = Pa_GetStreamInfo(player->stream); 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", 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 // Set values
endPos = start + count; endPos = start + count;
playPos = start; playPos = start;
realPlayPos = start;
startPos = start; startPos = start;
// Start playing // Start playing
@ -235,6 +233,23 @@ void PortAudioPlayer::CloseStream() {
} catch (...) {} } 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. /// Return a list of available output devices.

View file

@ -64,7 +64,6 @@ private:
volatile int64_t endPos; volatile int64_t endPos;
void *stream; void *stream;
PaTime paStart; PaTime paStart;
volatile int64_t realPlayPos;
static int paCallback( static int paCallback(
const void *inputBuffer, const void *inputBuffer,
@ -89,9 +88,9 @@ public:
int64_t GetStartPosition() { return startPos; } int64_t GetStartPosition() { return startPos; }
int64_t GetEndPosition() { return endPos; } int64_t GetEndPosition() { return endPos; }
int64_t GetCurrentPosition() { return realPlayPos; } int64_t GetCurrentPosition();
void SetEndPosition(int64_t pos) { endPos = pos; } 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; } void SetVolume(double vol) { volume = vol; }
double GetVolume() { return volume; } double GetVolume() { return volume; }