40template <
typename FloatType>
44 Bias()
noexcept =
default;
60 FloatType
getBias()
const noexcept {
return bias.getTargetValue(); }
72 double getRampDurationSeconds()
const noexcept {
return rampDurationSeconds; }
78 sampleRate =
spec.sampleRate;
84 bias.reset (sampleRate, rampDurationSeconds);
89 template <
typename SampleType>
97 template <
typename ProcessContext>
100 auto&&
inBlock = context.getInputBlock();
101 auto&&
outBlock = context.getOutputBlock();
106 auto len =
inBlock.getNumSamples();
107 auto numChannels =
inBlock.getNumChannels();
109 if (context.isBypassed)
111 bias.skip (
static_cast<int> (len));
113 if (context.usesSeparateInputAndOutputBlocks())
119 if (numChannels == 1)
121 auto* src =
inBlock.getChannelPointer (0);
124 for (
size_t i = 0; i < len; ++i)
125 dst[i] = src[i] + bias.getNextValue();
129 JUCE_BEGIN_IGNORE_WARNINGS_MSVC (6255 6386)
130 auto*
biases =
static_cast<FloatType*
> (
alloca (
sizeof (FloatType) * len));
132 for (
size_t i = 0; i < len; ++i)
133 biases[i] = bias.getNextValue();
136 FloatVectorOperations::add (
outBlock.getChannelPointer (
chan),
138 biases,
static_cast<int> (len));
139 JUCE_END_IGNORE_WARNINGS_MSVC
147 double sampleRate = 0, rampDurationSeconds = 0;
149 void updateRamp() noexcept
152 bias.
reset (sampleRate, rampDurationSeconds);
A utility class for values that need smoothing to avoid audio glitches.
void reset(double sampleRate, double rampLengthInSeconds) noexcept
Reset to a new sample rate and ramp length.
Adds a DC offset (voltage bias) to the audio samples.
SampleType processSample(SampleType inputSample) noexcept
Returns the result of processing a single sample.
FloatType getBias() const noexcept
Returns the DC bias.
void prepare(const ProcessSpec &spec) noexcept
Called before processing starts.
void setRampDurationSeconds(double newDurationSeconds) noexcept
Sets the length of the ramp used for smoothing gain changes.
void setBias(FloatType newBias) noexcept
Sets the DC bias.
void process(const ProcessContext &context) noexcept
Processes the input and output buffers supplied in the processing context.
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...