1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +02:00

Make AudioThread wake-ups as uniformly spaced as we can

This commit is contained in:
Paul Licameli 2018-08-15 21:38:20 -04:00
parent 0c0cc07686
commit a62cf53161
2 changed files with 11 additions and 11 deletions

View File

@ -911,6 +911,8 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer,
//
//////////////////////////////////////////////////////////////////////
#include <thread>
#ifdef __WXMAC__
// On Mac OS X, it's better not to use the wxThread class.
@ -946,7 +948,6 @@ class AudioThread {
private:
bool mDestroy;
pthread_t mThread;
};
#else
@ -3229,6 +3230,10 @@ AudioThread::ExitCode AudioThread::Entry()
{
while( !TestDestroy() )
{
using Clock = std::chrono::steady_clock;
auto loopPassStart = Clock::now();
const auto interval = Scrubber::ScrubPollInterval_ms;
// Set LoopActive outside the tests to avoid race condition
gAudioIO->mAudioThreadFillBuffersLoopActive = true;
if( gAudioIO->mAudioThreadShouldCallFillBuffersOnce )
@ -3242,16 +3247,11 @@ AudioThread::ExitCode AudioThread::Entry()
}
gAudioIO->mAudioThreadFillBuffersLoopActive = false;
if (gAudioIO->mPlaybackSchedule.Interactive()) {
// Rely on the Wait() in ScrubState::Consumer()
// This allows the scrubbing update interval to be made very short without
// playback becoming intermittent.
}
else {
// Perhaps this too could use a condition variable, for available space in the
// ring buffer, instead of a polling loop? But no harm in doing it this way.
if ( gAudioIO->mPlaybackSchedule.Interactive() )
std::this_thread::sleep_until(
loopPassStart + std::chrono::milliseconds( interval ) );
else
Sleep(10);
}
}
return 0;

View File

@ -76,7 +76,7 @@ public:
Scrubber(AudacityProject *project);
~Scrubber();
// Assume xx is relative to the left edge of TrackPanel!
void MarkScrubStart(wxCoord xx, bool smoothScrolling, bool seek);