diff options
author | Chris Robinson <[email protected]> | 2021-04-25 11:36:37 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2021-04-25 11:36:37 -0700 |
commit | 0fe38c053d8dd827e774fbe0aef121e7aa0a0f28 (patch) | |
tree | aaa18481969ff730ff2c287016644aca03622506 /alc/effects | |
parent | 9b65ca4556611c0b5b582a57d0c7714614badcc0 (diff) |
Move some functions to core
And clean up more includes
Diffstat (limited to 'alc/effects')
-rw-r--r-- | alc/effects/autowah.cpp | 22 | ||||
-rw-r--r-- | alc/effects/base.h | 6 | ||||
-rw-r--r-- | alc/effects/chorus.cpp | 18 | ||||
-rw-r--r-- | alc/effects/compressor.cpp | 22 | ||||
-rw-r--r-- | alc/effects/convolution.cpp | 18 | ||||
-rw-r--r-- | alc/effects/dedicated.cpp | 19 | ||||
-rw-r--r-- | alc/effects/distortion.cpp | 15 | ||||
-rw-r--r-- | alc/effects/echo.cpp | 22 | ||||
-rw-r--r-- | alc/effects/equalizer.cpp | 18 | ||||
-rw-r--r-- | alc/effects/fshifter.cpp | 20 | ||||
-rw-r--r-- | alc/effects/modulator.cpp | 22 | ||||
-rw-r--r-- | alc/effects/pshifter.cpp | 22 | ||||
-rw-r--r-- | alc/effects/reverb.cpp | 83 | ||||
-rw-r--r-- | alc/effects/vmorpher.cpp | 19 |
14 files changed, 238 insertions, 88 deletions
diff --git a/alc/effects/autowah.cpp b/alc/effects/autowah.cpp index a21d2a01..3df19eb2 100644 --- a/alc/effects/autowah.cpp +++ b/alc/effects/autowah.cpp @@ -20,16 +20,26 @@ #include "config.h" -#include <cmath> -#include <cstdlib> - #include <algorithm> +#include <array> +#include <cstdlib> +#include <iterator> +#include <utility> -#include "alcmain.h" #include "alcontext.h" -#include "core/filters/biquad.h" +#include "almalloc.h" +#include "alnumeric.h" +#include "alspan.h" +#include "core/ambidefs.h" +#include "core/bufferline.h" +#include "core/devformat.h" +#include "core/device.h" +#include "core/mixer.h" +#include "effects/base.h" #include "effectslot.h" -#include "vecmat.h" +#include "intrusive_ptr.h" +#include "math_defs.h" + namespace { diff --git a/alc/effects/base.h b/alc/effects/base.h index 09c722f5..6c31ae0c 100644 --- a/alc/effects/base.h +++ b/alc/effects/base.h @@ -18,11 +18,17 @@ struct BufferStorage; /** Target gain for the reverb decay feedback reaching the decay time. */ constexpr float ReverbDecayGain{0.001f}; /* -60 dB */ +constexpr float ReverbMaxReflectionsDelay{0.3f}; +constexpr float ReverbMaxLateReverbDelay{0.1f}; + enum class ChorusWaveform { Sinusoid, Triangle }; +constexpr float ChorusMaxDelay{0.016f}; +constexpr float FlangerMaxDelay{0.004f}; + constexpr float EchoMaxDelay{0.207f}; constexpr float EchoMaxLRDelay{0.404f}; diff --git a/alc/effects/chorus.cpp b/alc/effects/chorus.cpp index 805c57d5..4171cef8 100644 --- a/alc/effects/chorus.cpp +++ b/alc/effects/chorus.cpp @@ -21,20 +21,24 @@ #include "config.h" #include <algorithm> +#include <array> #include <climits> -#include <cmath> #include <cstdlib> #include <iterator> -#include "alcmain.h" #include "alcontext.h" #include "almalloc.h" #include "alnumeric.h" #include "alspan.h" -#include "alu.h" -#include "core/ambidefs.h" +#include "core/bufferline.h" +#include "core/devformat.h" +#include "core/device.h" +#include "core/mixer.h" +#include "core/mixer/defs.h" +#include "core/resampler_limits.h" #include "effects/base.h" #include "effectslot.h" +#include "intrusive_ptr.h" #include "math_defs.h" #include "opthelpers.h" #include "vector.h" @@ -42,6 +46,8 @@ namespace { +using uint = unsigned int; + #define MAX_UPDATE_SAMPLES 256 struct ChorusState final : public EffectState { @@ -79,7 +85,7 @@ struct ChorusState final : public EffectState { void ChorusState::deviceUpdate(const DeviceBase *Device, const Buffer&) { - constexpr float max_delay{maxf(AL_CHORUS_MAX_DELAY, AL_FLANGER_MAX_DELAY)}; + constexpr float max_delay{maxf(ChorusMaxDelay, FlangerMaxDelay)}; const auto frequency = static_cast<float>(Device->Frequency); const size_t maxlen{NextPowerOf2(float2uint(max_delay*2.0f*frequency) + 1u)}; @@ -247,7 +253,7 @@ void ChorusState::process(const size_t samplesToDo, const al::span<const FloatBu ++offset; } - for(ALsizei c{0};c < 2;++c) + for(size_t c{0};c < 2;++c) MixSamples({temps[c], todo}, samplesOut, mGains[c].Current, mGains[c].Target, samplesToDo-base, base); diff --git a/alc/effects/compressor.cpp b/alc/effects/compressor.cpp index 88fcf442..cedcaed0 100644 --- a/alc/effects/compressor.cpp +++ b/alc/effects/compressor.cpp @@ -20,13 +20,25 @@ #include "config.h" +#include <array> #include <cstdlib> - -#include "alcmain.h" -#include "alcontext.h" -#include "alu.h" +#include <iterator> +#include <utility> + +#include "almalloc.h" +#include "alnumeric.h" +#include "alspan.h" +#include "core/ambidefs.h" +#include "core/bufferline.h" +#include "core/devformat.h" +#include "core/device.h" +#include "core/mixer.h" +#include "core/mixer/defs.h" +#include "effects/base.h" #include "effectslot.h" -#include "vecmat.h" +#include "intrusive_ptr.h" + +struct ContextBase; namespace { diff --git a/alc/effects/convolution.cpp b/alc/effects/convolution.cpp index 072bc034..efc1c4c7 100644 --- a/alc/effects/convolution.cpp +++ b/alc/effects/convolution.cpp @@ -1,7 +1,15 @@ #include "config.h" +#include <algorithm> +#include <array> +#include <complex> +#include <cstddef> +#include <functional> +#include <iterator> +#include <memory> #include <stdint.h> +#include <utility> #ifdef HAVE_SSE_INTRINSICS #include <xmmintrin.h> @@ -9,20 +17,28 @@ #include <arm_neon.h> #endif +#include "albyte.h" #include "alcmain.h" #include "alcomplex.h" #include "alcontext.h" #include "almalloc.h" +#include "alnumeric.h" #include "alspan.h" #include "buffer_storage.h" +#include "config.h" #include "core/ambidefs.h" +#include "core/bufferline.h" +#include "core/devformat.h" +#include "core/device.h" #include "core/filters/splitter.h" #include "core/fmt_traits.h" -#include "core/logging.h" +#include "core/mixer.h" #include "effects/base.h" #include "effectslot.h" +#include "intrusive_ptr.h" #include "math_defs.h" #include "polyphase_resampler.h" +#include "vector.h" namespace { diff --git a/alc/effects/dedicated.cpp b/alc/effects/dedicated.cpp index f29458d2..78663053 100644 --- a/alc/effects/dedicated.cpp +++ b/alc/effects/dedicated.cpp @@ -20,18 +20,29 @@ #include "config.h" -#include <cstdlib> -#include <cmath> #include <algorithm> +#include <array> +#include <cstdlib> +#include <iterator> #include "alcmain.h" -#include "alcontext.h" -#include "alu.h" +#include "almalloc.h" +#include "alspan.h" +#include "core/bufferline.h" +#include "core/devformat.h" +#include "core/device.h" +#include "core/mixer.h" +#include "effects/base.h" #include "effectslot.h" +#include "intrusive_ptr.h" + +struct ContextBase; namespace { +using uint = unsigned int; + struct DedicatedState final : public EffectState { float mCurrentGains[MAX_OUTPUT_CHANNELS]; float mTargetGains[MAX_OUTPUT_CHANNELS]; diff --git a/alc/effects/distortion.cpp b/alc/effects/distortion.cpp index a9ac8293..d5d0fd32 100644 --- a/alc/effects/distortion.cpp +++ b/alc/effects/distortion.cpp @@ -21,13 +21,24 @@ #include "config.h" #include <algorithm> -#include <cmath> +#include <array> #include <cstdlib> +#include <iterator> -#include "alcmain.h" #include "alcontext.h" +#include "almalloc.h" +#include "alnumeric.h" +#include "alspan.h" +#include "core/bufferline.h" +#include "core/devformat.h" +#include "core/device.h" #include "core/filters/biquad.h" +#include "core/mixer.h" +#include "core/mixer/defs.h" +#include "effects/base.h" #include "effectslot.h" +#include "intrusive_ptr.h" +#include "math_defs.h" namespace { diff --git a/alc/effects/echo.cpp b/alc/effects/echo.cpp index 38183460..8ee1723c 100644 --- a/alc/effects/echo.cpp +++ b/alc/effects/echo.cpp @@ -20,20 +20,32 @@ #include "config.h" -#include <cmath> -#include <cstdlib> - #include <algorithm> +#include <array> +#include <cstdlib> +#include <iterator> +#include <tuple> -#include "alcmain.h" #include "alcontext.h" +#include "almalloc.h" +#include "alnumeric.h" +#include "alspan.h" +#include "core/bufferline.h" +#include "core/devformat.h" +#include "core/device.h" #include "core/filters/biquad.h" +#include "core/mixer.h" +#include "effects/base.h" #include "effectslot.h" +#include "intrusive_ptr.h" +#include "opthelpers.h" #include "vector.h" namespace { +using uint = unsigned int; + constexpr float LowpassFreqRef{5000.0f}; struct EchoState final : public EffectState { @@ -148,7 +160,7 @@ void EchoState::process(const size_t samplesToDo, const al::span<const FloatBuff mFilter.setComponents(z1, z2); mOffset = offset; - for(ALsizei c{0};c < 2;c++) + for(size_t c{0};c < 2;c++) MixSamples({mTempBuffer[c], samplesToDo}, samplesOut, mGains[c].Current, mGains[c].Target, samplesToDo, 0); } diff --git a/alc/effects/equalizer.cpp b/alc/effects/equalizer.cpp index fd8bf8c7..26a3cc47 100644 --- a/alc/effects/equalizer.cpp +++ b/alc/effects/equalizer.cpp @@ -20,17 +20,25 @@ #include "config.h" -#include <cmath> -#include <cstdlib> - #include <algorithm> +#include <array> +#include <cstdlib> #include <functional> +#include <iterator> +#include <utility> -#include "alcmain.h" #include "alcontext.h" +#include "almalloc.h" +#include "alspan.h" +#include "core/ambidefs.h" +#include "core/bufferline.h" +#include "core/devformat.h" +#include "core/device.h" #include "core/filters/biquad.h" +#include "core/mixer.h" +#include "effects/base.h" #include "effectslot.h" -#include "vecmat.h" +#include "intrusive_ptr.h" namespace { diff --git a/alc/effects/fshifter.cpp b/alc/effects/fshifter.cpp index e378a267..aae4b72c 100644 --- a/alc/effects/fshifter.cpp +++ b/alc/effects/fshifter.cpp @@ -20,22 +20,32 @@ #include "config.h" -#include <cmath> -#include <cstdlib> +#include <algorithm> #include <array> +#include <cmath> #include <complex> -#include <algorithm> +#include <cstdlib> +#include <iterator> -#include "alcmain.h" #include "alcomplex.h" #include "alcontext.h" -#include "alu.h" +#include "almalloc.h" +#include "alnumeric.h" +#include "alspan.h" +#include "core/bufferline.h" +#include "core/devformat.h" +#include "core/device.h" +#include "core/mixer.h" +#include "core/mixer/defs.h" +#include "effects/base.h" #include "effectslot.h" +#include "intrusive_ptr.h" #include "math_defs.h" namespace { +using uint = unsigned int; using complex_d = std::complex<double>; #define HIL_SIZE 1024 diff --git a/alc/effects/modulator.cpp b/alc/effects/modulator.cpp index 380d9809..735163a4 100644 --- a/alc/effects/modulator.cpp +++ b/alc/effects/modulator.cpp @@ -20,21 +20,31 @@ #include "config.h" -#include <cmath> -#include <cstdlib> - -#include <cmath> #include <algorithm> +#include <array> +#include <cstdlib> +#include <iterator> -#include "alcmain.h" #include "alcontext.h" +#include "almalloc.h" +#include "alnumeric.h" +#include "alspan.h" +#include "core/ambidefs.h" +#include "core/bufferline.h" +#include "core/devformat.h" +#include "core/device.h" #include "core/filters/biquad.h" +#include "core/mixer.h" +#include "effects/base.h" #include "effectslot.h" -#include "vecmat.h" +#include "intrusive_ptr.h" +#include "math_defs.h" namespace { +using uint = unsigned int; + #define MAX_UPDATE_SAMPLES 128 #define WAVEFORM_FRACBITS 24 diff --git a/alc/effects/pshifter.cpp b/alc/effects/pshifter.cpp index 1cf4861f..5bf813e5 100644 --- a/alc/effects/pshifter.cpp +++ b/alc/effects/pshifter.cpp @@ -20,23 +20,33 @@ #include "config.h" -#include <cmath> -#include <cstdlib> +#include <algorithm> #include <array> +#include <cmath> #include <complex> -#include <algorithm> +#include <cstdlib> +#include <iterator> -#include "alcmain.h" #include "alcomplex.h" -#include "alcontext.h" +#include "almalloc.h" #include "alnumeric.h" -#include "alu.h" +#include "alspan.h" +#include "core/bufferline.h" +#include "core/devformat.h" +#include "core/device.h" +#include "core/mixer.h" +#include "core/mixer/defs.h" +#include "effects/base.h" #include "effectslot.h" +#include "intrusive_ptr.h" #include "math_defs.h" +struct ContextBase; + namespace { +using uint = unsigned int; using complex_d = std::complex<double>; #define STFT_SIZE 1024 diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp index 2af7472d..ccb4f544 100644 --- a/alc/effects/reverb.cpp +++ b/alc/effects/reverb.cpp @@ -20,23 +20,34 @@ #include "config.h" -#include <cstdio> -#include <cstdlib> -#include <cmath> - -#include <array> -#include <numeric> #include <algorithm> +#include <array> +#include <cstdio> #include <functional> +#include <iterator> +#include <numeric> +#include <stdint.h> -#include "alcmain.h" #include "alcontext.h" +#include "almalloc.h" #include "alnumeric.h" +#include "alspan.h" +#include "alu.h" #include "core/ambidefs.h" +#include "core/bufferline.h" +#include "core/devformat.h" +#include "core/device.h" #include "core/filters/biquad.h" +#include "core/filters/splitter.h" +#include "core/mixer.h" +#include "core/mixer/defs.h" +#include "effects/base.h" #include "effectslot.h" -#include "vector.h" +#include "intrusive_ptr.h" +#include "math_defs.h" +#include "opthelpers.h" #include "vecmat.h" +#include "vector.h" /* This is a user config option for modifying the overall output of the reverb * effect. @@ -45,6 +56,11 @@ float ReverbBoost = 1.0f; namespace { +using uint = unsigned int; + +constexpr float MaxModulationTime{4.0f}; +constexpr float DefaultModulationTime{0.25f}; + #define MOD_FRACBITS 24 #define MOD_FRACONE (1<<MOD_FRACBITS) #define MOD_FRACMASK (MOD_FRACONE-1) @@ -379,15 +395,15 @@ struct ReverbState final : public EffectState { /* Calculated parameters which indicate if cross-fading is needed after * an update. */ - float Density{AL_EAXREVERB_DEFAULT_DENSITY}; - float Diffusion{AL_EAXREVERB_DEFAULT_DIFFUSION}; - float DecayTime{AL_EAXREVERB_DEFAULT_DECAY_TIME}; - float HFDecayTime{AL_EAXREVERB_DEFAULT_DECAY_HFRATIO * AL_EAXREVERB_DEFAULT_DECAY_TIME}; - float LFDecayTime{AL_EAXREVERB_DEFAULT_DECAY_LFRATIO * AL_EAXREVERB_DEFAULT_DECAY_TIME}; - float ModulationTime{AL_EAXREVERB_DEFAULT_MODULATION_TIME}; - float ModulationDepth{AL_EAXREVERB_DEFAULT_MODULATION_DEPTH}; - float HFReference{AL_EAXREVERB_DEFAULT_HFREFERENCE}; - float LFReference{AL_EAXREVERB_DEFAULT_LFREFERENCE}; + float Density{1.0f}; + float Diffusion{1.0f}; + float DecayTime{1.49f}; + float HFDecayTime{0.83f * 1.49f}; + float LFDecayTime{1.0f * 1.49f}; + float ModulationTime{0.25f}; + float ModulationDepth{0.0f}; + float HFReference{5000.0f}; + float LFReference{250.0f}; } mParams; /* Master effect filters */ @@ -556,16 +572,17 @@ void ReverbState::allocLines(const float frequency) /* Multiplier for the maximum density value, i.e. density=1, which is * actually the least density... */ - const float multiplier{CalcDelayLengthMult(AL_EAXREVERB_MAX_DENSITY)}; + const float multiplier{CalcDelayLengthMult(1.0f)}; /* The main delay length includes the maximum early reflection delay, the * largest early tap width, the maximum late reverb delay, and the * largest late tap width. Finally, it must also be extended by the * update size (BufferLineSize) for block processing. */ - float length{AL_EAXREVERB_MAX_REFLECTIONS_DELAY + EARLY_TAP_LENGTHS.back()*multiplier + - AL_EAXREVERB_MAX_LATE_REVERB_DELAY + - (LATE_LINE_LENGTHS.back() - LATE_LINE_LENGTHS.front())/float{NUM_LINES}*multiplier}; + constexpr float LateLineDiffAvg{(LATE_LINE_LENGTHS.back()-LATE_LINE_LENGTHS.front()) / + float{NUM_LINES}}; + float length{ReverbMaxReflectionsDelay + EARLY_TAP_LENGTHS.back()*multiplier + + ReverbMaxLateReverbDelay + LateLineDiffAvg*multiplier}; totalSamples += mDelay.calcLineLength(length, totalSamples, frequency, BufferLineSize); /* The early vector all-pass line. */ @@ -584,7 +601,7 @@ void ReverbState::allocLines(const float frequency) * time and depth coefficient, and halfed for the low-to-high frequency * swing. */ - constexpr float max_mod_delay{AL_EAXREVERB_MAX_MODULATION_TIME*MODULATION_DEPTH_COEFF / 2.0f}; + constexpr float max_mod_delay{MaxModulationTime*MODULATION_DEPTH_COEFF / 2.0f}; /* The late delay lines are calculated from the largest maximum density * line length, and the maximum modulation delay. An additional sample is @@ -614,11 +631,11 @@ void ReverbState::deviceUpdate(const DeviceBase *device, const Buffer&) /* Allocate the delay lines. */ allocLines(frequency); - const float multiplier{CalcDelayLengthMult(AL_EAXREVERB_MAX_DENSITY)}; + const float multiplier{CalcDelayLengthMult(1.0f)}; /* The late feed taps are set a fixed position past the latest delay tap. */ - mLateFeedTap = float2uint( - (AL_EAXREVERB_MAX_REFLECTIONS_DELAY + EARLY_TAP_LENGTHS.back()*multiplier) * frequency); + mLateFeedTap = float2uint((ReverbMaxReflectionsDelay + EARLY_TAP_LENGTHS.back()*multiplier) * + frequency); /* Clear filters and gain coefficients since the delay lines were all just * cleared (if not reallocated). @@ -813,15 +830,14 @@ void Modulation::updateModulator(float modTime, float modDepth, float frequency) * (half of it is spent decreasing the frequency, half is spent increasing * it). */ - if(modTime >= AL_EAXREVERB_DEFAULT_MODULATION_TIME) + if(modTime >= DefaultModulationTime) { /* To cancel the effects of a long period modulation on the late * reverberation, the amount of pitch should be varied (decreased) * according to the modulation time. The natural form is varying * inversely, in fact resulting in an invariant. */ - Depth[1] = MODULATION_DEPTH_COEFF / 4.0f * AL_EAXREVERB_DEFAULT_MODULATION_TIME * - modDepth * frequency; + Depth[1] = MODULATION_DEPTH_COEFF / 4.0f * DefaultModulationTime * modDepth * frequency; } else Depth[1] = MODULATION_DEPTH_COEFF / 4.0f * modTime * modDepth * frequency; @@ -835,7 +851,8 @@ void LateReverb::updateLines(const float density_mult, const float diffusion, /* Scaling factor to convert the normalized reference frequencies from * representing 0...freq to 0...max_reference. */ - const float norm_weight_factor{frequency / AL_EAXREVERB_MAX_HFREFERENCE}; + constexpr float MaxHFReference{20000.0f}; + const float norm_weight_factor{frequency / MaxHFReference}; const float late_allpass_avg{ std::accumulate(LATE_ALLPASS_LENGTHS.begin(), LATE_ALLPASS_LENGTHS.end(), 0.0f) / @@ -1024,10 +1041,10 @@ void ReverbState::update(const ContextBase *Context, const EffectSlot *Slot, props->Reverb.DecayTime); /* Calculate the LF/HF decay times. */ - const float lfDecayTime{clampf(props->Reverb.DecayTime * props->Reverb.DecayLFRatio, - AL_EAXREVERB_MIN_DECAY_TIME, AL_EAXREVERB_MAX_DECAY_TIME)}; - const float hfDecayTime{clampf(props->Reverb.DecayTime * hfRatio, - AL_EAXREVERB_MIN_DECAY_TIME, AL_EAXREVERB_MAX_DECAY_TIME)}; + constexpr float MinDecayTime{0.1f}, MaxDecayTime{20.0f}; + const float lfDecayTime{clampf(props->Reverb.DecayTime*props->Reverb.DecayLFRatio, + MinDecayTime, MaxDecayTime)}; + const float hfDecayTime{clampf(props->Reverb.DecayTime*hfRatio, MinDecayTime, MaxDecayTime)}; /* Update the modulator rate and depth. */ mLate.Mod.updateModulator(props->Reverb.ModulationTime, props->Reverb.ModulationDepth, diff --git a/alc/effects/vmorpher.cpp b/alc/effects/vmorpher.cpp index 332df159..f3ed7aad 100644 --- a/alc/effects/vmorpher.cpp +++ b/alc/effects/vmorpher.cpp @@ -20,20 +20,31 @@ #include "config.h" -#include <cmath> -#include <cstdlib> #include <algorithm> +#include <array> +#include <cstdlib> #include <functional> +#include <iterator> -#include "alcmain.h" #include "alcontext.h" -#include "alu.h" +#include "almalloc.h" +#include "alnumeric.h" +#include "alspan.h" +#include "core/ambidefs.h" +#include "core/bufferline.h" +#include "core/devformat.h" +#include "core/device.h" +#include "core/mixer.h" +#include "effects/base.h" #include "effectslot.h" +#include "intrusive_ptr.h" #include "math_defs.h" namespace { +using uint = unsigned int; + #define MAX_UPDATE_SAMPLES 256 #define NUM_FORMANTS 4 #define NUM_FILTERS 2 |