2 * Reverb for the OpenAL cross platform audio library
3 * Copyright (C) 2008-2009 by Christopher Fitzgerald.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 * Or go to http://www.gnu.org/copyleft/lgpl.html
29 #include "alAuxEffectSlot.h"
35 /* This is the maximum number of samples processed for each inner loop
37 #define MAX_UPDATE_SAMPLES 256
39 typedef struct DelayLine
41 // The delay lines use sample lengths that are powers of 2 to allow the
42 // use of bit-masking instead of a modulus for wrapping.
47 typedef struct ALreverbState
{
48 DERIVE_FROM_TYPE(ALeffectState
);
51 ALuint ExtraChannels
; // For HRTF
53 // All delay lines are allocated as a single buffer to reduce memory
54 // fragmentation and management code.
55 ALfloat
*SampleBuffer
;
58 // Master effect filters
59 ALfilterState LpFilter
;
60 ALfilterState HpFilter
; // EAX only
63 // Modulator delay line.
66 // The vibrato time is tracked with an index over a modulus-wrapped
67 // range (in samples).
71 // The depth of frequency change (also in samples) and its filter.
77 // Initial effect delay.
79 // The tap points for the initial delay. First tap goes to early
80 // reflections, the last to late reverb.
84 // Early reflections are done with 4 delay lines.
89 // The gain for each output channel based on 3D panning.
90 // NOTE: With certain output modes, we may be rendering to the dry
91 // buffer and the "real" buffer. The two combined may be using more
92 // than the max output channels, so we need some extra for the real
94 ALfloat PanGain
[4][MAX_OUTPUT_CHANNELS
*2];
97 // Decorrelator delay line.
98 DelayLine Decorrelator
;
99 // There are actually 4 decorrelator taps, but the first occurs at the
104 // Output gain for late reverb.
107 // Attenuation to compensate for the modal density and decay rate of
111 // The feed-back and feed-forward all-pass coefficient.
114 // Mixing matrix coefficient.
117 // Late reverb has 4 parallel all-pass filters.
119 DelayLine ApDelay
[4];
122 // In addition to 4 cyclical delay lines.
127 // The cyclical delay lines are 1-pole low-pass filtered.
131 // The gain for each output channel based on 3D panning.
132 // NOTE: Add some extra in case (see note about early pan).
133 ALfloat PanGain
[4][MAX_OUTPUT_CHANNELS
*2];
137 // Attenuation to compensate for the modal density and decay rate of
141 // Echo delay and all-pass lines.
152 // The echo line is 1-pole low-pass filtered.
156 // Echo mixing coefficient.
160 // The current read offset for all delay lines.
163 /* Temporary storage used when processing. */
164 ALfloat ReverbSamples
[MAX_UPDATE_SAMPLES
][4];
165 ALfloat EarlySamples
[MAX_UPDATE_SAMPLES
][4];
168 static ALvoid
ALreverbState_Destruct(ALreverbState
*State
)
170 free(State
->SampleBuffer
);
171 State
->SampleBuffer
= NULL
;
174 static ALboolean
ALreverbState_deviceUpdate(ALreverbState
*State
, ALCdevice
*Device
);
175 static ALvoid
ALreverbState_update(ALreverbState
*State
, const ALCdevice
*Device
, const ALeffectslot
*Slot
);
176 static ALvoid
ALreverbState_processStandard(ALreverbState
*State
, ALuint SamplesToDo
, const ALfloat
*restrict SamplesIn
, ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALuint NumChannels
);
177 static ALvoid
ALreverbState_processEax(ALreverbState
*State
, ALuint SamplesToDo
, const ALfloat
*restrict SamplesIn
, ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALuint NumChannels
);
178 static ALvoid
ALreverbState_process(ALreverbState
*State
, ALuint SamplesToDo
, const ALfloat (*restrict SamplesIn
)[BUFFERSIZE
], ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALuint NumChannels
);
179 DECLARE_DEFAULT_ALLOCATORS(ALreverbState
)
181 DEFINE_ALEFFECTSTATE_VTABLE(ALreverbState
);
183 /* This is a user config option for modifying the overall output of the reverb
186 ALfloat ReverbBoost
= 1.0f
;
188 /* Specifies whether to use a standard reverb effect in place of EAX reverb (no
189 * high-pass, modulation, or echo).
191 ALboolean EmulateEAXReverb
= AL_FALSE
;
193 /* This coefficient is used to define the maximum frequency range controlled
194 * by the modulation depth. The current value of 0.1 will allow it to swing
195 * from 0.9x to 1.1x. This value must be below 1. At 1 it will cause the
196 * sampler to stall on the downswing, and above 1 it will cause it to sample
199 static const ALfloat MODULATION_DEPTH_COEFF
= 0.1f
;
201 /* A filter is used to avoid the terrible distortion caused by changing
202 * modulation time and/or depth. To be consistent across different sample
203 * rates, the coefficient must be raised to a constant divided by the sample
204 * rate: coeff^(constant / rate).
206 static const ALfloat MODULATION_FILTER_COEFF
= 0.048f
;
207 static const ALfloat MODULATION_FILTER_CONST
= 100000.0f
;
209 // When diffusion is above 0, an all-pass filter is used to take the edge off
210 // the echo effect. It uses the following line length (in seconds).
211 static const ALfloat ECHO_ALLPASS_LENGTH
= 0.0133f
;
213 // Input into the late reverb is decorrelated between four channels. Their
214 // timings are dependent on a fraction and multiplier. See the
215 // UpdateDecorrelator() routine for the calculations involved.
216 static const ALfloat DECO_FRACTION
= 0.15f
;
217 static const ALfloat DECO_MULTIPLIER
= 2.0f
;
219 // All delay line lengths are specified in seconds.
221 // The lengths of the early delay lines.
222 static const ALfloat EARLY_LINE_LENGTH
[4] =
224 0.0015f
, 0.0045f
, 0.0135f
, 0.0405f
227 // The lengths of the late all-pass delay lines.
228 static const ALfloat ALLPASS_LINE_LENGTH
[4] =
230 0.0151f
, 0.0167f
, 0.0183f
, 0.0200f
,
233 // The lengths of the late cyclical delay lines.
234 static const ALfloat LATE_LINE_LENGTH
[4] =
236 0.0211f
, 0.0311f
, 0.0461f
, 0.0680f
239 // The late cyclical delay lines have a variable length dependent on the
240 // effect's density parameter (inverted for some reason) and this multiplier.
241 static const ALfloat LATE_LINE_MULTIPLIER
= 4.0f
;
244 #if defined(_WIN32) && !defined (_M_X64) && !defined(_M_ARM)
245 /* HACK: Workaround for a modff bug in 32-bit Windows, which attempts to write
246 * a 64-bit double to the 32-bit float parameter.
248 static inline float hack_modff(float x
, float *y
)
251 double df
= modf((double)x
, &di
);
255 #define modff hack_modff
259 /**************************************
261 **************************************/
263 // Given the allocated sample buffer, this function updates each delay line
265 static inline ALvoid
RealizeLineOffset(ALfloat
*sampleBuffer
, DelayLine
*Delay
)
267 Delay
->Line
= &sampleBuffer
[(ptrdiff_t)Delay
->Line
];
270 // Calculate the length of a delay line and store its mask and offset.
271 static ALuint
CalcLineLength(ALfloat length
, ptrdiff_t offset
, ALuint frequency
, ALuint extra
, DelayLine
*Delay
)
275 // All line lengths are powers of 2, calculated from their lengths, with
276 // an additional sample in case of rounding errors.
277 samples
= fastf2u(length
*frequency
) + extra
;
278 samples
= NextPowerOf2(samples
+ 1);
279 // All lines share a single sample buffer.
280 Delay
->Mask
= samples
- 1;
281 Delay
->Line
= (ALfloat
*)offset
;
282 // Return the sample count for accumulation.
286 /* Calculates the delay line metrics and allocates the shared sample buffer
287 * for all lines given the sample rate (frequency). If an allocation failure
288 * occurs, it returns AL_FALSE.
290 static ALboolean
AllocLines(ALuint frequency
, ALreverbState
*State
)
292 ALuint totalSamples
, index
;
294 ALfloat
*newBuffer
= NULL
;
296 // All delay line lengths are calculated to accomodate the full range of
297 // lengths given their respective paramters.
300 /* The modulator's line length is calculated from the maximum modulation
301 * time and depth coefficient, and halfed for the low-to-high frequency
302 * swing. An additional sample is added to keep it stable when there is no
305 length
= (AL_EAXREVERB_MAX_MODULATION_TIME
*MODULATION_DEPTH_COEFF
/2.0f
);
306 totalSamples
+= CalcLineLength(length
, totalSamples
, frequency
, 1,
309 // The initial delay is the sum of the reflections and late reverb
310 // delays. This must include space for storing a loop update to feed the
311 // early reflections, decorrelator, and echo.
312 length
= AL_EAXREVERB_MAX_REFLECTIONS_DELAY
+
313 AL_EAXREVERB_MAX_LATE_REVERB_DELAY
;
314 totalSamples
+= CalcLineLength(length
, totalSamples
, frequency
,
315 MAX_UPDATE_SAMPLES
, &State
->Delay
);
317 // The early reflection lines.
318 for(index
= 0;index
< 4;index
++)
319 totalSamples
+= CalcLineLength(EARLY_LINE_LENGTH
[index
], totalSamples
,
320 frequency
, 0, &State
->Early
.Delay
[index
]);
322 // The decorrelator line is calculated from the lowest reverb density (a
323 // parameter value of 1). This must include space for storing a loop update
324 // to feed the late reverb.
325 length
= (DECO_FRACTION
* DECO_MULTIPLIER
* DECO_MULTIPLIER
) *
326 LATE_LINE_LENGTH
[0] * (1.0f
+ LATE_LINE_MULTIPLIER
);
327 totalSamples
+= CalcLineLength(length
, totalSamples
, frequency
, MAX_UPDATE_SAMPLES
,
328 &State
->Decorrelator
);
330 // The late all-pass lines.
331 for(index
= 0;index
< 4;index
++)
332 totalSamples
+= CalcLineLength(ALLPASS_LINE_LENGTH
[index
], totalSamples
,
333 frequency
, 0, &State
->Late
.ApDelay
[index
]);
335 // The late delay lines are calculated from the lowest reverb density.
336 for(index
= 0;index
< 4;index
++)
338 length
= LATE_LINE_LENGTH
[index
] * (1.0f
+ LATE_LINE_MULTIPLIER
);
339 totalSamples
+= CalcLineLength(length
, totalSamples
, frequency
, 0,
340 &State
->Late
.Delay
[index
]);
343 // The echo all-pass and delay lines.
344 totalSamples
+= CalcLineLength(ECHO_ALLPASS_LENGTH
, totalSamples
,
345 frequency
, 0, &State
->Echo
.ApDelay
);
346 totalSamples
+= CalcLineLength(AL_EAXREVERB_MAX_ECHO_TIME
, totalSamples
,
347 frequency
, 0, &State
->Echo
.Delay
);
349 if(totalSamples
!= State
->TotalSamples
)
351 TRACE("New reverb buffer length: %u samples (%f sec)\n", totalSamples
, totalSamples
/(float)frequency
);
352 newBuffer
= realloc(State
->SampleBuffer
, sizeof(ALfloat
) * totalSamples
);
353 if(newBuffer
== NULL
)
355 State
->SampleBuffer
= newBuffer
;
356 State
->TotalSamples
= totalSamples
;
359 // Update all delays to reflect the new sample buffer.
360 RealizeLineOffset(State
->SampleBuffer
, &State
->Delay
);
361 RealizeLineOffset(State
->SampleBuffer
, &State
->Decorrelator
);
362 for(index
= 0;index
< 4;index
++)
364 RealizeLineOffset(State
->SampleBuffer
, &State
->Early
.Delay
[index
]);
365 RealizeLineOffset(State
->SampleBuffer
, &State
->Late
.ApDelay
[index
]);
366 RealizeLineOffset(State
->SampleBuffer
, &State
->Late
.Delay
[index
]);
368 RealizeLineOffset(State
->SampleBuffer
, &State
->Mod
.Delay
);
369 RealizeLineOffset(State
->SampleBuffer
, &State
->Echo
.ApDelay
);
370 RealizeLineOffset(State
->SampleBuffer
, &State
->Echo
.Delay
);
372 // Clear the sample buffer.
373 for(index
= 0;index
< State
->TotalSamples
;index
++)
374 State
->SampleBuffer
[index
] = 0.0f
;
379 static ALboolean
ALreverbState_deviceUpdate(ALreverbState
*State
, ALCdevice
*Device
)
381 ALuint frequency
= Device
->Frequency
, index
;
383 // Allocate the delay lines.
384 if(!AllocLines(frequency
, State
))
387 /* WARNING: This assumes the real output follows the virtual output in the
388 * device's DryBuffer.
390 if(Device
->Hrtf
|| Device
->Uhj_Encoder
)
391 State
->ExtraChannels
= ChannelsFromDevFmt(Device
->FmtChans
);
393 State
->ExtraChannels
= 0;
395 // Calculate the modulation filter coefficient. Notice that the exponent
396 // is calculated given the current sample rate. This ensures that the
397 // resulting filter response over time is consistent across all sample
399 State
->Mod
.Coeff
= powf(MODULATION_FILTER_COEFF
,
400 MODULATION_FILTER_CONST
/ frequency
);
402 // The early reflection and late all-pass filter line lengths are static,
403 // so their offsets only need to be calculated once.
404 for(index
= 0;index
< 4;index
++)
406 State
->Early
.Offset
[index
] = fastf2u(EARLY_LINE_LENGTH
[index
] * frequency
);
407 State
->Late
.ApOffset
[index
] = fastf2u(ALLPASS_LINE_LENGTH
[index
] * frequency
);
410 // The echo all-pass filter line length is static, so its offset only
411 // needs to be calculated once.
412 State
->Echo
.ApOffset
= fastf2u(ECHO_ALLPASS_LENGTH
* frequency
);
417 /**************************************
419 **************************************/
421 // Calculate a decay coefficient given the length of each cycle and the time
422 // until the decay reaches -60 dB.
423 static inline ALfloat
CalcDecayCoeff(ALfloat length
, ALfloat decayTime
)
425 return powf(0.001f
/*-60 dB*/, length
/decayTime
);
428 // Calculate a decay length from a coefficient and the time until the decay
430 static inline ALfloat
CalcDecayLength(ALfloat coeff
, ALfloat decayTime
)
432 return log10f(coeff
) * decayTime
/ log10f(0.001f
)/*-60 dB*/;
435 // Calculate an attenuation to be applied to the input of any echo models to
436 // compensate for modal density and decay time.
437 static inline ALfloat
CalcDensityGain(ALfloat a
)
439 /* The energy of a signal can be obtained by finding the area under the
440 * squared signal. This takes the form of Sum(x_n^2), where x is the
441 * amplitude for the sample n.
443 * Decaying feedback matches exponential decay of the form Sum(a^n),
444 * where a is the attenuation coefficient, and n is the sample. The area
445 * under this decay curve can be calculated as: 1 / (1 - a).
447 * Modifying the above equation to find the squared area under the curve
448 * (for energy) yields: 1 / (1 - a^2). Input attenuation can then be
449 * calculated by inverting the square root of this approximation,
450 * yielding: 1 / sqrt(1 / (1 - a^2)), simplified to: sqrt(1 - a^2).
452 return sqrtf(1.0f
- (a
* a
));
455 // Calculate the mixing matrix coefficients given a diffusion factor.
456 static inline ALvoid
CalcMatrixCoeffs(ALfloat diffusion
, ALfloat
*x
, ALfloat
*y
)
460 // The matrix is of order 4, so n is sqrt (4 - 1).
462 t
= diffusion
* atanf(n
);
464 // Calculate the first mixing matrix coefficient.
466 // Calculate the second mixing matrix coefficient.
470 // Calculate the limited HF ratio for use with the late reverb low-pass
472 static ALfloat
CalcLimitedHfRatio(ALfloat hfRatio
, ALfloat airAbsorptionGainHF
, ALfloat decayTime
)
476 /* Find the attenuation due to air absorption in dB (converting delay
477 * time to meters using the speed of sound). Then reversing the decay
478 * equation, solve for HF ratio. The delay length is cancelled out of
479 * the equation, so it can be calculated once for all lines.
481 limitRatio
= 1.0f
/ (CalcDecayLength(airAbsorptionGainHF
, decayTime
) *
482 SPEEDOFSOUNDMETRESPERSEC
);
483 /* Using the limit calculated above, apply the upper bound to the HF
484 * ratio. Also need to limit the result to a minimum of 0.1, just like the
485 * HF ratio parameter. */
486 return clampf(limitRatio
, 0.1f
, hfRatio
);
489 // Calculate the coefficient for a HF (and eventually LF) decay damping
491 static inline ALfloat
CalcDampingCoeff(ALfloat hfRatio
, ALfloat length
, ALfloat decayTime
, ALfloat decayCoeff
, ALfloat cw
)
495 // Eventually this should boost the high frequencies when the ratio
500 // Calculate the low-pass coefficient by dividing the HF decay
501 // coefficient by the full decay coefficient.
502 g
= CalcDecayCoeff(length
, decayTime
* hfRatio
) / decayCoeff
;
504 // Damping is done with a 1-pole filter, so g needs to be squared.
506 if(g
< 0.9999f
) /* 1-epsilon */
508 /* Be careful with gains < 0.001, as that causes the coefficient
509 * head towards 1, which will flatten the signal. */
511 coeff
= (1 - g
*cw
- sqrtf(2*g
*(1-cw
) - g
*g
*(1 - cw
*cw
))) /
515 // Very low decay times will produce minimal output, so apply an
516 // upper bound to the coefficient.
517 coeff
= minf(coeff
, 0.98f
);
522 // Update the EAX modulation index, range, and depth. Keep in mind that this
523 // kind of vibrato is additive and not multiplicative as one may expect. The
524 // downswing will sound stronger than the upswing.
525 static ALvoid
UpdateModulator(ALfloat modTime
, ALfloat modDepth
, ALuint frequency
, ALreverbState
*State
)
529 /* Modulation is calculated in two parts.
531 * The modulation time effects the sinus applied to the change in
532 * frequency. An index out of the current time range (both in samples)
533 * is incremented each sample. The range is bound to a reasonable
534 * minimum (1 sample) and when the timing changes, the index is rescaled
535 * to the new range (to keep the sinus consistent).
537 range
= maxu(fastf2u(modTime
*frequency
), 1);
538 State
->Mod
.Index
= (ALuint
)(State
->Mod
.Index
* (ALuint64
)range
/
540 State
->Mod
.Range
= range
;
542 /* The modulation depth effects the amount of frequency change over the
543 * range of the sinus. It needs to be scaled by the modulation time so
544 * that a given depth produces a consistent change in frequency over all
545 * ranges of time. Since the depth is applied to a sinus value, it needs
546 * to be halfed once for the sinus range and again for the sinus swing
547 * in time (half of it is spent decreasing the frequency, half is spent
550 State
->Mod
.Depth
= modDepth
* MODULATION_DEPTH_COEFF
* modTime
/ 2.0f
/
554 // Update the offsets for the initial effect delay line.
555 static ALvoid
UpdateDelayLine(ALfloat earlyDelay
, ALfloat lateDelay
, ALuint frequency
, ALreverbState
*State
)
557 // Calculate the initial delay taps.
558 State
->DelayTap
[0] = fastf2u(earlyDelay
* frequency
);
559 State
->DelayTap
[1] = fastf2u((earlyDelay
+ lateDelay
) * frequency
);
562 // Update the early reflections mix and line coefficients.
563 static ALvoid
UpdateEarlyLines(ALfloat lateDelay
, ALreverbState
*State
)
567 // Calculate the gain (coefficient) for each early delay line using the
568 // late delay time. This expands the early reflections to the start of
570 for(index
= 0;index
< 4;index
++)
571 State
->Early
.Coeff
[index
] = CalcDecayCoeff(EARLY_LINE_LENGTH
[index
],
575 // Update the offsets for the decorrelator line.
576 static ALvoid
UpdateDecorrelator(ALfloat density
, ALuint frequency
, ALreverbState
*State
)
581 /* The late reverb inputs are decorrelated to smooth the reverb tail and
582 * reduce harsh echos. The first tap occurs immediately, while the
583 * remaining taps are delayed by multiples of a fraction of the smallest
584 * cyclical delay time.
586 * offset[index] = (FRACTION (MULTIPLIER^index)) smallest_delay
588 for(index
= 0;index
< 3;index
++)
590 length
= (DECO_FRACTION
* powf(DECO_MULTIPLIER
, (ALfloat
)index
)) *
591 LATE_LINE_LENGTH
[0] * (1.0f
+ (density
* LATE_LINE_MULTIPLIER
));
592 State
->DecoTap
[index
] = fastf2u(length
* frequency
);
596 // Update the late reverb mix, line lengths, and line coefficients.
597 static ALvoid
UpdateLateLines(ALfloat xMix
, ALfloat density
, ALfloat decayTime
, ALfloat diffusion
, ALfloat echoDepth
, ALfloat hfRatio
, ALfloat cw
, ALuint frequency
, ALreverbState
*State
)
602 /* Calculate the late reverb gain. Since the output is tapped prior to the
603 * application of the next delay line coefficients, this gain needs to be
604 * attenuated by the 'x' mixing matrix coefficient as well. Also attenuate
605 * the late reverb when echo depth is high and diffusion is low, so the
606 * echo is slightly stronger than the decorrelated echos in the reverb
609 State
->Late
.Gain
= xMix
* (1.0f
- (echoDepth
*0.5f
*(1.0f
- diffusion
)));
611 /* To compensate for changes in modal density and decay time of the late
612 * reverb signal, the input is attenuated based on the maximal energy of
613 * the outgoing signal. This approximation is used to keep the apparent
614 * energy of the signal equal for all ranges of density and decay time.
616 * The average length of the cyclcical delay lines is used to calculate
617 * the attenuation coefficient.
619 length
= (LATE_LINE_LENGTH
[0] + LATE_LINE_LENGTH
[1] +
620 LATE_LINE_LENGTH
[2] + LATE_LINE_LENGTH
[3]) / 4.0f
;
621 length
*= 1.0f
+ (density
* LATE_LINE_MULTIPLIER
);
622 State
->Late
.DensityGain
= CalcDensityGain(
623 CalcDecayCoeff(length
, decayTime
)
626 // Calculate the all-pass feed-back and feed-forward coefficient.
627 State
->Late
.ApFeedCoeff
= 0.5f
* powf(diffusion
, 2.0f
);
629 for(index
= 0;index
< 4;index
++)
631 // Calculate the gain (coefficient) for each all-pass line.
632 State
->Late
.ApCoeff
[index
] = CalcDecayCoeff(
633 ALLPASS_LINE_LENGTH
[index
], decayTime
636 // Calculate the length (in seconds) of each cyclical delay line.
637 length
= LATE_LINE_LENGTH
[index
] *
638 (1.0f
+ (density
* LATE_LINE_MULTIPLIER
));
640 // Calculate the delay offset for each cyclical delay line.
641 State
->Late
.Offset
[index
] = fastf2u(length
* frequency
);
643 // Calculate the gain (coefficient) for each cyclical line.
644 State
->Late
.Coeff
[index
] = CalcDecayCoeff(length
, decayTime
);
646 // Calculate the damping coefficient for each low-pass filter.
647 State
->Late
.LpCoeff
[index
] = CalcDampingCoeff(
648 hfRatio
, length
, decayTime
, State
->Late
.Coeff
[index
], cw
651 // Attenuate the cyclical line coefficients by the mixing coefficient
653 State
->Late
.Coeff
[index
] *= xMix
;
657 // Update the echo gain, line offset, line coefficients, and mixing
659 static ALvoid
UpdateEchoLine(ALfloat echoTime
, ALfloat decayTime
, ALfloat diffusion
, ALfloat echoDepth
, ALfloat hfRatio
, ALfloat cw
, ALuint frequency
, ALreverbState
*State
)
661 // Update the offset and coefficient for the echo delay line.
662 State
->Echo
.Offset
= fastf2u(echoTime
* frequency
);
664 // Calculate the decay coefficient for the echo line.
665 State
->Echo
.Coeff
= CalcDecayCoeff(echoTime
, decayTime
);
667 // Calculate the energy-based attenuation coefficient for the echo delay
669 State
->Echo
.DensityGain
= CalcDensityGain(State
->Echo
.Coeff
);
671 // Calculate the echo all-pass feed coefficient.
672 State
->Echo
.ApFeedCoeff
= 0.5f
* powf(diffusion
, 2.0f
);
674 // Calculate the echo all-pass attenuation coefficient.
675 State
->Echo
.ApCoeff
= CalcDecayCoeff(ECHO_ALLPASS_LENGTH
, decayTime
);
677 // Calculate the damping coefficient for each low-pass filter.
678 State
->Echo
.LpCoeff
= CalcDampingCoeff(hfRatio
, echoTime
, decayTime
,
679 State
->Echo
.Coeff
, cw
);
681 /* Calculate the echo mixing coefficient. This is applied to the output mix
682 * only, not the feedback.
684 State
->Echo
.MixCoeff
= echoDepth
;
687 // Update the early and late 3D panning gains.
688 static ALvoid
UpdateMixedPanning(const ALCdevice
*Device
, const ALfloat
*ReflectionsPan
, const ALfloat
*LateReverbPan
, ALfloat Gain
, ALfloat EarlyGain
, ALfloat LateGain
, ALreverbState
*State
)
690 ALfloat DirGains
[MAX_OUTPUT_CHANNELS
];
691 ALfloat coeffs
[MAX_AMBI_COEFFS
];
695 /* With HRTF or UHJ, the normal output provides a panned reverb channel
696 * when a non-0-length vector is specified, while the real stereo output
697 * provides two other "direct" non-panned reverb channels.
699 * WARNING: This assumes the real output follows the virtual output in the
700 * device's DryBuffer.
702 memset(State
->Early
.PanGain
, 0, sizeof(State
->Early
.PanGain
));
703 length
= sqrtf(ReflectionsPan
[0]*ReflectionsPan
[0] + ReflectionsPan
[1]*ReflectionsPan
[1] + ReflectionsPan
[2]*ReflectionsPan
[2]);
704 if(!(length
> FLT_EPSILON
))
706 for(i
= 0;i
< Device
->RealOut
.NumChannels
;i
++)
707 State
->Early
.PanGain
[i
&3][Device
->Dry
.NumChannels
+i
] = Gain
* EarlyGain
;
711 /* Note that EAX Reverb's panning vectors are using right-handed
712 * coordinates, rather that the OpenAL's left-handed coordinates.
713 * Negate Z to fix this.
716 ReflectionsPan
[0] / length
,
717 ReflectionsPan
[1] / length
,
718 -ReflectionsPan
[2] / length
,
720 length
= minf(length
, 1.0f
);
722 CalcDirectionCoeffs(pan
, 0.0f
, coeffs
);
723 ComputePanningGains(Device
->Dry
, coeffs
, Gain
, DirGains
);
724 for(i
= 0;i
< Device
->Dry
.NumChannels
;i
++)
725 State
->Early
.PanGain
[3][i
] = DirGains
[i
] * EarlyGain
* length
;
726 for(i
= 0;i
< Device
->RealOut
.NumChannels
;i
++)
727 State
->Early
.PanGain
[i
&3][Device
->Dry
.NumChannels
+i
] = Gain
* EarlyGain
* (1.0f
-length
);
730 memset(State
->Late
.PanGain
, 0, sizeof(State
->Late
.PanGain
));
731 length
= sqrtf(LateReverbPan
[0]*LateReverbPan
[0] + LateReverbPan
[1]*LateReverbPan
[1] + LateReverbPan
[2]*LateReverbPan
[2]);
732 if(!(length
> FLT_EPSILON
))
734 for(i
= 0;i
< Device
->RealOut
.NumChannels
;i
++)
735 State
->Late
.PanGain
[i
&3][Device
->Dry
.NumChannels
+i
] = Gain
* LateGain
;
740 LateReverbPan
[0] / length
,
741 LateReverbPan
[1] / length
,
742 -LateReverbPan
[2] / length
,
744 length
= minf(length
, 1.0f
);
746 CalcDirectionCoeffs(pan
, 0.0f
, coeffs
);
747 ComputePanningGains(Device
->Dry
, coeffs
, Gain
, DirGains
);
748 for(i
= 0;i
< Device
->Dry
.NumChannels
;i
++)
749 State
->Late
.PanGain
[3][i
] = DirGains
[i
] * LateGain
* length
;
750 for(i
= 0;i
< Device
->RealOut
.NumChannels
;i
++)
751 State
->Late
.PanGain
[i
&3][Device
->Dry
.NumChannels
+i
] = Gain
* LateGain
* (1.0f
-length
);
755 static ALvoid
UpdateDirectPanning(const ALCdevice
*Device
, const ALfloat
*ReflectionsPan
, const ALfloat
*LateReverbPan
, ALfloat Gain
, ALfloat EarlyGain
, ALfloat LateGain
, ALreverbState
*State
)
757 ALfloat AmbientGains
[MAX_OUTPUT_CHANNELS
];
758 ALfloat DirGains
[MAX_OUTPUT_CHANNELS
];
759 ALfloat coeffs
[MAX_AMBI_COEFFS
];
763 /* Apply a boost of about 3dB to better match the expected stereo output volume. */
764 ComputeAmbientGains(Device
->Dry
, Gain
*1.414213562f
, AmbientGains
);
766 memset(State
->Early
.PanGain
, 0, sizeof(State
->Early
.PanGain
));
767 length
= sqrtf(ReflectionsPan
[0]*ReflectionsPan
[0] + ReflectionsPan
[1]*ReflectionsPan
[1] + ReflectionsPan
[2]*ReflectionsPan
[2]);
768 if(!(length
> FLT_EPSILON
))
770 for(i
= 0;i
< Device
->Dry
.NumChannels
;i
++)
771 State
->Early
.PanGain
[i
&3][i
] = AmbientGains
[i
] * EarlyGain
;
775 /* Note that EAX Reverb's panning vectors are using right-handed
776 * coordinates, rather that the OpenAL's left-handed coordinates.
777 * Negate Z to fix this.
780 ReflectionsPan
[0] / length
,
781 ReflectionsPan
[1] / length
,
782 -ReflectionsPan
[2] / length
,
784 length
= minf(length
, 1.0f
);
786 CalcDirectionCoeffs(pan
, 0.0f
, coeffs
);
787 ComputePanningGains(Device
->Dry
, coeffs
, Gain
, DirGains
);
788 for(i
= 0;i
< Device
->Dry
.NumChannels
;i
++)
789 State
->Early
.PanGain
[i
&3][i
] = lerp(AmbientGains
[i
], DirGains
[i
], length
) * EarlyGain
;
792 memset(State
->Late
.PanGain
, 0, sizeof(State
->Late
.PanGain
));
793 length
= sqrtf(LateReverbPan
[0]*LateReverbPan
[0] + LateReverbPan
[1]*LateReverbPan
[1] + LateReverbPan
[2]*LateReverbPan
[2]);
794 if(!(length
> FLT_EPSILON
))
796 for(i
= 0;i
< Device
->Dry
.NumChannels
;i
++)
797 State
->Late
.PanGain
[i
&3][i
] = AmbientGains
[i
] * LateGain
;
802 LateReverbPan
[0] / length
,
803 LateReverbPan
[1] / length
,
804 -LateReverbPan
[2] / length
,
806 length
= minf(length
, 1.0f
);
808 CalcDirectionCoeffs(pan
, 0.0f
, coeffs
);
809 ComputePanningGains(Device
->Dry
, coeffs
, Gain
, DirGains
);
810 for(i
= 0;i
< Device
->Dry
.NumChannels
;i
++)
811 State
->Late
.PanGain
[i
&3][i
] = lerp(AmbientGains
[i
], DirGains
[i
], length
) * LateGain
;
815 static ALvoid
Update3DPanning(const ALCdevice
*Device
, const ALfloat
*ReflectionsPan
, const ALfloat
*LateReverbPan
, ALfloat Gain
, ALfloat EarlyGain
, ALfloat LateGain
, ALreverbState
*State
)
817 static const ALfloat PanDirs
[4][3] = {
818 { -0.707106781f
, 0.0f
, -0.707106781f
}, /* Front left */
819 { 0.707106781f
, 0.0f
, -0.707106781f
}, /* Front right */
820 { 0.707106781f
, 0.0f
, 0.707106781f
}, /* Back right */
821 { -0.707106781f
, 0.0f
, 0.707106781f
} /* Back left */
823 ALfloat coeffs
[MAX_AMBI_COEFFS
];
828 /* 0.5 would be the gain scaling when the panning vector is 0. This also
829 * equals sqrt(1/4), a nice gain scaling for the four virtual points
830 * producing an "ambient" response.
832 gain
[0] = gain
[1] = gain
[2] = gain
[3] = 0.5f
;
833 length
= sqrtf(ReflectionsPan
[0]*ReflectionsPan
[0] + ReflectionsPan
[1]*ReflectionsPan
[1] + ReflectionsPan
[2]*ReflectionsPan
[2]);
837 ReflectionsPan
[0] / length
,
838 ReflectionsPan
[1] / length
,
839 -ReflectionsPan
[2] / length
,
843 ALfloat dotp
= pan
[0]*PanDirs
[i
][0] + pan
[1]*PanDirs
[i
][1] + pan
[2]*PanDirs
[i
][2];
844 gain
[i
] = dotp
*0.5f
+ 0.5f
;
847 else if(length
> FLT_EPSILON
)
851 ALfloat dotp
= ReflectionsPan
[0]*PanDirs
[i
][0] + ReflectionsPan
[1]*PanDirs
[i
][1] +
852 -ReflectionsPan
[2]*PanDirs
[i
][2];
853 gain
[i
] = dotp
*0.5f
+ 0.5f
;
858 CalcDirectionCoeffs(PanDirs
[i
], 0.0f
, coeffs
);
859 ComputePanningGains(Device
->Dry
, coeffs
, Gain
*EarlyGain
*gain
[i
],
860 State
->Early
.PanGain
[i
]);
863 gain
[0] = gain
[1] = gain
[2] = gain
[3] = 0.5f
;
864 length
= sqrtf(LateReverbPan
[0]*LateReverbPan
[0] + LateReverbPan
[1]*LateReverbPan
[1] + LateReverbPan
[2]*LateReverbPan
[2]);
868 LateReverbPan
[0] / length
,
869 LateReverbPan
[1] / length
,
870 -LateReverbPan
[2] / length
,
874 ALfloat dotp
= pan
[0]*PanDirs
[i
][0] + pan
[1]*PanDirs
[i
][1] + pan
[2]*PanDirs
[i
][2];
875 gain
[i
] = dotp
*0.5f
+ 0.5f
;
878 else if(length
> FLT_EPSILON
)
882 ALfloat dotp
= LateReverbPan
[0]*PanDirs
[i
][0] + LateReverbPan
[1]*PanDirs
[i
][1] +
883 -LateReverbPan
[2]*PanDirs
[i
][2];
884 gain
[i
] = dotp
*0.5f
+ 0.5f
;
889 CalcDirectionCoeffs(PanDirs
[i
], 0.0f
, coeffs
);
890 ComputePanningGains(Device
->Dry
, coeffs
, Gain
*LateGain
*gain
[i
],
891 State
->Late
.PanGain
[i
]);
895 static ALvoid
ALreverbState_update(ALreverbState
*State
, const ALCdevice
*Device
, const ALeffectslot
*Slot
)
897 const ALeffectProps
*props
= &Slot
->EffectProps
;
898 ALuint frequency
= Device
->Frequency
;
899 ALfloat lfscale
, hfscale
, hfRatio
;
900 ALfloat gain
, gainlf
, gainhf
;
903 if(Slot
->EffectType
== AL_EFFECT_EAXREVERB
&& !EmulateEAXReverb
)
904 State
->IsEax
= AL_TRUE
;
905 else if(Slot
->EffectType
== AL_EFFECT_REVERB
|| EmulateEAXReverb
)
906 State
->IsEax
= AL_FALSE
;
908 // Calculate the master filters
909 hfscale
= props
->Reverb
.HFReference
/ frequency
;
910 gainhf
= maxf(props
->Reverb
.GainHF
, 0.0001f
);
911 ALfilterState_setParams(&State
->LpFilter
, ALfilterType_HighShelf
,
912 gainhf
, hfscale
, calc_rcpQ_from_slope(gainhf
, 0.75f
));
913 lfscale
= props
->Reverb
.LFReference
/ frequency
;
914 gainlf
= maxf(props
->Reverb
.GainLF
, 0.0001f
);
915 ALfilterState_setParams(&State
->HpFilter
, ALfilterType_LowShelf
,
916 gainlf
, lfscale
, calc_rcpQ_from_slope(gainlf
, 0.75f
));
918 // Update the modulator line.
919 UpdateModulator(props
->Reverb
.ModulationTime
, props
->Reverb
.ModulationDepth
,
922 // Update the initial effect delay.
923 UpdateDelayLine(props
->Reverb
.ReflectionsDelay
, props
->Reverb
.LateReverbDelay
,
926 // Update the early lines.
927 UpdateEarlyLines(props
->Reverb
.LateReverbDelay
, State
);
929 // Update the decorrelator.
930 UpdateDecorrelator(props
->Reverb
.Density
, frequency
, State
);
932 // Get the mixing matrix coefficients (x and y).
933 CalcMatrixCoeffs(props
->Reverb
.Diffusion
, &x
, &y
);
934 // Then divide x into y to simplify the matrix calculation.
935 State
->Late
.MixCoeff
= y
/ x
;
937 // If the HF limit parameter is flagged, calculate an appropriate limit
938 // based on the air absorption parameter.
939 hfRatio
= props
->Reverb
.DecayHFRatio
;
940 if(props
->Reverb
.DecayHFLimit
&& props
->Reverb
.AirAbsorptionGainHF
< 1.0f
)
941 hfRatio
= CalcLimitedHfRatio(hfRatio
, props
->Reverb
.AirAbsorptionGainHF
,
942 props
->Reverb
.DecayTime
);
944 cw
= cosf(F_TAU
* hfscale
);
945 // Update the late lines.
946 UpdateLateLines(x
, props
->Reverb
.Density
, props
->Reverb
.DecayTime
,
947 props
->Reverb
.Diffusion
, props
->Reverb
.EchoDepth
,
948 hfRatio
, cw
, frequency
, State
);
950 // Update the echo line.
951 UpdateEchoLine(props
->Reverb
.EchoTime
, props
->Reverb
.DecayTime
,
952 props
->Reverb
.Diffusion
, props
->Reverb
.EchoDepth
,
953 hfRatio
, cw
, frequency
, State
);
955 gain
= props
->Reverb
.Gain
* Slot
->Gain
* ReverbBoost
;
956 // Update early and late 3D panning.
957 if(Device
->Hrtf
|| Device
->Uhj_Encoder
)
958 UpdateMixedPanning(Device
, props
->Reverb
.ReflectionsPan
,
959 props
->Reverb
.LateReverbPan
, gain
,
960 props
->Reverb
.ReflectionsGain
,
961 props
->Reverb
.LateReverbGain
, State
);
962 else if(Device
->FmtChans
== DevFmtBFormat3D
|| Device
->AmbiDecoder
)
963 Update3DPanning(Device
, props
->Reverb
.ReflectionsPan
,
964 props
->Reverb
.LateReverbPan
, gain
,
965 props
->Reverb
.ReflectionsGain
,
966 props
->Reverb
.LateReverbGain
, State
);
968 UpdateDirectPanning(Device
, props
->Reverb
.ReflectionsPan
,
969 props
->Reverb
.LateReverbPan
, gain
,
970 props
->Reverb
.ReflectionsGain
,
971 props
->Reverb
.LateReverbGain
, State
);
975 /**************************************
976 * Effect Processing *
977 **************************************/
979 // Basic delay line input/output routines.
980 static inline ALfloat
DelayLineOut(DelayLine
*Delay
, ALuint offset
)
982 return Delay
->Line
[offset
&Delay
->Mask
];
985 static inline ALvoid
DelayLineIn(DelayLine
*Delay
, ALuint offset
, ALfloat in
)
987 Delay
->Line
[offset
&Delay
->Mask
] = in
;
990 // Given an input sample, this function produces modulation for the late
992 static inline ALfloat
EAXModulation(ALreverbState
*State
, ALuint offset
, ALfloat in
)
994 ALfloat sinus
, frac
, fdelay
;
998 // Calculate the sinus rythm (dependent on modulation time and the
999 // sampling rate). The center of the sinus is moved to reduce the delay
1000 // of the effect when the time or depth are low.
1001 sinus
= 1.0f
- cosf(F_TAU
* State
->Mod
.Index
/ State
->Mod
.Range
);
1003 // Step the modulation index forward, keeping it bound to its range.
1004 State
->Mod
.Index
= (State
->Mod
.Index
+ 1) % State
->Mod
.Range
;
1006 // The depth determines the range over which to read the input samples
1007 // from, so it must be filtered to reduce the distortion caused by even
1008 // small parameter changes.
1009 State
->Mod
.Filter
= lerp(State
->Mod
.Filter
, State
->Mod
.Depth
,
1012 // Calculate the read offset and fraction between it and the next sample.
1013 frac
= modff(State
->Mod
.Filter
*sinus
, &fdelay
);
1014 delay
= fastf2u(fdelay
);
1016 /* Add the incoming sample to the delay line first, so a 0 delay gets the
1019 DelayLineIn(&State
->Mod
.Delay
, offset
, in
);
1020 /* Get the two samples crossed by the offset delay */
1021 out0
= DelayLineOut(&State
->Mod
.Delay
, offset
- delay
);
1022 out1
= DelayLineOut(&State
->Mod
.Delay
, offset
- delay
- 1);
1024 // The output is obtained by linearly interpolating the two samples that
1025 // were acquired above.
1026 return lerp(out0
, out1
, frac
);
1029 // Given some input sample, this function produces four-channel outputs for the
1030 // early reflections.
1031 static inline ALvoid
EarlyReflection(ALreverbState
*State
, ALuint todo
, ALfloat (*restrict out
)[4])
1033 ALfloat d
[4], v
, f
[4];
1036 for(i
= 0;i
< todo
;i
++)
1038 ALuint offset
= State
->Offset
+i
;
1040 // Obtain the decayed results of each early delay line.
1041 d
[0] = DelayLineOut(&State
->Early
.Delay
[0], offset
-State
->Early
.Offset
[0]) * State
->Early
.Coeff
[0];
1042 d
[1] = DelayLineOut(&State
->Early
.Delay
[1], offset
-State
->Early
.Offset
[1]) * State
->Early
.Coeff
[1];
1043 d
[2] = DelayLineOut(&State
->Early
.Delay
[2], offset
-State
->Early
.Offset
[2]) * State
->Early
.Coeff
[2];
1044 d
[3] = DelayLineOut(&State
->Early
.Delay
[3], offset
-State
->Early
.Offset
[3]) * State
->Early
.Coeff
[3];
1046 /* The following uses a lossless scattering junction from waveguide
1047 * theory. It actually amounts to a householder mixing matrix, which
1048 * will produce a maximally diffuse response, and means this can
1049 * probably be considered a simple feed-back delay network (FDN).
1057 v
= (d
[0] + d
[1] + d
[2] + d
[3]) * 0.5f
;
1058 // The junction is loaded with the input here.
1059 v
+= DelayLineOut(&State
->Delay
, offset
-State
->DelayTap
[0]);
1061 // Calculate the feed values for the delay lines.
1067 // Re-feed the delay lines.
1068 DelayLineIn(&State
->Early
.Delay
[0], offset
, f
[0]);
1069 DelayLineIn(&State
->Early
.Delay
[1], offset
, f
[1]);
1070 DelayLineIn(&State
->Early
.Delay
[2], offset
, f
[2]);
1071 DelayLineIn(&State
->Early
.Delay
[3], offset
, f
[3]);
1073 /* Output the results of the junction for all four channels with a
1074 * constant attenuation of 0.5.
1076 out
[i
][0] = f
[0] * 0.5f
;
1077 out
[i
][1] = f
[1] * 0.5f
;
1078 out
[i
][2] = f
[2] * 0.5f
;
1079 out
[i
][3] = f
[3] * 0.5f
;
1083 // Basic attenuated all-pass input/output routine.
1084 static inline ALfloat
AllpassInOut(DelayLine
*Delay
, ALuint outOffset
, ALuint inOffset
, ALfloat in
, ALfloat feedCoeff
, ALfloat coeff
)
1088 out
= DelayLineOut(Delay
, outOffset
);
1089 feed
= feedCoeff
* in
;
1090 DelayLineIn(Delay
, inOffset
, (feedCoeff
* (out
- feed
)) + in
);
1092 // The time-based attenuation is only applied to the delay output to
1093 // keep it from affecting the feed-back path (which is already controlled
1094 // by the all-pass feed coefficient).
1095 return (coeff
* out
) - feed
;
1098 // All-pass input/output routine for late reverb.
1099 static inline ALfloat
LateAllPassInOut(ALreverbState
*State
, ALuint offset
, ALuint index
, ALfloat in
)
1101 return AllpassInOut(&State
->Late
.ApDelay
[index
],
1102 offset
- State
->Late
.ApOffset
[index
],
1103 offset
, in
, State
->Late
.ApFeedCoeff
,
1104 State
->Late
.ApCoeff
[index
]);
1107 // Low-pass filter input/output routine for late reverb.
1108 static inline ALfloat
LateLowPassInOut(ALreverbState
*State
, ALuint index
, ALfloat in
)
1110 in
= lerp(in
, State
->Late
.LpSample
[index
], State
->Late
.LpCoeff
[index
]);
1111 State
->Late
.LpSample
[index
] = in
;
1115 // Given four decorrelated input samples, this function produces four-channel
1116 // output for the late reverb.
1117 static inline ALvoid
LateReverb(ALreverbState
*State
, ALuint todo
, ALfloat (*restrict out
)[4])
1122 // Feed the decorrelator from the energy-attenuated output of the second
1124 for(i
= 0;i
< todo
;i
++)
1126 ALuint offset
= State
->Offset
+i
;
1127 ALfloat sample
= DelayLineOut(&State
->Delay
, offset
- State
->DelayTap
[1]) *
1128 State
->Late
.DensityGain
;
1129 DelayLineIn(&State
->Decorrelator
, offset
, sample
);
1132 for(i
= 0;i
< todo
;i
++)
1134 ALuint offset
= State
->Offset
+i
;
1136 /* Obtain four decorrelated input samples. */
1137 f
[0] = DelayLineOut(&State
->Decorrelator
, offset
);
1138 f
[1] = DelayLineOut(&State
->Decorrelator
, offset
-State
->DecoTap
[0]);
1139 f
[2] = DelayLineOut(&State
->Decorrelator
, offset
-State
->DecoTap
[1]);
1140 f
[3] = DelayLineOut(&State
->Decorrelator
, offset
-State
->DecoTap
[2]);
1142 /* Add the decayed results of the cyclical delay lines, then pass the
1143 * results through the low-pass filters.
1145 f
[0] += DelayLineOut(&State
->Late
.Delay
[0], offset
-State
->Late
.Offset
[0]) * State
->Late
.Coeff
[0];
1146 f
[1] += DelayLineOut(&State
->Late
.Delay
[1], offset
-State
->Late
.Offset
[1]) * State
->Late
.Coeff
[1];
1147 f
[2] += DelayLineOut(&State
->Late
.Delay
[2], offset
-State
->Late
.Offset
[2]) * State
->Late
.Coeff
[2];
1148 f
[3] += DelayLineOut(&State
->Late
.Delay
[3], offset
-State
->Late
.Offset
[3]) * State
->Late
.Coeff
[3];
1150 // This is where the feed-back cycles from line 0 to 1 to 3 to 2 and
1152 d
[0] = LateLowPassInOut(State
, 2, f
[2]);
1153 d
[1] = LateLowPassInOut(State
, 0, f
[0]);
1154 d
[2] = LateLowPassInOut(State
, 3, f
[3]);
1155 d
[3] = LateLowPassInOut(State
, 1, f
[1]);
1157 // To help increase diffusion, run each line through an all-pass filter.
1158 // When there is no diffusion, the shortest all-pass filter will feed
1159 // the shortest delay line.
1160 d
[0] = LateAllPassInOut(State
, offset
, 0, d
[0]);
1161 d
[1] = LateAllPassInOut(State
, offset
, 1, d
[1]);
1162 d
[2] = LateAllPassInOut(State
, offset
, 2, d
[2]);
1163 d
[3] = LateAllPassInOut(State
, offset
, 3, d
[3]);
1165 /* Late reverb is done with a modified feed-back delay network (FDN)
1166 * topology. Four input lines are each fed through their own all-pass
1167 * filter and then into the mixing matrix. The four outputs of the
1168 * mixing matrix are then cycled back to the inputs. Each output feeds
1169 * a different input to form a circlular feed cycle.
1171 * The mixing matrix used is a 4D skew-symmetric rotation matrix
1172 * derived using a single unitary rotational parameter:
1174 * [ d, a, b, c ] 1 = a^2 + b^2 + c^2 + d^2
1179 * The rotation is constructed from the effect's diffusion parameter,
1180 * yielding: 1 = x^2 + 3 y^2; where a, b, and c are the coefficient y
1181 * with differing signs, and d is the coefficient x. The matrix is
1184 * [ x, y, -y, y ] n = sqrt(matrix_order - 1)
1185 * [ -y, x, y, y ] t = diffusion_parameter * atan(n)
1186 * [ y, -y, x, y ] x = cos(t)
1187 * [ -y, -y, -y, x ] y = sin(t) / n
1189 * To reduce the number of multiplies, the x coefficient is applied
1190 * with the cyclical delay line coefficients. Thus only the y
1191 * coefficient is applied when mixing, and is modified to be: y / x.
1193 f
[0] = d
[0] + (State
->Late
.MixCoeff
* ( d
[1] + -d
[2] + d
[3]));
1194 f
[1] = d
[1] + (State
->Late
.MixCoeff
* (-d
[0] + d
[2] + d
[3]));
1195 f
[2] = d
[2] + (State
->Late
.MixCoeff
* ( d
[0] + -d
[1] + d
[3]));
1196 f
[3] = d
[3] + (State
->Late
.MixCoeff
* (-d
[0] + -d
[1] + -d
[2] ));
1198 // Output the results of the matrix for all four channels, attenuated by
1199 // the late reverb gain (which is attenuated by the 'x' mix coefficient).
1200 out
[i
][0] = State
->Late
.Gain
* f
[0];
1201 out
[i
][1] = State
->Late
.Gain
* f
[1];
1202 out
[i
][2] = State
->Late
.Gain
* f
[2];
1203 out
[i
][3] = State
->Late
.Gain
* f
[3];
1205 // Re-feed the cyclical delay lines.
1206 DelayLineIn(&State
->Late
.Delay
[0], offset
, f
[0]);
1207 DelayLineIn(&State
->Late
.Delay
[1], offset
, f
[1]);
1208 DelayLineIn(&State
->Late
.Delay
[2], offset
, f
[2]);
1209 DelayLineIn(&State
->Late
.Delay
[3], offset
, f
[3]);
1213 // Given an input sample, this function mixes echo into the four-channel late
1215 static inline ALvoid
EAXEcho(ALreverbState
*State
, ALuint todo
, ALfloat (*restrict late
)[4])
1220 for(i
= 0;i
< todo
;i
++)
1222 ALuint offset
= State
->Offset
+i
;
1224 // Get the latest attenuated echo sample for output.
1225 feed
= DelayLineOut(&State
->Echo
.Delay
, offset
-State
->Echo
.Offset
) *
1228 // Mix the output into the late reverb channels.
1229 out
= State
->Echo
.MixCoeff
* feed
;
1235 // Mix the energy-attenuated input with the output and pass it through
1236 // the echo low-pass filter.
1237 feed
+= DelayLineOut(&State
->Delay
, offset
-State
->DelayTap
[1]) *
1238 State
->Echo
.DensityGain
;
1239 feed
= lerp(feed
, State
->Echo
.LpSample
, State
->Echo
.LpCoeff
);
1240 State
->Echo
.LpSample
= feed
;
1242 // Then the echo all-pass filter.
1243 feed
= AllpassInOut(&State
->Echo
.ApDelay
, offset
-State
->Echo
.ApOffset
,
1244 offset
, feed
, State
->Echo
.ApFeedCoeff
,
1245 State
->Echo
.ApCoeff
);
1247 // Feed the delay with the mixed and filtered sample.
1248 DelayLineIn(&State
->Echo
.Delay
, offset
, feed
);
1252 // Perform the non-EAX reverb pass on a given input sample, resulting in
1253 // four-channel output.
1254 static inline ALvoid
VerbPass(ALreverbState
*State
, ALuint todo
, const ALfloat
*in
, ALfloat (*restrict early
)[4], ALfloat (*restrict late
)[4])
1258 // Low-pass filter the incoming samples.
1259 for(i
= 0;i
< todo
;i
++)
1260 DelayLineIn(&State
->Delay
, State
->Offset
+i
,
1261 ALfilterState_processSingle(&State
->LpFilter
, in
[i
])
1264 // Calculate the early reflection from the first delay tap.
1265 EarlyReflection(State
, todo
, early
);
1267 // Calculate the late reverb from the decorrelator taps.
1268 LateReverb(State
, todo
, late
);
1270 // Step all delays forward one sample.
1271 State
->Offset
+= todo
;
1274 // Perform the EAX reverb pass on a given input sample, resulting in four-
1276 static inline ALvoid
EAXVerbPass(ALreverbState
*State
, ALuint todo
, const ALfloat
*input
, ALfloat (*restrict early
)[4], ALfloat (*restrict late
)[4])
1280 // Band-pass and modulate the incoming samples.
1281 for(i
= 0;i
< todo
;i
++)
1283 ALfloat sample
= input
[i
];
1284 sample
= ALfilterState_processSingle(&State
->LpFilter
, sample
);
1285 sample
= ALfilterState_processSingle(&State
->HpFilter
, sample
);
1287 // Perform any modulation on the input.
1288 sample
= EAXModulation(State
, State
->Offset
+i
, sample
);
1290 // Feed the initial delay line.
1291 DelayLineIn(&State
->Delay
, State
->Offset
+i
, sample
);
1294 // Calculate the early reflection from the first delay tap.
1295 EarlyReflection(State
, todo
, early
);
1297 // Calculate the late reverb from the decorrelator taps.
1298 LateReverb(State
, todo
, late
);
1300 // Calculate and mix in any echo.
1301 EAXEcho(State
, todo
, late
);
1303 // Step all delays forward.
1304 State
->Offset
+= todo
;
1307 static ALvoid
ALreverbState_processStandard(ALreverbState
*State
, ALuint SamplesToDo
, const ALfloat
*restrict SamplesIn
, ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALuint NumChannels
)
1309 ALfloat (*restrict early
)[4] = State
->EarlySamples
;
1310 ALfloat (*restrict late
)[4] = State
->ReverbSamples
;
1311 ALuint index
, c
, i
, l
;
1314 /* Process reverb for these samples. */
1315 for(index
= 0;index
< SamplesToDo
;)
1317 ALuint todo
= minu(SamplesToDo
-index
, MAX_UPDATE_SAMPLES
);
1319 VerbPass(State
, todo
, &SamplesIn
[index
], early
, late
);
1321 for(l
= 0;l
< 4;l
++)
1323 for(c
= 0;c
< NumChannels
;c
++)
1325 gain
= State
->Early
.PanGain
[l
][c
];
1326 if(fabsf(gain
) > GAIN_SILENCE_THRESHOLD
)
1328 for(i
= 0;i
< todo
;i
++)
1329 SamplesOut
[c
][index
+i
] += gain
*early
[i
][l
];
1331 gain
= State
->Late
.PanGain
[l
][c
];
1332 if(fabsf(gain
) > GAIN_SILENCE_THRESHOLD
)
1334 for(i
= 0;i
< todo
;i
++)
1335 SamplesOut
[c
][index
+i
] += gain
*late
[i
][l
];
1344 static ALvoid
ALreverbState_processEax(ALreverbState
*State
, ALuint SamplesToDo
, const ALfloat
*restrict SamplesIn
, ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALuint NumChannels
)
1346 ALfloat (*restrict early
)[4] = State
->EarlySamples
;
1347 ALfloat (*restrict late
)[4] = State
->ReverbSamples
;
1348 ALuint index
, c
, i
, l
;
1351 /* Process reverb for these samples. */
1352 for(index
= 0;index
< SamplesToDo
;)
1354 ALuint todo
= minu(SamplesToDo
-index
, MAX_UPDATE_SAMPLES
);
1356 EAXVerbPass(State
, todo
, &SamplesIn
[index
], early
, late
);
1358 for(l
= 0;l
< 4;l
++)
1360 for(c
= 0;c
< NumChannels
;c
++)
1362 gain
= State
->Early
.PanGain
[l
][c
];
1363 if(fabsf(gain
) > GAIN_SILENCE_THRESHOLD
)
1365 for(i
= 0;i
< todo
;i
++)
1366 SamplesOut
[c
][index
+i
] += gain
*early
[i
][l
];
1368 gain
= State
->Late
.PanGain
[l
][c
];
1369 if(fabsf(gain
) > GAIN_SILENCE_THRESHOLD
)
1371 for(i
= 0;i
< todo
;i
++)
1372 SamplesOut
[c
][index
+i
] += gain
*late
[i
][l
];
1381 static ALvoid
ALreverbState_process(ALreverbState
*State
, ALuint SamplesToDo
, const ALfloat (*restrict SamplesIn
)[BUFFERSIZE
], ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALuint NumChannels
)
1383 NumChannels
+= State
->ExtraChannels
;
1385 ALreverbState_processEax(State
, SamplesToDo
, SamplesIn
[0], SamplesOut
, NumChannels
);
1387 ALreverbState_processStandard(State
, SamplesToDo
, SamplesIn
[0], SamplesOut
, NumChannels
);
1391 typedef struct ALreverbStateFactory
{
1392 DERIVE_FROM_TYPE(ALeffectStateFactory
);
1393 } ALreverbStateFactory
;
1395 static ALeffectState
*ALreverbStateFactory_create(ALreverbStateFactory
* UNUSED(factory
))
1397 ALreverbState
*state
;
1400 state
= ALreverbState_New(sizeof(*state
));
1401 if(!state
) return NULL
;
1402 SET_VTABLE2(ALreverbState
, ALeffectState
, state
);
1404 state
->IsEax
= AL_FALSE
;
1405 state
->ExtraChannels
= 0;
1407 state
->TotalSamples
= 0;
1408 state
->SampleBuffer
= NULL
;
1410 ALfilterState_clear(&state
->LpFilter
);
1411 ALfilterState_clear(&state
->HpFilter
);
1413 state
->Mod
.Delay
.Mask
= 0;
1414 state
->Mod
.Delay
.Line
= NULL
;
1415 state
->Mod
.Index
= 0;
1416 state
->Mod
.Range
= 1;
1417 state
->Mod
.Depth
= 0.0f
;
1418 state
->Mod
.Coeff
= 0.0f
;
1419 state
->Mod
.Filter
= 0.0f
;
1421 state
->Delay
.Mask
= 0;
1422 state
->Delay
.Line
= NULL
;
1423 state
->DelayTap
[0] = 0;
1424 state
->DelayTap
[1] = 0;
1426 for(index
= 0;index
< 4;index
++)
1428 state
->Early
.Coeff
[index
] = 0.0f
;
1429 state
->Early
.Delay
[index
].Mask
= 0;
1430 state
->Early
.Delay
[index
].Line
= NULL
;
1431 state
->Early
.Offset
[index
] = 0;
1434 state
->Decorrelator
.Mask
= 0;
1435 state
->Decorrelator
.Line
= NULL
;
1436 state
->DecoTap
[0] = 0;
1437 state
->DecoTap
[1] = 0;
1438 state
->DecoTap
[2] = 0;
1440 state
->Late
.Gain
= 0.0f
;
1441 state
->Late
.DensityGain
= 0.0f
;
1442 state
->Late
.ApFeedCoeff
= 0.0f
;
1443 state
->Late
.MixCoeff
= 0.0f
;
1444 for(index
= 0;index
< 4;index
++)
1446 state
->Late
.ApCoeff
[index
] = 0.0f
;
1447 state
->Late
.ApDelay
[index
].Mask
= 0;
1448 state
->Late
.ApDelay
[index
].Line
= NULL
;
1449 state
->Late
.ApOffset
[index
] = 0;
1451 state
->Late
.Coeff
[index
] = 0.0f
;
1452 state
->Late
.Delay
[index
].Mask
= 0;
1453 state
->Late
.Delay
[index
].Line
= NULL
;
1454 state
->Late
.Offset
[index
] = 0;
1456 state
->Late
.LpCoeff
[index
] = 0.0f
;
1457 state
->Late
.LpSample
[index
] = 0.0f
;
1460 for(l
= 0;l
< 4;l
++)
1462 for(index
= 0;index
< MAX_OUTPUT_CHANNELS
;index
++)
1464 state
->Early
.PanGain
[l
][index
] = 0.0f
;
1465 state
->Late
.PanGain
[l
][index
] = 0.0f
;
1469 state
->Echo
.DensityGain
= 0.0f
;
1470 state
->Echo
.Delay
.Mask
= 0;
1471 state
->Echo
.Delay
.Line
= NULL
;
1472 state
->Echo
.ApDelay
.Mask
= 0;
1473 state
->Echo
.ApDelay
.Line
= NULL
;
1474 state
->Echo
.Coeff
= 0.0f
;
1475 state
->Echo
.ApFeedCoeff
= 0.0f
;
1476 state
->Echo
.ApCoeff
= 0.0f
;
1477 state
->Echo
.Offset
= 0;
1478 state
->Echo
.ApOffset
= 0;
1479 state
->Echo
.LpCoeff
= 0.0f
;
1480 state
->Echo
.LpSample
= 0.0f
;
1481 state
->Echo
.MixCoeff
= 0.0f
;
1485 return STATIC_CAST(ALeffectState
, state
);
1488 DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALreverbStateFactory
);
1490 ALeffectStateFactory
*ALreverbStateFactory_getFactory(void)
1492 static ALreverbStateFactory ReverbFactory
= { { GET_VTABLE2(ALreverbStateFactory
, ALeffectStateFactory
) } };
1494 return STATIC_CAST(ALeffectStateFactory
, &ReverbFactory
);
1498 void ALeaxreverb_setParami(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALint val
)
1500 ALeffectProps
*props
= &effect
->Props
;
1503 case AL_EAXREVERB_DECAY_HFLIMIT
:
1504 if(!(val
>= AL_EAXREVERB_MIN_DECAY_HFLIMIT
&& val
<= AL_EAXREVERB_MAX_DECAY_HFLIMIT
))
1505 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1506 props
->Reverb
.DecayHFLimit
= val
;
1510 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1513 void ALeaxreverb_setParamiv(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, const ALint
*vals
)
1515 ALeaxreverb_setParami(effect
, context
, param
, vals
[0]);
1517 void ALeaxreverb_setParamf(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat val
)
1519 ALeffectProps
*props
= &effect
->Props
;
1522 case AL_EAXREVERB_DENSITY
:
1523 if(!(val
>= AL_EAXREVERB_MIN_DENSITY
&& val
<= AL_EAXREVERB_MAX_DENSITY
))
1524 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1525 props
->Reverb
.Density
= val
;
1528 case AL_EAXREVERB_DIFFUSION
:
1529 if(!(val
>= AL_EAXREVERB_MIN_DIFFUSION
&& val
<= AL_EAXREVERB_MAX_DIFFUSION
))
1530 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1531 props
->Reverb
.Diffusion
= val
;
1534 case AL_EAXREVERB_GAIN
:
1535 if(!(val
>= AL_EAXREVERB_MIN_GAIN
&& val
<= AL_EAXREVERB_MAX_GAIN
))
1536 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1537 props
->Reverb
.Gain
= val
;
1540 case AL_EAXREVERB_GAINHF
:
1541 if(!(val
>= AL_EAXREVERB_MIN_GAINHF
&& val
<= AL_EAXREVERB_MAX_GAINHF
))
1542 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1543 props
->Reverb
.GainHF
= val
;
1546 case AL_EAXREVERB_GAINLF
:
1547 if(!(val
>= AL_EAXREVERB_MIN_GAINLF
&& val
<= AL_EAXREVERB_MAX_GAINLF
))
1548 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1549 props
->Reverb
.GainLF
= val
;
1552 case AL_EAXREVERB_DECAY_TIME
:
1553 if(!(val
>= AL_EAXREVERB_MIN_DECAY_TIME
&& val
<= AL_EAXREVERB_MAX_DECAY_TIME
))
1554 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1555 props
->Reverb
.DecayTime
= val
;
1558 case AL_EAXREVERB_DECAY_HFRATIO
:
1559 if(!(val
>= AL_EAXREVERB_MIN_DECAY_HFRATIO
&& val
<= AL_EAXREVERB_MAX_DECAY_HFRATIO
))
1560 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1561 props
->Reverb
.DecayHFRatio
= val
;
1564 case AL_EAXREVERB_DECAY_LFRATIO
:
1565 if(!(val
>= AL_EAXREVERB_MIN_DECAY_LFRATIO
&& val
<= AL_EAXREVERB_MAX_DECAY_LFRATIO
))
1566 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1567 props
->Reverb
.DecayLFRatio
= val
;
1570 case AL_EAXREVERB_REFLECTIONS_GAIN
:
1571 if(!(val
>= AL_EAXREVERB_MIN_REFLECTIONS_GAIN
&& val
<= AL_EAXREVERB_MAX_REFLECTIONS_GAIN
))
1572 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1573 props
->Reverb
.ReflectionsGain
= val
;
1576 case AL_EAXREVERB_REFLECTIONS_DELAY
:
1577 if(!(val
>= AL_EAXREVERB_MIN_REFLECTIONS_DELAY
&& val
<= AL_EAXREVERB_MAX_REFLECTIONS_DELAY
))
1578 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1579 props
->Reverb
.ReflectionsDelay
= val
;
1582 case AL_EAXREVERB_LATE_REVERB_GAIN
:
1583 if(!(val
>= AL_EAXREVERB_MIN_LATE_REVERB_GAIN
&& val
<= AL_EAXREVERB_MAX_LATE_REVERB_GAIN
))
1584 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1585 props
->Reverb
.LateReverbGain
= val
;
1588 case AL_EAXREVERB_LATE_REVERB_DELAY
:
1589 if(!(val
>= AL_EAXREVERB_MIN_LATE_REVERB_DELAY
&& val
<= AL_EAXREVERB_MAX_LATE_REVERB_DELAY
))
1590 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1591 props
->Reverb
.LateReverbDelay
= val
;
1594 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF
:
1595 if(!(val
>= AL_EAXREVERB_MIN_AIR_ABSORPTION_GAINHF
&& val
<= AL_EAXREVERB_MAX_AIR_ABSORPTION_GAINHF
))
1596 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1597 props
->Reverb
.AirAbsorptionGainHF
= val
;
1600 case AL_EAXREVERB_ECHO_TIME
:
1601 if(!(val
>= AL_EAXREVERB_MIN_ECHO_TIME
&& val
<= AL_EAXREVERB_MAX_ECHO_TIME
))
1602 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1603 props
->Reverb
.EchoTime
= val
;
1606 case AL_EAXREVERB_ECHO_DEPTH
:
1607 if(!(val
>= AL_EAXREVERB_MIN_ECHO_DEPTH
&& val
<= AL_EAXREVERB_MAX_ECHO_DEPTH
))
1608 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1609 props
->Reverb
.EchoDepth
= val
;
1612 case AL_EAXREVERB_MODULATION_TIME
:
1613 if(!(val
>= AL_EAXREVERB_MIN_MODULATION_TIME
&& val
<= AL_EAXREVERB_MAX_MODULATION_TIME
))
1614 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1615 props
->Reverb
.ModulationTime
= val
;
1618 case AL_EAXREVERB_MODULATION_DEPTH
:
1619 if(!(val
>= AL_EAXREVERB_MIN_MODULATION_DEPTH
&& val
<= AL_EAXREVERB_MAX_MODULATION_DEPTH
))
1620 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1621 props
->Reverb
.ModulationDepth
= val
;
1624 case AL_EAXREVERB_HFREFERENCE
:
1625 if(!(val
>= AL_EAXREVERB_MIN_HFREFERENCE
&& val
<= AL_EAXREVERB_MAX_HFREFERENCE
))
1626 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1627 props
->Reverb
.HFReference
= val
;
1630 case AL_EAXREVERB_LFREFERENCE
:
1631 if(!(val
>= AL_EAXREVERB_MIN_LFREFERENCE
&& val
<= AL_EAXREVERB_MAX_LFREFERENCE
))
1632 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1633 props
->Reverb
.LFReference
= val
;
1636 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR
:
1637 if(!(val
>= AL_EAXREVERB_MIN_ROOM_ROLLOFF_FACTOR
&& val
<= AL_EAXREVERB_MAX_ROOM_ROLLOFF_FACTOR
))
1638 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1639 props
->Reverb
.RoomRolloffFactor
= val
;
1643 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1646 void ALeaxreverb_setParamfv(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, const ALfloat
*vals
)
1648 ALeffectProps
*props
= &effect
->Props
;
1651 case AL_EAXREVERB_REFLECTIONS_PAN
:
1652 if(!(isfinite(vals
[0]) && isfinite(vals
[1]) && isfinite(vals
[2])))
1653 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1654 LockContext(context
);
1655 props
->Reverb
.ReflectionsPan
[0] = vals
[0];
1656 props
->Reverb
.ReflectionsPan
[1] = vals
[1];
1657 props
->Reverb
.ReflectionsPan
[2] = vals
[2];
1658 UnlockContext(context
);
1660 case AL_EAXREVERB_LATE_REVERB_PAN
:
1661 if(!(isfinite(vals
[0]) && isfinite(vals
[1]) && isfinite(vals
[2])))
1662 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1663 LockContext(context
);
1664 props
->Reverb
.LateReverbPan
[0] = vals
[0];
1665 props
->Reverb
.LateReverbPan
[1] = vals
[1];
1666 props
->Reverb
.LateReverbPan
[2] = vals
[2];
1667 UnlockContext(context
);
1671 ALeaxreverb_setParamf(effect
, context
, param
, vals
[0]);
1676 void ALeaxreverb_getParami(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALint
*val
)
1678 const ALeffectProps
*props
= &effect
->Props
;
1681 case AL_EAXREVERB_DECAY_HFLIMIT
:
1682 *val
= props
->Reverb
.DecayHFLimit
;
1686 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1689 void ALeaxreverb_getParamiv(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALint
*vals
)
1691 ALeaxreverb_getParami(effect
, context
, param
, vals
);
1693 void ALeaxreverb_getParamf(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat
*val
)
1695 const ALeffectProps
*props
= &effect
->Props
;
1698 case AL_EAXREVERB_DENSITY
:
1699 *val
= props
->Reverb
.Density
;
1702 case AL_EAXREVERB_DIFFUSION
:
1703 *val
= props
->Reverb
.Diffusion
;
1706 case AL_EAXREVERB_GAIN
:
1707 *val
= props
->Reverb
.Gain
;
1710 case AL_EAXREVERB_GAINHF
:
1711 *val
= props
->Reverb
.GainHF
;
1714 case AL_EAXREVERB_GAINLF
:
1715 *val
= props
->Reverb
.GainLF
;
1718 case AL_EAXREVERB_DECAY_TIME
:
1719 *val
= props
->Reverb
.DecayTime
;
1722 case AL_EAXREVERB_DECAY_HFRATIO
:
1723 *val
= props
->Reverb
.DecayHFRatio
;
1726 case AL_EAXREVERB_DECAY_LFRATIO
:
1727 *val
= props
->Reverb
.DecayLFRatio
;
1730 case AL_EAXREVERB_REFLECTIONS_GAIN
:
1731 *val
= props
->Reverb
.ReflectionsGain
;
1734 case AL_EAXREVERB_REFLECTIONS_DELAY
:
1735 *val
= props
->Reverb
.ReflectionsDelay
;
1738 case AL_EAXREVERB_LATE_REVERB_GAIN
:
1739 *val
= props
->Reverb
.LateReverbGain
;
1742 case AL_EAXREVERB_LATE_REVERB_DELAY
:
1743 *val
= props
->Reverb
.LateReverbDelay
;
1746 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF
:
1747 *val
= props
->Reverb
.AirAbsorptionGainHF
;
1750 case AL_EAXREVERB_ECHO_TIME
:
1751 *val
= props
->Reverb
.EchoTime
;
1754 case AL_EAXREVERB_ECHO_DEPTH
:
1755 *val
= props
->Reverb
.EchoDepth
;
1758 case AL_EAXREVERB_MODULATION_TIME
:
1759 *val
= props
->Reverb
.ModulationTime
;
1762 case AL_EAXREVERB_MODULATION_DEPTH
:
1763 *val
= props
->Reverb
.ModulationDepth
;
1766 case AL_EAXREVERB_HFREFERENCE
:
1767 *val
= props
->Reverb
.HFReference
;
1770 case AL_EAXREVERB_LFREFERENCE
:
1771 *val
= props
->Reverb
.LFReference
;
1774 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR
:
1775 *val
= props
->Reverb
.RoomRolloffFactor
;
1779 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1782 void ALeaxreverb_getParamfv(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat
*vals
)
1784 const ALeffectProps
*props
= &effect
->Props
;
1787 case AL_EAXREVERB_REFLECTIONS_PAN
:
1788 LockContext(context
);
1789 vals
[0] = props
->Reverb
.ReflectionsPan
[0];
1790 vals
[1] = props
->Reverb
.ReflectionsPan
[1];
1791 vals
[2] = props
->Reverb
.ReflectionsPan
[2];
1792 UnlockContext(context
);
1794 case AL_EAXREVERB_LATE_REVERB_PAN
:
1795 LockContext(context
);
1796 vals
[0] = props
->Reverb
.LateReverbPan
[0];
1797 vals
[1] = props
->Reverb
.LateReverbPan
[1];
1798 vals
[2] = props
->Reverb
.LateReverbPan
[2];
1799 UnlockContext(context
);
1803 ALeaxreverb_getParamf(effect
, context
, param
, vals
);
1808 DEFINE_ALEFFECT_VTABLE(ALeaxreverb
);
1810 void ALreverb_setParami(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALint val
)
1812 ALeffectProps
*props
= &effect
->Props
;
1815 case AL_REVERB_DECAY_HFLIMIT
:
1816 if(!(val
>= AL_REVERB_MIN_DECAY_HFLIMIT
&& val
<= AL_REVERB_MAX_DECAY_HFLIMIT
))
1817 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1818 props
->Reverb
.DecayHFLimit
= val
;
1822 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1825 void ALreverb_setParamiv(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, const ALint
*vals
)
1827 ALreverb_setParami(effect
, context
, param
, vals
[0]);
1829 void ALreverb_setParamf(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat val
)
1831 ALeffectProps
*props
= &effect
->Props
;
1834 case AL_REVERB_DENSITY
:
1835 if(!(val
>= AL_REVERB_MIN_DENSITY
&& val
<= AL_REVERB_MAX_DENSITY
))
1836 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1837 props
->Reverb
.Density
= val
;
1840 case AL_REVERB_DIFFUSION
:
1841 if(!(val
>= AL_REVERB_MIN_DIFFUSION
&& val
<= AL_REVERB_MAX_DIFFUSION
))
1842 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1843 props
->Reverb
.Diffusion
= val
;
1846 case AL_REVERB_GAIN
:
1847 if(!(val
>= AL_REVERB_MIN_GAIN
&& val
<= AL_REVERB_MAX_GAIN
))
1848 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1849 props
->Reverb
.Gain
= val
;
1852 case AL_REVERB_GAINHF
:
1853 if(!(val
>= AL_REVERB_MIN_GAINHF
&& val
<= AL_REVERB_MAX_GAINHF
))
1854 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1855 props
->Reverb
.GainHF
= val
;
1858 case AL_REVERB_DECAY_TIME
:
1859 if(!(val
>= AL_REVERB_MIN_DECAY_TIME
&& val
<= AL_REVERB_MAX_DECAY_TIME
))
1860 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1861 props
->Reverb
.DecayTime
= val
;
1864 case AL_REVERB_DECAY_HFRATIO
:
1865 if(!(val
>= AL_REVERB_MIN_DECAY_HFRATIO
&& val
<= AL_REVERB_MAX_DECAY_HFRATIO
))
1866 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1867 props
->Reverb
.DecayHFRatio
= val
;
1870 case AL_REVERB_REFLECTIONS_GAIN
:
1871 if(!(val
>= AL_REVERB_MIN_REFLECTIONS_GAIN
&& val
<= AL_REVERB_MAX_REFLECTIONS_GAIN
))
1872 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1873 props
->Reverb
.ReflectionsGain
= val
;
1876 case AL_REVERB_REFLECTIONS_DELAY
:
1877 if(!(val
>= AL_REVERB_MIN_REFLECTIONS_DELAY
&& val
<= AL_REVERB_MAX_REFLECTIONS_DELAY
))
1878 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1879 props
->Reverb
.ReflectionsDelay
= val
;
1882 case AL_REVERB_LATE_REVERB_GAIN
:
1883 if(!(val
>= AL_REVERB_MIN_LATE_REVERB_GAIN
&& val
<= AL_REVERB_MAX_LATE_REVERB_GAIN
))
1884 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1885 props
->Reverb
.LateReverbGain
= val
;
1888 case AL_REVERB_LATE_REVERB_DELAY
:
1889 if(!(val
>= AL_REVERB_MIN_LATE_REVERB_DELAY
&& val
<= AL_REVERB_MAX_LATE_REVERB_DELAY
))
1890 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1891 props
->Reverb
.LateReverbDelay
= val
;
1894 case AL_REVERB_AIR_ABSORPTION_GAINHF
:
1895 if(!(val
>= AL_REVERB_MIN_AIR_ABSORPTION_GAINHF
&& val
<= AL_REVERB_MAX_AIR_ABSORPTION_GAINHF
))
1896 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1897 props
->Reverb
.AirAbsorptionGainHF
= val
;
1900 case AL_REVERB_ROOM_ROLLOFF_FACTOR
:
1901 if(!(val
>= AL_REVERB_MIN_ROOM_ROLLOFF_FACTOR
&& val
<= AL_REVERB_MAX_ROOM_ROLLOFF_FACTOR
))
1902 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1903 props
->Reverb
.RoomRolloffFactor
= val
;
1907 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1910 void ALreverb_setParamfv(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, const ALfloat
*vals
)
1912 ALreverb_setParamf(effect
, context
, param
, vals
[0]);
1915 void ALreverb_getParami(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALint
*val
)
1917 const ALeffectProps
*props
= &effect
->Props
;
1920 case AL_REVERB_DECAY_HFLIMIT
:
1921 *val
= props
->Reverb
.DecayHFLimit
;
1925 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1928 void ALreverb_getParamiv(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALint
*vals
)
1930 ALreverb_getParami(effect
, context
, param
, vals
);
1932 void ALreverb_getParamf(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat
*val
)
1934 const ALeffectProps
*props
= &effect
->Props
;
1937 case AL_REVERB_DENSITY
:
1938 *val
= props
->Reverb
.Density
;
1941 case AL_REVERB_DIFFUSION
:
1942 *val
= props
->Reverb
.Diffusion
;
1945 case AL_REVERB_GAIN
:
1946 *val
= props
->Reverb
.Gain
;
1949 case AL_REVERB_GAINHF
:
1950 *val
= props
->Reverb
.GainHF
;
1953 case AL_REVERB_DECAY_TIME
:
1954 *val
= props
->Reverb
.DecayTime
;
1957 case AL_REVERB_DECAY_HFRATIO
:
1958 *val
= props
->Reverb
.DecayHFRatio
;
1961 case AL_REVERB_REFLECTIONS_GAIN
:
1962 *val
= props
->Reverb
.ReflectionsGain
;
1965 case AL_REVERB_REFLECTIONS_DELAY
:
1966 *val
= props
->Reverb
.ReflectionsDelay
;
1969 case AL_REVERB_LATE_REVERB_GAIN
:
1970 *val
= props
->Reverb
.LateReverbGain
;
1973 case AL_REVERB_LATE_REVERB_DELAY
:
1974 *val
= props
->Reverb
.LateReverbDelay
;
1977 case AL_REVERB_AIR_ABSORPTION_GAINHF
:
1978 *val
= props
->Reverb
.AirAbsorptionGainHF
;
1981 case AL_REVERB_ROOM_ROLLOFF_FACTOR
:
1982 *val
= props
->Reverb
.RoomRolloffFactor
;
1986 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1989 void ALreverb_getParamfv(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat
*vals
)
1991 ALreverb_getParamf(effect
, context
, param
, vals
);
1994 DEFINE_ALEFFECT_VTABLE(ALreverb
);