mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Set realtime priorities if available
This significantly reduces the latency with no real drawbacks from what I've noticed. Wineserver is still run using the normal scheduling policies because from my testing running that with realtime priority that can actually increase latencies, although doing so will greatly reduce the variance in processing time.
This commit is contained in:
@@ -17,6 +17,14 @@ Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
[readme](https://github.com/robbert-vdh/yabridge#editor-hosting-modes) for
|
||||
more details.
|
||||
|
||||
### Changed
|
||||
|
||||
- Both parts of yabridge will now run with realtime priority if available. This
|
||||
can significantly reduce overall latency and spikes. Wine itself will still
|
||||
run with a normal scheduling policy by default, since running wineserver with
|
||||
realtime priority can increase the audio processing latency although it does
|
||||
greatly reduce the amount of latency spikes even further.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed rare plugin location detection issue related to the plugin and host
|
||||
|
||||
@@ -92,6 +92,7 @@ shared_library(
|
||||
'src/common/configuration.cpp',
|
||||
'src/common/logging.cpp',
|
||||
'src/common/serialization.cpp',
|
||||
'src/common/utils.cpp',
|
||||
'src/plugin/host-process.cpp',
|
||||
'src/plugin/plugin.cpp',
|
||||
'src/plugin/plugin-bridge.cpp',
|
||||
@@ -115,6 +116,7 @@ host_sources = [
|
||||
'src/common/configuration.cpp',
|
||||
'src/common/logging.cpp',
|
||||
'src/common/serialization.cpp',
|
||||
'src/common/utils.cpp',
|
||||
'src/wine-host/bridges/vst2.cpp',
|
||||
'src/wine-host/editor.cpp',
|
||||
'src/wine-host/editor.cpp',
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// yabridge: a Wine VST bridge
|
||||
// Copyright (C) 2020 Robbert van der Helm
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#include <sched.h>
|
||||
|
||||
bool set_realtime_priority() {
|
||||
sched_param params{.sched_priority = 10};
|
||||
return sched_setscheduler(0, SCHED_FIFO, ¶ms) == 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// yabridge: a Wine VST bridge
|
||||
// Copyright (C) 2020 Robbert van der Helm
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* Set the scheduling policy to `SCHED_FIFO` with priority 10 for this process.
|
||||
* We explicitly don't do this for wineserver itself since from my testing that
|
||||
* can actually increase latencies.
|
||||
*
|
||||
* @return Whether the operation was successful or not. This will fail if the
|
||||
* user does not have the privileges to set realtime priorities.
|
||||
*/
|
||||
bool set_realtime_priority();
|
||||
@@ -16,12 +16,13 @@
|
||||
|
||||
#include "plugin-bridge.h"
|
||||
|
||||
// Generated inside of build directory
|
||||
// Generated inside of the build directory
|
||||
#include <src/common/config/config.h>
|
||||
#include <src/common/config/version.h>
|
||||
|
||||
#include "../common/communication.h"
|
||||
#include "../common/events.h"
|
||||
#include "../common/utils.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace bp = boost::process;
|
||||
@@ -78,6 +79,7 @@ PluginBridge::PluginBridge(audioMasterCallback host_callback)
|
||||
logger,
|
||||
vst_plugin_path,
|
||||
socket_endpoint.path()))),
|
||||
has_realtime_priority(set_realtime_priority()),
|
||||
wine_io_handler([&]() { io_context.run(); }) {
|
||||
log_init_message();
|
||||
|
||||
@@ -598,6 +600,8 @@ void PluginBridge::log_init_message() {
|
||||
<< std::endl;
|
||||
init_msg << "plugin: '" << vst_plugin_path.string() << "'"
|
||||
<< std::endl;
|
||||
init_msg << "realtime: '" << (has_realtime_priority ? "yes" : "no")
|
||||
<< "'" << std::endl;
|
||||
init_msg << "socket: '" << socket_endpoint.path() << "'" << std::endl;
|
||||
init_msg << "wine prefix: '";
|
||||
|
||||
|
||||
@@ -183,6 +183,14 @@ class PluginBridge {
|
||||
* @see launch_vst_host
|
||||
*/
|
||||
std::unique_ptr<HostProcess> vst_host;
|
||||
|
||||
/**
|
||||
* Whether this process runs with realtime priority. We'll set this _after_
|
||||
* spawning the Wine process because from my testing running wineserver with
|
||||
* realtime priority can actually increase latency.
|
||||
*/
|
||||
bool has_realtime_priority;
|
||||
|
||||
/**
|
||||
* Runs the Boost.Asio `io_context` thread for logging the Wine process
|
||||
* STDOUT and STDERR messages.
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
|
||||
// Generated inside of build directory
|
||||
// Generated inside of the build directory
|
||||
#include <src/common/config/config.h>
|
||||
|
||||
#include "../common/configuration.h"
|
||||
|
||||
@@ -18,10 +18,11 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// Generated inside of build directory
|
||||
// Generated inside of the build directory
|
||||
#include <src/common/config/config.h>
|
||||
#include <src/common/config/version.h>
|
||||
|
||||
#include "../common/utils.h"
|
||||
#include "bridges/group.h"
|
||||
#include "bridges/vst2.h"
|
||||
|
||||
@@ -39,6 +40,8 @@
|
||||
* Wine 5.7: https://bugs.winehq.org/show_bug.cgi?id=49138
|
||||
*/
|
||||
int __cdecl main(int argc, char* argv[]) {
|
||||
set_realtime_priority();
|
||||
|
||||
// Instead of directly hosting a plugin, this process will receive a UNIX
|
||||
// domain socket endpoint path that it should listen on to allow yabridge
|
||||
// instances to spawn plugins in this process.
|
||||
|
||||
@@ -17,10 +17,11 @@
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
// Generated inside of build directory
|
||||
// Generated inside of the build directory
|
||||
#include <src/common/config/config.h>
|
||||
#include <src/common/config/version.h>
|
||||
|
||||
#include "../common/utils.h"
|
||||
#include "bridges/vst2.h"
|
||||
|
||||
using namespace std::literals::chrono_literals;
|
||||
@@ -45,6 +46,8 @@ void async_handle_events(boost::asio::steady_timer& timer, Vst2Bridge& bridge);
|
||||
* Wine 5.7: https://bugs.winehq.org/show_bug.cgi?id=49138
|
||||
*/
|
||||
int __cdecl main(int argc, char* argv[]) {
|
||||
set_realtime_priority();
|
||||
|
||||
// We pass the name of the VST plugin .dll file to load and the Unix domain
|
||||
// socket to connect to in plugin/bridge.cpp as the first two arguments of
|
||||
// this process.
|
||||
|
||||
Reference in New Issue
Block a user