diff --git a/zones_convolver/ConvolutionEngine.cpp b/zones_convolver/ConvolutionEngine.cpp index 7bcd81e..89f9f48 100644 --- a/zones_convolver/ConvolutionEngine.cpp +++ b/zones_convolver/ConvolutionEngine.cpp @@ -101,11 +101,8 @@ void ConvolutionEngine::reset () convolver_->Reset (); } -void ConvolutionEngine::ConfigureEngine (const EngineSpec & engine_spec) -{ -} - -void ConvolutionEngine::LoadIR (juce::dsp::AudioBlock ir_block) +void ConvolutionEngine::LoadIR (juce::dsp::AudioBlock ir_block, + const EngineSpec & engine_spec) { if (spec_ != std::nullopt) thread_pool_.addJob (new LoadIRJob (ir_block, *spec_, command_queue_), true); diff --git a/zones_convolver/ConvolutionEngine.h b/zones_convolver/ConvolutionEngine.h index 1b09c49..ff992f4 100644 --- a/zones_convolver/ConvolutionEngine.h +++ b/zones_convolver/ConvolutionEngine.h @@ -111,10 +111,6 @@ class ConvolutionEngine , public juce::Thread { public: - struct EngineSpec - { - }; - explicit ConvolutionEngine (juce::ThreadPool & thread_pool); ~ConvolutionEngine () override; @@ -122,13 +118,12 @@ class ConvolutionEngine void operator() ( ConvolutionNotificationQueue::DisposeEngineCommand & dispose_engine_command) override; - void LoadIR (juce::dsp::AudioBlock ir_block); + void LoadIR (juce::dsp::AudioBlock ir_block, const EngineSpec & engine_spec); void operator() (ConvolutionCommandQueue::EngineReadyCommand & engine_ready_command) override; void prepare (const juce::dsp::ProcessSpec & spec) override; void process (const juce::dsp::ProcessContextReplacing & replacing) override; void reset () override; - void ConfigureEngine (const EngineSpec & engine_spec); private: std::unique_ptr convolver_; @@ -140,7 +135,6 @@ class ConvolutionEngine juce::ThreadPool & thread_pool_; ConvolutionCommandQueue::VisitorQueue command_queue_; ConvolutionNotificationQueue::VisitorQueue notification_queue_; - EngineSpec engine_spec_; juce::AudioBuffer ir_buffer_; }; } \ No newline at end of file diff --git a/zones_convolver/Convolver.cpp b/zones_convolver/Convolver.cpp new file mode 100644 index 0000000..b945141 --- /dev/null +++ b/zones_convolver/Convolver.cpp @@ -0,0 +1,56 @@ +#include "Convolver.h" + +zones::Convolver::Convolver (juce::dsp::AudioBlock ir_block, + const juce::dsp::ProcessSpec & process_spec, + const zones::Convolver::ConvolverSpec & convolver_spec) + : process_spec_ (process_spec) + , convolver_spec_ (convolver_spec) +{ + num_convolution_channels_ = ir_block.getNumChannels (); + auto max_block_size = process_spec_.maximumBlockSize; + auto sample_rate = process_spec_.sampleRate; + + routing_buffer_.setSize (num_convolution_channels_, max_block_size); + + time_distributed_nupc_ = std::make_unique ( + ir_block, + juce::dsp::ProcessSpec { + .sampleRate = sample_rate, + .maximumBlockSize = max_block_size, + .numChannels = static_cast (num_convolution_channels_), + }); +} + +void zones::Convolver::Process (const juce::dsp::ProcessContextReplacing & replacing) +{ + auto output_block = replacing.getOutputBlock (); + + juce::dsp::AudioBlock routing_block {routing_buffer_}; + routing_block.clear (); + + for (auto convolution_channel = 0; convolution_channel < num_convolution_channels_; + ++convolution_channel) + { + auto input_routing_channel = convolver_spec_.input_routing [convolution_channel]; + auto input_routing_block = output_block.getSingleChannelBlock (input_routing_channel); + routing_block.getSingleChannelBlock (convolution_channel).copyFrom (input_routing_block); + } + + time_distributed_nupc_->Process ( + {routing_block}); // THIS NEEDS TO HANDLE SMALLER AND LARGER BLOCKS... + + output_block.clear (); + for (auto convolution_channel = 0; convolution_channel < num_convolution_channels_; + ++convolution_channel) + { + auto output_routing_channel = convolver_spec_.output_routing [convolution_channel]; + auto output_routing_block = output_block.getSingleChannelBlock (output_routing_channel); + output_routing_block.add (routing_block.getSingleChannelBlock (convolution_channel)); + } +} + +void zones::Convolver::Reset () +{ + time_distributed_nupc_->Reset (); + routing_buffer_.clear (); +} diff --git a/zones_convolver/Convolver.h b/zones_convolver/Convolver.h new file mode 100644 index 0000000..f6d2191 --- /dev/null +++ b/zones_convolver/Convolver.h @@ -0,0 +1,30 @@ +#pragma once + +#include "time_distributed/TimeDistributedNUPC.h" + +namespace zones +{ +class Convolver +{ +public: + struct ConvolverSpec + { + std::vector input_routing; + std::vector output_routing; + }; + + Convolver (juce::dsp::AudioBlock ir_block, + const juce::dsp::ProcessSpec & process_spec, + const ConvolverSpec & convolver_spec); + void Process (const juce::dsp::ProcessContextReplacing & replacing); + void Reset (); + +private: + juce::AudioBuffer routing_buffer_; + std::unique_ptr time_distributed_nupc_; + + juce::dsp::ProcessSpec process_spec_; + ConvolverSpec convolver_spec_; + int num_convolution_channels_; +}; +} \ No newline at end of file diff --git a/zones_convolver/zones_convolver.cpp b/zones_convolver/zones_convolver.cpp index 1c7c5ef..cebf58e 100644 --- a/zones_convolver/zones_convolver.cpp +++ b/zones_convolver/zones_convolver.cpp @@ -1,6 +1,7 @@ #include "zones_convolver.h" #include "ConvolutionEngine.cpp" +#include "Convolver.cpp" #include "PartitionSchemes.cpp" #include "UniformPartitionedConvolver.cpp" #include "time_distributed/TimeDistributedNUPC.cpp" diff --git a/zones_convolver/zones_convolver.h b/zones_convolver/zones_convolver.h index a7f8583..3bcbcf9 100644 --- a/zones_convolver/zones_convolver.h +++ b/zones_convolver/zones_convolver.h @@ -15,6 +15,7 @@ END_JUCE_MODULE_DECLARATION */ #include "ConvolutionEngine.h" +#include "Convolver.h" #include "PartitionSchemes.h" #include "UniformPartitionedConvolver.h" #include "time_distributed/TimeDistributedNUPC.h"