Don't pass the DirectParams to the dry-path mixer
[openal-soft.git] / Alc / mixer_c.c
blob700b326b22a97de4bc732f58e5228fa36651976f
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 void Resample_copy32_C(const ALfloat *data, ALuint UNUSED(frac),
19 ALuint increment, ALfloat *restrict OutBuffer, ALuint BufferSize)
21 assert(increment==FRACTIONONE);
22 memcpy(OutBuffer, data, BufferSize*sizeof(ALfloat));
25 #define DECL_TEMPLATE(Sampler) \
26 void Resample_##Sampler##_C(const ALfloat *data, ALuint frac, \
27 ALuint increment, ALfloat *restrict OutBuffer, ALuint BufferSize) \
28 { \
29 ALuint pos = 0; \
30 ALuint i; \
32 for(i = 0;i < BufferSize;i++) \
33 { \
34 OutBuffer[i] = Sampler(data + pos, frac); \
36 frac += increment; \
37 pos += frac>>FRACTIONBITS; \
38 frac &= FRACTIONMASK; \
39 } \
42 DECL_TEMPLATE(point32)
43 DECL_TEMPLATE(lerp32)
44 DECL_TEMPLATE(cubic32)
46 #undef DECL_TEMPLATE
49 void ALfilterState_processC(ALfilterState *filter, ALfloat *restrict dst, const ALfloat *src, ALuint numsamples)
51 ALuint i;
52 for(i = 0;i < numsamples;i++)
53 *(dst++) = ALfilterState_processSingle(filter, *(src++));
57 static inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
58 const ALuint IrSize,
59 ALfloat (*restrict Coeffs)[2],
60 const ALfloat (*restrict CoeffStep)[2],
61 ALfloat left, ALfloat right)
63 ALuint c;
64 for(c = 0;c < IrSize;c++)
66 const ALuint off = (Offset+c)&HRIR_MASK;
67 Values[off][0] += Coeffs[c][0] * left;
68 Values[off][1] += Coeffs[c][1] * right;
69 Coeffs[c][0] += CoeffStep[c][0];
70 Coeffs[c][1] += CoeffStep[c][1];
74 static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
75 const ALuint IrSize,
76 ALfloat (*restrict Coeffs)[2],
77 ALfloat left, ALfloat right)
79 ALuint c;
80 for(c = 0;c < IrSize;c++)
82 const ALuint off = (Offset+c)&HRIR_MASK;
83 Values[off][0] += Coeffs[c][0] * left;
84 Values[off][1] += Coeffs[c][1] * right;
88 #define SUFFIX C
89 #include "mixer_inc.c"
90 #undef SUFFIX
93 void MixDirect_C(ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat *data,
94 MixGains *Gains, ALuint Counter, ALuint OutPos, ALuint BufferSize)
96 ALfloat DrySend, Step;
97 ALuint c;
99 for(c = 0;c < MaxChannels;c++)
101 ALuint pos = 0;
102 DrySend = Gains->Current[c];
103 Step = Gains->Step[c];
104 if(Step != 1.0f && Counter > 0)
106 for(;pos < BufferSize && pos < Counter;pos++)
108 OutBuffer[c][OutPos+pos] += data[pos]*DrySend;
109 DrySend *= Step;
111 if(pos == Counter)
112 DrySend = Gains->Target[c];
113 Gains->Current[c] = DrySend;
116 if(!(DrySend > GAIN_SILENCE_THRESHOLD))
117 continue;
118 for(;pos < BufferSize;pos++)
119 OutBuffer[c][OutPos+pos] += data[pos]*DrySend;
124 void MixSend_C(SendParams *params, const ALfloat *restrict data,
125 ALuint OutPos, ALuint BufferSize)
127 ALfloat (*restrict OutBuffer)[BUFFERSIZE] = params->OutBuffer;
128 ALuint Counter = maxu(params->Counter, OutPos) - OutPos;
129 ALfloat WetSend, Step;
132 ALuint pos = 0;
133 WetSend = params->Gain.Current;
134 Step = params->Gain.Step;
135 if(Step != 1.0f && Counter > 0)
137 for(;pos < BufferSize && pos < Counter;pos++)
139 OutBuffer[0][OutPos+pos] += data[pos]*WetSend;
140 WetSend *= Step;
142 if(pos == Counter)
143 WetSend = params->Gain.Target;
144 params->Gain.Current = WetSend;
147 if(!(WetSend > GAIN_SILENCE_THRESHOLD))
148 return;
149 for(;pos < BufferSize;pos++)
150 OutBuffer[0][OutPos+pos] += data[pos] * WetSend;