14template <
typename SampleType =
float>
class GainT {
15 static_assert(std::is_floating_point_v<SampleType>,
16 "GainT requires a floating-point sample type");
22 gain_ramp_.set_ramp_time(seconds, sample_rate);
31 gain_ramp_.set_target(
linear);
33 gain_ramp_.set_immediate(
linear);
36 return SampleType{20} * std::log10(std::max(gain_ramp_.current(), SampleType{1e-10f}));
39 return gain_ramp_.current();
42 SampleType
process(SampleType input)
const {
43 return input * gain_ramp_.next();
51 for (
int i = 0;
i < num_samples; ++
i)
59 void process(SampleType*
const* channels,
int num_channels,
int num_samples)
const {
60 if (channels ==
nullptr || num_channels <= 0 || num_samples <= 0)
63 for (;
i < num_samples && gain_ramp_.is_smoothing(); ++
i) {
64 const SampleType gain = gain_ramp_.next();
65 for (
int c = 0;
c < num_channels; ++
c)
66 if (channels[
c] !=
nullptr)
67 channels[
c][
i] *= gain;
71 const SampleType gain = gain_ramp_.current();
72 for (
int c = 0;
c < num_channels; ++
c)
73 if (channels[
c] !=
nullptr)
74 for (
int k =
i; k < num_samples; ++k)
75 channels[
c][k] *= gain;
80 bool ramp_enabled_ =
false;
88 static_assert(std::is_floating_point_v<SampleType>,
89 "SimpleMixerT requires a floating-point sample type");
93 mix_ = std::clamp(
mix, SampleType{0}, SampleType{1});
95 SampleType
mix()
const {
99 SampleType
process(SampleType dry, SampleType wet)
const {
100 return dry * (SampleType{1} - mix_) + wet * mix_;
103 void process(
const SampleType* dry,
const SampleType* wet, SampleType* output,
104 int num_samples)
const {
105 const SampleType d = SampleType{1} - mix_;
106 for (
int i = 0;
i < num_samples; ++
i)
107 output[
i] = dry[
i] * d + wet[
i] * mix_;
111 SampleType mix_ = SampleType{1};
SampleType process(SampleType input) const
Definition gain.hpp:42
void set_ramp_time(SampleType seconds, SampleType sample_rate)
Enable a linear per-sample gain ramp.
Definition gain.hpp:21
void process(SampleType *buffer, int num_samples) const
One channel.
Definition gain.hpp:50
SampleType gain_db() const
Definition gain.hpp:35
SampleType gain_linear() const
Definition gain.hpp:38
void process(SampleType *const *channels, int num_channels, int num_samples) const
Every channel of a multi-channel block with one shared ramp: sample i of every channel is multiplied ...
Definition gain.hpp:59
void set_gain_db(SampleType db)
Definition gain.hpp:26
void set_gain_linear(SampleType linear)
Definition gain.hpp:29
void process(const SampleType *dry, const SampleType *wet, SampleType *output, int num_samples) const
Definition gain.hpp:103
void set_mix(SampleType mix)
Definition gain.hpp:92
float mix() const
Definition gain.hpp:95
SampleType process(SampleType dry, SampleType wet) const
Definition gain.hpp:99
Linear smoothing for control-rate parameters.
Definition smoothed_value.hpp:24
Definition additive_bank.hpp:218
@ buffer
A borrowed static buffer with a traversable playhead.
Definition granular.hpp:110
SimpleMixerT< double > SimpleMixer64
Definition gain.hpp:117
@ c
Definition spectrum_trace.hpp:35
@ i
Definition formant_filter_bank.hpp:20
@ linear
2-point. Cheapest; audible imaging when pitching up.
Definition granular.hpp:133
GainT< double > Gain64
Definition gain.hpp:115
GainT< float > Gain
Definition gain.hpp:114
SimpleMixerT< float > SimpleMixer
Definition gain.hpp:116