34template <
typename FloatType>
38 Gain()
noexcept =
default;
73 sampleRate =
spec.sampleRate;
81 gain.reset (sampleRate, rampDurationSeconds);
86 template <
typename SampleType>
89 return s * gain.getNextValue();
93 template <
typename ProcessContext>
96 auto&&
inBlock = context.getInputBlock();
97 auto&&
outBlock = context.getOutputBlock();
102 auto len =
inBlock.getNumSamples();
103 auto numChannels =
inBlock.getNumChannels();
105 if (context.isBypassed)
107 gain.skip (
static_cast<int> (len));
109 if (context.usesSeparateInputAndOutputBlocks())
115 if (numChannels == 1)
117 auto* src =
inBlock.getChannelPointer (0);
120 for (
size_t i = 0; i < len; ++i)
121 dst[i] = src[i] * gain.getNextValue();
125 JUCE_BEGIN_IGNORE_WARNINGS_MSVC (6255 6386)
126 auto*
gains =
static_cast<FloatType*
> (
alloca (
sizeof (FloatType) * len));
128 for (
size_t i = 0; i < len; ++i)
129 gains[i] = gain.getNextValue();
130 JUCE_END_IGNORE_WARNINGS_MSVC
133 FloatVectorOperations::multiply (
outBlock.getChannelPointer (
chan),
135 gains,
static_cast<int> (len));
142 double sampleRate = 0, rampDurationSeconds = 0;
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.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...