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 enum ActiveFilters Filters
[MAX_INPUT_CHANNELS
];
80 ALfilterState LpFilter
[MAX_INPUT_CHANNELS
];
81 ALfilterState HpFilter
[MAX_INPUT_CHANNELS
];
83 /* If not 'moving', gain/coefficients are set directly without fading. */
85 /* Stepping counter for gain/coefficient fading. */
87 /* History/coefficient offset. */
92 HrtfParams Params
[MAX_INPUT_CHANNELS
];
93 HrtfState State
[MAX_INPUT_CHANNELS
];
99 MixGains Gains
[MAX_INPUT_CHANNELS
];
103 typedef struct SendParams
{
104 ALfloat (*OutBuffer
)[BUFFERSIZE
];
106 enum ActiveFilters Filters
[MAX_INPUT_CHANNELS
];
107 ALfilterState LpFilter
[MAX_INPUT_CHANNELS
];
108 ALfilterState HpFilter
[MAX_INPUT_CHANNELS
];
113 /* Gain control, which applies to all input channels to a single (mono)
119 typedef void (*ResamplerFunc
)(const ALfloat
*src
, ALuint frac
, ALuint increment
,
120 ALfloat
*restrict dst
, ALuint dstlen
);
122 typedef void (*DryMixerFunc
)(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], const ALfloat
*data
,
123 MixGains
*Gains
, ALuint Counter
, ALuint OutPos
,
125 typedef void (*HrtfMixerFunc
)(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], const ALfloat
*data
,
126 ALuint Counter
, ALuint Offset
, ALuint OutPos
,
127 const ALuint IrSize
, const HrtfParams
*hrtfparams
,
128 HrtfState
*hrtfstate
, ALuint BufferSize
);
129 typedef void (*WetMixerFunc
)(ALfloat (*restrict OutBuffer
)[BUFFERSIZE
], const ALfloat
*data
,
130 MixGainMono
*Gain
, ALuint Counter
, ALuint OutPos
,
134 #define GAIN_SILENCE_THRESHOLD (0.00001f) /* -100dB */
136 #define SPEEDOFSOUNDMETRESPERSEC (343.3f)
137 #define AIRABSORBGAINHF (0.99426f) /* -0.05dB */
139 #define FRACTIONBITS (14)
140 #define FRACTIONONE (1<<FRACTIONBITS)
141 #define FRACTIONMASK (FRACTIONONE-1)
144 inline ALfloat
minf(ALfloat a
, ALfloat b
)
145 { return ((a
> b
) ? b
: a
); }
146 inline ALfloat
maxf(ALfloat a
, ALfloat b
)
147 { return ((a
> b
) ? a
: b
); }
148 inline ALfloat
clampf(ALfloat val
, ALfloat min
, ALfloat max
)
149 { return minf(max
, maxf(min
, val
)); }
151 inline ALdouble
mind(ALdouble a
, ALdouble b
)
152 { return ((a
> b
) ? b
: a
); }
153 inline ALdouble
maxd(ALdouble a
, ALdouble b
)
154 { return ((a
> b
) ? a
: b
); }
155 inline ALdouble
clampd(ALdouble val
, ALdouble min
, ALdouble max
)
156 { return mind(max
, maxd(min
, val
)); }
158 inline ALuint
minu(ALuint a
, ALuint b
)
159 { return ((a
> b
) ? b
: a
); }
160 inline ALuint
maxu(ALuint a
, ALuint b
)
161 { return ((a
> b
) ? a
: b
); }
162 inline ALuint
clampu(ALuint val
, ALuint min
, ALuint max
)
163 { return minu(max
, maxu(min
, val
)); }
165 inline ALint
mini(ALint a
, ALint b
)
166 { return ((a
> b
) ? b
: a
); }
167 inline ALint
maxi(ALint a
, ALint b
)
168 { return ((a
> b
) ? a
: b
); }
169 inline ALint
clampi(ALint val
, ALint min
, ALint max
)
170 { return mini(max
, maxi(min
, val
)); }
172 inline ALint64
mini64(ALint64 a
, ALint64 b
)
173 { return ((a
> b
) ? b
: a
); }
174 inline ALint64
maxi64(ALint64 a
, ALint64 b
)
175 { return ((a
> b
) ? a
: b
); }
176 inline ALint64
clampi64(ALint64 val
, ALint64 min
, ALint64 max
)
177 { return mini64(max
, maxi64(min
, val
)); }
179 inline ALuint64
minu64(ALuint64 a
, ALuint64 b
)
180 { return ((a
> b
) ? b
: a
); }
181 inline ALuint64
maxu64(ALuint64 a
, ALuint64 b
)
182 { return ((a
> b
) ? a
: b
); }
183 inline ALuint64
clampu64(ALuint64 val
, ALuint64 min
, ALuint64 max
)
184 { return minu64(max
, maxu64(min
, val
)); }
187 inline ALfloat
lerp(ALfloat val1
, ALfloat val2
, ALfloat mu
)
189 return val1
+ (val2
-val1
)*mu
;
191 inline ALfloat
cubic(ALfloat val0
, ALfloat val1
, ALfloat val2
, ALfloat val3
, ALfloat mu
)
194 ALfloat a0
= -0.5f
*val0
+ 1.5f
*val1
+ -1.5f
*val2
+ 0.5f
*val3
;
195 ALfloat a1
= val0
+ -2.5f
*val1
+ 2.0f
*val2
+ -0.5f
*val3
;
196 ALfloat a2
= -0.5f
*val0
+ 0.5f
*val2
;
199 return a0
*mu
*mu2
+ a1
*mu2
+ a2
*mu
+ a3
;
203 ALvoid
aluInitPanning(ALCdevice
*Device
);
208 * Sets channel gains based on a given source's angle and its half-width. The
209 * angle and hwidth parameters are in radians.
211 void ComputeAngleGains(const ALCdevice
*device
, ALfloat angle
, ALfloat hwidth
, ALfloat ingain
, ALfloat gains
[MaxChannels
]);
216 * Helper to set the appropriate channels to the specified gain.
218 inline void SetGains(const ALCdevice
*device
, ALfloat ingain
, ALfloat gains
[MaxChannels
])
220 ComputeAngleGains(device
, 0.0f
, F_PI
, ingain
, gains
);
224 ALvoid
CalcSourceParams(struct ALactivesource
*src
, const ALCcontext
*ALContext
);
225 ALvoid
CalcNonAttnSourceParams(struct ALactivesource
*src
, const ALCcontext
*ALContext
);
227 ALvoid
MixSource(struct ALactivesource
*src
, ALCdevice
*Device
, ALuint SamplesToDo
);
229 ALvoid
aluMixData(ALCdevice
*device
, ALvoid
*buffer
, ALsizei size
);
230 /* Caller must lock the device. */
231 ALvoid
aluHandleDisconnect(ALCdevice
*device
);
233 extern ALfloat ConeScale
;
234 extern ALfloat ZScale
;