aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/mixer
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-03-22 05:06:15 -0700
committerChris Robinson <[email protected]>2018-03-22 05:06:15 -0700
commit091e676db34ff51a709427d5b1203bfcd0788fb4 (patch)
tree6d67621e71b1290cdf3241a949f45f0e9915ab0e /Alc/mixer
parent6ad171781a8e2270f598263149356385cc06d8f9 (diff)
Move mixer sources into a sub-directory
Diffstat (limited to 'Alc/mixer')
-rw-r--r--Alc/mixer/defs.h119
-rw-r--r--Alc/mixer/mixer_c.c209
-rw-r--r--Alc/mixer/mixer_inc.c114
-rw-r--r--Alc/mixer/mixer_neon.c261
-rw-r--r--Alc/mixer/mixer_sse.c229
-rw-r--r--Alc/mixer/mixer_sse2.c82
-rw-r--r--Alc/mixer/mixer_sse3.c0
-rw-r--r--Alc/mixer/mixer_sse41.c86
8 files changed, 1100 insertions, 0 deletions
diff --git a/Alc/mixer/defs.h b/Alc/mixer/defs.h
new file mode 100644
index 00000000..fe19cef4
--- /dev/null
+++ b/Alc/mixer/defs.h
@@ -0,0 +1,119 @@
+#ifndef MIXER_DEFS_H
+#define MIXER_DEFS_H
+
+#include "AL/alc.h"
+#include "AL/al.h"
+#include "alMain.h"
+#include "alu.h"
+
+struct MixGains;
+
+struct MixHrtfParams;
+struct HrtfState;
+
+/* C resamplers */
+const ALfloat *Resample_copy_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen);
+const ALfloat *Resample_point_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen);
+const ALfloat *Resample_lerp_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen);
+const ALfloat *Resample_cubic_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen);
+const ALfloat *Resample_bsinc_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen);
+
+
+/* C mixers */
+void MixHrtf_C(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, struct MixHrtfParams *hrtfparams,
+ struct HrtfState *hrtfstate, ALsizei BufferSize);
+void MixHrtfBlend_C(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, const HrtfParams *oldparams,
+ MixHrtfParams *newparams, HrtfState *hrtfstate,
+ ALsizei BufferSize);
+void MixDirectHrtf_C(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2], ALfloat (*restrict Values)[2],
+ ALsizei BufferSize);
+void Mix_C(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
+ ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
+ ALsizei BufferSize);
+void MixRow_C(ALfloat *OutBuffer, const ALfloat *Gains,
+ const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans,
+ ALsizei InPos, ALsizei BufferSize);
+
+/* SSE mixers */
+void MixHrtf_SSE(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, struct MixHrtfParams *hrtfparams,
+ struct HrtfState *hrtfstate, ALsizei BufferSize);
+void MixHrtfBlend_SSE(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, const HrtfParams *oldparams,
+ MixHrtfParams *newparams, HrtfState *hrtfstate,
+ ALsizei BufferSize);
+void MixDirectHrtf_SSE(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2], ALfloat (*restrict Values)[2],
+ ALsizei BufferSize);
+void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
+ ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
+ ALsizei BufferSize);
+void MixRow_SSE(ALfloat *OutBuffer, const ALfloat *Gains,
+ const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans,
+ ALsizei InPos, ALsizei BufferSize);
+
+/* SSE resamplers */
+inline void InitiatePositionArrays(ALsizei frac, ALint increment, ALsizei *restrict frac_arr, ALint *restrict pos_arr, ALsizei size)
+{
+ ALsizei i;
+
+ pos_arr[0] = 0;
+ frac_arr[0] = frac;
+ for(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;
+ }
+}
+
+const ALfloat *Resample_lerp_SSE2(const InterpState *state, const ALfloat *restrict src,
+ ALsizei frac, ALint increment, ALfloat *restrict dst,
+ ALsizei numsamples);
+const ALfloat *Resample_lerp_SSE41(const InterpState *state, const ALfloat *restrict src,
+ ALsizei frac, ALint increment, ALfloat *restrict dst,
+ ALsizei numsamples);
+
+const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *restrict src,
+ ALsizei frac, ALint increment, ALfloat *restrict dst,
+ ALsizei dstlen);
+
+/* Neon mixers */
+void MixHrtf_Neon(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, struct MixHrtfParams *hrtfparams,
+ struct HrtfState *hrtfstate, ALsizei BufferSize);
+void MixHrtfBlend_Neon(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, const HrtfParams *oldparams,
+ MixHrtfParams *newparams, HrtfState *hrtfstate,
+ ALsizei BufferSize);
+void MixDirectHrtf_Neon(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2], ALfloat (*restrict Values)[2],
+ ALsizei BufferSize);
+void Mix_Neon(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
+ ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
+ ALsizei BufferSize);
+void MixRow_Neon(ALfloat *OutBuffer, const ALfloat *Gains,
+ const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans,
+ ALsizei InPos, ALsizei BufferSize);
+
+/* Neon resamplers */
+const ALfloat *Resample_lerp_Neon(const InterpState *state, const ALfloat *restrict src,
+ ALsizei frac, ALint increment, ALfloat *restrict dst,
+ ALsizei numsamples);
+const ALfloat *Resample_bsinc_Neon(const InterpState *state, const ALfloat *restrict src,
+ ALsizei frac, ALint increment, ALfloat *restrict dst,
+ ALsizei dstlen);
+
+#endif /* MIXER_DEFS_H */
diff --git a/Alc/mixer/mixer_c.c b/Alc/mixer/mixer_c.c
new file mode 100644
index 00000000..0c33e9b0
--- /dev/null
+++ b/Alc/mixer/mixer_c.c
@@ -0,0 +1,209 @@
+#include "config.h"
+
+#include <assert.h>
+
+#include "alMain.h"
+#include "alu.h"
+#include "alSource.h"
+#include "alAuxEffectSlot.h"
+#include "defs.h"
+
+
+static inline ALfloat do_point(const ALfloat *restrict vals, ALsizei UNUSED(frac))
+{ return vals[0]; }
+static inline ALfloat do_lerp(const ALfloat *restrict vals, ALsizei frac)
+{ return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); }
+static inline ALfloat do_cubic(const ALfloat *restrict vals, ALsizei frac)
+{ return cubic(vals[0], vals[1], vals[2], vals[3], frac * (1.0f/FRACTIONONE)); }
+
+const ALfloat *Resample_copy_C(const InterpState* UNUSED(state),
+ const ALfloat *restrict src, ALsizei UNUSED(frac), ALint UNUSED(increment),
+ ALfloat *restrict dst, ALsizei numsamples)
+{
+#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));
+ return dst;
+}
+
+#define DECL_TEMPLATE(Tag, Sampler, O) \
+const ALfloat *Resample_##Tag##_C(const InterpState* UNUSED(state), \
+ const ALfloat *restrict src, ALsizei frac, ALint increment, \
+ ALfloat *restrict dst, ALsizei numsamples) \
+{ \
+ ALsizei i; \
+ \
+ src -= O; \
+ for(i = 0;i < numsamples;i++) \
+ { \
+ dst[i] = Sampler(src, frac); \
+ \
+ frac += increment; \
+ src += frac>>FRACTIONBITS; \
+ frac &= FRACTIONMASK; \
+ } \
+ return dst; \
+}
+
+DECL_TEMPLATE(point, do_point, 0)
+DECL_TEMPLATE(lerp, do_lerp, 0)
+DECL_TEMPLATE(cubic, do_cubic, 1)
+
+#undef DECL_TEMPLATE
+
+const ALfloat *Resample_bsinc_C(const InterpState *state, const ALfloat *restrict src,
+ ALsizei frac, ALint increment, ALfloat *restrict dst,
+ ALsizei dstlen)
+{
+ const ALfloat *fil, *scd, *phd, *spd;
+ const ALfloat *const filter = state->bsinc.filter;
+ const ALfloat sf = state->bsinc.sf;
+ const ALsizei m = state->bsinc.m;
+ ALsizei j_f, pi, i;
+ ALfloat pf, r;
+
+ 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
+
+ fil = ASSUME_ALIGNED(filter + m*pi*4, 16);
+ scd = ASSUME_ALIGNED(fil + m, 16);
+ phd = ASSUME_ALIGNED(scd + m, 16);
+ spd = ASSUME_ALIGNED(phd + m, 16);
+
+ // Apply the scale and phase interpolated filter.
+ r = 0.0f;
+ for(j_f = 0;j_f < m;j_f++)
+ r += (fil[j_f] + sf*scd[j_f] + pf*(phd[j_f] + sf*spd[j_f])) * src[j_f];
+ dst[i] = r;
+
+ frac += increment;
+ src += frac>>FRACTIONBITS;
+ frac &= FRACTIONMASK;
+ }
+ return dst;
+}
+
+
+void ALfilterState_processC(ALfilterState *filter, ALfloat *restrict dst, const ALfloat *restrict src, ALsizei numsamples)
+{
+ ALsizei i;
+ if(LIKELY(numsamples > 1))
+ {
+ ALfloat x0 = filter->x[0];
+ ALfloat x1 = filter->x[1];
+ ALfloat y0 = filter->y[0];
+ ALfloat y1 = filter->y[1];
+
+ for(i = 0;i < numsamples;i++)
+ {
+ dst[i] = filter->b0* src[i] +
+ filter->b1*x0 + filter->b2*x1 -
+ filter->a1*y0 - filter->a2*y1;
+ y1 = y0; y0 = dst[i];
+ x1 = x0; x0 = src[i];
+ }
+
+ filter->x[0] = x0;
+ filter->x[1] = x1;
+ filter->y[0] = y0;
+ filter->y[1] = y1;
+ }
+ else if(numsamples == 1)
+ {
+ dst[0] = filter->b0 * src[0] +
+ filter->b1 * filter->x[0] +
+ filter->b2 * filter->x[1] -
+ filter->a1 * filter->y[0] -
+ filter->a2 * filter->y[1];
+ filter->x[1] = filter->x[0];
+ filter->x[0] = src[0];
+ filter->y[1] = filter->y[0];
+ filter->y[0] = dst[0];
+ }
+}
+
+
+static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2],
+ const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2],
+ ALfloat left, ALfloat right)
+{
+ ALsizei c;
+ for(c = 0;c < IrSize;c++)
+ {
+ const ALsizei off = (Offset+c)&HRIR_MASK;
+ Values[off][0] += Coeffs[c][0] * left;
+ Values[off][1] += Coeffs[c][1] * right;
+ }
+}
+
+#define MixHrtf MixHrtf_C
+#define MixHrtfBlend MixHrtfBlend_C
+#define MixDirectHrtf MixDirectHrtf_C
+#include "mixer_inc.c"
+#undef MixHrtf
+
+
+void Mix_C(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
+ ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
+ ALsizei BufferSize)
+{
+ ALfloat gain, delta, step;
+ ALsizei c;
+
+ delta = (Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f;
+
+ for(c = 0;c < OutChans;c++)
+ {
+ ALsizei pos = 0;
+ gain = CurrentGains[c];
+ step = (TargetGains[c] - gain) * delta;
+ if(fabsf(step) > FLT_EPSILON)
+ {
+ ALsizei minsize = mini(BufferSize, Counter);
+ for(;pos < minsize;pos++)
+ {
+ OutBuffer[c][OutPos+pos] += data[pos]*gain;
+ gain += step;
+ }
+ if(pos == Counter)
+ gain = TargetGains[c];
+ CurrentGains[c] = gain;
+ }
+
+ if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+ for(;pos < BufferSize;pos++)
+ OutBuffer[c][OutPos+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.
+ */
+void MixRow_C(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize)
+{
+ ALsizei c, i;
+
+ for(c = 0;c < InChans;c++)
+ {
+ ALfloat gain = Gains[c];
+ if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+
+ for(i = 0;i < BufferSize;i++)
+ OutBuffer[i] += data[c][InPos+i] * gain;
+ }
+}
diff --git a/Alc/mixer/mixer_inc.c b/Alc/mixer/mixer_inc.c
new file mode 100644
index 00000000..ad0daa63
--- /dev/null
+++ b/Alc/mixer/mixer_inc.c
@@ -0,0 +1,114 @@
+#include "config.h"
+
+#include "alMain.h"
+#include "alSource.h"
+
+#include "hrtf.h"
+#include "align.h"
+#include "alu.h"
+#include "defs.h"
+
+
+static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2],
+ const ALsizei irSize,
+ const ALfloat (*restrict Coeffs)[2],
+ ALfloat left, ALfloat right);
+
+
+void MixHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, MixHrtfParams *hrtfparams, HrtfState *hrtfstate,
+ ALsizei BufferSize)
+{
+ const ALfloat (*Coeffs)[2] = ASSUME_ALIGNED(hrtfparams->Coeffs, 16);
+ const ALsizei Delay[2] = { hrtfparams->Delay[0], hrtfparams->Delay[1] };
+ ALfloat gainstep = hrtfparams->GainStep;
+ ALfloat gain = hrtfparams->Gain;
+ ALfloat left, right;
+ ALsizei i;
+
+ LeftOut += OutPos;
+ RightOut += OutPos;
+ for(i = 0;i < BufferSize;i++)
+ {
+ hrtfstate->History[Offset&HRTF_HISTORY_MASK] = *(data++);
+ left = hrtfstate->History[(Offset-Delay[0])&HRTF_HISTORY_MASK]*gain;
+ right = hrtfstate->History[(Offset-Delay[1])&HRTF_HISTORY_MASK]*gain;
+
+ hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][0] = 0.0f;
+ hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][1] = 0.0f;
+
+ ApplyCoeffs(Offset, hrtfstate->Values, IrSize, Coeffs, left, right);
+ *(LeftOut++) += hrtfstate->Values[Offset&HRIR_MASK][0];
+ *(RightOut++) += hrtfstate->Values[Offset&HRIR_MASK][1];
+
+ gain += gainstep;
+ Offset++;
+ }
+ hrtfparams->Gain = gain;
+}
+
+void MixHrtfBlend(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, ALsizei OutPos,
+ const ALsizei IrSize, const HrtfParams *oldparams,
+ MixHrtfParams *newparams, HrtfState *hrtfstate,
+ ALsizei BufferSize)
+{
+ const ALfloat (*OldCoeffs)[2] = ASSUME_ALIGNED(oldparams->Coeffs, 16);
+ const ALsizei OldDelay[2] = { oldparams->Delay[0], oldparams->Delay[1] };
+ ALfloat oldGain = oldparams->Gain;
+ ALfloat oldGainStep = -oldGain / (ALfloat)BufferSize;
+ const ALfloat (*NewCoeffs)[2] = ASSUME_ALIGNED(newparams->Coeffs, 16);
+ const ALsizei NewDelay[2] = { newparams->Delay[0], newparams->Delay[1] };
+ ALfloat newGain = newparams->Gain;
+ ALfloat newGainStep = newparams->GainStep;
+ ALfloat left, right;
+ ALsizei i;
+
+ LeftOut += OutPos;
+ RightOut += OutPos;
+ for(i = 0;i < BufferSize;i++)
+ {
+ hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][0] = 0.0f;
+ hrtfstate->Values[(Offset+IrSize-1)&HRIR_MASK][1] = 0.0f;
+
+ hrtfstate->History[Offset&HRTF_HISTORY_MASK] = *(data++);
+
+ left = hrtfstate->History[(Offset-OldDelay[0])&HRTF_HISTORY_MASK]*oldGain;
+ right = hrtfstate->History[(Offset-OldDelay[1])&HRTF_HISTORY_MASK]*oldGain;
+ ApplyCoeffs(Offset, hrtfstate->Values, IrSize, OldCoeffs, left, right);
+
+ left = hrtfstate->History[(Offset-NewDelay[0])&HRTF_HISTORY_MASK]*newGain;
+ right = hrtfstate->History[(Offset-NewDelay[1])&HRTF_HISTORY_MASK]*newGain;
+ ApplyCoeffs(Offset, hrtfstate->Values, IrSize, NewCoeffs, left, right);
+
+ *(LeftOut++) += hrtfstate->Values[Offset&HRIR_MASK][0];
+ *(RightOut++) += hrtfstate->Values[Offset&HRIR_MASK][1];
+
+ oldGain += oldGainStep;
+ newGain += newGainStep;
+ Offset++;
+ }
+ newparams->Gain = newGain;
+}
+
+void MixDirectHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut,
+ const ALfloat *data, ALsizei Offset, const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2], ALfloat (*restrict Values)[2],
+ ALsizei BufferSize)
+{
+ ALfloat insample;
+ ALsizei i;
+
+ for(i = 0;i < BufferSize;i++)
+ {
+ Values[(Offset+IrSize)&HRIR_MASK][0] = 0.0f;
+ Values[(Offset+IrSize)&HRIR_MASK][1] = 0.0f;
+ Offset++;
+
+ insample = *(data++);
+ ApplyCoeffs(Offset, Values, IrSize, Coeffs, insample, insample);
+ *(LeftOut++) += Values[Offset&HRIR_MASK][0];
+ *(RightOut++) += Values[Offset&HRIR_MASK][1];
+ }
+}
diff --git a/Alc/mixer/mixer_neon.c b/Alc/mixer/mixer_neon.c
new file mode 100644
index 00000000..b93d11fd
--- /dev/null
+++ b/Alc/mixer/mixer_neon.c
@@ -0,0 +1,261 @@
+#include "config.h"
+
+#include <arm_neon.h>
+
+#include "AL/al.h"
+#include "AL/alc.h"
+#include "alMain.h"
+#include "alu.h"
+#include "hrtf.h"
+#include "defs.h"
+
+
+const ALfloat *Resample_lerp_Neon(const InterpState* UNUSED(state),
+ const ALfloat *restrict src, ALsizei frac, ALint increment,
+ ALfloat *restrict dst, ALsizei numsamples)
+{
+ 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) ALint pos_[4];
+ alignas(16) ALsizei frac_[4];
+ int32x4_t pos4;
+ int32x4_t frac4;
+ ALsizei i;
+
+ InitiatePositionArrays(frac, increment, frac_, pos_, 4);
+
+ frac4 = vld1q_s32(frac_);
+ pos4 = vld1q_s32(pos_);
+
+ for(i = 0;numsamples-i > 3;i += 4)
+ {
+ const float32x4_t val1 = (float32x4_t){src[pos_[0]], src[pos_[1]], src[pos_[2]], src[pos_[3]]};
+ const float32x4_t val2 = (float32x4_t){src[pos_[0]+1], src[pos_[1]+1], src[pos_[2]+1], src[pos_[3]+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);
+
+ vst1q_s32(pos_, pos4);
+ }
+
+ if(i < numsamples)
+ {
+ /* NOTE: These four elements represent the position *after* the last
+ * four samples, so the lowest element is the next position to
+ * resample.
+ */
+ ALint pos = pos_[0];
+ frac = vgetq_lane_s32(frac4, 0);
+ do {
+ dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE));
+
+ frac += increment;
+ pos += frac>>FRACTIONBITS;
+ frac &= FRACTIONMASK;
+ } while(++i < numsamples);
+ }
+ return dst;
+}
+
+const ALfloat *Resample_bsinc_Neon(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;
+
+ 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 = ASSUME_ALIGNED(filter + offset, 16); offset += m;
+ scd = ASSUME_ALIGNED(filter + offset, 16); offset += m;
+ phd = ASSUME_ALIGNED(filter + offset, 16); offset += m;
+ spd = ASSUME_ALIGNED(filter + offset, 16);
+
+ // Apply the scale and phase interpolated filter.
+ r4 = vdupq_n_f32(0.0f);
+ {
+ const float32x4_t pf4 = vdupq_n_f32(pf);
+ for(j = 0;j < m;j+=4,fil++,scd++,phd++,spd++)
+ {
+ /* f = ((fil + sf*scd) + pf*(phd + sf*spd)) */
+ const float32x4_t f4 = vmlaq_f32(
+ vmlaq_f32(*fil, sf4, *scd),
+ pf4, vmlaq_f32(*phd, sf4, *spd)
+ );
+ /* r += f*src */
+ r4 = vmlaq_f32(r4, f4, vld1q_f32(&src[j]));
+ }
+ }
+ 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, ALfloat (*restrict Values)[2],
+ const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2],
+ ALfloat left, ALfloat right)
+{
+ ALsizei c;
+ 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);
+ }
+ Values = ASSUME_ALIGNED(Values, 16);
+ Coeffs = ASSUME_ALIGNED(Coeffs, 16);
+ for(c = 0;c < IrSize;c += 2)
+ {
+ const ALsizei o0 = (Offset+c)&HRIR_MASK;
+ const ALsizei o1 = (o0+1)&HRIR_MASK;
+ float32x4_t vals = vcombine_f32(vld1_f32((float32_t*)&Values[o0][0]),
+ vld1_f32((float32_t*)&Values[o1][0]));
+ float32x4_t coefs = vld1q_f32((float32_t*)&Coeffs[c][0]);
+
+ vals = vmlaq_f32(vals, coefs, leftright4);
+
+ vst1_f32((float32_t*)&Values[o0][0], vget_low_f32(vals));
+ vst1_f32((float32_t*)&Values[o1][0], vget_high_f32(vals));
+ }
+}
+
+#define MixHrtf MixHrtf_Neon
+#define MixHrtfBlend MixHrtfBlend_Neon
+#define MixDirectHrtf MixDirectHrtf_Neon
+#include "mixer_inc.c"
+#undef MixHrtf
+
+
+void Mix_Neon(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
+ ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
+ ALsizei BufferSize)
+{
+ ALfloat gain, delta, step;
+ float32x4_t gain4;
+ ALsizei c;
+
+ data = ASSUME_ALIGNED(data, 16);
+ OutBuffer = ASSUME_ALIGNED(OutBuffer, 16);
+
+ delta = (Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f;
+
+ for(c = 0;c < OutChans;c++)
+ {
+ ALsizei pos = 0;
+ gain = CurrentGains[c];
+ step = (TargetGains[c] - gain) * delta;
+ if(fabsf(step) > FLT_EPSILON)
+ {
+ ALsizei minsize = mini(BufferSize, Counter);
+ /* Mix with applying gain steps in aligned multiples of 4. */
+ if(minsize-pos > 3)
+ {
+ float32x4_t step4;
+ gain4 = vsetq_lane_f32(gain, gain4, 0);
+ gain4 = vsetq_lane_f32(gain + step, gain4, 1);
+ gain4 = vsetq_lane_f32(gain + step + step, gain4, 2);
+ gain4 = vsetq_lane_f32(gain + step + step + step, gain4, 3);
+ step4 = vdupq_n_f32(step + step + step + step);
+ do {
+ const float32x4_t val4 = vld1q_f32(&data[pos]);
+ float32x4_t dry4 = vld1q_f32(&OutBuffer[c][OutPos+pos]);
+ dry4 = vmlaq_f32(dry4, val4, gain4);
+ gain4 = vaddq_f32(gain4, step4);
+ vst1q_f32(&OutBuffer[c][OutPos+pos], dry4);
+ pos += 4;
+ } while(minsize-pos > 3);
+ /* NOTE: gain4 now represents the next four gains after the
+ * last four mixed samples, so the lowest element represents
+ * the next gain to apply.
+ */
+ gain = vgetq_lane_f32(gain4, 0);
+ }
+ /* Mix with applying left over gain steps that aren't aligned multiples of 4. */
+ for(;pos < minsize;pos++)
+ {
+ OutBuffer[c][OutPos+pos] += data[pos]*gain;
+ gain += step;
+ }
+ if(pos == Counter)
+ gain = TargetGains[c];
+ CurrentGains[c] = gain;
+
+ /* Mix until pos is aligned with 4 or the mix is done. */
+ minsize = mini(BufferSize, (pos+3)&~3);
+ for(;pos < minsize;pos++)
+ OutBuffer[c][OutPos+pos] += data[pos]*gain;
+ }
+
+ if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+ gain4 = vdupq_n_f32(gain);
+ for(;BufferSize-pos > 3;pos += 4)
+ {
+ const float32x4_t val4 = vld1q_f32(&data[pos]);
+ float32x4_t dry4 = vld1q_f32(&OutBuffer[c][OutPos+pos]);
+ dry4 = vmlaq_f32(dry4, val4, gain4);
+ vst1q_f32(&OutBuffer[c][OutPos+pos], dry4);
+ }
+ for(;pos < BufferSize;pos++)
+ OutBuffer[c][OutPos+pos] += data[pos]*gain;
+ }
+}
+
+void MixRow_Neon(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize)
+{
+ float32x4_t gain4;
+ ALsizei c;
+
+ data = ASSUME_ALIGNED(data, 16);
+ OutBuffer = ASSUME_ALIGNED(OutBuffer, 16);
+
+ for(c = 0;c < InChans;c++)
+ {
+ ALsizei pos = 0;
+ ALfloat gain = Gains[c];
+ if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+
+ gain4 = vdupq_n_f32(gain);
+ for(;BufferSize-pos > 3;pos += 4)
+ {
+ const float32x4_t val4 = vld1q_f32(&data[c][InPos+pos]);
+ float32x4_t dry4 = vld1q_f32(&OutBuffer[pos]);
+ dry4 = vmlaq_f32(dry4, val4, gain4);
+ vst1q_f32(&OutBuffer[pos], dry4);
+ }
+ for(;pos < BufferSize;pos++)
+ OutBuffer[pos] += data[c][InPos+pos]*gain;
+ }
+}
diff --git a/Alc/mixer/mixer_sse.c b/Alc/mixer/mixer_sse.c
new file mode 100644
index 00000000..288661b2
--- /dev/null
+++ b/Alc/mixer/mixer_sse.c
@@ -0,0 +1,229 @@
+#include "config.h"
+
+#include <xmmintrin.h>
+
+#include "AL/al.h"
+#include "AL/alc.h"
+#include "alMain.h"
+#include "alu.h"
+
+#include "alSource.h"
+#include "alAuxEffectSlot.h"
+#include "defs.h"
+
+
+const ALfloat *Resample_bsinc_SSE(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;
+ const __m128 *fil, *scd, *phd, *spd;
+ ALsizei pi, i, j, offset;
+ ALfloat pf;
+ __m128 r4;
+
+ 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 __m128*)ASSUME_ALIGNED(filter + offset, 16); offset += m;
+ scd = (const __m128*)ASSUME_ALIGNED(filter + offset, 16); offset += m;
+ phd = (const __m128*)ASSUME_ALIGNED(filter + offset, 16); offset += m;
+ spd = (const __m128*)ASSUME_ALIGNED(filter + offset, 16);
+
+ // Apply the scale and phase interpolated filter.
+ r4 = _mm_setzero_ps();
+ {
+ const __m128 pf4 = _mm_set1_ps(pf);
+#define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z))
+ for(j = 0;j < m;j+=4,fil++,scd++,phd++,spd++)
+ {
+ /* f = ((fil + sf*scd) + pf*(phd + sf*spd)) */
+ const __m128 f4 = MLA4(
+ MLA4(*fil, sf4, *scd),
+ pf4, MLA4(*phd, sf4, *spd)
+ );
+ /* r += f*src */
+ r4 = MLA4(r4, f4, _mm_loadu_ps(&src[j]));
+ }
+#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, ALfloat (*restrict Values)[2],
+ const ALsizei IrSize,
+ const ALfloat (*restrict Coeffs)[2],
+ ALfloat left, ALfloat right)
+{
+ const __m128 lrlr = _mm_setr_ps(left, right, left, right);
+ __m128 vals = _mm_setzero_ps();
+ __m128 coeffs;
+ ALsizei i;
+
+ Values = ASSUME_ALIGNED(Values, 16);
+ Coeffs = ASSUME_ALIGNED(Coeffs, 16);
+ if((Offset&1))
+ {
+ const ALsizei o0 = Offset&HRIR_MASK;
+ const ALsizei o1 = (Offset+IrSize-1)&HRIR_MASK;
+ __m128 imp0, imp1;
+
+ coeffs = _mm_load_ps(&Coeffs[0][0]);
+ vals = _mm_loadl_pi(vals, (__m64*)&Values[o0][0]);
+ imp0 = _mm_mul_ps(lrlr, coeffs);
+ vals = _mm_add_ps(imp0, vals);
+ _mm_storel_pi((__m64*)&Values[o0][0], vals);
+ for(i = 1;i < IrSize-1;i += 2)
+ {
+ const ALsizei o2 = (Offset+i)&HRIR_MASK;
+
+ coeffs = _mm_load_ps(&Coeffs[i+1][0]);
+ vals = _mm_load_ps(&Values[o2][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[o2][0], vals);
+ imp0 = imp1;
+ }
+ vals = _mm_loadl_pi(vals, (__m64*)&Values[o1][0]);
+ imp0 = _mm_movehl_ps(imp0, imp0);
+ vals = _mm_add_ps(imp0, vals);
+ _mm_storel_pi((__m64*)&Values[o1][0], vals);
+ }
+ else
+ {
+ for(i = 0;i < IrSize;i += 2)
+ {
+ const ALsizei o = (Offset + i)&HRIR_MASK;
+
+ coeffs = _mm_load_ps(&Coeffs[i][0]);
+ vals = _mm_load_ps(&Values[o][0]);
+ vals = _mm_add_ps(vals, _mm_mul_ps(lrlr, coeffs));
+ _mm_store_ps(&Values[o][0], vals);
+ }
+ }
+}
+
+#define MixHrtf MixHrtf_SSE
+#define MixHrtfBlend MixHrtfBlend_SSE
+#define MixDirectHrtf MixDirectHrtf_SSE
+#include "mixer_inc.c"
+#undef MixHrtf
+
+
+void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
+ ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
+ ALsizei BufferSize)
+{
+ ALfloat gain, delta, step;
+ __m128 gain4;
+ ALsizei c;
+
+ delta = (Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f;
+
+ for(c = 0;c < OutChans;c++)
+ {
+ ALsizei pos = 0;
+ gain = CurrentGains[c];
+ step = (TargetGains[c] - gain) * delta;
+ if(fabsf(step) > FLT_EPSILON)
+ {
+ ALsizei minsize = mini(BufferSize, Counter);
+ /* Mix with applying gain steps in aligned multiples of 4. */
+ if(minsize-pos > 3)
+ {
+ __m128 step4;
+ gain4 = _mm_setr_ps(
+ gain,
+ gain + step,
+ gain + step + step,
+ gain + step + step + step
+ );
+ step4 = _mm_set1_ps(step + step + step + step);
+ do {
+ const __m128 val4 = _mm_load_ps(&data[pos]);
+ __m128 dry4 = _mm_load_ps(&OutBuffer[c][OutPos+pos]);
+ dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4));
+ gain4 = _mm_add_ps(gain4, step4);
+ _mm_store_ps(&OutBuffer[c][OutPos+pos], dry4);
+ pos += 4;
+ } while(minsize-pos > 3);
+ /* NOTE: gain4 now represents the next four gains after the
+ * last four mixed samples, so the lowest element represents
+ * the next gain to apply.
+ */
+ gain = _mm_cvtss_f32(gain4);
+ }
+ /* Mix with applying left over gain steps that aren't aligned multiples of 4. */
+ for(;pos < minsize;pos++)
+ {
+ OutBuffer[c][OutPos+pos] += data[pos]*gain;
+ gain += step;
+ }
+ if(pos == Counter)
+ gain = TargetGains[c];
+ CurrentGains[c] = gain;
+
+ /* Mix until pos is aligned with 4 or the mix is done. */
+ minsize = mini(BufferSize, (pos+3)&~3);
+ for(;pos < minsize;pos++)
+ OutBuffer[c][OutPos+pos] += data[pos]*gain;
+ }
+
+ if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+ gain4 = _mm_set1_ps(gain);
+ for(;BufferSize-pos > 3;pos += 4)
+ {
+ const __m128 val4 = _mm_load_ps(&data[pos]);
+ __m128 dry4 = _mm_load_ps(&OutBuffer[c][OutPos+pos]);
+ dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4));
+ _mm_store_ps(&OutBuffer[c][OutPos+pos], dry4);
+ }
+ for(;pos < BufferSize;pos++)
+ OutBuffer[c][OutPos+pos] += data[pos]*gain;
+ }
+}
+
+void MixRow_SSE(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize)
+{
+ __m128 gain4;
+ ALsizei c;
+
+ for(c = 0;c < InChans;c++)
+ {
+ ALsizei pos = 0;
+ ALfloat gain = Gains[c];
+ if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
+ continue;
+
+ gain4 = _mm_set1_ps(gain);
+ for(;BufferSize-pos > 3;pos += 4)
+ {
+ const __m128 val4 = _mm_load_ps(&data[c][InPos+pos]);
+ __m128 dry4 = _mm_load_ps(&OutBuffer[pos]);
+ dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4));
+ _mm_store_ps(&OutBuffer[pos], dry4);
+ }
+ for(;pos < BufferSize;pos++)
+ OutBuffer[pos] += data[c][InPos+pos]*gain;
+ }
+}
diff --git a/Alc/mixer/mixer_sse2.c b/Alc/mixer/mixer_sse2.c
new file mode 100644
index 00000000..19d07719
--- /dev/null
+++ b/Alc/mixer/mixer_sse2.c
@@ -0,0 +1,82 @@
+/**
+ * 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"
+
+
+const ALfloat *Resample_lerp_SSE2(const InterpState* UNUSED(state),
+ const ALfloat *restrict src, ALsizei frac, ALint increment,
+ ALfloat *restrict dst, ALsizei numsamples)
+{
+ const __m128i increment4 = _mm_set1_epi32(increment*4);
+ const __m128 fracOne4 = _mm_set1_ps(1.0f/FRACTIONONE);
+ const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK);
+ union { alignas(16) ALint i[4]; float f[4]; } pos_;
+ union { alignas(16) ALsizei i[4]; float f[4]; } frac_;
+ __m128i frac4, pos4;
+ ALint pos;
+ ALsizei i;
+
+ InitiatePositionArrays(frac, increment, frac_.i, pos_.i, 4);
+
+ frac4 = _mm_castps_si128(_mm_load_ps(frac_.f));
+ pos4 = _mm_castps_si128(_mm_load_ps(pos_.f));
+
+ for(i = 0;numsamples-i > 3;i += 4)
+ {
+ const __m128 val1 = _mm_setr_ps(src[pos_.i[0]], src[pos_.i[1]], src[pos_.i[2]], src[pos_.i[3]]);
+ const __m128 val2 = _mm_setr_ps(src[pos_.i[0]+1], src[pos_.i[1]+1], src[pos_.i[2]+1], src[pos_.i[3]+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);
+
+ _mm_store_ps(pos_.f, _mm_castsi128_ps(pos4));
+ }
+
+ /* NOTE: These four elements represent the position *after* the last four
+ * samples, so the lowest element is the next position to resample.
+ */
+ pos = pos_.i[0];
+ frac = _mm_cvtsi128_si32(frac4);
+
+ for(;i < numsamples;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.c b/Alc/mixer/mixer_sse3.c
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/Alc/mixer/mixer_sse3.c
diff --git a/Alc/mixer/mixer_sse41.c b/Alc/mixer/mixer_sse41.c
new file mode 100644
index 00000000..85fd0f5e
--- /dev/null
+++ b/Alc/mixer/mixer_sse41.c
@@ -0,0 +1,86 @@
+/**
+ * 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"
+
+
+const ALfloat *Resample_lerp_SSE41(const InterpState* UNUSED(state),
+ const ALfloat *restrict src, ALsizei frac, ALint increment,
+ ALfloat *restrict dst, ALsizei numsamples)
+{
+ const __m128i increment4 = _mm_set1_epi32(increment*4);
+ const __m128 fracOne4 = _mm_set1_ps(1.0f/FRACTIONONE);
+ const __m128i fracMask4 = _mm_set1_epi32(FRACTIONMASK);
+ union { alignas(16) ALint i[4]; float f[4]; } pos_;
+ union { alignas(16) ALsizei i[4]; float f[4]; } frac_;
+ __m128i frac4, pos4;
+ ALint pos;
+ ALsizei i;
+
+ InitiatePositionArrays(frac, increment, frac_.i, pos_.i, 4);
+
+ frac4 = _mm_castps_si128(_mm_load_ps(frac_.f));
+ pos4 = _mm_castps_si128(_mm_load_ps(pos_.f));
+
+ for(i = 0;numsamples-i > 3;i += 4)
+ {
+ const __m128 val1 = _mm_setr_ps(src[pos_.i[0]], src[pos_.i[1]], src[pos_.i[2]], src[pos_.i[3]]);
+ const __m128 val2 = _mm_setr_ps(src[pos_.i[0]+1], src[pos_.i[1]+1], src[pos_.i[2]+1], src[pos_.i[3]+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);
+
+ pos_.i[0] = _mm_extract_epi32(pos4, 0);
+ pos_.i[1] = _mm_extract_epi32(pos4, 1);
+ pos_.i[2] = _mm_extract_epi32(pos4, 2);
+ pos_.i[3] = _mm_extract_epi32(pos4, 3);
+ }
+
+ /* NOTE: These four elements represent the position *after* the last four
+ * samples, so the lowest element is the next position to resample.
+ */
+ pos = pos_.i[0];
+ frac = _mm_cvtsi128_si32(frac4);
+
+ for(;i < numsamples;i++)
+ {
+ dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE));
+
+ frac += increment;
+ pos += frac>>FRACTIONBITS;
+ frac &= FRACTIONMASK;
+ }
+ return dst;
+}