mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Sync VST2 audio thread scheduling priorities
We'll periodically copy the scheduling priorities from the host's audio threads to the Wine plugin host's audio threads. The overhead of doing this is about 1 microsecond on my system, so doing this every cycle really adds up. But getting the Unix epoch time and comparing some timestamps has a neglegible overhead, so this should give you the best of both worlds. Next we'll do the same thing for VST3 plugins. As suggested by @jhernberg
This commit is contained in:
@@ -19,6 +19,14 @@
|
||||
#include "../../common/communication/vst2.h"
|
||||
#include "../utils.h"
|
||||
|
||||
/**
|
||||
* The interval in seconds between synchronizing the Wine plugin host's audio
|
||||
* thread scheduling priority with the host's audio thread.
|
||||
*
|
||||
* @relates Vst2Bridge::last_audio_thread_priority_synchronization
|
||||
*/
|
||||
constexpr time_t audio_thread_priority_synchronization_interval = 10;
|
||||
|
||||
intptr_t dispatch_proxy(AEffect*, int, int, intptr_t, void*, float);
|
||||
void process_proxy(AEffect*, float**, float**, int);
|
||||
void process_replacing_proxy(AEffect*, float**, float**, int);
|
||||
@@ -497,7 +505,19 @@ void Vst2PluginBridge::do_process(T** inputs, T** outputs, int sample_frames) {
|
||||
input_buffers[channel].begin());
|
||||
}
|
||||
|
||||
const AudioBuffers request{input_buffers, sample_frames};
|
||||
// We'll synchronize the scheduling priority of the audio thread on the Wine
|
||||
// plugin host with that of the host's audio thread every once in a while
|
||||
std::optional<int> new_realtime_priority = std::nullopt;
|
||||
time_t now = std::time(nullptr);
|
||||
if (now > last_audio_thread_priority_synchronization +
|
||||
audio_thread_priority_synchronization_interval) {
|
||||
new_realtime_priority = get_realtime_priority();
|
||||
last_audio_thread_priority_synchronization = now;
|
||||
}
|
||||
|
||||
const AudioBuffers request{.buffers = input_buffers,
|
||||
.sample_frames = sample_frames,
|
||||
.new_realtime_priority = new_realtime_priority};
|
||||
sockets.host_vst_process_replacing.send(request, process_buffer);
|
||||
|
||||
// Write the results back to the `outputs` arrays
|
||||
|
||||
Reference in New Issue
Block a user