diff options
author | Chris Robinson <[email protected]> | 2019-03-28 10:00:35 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-03-28 10:00:35 -0700 |
commit | fe7918465ed203b4731140aaf13c00d2aa9b1041 (patch) | |
tree | 7d63b553174a8f5ccb4c507ab9620b30e6bb968f | |
parent | dfb81ff42de27b474d27e5d9e30c8fbe538db5ca (diff) |
Use a function reference for a template parameter
-rw-r--r-- | Alc/mixer/mixer_c.cpp | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/Alc/mixer/mixer_c.cpp b/Alc/mixer/mixer_c.cpp index 6ee22cfe..ba094999 100644 --- a/Alc/mixer/mixer_c.cpp +++ b/Alc/mixer/mixer_c.cpp @@ -40,6 +40,33 @@ static inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRIC return r; } +using SamplerT = ALfloat(const InterpState&, const ALfloat*RESTRICT, const ALsizei); +template<SamplerT &Sampler> +static const ALfloat *DoResample(const InterpState *state, const ALfloat *RESTRICT src, + ALsizei frac, ALint increment, ALfloat *RESTRICT dst, + ALsizei numsamples) +{ + ASSUME(numsamples > 0); + ASSUME(increment > 0); + ASSUME(frac >= 0); + + const InterpState istate{*state}; + auto proc_sample = [&src,&frac,istate,increment]() -> ALfloat + { + const ALfloat ret{Sampler(istate, src, frac)}; + + frac += increment; + src += frac>>FRACTIONBITS; + frac &= FRACTIONMASK; + + return ret; + }; + std::generate_n<ALfloat*RESTRICT>(dst, numsamples, proc_sample); + + return dst; +} + + template<> const ALfloat *Resample_<CopyTag,CTag>(const InterpState* UNUSED(state), const ALfloat *RESTRICT src, ALsizei UNUSED(frac), ALint UNUSED(increment), @@ -55,31 +82,6 @@ const ALfloat *Resample_<CopyTag,CTag>(const InterpState* UNUSED(state), return dst; } -template<ALfloat Sampler(const InterpState&, const ALfloat*RESTRICT, const ALsizei) noexcept> -static const ALfloat *DoResample(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, ALfloat *RESTRICT dst, - ALsizei numsamples) -{ - ASSUME(numsamples > 0); - ASSUME(increment > 0); - ASSUME(frac >= 0); - - const InterpState istate{*state}; - std::generate_n<ALfloat*RESTRICT>(dst, numsamples, - [&src,&frac,istate,increment]() noexcept -> ALfloat - { - ALfloat ret{Sampler(istate, src, frac)}; - - frac += increment; - src += frac>>FRACTIONBITS; - frac &= FRACTIONMASK; - - return ret; - } - ); - return dst; -} - template<> const ALfloat *Resample_<PointTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen) |