From 691c25362b6362c741c72fc0030636547dce31fc Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Thu, 7 May 2020 20:48:48 +0200 Subject: [PATCH] Add a helper to apply a gain span to effect inputs Used for ramping out voice data --- src/sfizz/Effects.cpp | 11 +++++++++++ src/sfizz/Effects.h | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/sfizz/Effects.cpp b/src/sfizz/Effects.cpp index e6dd469d..de6e9692 100644 --- a/src/sfizz/Effects.cpp +++ b/src/sfizz/Effects.cpp @@ -109,6 +109,17 @@ void EffectBus::addToInputs(const float* const addInput[], float addGain, unsign } } +void EffectBus::applyGain(const float* gain, unsigned nframes) +{ + if (!gain) + return; + + absl::Span gainSpan { gain, nframes }; + for (unsigned c = 0; c < EffectChannels; ++c) { + sfz::applyGain(gainSpan, _inputs.getSpan(c)); + } +} + void EffectBus::setSampleRate(double sampleRate) { for (const auto& effectPtr : _effects) diff --git a/src/sfizz/Effects.h b/src/sfizz/Effects.h index 1c1edfeb..2056cac2 100644 --- a/src/sfizz/Effects.h +++ b/src/sfizz/Effects.h @@ -136,6 +136,11 @@ public: */ void addToInputs(const float* const addInput[], float addGain, unsigned nframes); + /** + @brief Apply a gain to the inputs + */ + void applyGain(const float* gain, unsigned nframes); + /** @brief Initializes all effects in the bus with the given sample rate. */