diff options
author | Chris Robinson <[email protected]> | 2023-01-05 01:47:55 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-01-05 01:47:55 -0800 |
commit | 23c8a35505fe6ab7a5c87754911a133b23ac75cf (patch) | |
tree | d36b9dabb413680d8074f3e8aad0084691d20813 /core/mixer/mixer_c.cpp | |
parent | 58a18ab3c0126337d17939b5060fce28a39b8cf1 (diff) |
Add and use mixers that process one input and output channel
Diffstat (limited to 'core/mixer/mixer_c.cpp')
-rw-r--r-- | core/mixer/mixer_c.cpp | 35 |
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; +} |