41 template <
typename FloatType>
45 Gain() noexcept =
default;
63 if (rampDurationSeconds != newDurationSeconds)
65 rampDurationSeconds = newDurationSeconds;
80 sampleRate = spec.sampleRate;
88 gain.
reset (sampleRate, rampDurationSeconds);
93 template <
typename SampleType>
100 template <
typename ProcessContext>
101 void process (
const ProcessContext& context) noexcept
103 auto&& inBlock = context.getInputBlock();
104 auto&& outBlock = context.getOutputBlock();
106 jassert (inBlock.getNumChannels() == outBlock.getNumChannels());
107 jassert (inBlock.getNumSamples() == outBlock.getNumSamples());
109 auto len = inBlock.getNumSamples();
110 auto numChannels = inBlock.getNumChannels();
112 if (context.isBypassed)
114 gain.
skip (static_cast<int> (len));
116 if (context.usesSeparateInputAndOutputBlocks())
117 outBlock.copyFrom (inBlock);
122 if (numChannels == 1)
124 auto* src = inBlock.getChannelPointer (0);
125 auto* dst = outBlock.getChannelPointer (0);
127 for (
size_t i = 0; i < len; ++i)
132 auto* gains =
static_cast<FloatType*
> (alloca (
sizeof (FloatType) * len));
134 for (
size_t i = 0; i < len; ++i)
137 for (
size_t chan = 0; chan < numChannels; ++chan)
139 inBlock.getChannelPointer (chan),
140 gains,
static_cast<int> (len));
147 double sampleRate = 0, rampDurationSeconds = 0;
FloatType getNextValue() noexcept
Compute the next value.
FloatType getTargetValue() const noexcept
Returns the target value towards which the smoothed value is currently moving.
void reset() noexcept
Resets the internal state of the gain.
FloatType skip(int numSamples) noexcept
Skip the next numSamples samples.
void setRampDurationSeconds(double newDurationSeconds) noexcept
Sets the length of the ramp used for smoothing gain changes.
void reset(double sampleRate, double rampLengthInSeconds) noexcept
Reset to a new sample rate and ramp length.
static void JUCE_CALLTYPE multiply(float *dest, const float *src, int numValues) noexcept
Multiplies the destination values by the source values.
void setGainLinear(FloatType newGain) noexcept
Applies a new gain as a linear value.
bool isSmoothing() const noexcept
Returns true if the current value is currently being interpolated.
SampleType JUCE_VECTOR_CALLTYPE processSample(SampleType s) noexcept
Returns the result of processing a single sample.
FloatType getGainDecibels() const noexcept
Returns the current gain in decibels.
void process(const ProcessContext &context) noexcept
Processes the input and output buffers supplied in the processing context.
void prepare(const ProcessSpec &spec) noexcept
Called before processing starts.
void setTargetValue(FloatType newValue) noexcept
Set the next value to ramp towards.
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...
void setGainDecibels(FloatType newGainDecibels) noexcept
Applies a new gain as a decibel value.
Applies a gain to audio samples as single samples or AudioBlocks.
FloatType getGainLinear() const noexcept
Returns the current gain as a linear value.
double getRampDurationSeconds() const noexcept
Returns the ramp duration in seconds.
bool isSmoothing() const noexcept
Returns true if the current value is currently being interpolated.