2007-11-13 18:02:18 -08:00
|
|
|
#ifndef _ALU_H_
|
|
|
|
#define _ALU_H_
|
|
|
|
|
2012-09-14 02:42:36 -07:00
|
|
|
#include "alMain.h"
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2010-08-07 05:43:16 -07:00
|
|
|
#include <limits.h>
|
2009-11-19 09:24:35 -08:00
|
|
|
#include <math.h>
|
2009-05-16 23:26:39 -07:00
|
|
|
#ifdef HAVE_FLOAT_H
|
|
|
|
#include <float.h>
|
|
|
|
#endif
|
2011-07-23 05:53:53 -07:00
|
|
|
#ifdef HAVE_IEEEFP_H
|
|
|
|
#include <ieeefp.h>
|
|
|
|
#endif
|
2009-05-16 23:26:39 -07:00
|
|
|
|
|
|
|
|
2013-10-08 08:29:14 -07:00
|
|
|
#define F_PI (3.14159265358979323846f)
|
|
|
|
#define F_PI_2 (1.57079632679489661923f)
|
2013-10-08 16:31:23 -07:00
|
|
|
#define F_2PI (6.28318530717958647692f)
|
2011-09-22 11:17:01 -07:00
|
|
|
|
2012-10-12 07:10:51 -07:00
|
|
|
#ifndef FLT_EPSILON
|
|
|
|
#define FLT_EPSILON (1.19209290e-07f)
|
|
|
|
#endif
|
|
|
|
|
2013-10-08 08:29:14 -07:00
|
|
|
#define DEG2RAD(x) ((ALfloat)(x) * (F_PI/180.0f))
|
|
|
|
#define RAD2DEG(x) ((ALfloat)(x) * (180.0f/F_PI))
|
|
|
|
|
2012-10-12 07:10:51 -07:00
|
|
|
|
2007-11-13 18:02:18 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2011-06-25 00:08:05 -07:00
|
|
|
struct ALsource;
|
|
|
|
struct ALbuffer;
|
2012-04-28 03:31:13 -07:00
|
|
|
struct DirectParams;
|
|
|
|
struct SendParams;
|
2011-06-25 00:08:05 -07:00
|
|
|
|
2012-09-27 02:46:15 -07:00
|
|
|
typedef void (*ResamplerFunc)(const ALfloat *src, ALuint frac, ALuint increment,
|
2013-05-22 15:11:39 -07:00
|
|
|
ALfloat *restrict dst, ALuint dstlen);
|
2012-09-14 04:13:18 -07:00
|
|
|
|
2012-10-15 01:31:58 -07:00
|
|
|
typedef ALvoid (*DryMixerFunc)(const struct DirectParams *params,
|
2013-05-22 15:11:39 -07:00
|
|
|
const ALfloat *restrict data, ALuint srcchan,
|
2012-04-27 23:46:51 -07:00
|
|
|
ALuint OutPos, ALuint SamplesToDo,
|
|
|
|
ALuint BufferSize);
|
2012-10-15 01:31:58 -07:00
|
|
|
typedef ALvoid (*WetMixerFunc)(const struct SendParams *params,
|
2013-05-22 15:11:39 -07:00
|
|
|
const ALfloat *restrict data,
|
2012-04-27 23:46:51 -07:00
|
|
|
ALuint OutPos, ALuint SamplesToDo,
|
|
|
|
ALuint BufferSize);
|
2011-06-25 00:08:05 -07:00
|
|
|
|
2010-11-26 17:47:43 -08:00
|
|
|
|
2013-10-06 17:25:47 -07:00
|
|
|
#define GAIN_SILENCE_THRESHOLD (0.00001f)
|
|
|
|
|
2012-09-14 02:52:37 -07:00
|
|
|
#define SPEEDOFSOUNDMETRESPERSEC (343.3f)
|
|
|
|
#define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
|
|
|
|
|
2012-09-08 22:09:34 -07:00
|
|
|
#define FRACTIONBITS (14)
|
|
|
|
#define FRACTIONONE (1<<FRACTIONBITS)
|
|
|
|
#define FRACTIONMASK (FRACTIONONE-1)
|
|
|
|
|
2010-08-07 05:43:16 -07:00
|
|
|
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALfloat minf(ALfloat a, ALfloat b)
|
2011-08-16 04:21:58 -07:00
|
|
|
{ return ((a > b) ? b : a); }
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALfloat maxf(ALfloat a, ALfloat b)
|
2011-08-16 04:21:58 -07:00
|
|
|
{ return ((a > b) ? a : b); }
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALfloat clampf(ALfloat val, ALfloat min, ALfloat max)
|
2011-08-16 18:40:21 -07:00
|
|
|
{ return minf(max, maxf(min, val)); }
|
2011-08-16 04:21:58 -07:00
|
|
|
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALuint minu(ALuint a, ALuint b)
|
2011-08-16 18:33:10 -07:00
|
|
|
{ return ((a > b) ? b : a); }
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALuint maxu(ALuint a, ALuint b)
|
2011-08-16 18:33:10 -07:00
|
|
|
{ return ((a > b) ? a : b); }
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALuint clampu(ALuint val, ALuint min, ALuint max)
|
2011-08-16 18:33:10 -07:00
|
|
|
{ return minu(max, maxu(min, val)); }
|
|
|
|
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALint mini(ALint a, ALint b)
|
2011-08-16 18:33:10 -07:00
|
|
|
{ return ((a > b) ? b : a); }
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALint maxi(ALint a, ALint b)
|
2011-08-16 18:33:10 -07:00
|
|
|
{ return ((a > b) ? a : b); }
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALint clampi(ALint val, ALint min, ALint max)
|
2011-08-16 18:33:10 -07:00
|
|
|
{ return mini(max, maxi(min, val)); }
|
|
|
|
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALint64 mini64(ALint64 a, ALint64 b)
|
2011-10-04 22:39:35 -07:00
|
|
|
{ return ((a > b) ? b : a); }
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALint64 maxi64(ALint64 a, ALint64 b)
|
2011-10-04 22:39:35 -07:00
|
|
|
{ return ((a > b) ? a : b); }
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALint64 clampi64(ALint64 val, ALint64 min, ALint64 max)
|
2011-10-04 22:39:35 -07:00
|
|
|
{ return mini64(max, maxi64(min, val)); }
|
|
|
|
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALuint64 minu64(ALuint64 a, ALuint64 b)
|
2012-08-17 13:38:52 -07:00
|
|
|
{ return ((a > b) ? b : a); }
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALuint64 maxu64(ALuint64 a, ALuint64 b)
|
2012-08-17 13:38:52 -07:00
|
|
|
{ return ((a > b) ? a : b); }
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALuint64 clampu64(ALuint64 val, ALuint64 min, ALuint64 max)
|
2012-08-17 13:38:52 -07:00
|
|
|
{ return minu64(max, maxu64(min, val)); }
|
|
|
|
|
2011-08-16 04:21:58 -07:00
|
|
|
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu)
|
2010-11-26 01:07:54 -08:00
|
|
|
{
|
2010-11-28 22:50:27 -08:00
|
|
|
return val1 + (val2-val1)*mu;
|
2010-11-26 01:07:54 -08:00
|
|
|
}
|
2013-11-04 13:44:46 -08:00
|
|
|
inline ALfloat cubic(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALfloat mu)
|
2010-11-26 01:07:54 -08:00
|
|
|
{
|
2011-09-23 23:03:59 -07:00
|
|
|
ALfloat mu2 = mu*mu;
|
|
|
|
ALfloat a0 = -0.5f*val0 + 1.5f*val1 + -1.5f*val2 + 0.5f*val3;
|
|
|
|
ALfloat a1 = val0 + -2.5f*val1 + 2.0f*val2 + -0.5f*val3;
|
|
|
|
ALfloat a2 = -0.5f*val0 + 0.5f*val2;
|
|
|
|
ALfloat a3 = val1;
|
2010-11-26 01:07:54 -08:00
|
|
|
|
|
|
|
return a0*mu*mu2 + a1*mu2 + a2*mu + a3;
|
|
|
|
}
|
|
|
|
|
2011-09-29 04:03:18 -07:00
|
|
|
|
2010-04-08 15:58:11 -07:00
|
|
|
ALvoid aluInitPanning(ALCdevice *Device);
|
2010-08-03 23:10:00 -07:00
|
|
|
|
2013-10-03 05:02:16 -07:00
|
|
|
/**
|
|
|
|
* ComputeAngleGains
|
|
|
|
*
|
|
|
|
* Sets channel gains based on a given source's angle and its half-width. The
|
|
|
|
* angle and hwidth parameters are in radians.
|
|
|
|
*/
|
|
|
|
void ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, ALfloat ingain, ALfloat gains[MaxChannels]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SetGains
|
|
|
|
*
|
|
|
|
* Helper to set the appropriate channels to the specified gain.
|
|
|
|
*/
|
2013-11-04 13:44:46 -08:00
|
|
|
inline void SetGains(const ALCdevice *device, ALfloat ingain, ALfloat gains[MaxChannels])
|
2013-10-03 05:02:16 -07:00
|
|
|
{
|
|
|
|
ComputeAngleGains(device, 0.0f, F_PI, ingain, gains);
|
|
|
|
}
|
|
|
|
|
2012-04-28 07:28:36 -07:00
|
|
|
|
2010-08-03 23:10:00 -07:00
|
|
|
ALvoid CalcSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
|
|
|
|
ALvoid CalcNonAttnSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext);
|
|
|
|
|
2010-09-26 12:23:22 -07:00
|
|
|
ALvoid MixSource(struct ALsource *Source, ALCdevice *Device, ALuint SamplesToDo);
|
2010-09-26 01:15:27 -07:00
|
|
|
|
2009-09-15 19:30:27 -07:00
|
|
|
ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size);
|
2012-12-02 11:20:20 -08:00
|
|
|
/* Caller must lock the device. */
|
2009-08-26 19:15:17 -07:00
|
|
|
ALvoid aluHandleDisconnect(ALCdevice *device);
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2011-09-23 22:33:37 -07:00
|
|
|
extern ALfloat ConeScale;
|
|
|
|
extern ALfloat ZScale;
|
|
|
|
|
2007-11-13 18:02:18 -08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|