Check the distance against epsilon to determine if it matches
[openal-soft.git] / OpenAL32 / Include / alu.h
blobd4339d9669044dd76c05bf6927fd9a0a949e4bc9
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)(struct ALsource *self, ALCdevice *Device,
92 struct DirectParams *params,
93 const ALfloat *RESTRICT data, ALuint srcchan,
94 ALuint OutPos, ALuint SamplesToDo,
95 ALuint BufferSize);
96 typedef ALvoid (*WetMixerFunc)(struct SendParams *params,
97 const ALfloat *RESTRICT data,
98 ALuint OutPos, ALuint SamplesToDo,
99 ALuint BufferSize);
102 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
103 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
105 #define FRACTIONBITS (14)
106 #define FRACTIONONE (1<<FRACTIONBITS)
107 #define FRACTIONMASK (FRACTIONONE-1)
110 static __inline ALfloat minf(ALfloat a, ALfloat b)
111 { return ((a > b) ? b : a); }
112 static __inline ALfloat maxf(ALfloat a, ALfloat b)
113 { return ((a > b) ? a : b); }
114 static __inline ALfloat clampf(ALfloat val, ALfloat min, ALfloat max)
115 { return minf(max, maxf(min, val)); }
117 static __inline ALuint minu(ALuint a, ALuint b)
118 { return ((a > b) ? b : a); }
119 static __inline ALuint maxu(ALuint a, ALuint b)
120 { return ((a > b) ? a : b); }
121 static __inline ALuint clampu(ALuint val, ALuint min, ALuint max)
122 { return minu(max, maxu(min, val)); }
124 static __inline ALint mini(ALint a, ALint b)
125 { return ((a > b) ? b : a); }
126 static __inline ALint maxi(ALint a, ALint b)
127 { return ((a > b) ? a : b); }
128 static __inline ALint clampi(ALint val, ALint min, ALint max)
129 { return mini(max, maxi(min, val)); }
131 static __inline ALint64 mini64(ALint64 a, ALint64 b)
132 { return ((a > b) ? b : a); }
133 static __inline ALint64 maxi64(ALint64 a, ALint64 b)
134 { return ((a > b) ? a : b); }
135 static __inline ALint64 clampi64(ALint64 val, ALint64 min, ALint64 max)
136 { return mini64(max, maxi64(min, val)); }
138 static __inline ALuint64 minu64(ALuint64 a, ALuint64 b)
139 { return ((a > b) ? b : a); }
140 static __inline ALuint64 maxu64(ALuint64 a, ALuint64 b)
141 { return ((a > b) ? a : b); }
142 static __inline ALuint64 clampu64(ALuint64 val, ALuint64 min, ALuint64 max)
143 { return minu64(max, maxu64(min, val)); }
146 static __inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu)
148 return val1 + (val2-val1)*mu;
150 static __inline ALfloat cubic(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALfloat mu)
152 ALfloat mu2 = mu*mu;
153 ALfloat a0 = -0.5f*val0 + 1.5f*val1 + -1.5f*val2 + 0.5f*val3;
154 ALfloat a1 = val0 + -2.5f*val1 + 2.0f*val2 + -0.5f*val3;
155 ALfloat a2 = -0.5f*val0 + 0.5f*val2;
156 ALfloat a3 = val1;
158 return a0*mu*mu2 + a1*mu2 + a2*mu + a3;
162 static __inline void aluCrossproduct(const ALfloat *inVector1, const ALfloat *inVector2, ALfloat *outVector)
164 outVector[0] = inVector1[1]*inVector2[2] - inVector1[2]*inVector2[1];
165 outVector[1] = inVector1[2]*inVector2[0] - inVector1[0]*inVector2[2];
166 outVector[2] = inVector1[0]*inVector2[1] - inVector1[1]*inVector2[0];
169 static __inline ALfloat aluDotproduct(const ALfloat *inVector1, const ALfloat *inVector2)
171 return inVector1[0]*inVector2[0] + inVector1[1]*inVector2[1] +
172 inVector1[2]*inVector2[2];
175 static __inline void aluNormalize(ALfloat *inVector)
177 ALfloat lengthsqr = aluDotproduct(inVector, inVector);
178 if(lengthsqr > 0.0f)
180 ALfloat inv_length = 1.0f/sqrtf(lengthsqr);
181 inVector[0] *= inv_length;
182 inVector[1] *= inv_length;
183 inVector[2] *= inv_length;
188 ALvoid aluInitPanning(ALCdevice *Device);
190 ALvoid ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, ALfloat ingain, ALfloat *gains);
192 ALvoid CalcSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
193 ALvoid CalcNonAttnSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
195 ALvoid MixSource(struct ALsource *Source, ALCdevice *Device, ALuint SamplesToDo);
197 ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size);
198 ALvoid aluHandleDisconnect(ALCdevice *device);
200 extern ALfloat ConeScale;
201 extern ALfloat ZScale;
203 #ifdef __cplusplus
205 #endif
207 #endif