From d1c5d4c4ac920c5452cce290b59e1397733ebf88 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 15 Dec 2020 23:11:59 +0100 Subject: [PATCH] Implement YaProcessData reading --- .../serialization/vst3/process-data.cpp | 50 +++++++++++++++---- src/common/serialization/vst3/process-data.h | 20 ++++---- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/common/serialization/vst3/process-data.cpp b/src/common/serialization/vst3/process-data.cpp index 0fd0662e..1e7fea8b 100644 --- a/src/common/serialization/vst3/process-data.cpp +++ b/src/common/serialization/vst3/process-data.cpp @@ -20,10 +20,9 @@ YaAudioBusBuffers::YaAudioBusBuffers() {} -YaAudioBusBuffers::YaAudioBusBuffers( - Steinberg::Vst::SymbolicSampleSizes sample_size, - size_t num_channels, - size_t num_samples) +YaAudioBusBuffers::YaAudioBusBuffers(int32 sample_size, + size_t num_channels, + size_t num_samples) : buffers(sample_size == Steinberg::Vst::SymbolicSampleSizes::kSample64 ? decltype(buffers)(std::vector>( num_channels, @@ -33,7 +32,7 @@ YaAudioBusBuffers::YaAudioBusBuffers( std::vector(num_samples, 0.0)))) {} YaAudioBusBuffers::YaAudioBusBuffers( - Steinberg::Vst::SymbolicSampleSizes sample_size, + int32 sample_size, int32 num_samples, const Steinberg::Vst::AudioBusBuffers& data) : silence_flags(data.silenceFlags) { @@ -67,27 +66,56 @@ Steinberg::Vst::AudioBusBuffers& YaAudioBusBuffers::get() { reconstructed_buffers.silenceFlags = silence_flags; std::visit(overload{ [&](std::vector>& buffers) { - double_buffer_pointers.clear(); + buffer_pointers.clear(); for (auto& buffer : buffers) { - double_buffer_pointers.push_back(buffer.data()); + buffer_pointers.push_back(buffer.data()); } reconstructed_buffers.numChannels = buffers.size(); reconstructed_buffers.channelBuffers64 = - double_buffer_pointers.data(); + reinterpret_cast(buffer_pointers.data()); }, [&](std::vector>& buffers) { - float_buffer_pointers.clear(); + buffer_pointers.clear(); for (auto& buffer : buffers) { - float_buffer_pointers.push_back(buffer.data()); + buffer_pointers.push_back(buffer.data()); } reconstructed_buffers.numChannels = buffers.size(); reconstructed_buffers.channelBuffers32 = - float_buffer_pointers.data(); + reinterpret_cast(buffer_pointers.data()); }, }, buffers); return reconstructed_buffers; } + +YaProcessData::YaProcessData() {} + +YaProcessData::YaProcessData(const Steinberg::Vst::ProcessData& process_data) + : process_mode(process_data.processMode), + symbolic_sample_size(process_data.symbolicSampleSize), + num_samples(process_data.numSamples), + outputs_num_channels(process_data.numOutputs), + input_parameter_changes(*process_data.inputParameterChanges), + input_events(process_data.inputEvents ? std::make_optional( + *process_data.inputEvents) + : std::nullopt), + process_context(process_data.processContext + ? std::make_optional( + *process_data.processContext) + : std::nullopt) { + for (int i = 0; i < process_data.numInputs; i++) { + inputs.emplace_back(symbolic_sample_size, num_samples, + process_data.inputs[i]); + } + + // Fetch the number of channels for each output so we can recreate these + // buffers in the Wine plugin host + for (int i = 0; i < process_data.numOutputs; i++) { + outputs_num_channels[i] = process_data.outputs[i].numChannels; + } +} + +// TODO: Reconstruction diff --git a/src/common/serialization/vst3/process-data.h b/src/common/serialization/vst3/process-data.h index b441452e..76e754c3 100644 --- a/src/common/serialization/vst3/process-data.h +++ b/src/common/serialization/vst3/process-data.h @@ -48,7 +48,7 @@ class YaAudioBusBuffers { * Create a new, zero initialize audio bus buffers object. Used to * reconstruct the output buffers during `YaProcessData::get()`. */ - YaAudioBusBuffers(Steinberg::Vst::SymbolicSampleSizes sample_size, + YaAudioBusBuffers(int32 sample_size, size_t num_channels, size_t num_samples); @@ -60,7 +60,7 @@ class YaAudioBusBuffers { * field determines which variant of that union to use. Similarly the * `ProcessData`' `numSamples` field determines the extent of these arrays. */ - YaAudioBusBuffers(Steinberg::Vst::SymbolicSampleSizes sample_size, + YaAudioBusBuffers(int32 sample_size, int32 num_samples, const Steinberg::Vst::AudioBusBuffers& data); @@ -96,13 +96,11 @@ class YaAudioBusBuffers { */ Steinberg::Vst::AudioBusBuffers reconstructed_buffers; - // Used in reconstructed_buffers, because we need to store pointers to the - // inner vectors in `buffers`. We're using a union instead of void pointers - // here to have at least some resemblance of type safety. - union { - std::vector float_buffer_pointers; - std::vector double_buffer_pointers; - }; + /** + * 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. @@ -195,7 +193,7 @@ class YaProcessData { /** * The processing mode copied directly from the input struct. */ - Steinberg::Vst::ProcessModes process_mode; + int32 process_mode; /** * The symbolic sample size (see `Steinberg::Vst::SymbolicSampleSizes`) is @@ -203,7 +201,7 @@ class YaProcessData { * union of array of either single or double precision floating point * arrays. This field determines which of those variants should be used. */ - Steinberg::Vst::SymbolicSampleSizes symbolic_sample_size; + int32 symbolic_sample_size; /** * The number of samples in each audio buffer.