From 04d0ff094911edc9423001c8fd26d326e858f673 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 26 Jan 2021 23:50:48 +0100 Subject: [PATCH] Fix serializing silence flags We didn't initialize the field, and we also didn't copy the updated value back (since everything else is a pointer to the original data). This fixes audio channels in REAPER randomly being silence, as this field would otherwise be uninitialized. Thanks a lot to @kytdkut for finding this issue! --- .../serialization/vst3/process-data.cpp | 9 +++++++++ src/common/serialization/vst3/process-data.h | 19 +++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/common/serialization/vst3/process-data.cpp b/src/common/serialization/vst3/process-data.cpp index 572c506b..899d06e6 100644 --- a/src/common/serialization/vst3/process-data.cpp +++ b/src/common/serialization/vst3/process-data.cpp @@ -233,6 +233,15 @@ Steinberg::Vst::ProcessData& YaProcessData::get() { } YaProcessDataResponse YaProcessData::move_outputs_to_response() { + // NOTE: We _have_ to manually copy over the silence flags from the + // `ProcessData` object generated in `get()` here sicne these of + // course are not references or pointers like all other fields, so + // they're not implicitly copied like all of our other fields + for (int i = 0; i < reconstructed_process_data.numOutputs; i++) { + outputs[i].silence_flags = + reconstructed_process_data.outputs[i].silenceFlags; + } + return YaProcessDataResponse{ .outputs = std::move(outputs), .output_parameter_changes = std::move(output_parameter_changes), diff --git a/src/common/serialization/vst3/process-data.h b/src/common/serialization/vst3/process-data.h index 5f58dc44..794bfecf 100644 --- a/src/common/serialization/vst3/process-data.h +++ b/src/common/serialization/vst3/process-data.h @@ -69,6 +69,9 @@ class YaAudioBusBuffers { * constructor and return it. This is used as part of * `YaProcessData::get()`. The object contains pointers to `buffers`, so it * may not outlive this object. + * + * NOTE: The `silenceFlags` field is of course not a reference, so writing + * to that will not modify `silence_flags`. */ Steinberg::Vst::AudioBusBuffers get(); @@ -103,13 +106,6 @@ class YaAudioBusBuffers { }); } - private: - /** - * We need these during the reconstruction process to provide a pointer to - * an array of pointers to the actual buffers. - */ - std::vector buffer_pointers; - /** * A bitfield for silent channels copied directly from the input struct. * @@ -117,7 +113,14 @@ class YaAudioBusBuffers { * these silence flags are set, but since it's an optional feature we * shouldn't risk it. */ - uint64 silence_flags; + uint64 silence_flags = 0; + + private: + /** + * We need these during the reconstruction process to provide a pointer to + * an array of pointers to the actual buffers. + */ + std::vector buffer_pointers; /** * The original implementation uses heap arrays and it stores a