21 #define F_PI (3.14159265358979323846f)
22 #define F_PI_2 (1.57079632679489661923f)
23 #define F_2PI (6.28318530717958647692f)
26 #define FLT_EPSILON (1.19209290e-07f)
29 #define DEG2RAD(x) ((ALfloat)(x) * (F_PI/180.0f))
30 #define RAD2DEG(x) ((ALfloat)(x) * (180.0f/F_PI))
33 #define MAX_PITCH (10)
48 AF_BandPass
= AF_LowPass
| AF_HighPass
52 typedef struct MixGains
{
59 typedef struct DirectParams
{
60 ALfloat (*OutBuffer
)[BUFFERSIZE
];
63 /* If not 'moving', gain/coefficients are set directly without fading. */
65 /* Stepping counter for gain/coefficient fading. */
67 /* Last direction (relative to listener) and gain of a moving source. */
72 enum ActiveFilters ActiveType
;
73 ALfilterState LowPass
;
74 ALfilterState HighPass
;
75 } Filters
[MAX_INPUT_CHANNELS
];
78 HrtfParams Params
[MAX_INPUT_CHANNELS
];
79 HrtfState State
[MAX_INPUT_CHANNELS
];
82 MixGains Gains
[MAX_INPUT_CHANNELS
][MAX_OUTPUT_CHANNELS
];
85 typedef struct SendParams
{
86 ALfloat (*OutBuffer
)[BUFFERSIZE
];
92 enum ActiveFilters ActiveType
;
93 ALfilterState LowPass
;
94 ALfilterState HighPass
;
95 } Filters
[MAX_INPUT_CHANNELS
];
97 /* Gain control, which applies to all input channels to a single (mono)
103 typedef const ALfloat
* (*ResamplerFunc
)(const ALfloat
*src
, ALuint frac
, ALuint increment
,
104 ALfloat
*restrict dst
, ALuint dstlen
);
106 typedef void (*MixerFunc
)(const ALfloat
*data
, ALuint OutChans
,
107 ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], struct MixGains
*Gains
,
108 ALuint Counter
, ALuint OutPos
, ALuint BufferSize
);
109 typedef void (*HrtfMixerFunc
)(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], const ALfloat
*data
,
110 ALuint Counter
, ALuint Offset
, ALuint OutPos
,
111 const ALuint IrSize
, const HrtfParams
*hrtfparams
,
112 HrtfState
*hrtfstate
, ALuint BufferSize
);
115 #define GAIN_SILENCE_THRESHOLD (0.00001f) /* -100dB */
117 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
118 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
120 #define FRACTIONBITS (14)
121 #define FRACTIONONE (1<<FRACTIONBITS)
122 #define FRACTIONMASK (FRACTIONONE-1)
125 inline ALfloat
minf(ALfloat a
, ALfloat b
)
126 { return ((a
> b
) ? b
: a
); }
127 inline ALfloat
maxf(ALfloat a
, ALfloat b
)
128 { return ((a
> b
) ? a
: b
); }
129 inline ALfloat
clampf(ALfloat val
, ALfloat min
, ALfloat max
)
130 { return minf(max
, maxf(min
, val
)); }
132 inline ALdouble
mind(ALdouble a
, ALdouble b
)
133 { return ((a
> b
) ? b
: a
); }
134 inline ALdouble
maxd(ALdouble a
, ALdouble b
)
135 { return ((a
> b
) ? a
: b
); }
136 inline ALdouble
clampd(ALdouble val
, ALdouble min
, ALdouble max
)
137 { return mind(max
, maxd(min
, val
)); }
139 inline ALuint
minu(ALuint a
, ALuint b
)
140 { return ((a
> b
) ? b
: a
); }
141 inline ALuint
maxu(ALuint a
, ALuint b
)
142 { return ((a
> b
) ? a
: b
); }
143 inline ALuint
clampu(ALuint val
, ALuint min
, ALuint max
)
144 { return minu(max
, maxu(min
, val
)); }
146 inline ALint
mini(ALint a
, ALint b
)
147 { return ((a
> b
) ? b
: a
); }
148 inline ALint
maxi(ALint a
, ALint b
)
149 { return ((a
> b
) ? a
: b
); }
150 inline ALint
clampi(ALint val
, ALint min
, ALint max
)
151 { return mini(max
, maxi(min
, val
)); }
153 inline ALint64
mini64(ALint64 a
, ALint64 b
)
154 { return ((a
> b
) ? b
: a
); }
155 inline ALint64
maxi64(ALint64 a
, ALint64 b
)
156 { return ((a
> b
) ? a
: b
); }
157 inline ALint64
clampi64(ALint64 val
, ALint64 min
, ALint64 max
)
158 { return mini64(max
, maxi64(min
, val
)); }
160 inline ALuint64
minu64(ALuint64 a
, ALuint64 b
)
161 { return ((a
> b
) ? b
: a
); }
162 inline ALuint64
maxu64(ALuint64 a
, ALuint64 b
)
163 { return ((a
> b
) ? a
: b
); }
164 inline ALuint64
clampu64(ALuint64 val
, ALuint64 min
, ALuint64 max
)
165 { return minu64(max
, maxu64(min
, val
)); }
168 inline ALfloat
lerp(ALfloat val1
, ALfloat val2
, ALfloat mu
)
170 return val1
+ (val2
-val1
)*mu
;
172 inline ALfloat
cubic(ALfloat val0
, ALfloat val1
, ALfloat val2
, ALfloat val3
, ALfloat mu
)
175 ALfloat a0
= -0.5f
*val0
+ 1.5f
*val1
+ -1.5f
*val2
+ 0.5f
*val3
;
176 ALfloat a1
= val0
+ -2.5f
*val1
+ 2.0f
*val2
+ -0.5f
*val3
;
177 ALfloat a2
= -0.5f
*val0
+ 0.5f
*val2
;
180 return a0
*mu
*mu2
+ a1
*mu2
+ a2
*mu
+ a3
;
184 ALvoid
aluInitPanning(ALCdevice
*Device
);
187 * ComputeDirectionalGains
189 * Sets channel gains based on a direction. The direction must be a 3-component
190 * vector no longer than 1 unit.
192 void ComputeDirectionalGains(const ALCdevice
*device
, const ALfloat dir
[3], ALfloat ingain
, ALfloat gains
[MAX_OUTPUT_CHANNELS
]);
197 * Sets channel gains based on angle and elevation. The angle and elevation
198 * parameters are in radians, going right and up respectively.
200 void ComputeAngleGains(const ALCdevice
*device
, ALfloat angle
, ALfloat elevation
, ALfloat ingain
, ALfloat gains
[MAX_OUTPUT_CHANNELS
]);
203 * ComputeAmbientGains
205 * Sets channel gains for ambient, omni-directional sounds.
207 void ComputeAmbientGains(const ALCdevice
*device
, ALfloat ingain
, ALfloat gains
[MAX_OUTPUT_CHANNELS
]);
210 * ComputeBFormatGains
212 * Sets channel gains for a given (first-order) B-Format channel. The matrix is
213 * a 1x4 'slice' of the rotation matrix for a given channel used to orient the
216 void ComputeBFormatGains(const ALCdevice
*device
, const ALfloat mtx
[4], ALfloat ingain
, ALfloat gains
[MAX_OUTPUT_CHANNELS
]);
219 ALvoid
CalcSourceParams(struct ALvoice
*voice
, const struct ALsource
*source
, const ALCcontext
*ALContext
);
220 ALvoid
CalcNonAttnSourceParams(struct ALvoice
*voice
, const struct ALsource
*source
, const ALCcontext
*ALContext
);
222 ALvoid
MixSource(struct ALvoice
*voice
, struct ALsource
*source
, ALCdevice
*Device
, ALuint SamplesToDo
);
224 ALvoid
aluMixData(ALCdevice
*device
, ALvoid
*buffer
, ALsizei size
);
225 /* Caller must lock the device. */
226 ALvoid
aluHandleDisconnect(ALCdevice
*device
);
228 extern ALfloat ConeScale
;
229 extern ALfloat ZScale
;