41template <
typename FloatType>
45 Gain()
noexcept =
default;
49 void setGainLinear (FloatType newGain)
noexcept { gain.setTargetValue (newGain); }
55 FloatType
getGainLinear() const noexcept {
return gain.getTargetValue(); }
63 if (rampDurationSeconds != newDurationSeconds)
65 rampDurationSeconds = newDurationSeconds;
74 bool isSmoothing() const noexcept {
return gain.isSmoothing(); }
80 sampleRate = spec.sampleRate;
88 gain.reset (sampleRate, rampDurationSeconds);
93 template <
typename SampleType>
96 return s * gain.getNextValue();
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)
128 dst[i] = src[i] * gain.getNextValue();
132 auto* gains =
static_cast<FloatType*
> (alloca (
sizeof (FloatType) * len));
134 for (
size_t i = 0; i < len; ++i)
135 gains[i] = gain.getNextValue();
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;
static void JUCE_CALLTYPE multiply(float *dest, const float *src, int numValues) noexcept
Multiplies the destination values by the source values.
A utility class for values that need smoothing to avoid audio glitches.
Applies a gain to audio samples as single samples or AudioBlocks.
FloatType getGainDecibels() const noexcept
Returns the current gain in decibels.
FloatType getGainLinear() const noexcept
Returns the current gain as a linear value.
void prepare(const ProcessSpec &spec) noexcept
Called before processing starts.
double getRampDurationSeconds() const noexcept
Returns the ramp duration in seconds.
bool isSmoothing() const noexcept
Returns true if the current value is currently being interpolated.
void setGainLinear(FloatType newGain) noexcept
Applies a new gain as a linear value.
SampleType JUCE_VECTOR_CALLTYPE processSample(SampleType s) noexcept
Returns the result of processing a single sample.
void reset() noexcept
Resets the internal state of the gain.
void process(const ProcessContext &context) noexcept
Processes the input and output buffers supplied in the processing context.
void setRampDurationSeconds(double newDurationSeconds) noexcept
Sets the length of the ramp used for smoothing gain changes.
void setGainDecibels(FloatType newGainDecibels) noexcept
Applies a new gain as a decibel value.
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...