34template <
typename FloatType>
38 Gain()
noexcept =
default;
42 void setGainLinear (FloatType newGain)
noexcept { gain.setTargetValue (newGain); }
48 FloatType
getGainLinear() const noexcept {
return gain.getTargetValue(); }
56 if (! approximatelyEqual (rampDurationSeconds, newDurationSeconds))
58 rampDurationSeconds = newDurationSeconds;
67 bool isSmoothing() const noexcept {
return gain.isSmoothing(); }
73 sampleRate = spec.sampleRate;
81 gain.reset (sampleRate, rampDurationSeconds);
86 template <
typename SampleType>
89 return s * gain.getNextValue();
93 template <
typename ProcessContext>
94 void process (
const ProcessContext& context)
noexcept
96 auto&& inBlock = context.getInputBlock();
97 auto&& outBlock = context.getOutputBlock();
99 jassert (inBlock.getNumChannels() == outBlock.getNumChannels());
100 jassert (inBlock.getNumSamples() == outBlock.getNumSamples());
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())
110 outBlock.copyFrom (inBlock);
115 if (numChannels == 1)
117 auto* src = inBlock.getChannelPointer (0);
118 auto* dst = outBlock.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
132 for (
size_t chan = 0; chan < numChannels; ++chan)
133 FloatVectorOperations::multiply (outBlock.getChannelPointer (chan),
134 inBlock.getChannelPointer (chan),
135 gains,
static_cast<int> (len));
142 double sampleRate = 0, rampDurationSeconds = 0;
FloatType getGainDecibels() const noexcept
FloatType getGainLinear() const noexcept
void prepare(const ProcessSpec &spec) noexcept
double getRampDurationSeconds() const noexcept
bool isSmoothing() const noexcept
void setGainLinear(FloatType newGain) noexcept
SampleType JUCE_VECTOR_CALLTYPE processSample(SampleType s) noexcept
void process(const ProcessContext &context) noexcept
void setRampDurationSeconds(double newDurationSeconds) noexcept
void setGainDecibels(FloatType newGainDecibels) noexcept