aboutsummaryrefslogtreecommitdiffstats
path: root/alc/mixer
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-07-28 18:56:04 -0700
committerChris Robinson <[email protected]>2019-07-28 18:56:04 -0700
commitcb3e96e75640730b9391f0d2d922eecd9ee2ce79 (patch)
tree23520551bddb2a80354e44da47f54201fdc084f0 /alc/mixer
parent93e60919c8f387c36c267ca9faa1ac653254aea6 (diff)
Rename Alc to alc
Diffstat (limited to 'alc/mixer')
-rw-r--r--alc/mixer/defs.h59
-rw-r--r--alc/mixer/hrtfbase.h138
-rw-r--r--alc/mixer/mixer_c.cpp208
-rw-r--r--alc/mixer/mixer_neon.cpp307
-rw-r--r--alc/mixer/mixer_sse.cpp262
-rw-r--r--alc/mixer/mixer_sse2.cpp84
-rw-r--r--alc/mixer/mixer_sse3.cpp0
-rw-r--r--alc/mixer/mixer_sse41.cpp85
8 files changed, 1143 insertions, 0 deletions
diff --git a/alc/mixer/defs.h b/alc/mixer/defs.h
new file mode 100644
index 00000000..3e5d1125
--- /dev/null
+++ b/alc/mixer/defs.h
@@ -0,0 +1,59 @@
+#ifndef MIXER_DEFS_H
+#define MIXER_DEFS_H
+
+#include "AL/alc.h"
+#include "AL/al.h"
+
+#include "alcmain.h"
+#include "alu.h"
+#include "alspan.h"
+
+
+struct MixGains;
+struct MixHrtfFilter;
+struct HrtfState;
+struct DirectHrtfState;
+
+
+struct CTag { };
+struct SSETag { };
+struct SSE2Tag { };
+struct SSE3Tag { };
+struct SSE4Tag { };
+struct NEONTag { };
+
+struct CopyTag { };
+struct PointTag { };
+struct LerpTag { };
+struct CubicTag { };
+struct BSincTag { };
+
+template<typename TypeTag, typename InstTag>
+const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen);
+
+template<typename InstTag>
+void Mix_(const ALfloat *data, const al::span<FloatBufferLine> OutBuffer, ALfloat *CurrentGains, const ALfloat *TargetGains, const ALsizei Counter, const ALsizei OutPos, const ALsizei BufferSize);
+template<typename InstTag>
+void MixRow_(FloatBufferLine &OutBuffer, const ALfloat *Gains, const al::span<const FloatBufferLine> InSamples, const ALsizei InPos, const ALsizei BufferSize);
+
+template<typename InstTag>
+void MixHrtf_(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, const ALfloat *InSamples, float2 *AccumSamples, const ALsizei OutPos, const ALsizei IrSize, MixHrtfFilter *hrtfparams, const ALsizei BufferSize);
+template<typename InstTag>
+void MixHrtfBlend_(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, const ALfloat *InSamples, float2 *AccumSamples, const ALsizei OutPos, const ALsizei IrSize, const HrtfFilter *oldparams, MixHrtfFilter *newparams, const ALsizei BufferSize);
+template<typename InstTag>
+void MixDirectHrtf_(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples, DirectHrtfState *State, const ALsizei BufferSize);
+
+/* Vectorized resampler helpers */
+inline void InitiatePositionArrays(ALsizei frac, ALint increment, ALsizei *RESTRICT frac_arr, ALsizei *RESTRICT pos_arr, ALsizei size)
+{
+ pos_arr[0] = 0;
+ frac_arr[0] = frac;
+ for(ALsizei i{1};i < size;i++)
+ {
+ ALint frac_tmp = frac_arr[i-1] + increment;
+ pos_arr[i] = pos_arr[i-1] + (frac_tmp>>FRACTIONBITS);
+ frac_arr[i] = frac_tmp&FRACTIONMASK;
+ }
+}
+
+#endif /* MIXER_DEFS_H */
diff --git a/alc/mixer/hrtfbase.h b/alc/mixer/hrtfbase.h
new file mode 100644
index 00000000..a76bd62e
--- /dev/null
+++ b/alc/mixer/hrtfbase.h
@@ -0,0 +1,138 @@
+#ifndef MIXER_HRTFBASE_H
+#define MIXER_HRTFBASE_H
+
+#include <algorithm>
+
+#include "alu.h"
+#include "../hrtf.h"
+#include "opthelpers.h"
+
+
+using ApplyCoeffsT = void(ALsizei Offset, float2 *RESTRICT Values, const ALsizei irSize,
+ const HrirArray<ALfloat> &Coeffs, const ALfloat left, const ALfloat right);
+
+template<ApplyCoeffsT &ApplyCoeffs>
+inline void MixHrtfBase(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
+ const ALfloat *InSamples, float2 *RESTRICT AccumSamples, const ALsizei OutPos,
+ const ALsizei IrSize, MixHrtfFilter *hrtfparams, const ALsizei BufferSize)
+{
+ ASSUME(OutPos >= 0);
+ ASSUME(IrSize >= 4);
+ ASSUME(BufferSize > 0);
+
+ const auto &Coeffs = *hrtfparams->Coeffs;
+ const ALfloat gainstep{hrtfparams->GainStep};
+ const ALfloat gain{hrtfparams->Gain};
+
+ ALsizei Delay[2]{
+ HRTF_HISTORY_LENGTH - hrtfparams->Delay[0],
+ HRTF_HISTORY_LENGTH - hrtfparams->Delay[1] };
+ ASSUME(Delay[0] >= 0 && Delay[1] >= 0);
+ ALfloat stepcount{0.0f};
+ for(ALsizei i{0};i < BufferSize;++i)
+ {
+ const ALfloat g{gain + gainstep*stepcount};
+ const ALfloat left{InSamples[Delay[0]++] * g};
+ const ALfloat right{InSamples[Delay[1]++] * g};
+ ApplyCoeffs(i, AccumSamples+i, IrSize, Coeffs, left, right);
+
+ stepcount += 1.0f;
+ }
+
+ for(ALsizei i{0};i < BufferSize;++i)
+ LeftOut[OutPos+i] += AccumSamples[i][0];
+ for(ALsizei i{0};i < BufferSize;++i)
+ RightOut[OutPos+i] += AccumSamples[i][1];
+
+ hrtfparams->Gain = gain + gainstep*stepcount;
+}
+
+template<ApplyCoeffsT &ApplyCoeffs>
+inline void MixHrtfBlendBase(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
+ const ALfloat *InSamples, float2 *RESTRICT AccumSamples, const ALsizei OutPos,
+ const ALsizei IrSize, const HrtfFilter *oldparams, MixHrtfFilter *newparams,
+ const ALsizei BufferSize)
+{
+ const auto &OldCoeffs = oldparams->Coeffs;
+ const ALfloat oldGain{oldparams->Gain};
+ const ALfloat oldGainStep{-oldGain / static_cast<ALfloat>(BufferSize)};
+ const auto &NewCoeffs = *newparams->Coeffs;
+ const ALfloat newGainStep{newparams->GainStep};
+
+ ASSUME(OutPos >= 0);
+ ASSUME(IrSize >= 4);
+ ASSUME(BufferSize > 0);
+
+ ALsizei Delay[2]{
+ HRTF_HISTORY_LENGTH - oldparams->Delay[0],
+ HRTF_HISTORY_LENGTH - oldparams->Delay[1] };
+ ASSUME(Delay[0] >= 0 && Delay[1] >= 0);
+ ALfloat stepcount{0.0f};
+ for(ALsizei i{0};i < BufferSize;++i)
+ {
+ const ALfloat g{oldGain + oldGainStep*stepcount};
+ const ALfloat left{InSamples[Delay[0]++] * g};
+ const ALfloat right{InSamples[Delay[1]++] * g};
+ ApplyCoeffs(i, AccumSamples+i, IrSize, OldCoeffs, left, right);
+
+ stepcount += 1.0f;
+ }
+
+ Delay[0] = HRTF_HISTORY_LENGTH - newparams->Delay[0];
+ Delay[1] = HRTF_HISTORY_LENGTH - newparams->Delay[1];
+ ASSUME(Delay[0] >= 0 && Delay[1] >= 0);
+ stepcount = 0.0f;
+ for(ALsizei i{0};i < BufferSize;++i)
+ {
+ const ALfloat g{newGainStep*stepcount};
+ const ALfloat left{InSamples[Delay[0]++] * g};
+ const ALfloat right{InSamples[Delay[1]++] * g};
+ ApplyCoeffs(i, AccumSamples+i, IrSize, NewCoeffs, left, right);
+
+ stepcount += 1.0f;
+ }
+
+ for(ALsizei i{0};i < BufferSize;++i)
+ LeftOut[OutPos+i] += AccumSamples[i][0];
+ for(ALsizei i{0};i < BufferSize;++i)
+ RightOut[OutPos+i] += AccumSamples[i][1];
+
+ newparams->Gain = newGainStep*stepcount;
+}
+
+template<ApplyCoeffsT &ApplyCoeffs>
+inline void MixDirectHrtfBase(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
+ const al::span<const FloatBufferLine> InSamples, float2 *RESTRICT AccumSamples,
+ DirectHrtfState *State, const ALsizei BufferSize)
+{
+ ASSUME(BufferSize > 0);
+
+ const ALsizei IrSize{State->IrSize};
+ ASSUME(IrSize >= 4);
+
+ auto chanstate = State->Chan.begin();
+ for(const FloatBufferLine &input : InSamples)
+ {
+ const auto &Coeffs = chanstate->Coeffs;
+
+ auto accum_iter = std::copy_n(chanstate->Values.begin(),
+ chanstate->Values.size(), AccumSamples);
+ std::fill_n(accum_iter, BufferSize, float2{});
+
+ for(ALsizei i{0};i < BufferSize;++i)
+ {
+ const ALfloat insample{input[i]};
+ ApplyCoeffs(i, AccumSamples+i, IrSize, Coeffs, insample, insample);
+ }
+ for(ALsizei i{0};i < BufferSize;++i)
+ LeftOut[i] += AccumSamples[i][0];
+ for(ALsizei i{0};i < BufferSize;++i)
+ RightOut[i] += AccumSamples[i][1];
+
+ std::copy_n(AccumSamples + BufferSize, chanstate->Values.size(),
+ chanstate->Values.begin());
+ ++chanstate;
+ }
+}
+
+#endif /* MIXER_HRTFBASE_H */
diff --git a/alc/mixer/mixer_c.cpp b/alc/mixer/mixer_c.cpp
new file mode 100644
index 00000000..47c4a6f4
--- /dev/null
+++ b/alc/mixer/mixer_c.cpp
@@ -0,0 +1,208 @@
+#include "config.h"
+
+#include <cassert>
+
+#include <limits>
+
+#include "alcmain.h"
+#include "alu.h"
+#include "alSource.h"
+#include "alAuxEffectSlot.h"
+#include "defs.h"
+#include "hrtfbase.h"
+
+
+namespace {
+
+inline ALfloat do_point(const InterpState&, const ALfloat *RESTRICT vals, const ALsizei)
+{ return vals[0]; }
+inline ALfloat do_lerp(const InterpState&, const ALfloat *RESTRICT vals, const ALsizei frac)
+{ return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); }
+inline ALfloat do_cubic(const InterpState&, const ALfloat *RESTRICT vals, const ALsizei frac)
+{ return cubic(vals[0], vals[1], vals[2], vals[3], frac * (1.0f/FRACTIONONE)); }
+inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRICT vals, const ALsizei frac)
+{
+ ASSUME(istate.bsinc.m > 0);
+
+ // Calculate the phase index and factor.
+#define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS)
+ const ALsizei pi{frac >> FRAC_PHASE_BITDIFF};
+ const ALfloat pf{(frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF))};
+#undef FRAC_PHASE_BITDIFF
+
+ const ALfloat *fil{istate.bsinc.filter + istate.bsinc.m*pi*4};
+ const ALfloat *scd{fil + istate.bsinc.m};
+ const ALfloat *phd{scd + istate.bsinc.m};
+ const ALfloat *spd{phd + istate.bsinc.m};
+
+ // Apply the scale and phase interpolated filter.
+ ALfloat r{0.0f};
+ for(ALsizei j_f{0};j_f < istate.bsinc.m;j_f++)
+ r += (fil[j_f] + istate.bsinc.sf*scd[j_f] + pf*(phd[j_f] + istate.bsinc.sf*spd[j_f])) * vals[j_f];
+ return r;
+}
+
+using SamplerT = ALfloat(const InterpState&, const ALfloat*RESTRICT, const ALsizei);
+template<SamplerT &Sampler>
+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(dst, numsamples, proc_sample);
+
+ return dst;
+}
+
+} // namespace
+
+template<>
+const ALfloat *Resample_<CopyTag,CTag>(const InterpState*, const ALfloat *RESTRICT src, ALsizei,
+ ALint, ALfloat *RESTRICT dst, ALsizei dstlen)
+{
+ ASSUME(dstlen > 0);
+#if defined(HAVE_SSE) || defined(HAVE_NEON)
+ /* Avoid copying the source data if it's aligned like the destination. */
+ if((reinterpret_cast<intptr_t>(src)&15) == (reinterpret_cast<intptr_t>(dst)&15))
+ return src;
+#endif
+ std::copy_n(src, dstlen, dst);
+ return dst;
+}
+
+template<>
+const ALfloat *Resample_<PointTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
+{ return DoResample<do_point>(state, src, frac, increment, dst, dstlen); }
+
+template<>
+const ALfloat *Resample_<LerpTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
+{ return DoResample<do_lerp>(state, src, frac, increment, dst, dstlen); }
+
+template<>
+const ALfloat *Resample_<CubicTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
+{ return DoResample<do_cubic>(state, src-1, frac, increment, dst, dstlen); }
+
+template<>
+const ALfloat *Resample_<BSincTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
+{ return DoResample<do_bsinc>(state, src-state->bsinc.l, frac, increment, dst, dstlen); }
+
+
+static inline void ApplyCoeffs(ALsizei /*Offset*/, float2 *RESTRICT Values, const ALsizei IrSize,
+ const HrirArray<ALfloat> &Coeffs, const ALfloat left, const ALfloat right)
+{
+ ASSUME(IrSize >= 2);
+ for(ALsizei c{0};c < IrSize;++c)
+ {
+ Values[c][0] += Coeffs[c][0] * left;
+ Values[c][1] += Coeffs[c][1] * right;
+ }
+}
+
+template<>
+void MixHrtf_<CTag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
+ const ALfloat *InSamples, float2 *AccumSamples, const ALsizei OutPos, const ALsizei IrSize,
+ MixHrtfFilter *hrtfparams, const ALsizei BufferSize)
+{
+ MixHrtfBase<ApplyCoeffs>(LeftOut, RightOut, InSamples, AccumSamples, OutPos, IrSize,
+ hrtfparams, BufferSize);
+}
+
+template<>
+void MixHrtfBlend_<CTag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
+ const ALfloat *InSamples, float2 *AccumSamples, const ALsizei OutPos, const ALsizei IrSize,
+ const HrtfFilter *oldparams, MixHrtfFilter *newparams, const ALsizei BufferSize)
+{
+ MixHrtfBlendBase<ApplyCoeffs>(LeftOut, RightOut, InSamples, AccumSamples, OutPos, IrSize,
+ oldparams, newparams, BufferSize);
+}
+
+template<>
+void MixDirectHrtf_<CTag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
+ const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples, DirectHrtfState *State,
+ const ALsizei BufferSize)
+{
+ MixDirectHrtfBase<ApplyCoeffs>(LeftOut, RightOut, InSamples, AccumSamples, State, BufferSize);
+}
+
+
+template<>
+void Mix_<CTag>(const ALfloat *data, const al::span<FloatBufferLine> OutBuffer,
+ ALfloat *CurrentGains, const ALfloat *TargetGains, const ALsizei Counter, const ALsizei OutPos,
+ const ALsizei BufferSize)
+{
+ ASSUME(BufferSize > 0);
+
+ const ALfloat delta{(Counter > 0) ? 1.0f / static_cast<ALfloat>(Counter) : 0.0f};
+ for(FloatBufferLine &output : OutBuffer)
+ {
+ ALfloat *RESTRICT dst{output.data()+OutPos};
+ ALfloat gain{*CurrentGains};
+ const ALfloat diff{*TargetGains - gain};
+
+ ALsizei pos{0};
+ if(std::fabs(diff) > std::numeric_limits<float>::epsilon())
+ {
+ ALsizei minsize{mini(BufferSize, Counter)};
+ const ALfloat step{diff * delta};
+ ALfloat step_count{0.0f};
+ for(;pos < minsize;pos++)
+ {
+ dst[pos] += data[pos] * (gain + step*step_count);
+ step_count += 1.0f;
+ }
+ if(pos == Counter)
+ gain = *TargetGains;
+ else
+ gain += step*step_count;
+ *CurrentGains = gain;
+ }
+ ++CurrentGains;
+ ++TargetGains;
+
+ if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+ for(;pos < BufferSize;pos++)
+ dst[pos] += data[pos]*gain;
+ }
+}
+
+/* Basically the inverse of the above. Rather than one input going to multiple
+ * outputs (each with its own gain), it's multiple inputs (each with its own
+ * gain) going to one output. This applies one row (vs one column) of a matrix
+ * transform. And as the matrices are more or less static once set up, no
+ * stepping is necessary.
+ */
+template<>
+void MixRow_<CTag>(FloatBufferLine &OutBuffer, const ALfloat *Gains,
+ const al::span<const FloatBufferLine> InSamples, const ALsizei InPos, const ALsizei BufferSize)
+{
+ ASSUME(BufferSize > 0);
+
+ for(const FloatBufferLine &input : InSamples)
+ {
+ const ALfloat *RESTRICT src{input.data()+InPos};
+ const ALfloat gain{*(Gains++)};
+ if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+
+ for(ALsizei i{0};i < BufferSize;i++)
+ OutBuffer[i] += src[i] * gain;
+ }
+}
diff --git a/alc/mixer/mixer_neon.cpp b/alc/mixer/mixer_neon.cpp
new file mode 100644
index 00000000..fa487d97
--- /dev/null
+++ b/alc/mixer/mixer_neon.cpp
@@ -0,0 +1,307 @@
+#include "config.h"
+
+#include <arm_neon.h>
+
+#include <limits>
+
+#include "AL/al.h"
+#include "AL/alc.h"
+#include "alcmain.h"
+#include "alu.h"
+#include "hrtf.h"
+#include "defs.h"
+#include "hrtfbase.h"
+
+
+
+template<>
+const ALfloat *Resample_<LerpTag,NEONTag>(const InterpState*, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
+{
+ const int32x4_t increment4 = vdupq_n_s32(increment*4);
+ const float32x4_t fracOne4 = vdupq_n_f32(1.0f/FRACTIONONE);
+ const int32x4_t fracMask4 = vdupq_n_s32(FRACTIONMASK);
+ alignas(16) ALsizei pos_[4], frac_[4];
+ int32x4_t pos4, frac4;
+ ALsizei todo, pos, i;
+
+ ASSUME(frac >= 0);
+ ASSUME(increment > 0);
+ ASSUME(dstlen > 0);
+
+ InitiatePositionArrays(frac, increment, frac_, pos_, 4);
+ frac4 = vld1q_s32(frac_);
+ pos4 = vld1q_s32(pos_);
+
+ todo = dstlen & ~3;
+ for(i = 0;i < todo;i += 4)
+ {
+ const int pos0 = vgetq_lane_s32(pos4, 0);
+ const int pos1 = vgetq_lane_s32(pos4, 1);
+ const int pos2 = vgetq_lane_s32(pos4, 2);
+ const int pos3 = vgetq_lane_s32(pos4, 3);
+ const float32x4_t val1 = (float32x4_t){src[pos0], src[pos1], src[pos2], src[pos3]};
+ const float32x4_t val2 = (float32x4_t){src[pos0+1], src[pos1+1], src[pos2+1], src[pos3+1]};
+
+ /* val1 + (val2-val1)*mu */
+ const float32x4_t r0 = vsubq_f32(val2, val1);
+ const float32x4_t mu = vmulq_f32(vcvtq_f32_s32(frac4), fracOne4);
+ const float32x4_t out = vmlaq_f32(val1, mu, r0);
+
+ vst1q_f32(&dst[i], out);
+
+ frac4 = vaddq_s32(frac4, increment4);
+ pos4 = vaddq_s32(pos4, vshrq_n_s32(frac4, FRACTIONBITS));
+ frac4 = vandq_s32(frac4, fracMask4);
+ }
+
+ /* NOTE: These four elements represent the position *after* the last four
+ * samples, so the lowest element is the next position to resample.
+ */
+ pos = vgetq_lane_s32(pos4, 0);
+ frac = vgetq_lane_s32(frac4, 0);
+
+ for(;i < dstlen;++i)
+ {
+ dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE));
+
+ frac += increment;
+ pos += frac>>FRACTIONBITS;
+ frac &= FRACTIONMASK;
+ }
+ return dst;
+}
+
+template<>
+const ALfloat *Resample_<BSincTag,NEONTag>(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
+{
+ const ALfloat *const filter = state->bsinc.filter;
+ const float32x4_t sf4 = vdupq_n_f32(state->bsinc.sf);
+ const ALsizei m = state->bsinc.m;
+ const float32x4_t *fil, *scd, *phd, *spd;
+ ALsizei pi, i, j, offset;
+ float32x4_t r4;
+ ALfloat pf;
+
+ ASSUME(m > 0);
+ ASSUME(dstlen > 0);
+ ASSUME(increment > 0);
+ ASSUME(frac >= 0);
+
+ src -= state->bsinc.l;
+ for(i = 0;i < dstlen;i++)
+ {
+ // Calculate the phase index and factor.
+#define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS)
+ pi = frac >> FRAC_PHASE_BITDIFF;
+ pf = (frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF));
+#undef FRAC_PHASE_BITDIFF
+
+ offset = m*pi*4;
+ fil = (const float32x4_t*)(filter + offset); offset += m;
+ scd = (const float32x4_t*)(filter + offset); offset += m;
+ phd = (const float32x4_t*)(filter + offset); offset += m;
+ spd = (const float32x4_t*)(filter + offset);
+
+ // Apply the scale and phase interpolated filter.
+ r4 = vdupq_n_f32(0.0f);
+ {
+ const ALsizei count = m >> 2;
+ const float32x4_t pf4 = vdupq_n_f32(pf);
+
+ ASSUME(count > 0);
+
+ for(j = 0;j < count;j++)
+ {
+ /* f = ((fil + sf*scd) + pf*(phd + sf*spd)) */
+ const float32x4_t f4 = vmlaq_f32(
+ vmlaq_f32(fil[j], sf4, scd[j]),
+ pf4, vmlaq_f32(phd[j], sf4, spd[j])
+ );
+ /* r += f*src */
+ r4 = vmlaq_f32(r4, f4, vld1q_f32(&src[j*4]));
+ }
+ }
+ r4 = vaddq_f32(r4, vcombine_f32(vrev64_f32(vget_high_f32(r4)),
+ vrev64_f32(vget_low_f32(r4))));
+ dst[i] = vget_lane_f32(vadd_f32(vget_low_f32(r4), vget_high_f32(r4)), 0);
+
+ frac += increment;
+ src += frac>>FRACTIONBITS;
+ frac &= FRACTIONMASK;
+ }
+ return dst;
+}
+
+
+static inline void ApplyCoeffs(ALsizei /*Offset*/, float2 *RESTRICT Values, const ALsizei IrSize,
+ const HrirArray<ALfloat> &Coeffs, const ALfloat left, const ALfloat right)
+{
+ ASSUME(IrSize >= 2);
+
+ float32x4_t leftright4;
+ {
+ float32x2_t leftright2 = vdup_n_f32(0.0);
+ leftright2 = vset_lane_f32(left, leftright2, 0);
+ leftright2 = vset_lane_f32(right, leftright2, 1);
+ leftright4 = vcombine_f32(leftright2, leftright2);
+ }
+
+ for(ALsizei c{0};c < IrSize;c += 2)
+ {
+ float32x4_t vals = vcombine_f32(vld1_f32((float32_t*)&Values[c ][0]),
+ vld1_f32((float32_t*)&Values[c+1][0]));
+ float32x4_t coefs = vld1q_f32((float32_t*)&Coeffs[c][0]);
+
+ vals = vmlaq_f32(vals, coefs, leftright4);
+
+ vst1_f32((float32_t*)&Values[c ][0], vget_low_f32(vals));
+ vst1_f32((float32_t*)&Values[c+1][0], vget_high_f32(vals));
+ }
+}
+
+template<>
+void MixHrtf_<NEONTag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
+ const ALfloat *InSamples, float2 *AccumSamples, const ALsizei OutPos, const ALsizei IrSize,
+ MixHrtfFilter *hrtfparams, const ALsizei BufferSize)
+{
+ MixHrtfBase<ApplyCoeffs>(LeftOut, RightOut, InSamples, AccumSamples, OutPos, IrSize,
+ hrtfparams, BufferSize);
+}
+
+template<>
+void MixHrtfBlend_<NEONTag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
+ const ALfloat *InSamples, float2 *AccumSamples, const ALsizei OutPos, const ALsizei IrSize,
+ const HrtfFilter *oldparams, MixHrtfFilter *newparams, const ALsizei BufferSize)
+{
+ MixHrtfBlendBase<ApplyCoeffs>(LeftOut, RightOut, InSamples, AccumSamples, OutPos, IrSize,
+ oldparams, newparams, BufferSize);
+}
+
+template<>
+void MixDirectHrtf_<NEONTag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
+ const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples, DirectHrtfState *State,
+ const ALsizei BufferSize)
+{
+ MixDirectHrtfBase<ApplyCoeffs>(LeftOut, RightOut, InSamples, AccumSamples, State, BufferSize);
+}
+
+
+template<>
+void Mix_<NEONTag>(const ALfloat *data, const al::span<FloatBufferLine> OutBuffer,
+ ALfloat *CurrentGains, const ALfloat *TargetGains, const ALsizei Counter, const ALsizei OutPos,
+ const ALsizei BufferSize)
+{
+ ASSUME(BufferSize > 0);
+
+ const ALfloat delta{(Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f};
+ for(FloatBufferLine &output : OutBuffer)
+ {
+ ALfloat *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)};
+ ALfloat gain{*CurrentGains};
+ const ALfloat diff{*TargetGains - gain};
+
+ ALsizei pos{0};
+ if(std::fabs(diff) > std::numeric_limits<float>::epsilon())
+ {
+ ALsizei minsize{mini(BufferSize, Counter)};
+ const ALfloat step{diff * delta};
+ ALfloat step_count{0.0f};
+ /* Mix with applying gain steps in aligned multiples of 4. */
+ if(LIKELY(minsize > 3))
+ {
+ const float32x4_t four4{vdupq_n_f32(4.0f)};
+ const float32x4_t step4{vdupq_n_f32(step)};
+ const float32x4_t gain4{vdupq_n_f32(gain)};
+ float32x4_t step_count4{vsetq_lane_f32(0.0f,
+ vsetq_lane_f32(1.0f,
+ vsetq_lane_f32(2.0f,
+ vsetq_lane_f32(3.0f, vdupq_n_f32(0.0f), 3),
+ 2), 1), 0
+ )};
+ ALsizei todo{minsize >> 2};
+
+ do {
+ const float32x4_t val4 = vld1q_f32(&data[pos]);
+ float32x4_t dry4 = vld1q_f32(&dst[pos]);
+ dry4 = vmlaq_f32(dry4, val4, vmlaq_f32(gain4, step4, step_count4));
+ step_count4 = vaddq_f32(step_count4, four4);
+ vst1q_f32(&dst[pos], dry4);
+ pos += 4;
+ } while(--todo);
+ /* NOTE: step_count4 now represents the next four counts after
+ * the last four mixed samples, so the lowest element
+ * represents the next step count to apply.
+ */
+ step_count = vgetq_lane_f32(step_count4, 0);
+ }
+ /* Mix with applying left over gain steps that aren't aligned multiples of 4. */
+ for(;pos < minsize;pos++)
+ {
+ dst[pos] += data[pos]*(gain + step*step_count);
+ step_count += 1.0f;
+ }
+ if(pos == Counter)
+ gain = *TargetGains;
+ else
+ gain += step*step_count;
+ *CurrentGains = gain;
+
+ /* Mix until pos is aligned with 4 or the mix is done. */
+ minsize = mini(BufferSize, (pos+3)&~3);
+ for(;pos < minsize;pos++)
+ dst[pos] += data[pos]*gain;
+ }
+ ++CurrentGains;
+ ++TargetGains;
+
+ if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+ if(LIKELY(BufferSize-pos > 3))
+ {
+ ALsizei todo{(BufferSize-pos) >> 2};
+ const float32x4_t gain4 = vdupq_n_f32(gain);
+ do {
+ const float32x4_t val4 = vld1q_f32(&data[pos]);
+ float32x4_t dry4 = vld1q_f32(&dst[pos]);
+ dry4 = vmlaq_f32(dry4, val4, gain4);
+ vst1q_f32(&dst[pos], dry4);
+ pos += 4;
+ } while(--todo);
+ }
+ for(;pos < BufferSize;pos++)
+ dst[pos] += data[pos]*gain;
+ }
+}
+
+template<>
+void MixRow_<NEONTag>(FloatBufferLine &OutBuffer, const ALfloat *Gains,
+ const al::span<const FloatBufferLine> InSamples, const ALsizei InPos, const ALsizei BufferSize)
+{
+ ASSUME(BufferSize > 0);
+
+ for(const FloatBufferLine &input : InSamples)
+ {
+ const ALfloat *RESTRICT src{al::assume_aligned<16>(input.data()+InPos)};
+ const ALfloat gain{*(Gains++)};
+ if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+
+ ALsizei pos{0};
+ if(LIKELY(BufferSize > 3))
+ {
+ ALsizei todo{BufferSize >> 2};
+ float32x4_t gain4{vdupq_n_f32(gain)};
+ do {
+ const float32x4_t val4 = vld1q_f32(&src[pos]);
+ float32x4_t dry4 = vld1q_f32(&OutBuffer[pos]);
+ dry4 = vmlaq_f32(dry4, val4, gain4);
+ vst1q_f32(&OutBuffer[pos], dry4);
+ pos += 4;
+ } while(--todo);
+ }
+ for(;pos < BufferSize;pos++)
+ OutBuffer[pos] += src[pos]*gain;
+ }
+}
diff --git a/alc/mixer/mixer_sse.cpp b/alc/mixer/mixer_sse.cpp
new file mode 100644
index 00000000..b763fdbd
--- /dev/null
+++ b/alc/mixer/mixer_sse.cpp
@@ -0,0 +1,262 @@
+#include "config.h"
+
+#include <xmmintrin.h>
+
+#include <limits>
+
+#include "AL/al.h"
+#include "AL/alc.h"
+#include "alcmain.h"
+#include "alu.h"
+
+#include "alSource.h"
+#include "alAuxEffectSlot.h"
+#include "defs.h"
+#include "hrtfbase.h"
+
+
+template<>
+const ALfloat *Resample_<BSincTag,SSETag>(const InterpState *state, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
+{
+ const ALfloat *const filter{state->bsinc.filter};
+ const __m128 sf4{_mm_set1_ps(state->bsinc.sf)};
+ const ALsizei m{state->bsinc.m};
+
+ ASSUME(m > 0);
+ ASSUME(dstlen > 0);
+ ASSUME(increment > 0);
+ ASSUME(frac >= 0);
+
+ src -= state->bsinc.l;
+ for(ALsizei i{0};i < dstlen;i++)
+ {
+ // Calculate the phase index and factor.
+#define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS)
+ const ALsizei pi{frac >> FRAC_PHASE_BITDIFF};
+ const ALfloat pf{(frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF))};
+#undef FRAC_PHASE_BITDIFF
+
+ ALsizei offset{m*pi*4};
+ const __m128 *fil{reinterpret_cast<const __m128*>(filter + offset)}; offset += m;
+ const __m128 *scd{reinterpret_cast<const __m128*>(filter + offset)}; offset += m;
+ const __m128 *phd{reinterpret_cast<const __m128*>(filter + offset)}; offset += m;
+ const __m128 *spd{reinterpret_cast<const __m128*>(filter + offset)};
+
+ // Apply the scale and phase interpolated filter.
+ __m128 r4{_mm_setzero_ps()};
+ {
+ const ALsizei count{m >> 2};
+ const __m128 pf4{_mm_set1_ps(pf)};
+
+ ASSUME(count > 0);
+
+#define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z))
+ for(ALsizei j{0};j < count;j++)
+ {
+ /* f = ((fil + sf*scd) + pf*(phd + sf*spd)) */
+ const __m128 f4 = MLA4(
+ MLA4(fil[j], sf4, scd[j]),
+ pf4, MLA4(phd[j], sf4, spd[j])
+ );
+ /* r += f*src */
+ r4 = MLA4(r4, f4, _mm_loadu_ps(&src[j*4]));
+ }
+#undef MLA4
+ }
+ r4 = _mm_add_ps(r4, _mm_shuffle_ps(r4, r4, _MM_SHUFFLE(0, 1, 2, 3)));
+ r4 = _mm_add_ps(r4, _mm_movehl_ps(r4, r4));
+ dst[i] = _mm_cvtss_f32(r4);
+
+ frac += increment;
+ src += frac>>FRACTIONBITS;
+ frac &= FRACTIONMASK;
+ }
+ return dst;
+}
+
+
+static inline void ApplyCoeffs(ALsizei Offset, float2 *RESTRICT Values, const ALsizei IrSize,
+ const HrirArray<ALfloat> &Coeffs, const ALfloat left, const ALfloat right)
+{
+ const __m128 lrlr{_mm_setr_ps(left, right, left, right)};
+
+ ASSUME(IrSize >= 2);
+
+ if((Offset&1))
+ {
+ __m128 imp0, imp1;
+ __m128 coeffs{_mm_load_ps(&Coeffs[0][0])};
+ __m128 vals{_mm_loadl_pi(_mm_setzero_ps(), reinterpret_cast<__m64*>(&Values[0][0]))};
+ imp0 = _mm_mul_ps(lrlr, coeffs);
+ vals = _mm_add_ps(imp0, vals);
+ _mm_storel_pi(reinterpret_cast<__m64*>(&Values[0][0]), vals);
+ ALsizei i{1};
+ for(;i < IrSize-1;i += 2)
+ {
+ coeffs = _mm_load_ps(&Coeffs[i+1][0]);
+ vals = _mm_load_ps(&Values[i][0]);
+ imp1 = _mm_mul_ps(lrlr, coeffs);
+ imp0 = _mm_shuffle_ps(imp0, imp1, _MM_SHUFFLE(1, 0, 3, 2));
+ vals = _mm_add_ps(imp0, vals);
+ _mm_store_ps(&Values[i][0], vals);
+ imp0 = imp1;
+ }
+ vals = _mm_loadl_pi(vals, reinterpret_cast<__m64*>(&Values[i][0]));
+ imp0 = _mm_movehl_ps(imp0, imp0);
+ vals = _mm_add_ps(imp0, vals);
+ _mm_storel_pi(reinterpret_cast<__m64*>(&Values[i][0]), vals);
+ }
+ else
+ {
+ for(ALsizei i{0};i < IrSize;i += 2)
+ {
+ __m128 coeffs{_mm_load_ps(&Coeffs[i][0])};
+ __m128 vals{_mm_load_ps(&Values[i][0])};
+ vals = _mm_add_ps(vals, _mm_mul_ps(lrlr, coeffs));
+ _mm_store_ps(&Values[i][0], vals);
+ }
+ }
+}
+
+template<>
+void MixHrtf_<SSETag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
+ const ALfloat *InSamples, float2 *AccumSamples, const ALsizei OutPos, const ALsizei IrSize,
+ MixHrtfFilter *hrtfparams, const ALsizei BufferSize)
+{
+ MixHrtfBase<ApplyCoeffs>(LeftOut, RightOut, InSamples, AccumSamples, OutPos, IrSize,
+ hrtfparams, BufferSize);
+}
+
+template<>
+void MixHrtfBlend_<SSETag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
+ const ALfloat *InSamples, float2 *AccumSamples, const ALsizei OutPos, const ALsizei IrSize,
+ const HrtfFilter *oldparams, MixHrtfFilter *newparams, const ALsizei BufferSize)
+{
+ MixHrtfBlendBase<ApplyCoeffs>(LeftOut, RightOut, InSamples, AccumSamples, OutPos, IrSize,
+ oldparams, newparams, BufferSize);
+}
+
+template<>
+void MixDirectHrtf_<SSETag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
+ const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples, DirectHrtfState *State,
+ const ALsizei BufferSize)
+{
+ MixDirectHrtfBase<ApplyCoeffs>(LeftOut, RightOut, InSamples, AccumSamples, State, BufferSize);
+}
+
+
+template<>
+void Mix_<SSETag>(const ALfloat *data, const al::span<FloatBufferLine> OutBuffer,
+ ALfloat *CurrentGains, const ALfloat *TargetGains, const ALsizei Counter, const ALsizei OutPos,
+ const ALsizei BufferSize)
+{
+ ASSUME(BufferSize > 0);
+
+ const ALfloat delta{(Counter > 0) ? 1.0f / static_cast<ALfloat>(Counter) : 0.0f};
+ for(FloatBufferLine &output : OutBuffer)
+ {
+ ALfloat *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)};
+ ALfloat gain{*CurrentGains};
+ const ALfloat diff{*TargetGains - gain};
+
+ ALsizei pos{0};
+ if(std::fabs(diff) > std::numeric_limits<float>::epsilon())
+ {
+ ALsizei minsize{mini(BufferSize, Counter)};
+ const ALfloat step{diff * delta};
+ ALfloat step_count{0.0f};
+ /* Mix with applying gain steps in aligned multiples of 4. */
+ if(LIKELY(minsize > 3))
+ {
+ const __m128 four4{_mm_set1_ps(4.0f)};
+ const __m128 step4{_mm_set1_ps(step)};
+ const __m128 gain4{_mm_set1_ps(gain)};
+ __m128 step_count4{_mm_setr_ps(0.0f, 1.0f, 2.0f, 3.0f)};
+ ALsizei todo{minsize >> 2};
+ do {
+ const __m128 val4{_mm_load_ps(&data[pos])};
+ __m128 dry4{_mm_load_ps(&dst[pos])};
+#define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z))
+ /* dry += val * (gain + step*step_count) */
+ dry4 = MLA4(dry4, val4, MLA4(gain4, step4, step_count4));
+#undef MLA4
+ _mm_store_ps(&dst[pos], dry4);
+ step_count4 = _mm_add_ps(step_count4, four4);
+ pos += 4;
+ } while(--todo);
+ /* NOTE: step_count4 now represents the next four counts after
+ * the last four mixed samples, so the lowest element
+ * represents the next step count to apply.
+ */
+ step_count = _mm_cvtss_f32(step_count4);
+ }
+ /* Mix with applying left over gain steps that aren't aligned multiples of 4. */
+ for(;pos < minsize;pos++)
+ {
+ dst[pos] += data[pos]*(gain + step*step_count);
+ step_count += 1.0f;
+ }
+ if(pos == Counter)
+ gain = *TargetGains;
+ else
+ gain += step*step_count;
+ *CurrentGains = gain;
+
+ /* Mix until pos is aligned with 4 or the mix is done. */
+ minsize = mini(BufferSize, (pos+3)&~3);
+ for(;pos < minsize;pos++)
+ dst[pos] += data[pos]*gain;
+ }
+ ++CurrentGains;
+ ++TargetGains;
+
+ if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+ if(LIKELY(BufferSize-pos > 3))
+ {
+ ALsizei todo{(BufferSize-pos) >> 2};
+ const __m128 gain4{_mm_set1_ps(gain)};
+ do {
+ const __m128 val4{_mm_load_ps(&data[pos])};
+ __m128 dry4{_mm_load_ps(&dst[pos])};
+ dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4));
+ _mm_store_ps(&dst[pos], dry4);
+ pos += 4;
+ } while(--todo);
+ }
+ for(;pos < BufferSize;pos++)
+ dst[pos] += data[pos]*gain;
+ }
+}
+
+template<>
+void MixRow_<SSETag>(FloatBufferLine &OutBuffer, const ALfloat *Gains,
+ const al::span<const FloatBufferLine> InSamples, const ALsizei InPos, const ALsizei BufferSize)
+{
+ ASSUME(BufferSize > 0);
+
+ for(const FloatBufferLine &input : InSamples)
+ {
+ const ALfloat *RESTRICT src{al::assume_aligned<16>(input.data()+InPos)};
+ const ALfloat gain{*(Gains++)};
+ if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+
+ ALsizei pos{0};
+ if(LIKELY(BufferSize > 3))
+ {
+ ALsizei todo{BufferSize >> 2};
+ const __m128 gain4 = _mm_set1_ps(gain);
+ do {
+ const __m128 val4{_mm_load_ps(&src[pos])};
+ __m128 dry4{_mm_load_ps(&OutBuffer[pos])};
+ dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4));
+ _mm_store_ps(&OutBuffer[pos], dry4);
+ pos += 4;
+ } while(--todo);
+ }
+ for(;pos < BufferSize;pos++)
+ OutBuffer[pos] += src[pos]*gain;
+ }
+}
diff --git a/alc/mixer/mixer_sse2.cpp b/alc/mixer/mixer_sse2.cpp
new file mode 100644
index 00000000..b5d00106
--- /dev/null
+++ b/alc/mixer/mixer_sse2.cpp
@@ -0,0 +1,84 @@
+/**
+ * OpenAL cross platform audio library
+ * Copyright (C) 2014 by Timothy Arceri <[email protected]>.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * Or go to http://www.gnu.org/copyleft/lgpl.html
+ */
+
+#include "config.h"
+
+#include <xmmintrin.h>
+#include <emmintrin.h>
+
+#include "alu.h"
+#include "defs.h"
+
+
+template<>
+const ALfloat *Resample_<LerpTag,SSE2Tag>(const InterpState*, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
+{
+ const __m128i increment4{_mm_set1_epi32(increment*4)};
+ const __m128 fracOne4{_mm_set1_ps(1.0f/FRACTIONONE)};
+ const __m128i fracMask4{_mm_set1_epi32(FRACTIONMASK)};
+
+ ASSUME(frac > 0);
+ ASSUME(increment > 0);
+ ASSUME(dstlen >= 0);
+
+ alignas(16) ALsizei pos_[4], frac_[4];
+ InitiatePositionArrays(frac, increment, frac_, pos_, 4);
+ __m128i frac4{_mm_setr_epi32(frac_[0], frac_[1], frac_[2], frac_[3])};
+ __m128i pos4{_mm_setr_epi32(pos_[0], pos_[1], pos_[2], pos_[3])};
+
+ const ALsizei todo{dstlen & ~3};
+ for(ALsizei i{0};i < todo;i += 4)
+ {
+ const int pos0{_mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(0, 0, 0, 0)))};
+ const int pos1{_mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(1, 1, 1, 1)))};
+ const int pos2{_mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(2, 2, 2, 2)))};
+ const int pos3{_mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(3, 3, 3, 3)))};
+ const __m128 val1{_mm_setr_ps(src[pos0 ], src[pos1 ], src[pos2 ], src[pos3 ])};
+ const __m128 val2{_mm_setr_ps(src[pos0+1], src[pos1+1], src[pos2+1], src[pos3+1])};
+
+ /* val1 + (val2-val1)*mu */
+ const __m128 r0{_mm_sub_ps(val2, val1)};
+ const __m128 mu{_mm_mul_ps(_mm_cvtepi32_ps(frac4), fracOne4)};
+ const __m128 out{_mm_add_ps(val1, _mm_mul_ps(mu, r0))};
+
+ _mm_store_ps(&dst[i], out);
+
+ frac4 = _mm_add_epi32(frac4, increment4);
+ pos4 = _mm_add_epi32(pos4, _mm_srli_epi32(frac4, FRACTIONBITS));
+ frac4 = _mm_and_si128(frac4, fracMask4);
+ }
+
+ /* NOTE: These four elements represent the position *after* the last four
+ * samples, so the lowest element is the next position to resample.
+ */
+ ALsizei pos{_mm_cvtsi128_si32(pos4)};
+ frac = _mm_cvtsi128_si32(frac4);
+
+ for(ALsizei i{todo};i < dstlen;++i)
+ {
+ dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE));
+
+ frac += increment;
+ pos += frac>>FRACTIONBITS;
+ frac &= FRACTIONMASK;
+ }
+ return dst;
+}
diff --git a/alc/mixer/mixer_sse3.cpp b/alc/mixer/mixer_sse3.cpp
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/alc/mixer/mixer_sse3.cpp
diff --git a/alc/mixer/mixer_sse41.cpp b/alc/mixer/mixer_sse41.cpp
new file mode 100644
index 00000000..7efbda7b
--- /dev/null
+++ b/alc/mixer/mixer_sse41.cpp
@@ -0,0 +1,85 @@
+/**
+ * OpenAL cross platform audio library
+ * Copyright (C) 2014 by Timothy Arceri <[email protected]>.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * Or go to http://www.gnu.org/copyleft/lgpl.html
+ */
+
+#include "config.h"
+
+#include <xmmintrin.h>
+#include <emmintrin.h>
+#include <smmintrin.h>
+
+#include "alu.h"
+#include "defs.h"
+
+
+template<>
+const ALfloat *Resample_<LerpTag,SSE4Tag>(const InterpState*, const ALfloat *RESTRICT src,
+ ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen)
+{
+ const __m128i increment4{_mm_set1_epi32(increment*4)};
+ const __m128 fracOne4{_mm_set1_ps(1.0f/FRACTIONONE)};
+ const __m128i fracMask4{_mm_set1_epi32(FRACTIONMASK)};
+
+ ASSUME(frac > 0);
+ ASSUME(increment > 0);
+ ASSUME(dstlen >= 0);
+
+ alignas(16) ALsizei pos_[4], frac_[4];
+ InitiatePositionArrays(frac, increment, frac_, pos_, 4);
+ __m128i frac4{_mm_setr_epi32(frac_[0], frac_[1], frac_[2], frac_[3])};
+ __m128i pos4{_mm_setr_epi32(pos_[0], pos_[1], pos_[2], pos_[3])};
+
+ const ALsizei todo{dstlen & ~3};
+ for(ALsizei i{0};i < todo;i += 4)
+ {
+ const int pos0{_mm_extract_epi32(pos4, 0)};
+ const int pos1{_mm_extract_epi32(pos4, 1)};
+ const int pos2{_mm_extract_epi32(pos4, 2)};
+ const int pos3{_mm_extract_epi32(pos4, 3)};
+ const __m128 val1{_mm_setr_ps(src[pos0 ], src[pos1 ], src[pos2 ], src[pos3 ])};
+ const __m128 val2{_mm_setr_ps(src[pos0+1], src[pos1+1], src[pos2+1], src[pos3+1])};
+
+ /* val1 + (val2-val1)*mu */
+ const __m128 r0{_mm_sub_ps(val2, val1)};
+ const __m128 mu{_mm_mul_ps(_mm_cvtepi32_ps(frac4), fracOne4)};
+ const __m128 out{_mm_add_ps(val1, _mm_mul_ps(mu, r0))};
+
+ _mm_store_ps(&dst[i], out);
+
+ frac4 = _mm_add_epi32(frac4, increment4);
+ pos4 = _mm_add_epi32(pos4, _mm_srli_epi32(frac4, FRACTIONBITS));
+ frac4 = _mm_and_si128(frac4, fracMask4);
+ }
+
+ /* NOTE: These four elements represent the position *after* the last four
+ * samples, so the lowest element is the next position to resample.
+ */
+ ALsizei pos{_mm_cvtsi128_si32(pos4)};
+ frac = _mm_cvtsi128_si32(frac4);
+
+ for(ALsizei i{todo};i < dstlen;++i)
+ {
+ dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE));
+
+ frac += increment;
+ pos += frac>>FRACTIONBITS;
+ frac &= FRACTIONMASK;
+ }
+ return dst;
+}