From 259e201fac619ea3d818543fc995ed32eab16df9 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Mon, 2 Mar 2020 14:07:06 +0100 Subject: [PATCH] Add the multiplyAdd methods for AudioSpan --- src/sfizz/AudioSpan.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/sfizz/AudioSpan.h b/src/sfizz/AudioSpan.h index b4cb4e75..312c1e1b 100644 --- a/src/sfizz/AudioSpan.h +++ b/src/sfizz/AudioSpan.h @@ -11,6 +11,7 @@ #include "Debug.h" #include "LeakDetector.h" #include "SIMDHelpers.h" +#include "absl/types/span.h" #include #include #include @@ -306,6 +307,43 @@ public: } } + /** + * @brief Add another AudioSpan with a compatible number of channels to the current + * AudioSpan, applying an elementwise gain to the operand. + * + * @param other the other AudioSpan + * @param gain the gain to apply + */ + template > + void multiplyAdd(AudioSpan& other, absl::Span gain) + { + static_assert(!std::is_const::value, "Can't allow mutating operations on const AudioSpans"); + ASSERT(other.getNumChannels() == numChannels); + ASSERT(gain.size() == numFrames); + if (other.getNumChannels() == numChannels) { + for (size_t i = 0; i < numChannels; ++i) + sfz::multiplyAdd(gain, other.getConstSpan(i), getSpan(i)); + } + } + + /** + * @brief Add another AudioSpan with a compatible number of channels to the current + * AudioSpan, applying a fixed gain to the operand. + * + * @param other the other AudioSpan + * @param gain the gain to apply + */ + template > + void multiplyAdd(AudioSpan& other, const Type gain) + { + static_assert(!std::is_const::value, "Can't allow mutating operations on const AudioSpans"); + ASSERT(other.getNumChannels() == numChannels); + if (other.getNumChannels() == numChannels) { + for (size_t i = 0; i < numChannels; ++i) + sfz::multiplyAdd(gain, other.getConstSpan(i), getSpan(i)); + } + } + /** * @brief Copy the elements of another AudioSpan with a compatible number of channels * to the current AudioSpan.