17template <
typename SampleType>
30 m_initialGainDb (gainDb),
35 void prepare (
double , size_t , size_t , size_t maxBlockSizeFrames)
override
37 m_gainEnvelopeValuesLinear.resize (
this->hasEnvelopeFor (
Params::gainDb) ? maxBlockSizeFrames : 0);
42 const size_t numInputChannels = input.getNumChannels();
43 const size_t numOutputChannels = output.getNumChannels();
44 hassert (output.getNumFrames() == input.getNumFrames());
49 const bool hasGainEnvelope = ! envelopeBuffers.empty() &&
contains (envelopeBuffers
, (
int)
Params::gainDb
);
50 const bool multiplexerMode = numInputChannels != numOutputChannels;
54 auto& gainEnvelopeValuesDb = envelopeBuffers. at(
Params::gainDb);
55 hassert (gainEnvelopeValuesDb.size() == m_gainEnvelopeValuesLinear.size());
57 for (size_t i = 0; i < m_gainEnvelopeValuesLinear.size(); ++i)
58 m_gainEnvelopeValuesLinear[i] = decibelsToRatio (gainEnvelopeValuesDb[i]);
61 processEnvelopedGainAsMultiplexer (input, output);
63 processEnvelopedGainAsMultiChannel (input, output);
70 processConstantGainAsMultiplexer (input, output);
72 processConstantGainAsMultiChannel (input, output);
99 if (numInputChannels == numOutputChannels)
102 if (numInputChannels == 1)
108 virtual void represent (std::ostream& stream)
const override
110 stream <<
dbPrecision <<
"GainDb (" << m_initialGainDb <<
"_dB)";
117 return id ==
Params::gainDb;
123 double m_initialGainDb;
125 std::vector<
double> m_gainEnvelopeValuesLinear;
127 void processConstantGainAsMultiChannel (
const AudioBuffer<SampleType>& input,
AudioBuffer<SampleType>& output)
129 for (size_t channel = 0; channel < input.getNumChannels(); ++channel)
130 for (size_t frame = 0; frame < input.getNumFrames(); ++frame)
131 output[channel][frame] = input[channel][frame] * (SampleType) m_gainLinear;
134 void processConstantGainAsMultiplexer (
const AudioBuffer<SampleType>& input,
AudioBuffer<SampleType>& output)
136 for (size_t channel = 0; channel < output.getNumChannels(); ++channel)
137 for (size_t frame = 0; frame < input.getNumFrames(); ++frame)
138 output[channel][frame] = input[0][frame] * (SampleType) m_gainLinear;
141 void processEnvelopedGainAsMultiChannel (
const AudioBuffer<SampleType>& input,
AudioBuffer<SampleType>& output)
143 for (size_t channel = 0; channel < input.getNumChannels(); ++channel)
144 for (size_t frame = 0; frame < input.getNumFrames(); ++frame)
145 output[channel][frame] = input[channel][frame] * (SampleType) m_gainEnvelopeValuesLinear[frame];
148 void processEnvelopedGainAsMultiplexer (
const AudioBuffer<SampleType>& input,
AudioBuffer<SampleType>& output)
150 for (size_t channel = 0; channel < output.getNumChannels(); ++channel)
151 for (size_t frame = 0; frame < input.getNumFrames(); ++frame)
152 output[channel][frame] = input[0][frame] * (SampleType) m_gainEnvelopeValuesLinear[frame];
Applies gain in decibels to the signal.
virtual bool supportsChannelLayout(size_t numInputChannels, size_t numOutputChannels) const override
Checks if the DSP supports given i/o configuration.
void prepare(double, size_t, size_t, size_t maxBlockSizeFrames) override
Prepare for processing.
GainDb(double gainDb=0.0)
Constructor.
double getValue(int id) const override
void process(const AudioBuffer< SampleType > &input, AudioBuffer< SampleType > &output, const EnvelopeBuffers &envelopeBuffers) override
Processes the audio.
@ gainDb
Gain in decibels.
virtual void represent(std::ostream &stream) const override
Makes a text representation of this DSP effect for test failure outputs.
void setValue(int id, double value) override
bool supportsEnvelopeFor(int id) const override
void reset() override
Resets to initial state.
#define HART_DSP_DEFINE_COPY_AND_MOVE(ClassName)
Defines hart::DSP::copy() and hart::DSP::move() methods.
std::ostream & dbPrecision(std::ostream &stream)
Sets number of decimal places for values in decibels.
static bool contains(const std::unordered_map< KeyType, ValueType > &map, const KeyType &key)
std::unordered_map::contains() replacement for C++11
static SampleType ratioToDecibels(SampleType valueLinear)
Converts linear value (ratio) to dB.
static SampleType decibelsToRatio(SampleType valueDb)
Converts dB to linear value (ratio)
#define HART_DSP_DECLARE_ALIASES_FOR(ClassName)
#define HART_THROW_OR_RETURN_VOID(ExceptionType, message)
#define hassert(condition)