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
];
81 MixGains Gains
[MAX_INPUT_CHANNELS
][MAX_OUTPUT_CHANNELS
];
84 typedef struct SendParams
{
85 ALfloat (*OutBuffer
)[BUFFERSIZE
];
91 enum ActiveFilters ActiveType
;
92 ALfilterState LowPass
;
93 ALfilterState HighPass
;
94 } Filters
[MAX_INPUT_CHANNELS
];
96 /* Gain control, which applies to all input channels to a single (mono)
102 typedef const ALfloat
* (*ResamplerFunc
)(const ALfloat
*src
, ALuint frac
, ALuint increment
,
103 ALfloat
*restrict dst
, ALuint dstlen
);
105 typedef void (*MixerFunc
)(const ALfloat
*data
, ALuint OutChans
,
106 ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], struct MixGains
*Gains
,
107 ALuint Counter
, ALuint OutPos
, ALuint BufferSize
);
108 typedef void (*HrtfMixerFunc
)(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], const ALfloat
*data
,
109 ALuint Counter
, ALuint Offset
, ALuint OutPos
,
110 const ALuint IrSize
, const HrtfParams
*hrtfparams
,
111 HrtfState
*hrtfstate
, ALuint BufferSize
);
114 #define GAIN_SILENCE_THRESHOLD (0.00001f) /* -100dB */
116 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
117 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
119 #define FRACTIONBITS (14)
120 #define FRACTIONONE (1<<FRACTIONBITS)
121 #define FRACTIONMASK (FRACTIONONE-1)
124 inline ALfloat
minf(ALfloat a
, ALfloat b
)
125 { return ((a
> b
) ? b
: a
); }
126 inline ALfloat
maxf(ALfloat a
, ALfloat b
)
127 { return ((a
> b
) ? a
: b
); }
128 inline ALfloat
clampf(ALfloat val
, ALfloat min
, ALfloat max
)
129 { return minf(max
, maxf(min
, val
)); }
131 inline ALdouble
mind(ALdouble a
, ALdouble b
)
132 { return ((a
> b
) ? b
: a
); }
133 inline ALdouble
maxd(ALdouble a
, ALdouble b
)
134 { return ((a
> b
) ? a
: b
); }
135 inline ALdouble
clampd(ALdouble val
, ALdouble min
, ALdouble max
)
136 { return mind(max
, maxd(min
, val
)); }
138 inline ALuint
minu(ALuint a
, ALuint b
)
139 { return ((a
> b
) ? b
: a
); }
140 inline ALuint
maxu(ALuint a
, ALuint b
)
141 { return ((a
> b
) ? a
: b
); }
142 inline ALuint
clampu(ALuint val
, ALuint min
, ALuint max
)
143 { return minu(max
, maxu(min
, val
)); }
145 inline ALint
mini(ALint a
, ALint b
)
146 { return ((a
> b
) ? b
: a
); }
147 inline ALint
maxi(ALint a
, ALint b
)
148 { return ((a
> b
) ? a
: b
); }
149 inline ALint
clampi(ALint val
, ALint min
, ALint max
)
150 { return mini(max
, maxi(min
, val
)); }
152 inline ALint64
mini64(ALint64 a
, ALint64 b
)
153 { return ((a
> b
) ? b
: a
); }
154 inline ALint64
maxi64(ALint64 a
, ALint64 b
)
155 { return ((a
> b
) ? a
: b
); }
156 inline ALint64
clampi64(ALint64 val
, ALint64 min
, ALint64 max
)
157 { return mini64(max
, maxi64(min
, val
)); }
159 inline ALuint64
minu64(ALuint64 a
, ALuint64 b
)
160 { return ((a
> b
) ? b
: a
); }
161 inline ALuint64
maxu64(ALuint64 a
, ALuint64 b
)
162 { return ((a
> b
) ? a
: b
); }
163 inline ALuint64
clampu64(ALuint64 val
, ALuint64 min
, ALuint64 max
)
164 { return minu64(max
, maxu64(min
, val
)); }
167 inline ALfloat
lerp(ALfloat val1
, ALfloat val2
, ALfloat mu
)
169 return val1
+ (val2
-val1
)*mu
;
171 inline ALfloat
cubic(ALfloat val0
, ALfloat val1
, ALfloat val2
, ALfloat val3
, ALfloat mu
)
173 ALfloat mu2
= mu
*mu
, mu3
= mu
*mu
*mu
;
174 ALfloat a0
= -0.5f
*mu3
+ mu2
+ -0.5f
*mu
;
175 ALfloat a1
= 1.5f
*mu3
+ -2.5f
*mu2
+ 1.0f
;
176 ALfloat a2
= -1.5f
*mu3
+ 2.0f
*mu2
+ 0.5f
*mu
;
177 ALfloat a3
= 0.5f
*mu3
+ -0.5f
*mu2
;
179 return a0
*val0
+ a1
*val1
+ a2
*val2
+ a3
*val3
;
183 ALvoid
aluInitPanning(ALCdevice
*Device
);
186 * ComputeDirectionalGains
188 * Sets channel gains based on a direction. The direction must be a 3-component
189 * vector no longer than 1 unit.
191 void ComputeDirectionalGains(const ALCdevice
*device
, const ALfloat dir
[3], ALfloat ingain
, ALfloat gains
[MAX_OUTPUT_CHANNELS
]);
196 * Sets channel gains based on angle and elevation. The angle and elevation
197 * parameters are in radians, going right and up respectively.
199 void ComputeAngleGains(const ALCdevice
*device
, ALfloat angle
, ALfloat elevation
, ALfloat ingain
, ALfloat gains
[MAX_OUTPUT_CHANNELS
]);
202 * ComputeAmbientGains
204 * Sets channel gains for ambient, omni-directional sounds.
206 void ComputeAmbientGains(const ALCdevice
*device
, ALfloat ingain
, ALfloat gains
[MAX_OUTPUT_CHANNELS
]);
209 * ComputeBFormatGains
211 * Sets channel gains for a given (first-order) B-Format channel. The matrix is
212 * a 1x4 'slice' of the rotation matrix for a given channel used to orient the
215 void ComputeBFormatGains(const ALCdevice
*device
, const ALfloat mtx
[4], ALfloat ingain
, ALfloat gains
[MAX_OUTPUT_CHANNELS
]);
218 ALvoid
CalcSourceParams(struct ALvoice
*voice
, const struct ALsource
*source
, const ALCcontext
*ALContext
);
219 ALvoid
CalcNonAttnSourceParams(struct ALvoice
*voice
, const struct ALsource
*source
, const ALCcontext
*ALContext
);
221 ALvoid
MixSource(struct ALvoice
*voice
, struct ALsource
*source
, ALCdevice
*Device
, ALuint SamplesToDo
);
223 ALvoid
aluMixData(ALCdevice
*device
, ALvoid
*buffer
, ALsizei size
);
224 /* Caller must lock the device. */
225 ALvoid
aluHandleDisconnect(ALCdevice
*device
);
227 extern ALfloat ConeScale
;
228 extern ALfloat ZScale
;