Constify the direct and send parameters given to the mixer
[openal-soft.git] / OpenAL32 / Include / alu.h
blob32ea0047ad89820e73b55ca0393b69a2066ea5fd
1 #ifndef _ALU_H_
2 #define _ALU_H_
4 #include "alMain.h"
6 #include <limits.h>
7 #include <math.h>
8 #ifdef HAVE_FLOAT_H
9 #include <float.h>
10 #endif
11 #ifdef HAVE_IEEEFP_H
12 #include <ieeefp.h>
13 #endif
16 #define F_PI (3.14159265358979323846f) /* pi */
17 #define F_PI_2 (1.57079632679489661923f) /* pi/2 */
19 #ifndef FLT_EPSILON
20 #define FLT_EPSILON (1.19209290e-07f)
21 #endif
24 #ifndef HAVE_POWF
25 static __inline float powf(float x, float y)
26 { return (float)pow(x, y); }
27 #endif
29 #ifndef HAVE_SQRTF
30 static __inline float sqrtf(float x)
31 { return (float)sqrt(x); }
32 #endif
34 #ifndef HAVE_COSF
35 static __inline float cosf(float x)
36 { return (float)cos(x); }
37 #endif
39 #ifndef HAVE_SINF
40 static __inline float sinf(float x)
41 { return (float)sin(x); }
42 #endif
44 #ifndef HAVE_ACOSF
45 static __inline float acosf(float x)
46 { return (float)acos(x); }
47 #endif
49 #ifndef HAVE_ASINF
50 static __inline float asinf(float x)
51 { return (float)asin(x); }
52 #endif
54 #ifndef HAVE_ATANF
55 static __inline float atanf(float x)
56 { return (float)atan(x); }
57 #endif
59 #ifndef HAVE_ATAN2F
60 static __inline float atan2f(float x, float y)
61 { return (float)atan2(x, y); }
62 #endif
64 #ifndef HAVE_FABSF
65 static __inline float fabsf(float x)
66 { return (float)fabs(x); }
67 #endif
69 #ifndef HAVE_LOG10F
70 static __inline float log10f(float x)
71 { return (float)log10(x); }
72 #endif
74 #ifndef HAVE_FLOORF
75 static __inline float floorf(float x)
76 { return (float)floor(x); }
77 #endif
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
83 struct ALsource;
84 struct ALbuffer;
85 struct DirectParams;
86 struct SendParams;
88 typedef void (*ResamplerFunc)(const ALfloat *src, ALuint frac, ALuint increment,
89 ALfloat *RESTRICT dst, ALuint dstlen);
91 typedef ALvoid (*DryMixerFunc)(const struct DirectParams *params,
92 const ALfloat *RESTRICT data, ALuint srcchan,
93 ALuint OutPos, ALuint SamplesToDo,
94 ALuint BufferSize);
95 typedef ALvoid (*WetMixerFunc)(const struct SendParams *params,
96 const ALfloat *RESTRICT data,
97 ALuint OutPos, ALuint SamplesToDo,
98 ALuint BufferSize);
101 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
102 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
104 #define FRACTIONBITS (14)
105 #define FRACTIONONE (1<<FRACTIONBITS)
106 #define FRACTIONMASK (FRACTIONONE-1)
109 static __inline ALfloat minf(ALfloat a, ALfloat b)
110 { return ((a > b) ? b : a); }
111 static __inline ALfloat maxf(ALfloat a, ALfloat b)
112 { return ((a > b) ? a : b); }
113 static __inline ALfloat clampf(ALfloat val, ALfloat min, ALfloat max)
114 { return minf(max, maxf(min, val)); }
116 static __inline ALuint minu(ALuint a, ALuint b)
117 { return ((a > b) ? b : a); }
118 static __inline ALuint maxu(ALuint a, ALuint b)
119 { return ((a > b) ? a : b); }
120 static __inline ALuint clampu(ALuint val, ALuint min, ALuint max)
121 { return minu(max, maxu(min, val)); }
123 static __inline ALint mini(ALint a, ALint b)
124 { return ((a > b) ? b : a); }
125 static __inline ALint maxi(ALint a, ALint b)
126 { return ((a > b) ? a : b); }
127 static __inline ALint clampi(ALint val, ALint min, ALint max)
128 { return mini(max, maxi(min, val)); }
130 static __inline ALint64 mini64(ALint64 a, ALint64 b)
131 { return ((a > b) ? b : a); }
132 static __inline ALint64 maxi64(ALint64 a, ALint64 b)
133 { return ((a > b) ? a : b); }
134 static __inline ALint64 clampi64(ALint64 val, ALint64 min, ALint64 max)
135 { return mini64(max, maxi64(min, val)); }
137 static __inline ALuint64 minu64(ALuint64 a, ALuint64 b)
138 { return ((a > b) ? b : a); }
139 static __inline ALuint64 maxu64(ALuint64 a, ALuint64 b)
140 { return ((a > b) ? a : b); }
141 static __inline ALuint64 clampu64(ALuint64 val, ALuint64 min, ALuint64 max)
142 { return minu64(max, maxu64(min, val)); }
145 static __inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu)
147 return val1 + (val2-val1)*mu;
149 static __inline ALfloat cubic(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALfloat mu)
151 ALfloat mu2 = mu*mu;
152 ALfloat a0 = -0.5f*val0 + 1.5f*val1 + -1.5f*val2 + 0.5f*val3;
153 ALfloat a1 = val0 + -2.5f*val1 + 2.0f*val2 + -0.5f*val3;
154 ALfloat a2 = -0.5f*val0 + 0.5f*val2;
155 ALfloat a3 = val1;
157 return a0*mu*mu2 + a1*mu2 + a2*mu + a3;
161 static __inline void aluCrossproduct(const ALfloat *inVector1, const ALfloat *inVector2, ALfloat *outVector)
163 outVector[0] = inVector1[1]*inVector2[2] - inVector1[2]*inVector2[1];
164 outVector[1] = inVector1[2]*inVector2[0] - inVector1[0]*inVector2[2];
165 outVector[2] = inVector1[0]*inVector2[1] - inVector1[1]*inVector2[0];
168 static __inline ALfloat aluDotproduct(const ALfloat *inVector1, const ALfloat *inVector2)
170 return inVector1[0]*inVector2[0] + inVector1[1]*inVector2[1] +
171 inVector1[2]*inVector2[2];
174 static __inline void aluNormalize(ALfloat *inVector)
176 ALfloat lengthsqr = aluDotproduct(inVector, inVector);
177 if(lengthsqr > 0.0f)
179 ALfloat inv_length = 1.0f/sqrtf(lengthsqr);
180 inVector[0] *= inv_length;
181 inVector[1] *= inv_length;
182 inVector[2] *= inv_length;
187 ALvoid aluInitPanning(ALCdevice *Device);
189 ALvoid ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, ALfloat ingain, ALfloat *gains);
191 ALvoid CalcSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
192 ALvoid CalcNonAttnSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
194 ALvoid MixSource(struct ALsource *Source, ALCdevice *Device, ALuint SamplesToDo);
196 ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size);
197 ALvoid aluHandleDisconnect(ALCdevice *device);
199 extern ALfloat ConeScale;
200 extern ALfloat ZScale;
202 #ifdef __cplusplus
204 #endif
206 #endif