Rework HRTF decision logic
[openal-soft.git] / Alc / mixer_c.c
blobcaedd339008b6548284db6c34feb4104064874e1
1 #include "config.h"
3 #include <assert.h>
5 #include "alMain.h"
6 #include "alu.h"
7 #include "alSource.h"
8 #include "alAuxEffectSlot.h"
11 static inline ALfloat point32(const ALfloat *vals, ALuint UNUSED(frac))
12 { return vals[0]; }
13 static inline ALfloat lerp32(const ALfloat *vals, ALuint frac)
14 { return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); }
15 static inline ALfloat cubic32(const ALfloat *vals, ALuint frac)
16 { return cubic(vals[-1], vals[0], vals[1], vals[2], frac * (1.0f/FRACTIONONE)); }
18 const ALfloat *Resample_copy32_C(const ALfloat *src, ALuint UNUSED(frac),
19 ALuint increment, ALfloat *restrict dst, ALuint numsamples)
21 assert(increment==FRACTIONONE);
22 #if defined(HAVE_SSE) || defined(HAVE_NEON)
23 /* Avoid copying the source data if it's aligned like the destination. */
24 if((((intptr_t)src)&15) == (((intptr_t)dst)&15))
25 return src;
26 #endif
27 memcpy(dst, src, numsamples*sizeof(ALfloat));
28 return dst;
31 #define DECL_TEMPLATE(Sampler) \
32 const ALfloat *Resample_##Sampler##_C(const ALfloat *src, ALuint frac, \
33 ALuint increment, ALfloat *restrict dst, ALuint numsamples) \
34 { \
35 ALuint i; \
36 for(i = 0;i < numsamples;i++) \
37 { \
38 dst[i] = Sampler(src, frac); \
40 frac += increment; \
41 src += frac>>FRACTIONBITS; \
42 frac &= FRACTIONMASK; \
43 } \
44 return dst; \
47 DECL_TEMPLATE(point32)
48 DECL_TEMPLATE(lerp32)
49 DECL_TEMPLATE(cubic32)
51 #undef DECL_TEMPLATE
54 void ALfilterState_processC(ALfilterState *filter, ALfloat *restrict dst, const ALfloat *src, ALuint numsamples)
56 ALuint i;
57 for(i = 0;i < numsamples;i++)
58 *(dst++) = ALfilterState_processSingle(filter, *(src++));
62 static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
63 const ALuint IrSize,
64 ALfloat (*restrict Coeffs)[2],
65 ALfloat left, ALfloat right)
67 ALuint c;
68 for(c = 0;c < IrSize;c++)
70 const ALuint off = (Offset+c)&HRIR_MASK;
71 Values[off][0] += Coeffs[c][0] * left;
72 Values[off][1] += Coeffs[c][1] * right;
76 #define SUFFIX C
77 #include "mixer_inc.c"
78 #undef SUFFIX
81 void Mix_C(const ALfloat *data, ALuint OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
82 MixGains *Gains, ALuint Counter, ALuint OutPos, ALuint BufferSize)
84 ALfloat gain, step;
85 ALuint c;
87 for(c = 0;c < OutChans;c++)
89 ALuint pos = 0;
90 gain = Gains[c].Current;
91 step = Gains[c].Step;
92 if(step != 1.0f && Counter > 0)
94 for(;pos < BufferSize && pos < Counter;pos++)
96 OutBuffer[c][OutPos+pos] += data[pos]*gain;
97 gain *= step;
99 if(pos == Counter)
100 gain = Gains[c].Target;
101 Gains[c].Current = gain;
104 if(!(fabsf(gain) > GAIN_SILENCE_THRESHOLD))
105 continue;
106 for(;pos < BufferSize;pos++)
107 OutBuffer[c][OutPos+pos] += data[pos]*gain;