From f78a418df8c345367556318fe550a1e059d7efaf Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 17 Jan 2018 18:12:12 -0500 Subject: [PATCH] An alpha-only toggle command for extra dropout detection; default off --- src/AudioIO.cpp | 6 ++++-- src/AudioIO.h | 4 ++++ src/Menus.cpp | 11 +++++++++++ src/Menus.h | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index c5e96fd07..8d1008364 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -5168,8 +5168,10 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer, bool inputError = (statusFlags & (paInputOverflow)) && !(statusFlags & paPrimingOutput); + // But it seems it's easy to get false positives, at least on Mac - wxUnusedVar( inputError ); + // So we have not decided to enable this extra detection yet in + // production size_t len = framesPerBuffer; for(unsigned t = 0; t < numCaptureChannels; t++) @@ -5186,7 +5188,7 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer, // enough from mCaptureBuffers; maybe it's CPU-bound, or maybe the // storage device it writes is too slow if (gAudioIO->mDetectDropouts && - (//inputError || + ((gAudioIO->mDetectUpstreamDropouts && inputError) || len < framesPerBuffer) ) { // Assume that any good partial buffer should be written leftmost // and zeroes will be padded after; label the zeroes. diff --git a/src/AudioIO.h b/src/AudioIO.h index a6476939e..c84eb140a 100644 --- a/src/AudioIO.h +++ b/src/AudioIO.h @@ -807,6 +807,10 @@ public: // Used only for testing purposes in alpha builds bool mSimulateRecordingErrors{ false }; + + // Whether to check the error code passed to audacityAudioCallback to + // detect more dropouts + bool mDetectUpstreamDropouts{ false }; }; #endif diff --git a/src/Menus.cpp b/src/Menus.cpp index 779b0431e..8f833fec1 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -1237,6 +1237,10 @@ void AudacityProject::CreateMenusAndCommands() _("Simulate Recording Errors"), FN(OnSimulateRecordingErrors), gAudioIO->mSimulateRecordingErrors); + c->AddCheck(wxT("DetectUpstreamDropouts"), + _("Detect Upstream Dropouts"), + FN(OnDetectUpstreamDropouts), + gAudioIO->mDetectUpstreamDropouts); #endif c->AddItem(wxT("Screenshot"), _("&Screenshot Tools..."), FN(OnScreenshot)); @@ -8422,6 +8426,13 @@ void AudacityProject::OnSimulateRecordingErrors(const CommandContext &) setting = !setting; } +void AudacityProject::OnDetectUpstreamDropouts(const CommandContext &) +{ + bool &setting = gAudioIO->mDetectUpstreamDropouts; + mCommandManager.Check(wxT("DetectUpstreamDropouts"), !setting); + setting = !setting; +} + void AudacityProject::OnScreenshot(const CommandContext &) { ::OpenScreenshotTools(); diff --git a/src/Menus.h b/src/Menus.h index 91637188d..fe832f202 100644 --- a/src/Menus.h +++ b/src/Menus.h @@ -510,6 +510,7 @@ void OnBenchmark(const CommandContext &); void OnCrashReport(const CommandContext &); #endif void OnSimulateRecordingErrors(const CommandContext &); +void OnDetectUpstreamDropouts(const CommandContext &); void OnScreenshot(const CommandContext &); void OnAudioDeviceInfo(const CommandContext &); #ifdef EXPERIMENTAL_MIDI_OUT