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 | |
parent | 9b65ca4556611c0b5b582a57d0c7714614badcc0 (diff) |
Move some functions to core
And clean up more includes
Diffstat (limited to 'alc')
-rw-r--r-- | alc/alu.cpp | 1 | ||||
-rw-r--r-- | alc/alu.h | 85 | ||||
-rw-r--r-- | alc/bformatdec.cpp | 6 | ||||
-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 | ||||
-rw-r--r-- | alc/panning.cpp | 110 | ||||
-rw-r--r-- | alc/voice.cpp | 3 |
19 files changed, 242 insertions, 289 deletions
diff --git a/alc/alu.cpp b/alc/alu.cpp index d5103852..7221ce27 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -64,6 +64,7 @@ #include "core/fpu_ctrl.h" #include "core/hrtf.h" #include "core/mastering.h" +#include "core/mixer.h" #include "core/mixer/defs.h" #include "core/uhjfilter.h" #include "effects/base.h" @@ -22,13 +22,6 @@ struct MixParams; #define MAX_SENDS 6 -using MixerFunc = void(*)(const al::span<const float> InSamples, - const al::span<FloatBufferLine> OutBuffer, float *CurrentGains, const float *TargetGains, - const size_t Counter, const size_t OutPos); - -extern MixerFunc MixSamples; - - constexpr float GainMixMax{1000.0f}; /* +60dB */ constexpr float SpeedOfSoundMetersPerSec{343.3f}; @@ -55,84 +48,6 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq void aluInitEffectPanning(EffectSlot *slot, ALCcontext *context); -/** - * Calculates ambisonic encoder coefficients using the X, Y, and Z direction - * components, which must represent a normalized (unit length) vector, and the - * spread is the angular width of the sound (0...tau). - * - * NOTE: The components use ambisonic coordinates. As a result: - * - * Ambisonic Y = OpenAL -X - * Ambisonic Z = OpenAL Y - * Ambisonic X = OpenAL -Z - * - * The components are ordered such that OpenAL's X, Y, and Z are the first, - * second, and third parameters respectively -- simply negate X and Z. - */ -std::array<float,MaxAmbiChannels> CalcAmbiCoeffs(const float y, const float z, const float x, - const float spread); - -/** - * CalcDirectionCoeffs - * - * Calculates ambisonic coefficients based on an OpenAL direction vector. The - * vector must be normalized (unit length), and the spread is the angular width - * of the sound (0...tau). - */ -inline std::array<float,MaxAmbiChannels> CalcDirectionCoeffs(const float (&dir)[3], - const float spread) -{ - /* Convert from OpenAL coords to Ambisonics. */ - return CalcAmbiCoeffs(-dir[0], dir[1], -dir[2], spread); -} - -/** - * CalcAngleCoeffs - * - * Calculates ambisonic coefficients based on azimuth and elevation. The - * azimuth and elevation parameters are in radians, going right and up - * respectively. - */ -inline std::array<float,MaxAmbiChannels> CalcAngleCoeffs(const float azimuth, - const float elevation, const float spread) -{ - const float x{-std::sin(azimuth) * std::cos(elevation)}; - const float y{ std::sin(elevation)}; - const float z{ std::cos(azimuth) * std::cos(elevation)}; - - return CalcAmbiCoeffs(x, y, z, spread); -} - - -/** - * ComputePanGains - * - * Computes panning gains using the given channel decoder coefficients and the - * pre-calculated direction or angle coefficients. For B-Format sources, the - * coeffs are a 'slice' of a transform matrix for the input channel, used to - * scale and orient the sound samples. - */ -void ComputePanGains(const MixParams *mix, const float*RESTRICT coeffs, const float ingain, - const al::span<float,MAX_OUTPUT_CHANNELS> gains); - - -/** Helper to set an identity/pass-through panning for ambisonic mixing (3D input). */ -template<typename T, typename I, typename F> -auto SetAmbiPanIdentity(T iter, I count, F func) -> std::enable_if_t<std::is_integral<I>::value> -{ - if(count < 1) return; - - std::array<float,MaxAmbiChannels> coeffs{{1.0f}}; - func(*iter, coeffs); - ++iter; - for(I i{1};i < count;++i,++iter) - { - coeffs[i-1] = 0.0f; - coeffs[i ] = 1.0f; - func(*iter, coeffs); - } -} - extern const float ConeScale; extern const float ZScale; diff --git a/alc/bformatdec.cpp b/alc/bformatdec.cpp index 36b8d50e..e29af045 100644 --- a/alc/bformatdec.cpp +++ b/alc/bformatdec.cpp @@ -5,15 +5,13 @@ #include <algorithm> #include <array> -#include <cassert> #include <cmath> -#include <iterator> -#include <numeric> +#include <utility> #include "almalloc.h" -#include "alu.h" #include "core/ambdec.h" #include "core/filters/splitter.h" +#include "core/mixer.h" #include "front_stablizer.h" #include "math_defs.h" #include "opthelpers.h" 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 diff --git a/alc/panning.cpp b/alc/panning.cpp index 39f4f4c3..ce6ba29c 100644 --- a/alc/panning.cpp +++ b/alc/panning.cpp @@ -1090,113 +1090,3 @@ void aluInitEffectPanning(EffectSlot *slot, ALCcontext *context) std::fill(iter, slot->Wet.AmbiMap.end(), BFChannelConfig{}); slot->Wet.Buffer = wetbuffer->mBuffer; } - - -std::array<float,MaxAmbiChannels> CalcAmbiCoeffs(const float y, const float z, const float x, - const float spread) -{ - std::array<float,MaxAmbiChannels> coeffs; - - /* Zeroth-order */ - coeffs[0] = 1.0f; /* ACN 0 = 1 */ - /* First-order */ - coeffs[1] = 1.732050808f * y; /* ACN 1 = sqrt(3) * Y */ - coeffs[2] = 1.732050808f * z; /* ACN 2 = sqrt(3) * Z */ - coeffs[3] = 1.732050808f * x; /* ACN 3 = sqrt(3) * X */ - /* Second-order */ - const float xx{x*x}, yy{y*y}, zz{z*z}, xy{x*y}, yz{y*z}, xz{x*z}; - coeffs[4] = 3.872983346f * xy; /* ACN 4 = sqrt(15) * X * Y */ - coeffs[5] = 3.872983346f * yz; /* ACN 5 = sqrt(15) * Y * Z */ - coeffs[6] = 1.118033989f * (3.0f*zz - 1.0f); /* ACN 6 = sqrt(5)/2 * (3*Z*Z - 1) */ - coeffs[7] = 3.872983346f * xz; /* ACN 7 = sqrt(15) * X * Z */ - coeffs[8] = 1.936491673f * (xx - yy); /* ACN 8 = sqrt(15)/2 * (X*X - Y*Y) */ - /* Third-order */ - coeffs[9] = 2.091650066f * (y*(3.0f*xx - yy)); /* ACN 9 = sqrt(35/8) * Y * (3*X*X - Y*Y) */ - coeffs[10] = 10.246950766f * (z*xy); /* ACN 10 = sqrt(105) * Z * X * Y */ - coeffs[11] = 1.620185175f * (y*(5.0f*zz - 1.0f)); /* ACN 11 = sqrt(21/8) * Y * (5*Z*Z - 1) */ - coeffs[12] = 1.322875656f * (z*(5.0f*zz - 3.0f)); /* ACN 12 = sqrt(7)/2 * Z * (5*Z*Z - 3) */ - coeffs[13] = 1.620185175f * (x*(5.0f*zz - 1.0f)); /* ACN 13 = sqrt(21/8) * X * (5*Z*Z - 1) */ - coeffs[14] = 5.123475383f * (z*(xx - yy)); /* ACN 14 = sqrt(105)/2 * Z * (X*X - Y*Y) */ - coeffs[15] = 2.091650066f * (x*(xx - 3.0f*yy)); /* ACN 15 = sqrt(35/8) * X * (X*X - 3*Y*Y) */ - /* Fourth-order */ - /* ACN 16 = sqrt(35)*3/2 * X * Y * (X*X - Y*Y) */ - /* ACN 17 = sqrt(35/2)*3/2 * (3*X*X - Y*Y) * Y * Z */ - /* ACN 18 = sqrt(5)*3/2 * X * Y * (7*Z*Z - 1) */ - /* ACN 19 = sqrt(5/2)*3/2 * Y * Z * (7*Z*Z - 3) */ - /* ACN 20 = 3/8 * (35*Z*Z*Z*Z - 30*Z*Z + 3) */ - /* ACN 21 = sqrt(5/2)*3/2 * X * Z * (7*Z*Z - 3) */ - /* ACN 22 = sqrt(5)*3/4 * (X*X - Y*Y) * (7*Z*Z - 1) */ - /* ACN 23 = sqrt(35/2)*3/2 * (X*X - 3*Y*Y) * X * Z */ - /* ACN 24 = sqrt(35)*3/8 * (X*X*X*X - 6*X*X*Y*Y + Y*Y*Y*Y) */ - - if(spread > 0.0f) - { - /* Implement the spread by using a spherical source that subtends the - * angle spread. See: - * http://www.ppsloan.org/publications/StupidSH36.pdf - Appendix A3 - * - * When adjusted for N3D normalization instead of SN3D, these - * calculations are: - * - * ZH0 = -sqrt(pi) * (-1+ca); - * ZH1 = 0.5*sqrt(pi) * sa*sa; - * ZH2 = -0.5*sqrt(pi) * ca*(-1+ca)*(ca+1); - * ZH3 = -0.125*sqrt(pi) * (-1+ca)*(ca+1)*(5*ca*ca - 1); - * ZH4 = -0.125*sqrt(pi) * ca*(-1+ca)*(ca+1)*(7*ca*ca - 3); - * ZH5 = -0.0625*sqrt(pi) * (-1+ca)*(ca+1)*(21*ca*ca*ca*ca - 14*ca*ca + 1); - * - * The gain of the source is compensated for size, so that the - * loudness doesn't depend on the spread. Thus: - * - * ZH0 = 1.0f; - * ZH1 = 0.5f * (ca+1.0f); - * ZH2 = 0.5f * (ca+1.0f)*ca; - * ZH3 = 0.125f * (ca+1.0f)*(5.0f*ca*ca - 1.0f); - * ZH4 = 0.125f * (ca+1.0f)*(7.0f*ca*ca - 3.0f)*ca; - * ZH5 = 0.0625f * (ca+1.0f)*(21.0f*ca*ca*ca*ca - 14.0f*ca*ca + 1.0f); - */ - const float ca{std::cos(spread * 0.5f)}; - /* Increase the source volume by up to +3dB for a full spread. */ - const float scale{std::sqrt(1.0f + spread/al::MathDefs<float>::Tau())}; - - const float ZH0_norm{scale}; - const float ZH1_norm{scale * 0.5f * (ca+1.f)}; - const float ZH2_norm{scale * 0.5f * (ca+1.f)*ca}; - const float ZH3_norm{scale * 0.125f * (ca+1.f)*(5.f*ca*ca-1.f)}; - - /* Zeroth-order */ - coeffs[0] *= ZH0_norm; - /* First-order */ - coeffs[1] *= ZH1_norm; - coeffs[2] *= ZH1_norm; - coeffs[3] *= ZH1_norm; - /* Second-order */ - coeffs[4] *= ZH2_norm; - coeffs[5] *= ZH2_norm; - coeffs[6] *= ZH2_norm; - coeffs[7] *= ZH2_norm; - coeffs[8] *= ZH2_norm; - /* Third-order */ - coeffs[9] *= ZH3_norm; - coeffs[10] *= ZH3_norm; - coeffs[11] *= ZH3_norm; - coeffs[12] *= ZH3_norm; - coeffs[13] *= ZH3_norm; - coeffs[14] *= ZH3_norm; - coeffs[15] *= ZH3_norm; - } - - return coeffs; -} - -void ComputePanGains(const MixParams *mix, const float*RESTRICT coeffs, const float ingain, - const al::span<float,MAX_OUTPUT_CHANNELS> gains) -{ - auto ambimap = mix->AmbiMap.cbegin(); - - auto iter = std::transform(ambimap, ambimap+mix->Buffer.size(), gains.begin(), - [coeffs,ingain](const BFChannelConfig &chanmap) noexcept -> float - { return chanmap.Scale * coeffs[chanmap.Index] * ingain; } - ); - std::fill(iter, gains.end(), 0.0f); -} diff --git a/alc/voice.cpp b/alc/voice.cpp index 6368d5c4..8782e916 100644 --- a/alc/voice.cpp +++ b/alc/voice.cpp @@ -53,6 +53,7 @@ #include "core/filters/splitter.h" #include "core/fmt_traits.h" #include "core/logging.h" +#include "core/mixer.h" #include "core/mixer/defs.h" #include "core/mixer/hrtfdefs.h" #include "core/resampler_limits.h" @@ -75,8 +76,6 @@ static_assert(!(sizeof(Voice::BufferLine)&15), "Voice::BufferLine must be a mult Resampler ResamplerDefault{Resampler::Linear}; -MixerFunc MixSamples{Mix_<CTag>}; - namespace { using HrtfMixerFunc = void(*)(const float *InSamples, float2 *AccumSamples, const uint IrSize, |