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)
52 AF_BandPass
= AF_LowPass
| AF_HighPass
56 typedef struct HrtfState
{
57 alignas(16) ALfloat History
[SRC_HISTORY_LENGTH
];
58 alignas(16) ALfloat Values
[HRIR_LENGTH
][2];
61 typedef struct HrtfParams
{
62 alignas(16) ALfloat Coeffs
[HRIR_LENGTH
][2];
63 alignas(16) ALfloat CoeffStep
[HRIR_LENGTH
][2];
69 typedef struct MixGains
{
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. */
85 enum ActiveFilters ActiveType
;
86 ALfilterState LowPass
;
87 ALfilterState HighPass
;
88 } Filters
[MAX_INPUT_CHANNELS
];
92 HrtfParams Params
[MAX_INPUT_CHANNELS
];
93 HrtfState State
[MAX_INPUT_CHANNELS
];
99 MixGains Gains
[MAX_INPUT_CHANNELS
][MaxChannels
];
103 typedef struct SendParams
{
104 ALfloat (*OutBuffer
)[BUFFERSIZE
];
110 enum ActiveFilters ActiveType
;
111 ALfilterState LowPass
;
112 ALfilterState HighPass
;
113 } Filters
[MAX_INPUT_CHANNELS
];
115 /* Gain control, which applies to all input channels to a single (mono)
121 typedef const ALfloat
* (*ResamplerFunc
)(const ALfloat
*src
, ALuint frac
, ALuint increment
,
122 ALfloat
*restrict dst
, ALuint dstlen
);
124 typedef void (*MixerFunc
)(const ALfloat
*data
, ALuint OutChans
,
125 ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], struct MixGains
*Gains
,
126 ALuint Counter
, ALuint OutPos
, ALuint BufferSize
);
127 typedef void (*HrtfMixerFunc
)(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], const ALfloat
*data
,
128 ALuint Counter
, ALuint Offset
, ALuint OutPos
,
129 const ALuint IrSize
, const HrtfParams
*hrtfparams
,
130 HrtfState
*hrtfstate
, ALuint BufferSize
);
133 #define GAIN_SILENCE_THRESHOLD (0.00001f) /* -100dB */
135 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
136 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
138 #define FRACTIONBITS (14)
139 #define FRACTIONONE (1<<FRACTIONBITS)
140 #define FRACTIONMASK (FRACTIONONE-1)
143 inline ALfloat
minf(ALfloat a
, ALfloat b
)
144 { return ((a
> b
) ? b
: a
); }
145 inline ALfloat
maxf(ALfloat a
, ALfloat b
)
146 { return ((a
> b
) ? a
: b
); }
147 inline ALfloat
clampf(ALfloat val
, ALfloat min
, ALfloat max
)
148 { return minf(max
, maxf(min
, val
)); }
150 inline ALdouble
mind(ALdouble a
, ALdouble b
)
151 { return ((a
> b
) ? b
: a
); }
152 inline ALdouble
maxd(ALdouble a
, ALdouble b
)
153 { return ((a
> b
) ? a
: b
); }
154 inline ALdouble
clampd(ALdouble val
, ALdouble min
, ALdouble max
)
155 { return mind(max
, maxd(min
, val
)); }
157 inline ALuint
minu(ALuint a
, ALuint b
)
158 { return ((a
> b
) ? b
: a
); }
159 inline ALuint
maxu(ALuint a
, ALuint b
)
160 { return ((a
> b
) ? a
: b
); }
161 inline ALuint
clampu(ALuint val
, ALuint min
, ALuint max
)
162 { return minu(max
, maxu(min
, val
)); }
164 inline ALint
mini(ALint a
, ALint b
)
165 { return ((a
> b
) ? b
: a
); }
166 inline ALint
maxi(ALint a
, ALint b
)
167 { return ((a
> b
) ? a
: b
); }
168 inline ALint
clampi(ALint val
, ALint min
, ALint max
)
169 { return mini(max
, maxi(min
, val
)); }
171 inline ALint64
mini64(ALint64 a
, ALint64 b
)
172 { return ((a
> b
) ? b
: a
); }
173 inline ALint64
maxi64(ALint64 a
, ALint64 b
)
174 { return ((a
> b
) ? a
: b
); }
175 inline ALint64
clampi64(ALint64 val
, ALint64 min
, ALint64 max
)
176 { return mini64(max
, maxi64(min
, val
)); }
178 inline ALuint64
minu64(ALuint64 a
, ALuint64 b
)
179 { return ((a
> b
) ? b
: a
); }
180 inline ALuint64
maxu64(ALuint64 a
, ALuint64 b
)
181 { return ((a
> b
) ? a
: b
); }
182 inline ALuint64
clampu64(ALuint64 val
, ALuint64 min
, ALuint64 max
)
183 { return minu64(max
, maxu64(min
, val
)); }
186 inline ALfloat
lerp(ALfloat val1
, ALfloat val2
, ALfloat mu
)
188 return val1
+ (val2
-val1
)*mu
;
190 inline ALfloat
cubic(ALfloat val0
, ALfloat val1
, ALfloat val2
, ALfloat val3
, ALfloat mu
)
193 ALfloat a0
= -0.5f
*val0
+ 1.5f
*val1
+ -1.5f
*val2
+ 0.5f
*val3
;
194 ALfloat a1
= val0
+ -2.5f
*val1
+ 2.0f
*val2
+ -0.5f
*val3
;
195 ALfloat a2
= -0.5f
*val0
+ 0.5f
*val2
;
198 return a0
*mu
*mu2
+ a1
*mu2
+ a2
*mu
+ a3
;
202 ALvoid
aluInitPanning(ALCdevice
*Device
);
207 * Sets channel gains based on a given source's angle and its half-width. The
208 * angle and hwidth parameters are in radians.
210 void ComputeAngleGains(const ALCdevice
*device
, ALfloat angle
, ALfloat hwidth
, ALfloat ingain
, ALfloat gains
[MaxChannels
]);
215 * Helper to set the appropriate channels to the specified gain.
217 inline void SetGains(const ALCdevice
*device
, ALfloat ingain
, ALfloat gains
[MaxChannels
])
219 ComputeAngleGains(device
, 0.0f
, F_PI
, ingain
, gains
);
223 ALvoid
CalcSourceParams(struct ALvoice
*voice
, const struct ALsource
*source
, const ALCcontext
*ALContext
);
224 ALvoid
CalcNonAttnSourceParams(struct ALvoice
*voice
, const struct ALsource
*source
, const ALCcontext
*ALContext
);
226 ALvoid
MixSource(struct ALvoice
*voice
, struct ALsource
*source
, ALCdevice
*Device
, ALuint SamplesToDo
);
228 ALvoid
aluMixData(ALCdevice
*device
, ALvoid
*buffer
, ALsizei size
);
229 /* Caller must lock the device. */
230 ALvoid
aluHandleDisconnect(ALCdevice
*device
);
232 extern ALfloat ConeScale
;
233 extern ALfloat ZScale
;