16 #define F_PI (3.14159265358979323846f) /* pi */
17 #define F_PI_2 (1.57079632679489661923f) /* pi/2 */
20 #define FLT_EPSILON (1.19209290e-07f)
25 static __inline
float powf(float x
, float y
)
26 { return (float)pow(x
, y
); }
30 static __inline
float sqrtf(float x
)
31 { return (float)sqrt(x
); }
35 static __inline
float cosf(float x
)
36 { return (float)cos(x
); }
40 static __inline
float sinf(float x
)
41 { return (float)sin(x
); }
45 static __inline
float acosf(float x
)
46 { return (float)acos(x
); }
50 static __inline
float asinf(float x
)
51 { return (float)asin(x
); }
55 static __inline
float atanf(float x
)
56 { return (float)atan(x
); }
60 static __inline
float atan2f(float x
, float y
)
61 { return (float)atan2(x
, y
); }
65 static __inline
float fabsf(float x
)
66 { return (float)fabs(x
); }
70 static __inline
float log10f(float x
)
71 { return (float)log10(x
); }
75 static __inline
float floorf(float x
)
76 { return (float)floor(x
); }
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
,
96 typedef ALvoid (*WetMixerFunc
)(struct SendParams
*params
,
97 const ALfloat
*RESTRICT data
,
98 ALuint OutPos
, ALuint SamplesToDo
,
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
)
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
;
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
);
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
;