aboutsummaryrefslogtreecommitdiffstats
path: root/core/mixer/mixer_c.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/mixer/mixer_c.cpp')
-rw-r--r--core/mixer/mixer_c.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/core/mixer/mixer_c.cpp b/core/mixer/mixer_c.cpp
index f3e6aa6a..dabfa652 100644
--- a/core/mixer/mixer_c.cpp
+++ b/core/mixer/mixer_c.cpp
@@ -198,3 +198,38 @@ void Mix_<CTag>(const al::span<const float> InSamples, const al::span<FloatBuffe
dst[pos] += InSamples[pos] * gain;
}
}
+
+template<>
+void Mix_<CTag>(const al::span<const float> InSamples, float *OutBuffer, float &CurrentGain,
+ const float TargetGain, const size_t Counter)
+{
+ const float delta{(Counter > 0) ? 1.0f / static_cast<float>(Counter) : 0.0f};
+ const auto min_len = minz(Counter, InSamples.size());
+
+ float *RESTRICT dst{al::assume_aligned<16>(OutBuffer)};
+ float gain{CurrentGain};
+ const float step{(TargetGain-gain) * delta};
+
+ size_t pos{0};
+ if(!(std::abs(step) > std::numeric_limits<float>::epsilon()))
+ gain = TargetGain;
+ else
+ {
+ float step_count{0.0f};
+ for(;pos != min_len;++pos)
+ {
+ dst[pos] += InSamples[pos] * (gain + step*step_count);
+ step_count += 1.0f;
+ }
+ if(pos == Counter)
+ gain = TargetGain;
+ else
+ gain += step*step_count;
+ }
+ CurrentGain = gain;
+
+ if(!(std::abs(gain) > GainSilenceThreshold))
+ return;
+ for(;pos != InSamples.size();++pos)
+ dst[pos] += InSamples[pos] * gain;
+}