1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-09 16:41:14 +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__ #ifdef __WXMAC__
// On Mac OS X, it's better not to use the wxThread class. // On Mac OS X, it's better not to use the wxThread class.
@ -946,7 +948,6 @@ class AudioThread {
private: private:
bool mDestroy; bool mDestroy;
pthread_t mThread; pthread_t mThread;
}; };
#else #else
@ -3229,6 +3230,10 @@ AudioThread::ExitCode AudioThread::Entry()
{ {
while( !TestDestroy() ) 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 // Set LoopActive outside the tests to avoid race condition
gAudioIO->mAudioThreadFillBuffersLoopActive = true; gAudioIO->mAudioThreadFillBuffersLoopActive = true;
if( gAudioIO->mAudioThreadShouldCallFillBuffersOnce ) if( gAudioIO->mAudioThreadShouldCallFillBuffersOnce )
@ -3242,16 +3247,11 @@ AudioThread::ExitCode AudioThread::Entry()
} }
gAudioIO->mAudioThreadFillBuffersLoopActive = false; gAudioIO->mAudioThreadFillBuffersLoopActive = false;
if (gAudioIO->mPlaybackSchedule.Interactive()) { if ( gAudioIO->mPlaybackSchedule.Interactive() )
// Rely on the Wait() in ScrubState::Consumer() std::this_thread::sleep_until(
// This allows the scrubbing update interval to be made very short without loopPassStart + std::chrono::milliseconds( interval ) );
// playback becoming intermittent. else
}
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.
Sleep(10); Sleep(10);
}
} }
return 0; return 0;

View File

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