diff options
author | Chris Robinson <[email protected]> | 2019-10-03 04:22:39 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-10-03 04:22:39 -0700 |
commit | 1bb93f4fc213e4a93aedd4937ef2a8fa0d160b25 (patch) | |
tree | 68484db29211e8483d6175142213f430d4d834af /alc | |
parent | b350ae3766f0f85183c410b4c77ac9a0eb388511 (diff) |
Avoid direct function template and alias types
It's somewhat ambiguous what they mean. Sometimes acting as a pointer, other
times having weird behavior. Pointer-to-function types are explicitly defined
as such, whereas uses of these tend to be as references (never null and not
changeable).
Diffstat (limited to 'alc')
-rw-r--r-- | alc/effects/modulator.cpp | 29 | ||||
-rw-r--r-- | alc/effects/vmorpher.cpp | 29 | ||||
-rw-r--r-- | alc/mixer/mixer_c.cpp | 4 |
3 files changed, 24 insertions, 38 deletions
diff --git a/alc/effects/modulator.cpp b/alc/effects/modulator.cpp index 8042378a..23bae63f 100644 --- a/alc/effects/modulator.cpp +++ b/alc/effects/modulator.cpp @@ -42,29 +42,22 @@ namespace { #define WAVEFORM_FRACONE (1<<WAVEFORM_FRACBITS) #define WAVEFORM_FRACMASK (WAVEFORM_FRACONE-1) -inline ALfloat Sin(ALuint index) +inline float Sin(ALuint index) { - return std::sin(static_cast<ALfloat>(index) * - (al::MathDefs<float>::Tau() / ALfloat{WAVEFORM_FRACONE})); + constexpr float scale{al::MathDefs<float>::Tau() / WAVEFORM_FRACONE}; + return std::sin(static_cast<float>(index) * scale); } -inline ALfloat Saw(ALuint index) -{ - return static_cast<ALfloat>(index)*(2.0f/WAVEFORM_FRACONE) - 1.0f; -} +inline float Saw(ALuint index) +{ return static_cast<float>(index)*(2.0f/WAVEFORM_FRACONE) - 1.0f; } -inline ALfloat Square(ALuint index) -{ - return static_cast<ALfloat>(((index>>(WAVEFORM_FRACBITS-2))&2) - 1); -} +inline float Square(ALuint index) +{ return static_cast<float>(((index>>(WAVEFORM_FRACBITS-2))&2) - 1); } -inline ALfloat One(ALuint) -{ - return 1.0f; -} +inline float One(ALuint) { return 1.0f; } -template<ALfloat func(ALuint)> -void Modulate(ALfloat *RESTRICT dst, ALuint index, const ALuint step, size_t todo) +template<float (&func)(ALuint)> +void Modulate(float *RESTRICT dst, ALuint index, const ALuint step, size_t todo) { for(size_t i{0u};i < todo;i++) { @@ -76,7 +69,7 @@ void Modulate(ALfloat *RESTRICT dst, ALuint index, const ALuint step, size_t tod struct ModulatorState final : public EffectState { - void (*mGetSamples)(ALfloat*RESTRICT, ALuint, const ALuint, size_t){}; + void (*mGetSamples)(float*RESTRICT, ALuint, const ALuint, size_t){}; ALuint mIndex{0}; ALuint mStep{1}; diff --git a/alc/effects/vmorpher.cpp b/alc/effects/vmorpher.cpp index d24d41d6..b1b7cc06 100644 --- a/alc/effects/vmorpher.cpp +++ b/alc/effects/vmorpher.cpp @@ -44,29 +44,22 @@ namespace { #define WAVEFORM_FRACONE (1<<WAVEFORM_FRACBITS) #define WAVEFORM_FRACMASK (WAVEFORM_FRACONE-1) -inline ALfloat Sin(ALuint index) +inline float Sin(ALuint index) { - constexpr ALfloat scale{al::MathDefs<float>::Tau() / ALfloat{WAVEFORM_FRACONE}}; - return std::sin(static_cast<ALfloat>(index) * scale)*0.5f + 0.5f; + constexpr float scale{al::MathDefs<float>::Tau() / WAVEFORM_FRACONE}; + return std::sin(static_cast<float>(index) * scale)*0.5f + 0.5f; } -inline ALfloat Saw(ALuint index) -{ - return static_cast<ALfloat>(index) / ALfloat{WAVEFORM_FRACONE}; -} +inline float Saw(ALuint index) +{ return static_cast<float>(index) / float{WAVEFORM_FRACONE}; } -inline ALfloat Triangle(ALuint index) -{ - return std::fabs(static_cast<ALfloat>(index)*(2.0f/WAVEFORM_FRACONE) - 1.0f); -} +inline float Triangle(ALuint index) +{ return std::fabs(static_cast<float>(index)*(2.0f/WAVEFORM_FRACONE) - 1.0f); } -inline ALfloat Half(ALuint) -{ - return 0.5f; -} +inline float Half(ALuint) { return 0.5f; } -template<ALfloat func(ALuint)> -void Oscillate(ALfloat *RESTRICT dst, ALuint index, const ALuint step, size_t todo) +template<float (&func)(ALuint)> +void Oscillate(float *RESTRICT dst, ALuint index, const ALuint step, size_t todo) { for(size_t i{0u};i < todo;i++) { @@ -133,7 +126,7 @@ struct VmorpherState final : public EffectState { ALfloat TargetGains[MAX_OUTPUT_CHANNELS]{}; } mChans[MAX_AMBI_CHANNELS]; - void (*mGetSamples)(ALfloat* RESTRICT, ALuint, const ALuint, size_t){}; + void (*mGetSamples)(float*RESTRICT, ALuint, const ALuint, size_t){}; ALuint mIndex{0}; ALuint mStep{1}; diff --git a/alc/mixer/mixer_c.cpp b/alc/mixer/mixer_c.cpp index ffc07acd..8d375de7 100644 --- a/alc/mixer/mixer_c.cpp +++ b/alc/mixer/mixer_c.cpp @@ -62,8 +62,8 @@ inline float do_fastbsinc(const InterpState &istate, const float *RESTRICT vals, return r; } -using SamplerT = float(const InterpState&, const float*RESTRICT, const ALuint); -template<SamplerT &Sampler> +using SamplerT = float(&)(const InterpState&, const float*RESTRICT, const ALuint); +template<SamplerT Sampler> const float *DoResample(const InterpState *state, const float *RESTRICT src, ALuint frac, ALuint increment, const al::span<float> dst) { |