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)
46 AF_BandPass
= AF_LowPass
| AF_HighPass
50 typedef struct HrtfState
{
51 alignas(16) ALfloat History
[SRC_HISTORY_LENGTH
];
52 alignas(16) ALfloat Values
[HRIR_LENGTH
][2];
55 typedef struct HrtfParams
{
56 alignas(16) ALfloat Coeffs
[HRIR_LENGTH
][2];
57 alignas(16) ALfloat CoeffStep
[HRIR_LENGTH
][2];
63 typedef struct MixGains
{
64 ALfloat Current
[MaxChannels
];
65 ALfloat Step
[MaxChannels
];
66 ALfloat Target
[MaxChannels
];
69 typedef struct MixGainMono
{
76 typedef struct DirectParams
{
77 ALfloat (*OutBuffer
)[BUFFERSIZE
];
79 /* If not 'moving', gain/coefficients are set directly without fading. */
81 /* Stepping counter for gain/coefficient fading. */
83 /* History/coefficient offset. */
87 enum ActiveFilters ActiveType
;
88 ALfilterState LowPass
;
89 ALfilterState HighPass
;
90 } Filters
[MAX_INPUT_CHANNELS
];
94 HrtfParams Params
[MAX_INPUT_CHANNELS
];
95 HrtfState State
[MAX_INPUT_CHANNELS
];
101 MixGains Gains
[MAX_INPUT_CHANNELS
];
105 typedef struct SendParams
{
106 ALfloat (*OutBuffer
)[BUFFERSIZE
];
112 enum ActiveFilters ActiveType
;
113 ALfilterState LowPass
;
114 ALfilterState HighPass
;
115 } Filters
[MAX_INPUT_CHANNELS
];
117 /* Gain control, which applies to all input channels to a single (mono)
123 typedef const ALfloat
* (*ResamplerFunc
)(const ALfloat
*src
, ALuint frac
, ALuint increment
,
124 ALfloat
*restrict dst
, ALuint dstlen
);
126 typedef void (*DryMixerFunc
)(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], const ALfloat
*data
,
127 MixGains
*Gains
, ALuint Counter
, ALuint OutPos
,
129 typedef void (*HrtfMixerFunc
)(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], const ALfloat
*data
,
130 ALuint Counter
, ALuint Offset
, ALuint OutPos
,
131 const ALuint IrSize
, const HrtfParams
*hrtfparams
,
132 HrtfState
*hrtfstate
, ALuint BufferSize
);
133 typedef void (*WetMixerFunc
)(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], const ALfloat
*data
,
134 MixGainMono
*Gain
, ALuint Counter
, ALuint OutPos
,
138 #define GAIN_SILENCE_THRESHOLD (0.00001f) /* -100dB */
140 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
141 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
143 #define FRACTIONBITS (14)
144 #define FRACTIONONE (1<<FRACTIONBITS)
145 #define FRACTIONMASK (FRACTIONONE-1)
148 inline ALfloat
minf(ALfloat a
, ALfloat b
)
149 { return ((a
> b
) ? b
: a
); }
150 inline ALfloat
maxf(ALfloat a
, ALfloat b
)
151 { return ((a
> b
) ? a
: b
); }
152 inline ALfloat
clampf(ALfloat val
, ALfloat min
, ALfloat max
)
153 { return minf(max
, maxf(min
, val
)); }
155 inline ALdouble
mind(ALdouble a
, ALdouble b
)
156 { return ((a
> b
) ? b
: a
); }
157 inline ALdouble
maxd(ALdouble a
, ALdouble b
)
158 { return ((a
> b
) ? a
: b
); }
159 inline ALdouble
clampd(ALdouble val
, ALdouble min
, ALdouble max
)
160 { return mind(max
, maxd(min
, val
)); }
162 inline ALuint
minu(ALuint a
, ALuint b
)
163 { return ((a
> b
) ? b
: a
); }
164 inline ALuint
maxu(ALuint a
, ALuint b
)
165 { return ((a
> b
) ? a
: b
); }
166 inline ALuint
clampu(ALuint val
, ALuint min
, ALuint max
)
167 { return minu(max
, maxu(min
, val
)); }
169 inline ALint
mini(ALint a
, ALint b
)
170 { return ((a
> b
) ? b
: a
); }
171 inline ALint
maxi(ALint a
, ALint b
)
172 { return ((a
> b
) ? a
: b
); }
173 inline ALint
clampi(ALint val
, ALint min
, ALint max
)
174 { return mini(max
, maxi(min
, val
)); }
176 inline ALint64
mini64(ALint64 a
, ALint64 b
)
177 { return ((a
> b
) ? b
: a
); }
178 inline ALint64
maxi64(ALint64 a
, ALint64 b
)
179 { return ((a
> b
) ? a
: b
); }
180 inline ALint64
clampi64(ALint64 val
, ALint64 min
, ALint64 max
)
181 { return mini64(max
, maxi64(min
, val
)); }
183 inline ALuint64
minu64(ALuint64 a
, ALuint64 b
)
184 { return ((a
> b
) ? b
: a
); }
185 inline ALuint64
maxu64(ALuint64 a
, ALuint64 b
)
186 { return ((a
> b
) ? a
: b
); }
187 inline ALuint64
clampu64(ALuint64 val
, ALuint64 min
, ALuint64 max
)
188 { return minu64(max
, maxu64(min
, val
)); }
191 inline ALfloat
lerp(ALfloat val1
, ALfloat val2
, ALfloat mu
)
193 return val1
+ (val2
-val1
)*mu
;
195 inline ALfloat
cubic(ALfloat val0
, ALfloat val1
, ALfloat val2
, ALfloat val3
, ALfloat mu
)
198 ALfloat a0
= -0.5f
*val0
+ 1.5f
*val1
+ -1.5f
*val2
+ 0.5f
*val3
;
199 ALfloat a1
= val0
+ -2.5f
*val1
+ 2.0f
*val2
+ -0.5f
*val3
;
200 ALfloat a2
= -0.5f
*val0
+ 0.5f
*val2
;
203 return a0
*mu
*mu2
+ a1
*mu2
+ a2
*mu
+ a3
;
207 ALvoid
aluInitPanning(ALCdevice
*Device
);
212 * Sets channel gains based on a given source's angle and its half-width. The
213 * angle and hwidth parameters are in radians.
215 void ComputeAngleGains(const ALCdevice
*device
, ALfloat angle
, ALfloat hwidth
, ALfloat ingain
, ALfloat gains
[MaxChannels
]);
220 * Helper to set the appropriate channels to the specified gain.
222 inline void SetGains(const ALCdevice
*device
, ALfloat ingain
, ALfloat gains
[MaxChannels
])
224 ComputeAngleGains(device
, 0.0f
, F_PI
, ingain
, gains
);
228 ALvoid
CalcSourceParams(struct ALactivesource
*src
, const ALCcontext
*ALContext
);
229 ALvoid
CalcNonAttnSourceParams(struct ALactivesource
*src
, const ALCcontext
*ALContext
);
231 ALvoid
MixSource(struct ALactivesource
*src
, ALCdevice
*Device
, ALuint SamplesToDo
);
233 ALvoid
aluMixData(ALCdevice
*device
, ALvoid
*buffer
, ALsizei size
);
234 /* Caller must lock the device. */
235 ALvoid
aluHandleDisconnect(ALCdevice
*device
);
237 extern ALfloat ConeScale
;
238 extern ALfloat ZScale
;