Move ConeScale and ZScale to ALu.c and alu.h, and make them floats
[openal-soft/openal-hmr.git] / OpenAL32 / Include / alu.h
bloba62ca1c55aec5192b4eff864c2b37bc95b23cf42
1 #ifndef _ALU_H_
2 #define _ALU_H_
4 #include "AL/al.h"
5 #include "AL/alc.h"
6 #include "AL/alext.h"
8 #include <limits.h>
9 #include <math.h>
10 #ifdef HAVE_FLOAT_H
11 #include <float.h>
12 #endif
13 #ifdef HAVE_IEEEFP_H
14 #include <ieeefp.h>
15 #endif
17 #ifndef M_PI
18 #define M_PI 3.14159265358979323846 /* pi */
19 #define M_PI_2 1.57079632679489661923 /* pi/2 */
20 #endif
22 #define F_PI ((float)M_PI)
23 #define F_PI_2 ((float)M_PI_2)
25 #ifdef HAVE_POWF
26 #define aluPow(x,y) (powf((x),(y)))
27 #else
28 #define aluPow(x,y) ((ALfloat)pow((double)(x),(double)(y)))
29 #endif
31 #ifdef HAVE_SQRTF
32 #define aluSqrt(x) (sqrtf((x)))
33 #else
34 #define aluSqrt(x) ((ALfloat)sqrt((double)(x)))
35 #endif
37 #ifdef HAVE_COSF
38 #define aluCos(x) (cosf((x)))
39 #else
40 #define aluCos(x) ((ALfloat)cos((double)(x)))
41 #endif
43 #ifdef HAVE_SINF
44 #define aluSin(x) (sinf((x)))
45 #else
46 #define aluSin(x) ((ALfloat)sin((double)(x)))
47 #endif
49 #ifdef HAVE_ACOSF
50 #define aluAcos(x) (acosf((x)))
51 #else
52 #define aluAcos(x) ((ALfloat)acos((double)(x)))
53 #endif
55 #ifdef HAVE_ATANF
56 #define aluAtan(x) (atanf((x)))
57 #else
58 #define aluAtan(x) ((ALfloat)atan((double)(x)))
59 #endif
61 #ifdef HAVE_FABSF
62 #define aluFabs(x) (fabsf((x)))
63 #else
64 #define aluFabs(x) ((ALfloat)fabs((double)(x)))
65 #endif
67 #define QUADRANT_NUM 128
68 #define LUT_NUM (4 * QUADRANT_NUM)
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
74 struct ALsource;
75 struct ALbuffer;
77 typedef ALvoid (*MixerFunc)(struct ALsource *self, ALCdevice *Device,
78 const ALvoid *RESTRICT data,
79 ALuint *DataPosInt, ALuint *DataPosFrac,
80 ALuint OutPos, ALuint SamplesToDo,
81 ALuint BufferSize);
83 enum Resampler {
84 POINT_RESAMPLER = 0,
85 LINEAR_RESAMPLER,
86 CUBIC_RESAMPLER,
88 RESAMPLER_MAX,
89 RESAMPLER_MIN = -1,
90 RESAMPLER_DEFAULT = LINEAR_RESAMPLER
93 enum Channel {
94 FRONT_LEFT = 0,
95 FRONT_RIGHT,
96 FRONT_CENTER,
97 LFE,
98 BACK_LEFT,
99 BACK_RIGHT,
100 BACK_CENTER,
101 SIDE_LEFT,
102 SIDE_RIGHT,
104 MAXCHANNELS
107 enum DistanceModel {
108 InverseDistanceClamped = AL_INVERSE_DISTANCE_CLAMPED,
109 LinearDistanceClamped = AL_LINEAR_DISTANCE_CLAMPED,
110 ExponentDistanceClamped = AL_EXPONENT_DISTANCE_CLAMPED,
111 InverseDistance = AL_INVERSE_DISTANCE,
112 LinearDistance = AL_LINEAR_DISTANCE,
113 ExponentDistance = AL_EXPONENT_DISTANCE,
114 DisableDistance = AL_NONE
117 #define BUFFERSIZE 4096
119 #define FRACTIONBITS (14)
120 #define FRACTIONONE (1<<FRACTIONBITS)
121 #define FRACTIONMASK (FRACTIONONE-1)
123 /* Size for temporary stack storage of buffer data. Larger values need more
124 * stack, while smaller values may need more iterations. The value needs to be
125 * a sensible size, however, as it constrains the max stepping value used for
126 * mixing.
127 * The mixer requires being able to do two samplings per mixing loop. A 16KB
128 * buffer can hold 512 sample frames for a 7.1 float buffer. With the cubic
129 * resampler (which requires 3 padding sample frames), this limits the maximum
130 * step to about 508. This means that buffer_freq*source_pitch cannot exceed
131 * device_freq*508 for an 8-channel 32-bit buffer. */
132 #ifndef STACK_DATA_SIZE
133 #define STACK_DATA_SIZE 16384
134 #endif
137 static __inline ALfloat minf(ALfloat a, ALfloat b)
138 { return ((a > b) ? b : a); }
139 static __inline ALfloat maxf(ALfloat a, ALfloat b)
140 { return ((a > b) ? a : b); }
141 static __inline ALfloat clampf(ALfloat val, ALfloat min, ALfloat max)
142 { return minf(max, maxf(min, val)); }
144 static __inline ALuint minu(ALuint a, ALuint b)
145 { return ((a > b) ? b : a); }
146 static __inline ALuint maxu(ALuint a, ALuint b)
147 { return ((a > b) ? a : b); }
148 static __inline ALuint clampu(ALuint val, ALuint min, ALuint max)
149 { return minu(max, maxu(min, val)); }
151 static __inline ALint mini(ALint a, ALint b)
152 { return ((a > b) ? b : a); }
153 static __inline ALint maxi(ALint a, ALint b)
154 { return ((a > b) ? a : b); }
155 static __inline ALint clampi(ALint val, ALint min, ALint max)
156 { return mini(max, maxi(min, val)); }
159 static __inline ALdouble lerp(ALdouble val1, ALdouble val2, ALdouble mu)
161 return val1 + (val2-val1)*mu;
163 static __inline ALdouble cubic(ALdouble val0, ALdouble val1, ALdouble val2, ALdouble val3, ALdouble mu)
165 ALdouble mu2 = mu*mu;
166 ALdouble a0 = -0.5*val0 + 1.5*val1 + -1.5*val2 + 0.5*val3;
167 ALdouble a1 = val0 + -2.5*val1 + 2.0*val2 + -0.5*val3;
168 ALdouble a2 = -0.5*val0 + 0.5*val2;
169 ALdouble a3 = val1;
171 return a0*mu*mu2 + a1*mu2 + a2*mu + a3;
174 ALvoid aluInitPanning(ALCdevice *Device);
175 ALint aluCart2LUTpos(ALfloat re, ALfloat im);
177 ALvoid CalcSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
178 ALvoid CalcNonAttnSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
180 MixerFunc SelectMixer(struct ALbuffer *Buffer, enum Resampler Resampler);
181 MixerFunc SelectHrtfMixer(struct ALbuffer *Buffer, enum Resampler Resampler);
183 ALvoid MixSource(struct ALsource *Source, ALCdevice *Device, ALuint SamplesToDo);
185 ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size);
186 ALvoid aluHandleDisconnect(ALCdevice *device);
188 extern ALfloat ConeScale;
189 extern ALfloat ZScale;
191 #ifdef __cplusplus
193 #endif
195 #endif