12 /* HACK: Seems cross-compiling with MinGW includes the wrong float.h, which
13 * doesn't define Windows' _controlfp and related macros */
14 #if defined(__MINGW32__) && !defined(_RC_CHOP)
15 /* Control word masks for unMask */
16 #define _MCW_EM 0x0008001F /* Error masks */
17 #define _MCW_IC 0x00040000 /* Infinity */
18 #define _MCW_RC 0x00000300 /* Rounding */
19 #define _MCW_PC 0x00030000 /* Precision */
20 /* Control word values for unNew (use with related unMask above) */
21 #define _EM_INVALID 0x00000010
22 #define _EM_DENORMAL 0x00080000
23 #define _EM_ZERODIVIDE 0x00000008
24 #define _EM_OVERFLOW 0x00000004
25 #define _EM_UNDERFLOW 0x00000002
26 #define _EM_INEXACT 0x00000001
27 #define _IC_AFFINE 0x00040000
28 #define _IC_PROJECTIVE 0x00000000
29 #define _RC_CHOP 0x00000300
30 #define _RC_UP 0x00000200
31 #define _RC_DOWN 0x00000100
32 #define _RC_NEAR 0x00000000
33 #define _PC_24 0x00020000
34 #define _PC_53 0x00010000
35 #define _PC_64 0x00000000
36 _CRTIMP
unsigned int __cdecl __MINGW_NOTHROW
_controlfp (unsigned int unNew
, unsigned int unMask
);
44 #define F_PI (3.14159265358979323846f) /* pi */
45 #define F_PI_2 (1.57079632679489661923f) /* pi/2 */
48 static __inline
float powf(float x
, float y
)
49 { return (float)pow(x
, y
); }
53 static __inline
float sqrtf(float x
)
54 { return (float)sqrt(x
); }
58 static __inline
float cosf(float x
)
59 { return (float)cos(x
); }
63 static __inline
float sinf(float x
)
64 { return (float)sin(x
); }
68 static __inline
float acosf(float x
)
69 { return (float)acos(x
); }
73 static __inline
float asinf(float x
)
74 { return (float)asin(x
); }
78 static __inline
float atanf(float x
)
79 { return (float)atan(x
); }
83 static __inline
float atan2f(float x
, float y
)
84 { return (float)atan2(x
, y
); }
88 static __inline
float fabsf(float x
)
89 { return (float)fabs(x
); }
93 static __inline
float log10f(float x
)
94 { return (float)log10(x
); }
98 static __inline
float floorf(float x
)
99 { return (float)floor(x
); }
111 typedef ALvoid (*DryMixerFunc
)(struct ALsource
*self
, ALCdevice
*Device
,
112 struct DirectParams
*params
,
113 const ALfloat
*RESTRICT data
, ALuint srcchan
,
114 ALuint OutPos
, ALuint SamplesToDo
,
116 typedef ALvoid (*WetMixerFunc
)(struct SendParams
*params
,
117 const ALfloat
*RESTRICT data
, ALuint srcchan
,
118 ALuint OutPos
, ALuint SamplesToDo
,
144 InverseDistanceClamped
= AL_INVERSE_DISTANCE_CLAMPED
,
145 LinearDistanceClamped
= AL_LINEAR_DISTANCE_CLAMPED
,
146 ExponentDistanceClamped
= AL_EXPONENT_DISTANCE_CLAMPED
,
147 InverseDistance
= AL_INVERSE_DISTANCE
,
148 LinearDistance
= AL_LINEAR_DISTANCE
,
149 ExponentDistance
= AL_EXPONENT_DISTANCE
,
150 DisableDistance
= AL_NONE
,
152 DefaultDistanceModel
= InverseDistanceClamped
156 /* Size for temporary storage of buffer data, in ALfloats. Larger values need
157 * more stack, while smaller values may need more iterations. The value needs
158 * to be a sensible size, however, as it constrains the max stepping value used
159 * for mixing, as well as the maximum number of samples per mixing iteration.
160 * The mixer requires being able to do two samplings per mixing loop. A 16KB
161 * buffer can hold 512 sample frames for a 7.1 float buffer. With the cubic
162 * resampler (which requires 3 padding sample frames), this limits the maximum
163 * step to about 508. This means that buffer_freq*source_pitch cannot exceed
164 * device_freq*508 for an 8-channel 32-bit buffer.
167 #define BUFFERSIZE 4096
170 #define FRACTIONBITS (14)
171 #define FRACTIONONE (1<<FRACTIONBITS)
172 #define FRACTIONMASK (FRACTIONONE-1)
175 static __inline ALfloat
minf(ALfloat a
, ALfloat b
)
176 { return ((a
> b
) ? b
: a
); }
177 static __inline ALfloat
maxf(ALfloat a
, ALfloat b
)
178 { return ((a
> b
) ? a
: b
); }
179 static __inline ALfloat
clampf(ALfloat val
, ALfloat min
, ALfloat max
)
180 { return minf(max
, maxf(min
, val
)); }
182 static __inline ALuint
minu(ALuint a
, ALuint b
)
183 { return ((a
> b
) ? b
: a
); }
184 static __inline ALuint
maxu(ALuint a
, ALuint b
)
185 { return ((a
> b
) ? a
: b
); }
186 static __inline ALuint
clampu(ALuint val
, ALuint min
, ALuint max
)
187 { return minu(max
, maxu(min
, val
)); }
189 static __inline ALint
mini(ALint a
, ALint b
)
190 { return ((a
> b
) ? b
: a
); }
191 static __inline ALint
maxi(ALint a
, ALint b
)
192 { return ((a
> b
) ? a
: b
); }
193 static __inline ALint
clampi(ALint val
, ALint min
, ALint max
)
194 { return mini(max
, maxi(min
, val
)); }
196 static __inline ALint64
mini64(ALint64 a
, ALint64 b
)
197 { return ((a
> b
) ? b
: a
); }
198 static __inline ALint64
maxi64(ALint64 a
, ALint64 b
)
199 { return ((a
> b
) ? a
: b
); }
200 static __inline ALint64
clampi64(ALint64 val
, ALint64 min
, ALint64 max
)
201 { return mini64(max
, maxi64(min
, val
)); }
203 static __inline ALuint64
minu64(ALuint64 a
, ALuint64 b
)
204 { return ((a
> b
) ? b
: a
); }
205 static __inline ALuint64
maxu64(ALuint64 a
, ALuint64 b
)
206 { return ((a
> b
) ? a
: b
); }
207 static __inline ALuint64
clampu64(ALuint64 val
, ALuint64 min
, ALuint64 max
)
208 { return minu64(max
, maxu64(min
, val
)); }
211 static __inline ALfloat
lerp(ALfloat val1
, ALfloat val2
, ALfloat mu
)
213 return val1
+ (val2
-val1
)*mu
;
215 static __inline ALfloat
cubic(ALfloat val0
, ALfloat val1
, ALfloat val2
, ALfloat val3
, ALfloat mu
)
218 ALfloat a0
= -0.5f
*val0
+ 1.5f
*val1
+ -1.5f
*val2
+ 0.5f
*val3
;
219 ALfloat a1
= val0
+ -2.5f
*val1
+ 2.0f
*val2
+ -0.5f
*val3
;
220 ALfloat a2
= -0.5f
*val0
+ 0.5f
*val2
;
223 return a0
*mu
*mu2
+ a1
*mu2
+ a2
*mu
+ a3
;
227 static __inline
int SetMixerFPUMode(void)
229 #if defined(_FPU_GETCW) && defined(_FPU_SETCW) && (defined(__i386__) || defined(__x86_64__))
230 fpu_control_t fpuState
, newState
;
231 _FPU_GETCW(fpuState
);
232 newState
= fpuState
&~(_FPU_EXTENDED
|_FPU_DOUBLE
|_FPU_SINGLE
|
233 _FPU_RC_NEAREST
|_FPU_RC_DOWN
|_FPU_RC_UP
|_FPU_RC_ZERO
);
234 newState
|= _FPU_SINGLE
| _FPU_RC_ZERO
;
235 _FPU_SETCW(newState
);
238 #if defined(HAVE__CONTROLFP)
239 fpuState
= _controlfp(0, 0);
240 (void)_controlfp(_RC_CHOP
|_PC_24
, _MCW_RC
|_MCW_PC
);
241 #elif defined(HAVE_FESETROUND)
242 fpuState
= fegetround();
244 fesetround(FE_TOWARDZERO
);
251 static __inline
void RestoreFPUMode(int state
)
253 #if defined(_FPU_GETCW) && defined(_FPU_SETCW) && (defined(__i386__) || defined(__x86_64__))
254 fpu_control_t fpuState
= state
;
255 _FPU_SETCW(fpuState
);
256 #elif defined(HAVE__CONTROLFP)
257 _controlfp(state
, _MCW_RC
|_MCW_PC
);
258 #elif defined(HAVE_FESETROUND)
264 static __inline
void aluCrossproduct(const ALfloat
*inVector1
, const ALfloat
*inVector2
, ALfloat
*outVector
)
266 outVector
[0] = inVector1
[1]*inVector2
[2] - inVector1
[2]*inVector2
[1];
267 outVector
[1] = inVector1
[2]*inVector2
[0] - inVector1
[0]*inVector2
[2];
268 outVector
[2] = inVector1
[0]*inVector2
[1] - inVector1
[1]*inVector2
[0];
271 static __inline ALfloat
aluDotproduct(const ALfloat
*inVector1
, const ALfloat
*inVector2
)
273 return inVector1
[0]*inVector2
[0] + inVector1
[1]*inVector2
[1] +
274 inVector1
[2]*inVector2
[2];
277 static __inline
void aluNormalize(ALfloat
*inVector
)
279 ALfloat lengthsqr
= aluDotproduct(inVector
, inVector
);
282 ALfloat inv_length
= 1.0f
/sqrtf(lengthsqr
);
283 inVector
[0] *= inv_length
;
284 inVector
[1] *= inv_length
;
285 inVector
[2] *= inv_length
;
290 ALvoid
aluInitPanning(ALCdevice
*Device
);
292 ALvoid
ComputeAngleGains(const ALCdevice
*device
, ALfloat angle
, ALfloat hwidth
, ALfloat ingain
, ALfloat
*gains
);
294 ALvoid
CalcSourceParams(struct ALsource
*ALSource
, const ALCcontext
*ALContext
);
295 ALvoid
CalcNonAttnSourceParams(struct ALsource
*ALSource
, const ALCcontext
*ALContext
);
297 DryMixerFunc
SelectDirectMixer(void);
298 DryMixerFunc
SelectHrtfMixer(void);
299 WetMixerFunc
SelectSendMixer(void);
301 ALvoid
MixSource(struct ALsource
*Source
, ALCdevice
*Device
, ALuint SamplesToDo
);
303 ALvoid
aluMixData(ALCdevice
*device
, ALvoid
*buffer
, ALsizei size
);
304 ALvoid
aluHandleDisconnect(ALCdevice
*device
);
306 extern ALfloat ConeScale
;
307 extern ALfloat ZScale
;