From 43fac7e95568a2b7205db365a49e3938b05e913b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 11 Sep 2023 02:56:14 -0700 Subject: Approximate sin for the reverb modulator LFO Reverb needs to prioritize efficiency since it's expected that an app may use multiple reverb effects simultaneously, and each individual effect may process twice during a pipeline transition. Approximating sin helps by replacing a per- sample libc call that we don't need to be perfectly accurate. --- alc/effects/reverb.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'alc') diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp index 429d0225..b00f638b 100644 --- a/alc/effects/reverb.cpp +++ b/alc/effects/reverb.cpp @@ -1505,14 +1505,19 @@ void ReverbPipeline::processEarly(size_t offset, const size_t samplesToDo, void Modulation::calcDelays(size_t todo) { - constexpr float mod_scale{al::numbers::pi_v * 2.0f / MOD_FRACONE}; uint idx{Index}; const uint step{Step}; const float depth{Depth}; for(size_t i{0};i < todo;++i) { idx += step; - const float lfo{std::sin(static_cast(idx&MOD_FRACMASK) * mod_scale)}; + const float x{static_cast(idx&MOD_FRACMASK) * (1.0f/MOD_FRACONE)}; + /* Approximate sin(x*2pi). As long as it roughly fits a sinusoid shape + * and stays within [-1...+1], it needn't be perfect. + */ + const float lfo{!(idx&(MOD_FRACONE>>1)) + ? ((-16.0f * x * x) + (8.0f * x)) + : ((16.0f * x * x) + (-8.0f * x) + (-16.0f * x) + 8.0f)}; ModDelays[i] = (lfo+1.0f) * depth; } Index = idx; -- cgit v1.2.3