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
);
53 auto& gainEnvelopeValuesDb = envelopeBuffers. at(
Params::gainDb);
54 hassert (gainEnvelopeValuesDb.size() == m_gainEnvelopeValuesLinear.size());
56 for (size_t i = 0; i < m_gainEnvelopeValuesLinear.size(); ++i)
57 m_gainEnvelopeValuesLinear[i] = decibelsToRatio (gainEnvelopeValuesDb[i]);
59 processEnvelopedGain (input, output, channelsToProcess);
64 processConstantGain (input, output, channelsToProcess);
91 return numInputChannels == numOutputChannels;
94 virtual void represent (std::ostream& stream)
const override
96 stream <<
dbPrecision <<
"GainDb (" << m_initialGainDb <<
"_dB)";
103 return id ==
Params::gainDb;
107 double m_initialGainDb;
109 std::vector<
double> m_gainEnvelopeValuesLinear;
113 for (size_t channel = 0; channel < input.getNumChannels(); ++channel)
115 if (channelsToProcess
[channel
] ==
true)
117 for (size_t frame = 0; frame < input.getNumFrames(); ++frame)
118 output[channel][frame] = input[channel][frame] * (SampleType) m_gainLinear;
122 for (size_t frame = 0; frame < input.getNumFrames(); ++frame)
123 output[channel][frame] = input[channel][frame];
130 for (size_t channel = 0; channel < input.getNumChannels(); ++channel)
132 if (channelsToProcess
[channel
] ==
true)
134 for (size_t frame = 0; frame < input.getNumFrames(); ++frame)
135 output[channel][frame] = input[channel][frame] * (SampleType) m_gainEnvelopeValuesLinear[frame];
139 for (size_t frame = 0; frame < input.getNumFrames(); ++frame)
140 output[channel][frame] = input[channel][frame];
A set of boolean flags mapped to each audio channel.
std::bitset< m_maxChannels >::reference operator[](size_t channel)
Access the flag value for a specific channel.
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
@ 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 process(const AudioBuffer< SampleType > &input, AudioBuffer< SampleType > &output, const EnvelopeBuffers &envelopeBuffers, ChannelFlags channelsToProcess) override
Processes the audio.
void setValue(int id, double value) override
bool supportsEnvelopeFor(int id) const override
void reset() override
Resets to initial state.
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)