Skip to content

Commit

Permalink
Handle multiple channel formats
Browse files Browse the repository at this point in the history
  • Loading branch information
leonp-s committed Apr 18, 2024
1 parent cbf50fa commit 9e4ab60
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 12 deletions.
7 changes: 2 additions & 5 deletions zones_convolver/ConvolutionEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,8 @@ void ConvolutionEngine::reset ()
convolver_->Reset ();
}

void ConvolutionEngine::ConfigureEngine (const EngineSpec & engine_spec)
{
}

void ConvolutionEngine::LoadIR (juce::dsp::AudioBlock<const float> ir_block)
void ConvolutionEngine::LoadIR (juce::dsp::AudioBlock<const float> ir_block,
const EngineSpec & engine_spec)

Check failure on line 105 in zones_convolver/ConvolutionEngine.cpp

View workflow job for this annotation

GitHub Actions / build_and_test

‘EngineSpec’ does not name a type
{
if (spec_ != std::nullopt)
thread_pool_.addJob (new LoadIRJob (ir_block, *spec_, command_queue_), true);
Expand Down
8 changes: 1 addition & 7 deletions zones_convolver/ConvolutionEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,19 @@ class ConvolutionEngine
, public juce::Thread
{
public:
struct EngineSpec
{
};

explicit ConvolutionEngine (juce::ThreadPool & thread_pool);
~ConvolutionEngine () override;

void run () override;
void operator() (
ConvolutionNotificationQueue::DisposeEngineCommand & dispose_engine_command) override;

void LoadIR (juce::dsp::AudioBlock<const float> ir_block);
void LoadIR (juce::dsp::AudioBlock<const float> ir_block, const EngineSpec & engine_spec);

Check failure on line 121 in zones_convolver/ConvolutionEngine.h

View workflow job for this annotation

GitHub Actions / build_and_test

‘EngineSpec’ does not name a type
void operator() (ConvolutionCommandQueue::EngineReadyCommand & engine_ready_command) override;

void prepare (const juce::dsp::ProcessSpec & spec) override;
void process (const juce::dsp::ProcessContextReplacing<float> & replacing) override;
void reset () override;
void ConfigureEngine (const EngineSpec & engine_spec);

private:
std::unique_ptr<TimeDistributedNUPC> convolver_;
Expand All @@ -140,7 +135,6 @@ class ConvolutionEngine
juce::ThreadPool & thread_pool_;
ConvolutionCommandQueue::VisitorQueue command_queue_;
ConvolutionNotificationQueue::VisitorQueue notification_queue_;
EngineSpec engine_spec_;
juce::AudioBuffer<float> ir_buffer_;
};
}
56 changes: 56 additions & 0 deletions zones_convolver/Convolver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "Convolver.h"

zones::Convolver::Convolver (juce::dsp::AudioBlock<const float> 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<TimeDistributedNUPC> (
ir_block,
juce::dsp::ProcessSpec {
.sampleRate = sample_rate,
.maximumBlockSize = max_block_size,
.numChannels = static_cast<uint> (num_convolution_channels_),
});
}

void zones::Convolver::Process (const juce::dsp::ProcessContextReplacing<float> & replacing)
{
auto output_block = replacing.getOutputBlock ();

juce::dsp::AudioBlock<float> 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 ();
}
30 changes: 30 additions & 0 deletions zones_convolver/Convolver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "time_distributed/TimeDistributedNUPC.h"

namespace zones
{
class Convolver
{
public:
struct ConvolverSpec
{
std::vector<int> input_routing;
std::vector<int> output_routing;
};

Convolver (juce::dsp::AudioBlock<const float> ir_block,
const juce::dsp::ProcessSpec & process_spec,
const ConvolverSpec & convolver_spec);
void Process (const juce::dsp::ProcessContextReplacing<float> & replacing);
void Reset ();

private:
juce::AudioBuffer<float> routing_buffer_;
std::unique_ptr<TimeDistributedNUPC> time_distributed_nupc_;

juce::dsp::ProcessSpec process_spec_;
ConvolverSpec convolver_spec_;
int num_convolution_channels_;
};
}
1 change: 1 addition & 0 deletions zones_convolver/zones_convolver.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 1 addition & 0 deletions zones_convolver/zones_convolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9e4ab60

Please sign in to comment.