Use an unsigned type for the sample position fraction
[openal-soft.git] / Alc / mixer_c.c
blobb1ffb11b433127235f73bc6a960a2440ffc1e9ca
1 #include "config.h"
3 #include "alMain.h"
4 #include "alu.h"
5 #include "alSource.h"
6 #include "alAuxEffectSlot.h"
9 static __inline ALfloat point32(const ALfloat *vals, ALuint frac)
10 { return vals[0]; (void)frac; }
11 static __inline ALfloat lerp32(const ALfloat *vals, ALuint frac)
12 { return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); }
13 static __inline ALfloat cubic32(const ALfloat *vals, ALuint frac)
14 { return cubic(vals[-1], vals[0], vals[1], vals[2], frac * (1.0f/FRACTIONONE)); }
16 #define DECL_TEMPLATE(Sampler) \
17 void Resample_##Sampler##_C(const ALfloat *data, ALuint frac, \
18 ALuint increment, ALfloat *RESTRICT OutBuffer, ALuint BufferSize) \
19 { \
20 ALuint pos = 0; \
21 ALuint i; \
23 for(i = 0;i < BufferSize+1;i++) \
24 { \
25 OutBuffer[i] = Sampler(data + pos, frac); \
27 frac += increment; \
28 pos += frac>>FRACTIONBITS; \
29 frac &= FRACTIONMASK; \
30 } \
33 DECL_TEMPLATE(point32)
34 DECL_TEMPLATE(lerp32)
35 DECL_TEMPLATE(cubic32)
37 #undef DECL_TEMPLATE
40 static __inline void ApplyCoeffsStep(ALuint Offset, ALfloat (*RESTRICT Values)[2],
41 const ALuint IrSize,
42 ALfloat (*RESTRICT Coeffs)[2],
43 ALfloat (*RESTRICT CoeffStep)[2],
44 ALfloat left, ALfloat right)
46 ALuint c;
47 for(c = 0;c < IrSize;c++)
49 const ALuint off = (Offset+c)&HRIR_MASK;
50 Values[off][0] += Coeffs[c][0] * left;
51 Values[off][1] += Coeffs[c][1] * right;
52 Coeffs[c][0] += CoeffStep[c][0];
53 Coeffs[c][1] += CoeffStep[c][1];
57 static __inline void ApplyCoeffs(ALuint Offset, ALfloat (*RESTRICT Values)[2],
58 const ALuint IrSize,
59 ALfloat (*RESTRICT Coeffs)[2],
60 ALfloat left, ALfloat right)
62 ALuint c;
63 for(c = 0;c < IrSize;c++)
65 const ALuint off = (Offset+c)&HRIR_MASK;
66 Values[off][0] += Coeffs[c][0] * left;
67 Values[off][1] += Coeffs[c][1] * right;
71 #define SUFFIX C
72 #include "mixer_inc.c"
73 #undef SUFFIX
76 void MixDirect_C(ALsource *Source, ALCdevice *Device, DirectParams *params,
77 const ALfloat *RESTRICT data, ALuint srcchan,
78 ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
80 ALfloat (*RESTRICT DryBuffer)[BUFFERSIZE] = Device->DryBuffer;
81 ALfloat *RESTRICT ClickRemoval = Device->ClickRemoval;
82 ALfloat *RESTRICT PendingClicks = Device->PendingClicks;
83 ALfloat DrySend;
84 ALuint pos;
85 ALuint c;
86 (void)Source;
88 for(c = 0;c < MaxChannels;c++)
90 DrySend = params->Gains[srcchan][c];
91 if(DrySend < 0.00001f)
92 continue;
94 if(OutPos == 0)
95 ClickRemoval[c] -= data[0]*DrySend;
96 for(pos = 0;pos < BufferSize;pos++)
97 DryBuffer[c][OutPos+pos] += data[pos]*DrySend;
98 if(OutPos+pos == SamplesToDo)
99 PendingClicks[c] += data[pos]*DrySend;
104 void MixSend_C(SendParams *params, const ALfloat *RESTRICT data,
105 ALuint OutPos, ALuint SamplesToDo, ALuint BufferSize)
107 ALeffectslot *Slot = params->Slot;
108 ALfloat (*RESTRICT WetBuffer)[BUFFERSIZE] = Slot->WetBuffer;
109 ALfloat *RESTRICT WetClickRemoval = Slot->ClickRemoval;
110 ALfloat *RESTRICT WetPendingClicks = Slot->PendingClicks;
111 ALfloat WetSend = params->Gain;
112 ALuint pos;
114 if(OutPos == 0)
115 WetClickRemoval[0] -= data[0] * WetSend;
116 for(pos = 0;pos < BufferSize;pos++)
117 WetBuffer[0][OutPos+pos] += data[pos] * WetSend;
118 if(OutPos+pos == SamplesToDo)
119 WetPendingClicks[0] += data[pos] * WetSend;