2012-08-15 01:01:55 -07:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <xmmintrin.h>
|
|
|
|
|
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
|
|
|
#include "alMain.h"
|
|
|
|
#include "alu.h"
|
|
|
|
|
2012-09-09 00:53:54 -07:00
|
|
|
#include "alSource.h"
|
2012-09-16 06:19:39 -07:00
|
|
|
#include "alAuxEffectSlot.h"
|
2012-09-09 00:53:54 -07:00
|
|
|
#include "mixer_defs.h"
|
|
|
|
|
2012-08-15 01:01:55 -07:00
|
|
|
|
2017-08-16 18:09:53 -07:00
|
|
|
const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *restrict src,
|
|
|
|
ALsizei frac, ALint increment, ALfloat *restrict dst,
|
|
|
|
ALsizei dstlen)
|
2015-11-05 09:42:08 -08:00
|
|
|
{
|
2017-08-23 23:01:11 -07:00
|
|
|
const ALfloat *const filter = state->bsinc.filter;
|
2017-02-13 11:29:32 -08:00
|
|
|
const __m128 sf4 = _mm_set1_ps(state->bsinc.sf);
|
|
|
|
const ALsizei m = state->bsinc.m;
|
2017-08-30 11:30:19 -07:00
|
|
|
const __m128 *fil, *scd, *phd, *spd;
|
|
|
|
ALsizei pi, i, j, offset;
|
2015-11-05 21:57:12 -08:00
|
|
|
ALfloat pf;
|
|
|
|
__m128 r4;
|
2015-11-05 09:42:08 -08:00
|
|
|
|
2017-02-13 11:29:32 -08:00
|
|
|
src += state->bsinc.l;
|
2015-11-05 21:57:12 -08:00
|
|
|
for(i = 0;i < dstlen;i++)
|
|
|
|
{
|
|
|
|
// Calculate the phase index and factor.
|
2015-11-05 09:42:08 -08:00
|
|
|
#define FRAC_PHASE_BITDIFF (FRACTIONBITS-BSINC_PHASE_BITS)
|
2015-11-05 21:57:12 -08:00
|
|
|
pi = frac >> FRAC_PHASE_BITDIFF;
|
|
|
|
pf = (frac & ((1<<FRAC_PHASE_BITDIFF)-1)) * (1.0f/(1<<FRAC_PHASE_BITDIFF));
|
2015-11-05 09:42:08 -08:00
|
|
|
#undef FRAC_PHASE_BITDIFF
|
|
|
|
|
2017-08-30 11:30:19 -07:00
|
|
|
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);
|
2015-11-05 09:42:08 -08:00
|
|
|
|
|
|
|
// Apply the scale and phase interpolated filter.
|
2015-11-05 21:57:12 -08:00
|
|
|
r4 = _mm_setzero_ps();
|
2015-11-05 09:42:08 -08:00
|
|
|
{
|
2015-11-05 21:57:12 -08:00
|
|
|
const __m128 pf4 = _mm_set1_ps(pf);
|
2017-02-12 21:35:08 -08:00
|
|
|
#define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z))
|
2017-08-30 11:30:19 -07:00
|
|
|
for(j = 0;j < m;j+=4,fil++,scd++,phd++,spd++)
|
2015-11-05 21:57:12 -08:00
|
|
|
{
|
2017-02-13 07:36:49 -08:00
|
|
|
/* f = ((fil + sf*scd) + pf*(phd + sf*spd)) */
|
2017-08-30 11:30:19 -07:00
|
|
|
const __m128 f4 = MLA4(
|
|
|
|
MLA4(*fil, sf4, *scd),
|
|
|
|
pf4, MLA4(*phd, sf4, *spd)
|
2015-11-05 21:57:12 -08:00
|
|
|
);
|
2017-02-13 07:36:49 -08:00
|
|
|
/* r += f*src */
|
2017-08-30 11:30:19 -07:00
|
|
|
r4 = MLA4(r4, f4, _mm_loadu_ps(&src[j]));
|
2015-11-05 21:57:12 -08:00
|
|
|
}
|
2017-02-12 21:35:08 -08:00
|
|
|
#undef MLA4
|
2015-11-05 09:42:08 -08:00
|
|
|
}
|
|
|
|
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));
|
2015-11-05 21:57:12 -08:00
|
|
|
dst[i] = _mm_cvtss_f32(r4);
|
2015-11-05 09:42:08 -08:00
|
|
|
|
|
|
|
frac += increment;
|
|
|
|
src += frac>>FRACTIONBITS;
|
|
|
|
frac &= FRACTIONMASK;
|
|
|
|
}
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-16 07:45:07 -08:00
|
|
|
static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2],
|
|
|
|
const ALsizei IrSize,
|
2017-03-11 18:04:06 -08:00
|
|
|
const ALfloat (*restrict Coeffs)[2],
|
2013-05-28 22:27:07 -07:00
|
|
|
ALfloat left, ALfloat right)
|
2012-08-15 01:01:55 -07:00
|
|
|
{
|
2014-05-18 06:35:33 -07:00
|
|
|
const __m128 lrlr = _mm_setr_ps(left, right, left, right);
|
2012-09-09 04:09:31 -07:00
|
|
|
__m128 vals = _mm_setzero_ps();
|
2012-08-15 08:19:04 -07:00
|
|
|
__m128 coeffs;
|
2017-01-16 07:45:07 -08:00
|
|
|
ALsizei i;
|
2012-09-11 01:59:42 -07:00
|
|
|
|
2017-02-13 07:36:49 -08:00
|
|
|
Values = ASSUME_ALIGNED(Values, 16);
|
|
|
|
Coeffs = ASSUME_ALIGNED(Coeffs, 16);
|
2012-09-11 01:59:42 -07:00
|
|
|
if((Offset&1))
|
2012-08-15 01:01:55 -07:00
|
|
|
{
|
2017-01-16 07:45:07 -08:00
|
|
|
const ALsizei o0 = Offset&HRIR_MASK;
|
|
|
|
const ALsizei o1 = (Offset+IrSize-1)&HRIR_MASK;
|
2012-09-11 01:59:42 -07:00
|
|
|
__m128 imp0, imp1;
|
2012-08-15 08:19:04 -07:00
|
|
|
|
2012-09-11 01:59:42 -07:00
|
|
|
coeffs = _mm_load_ps(&Coeffs[0][0]);
|
2012-08-15 01:01:55 -07:00
|
|
|
vals = _mm_loadl_pi(vals, (__m64*)&Values[o0][0]);
|
2012-09-11 01:59:42 -07:00
|
|
|
imp0 = _mm_mul_ps(lrlr, coeffs);
|
|
|
|
vals = _mm_add_ps(imp0, vals);
|
2012-08-15 01:01:55 -07:00
|
|
|
_mm_storel_pi((__m64*)&Values[o0][0], vals);
|
2012-09-11 01:59:42 -07:00
|
|
|
for(i = 1;i < IrSize-1;i += 2)
|
|
|
|
{
|
2017-01-16 07:45:07 -08:00
|
|
|
const ALsizei o2 = (Offset+i)&HRIR_MASK;
|
2012-09-11 01:59:42 -07:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2017-01-16 07:45:07 -08:00
|
|
|
const ALsizei o = (Offset + i)&HRIR_MASK;
|
2012-09-11 01:59:42 -07:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2012-08-15 01:01:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-15 01:37:46 -07:00
|
|
|
#define MixHrtf MixHrtf_SSE
|
2017-05-03 03:29:21 -07:00
|
|
|
#define MixHrtfBlend MixHrtfBlend_SSE
|
2016-08-12 05:26:36 -07:00
|
|
|
#define MixDirectHrtf MixDirectHrtf_SSE
|
2012-09-16 08:14:26 -07:00
|
|
|
#include "mixer_inc.c"
|
2015-08-15 01:37:46 -07:00
|
|
|
#undef MixHrtf
|
2012-09-16 08:14:26 -07:00
|
|
|
|
2012-08-29 01:56:04 -07:00
|
|
|
|
2017-01-16 07:45:07 -08:00
|
|
|
void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
|
|
|
|
ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
|
|
|
|
ALsizei BufferSize)
|
2012-09-09 00:53:54 -07:00
|
|
|
{
|
2016-10-05 20:33:45 -07:00
|
|
|
ALfloat gain, delta, step;
|
2015-09-30 17:25:28 -07:00
|
|
|
__m128 gain4;
|
2017-01-16 07:45:07 -08:00
|
|
|
ALsizei c;
|
2012-09-09 00:53:54 -07:00
|
|
|
|
2016-10-05 20:33:45 -07:00
|
|
|
delta = (Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f;
|
|
|
|
|
2014-06-13 13:34:19 -07:00
|
|
|
for(c = 0;c < OutChans;c++)
|
2012-09-09 04:02:54 -07:00
|
|
|
{
|
2017-01-16 07:45:07 -08:00
|
|
|
ALsizei pos = 0;
|
2016-10-05 20:33:45 -07:00
|
|
|
gain = CurrentGains[c];
|
|
|
|
step = (TargetGains[c] - gain) * delta;
|
|
|
|
if(fabsf(step) > FLT_EPSILON)
|
2014-03-23 06:57:00 -07:00
|
|
|
{
|
2017-01-16 07:45:07 -08:00
|
|
|
ALsizei minsize = mini(BufferSize, Counter);
|
2014-05-03 17:24:46 -07:00
|
|
|
/* Mix with applying gain steps in aligned multiples of 4. */
|
2015-09-30 17:25:28 -07:00
|
|
|
if(minsize-pos > 3)
|
2014-03-23 06:57:00 -07:00
|
|
|
{
|
2015-09-30 17:25:28 -07:00
|
|
|
__m128 step4;
|
2014-06-13 13:34:19 -07:00
|
|
|
gain4 = _mm_setr_ps(
|
|
|
|
gain,
|
2014-11-25 02:08:48 -08:00
|
|
|
gain + step,
|
|
|
|
gain + step + step,
|
|
|
|
gain + step + step + step
|
2014-03-23 06:57:00 -07:00
|
|
|
);
|
2014-11-25 02:08:48 -08:00
|
|
|
step4 = _mm_set1_ps(step + step + step + step);
|
2014-03-23 06:57:00 -07:00
|
|
|
do {
|
|
|
|
const __m128 val4 = _mm_load_ps(&data[pos]);
|
|
|
|
__m128 dry4 = _mm_load_ps(&OutBuffer[c][OutPos+pos]);
|
2014-06-13 13:34:19 -07:00
|
|
|
dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4));
|
2014-11-25 02:08:48 -08:00
|
|
|
gain4 = _mm_add_ps(gain4, step4);
|
2014-03-23 06:57:00 -07:00
|
|
|
_mm_store_ps(&OutBuffer[c][OutPos+pos], dry4);
|
|
|
|
pos += 4;
|
2015-09-30 17:25:28 -07:00
|
|
|
} while(minsize-pos > 3);
|
2015-10-25 14:07:58 -07:00
|
|
|
/* NOTE: gain4 now represents the next four gains after the
|
|
|
|
* last four mixed samples, so the lowest element represents
|
|
|
|
* the next gain to apply.
|
|
|
|
*/
|
2014-06-13 13:34:19 -07:00
|
|
|
gain = _mm_cvtss_f32(gain4);
|
2014-03-23 06:57:00 -07:00
|
|
|
}
|
2014-05-03 17:24:46 -07:00
|
|
|
/* Mix with applying left over gain steps that aren't aligned multiples of 4. */
|
2015-09-30 17:25:28 -07:00
|
|
|
for(;pos < minsize;pos++)
|
2014-03-23 06:57:00 -07:00
|
|
|
{
|
2014-06-13 13:34:19 -07:00
|
|
|
OutBuffer[c][OutPos+pos] += data[pos]*gain;
|
2014-11-25 02:08:48 -08:00
|
|
|
gain += step;
|
2014-03-23 06:57:00 -07:00
|
|
|
}
|
2014-05-04 00:13:19 -07:00
|
|
|
if(pos == Counter)
|
2016-10-05 20:33:45 -07:00
|
|
|
gain = TargetGains[c];
|
|
|
|
CurrentGains[c] = gain;
|
2015-09-30 17:25:28 -07:00
|
|
|
|
2014-05-03 17:24:46 -07:00
|
|
|
/* Mix until pos is aligned with 4 or the mix is done. */
|
2017-01-16 07:45:07 -08:00
|
|
|
minsize = mini(BufferSize, (pos+3)&~3);
|
2015-09-30 17:25:28 -07:00
|
|
|
for(;pos < minsize;pos++)
|
2014-06-13 13:34:19 -07:00
|
|
|
OutBuffer[c][OutPos+pos] += data[pos]*gain;
|
2014-03-23 06:57:00 -07:00
|
|
|
}
|
|
|
|
|
2014-10-31 16:55:19 -07:00
|
|
|
if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
|
2012-09-24 15:33:44 -07:00
|
|
|
continue;
|
2014-06-13 13:34:19 -07:00
|
|
|
gain4 = _mm_set1_ps(gain);
|
2014-03-23 06:57:00 -07:00
|
|
|
for(;BufferSize-pos > 3;pos += 4)
|
2012-09-09 04:02:54 -07:00
|
|
|
{
|
2012-09-11 06:32:42 -07:00
|
|
|
const __m128 val4 = _mm_load_ps(&data[pos]);
|
2013-10-06 10:11:01 -07:00
|
|
|
__m128 dry4 = _mm_load_ps(&OutBuffer[c][OutPos+pos]);
|
2014-06-13 13:34:19 -07:00
|
|
|
dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4));
|
2013-10-06 10:11:01 -07:00
|
|
|
_mm_store_ps(&OutBuffer[c][OutPos+pos], dry4);
|
2012-09-09 04:02:54 -07:00
|
|
|
}
|
2012-09-24 19:07:07 -07:00
|
|
|
for(;pos < BufferSize;pos++)
|
2014-06-13 13:34:19 -07:00
|
|
|
OutBuffer[c][OutPos+pos] += data[pos]*gain;
|
2012-09-16 06:19:39 -07:00
|
|
|
}
|
|
|
|
}
|
2016-05-31 10:18:34 -07:00
|
|
|
|
2017-01-16 07:45:07 -08:00
|
|
|
void MixRow_SSE(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize)
|
2016-05-31 10:18:34 -07:00
|
|
|
{
|
|
|
|
__m128 gain4;
|
2017-01-16 07:45:07 -08:00
|
|
|
ALsizei c;
|
2016-05-31 10:18:34 -07:00
|
|
|
|
|
|
|
for(c = 0;c < InChans;c++)
|
|
|
|
{
|
2017-01-16 07:45:07 -08:00
|
|
|
ALsizei pos = 0;
|
2016-09-02 00:29:46 -07:00
|
|
|
ALfloat gain = Gains[c];
|
2016-05-31 10:18:34 -07:00
|
|
|
if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gain4 = _mm_set1_ps(gain);
|
|
|
|
for(;BufferSize-pos > 3;pos += 4)
|
|
|
|
{
|
2016-10-04 16:25:43 -07:00
|
|
|
const __m128 val4 = _mm_load_ps(&data[c][InPos+pos]);
|
2016-05-31 10:18:34 -07:00
|
|
|
__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++)
|
2016-10-04 16:25:43 -07:00
|
|
|
OutBuffer[pos] += data[c][InPos+pos]*gain;
|
2016-05-31 10:18:34 -07:00
|
|
|
}
|
|
|
|
}
|