Move a couple macros to more appropriate headers
[openal-soft.git] / OpenAL32 / Include / alu.h
bloba4ad48c8851fdea6cd02b34fd1178304712b9b48
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 HAVE_POWF
20 static __inline float powf(float x, float y)
21 { return (float)pow(x, y); }
22 #endif
24 #ifndef HAVE_SQRTF
25 static __inline float sqrtf(float x)
26 { return (float)sqrt(x); }
27 #endif
29 #ifndef HAVE_COSF
30 static __inline float cosf(float x)
31 { return (float)cos(x); }
32 #endif
34 #ifndef HAVE_SINF
35 static __inline float sinf(float x)
36 { return (float)sin(x); }
37 #endif
39 #ifndef HAVE_ACOSF
40 static __inline float acosf(float x)
41 { return (float)acos(x); }
42 #endif
44 #ifndef HAVE_ASINF
45 static __inline float asinf(float x)
46 { return (float)asin(x); }
47 #endif
49 #ifndef HAVE_ATANF
50 static __inline float atanf(float x)
51 { return (float)atan(x); }
52 #endif
54 #ifndef HAVE_ATAN2F
55 static __inline float atan2f(float x, float y)
56 { return (float)atan2(x, y); }
57 #endif
59 #ifndef HAVE_FABSF
60 static __inline float fabsf(float x)
61 { return (float)fabs(x); }
62 #endif
64 #ifndef HAVE_LOG10F
65 static __inline float log10f(float x)
66 { return (float)log10(x); }
67 #endif
69 #ifndef HAVE_FLOORF
70 static __inline float floorf(float x)
71 { return (float)floor(x); }
72 #endif
74 #ifdef __cplusplus
75 extern "C" {
76 #endif
78 struct ALsource;
79 struct ALbuffer;
80 struct DirectParams;
81 struct SendParams;
83 typedef ALvoid (*DryMixerFunc)(struct ALsource *self, ALCdevice *Device,
84 struct DirectParams *params,
85 const ALfloat *RESTRICT data, ALuint srcchan,
86 ALuint OutPos, ALuint SamplesToDo,
87 ALuint BufferSize);
88 typedef ALvoid (*WetMixerFunc)(struct SendParams *params,
89 const ALfloat *RESTRICT data,
90 ALuint OutPos, ALuint SamplesToDo,
91 ALuint BufferSize);
94 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
95 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
97 #define FRACTIONBITS (14)
98 #define FRACTIONONE (1<<FRACTIONBITS)
99 #define FRACTIONMASK (FRACTIONONE-1)
102 static __inline ALfloat minf(ALfloat a, ALfloat b)
103 { return ((a > b) ? b : a); }
104 static __inline ALfloat maxf(ALfloat a, ALfloat b)
105 { return ((a > b) ? a : b); }
106 static __inline ALfloat clampf(ALfloat val, ALfloat min, ALfloat max)
107 { return minf(max, maxf(min, val)); }
109 static __inline ALuint minu(ALuint a, ALuint b)
110 { return ((a > b) ? b : a); }
111 static __inline ALuint maxu(ALuint a, ALuint b)
112 { return ((a > b) ? a : b); }
113 static __inline ALuint clampu(ALuint val, ALuint min, ALuint max)
114 { return minu(max, maxu(min, val)); }
116 static __inline ALint mini(ALint a, ALint b)
117 { return ((a > b) ? b : a); }
118 static __inline ALint maxi(ALint a, ALint b)
119 { return ((a > b) ? a : b); }
120 static __inline ALint clampi(ALint val, ALint min, ALint max)
121 { return mini(max, maxi(min, val)); }
123 static __inline ALint64 mini64(ALint64 a, ALint64 b)
124 { return ((a > b) ? b : a); }
125 static __inline ALint64 maxi64(ALint64 a, ALint64 b)
126 { return ((a > b) ? a : b); }
127 static __inline ALint64 clampi64(ALint64 val, ALint64 min, ALint64 max)
128 { return mini64(max, maxi64(min, val)); }
130 static __inline ALuint64 minu64(ALuint64 a, ALuint64 b)
131 { return ((a > b) ? b : a); }
132 static __inline ALuint64 maxu64(ALuint64 a, ALuint64 b)
133 { return ((a > b) ? a : b); }
134 static __inline ALuint64 clampu64(ALuint64 val, ALuint64 min, ALuint64 max)
135 { return minu64(max, maxu64(min, val)); }
138 static __inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu)
140 return val1 + (val2-val1)*mu;
142 static __inline ALfloat cubic(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALfloat mu)
144 ALfloat mu2 = mu*mu;
145 ALfloat a0 = -0.5f*val0 + 1.5f*val1 + -1.5f*val2 + 0.5f*val3;
146 ALfloat a1 = val0 + -2.5f*val1 + 2.0f*val2 + -0.5f*val3;
147 ALfloat a2 = -0.5f*val0 + 0.5f*val2;
148 ALfloat a3 = val1;
150 return a0*mu*mu2 + a1*mu2 + a2*mu + a3;
154 static __inline void aluCrossproduct(const ALfloat *inVector1, const ALfloat *inVector2, ALfloat *outVector)
156 outVector[0] = inVector1[1]*inVector2[2] - inVector1[2]*inVector2[1];
157 outVector[1] = inVector1[2]*inVector2[0] - inVector1[0]*inVector2[2];
158 outVector[2] = inVector1[0]*inVector2[1] - inVector1[1]*inVector2[0];
161 static __inline ALfloat aluDotproduct(const ALfloat *inVector1, const ALfloat *inVector2)
163 return inVector1[0]*inVector2[0] + inVector1[1]*inVector2[1] +
164 inVector1[2]*inVector2[2];
167 static __inline void aluNormalize(ALfloat *inVector)
169 ALfloat lengthsqr = aluDotproduct(inVector, inVector);
170 if(lengthsqr > 0.0f)
172 ALfloat inv_length = 1.0f/sqrtf(lengthsqr);
173 inVector[0] *= inv_length;
174 inVector[1] *= inv_length;
175 inVector[2] *= inv_length;
180 ALvoid aluInitPanning(ALCdevice *Device);
182 ALvoid ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, ALfloat ingain, ALfloat *gains);
184 ALvoid CalcSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
185 ALvoid CalcNonAttnSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
187 ALvoid MixSource(struct ALsource *Source, ALCdevice *Device, ALuint SamplesToDo);
189 ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size);
190 ALvoid aluHandleDisconnect(ALCdevice *device);
192 extern ALfloat ConeScale;
193 extern ALfloat ZScale;
195 #ifdef __cplusplus
197 #endif
199 #endif