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 SRC_HISTORY_BITS (6)
34 #define SRC_HISTORY_LENGTH (1<<SRC_HISTORY_BITS)
35 #define SRC_HISTORY_MASK (SRC_HISTORY_LENGTH-1)
37 #define MAX_PITCH (10)
48 AF_BandPass
= AF_LowPass
| AF_HighPass
52 typedef struct HrtfState
{
53 alignas(16) ALfloat History
[SRC_HISTORY_LENGTH
];
54 alignas(16) ALfloat Values
[HRIR_LENGTH
][2];
57 typedef struct HrtfParams
{
58 alignas(16) ALfloat Coeffs
[HRIR_LENGTH
][2];
59 alignas(16) ALfloat CoeffStep
[HRIR_LENGTH
][2];
65 typedef struct MixGains
{
72 typedef struct DirectParams
{
73 ALfloat (*OutBuffer
)[BUFFERSIZE
];
75 /* If not 'moving', gain/coefficients are set directly without fading. */
77 /* Stepping counter for gain/coefficient fading. */
81 enum ActiveFilters ActiveType
;
82 ALfilterState LowPass
;
83 ALfilterState HighPass
;
84 } Filters
[MAX_INPUT_CHANNELS
];
88 HrtfParams Params
[MAX_INPUT_CHANNELS
];
89 HrtfState State
[MAX_INPUT_CHANNELS
];
95 MixGains Gains
[MAX_INPUT_CHANNELS
][MaxChannels
];
99 typedef struct SendParams
{
100 ALfloat (*OutBuffer
)[BUFFERSIZE
];
106 enum ActiveFilters ActiveType
;
107 ALfilterState LowPass
;
108 ALfilterState HighPass
;
109 } Filters
[MAX_INPUT_CHANNELS
];
111 /* Gain control, which applies to all input channels to a single (mono)
117 typedef const ALfloat
* (*ResamplerFunc
)(const ALfloat
*src
, ALuint frac
, ALuint increment
,
118 ALfloat
*restrict dst
, ALuint dstlen
);
120 typedef void (*MixerFunc
)(const ALfloat
*data
, ALuint OutChans
,
121 ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], struct MixGains
*Gains
,
122 ALuint Counter
, ALuint OutPos
, ALuint BufferSize
);
123 typedef void (*HrtfMixerFunc
)(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], const ALfloat
*data
,
124 ALuint Counter
, ALuint Offset
, ALuint OutPos
,
125 const ALuint IrSize
, const HrtfParams
*hrtfparams
,
126 HrtfState
*hrtfstate
, ALuint BufferSize
);
129 #define GAIN_SILENCE_THRESHOLD (0.00001f) /* -100dB */
131 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
132 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
134 #define FRACTIONBITS (14)
135 #define FRACTIONONE (1<<FRACTIONBITS)
136 #define FRACTIONMASK (FRACTIONONE-1)
139 inline ALfloat
minf(ALfloat a
, ALfloat b
)
140 { return ((a
> b
) ? b
: a
); }
141 inline ALfloat
maxf(ALfloat a
, ALfloat b
)
142 { return ((a
> b
) ? a
: b
); }
143 inline ALfloat
clampf(ALfloat val
, ALfloat min
, ALfloat max
)
144 { return minf(max
, maxf(min
, val
)); }
146 inline ALdouble
mind(ALdouble a
, ALdouble b
)
147 { return ((a
> b
) ? b
: a
); }
148 inline ALdouble
maxd(ALdouble a
, ALdouble b
)
149 { return ((a
> b
) ? a
: b
); }
150 inline ALdouble
clampd(ALdouble val
, ALdouble min
, ALdouble max
)
151 { return mind(max
, maxd(min
, val
)); }
153 inline ALuint
minu(ALuint a
, ALuint b
)
154 { return ((a
> b
) ? b
: a
); }
155 inline ALuint
maxu(ALuint a
, ALuint b
)
156 { return ((a
> b
) ? a
: b
); }
157 inline ALuint
clampu(ALuint val
, ALuint min
, ALuint max
)
158 { return minu(max
, maxu(min
, val
)); }
160 inline ALint
mini(ALint a
, ALint b
)
161 { return ((a
> b
) ? b
: a
); }
162 inline ALint
maxi(ALint a
, ALint b
)
163 { return ((a
> b
) ? a
: b
); }
164 inline ALint
clampi(ALint val
, ALint min
, ALint max
)
165 { return mini(max
, maxi(min
, val
)); }
167 inline ALint64
mini64(ALint64 a
, ALint64 b
)
168 { return ((a
> b
) ? b
: a
); }
169 inline ALint64
maxi64(ALint64 a
, ALint64 b
)
170 { return ((a
> b
) ? a
: b
); }
171 inline ALint64
clampi64(ALint64 val
, ALint64 min
, ALint64 max
)
172 { return mini64(max
, maxi64(min
, val
)); }
174 inline ALuint64
minu64(ALuint64 a
, ALuint64 b
)
175 { return ((a
> b
) ? b
: a
); }
176 inline ALuint64
maxu64(ALuint64 a
, ALuint64 b
)
177 { return ((a
> b
) ? a
: b
); }
178 inline ALuint64
clampu64(ALuint64 val
, ALuint64 min
, ALuint64 max
)
179 { return minu64(max
, maxu64(min
, val
)); }
182 inline ALfloat
lerp(ALfloat val1
, ALfloat val2
, ALfloat mu
)
184 return val1
+ (val2
-val1
)*mu
;
186 inline ALfloat
cubic(ALfloat val0
, ALfloat val1
, ALfloat val2
, ALfloat val3
, ALfloat mu
)
189 ALfloat a0
= -0.5f
*val0
+ 1.5f
*val1
+ -1.5f
*val2
+ 0.5f
*val3
;
190 ALfloat a1
= val0
+ -2.5f
*val1
+ 2.0f
*val2
+ -0.5f
*val3
;
191 ALfloat a2
= -0.5f
*val0
+ 0.5f
*val2
;
194 return a0
*mu
*mu2
+ a1
*mu2
+ a2
*mu
+ a3
;
198 ALvoid
aluInitPanning(ALCdevice
*Device
);
203 * Sets channel gains based on a given source's angle and its half-width. The
204 * angle and hwidth parameters are in radians.
206 void ComputeAngleGains(const ALCdevice
*device
, ALfloat angle
, ALfloat hwidth
, ALfloat ingain
, ALfloat gains
[MaxChannels
]);
211 * Helper to set the appropriate channels to the specified gain.
213 inline void SetGains(const ALCdevice
*device
, ALfloat ingain
, ALfloat gains
[MaxChannels
])
215 ComputeAngleGains(device
, 0.0f
, F_PI
, ingain
, gains
);
219 ALvoid
CalcSourceParams(struct ALactivesource
*src
, const ALCcontext
*ALContext
);
220 ALvoid
CalcNonAttnSourceParams(struct ALactivesource
*src
, const ALCcontext
*ALContext
);
222 ALvoid
MixSource(struct ALactivesource
*src
, 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
;