6#ifndef SBL_DSP_DYNAMICS_VCA_HPP_
7#define SBL_DSP_DYNAMICS_VCA_HPP_
80 template<
class... Ports>
81 void process(
const float* in,
float* out, uint16_t frames, Ports... ports) {
83 "SBL ERROR: Vca takes gain (a block or a scalar), then level and mod_amount (scalars)");
84 const auto gain = transport::arg<0>(ports...);
85 const auto level = transport::arg<1>(ports...);
86 const auto mod_amount = transport::arg<2>(ports...);
87 if constexpr (transport::is_scalar_v<
decltype(level)>) {
90 if constexpr (transport::is_scalar_v<
decltype(
mod_amount)>) {
93 if constexpr (transport::is_block_v<
decltype(
gain)>) {
94 for (uint16_t i = 0; i < frames; ++i) {
95 const float lg = level_gain_.
step();
96 const float a = amount_.
step();
97 out[i] = in[i] * lg * (1.0f - a + a *
gain[i]);
103 if constexpr (transport::is_scalar_v<
decltype(
gain)>) {
104 const auto g =
static_cast<float>(
gain);
107 for (uint16_t i = 0; i < frames; ++i) {
108 const float lg = level_gain_.
step();
109 const float a = amount_.
step();
110 const float g = gain_.
step();
111 out[i] = in[i] * lg * (1.0f - a + a * g);
131 Ramp level_gain_{1.0f};
A linear ramp to a target over a fixed number of frames.
float target() const
The value the ramp heads for.
void head(float target)
set(), except that the first value given since construction, by head() or jump(), is arrived at at on...
float value() const
The current value.
void jump(float value)
Arrive at a value at once.
void set_length(uint16_t frames)
Set how many frames a ramp takes.
An amplifier: gain, Level and Mod Amt as ports over a linear multiply.
void process(const float *in, float *out, uint16_t frames, Ports... ports)
One block, the ports in PORTS' order, any trailing ones left off.
void reset()
Every ramp at its target.
static constexpr transport::Port PORTS[]
static constexpr uint16_t RAMP_FRAMES
float gain() const
The scalar gain, where the ramp is now, or the last frame of a gain block.
float mod_amount() const
Mod Amt, where the ramp is now.
static constexpr float LEVEL_RANGE_DB
float level_gain() const
Level's gain after the taper, where the ramp is now.
Vca()
Unity gain until ports are given; every scalar port ramps over RAMP_FRAMES.
Finiteness of a float, read from its bits, and a fallback for a value that is not finite.
Gain in decibels, and the level taper for an amplifier's Level control.
float level_gain(float level, float range_db)
The level taper: a level in [0, 1] to a gain.
float finite_or(float x, float fallback)
x, or fallback when x is an infinity or a NaN.
constexpr T clamp01(T x)
x held to [0, 1]; a NaN goes to 0.
A linear ramp to a target over a fixed number of frames.
The processing call's shape as a checked contract.