Move atomic method definitions to a separate common source
[openal-soft.git] / Alc / mixer_c.c
blob2b8325ae21c8e40bdfaac841dc5327c2bddcc0fa
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 static inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*restrict Values)[2],
50 const ALuint IrSize,
51 ALfloat (*restrict Coeffs)[2],
52 const ALfloat (*restrict CoeffStep)[2],
53 ALfloat left, ALfloat right)
55 ALuint c;
56 for(c = 0;c < IrSize;c++)
58 const ALuint off = (Offset+c)&HRIR_MASK;
59 Values[off][0] += Coeffs[c][0] * left;
60 Values[off][1] += Coeffs[c][1] * right;
61 Coeffs[c][0] += CoeffStep[c][0];
62 Coeffs[c][1] += CoeffStep[c][1];
66 static inline void ApplyCoeffs(ALuint Offset, ALfloat (*restrict Values)[2],
67 const ALuint IrSize,
68 ALfloat (*restrict Coeffs)[2],
69 ALfloat left, ALfloat right)
71 ALuint c;
72 for(c = 0;c < IrSize;c++)
74 const ALuint off = (Offset+c)&HRIR_MASK;
75 Values[off][0] += Coeffs[c][0] * left;
76 Values[off][1] += Coeffs[c][1] * right;
80 #define SUFFIX C
81 #include "mixer_inc.c"
82 #undef SUFFIX
85 void MixDirect_C(DirectParams *params, const ALfloat *restrict data, ALuint srcchan,
86 ALuint OutPos, ALuint BufferSize)
88 ALfloat (*restrict OutBuffer)[BUFFERSIZE] = params->OutBuffer;
89 ALuint Counter = maxu(params->Counter, OutPos) - OutPos;
90 ALfloat DrySend, Step;
91 ALuint c;
93 for(c = 0;c < MaxChannels;c++)
95 ALuint pos = 0;
96 DrySend = params->Mix.Gains.Current[srcchan][c];
97 Step = params->Mix.Gains.Step[srcchan][c];
98 if(Step != 1.0f && Counter > 0)
100 for(;pos < BufferSize && pos < Counter;pos++)
102 OutBuffer[c][OutPos+pos] += data[pos]*DrySend;
103 DrySend *= Step;
105 if(pos == Counter)
106 DrySend = params->Mix.Gains.Target[srcchan][c];
107 params->Mix.Gains.Current[srcchan][c] = DrySend;
110 if(!(DrySend > GAIN_SILENCE_THRESHOLD))
111 continue;
112 for(;pos < BufferSize;pos++)
113 OutBuffer[c][OutPos+pos] += data[pos]*DrySend;
118 void MixSend_C(SendParams *params, const ALfloat *restrict data,
119 ALuint OutPos, ALuint BufferSize)
121 ALfloat (*restrict OutBuffer)[BUFFERSIZE] = params->OutBuffer;
122 ALuint Counter = maxu(params->Counter, OutPos) - OutPos;
123 ALfloat WetSend, Step;
126 ALuint pos = 0;
127 WetSend = params->Gain.Current;
128 Step = params->Gain.Step;
129 if(Step != 1.0f && Counter > 0)
131 for(;pos < BufferSize && pos < Counter;pos++)
133 OutBuffer[0][OutPos+pos] += data[pos]*WetSend;
134 WetSend *= Step;
136 if(pos == Counter)
137 WetSend = params->Gain.Target;
138 params->Gain.Current = WetSend;
141 if(!(WetSend > GAIN_SILENCE_THRESHOLD))
142 return;
143 for(;pos < BufferSize;pos++)
144 OutBuffer[0][OutPos+pos] += data[pos] * WetSend;