commit 4f981c5336c48052cdffeb463572365bf2315c37
parent ad3c5dae30b548134635873ee05e021d18da2e5e
Author: falkTX <falktx@falktx.com>
Date: Fri, 22 Jul 2022 15:37:47 +0100
Implement buffer size changes in RtAudio native audio fallback
Diffstat:
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/distrho/src/jackbridge/RtAudioBridge.hpp b/distrho/src/jackbridge/RtAudioBridge.hpp
@@ -42,6 +42,7 @@
# include "rtaudio/RtAudio.h"
# undef Point
# include "../../extra/ScopedPointer.hpp"
+# include "../../extra/String.hpp"
using DISTRHO_NAMESPACE::ScopedPointer;
@@ -49,6 +50,10 @@ struct RtAudioBridge : NativeBridge {
// pointer to RtAudio instance
ScopedPointer<RtAudio> handle;
+ // for buffer size changes
+ String name;
+ uint nextBufferSize = 512;
+
const char* getVersion() const noexcept
{
return RTAUDIO_VERSION;
@@ -62,7 +67,7 @@ struct RtAudioBridge : NativeBridge {
rtAudio = new RtAudio(RtAudio::RTAUDIO_API_TYPE);
} DISTRHO_SAFE_EXCEPTION_RETURN("new RtAudio()", false);
- uint rtAudioBufferFrames = 512;
+ uint rtAudioBufferFrames = nextBufferSize;
#if DISTRHO_PLUGIN_NUM_INPUTS > 0
RtAudio::StreamParameters inParams;
@@ -94,6 +99,7 @@ struct RtAudioBridge : NativeBridge {
return false;
} DISTRHO_SAFE_EXCEPTION_RETURN("rtAudio->openStream()", false);
+ name = clientName;
handle = rtAudio;
bufferSize = rtAudioBufferFrames;
sampleRate = handle->getStreamSampleRate();
@@ -137,6 +143,42 @@ struct RtAudioBridge : NativeBridge {
return true;
}
+ /* RtAudio in macOS uses a different than usual way to handle audio block size,
+ * where RTAUDIO_MINIMIZE_LATENCY makes CoreAudio use very low latencies (around 15 samples).
+ * As such, dynamic buffer sizes are meaningless there.
+ */
+ #ifndef DISTRHO_OS_MAC
+ bool supportsBufferSizeChanges() const override
+ {
+ return true;
+ }
+
+ bool requestBufferSizeChange(const uint32_t newBufferSize) override
+ {
+ // stop audio first
+ deactivate();
+ close();
+
+ // try to open with new buffer size
+ nextBufferSize = newBufferSize;
+
+ const bool ok = open(name);
+
+ if (!ok)
+ {
+ // revert to old buffer size if new one failed
+ nextBufferSize = bufferSize;
+ open(name);
+ }
+
+ if (bufferSizeCallback != nullptr)
+ bufferSizeCallback(bufferSize, jackBufferSizeArg);
+
+ activate();
+ return ok;
+ }
+ #endif
+
static int RtAudioCallback(void* const outputBuffer,
#if DISTRHO_PLUGIN_NUM_INPUTS > 0
void* const inputBuffer,