mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Also sync VST3 audio thread scheduling priorities
The exact same thing as the last commit, but for VST3 plugins.
This commit is contained in:
@@ -250,10 +250,22 @@ class YaAudioProcessor : public Steinberg::Vst::IAudioProcessor {
|
|||||||
|
|
||||||
YaProcessData data;
|
YaProcessData data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We'll periodically synchronize the realtime priority setting of the
|
||||||
|
* host's audio thread with the Wine plugin host. We'll do this
|
||||||
|
* approximately every ten seconds, as doing this getting and setting
|
||||||
|
* scheduler information has a non trivial amount of overhead (even if
|
||||||
|
* it's only a single microsoecond).
|
||||||
|
*/
|
||||||
|
std::optional<int> new_realtime_priority;
|
||||||
|
|
||||||
template <typename S>
|
template <typename S>
|
||||||
void serialize(S& s) {
|
void serialize(S& s) {
|
||||||
s.value8b(instance_id);
|
s.value8b(instance_id);
|
||||||
s.object(data);
|
s.object(data);
|
||||||
|
|
||||||
|
s.ext(new_realtime_priority, bitsery::ext::StdOptional{},
|
||||||
|
[](S& s, int& priority) { s.value4b(priority); });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,14 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
// The cannonical overloading template for `std::visitor`, not sure why this
|
// The cannonical overloading template for `std::visitor`, not sure why this
|
||||||
// isn't part of the standard library
|
// isn't part of the standard library
|
||||||
template <class... Ts>
|
template <class... Ts>
|
||||||
|
|||||||
@@ -19,14 +19,6 @@
|
|||||||
#include "../../common/communication/vst2.h"
|
#include "../../common/communication/vst2.h"
|
||||||
#include "../utils.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);
|
intptr_t dispatch_proxy(AEffect*, int, int, intptr_t, void*, float);
|
||||||
void process_proxy(AEffect*, float**, float**, int);
|
void process_proxy(AEffect*, float**, float**, int);
|
||||||
void process_replacing_proxy(AEffect*, float**, float**, int);
|
void process_replacing_proxy(AEffect*, float**, float**, int);
|
||||||
|
|||||||
@@ -141,10 +141,23 @@ tresult PLUGIN_API Vst3PluginProxyImpl::setProcessing(TBool state) {
|
|||||||
|
|
||||||
tresult PLUGIN_API
|
tresult PLUGIN_API
|
||||||
Vst3PluginProxyImpl::process(Steinberg::Vst::ProcessData& data) {
|
Vst3PluginProxyImpl::process(Steinberg::Vst::ProcessData& data) {
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Check whether reusing a `YaProcessData` object make a difference in
|
// TODO: Check whether reusing a `YaProcessData` object make a difference in
|
||||||
// terms of performance
|
// terms of performance
|
||||||
ProcessResponse response = bridge.send_audio_processor_message(
|
ProcessResponse response =
|
||||||
YaAudioProcessor::Process{.instance_id = instance_id(), .data = data});
|
bridge.send_audio_processor_message(YaAudioProcessor::Process{
|
||||||
|
.instance_id = instance_id(),
|
||||||
|
.data = data,
|
||||||
|
.new_realtime_priority = new_realtime_priority});
|
||||||
|
|
||||||
response.output_data.write_back_outputs(data);
|
response.output_data.write_back_outputs(data);
|
||||||
|
|
||||||
|
|||||||
@@ -375,6 +375,13 @@ class Vst3PluginProxyImpl : public Vst3PluginProxy {
|
|||||||
*/
|
*/
|
||||||
Steinberg::IPtr<Steinberg::FUnknown> host_context;
|
Steinberg::IPtr<Steinberg::FUnknown> host_context;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We'll periodically synchronize the Wine host's audio thread priority with
|
||||||
|
* that of the host. Since the overhead from doing so does add up, we'll
|
||||||
|
* only do this every once in a while.
|
||||||
|
*/
|
||||||
|
time_t last_audio_thread_priority_synchronization = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to assign unique identifiers to context menus created by
|
* Used to assign unique identifiers to context menus created by
|
||||||
* `IComponentHandler3::CreateContextMenu`.
|
* `IComponentHandler3::CreateContextMenu`.
|
||||||
|
|||||||
@@ -1129,6 +1129,14 @@ size_t Vst3Bridge::register_object_instance(
|
|||||||
},
|
},
|
||||||
[&](YaAudioProcessor::Process& request)
|
[&](YaAudioProcessor::Process& request)
|
||||||
-> YaAudioProcessor::Process::Response {
|
-> YaAudioProcessor::Process::Response {
|
||||||
|
// As suggested by Jack Winter, we'll synchronize this
|
||||||
|
// thread's audio processing priority with that of the
|
||||||
|
// host's audio thread every once in a while
|
||||||
|
if (request.new_realtime_priority) {
|
||||||
|
set_realtime_priority(
|
||||||
|
true, *request.new_realtime_priority);
|
||||||
|
}
|
||||||
|
|
||||||
const tresult result =
|
const tresult result =
|
||||||
object_instances[request.instance_id]
|
object_instances[request.instance_id]
|
||||||
.audio_processor->process(request.data.get());
|
.audio_processor->process(request.data.get());
|
||||||
|
|||||||
Reference in New Issue
Block a user