mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
Reuse output buffers
This commit is contained in:
@@ -154,6 +154,8 @@ PluginBridge::PluginBridge(std::string plugin_dll_path,
|
|||||||
});
|
});
|
||||||
|
|
||||||
process_replacing_handler = std::thread([&]() {
|
process_replacing_handler = std::thread([&]() {
|
||||||
|
std::vector<std::vector<float>> output_buffers(plugin->numOutputs);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
AudioBuffers request;
|
AudioBuffers request;
|
||||||
request = read_object(host_vst_process_replacing, request,
|
request = read_object(host_vst_process_replacing, request,
|
||||||
@@ -161,25 +163,26 @@ PluginBridge::PluginBridge(std::string plugin_dll_path,
|
|||||||
|
|
||||||
// TODO: Check if the plugin doesn't support `processReplacing` and
|
// TODO: Check if the plugin doesn't support `processReplacing` and
|
||||||
// call the legacy `process` function instead
|
// call the legacy `process` function instead
|
||||||
// TODO: Reuse the output_buffers and resize if necessary to avoid
|
|
||||||
// unnecessary allocations
|
|
||||||
std::vector<std::vector<float>> output_buffers(
|
|
||||||
plugin->numOutputs, std::vector<float>(request.sample_frames));
|
|
||||||
|
|
||||||
// The process functions expect a `float**` for their inputs and
|
// The process functions expect a `float**` for their inputs and
|
||||||
// their outputs
|
// their outputs
|
||||||
std::vector<float*> inputs;
|
std::vector<float*> inputs;
|
||||||
for (auto& buffer : request.buffers) {
|
for (auto& buffer : request.buffers) {
|
||||||
inputs.push_back(buffer.data());
|
inputs.push_back(buffer.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We reuse the buffers to avoid some unnecessary heap allocations,
|
||||||
|
// so we need to make sure the buffers are large enough since
|
||||||
|
// plugins can change their output configuration
|
||||||
std::vector<float*> outputs;
|
std::vector<float*> outputs;
|
||||||
|
output_buffers.resize(plugin->numOutputs);
|
||||||
for (auto& buffer : output_buffers) {
|
for (auto& buffer : output_buffers) {
|
||||||
|
buffer.resize(request.sample_frames);
|
||||||
outputs.push_back(buffer.data());
|
outputs.push_back(buffer.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Some plugins (e.g. Serum) don't allow audio processing while the
|
||||||
|
// GUI is being updated
|
||||||
{
|
{
|
||||||
// Some plugins (e.g. Serum) don't allow audio processing while
|
|
||||||
// the GUI is being updated
|
|
||||||
std::lock_guard lock(processing_mutex);
|
std::lock_guard lock(processing_mutex);
|
||||||
plugin->processReplacing(plugin, inputs.data(), outputs.data(),
|
plugin->processReplacing(plugin, inputs.data(), outputs.data(),
|
||||||
request.sample_frames);
|
request.sample_frames);
|
||||||
|
|||||||
Reference in New Issue
Block a user