aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-25 10:50:42 -0800
committerChris Robinson <[email protected]>2018-11-25 10:52:17 -0800
commitad2639248a8825cb2dbd0416ebacd840000fd9f0 (patch)
tree725afa91f681b4a77cf89098a2d37a66a0415460 /Alc
parentadcdb8ce64e76a7e772b05fe3be8ce633d29aa90 (diff)
Avoid another DECL_TEMPLATE macro
Diffstat (limited to 'Alc')
-rw-r--r--Alc/mixer/mixer_c.cpp79
-rw-r--r--Alc/mixer/mixer_neon.cpp4
-rw-r--r--Alc/mixer/mixer_sse.cpp2
-rw-r--r--Alc/mixer/mixer_sse2.cpp2
-rw-r--r--Alc/mixer/mixer_sse41.cpp2
5 files changed, 58 insertions, 31 deletions
diff --git a/Alc/mixer/mixer_c.cpp b/Alc/mixer/mixer_c.cpp
index 06e3ae22..99d3e343 100644
--- a/Alc/mixer/mixer_c.cpp
+++ b/Alc/mixer/mixer_c.cpp
@@ -9,13 +9,13 @@
#include "defs.h"
-static inline ALfloat do_point(const InterpState* UNUSED(state), const ALfloat *RESTRICT vals, ALsizei UNUSED(frac))
+static inline ALfloat do_point(const InterpState*, const ALfloat *RESTRICT vals, ALsizei) noexcept
{ return vals[0]; }
-static inline ALfloat do_lerp(const InterpState* UNUSED(state), const ALfloat *RESTRICT vals, ALsizei frac)
+static inline ALfloat do_lerp(const InterpState*, const ALfloat *RESTRICT vals, ALsizei frac) noexcept
{ return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); }
-static inline ALfloat do_cubic(const InterpState* UNUSED(state), const ALfloat *RESTRICT vals, ALsizei frac)
+static inline ALfloat do_cubic(const InterpState*, const ALfloat *RESTRICT vals, ALsizei frac) noexcept
{ return cubic(vals[0], vals[1], vals[2], vals[3], frac * (1.0f/FRACTIONONE)); }
-static inline ALfloat do_bsinc(const InterpState *state, const ALfloat *RESTRICT vals, ALsizei frac)
+static inline ALfloat do_bsinc(const InterpState *state, const ALfloat *RESTRICT vals, ALsizei frac) noexcept
{
const ALfloat *fil, *scd, *phd, *spd;
ALsizei j_f, pi;
@@ -45,43 +45,60 @@ const ALfloat *Resample_copy_C(const InterpState* UNUSED(state),
const ALfloat *RESTRICT src, ALsizei UNUSED(frac), ALint UNUSED(increment),
ALfloat *RESTRICT dst, ALsizei numsamples)
{
+ ASSUME(numsamples > 0);
#if defined(HAVE_SSE) || defined(HAVE_NEON)
/* Avoid copying the source data if it's aligned like the destination. */
if((((intptr_t)src)&15) == (((intptr_t)dst)&15))
return src;
#endif
- memcpy(dst, src, numsamples*sizeof(ALfloat));
+ std::copy_n(src, numsamples, dst);
return dst;
}
-#define DECL_TEMPLATE(Tag, Sampler, O) \
-const ALfloat *Resample_##Tag##_C(const InterpState *state, \
- const ALfloat *RESTRICT src, ALsizei frac, ALint increment, \
- ALfloat *RESTRICT dst, ALsizei numsamples) \
-{ \
- const InterpState istate = *state; \
- ALsizei i; \
- \
- ASSUME(numsamples > 0); \
- \
- src -= O; \
- for(i = 0;i < numsamples;i++) \
- { \
- dst[i] = Sampler(&istate, src, frac); \
- \
- frac += increment; \
- src += frac>>FRACTIONBITS; \
- frac &= FRACTIONMASK; \
- } \
- return dst; \
-}
+template<ALfloat Sampler(const InterpState*, const ALfloat*RESTRICT, 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)};
-DECL_TEMPLATE(point, do_point, 0)
-DECL_TEMPLATE(lerp, do_lerp, 0)
-DECL_TEMPLATE(cubic, do_cubic, 1)
-DECL_TEMPLATE(bsinc, do_bsinc, istate.bsinc.l)
+ frac += increment;
+ src += frac>>FRACTIONBITS;
+ frac &= FRACTIONMASK;
+
+ return ret;
+ }
+ );
+ return dst;
+}
-#undef DECL_TEMPLATE
+const ALfloat *Resample_point_C(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst,
+ ALsizei numsamples)
+{ return DoResample<do_point>(state, src, frac, increment, dst, numsamples); }
+
+const ALfloat *Resample_lerp_C(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst,
+ ALsizei numsamples)
+{ return DoResample<do_lerp>(state, src, frac, increment, dst, numsamples); }
+
+const ALfloat *Resample_cubic_C(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst,
+ ALsizei numsamples)
+{ return DoResample<do_cubic>(state, src-1, frac, increment, dst, numsamples); }
+
+const ALfloat *Resample_bsinc_C(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst,
+ ALsizei numsamples)
+{ return DoResample<do_bsinc>(state, src-state->bsinc.l, frac, increment, dst, numsamples); }
static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*RESTRICT Values)[2],
diff --git a/Alc/mixer/mixer_neon.cpp b/Alc/mixer/mixer_neon.cpp
index b1f219e4..f7fe57d1 100644
--- a/Alc/mixer/mixer_neon.cpp
+++ b/Alc/mixer/mixer_neon.cpp
@@ -22,6 +22,8 @@ const ALfloat *Resample_lerp_Neon(const InterpState* UNUSED(state),
ALsizei todo, pos, i;
ASSUME(numsamples > 0);
+ ASSUME(increment > 0);
+ ASSUME(frac >= 0);
InitiatePositionArrays(frac, increment, frac_, pos_, 4);
frac4 = vld1q_s32(frac_);
@@ -80,6 +82,8 @@ const ALfloat *Resample_bsinc_Neon(const InterpState *state,
ASSUME(m > 0);
ASSUME(dstlen > 0);
+ ASSUME(increment > 0);
+ ASSUME(frac >= 0);
src -= state->bsinc.l;
for(i = 0;i < dstlen;i++)
diff --git a/Alc/mixer/mixer_sse.cpp b/Alc/mixer/mixer_sse.cpp
index 8492a1c8..000196ca 100644
--- a/Alc/mixer/mixer_sse.cpp
+++ b/Alc/mixer/mixer_sse.cpp
@@ -26,6 +26,8 @@ const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *RESTR
ASSUME(m > 0);
ASSUME(dstlen > 0);
+ ASSUME(increment > 0);
+ ASSUME(frac >= 0);
src -= state->bsinc.l;
for(i = 0;i < dstlen;i++)
diff --git a/Alc/mixer/mixer_sse2.cpp b/Alc/mixer/mixer_sse2.cpp
index 2432342f..26fe26ba 100644
--- a/Alc/mixer/mixer_sse2.cpp
+++ b/Alc/mixer/mixer_sse2.cpp
@@ -39,6 +39,8 @@ const ALfloat *Resample_lerp_SSE2(const InterpState* UNUSED(state),
ALsizei todo, pos, i;
ASSUME(numsamples > 0);
+ ASSUME(increment > 0);
+ ASSUME(frac >= 0);
InitiatePositionArrays(frac, increment, frac_, pos_, 4);
frac4 = _mm_setr_epi32(frac_[0], frac_[1], frac_[2], frac_[3]);
diff --git a/Alc/mixer/mixer_sse41.cpp b/Alc/mixer/mixer_sse41.cpp
index 34b405f8..cfda905b 100644
--- a/Alc/mixer/mixer_sse41.cpp
+++ b/Alc/mixer/mixer_sse41.cpp
@@ -40,6 +40,8 @@ const ALfloat *Resample_lerp_SSE41(const InterpState* UNUSED(state),
ALsizei todo, pos, i;
ASSUME(numsamples > 0);
+ ASSUME(increment > 0);
+ ASSUME(frac >= 0);
InitiatePositionArrays(frac, increment, frac_, pos_, 4);
frac4 = _mm_setr_epi32(frac_[0], frac_[1], frac_[2], frac_[3]);