OpenShot Audio Library | OpenShotAudio 0.4.0
 
Loading...
Searching...
No Matches
juce_Convolution.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
26namespace juce::dsp
27{
28
38{
39public:
47 ~ConvolutionMessageQueue() noexcept;
48
55 explicit ConvolutionMessageQueue (int numEntries);
56
59
61 ConvolutionMessageQueue& operator= (const ConvolutionMessageQueue&) = delete;
62
63private:
64 struct Impl;
65 std::unique_ptr<Impl> pimpl;
66
67 friend class Convolution;
68};
69
102class JUCE_API Convolution
103{
104public:
105 //==============================================================================
107 Convolution();
108
114 explicit Convolution (ConvolutionMessageQueue& queue);
115
117 struct Latency { int latencyInSamples; };
118
129 explicit Convolution (const Latency& requiredLatency);
130
132 struct NonUniform { int headSizeInSamples; };
133
144 explicit Convolution (const NonUniform& requiredHeadSize);
145
153
161
162 ~Convolution() noexcept;
163
164 //==============================================================================
176 void prepare (const ProcessSpec&);
177
179 void reset() noexcept;
180
184 template <typename ProcessContext,
185 std::enable_if_t<std::is_same_v<typename ProcessContext::SampleType, float>, int> = 0>
186 void process (const ProcessContext& context) noexcept
187 {
188 processSamples (context.getInputBlock(), context.getOutputBlock(), context.isBypassed);
189 }
190
191 //==============================================================================
192 enum class Stereo { no, yes };
193 enum class Trim { no, yes };
194 enum class Normalise { no, yes };
195
196 //==============================================================================
216 void loadImpulseResponse (const void* sourceData, size_t sourceDataSize,
217 Stereo isStereo, Trim requiresTrimming, size_t size,
218 Normalise requiresNormalisation = Normalise::yes);
219
231 void loadImpulseResponse (const File& fileImpulseResponse,
232 Stereo isStereo, Trim requiresTrimming, size_t size,
233 Normalise requiresNormalisation = Normalise::yes);
234
252 void loadImpulseResponse (AudioBuffer<float>&& buffer, double bufferSampleRate,
253 Stereo isStereo, Trim requiresTrimming, Normalise requiresNormalisation);
254
256 int getCurrentIRSize() const;
257
264 int getLatency() const;
265
266private:
267 //==============================================================================
268 Convolution (const Latency&,
269 const NonUniform&,
270 OptionalScopedPointer<ConvolutionMessageQueue>&&);
271
272 void processSamples (const AudioBlock<const float>&, AudioBlock<float>&, bool isBypassed) noexcept;
273
274 class Mixer
275 {
276 public:
277 void prepare (const ProcessSpec&);
278
279 template <typename ProcessWet>
280 void processSamples (const AudioBlock<const float>&,
281 AudioBlock<float>&,
282 bool isBypassed,
283 ProcessWet&&) noexcept;
284
285 void reset();
286
287 private:
288 std::array<SmoothedValue<float>, 2> volumeDry, volumeWet;
289 AudioBlock<float> dryBlock;
290 HeapBlock<char> dryBlockStorage;
291 double sampleRate = 0;
292 bool currentIsBypassed = false;
293 };
294
295 //==============================================================================
296 class Impl;
297 std::unique_ptr<Impl> pimpl;
298
299 //==============================================================================
300 Mixer mixer;
301 bool isActive = false;
302
303 //==============================================================================
304 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Convolution)
305};
306
307} // namespace juce::dsp
void prepare(const ProcessSpec &)
void process(const ProcessContext &context) noexcept