diff options
author | Chris Robinson <[email protected]> | 2019-12-25 18:39:22 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-12-25 18:39:22 -0800 |
commit | f153def94194050b331c7a2674959b9ea1d0008d (patch) | |
tree | 17012f29ae0f51ebf615a3866210bba2b8636652 /alc/effects/distortion.cpp | |
parent | 36c745a5149fe196b2ea8c058d2d3391db3dde8b (diff) |
Pass a span for the biquad filter input
Diffstat (limited to 'alc/effects/distortion.cpp')
-rw-r--r-- | alc/effects/distortion.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/alc/effects/distortion.cpp b/alc/effects/distortion.cpp index 0916b7c6..48fc83ee 100644 --- a/alc/effects/distortion.cpp +++ b/alc/effects/distortion.cpp @@ -20,11 +20,10 @@ #include "config.h" +#include <algorithm> #include <cmath> #include <cstdlib> -#include <cmath> - #include "al/auxeffectslot.h" #include "alcmain.h" #include "alcontext.h" @@ -114,26 +113,25 @@ void DistortionState::process(const size_t samplesToDo, const al::span<const Flo * (which is fortunately first step of distortion). So combine three * operations into the one. */ - mLowpass.process(mBuffer[1], mBuffer[0], todo); + mLowpass.process({mBuffer[0], todo}, mBuffer[1]); /* Second step, do distortion using waveshaper function to emulate * signal processing during tube overdriving. Three steps of * waveshaping are intended to modify waveform without boost/clipping/ * attenuation process. */ - for(size_t i{0u};i < todo;i++) + auto proc_sample = [fc](float smp) -> float { - ALfloat smp{mBuffer[1][i]}; - - smp = (1.0f + fc) * smp/(1.0f + fc*fabsf(smp)); - smp = (1.0f + fc) * smp/(1.0f + fc*fabsf(smp)) * -1.0f; - smp = (1.0f + fc) * smp/(1.0f + fc*fabsf(smp)); - - mBuffer[0][i] = smp; - } + smp = (1.0f + fc) * smp/(1.0f + fc*std::abs(smp)); + smp = (1.0f + fc) * smp/(1.0f + fc*std::abs(smp)) * -1.0f; + smp = (1.0f + fc) * smp/(1.0f + fc*std::abs(smp)); + return smp; + }; + std::transform(std::begin(mBuffer[1]), std::begin(mBuffer[1])+todo, std::begin(mBuffer[0]), + proc_sample); /* Third step, do bandpass filtering of distorted signal. */ - mBandpass.process(mBuffer[1], mBuffer[0], todo); + mBandpass.process({mBuffer[0], todo}, mBuffer[1]); todo >>= 2; const ALfloat *outgains{mGain}; |