Use WARN when implicitly deleting resources with the context
[openal-soft.git] / Alc / mixer_c.c
blobd9c8ca25e1a80e2b667cc8d73918c17bd6e4b48a
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 frac)
12 { return vals[0]; (void)frac; }
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 frac,
19 ALuint increment, ALfloat *RESTRICT OutBuffer, ALuint BufferSize)
21 (void)frac;
22 assert(increment==FRACTIONONE);
23 memcpy(OutBuffer, data, (BufferSize+1)*sizeof(ALfloat));
26 #define DECL_TEMPLATE(Sampler) \
27 void Resample_##Sampler##_C(const ALfloat *data, ALuint frac, \
28 ALuint increment, ALfloat *RESTRICT OutBuffer, ALuint BufferSize) \
29 { \
30 ALuint pos = 0; \
31 ALuint i; \
33 for(i = 0;i < BufferSize+1;i++) \
34 { \
35 OutBuffer[i] = Sampler(data + pos, frac); \
37 frac += increment; \
38 pos += frac>>FRACTIONBITS; \
39 frac &= FRACTIONMASK; \
40 } \
43 DECL_TEMPLATE(point32)
44 DECL_TEMPLATE(lerp32)
45 DECL_TEMPLATE(cubic32)
47 #undef DECL_TEMPLATE
50 static __inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*RESTRICT Values)[2],
51 const ALuint IrSize,
52 ALfloat (*RESTRICT Coeffs)[2],
53 const ALfloat (*RESTRICT CoeffStep)[2],
54 ALfloat left, ALfloat right)
56 ALuint c;
57 for(c = 0;c < IrSize;c++)
59 const ALuint off = (Offset+c)&HRIR_MASK;
60 Values[off][0] += Coeffs[c][0] * left;
61 Values[off][1] += Coeffs[c][1] * right;
62 Coeffs[c][0] += CoeffStep[c][0];
63 Coeffs[c][1] += CoeffStep[c][1];
67 static __inline void ApplyCoeffs(ALuint Offset, ALfloat (*RESTRICT Values)[2],
68 const ALuint IrSize,
69 ALfloat (*RESTRICT Coeffs)[2],
70 ALfloat left, ALfloat right)
72 ALuint c;
73 for(c = 0;c < IrSize;c++)
75 const ALuint off = (Offset+c)&HRIR_MASK;
76 Values[off][0] += Coeffs[c][0] * left;
77 Values[off][1] += Coeffs[c][1] * right;
81 #define SUFFIX C
82 #include "mixer_inc.c"
83 #undef SUFFIX
86 void MixDirect_C(const DirectParams *params, const ALfloat *RESTRICT data, ALuint srcchan,
87 ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
89 ALfloat (*RESTRICT DryBuffer)[BUFFERSIZE] = params->OutBuffer;
90 ALfloat *RESTRICT ClickRemoval = params->ClickRemoval;
91 ALfloat *RESTRICT PendingClicks = params->PendingClicks;
92 ALfloat DrySend;
93 ALuint pos;
94 ALuint c;
96 for(c = 0;c < MaxChannels;c++)
98 DrySend = params->Gains[srcchan][c];
99 if(DrySend < 0.00001f)
100 continue;
102 if(OutPos == 0)
103 ClickRemoval[c] -= data[0]*DrySend;
104 for(pos = 0;pos < BufferSize;pos++)
105 DryBuffer[c][OutPos+pos] += data[pos]*DrySend;
106 if(OutPos+pos == SamplesToDo)
107 PendingClicks[c] += data[pos]*DrySend;
112 void MixSend_C(const SendParams *params, const ALfloat *RESTRICT data,
113 ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
115 ALeffectslot *Slot = params->Slot;
116 ALfloat (*RESTRICT WetBuffer)[BUFFERSIZE] = Slot->WetBuffer;
117 ALfloat *RESTRICT WetClickRemoval = Slot->ClickRemoval;
118 ALfloat *RESTRICT WetPendingClicks = Slot->PendingClicks;
119 ALfloat WetSend = params->Gain;
120 ALuint pos;
122 if(WetSend < 0.00001f)
123 return;
125 if(OutPos == 0)
126 WetClickRemoval[0] -= data[0] * WetSend;
127 for(pos = 0;pos < BufferSize;pos++)
128 WetBuffer[0][OutPos+pos] += data[pos] * WetSend;
129 if(OutPos+pos == SamplesToDo)
130 WetPendingClicks[0] += data[pos] * WetSend;