From ce649cf851579992604ef81b40a1aaf904dbab1e Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sat, 23 Sep 2017 20:37:41 -0400 Subject: [PATCH] Re-enabling the separate MIDI thread, and comments about that --- src/AudioIO.cpp | 14 ++++++++++++-- src/AudioIO.h | 12 ++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index 629bdce8e..a8d145dbc 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -441,8 +441,14 @@ writing audio. #ifdef EXPERIMENTAL_MIDI_OUT #define MIDI_SLEEP 10 /* milliseconds */ - // how long do we think the thread might be delayed due to other threads? - #define THREAD_LATENCY 10 /* milliseconds */ + // how long do we think the thread that fills MIDI buffers, + // if it is separate from the portaudio thread, + // might be delayed due to other threads? + #ifdef USE_MIDI_THREAD + #define THREAD_LATENCY 10 /* milliseconds */ + #else + #define THREAD_LATENCY 0 /* milliseconds */ + #endif #define ROUND(x) (int) ((x)+0.5) //#include #include "../lib-src/portmidi/pm_common/portmidi.h" @@ -4987,6 +4993,8 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer, if ((gAudioIO->ReversedTime() ? gAudioIO->mTime <= gAudioIO->mT1 : gAudioIO->mTime >= gAudioIO->mT1)) + // PRL: singalling MIDI output complete is necessary if + // not USE_MIDI_THREAD, otherwise it's harmlessly redundant gAudioIO->mMidiOutputComplete = true, callbackReturn = paComplete; } @@ -5048,6 +5056,8 @@ int audacityAudioCallback(const void *inputBuffer, void *outputBuffer, ? gAudioIO->mTime <= gAudioIO->mT1 : gAudioIO->mTime >= gAudioIO->mT1)) { + // PRL: singalling MIDI output complete is necessary if + // not USE_MIDI_THREAD, otherwise it's harmlessly redundant gAudioIO->mMidiOutputComplete = true, callbackReturn = paComplete; } diff --git a/src/AudioIO.h b/src/AudioIO.h index 506232d62..40e997ed0 100644 --- a/src/AudioIO.h +++ b/src/AudioIO.h @@ -93,11 +93,15 @@ DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_AUDIOIO_PLAYBACK, -1); DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_AUDIOIO_CAPTURE, -1); DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_AUDIOIO_MONITOR, -1); +// PRL: // If we always run a portaudio output stream (even just to produce silence) -// whenever we play Midi, then we can use just one thread for both, which -// simplifies synchronization problems and avoids the rush of notes at start of -// play. PRL. -#undef USE_MIDI_THREAD +// whenever we play Midi, then we might use just one thread for both. +// I thought this would improve MIDI synch problems on Linux/ALSA, but RBD +// convinced me it was neither a necessary nor sufficient fix. Perhaps too the +// MIDI thread might block in some error situations but we should then not +// also block the audio thread. +// So leave the separate thread ENABLED. +#define USE_MIDI_THREAD struct ScrubbingOptions;