Loading...
Searching...
No Matches
juce_Convolution.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce::dsp
{
class JUCE_API ConvolutionMessageQueue
{
public:
ConvolutionMessageQueue();
~ConvolutionMessageQueue() noexcept;
explicit ConvolutionMessageQueue (int numEntries);
ConvolutionMessageQueue (ConvolutionMessageQueue&&) noexcept;
ConvolutionMessageQueue& operator= (ConvolutionMessageQueue&&) noexcept;
ConvolutionMessageQueue (const ConvolutionMessageQueue&) = delete;
ConvolutionMessageQueue& operator= (const ConvolutionMessageQueue&) = delete;
private:
struct Impl;
std::unique_ptr<Impl> pimpl;
friend class Convolution;
};
class JUCE_API Convolution
{
public:
//==============================================================================
Convolution();
explicit Convolution (ConvolutionMessageQueue& queue);
struct Latency { int latencyInSamples; };
explicit Convolution (const Latency& requiredLatency);
struct NonUniform { int headSizeInSamples; };
explicit Convolution (const NonUniform& requiredHeadSize);
Convolution (const Latency&, ConvolutionMessageQueue&);
Convolution (const NonUniform&, ConvolutionMessageQueue&);
~Convolution() noexcept;
//==============================================================================
void prepare (const ProcessSpec&);
void reset() noexcept;
template <typename ProcessContext,
std::enable_if_t<std::is_same_v<typename ProcessContext::SampleType, float>, int> = 0>
void process (const ProcessContext& context) noexcept
{
processSamples (context.getInputBlock(), context.getOutputBlock(), context.isBypassed);
}
//==============================================================================
enum class Stereo { no, yes };
enum class Trim { no, yes };
enum class Normalise { no, yes };
//==============================================================================
void loadImpulseResponse (const void* sourceData, size_t sourceDataSize,
Stereo isStereo, Trim requiresTrimming, size_t size,
Normalise requiresNormalisation = Normalise::yes);
void loadImpulseResponse (const File& fileImpulseResponse,
Stereo isStereo, Trim requiresTrimming, size_t size,
Normalise requiresNormalisation = Normalise::yes);
void loadImpulseResponse (AudioBuffer<float>&& buffer, double bufferSampleRate,
Stereo isStereo, Trim requiresTrimming, Normalise requiresNormalisation);
int getCurrentIRSize() const;
int getLatency() const;
private:
//==============================================================================
Convolution (const Latency&,
const NonUniform&,
OptionalScopedPointer<ConvolutionMessageQueue>&&);
void processSamples (const AudioBlock<const float>&, AudioBlock<float>&, bool isBypassed) noexcept;
class Mixer
{
public:
void prepare (const ProcessSpec&);
template <typename ProcessWet>
void processSamples (const AudioBlock<const float>&,
AudioBlock<float>&,
bool isBypassed,
ProcessWet&&) noexcept;
void reset();
private:
std::array<SmoothedValue<float>, 2> volumeDry, volumeWet;
AudioBlock<float> dryBlock;
HeapBlock<char> dryBlockStorage;
double sampleRate = 0;
bool currentIsBypassed = false;
};
//==============================================================================
class Impl;
std::unique_ptr<Impl> pimpl;
//==============================================================================
Mixer mixer;
bool isActive = false;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Convolution)
};
} // namespace juce::dsp
juce::dsp::ConvolutionMessageQueue
Definition juce_Convolution.h:38
juce::dsp::ConvolutionMessageQueue::ConvolutionMessageQueue
ConvolutionMessageQueue()
Definition juce_Convolution.cpp:128
juce::dsp::Convolution::Convolution
Convolution()
Definition juce_Convolution.cpp:1197
juce::dsp::Convolution::prepare
void prepare(const ProcessSpec &)
Definition juce_Convolution.cpp:1261
juce::dsp::Convolution::process
void process(const ProcessContext &context) noexcept
Definition juce_Convolution.h:186
juce::dsp::Convolution::reset
void reset() noexcept
Definition juce_Convolution.cpp:1268
juce::dsp::Convolution::Latency
Definition juce_Convolution.h:117
juce::dsp::Convolution::NonUniform
Definition juce_Convolution.h:132
juce::dsp::ProcessSpec
Definition juce_ProcessContext.h:36