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"
|
2018-03-22 05:06:15 -07:00
|
|
|
#include "defs.h"
|
2012-09-09 00:53:54 -07:00
|
|
|
|
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
|
|
|
|
2018-04-17 22:50:50 -07:00
|
|
|
ASSUME(m > 0);
|
2018-04-18 20:39:52 -07:00
|
|
|
ASSUME(dstlen > 0);
|
2018-04-17 22:50:50 -07: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;
|
2017-10-07 15:28:35 -07:00
|
|
|
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);
|
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
|
2018-03-22 05:41:42 -07:00
|
|
|
#include "hrtf_inc.c"
|
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
|
|
|
{
|
2018-05-14 23:41:29 -07:00
|
|
|
const ALfloat delta = (Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f;
|
2017-01-16 07:45:07 -08:00
|
|
|
ALsizei c;
|
2012-09-09 00:53:54 -07:00
|
|
|
|
2018-04-21 02:44:01 -07:00
|
|
|
ASSUME(OutChans > 0);
|
2018-04-18 20:39:52 -07:00
|
|
|
ASSUME(BufferSize > 0);
|
2016-10-05 20:33:45 -07:00
|
|
|
|
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;
|
2018-05-14 23:41:29 -07:00
|
|
|
ALfloat gain = CurrentGains[c];
|
|
|
|
const ALfloat step = (TargetGains[c] - gain) * delta;
|
|
|
|
|
2016-10-05 20:33:45 -07:00
|
|
|
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);
|
2018-05-14 23:41:29 -07:00
|
|
|
ALfloat step_count = 0.0f;
|
2014-05-03 17:24:46 -07:00
|
|
|
/* Mix with applying gain steps in aligned multiples of 4. */
|
2018-05-14 23:41:29 -07:00
|
|
|
if(LIKELY(minsize > 3))
|
2014-03-23 06:57:00 -07:00
|
|
|
{
|
2018-05-14 23:41:29 -07:00
|
|
|
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;
|
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]);
|
2018-05-14 23:41:29 -07:00
|
|
|
#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
|
2014-03-23 06:57:00 -07:00
|
|
|
_mm_store_ps(&OutBuffer[c][OutPos+pos], dry4);
|
2018-05-14 23:41:29 -07:00
|
|
|
step_count4 = _mm_add_ps(step_count4, four4);
|
2014-03-23 06:57:00 -07:00
|
|
|
pos += 4;
|
2018-05-14 23:41:29 -07:00
|
|
|
} 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.
|
2015-10-25 14:07:58 -07:00
|
|
|
*/
|
2018-05-14 23:41:29 -07:00
|
|
|
step_count = _mm_cvtss_f32(step_count4);
|
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
|
|
|
{
|
2018-05-14 23:41:29 -07:00
|
|
|
OutBuffer[c][OutPos+pos] += data[pos]*(gain + step*step_count);
|
|
|
|
step_count += 1.0f;
|
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];
|
2018-05-14 23:41:29 -07:00
|
|
|
else
|
|
|
|
gain += step*step_count;
|
2016-10-05 20:33:45 -07:00
|
|
|
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;
|
2018-05-14 23:41:29 -07:00
|
|
|
if(LIKELY(BufferSize-pos > 3))
|
2012-09-09 04:02:54 -07:00
|
|
|
{
|
2018-05-14 23:41:29 -07:00
|
|
|
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(&OutBuffer[c][OutPos+pos]);
|
|
|
|
dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4));
|
|
|
|
_mm_store_ps(&OutBuffer[c][OutPos+pos], dry4);
|
|
|
|
pos += 4;
|
|
|
|
} while(--todo);
|
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
|
|
|
{
|
2017-01-16 07:45:07 -08:00
|
|
|
ALsizei c;
|
2016-05-31 10:18:34 -07:00
|
|
|
|
2018-04-21 02:44:01 -07:00
|
|
|
ASSUME(InChans > 0);
|
2018-04-18 20:39:52 -07:00
|
|
|
ASSUME(BufferSize > 0);
|
|
|
|
|
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;
|
|
|
|
|
2018-05-15 23:14:23 -07:00
|
|
|
if(LIKELY(BufferSize > 3))
|
2016-05-31 10:18:34 -07:00
|
|
|
{
|
2018-05-15 23:14:23 -07:00
|
|
|
ALsizei todo = BufferSize >> 2;
|
|
|
|
const __m128 gain4 = _mm_set1_ps(gain);
|
|
|
|
do {
|
|
|
|
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);
|
|
|
|
pos += 4;
|
|
|
|
} while(--todo);
|
2016-05-31 10:18:34 -07:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|