New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use two separate RtAudio streams when input != output device #1235
Conversation
0235e34
to
e9dee32
Compare
RtAudio supports the creation of streams that are input-only, output-only, or input + output (duplex). Previously, we always used a single duplex stream even when the input and output devices differ. This is problematic because each device may have its own clock, and trigger callbacks at different points in time. RtAudio therefore needed to wait for both audio interfaces to trigger callbacks before it could trigger its own, reducing the interval of time that JackTrip has to perform its work. If the delta between the interface callbacks is small enough, relative to the work JackTrip is performing, everything work just fine. However, over time we've added more CPU intensive work in the JackTrip callbacks, such as PLC. If the delta is too short, callbacks get missed causing audio glitches. By using separate (simplex) RtAudio streams for input and output, we are able to decouple the two audio interfaces from one another, ensuring that JackTrip always has the maximum amount of time available to "do its thing."
e9dee32
to
4fe5bec
Compare
This seemed to sort of kind of work sometimes, but is very buggy.
0dc227a
to
2c19a05
Compare
12e3665
to
9274742
Compare
Note that this requires and incorporates a patch for an RtAudio bug as described here thestk/rtaudio#417 |
on first call to AudioInterface::audioOutputCallback. When using two different devices, the input device could start triggering callbacks before the output device. This can cause several pushes into the monitor queue before the output callback performs its first pop. The net result is random variable latency added to the monitor signal. Draining the queue ensures that the two will also be as in sync as possible. Note that for duplex devices, the queue would never grow larger than a size of 1, and drop down to zero before the audio callback returns.
b84eaec
to
f7c0933
Compare
@cchafe note that this appears to solve a problem with bufstrategy 4 (PLC in callback, or no worker thread), where using two different audio interfaces on OSX would cause audio artifacts. With this, I think we can finally do away with the extra queue & worker thread (bufstrategy 3), shaving off an extra buffer or more of latency. |
445d1f7
to
2776d09
Compare
Since the pip version uses outdated version of meson where diff_files is broken
2776d09
to
39a6e55
Compare
very cool news! |
c7aeef5
to
6baacac
Compare
It sounds like your build has the rtaudio bug I had to fix. Wipe out your subprojects/rtaudio-6.0.1 directory, your builddir directory, and re-run meson setup & compile. You can also look at the RtAudio.cpp file to verify that the patch was applied by meson. |
RtAudio supports the creation of streams that are input-only, output-only, or input + output (duplex). Previously, we always used a single duplex stream even when the input and output devices differ. This is problematic because each device may have its own clock, and trigger callbacks at different points in time.
RtAudio therefore needed to wait for both audio interfaces to trigger callbacks before it could trigger its own, reducing the interval of time that JackTrip has to perform its work. If the delta between the interface callbacks is small enough, relative to the work JackTrip is performing, everything work just fine. However, over time we've added more CPU intensive work in the JackTrip callbacks, such as PLC. If the delta is too short, callbacks get missed causing audio glitches.
By using separate (simplex) RtAudio streams for input and output, we are able to decouple the two audio interfaces from one another, ensuring that JackTrip always has the maximum amount of time available to "do its thing."