Use an ambisonics-based panning method
[openal-soft.git] / Alc / mixer_c.c
blobf3a229e5cf88153f8c53c8c691f01b748eea9f97
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 ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
63 const ALuint IrSize,
64 ALfloat (*restrict Coeffs)[2],
65 const ALfloat (*restrict CoeffStep)[2],
66 ALfloat left, ALfloat right)
68 ALuint c;
69 for(c = 0;c < IrSize;c++)
71 const ALuint off = (Offset+c)&HRIR_MASK;
72 Values[off][0] += Coeffs[c][0] * left;
73 Values[off][1] += Coeffs[c][1] * right;
74 Coeffs[c][0] += CoeffStep[c][0];
75 Coeffs[c][1] += CoeffStep[c][1];
79 static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
80 const ALuint IrSize,
81 ALfloat (*restrict Coeffs)[2],
82 ALfloat left, ALfloat right)
84 ALuint c;
85 for(c = 0;c < IrSize;c++)
87 const ALuint off = (Offset+c)&HRIR_MASK;
88 Values[off][0] += Coeffs[c][0] * left;
89 Values[off][1] += Coeffs[c][1] * right;
93 #define SUFFIX C
94 #include "mixer_inc.c"
95 #undef SUFFIX
98 void Mix_C(const ALfloat *data, ALuint OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE],
99 MixGains *Gains, ALuint Counter, ALuint OutPos, ALuint BufferSize)
101 ALfloat gain, step;
102 ALuint c;
104 for(c = 0;c < OutChans;c++)
106 ALuint pos = 0;
107 gain = Gains[c].Current;
108 step = Gains[c].Step;
109 if(step != 1.0f && Counter > 0)
111 for(;pos < BufferSize && pos < Counter;pos++)
113 OutBuffer[c][OutPos+pos] += data[pos]*gain;
114 gain *= step;
116 if(pos == Counter)
117 gain = Gains[c].Target;
118 Gains[c].Current = gain;
121 if(!(gain > GAIN_SILENCE_THRESHOLD))
122 continue;
123 for(;pos < BufferSize;pos++)
124 OutBuffer[c][OutPos+pos] += data[pos]*gain;