OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_ProcessorDuplicator.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26 namespace juce::dsp
27{
28
39 template <typename MonoProcessorType, typename StateType>
40 struct ProcessorDuplicator
41{
42 ProcessorDuplicator() : state (new StateType()) {}
43 ProcessorDuplicator (StateType* stateToUse) : state (stateToUse) {}
44 ProcessorDuplicator (typename StateType::Ptr stateToUse) : state (std::move (stateToUse)) {}
45 ProcessorDuplicator (const ProcessorDuplicator&) = default;
46 ProcessorDuplicator (ProcessorDuplicator&&) = default;
47
48 void prepare (const ProcessSpec& spec)
49 {
50 processors.removeRange ((int) spec.numChannels, processors.size());
51
52 while (static_cast<size_t> (processors.size()) < spec.numChannels)
53 processors.add (new MonoProcessorType (state));
54
55 auto monoSpec = spec;
56 monoSpec.numChannels = 1;
57
58 for (auto* p : processors)
59 p->prepare (monoSpec);
60 }
61
62 void reset() noexcept { for (auto* p : processors) p->reset(); }
63
64 template <typename ProcessContext>
65 void process (const ProcessContext& context) noexcept
66 {
67 jassert ((int) context.getInputBlock().getNumChannels() <= processors.size());
68 jassert ((int) context.getOutputBlock().getNumChannels() <= processors.size());
69
70 auto numChannels = static_cast<size_t> (jmin (context.getInputBlock().getNumChannels(),
71 context.getOutputBlock().getNumChannels()));
72
73 for (size_t chan = 0; chan < numChannels; ++chan)
74 processors[(int) chan]->process (MonoProcessContext<ProcessContext> (context, chan));
75 }
76
77 typename StateType::Ptr state;
78
79 private:
80 template <typename ProcessContext>
81 struct MonoProcessContext : public ProcessContext
82 {
83 MonoProcessContext (const ProcessContext& multiChannelContext, size_t channelToUse)
84 : ProcessContext (multiChannelContext), channel (channelToUse)
85 {}
86
87 size_t channel;
88
89 typename ProcessContext::ConstAudioBlockType getInputBlock() const noexcept { return ProcessContext::getInputBlock() .getSingleChannelBlock (channel); }
90 typename ProcessContext::AudioBlockType getOutputBlock() const noexcept { return ProcessContext::getOutputBlock().getSingleChannelBlock (channel); }
91 };
92
93 juce::OwnedArray<MonoProcessorType> processors;
94};
95
96} // namespace juce::dsp
juce::OwnedArray
Definition juce_OwnedArray.h:50
juce::OwnedArray::size
int size() const noexcept
Definition juce_OwnedArray.h:129
juce::OwnedArray::add
ObjectClass * add(ObjectClass *newObject)
Definition juce_OwnedArray.h:293
juce::OwnedArray::removeRange
void removeRange(int startIndex, int numberToRemove, bool deleteObjects=true)
Definition juce_OwnedArray.h:645
juce::dsp::ProcessSpec
Definition juce_ProcessContext.h:36
juce::dsp::ProcessSpec::numChannels
uint32 numChannels
Definition juce_ProcessContext.h:44
juce::dsp::ProcessorDuplicator
Definition juce_ProcessorDuplicator.h:41