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
);
52 // All delay lines are allocated as a single buffer to reduce memory
53 // fragmentation and management code.
54 ALfloat
*SampleBuffer
;
57 // Master effect filters
58 ALfilterState LpFilter
;
59 ALfilterState HpFilter
; // EAX only
62 // Modulator delay line.
65 // The vibrato time is tracked with an index over a modulus-wrapped
66 // range (in samples).
70 // The depth of frequency change (also in samples) and its filter.
76 // Initial effect delay.
78 // The tap points for the initial delay. First tap goes to early
79 // reflections, the last to late reverb.
83 // Output gain for early reflections.
86 // Early reflections are done with 4 delay lines.
91 // The gain for each output channel based on 3D panning.
92 ALfloat PanGain
[4][MAX_OUTPUT_CHANNELS
];
95 // Decorrelator delay line.
96 DelayLine Decorrelator
;
97 // There are actually 4 decorrelator taps, but the first occurs at the
102 // Output gain for late reverb.
105 // Attenuation to compensate for the modal density and decay rate of
109 // The feed-back and feed-forward all-pass coefficient.
112 // Mixing matrix coefficient.
115 // Late reverb has 4 parallel all-pass filters.
117 DelayLine ApDelay
[4];
120 // In addition to 4 cyclical delay lines.
125 // The cyclical delay lines are 1-pole low-pass filtered.
129 // The gain for each output channel based on 3D panning.
130 ALfloat PanGain
[4][MAX_OUTPUT_CHANNELS
];
134 // Attenuation to compensate for the modal density and decay rate of
138 // Echo delay and all-pass lines.
149 // The echo line is 1-pole low-pass filtered.
153 // Echo mixing coefficient.
157 // The current read offset for all delay lines.
160 /* Temporary storage used when processing. */
161 ALfloat ReverbSamples
[MAX_UPDATE_SAMPLES
][4];
162 ALfloat EarlySamples
[MAX_UPDATE_SAMPLES
][4];
165 static ALvoid
ALreverbState_Destruct(ALreverbState
*State
)
167 free(State
->SampleBuffer
);
168 State
->SampleBuffer
= NULL
;
171 static ALboolean
ALreverbState_deviceUpdate(ALreverbState
*State
, ALCdevice
*Device
);
172 static ALvoid
ALreverbState_update(ALreverbState
*State
, const ALCdevice
*Device
, const ALeffectslot
*Slot
);
173 static ALvoid
ALreverbState_processStandard(ALreverbState
*State
, ALuint SamplesToDo
, const ALfloat
*restrict SamplesIn
, ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALuint NumChannels
);
174 static ALvoid
ALreverbState_processEax(ALreverbState
*State
, ALuint SamplesToDo
, const ALfloat
*restrict SamplesIn
, ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALuint NumChannels
);
175 static ALvoid
ALreverbState_process(ALreverbState
*State
, ALuint SamplesToDo
, const ALfloat (*restrict SamplesIn
)[BUFFERSIZE
], ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALuint NumChannels
);
176 DECLARE_DEFAULT_ALLOCATORS(ALreverbState
)
178 DEFINE_ALEFFECTSTATE_VTABLE(ALreverbState
);
180 /* This is a user config option for modifying the overall output of the reverb
183 ALfloat ReverbBoost
= 1.0f
;
185 /* Specifies whether to use a standard reverb effect in place of EAX reverb (no
186 * high-pass, modulation, or echo).
188 ALboolean EmulateEAXReverb
= AL_FALSE
;
190 /* This coefficient is used to define the maximum frequency range controlled
191 * by the modulation depth. The current value of 0.1 will allow it to swing
192 * from 0.9x to 1.1x. This value must be below 1. At 1 it will cause the
193 * sampler to stall on the downswing, and above 1 it will cause it to sample
196 static const ALfloat MODULATION_DEPTH_COEFF
= 0.1f
;
198 /* A filter is used to avoid the terrible distortion caused by changing
199 * modulation time and/or depth. To be consistent across different sample
200 * rates, the coefficient must be raised to a constant divided by the sample
201 * rate: coeff^(constant / rate).
203 static const ALfloat MODULATION_FILTER_COEFF
= 0.048f
;
204 static const ALfloat MODULATION_FILTER_CONST
= 100000.0f
;
206 // When diffusion is above 0, an all-pass filter is used to take the edge off
207 // the echo effect. It uses the following line length (in seconds).
208 static const ALfloat ECHO_ALLPASS_LENGTH
= 0.0133f
;
210 // Input into the late reverb is decorrelated between four channels. Their
211 // timings are dependent on a fraction and multiplier. See the
212 // UpdateDecorrelator() routine for the calculations involved.
213 static const ALfloat DECO_FRACTION
= 0.15f
;
214 static const ALfloat DECO_MULTIPLIER
= 2.0f
;
216 // All delay line lengths are specified in seconds.
218 // The lengths of the early delay lines.
219 static const ALfloat EARLY_LINE_LENGTH
[4] =
221 0.0015f
, 0.0045f
, 0.0135f
, 0.0405f
224 // The lengths of the late all-pass delay lines.
225 static const ALfloat ALLPASS_LINE_LENGTH
[4] =
227 0.0151f
, 0.0167f
, 0.0183f
, 0.0200f
,
230 // The lengths of the late cyclical delay lines.
231 static const ALfloat LATE_LINE_LENGTH
[4] =
233 0.0211f
, 0.0311f
, 0.0461f
, 0.0680f
236 // The late cyclical delay lines have a variable length dependent on the
237 // effect's density parameter (inverted for some reason) and this multiplier.
238 static const ALfloat LATE_LINE_MULTIPLIER
= 4.0f
;
241 /**************************************
243 **************************************/
245 // Given the allocated sample buffer, this function updates each delay line
247 static inline ALvoid
RealizeLineOffset(ALfloat
*sampleBuffer
, DelayLine
*Delay
)
249 Delay
->Line
= &sampleBuffer
[(ptrdiff_t)Delay
->Line
];
252 // Calculate the length of a delay line and store its mask and offset.
253 static ALuint
CalcLineLength(ALfloat length
, ptrdiff_t offset
, ALuint frequency
, ALuint extra
, DelayLine
*Delay
)
257 // All line lengths are powers of 2, calculated from their lengths, with
258 // an additional sample in case of rounding errors.
259 samples
= fastf2u(length
*frequency
) + extra
;
260 samples
= NextPowerOf2(samples
+ 1);
261 // All lines share a single sample buffer.
262 Delay
->Mask
= samples
- 1;
263 Delay
->Line
= (ALfloat
*)offset
;
264 // Return the sample count for accumulation.
268 /* Calculates the delay line metrics and allocates the shared sample buffer
269 * for all lines given the sample rate (frequency). If an allocation failure
270 * occurs, it returns AL_FALSE.
272 static ALboolean
AllocLines(ALuint frequency
, ALreverbState
*State
)
274 ALuint totalSamples
, index
;
276 ALfloat
*newBuffer
= NULL
;
278 // All delay line lengths are calculated to accomodate the full range of
279 // lengths given their respective paramters.
282 /* The modulator's line length is calculated from the maximum modulation
283 * time and depth coefficient, and halfed for the low-to-high frequency
284 * swing. An additional sample is added to keep it stable when there is no
287 length
= (AL_EAXREVERB_MAX_MODULATION_TIME
*MODULATION_DEPTH_COEFF
/2.0f
);
288 totalSamples
+= CalcLineLength(length
, totalSamples
, frequency
, 1,
291 // The initial delay is the sum of the reflections and late reverb
292 // delays. This must include space for storing a loop update to feed the
293 // early reflections, decorrelator, and echo.
294 length
= AL_EAXREVERB_MAX_REFLECTIONS_DELAY
+
295 AL_EAXREVERB_MAX_LATE_REVERB_DELAY
;
296 totalSamples
+= CalcLineLength(length
, totalSamples
, frequency
,
297 MAX_UPDATE_SAMPLES
, &State
->Delay
);
299 // The early reflection lines.
300 for(index
= 0;index
< 4;index
++)
301 totalSamples
+= CalcLineLength(EARLY_LINE_LENGTH
[index
], totalSamples
,
302 frequency
, 0, &State
->Early
.Delay
[index
]);
304 // The decorrelator line is calculated from the lowest reverb density (a
305 // parameter value of 1). This must include space for storing a loop update
306 // to feed the late reverb.
307 length
= (DECO_FRACTION
* DECO_MULTIPLIER
* DECO_MULTIPLIER
) *
308 LATE_LINE_LENGTH
[0] * (1.0f
+ LATE_LINE_MULTIPLIER
);
309 totalSamples
+= CalcLineLength(length
, totalSamples
, frequency
, MAX_UPDATE_SAMPLES
,
310 &State
->Decorrelator
);
312 // The late all-pass lines.
313 for(index
= 0;index
< 4;index
++)
314 totalSamples
+= CalcLineLength(ALLPASS_LINE_LENGTH
[index
], totalSamples
,
315 frequency
, 0, &State
->Late
.ApDelay
[index
]);
317 // The late delay lines are calculated from the lowest reverb density.
318 for(index
= 0;index
< 4;index
++)
320 length
= LATE_LINE_LENGTH
[index
] * (1.0f
+ LATE_LINE_MULTIPLIER
);
321 totalSamples
+= CalcLineLength(length
, totalSamples
, frequency
, 0,
322 &State
->Late
.Delay
[index
]);
325 // The echo all-pass and delay lines.
326 totalSamples
+= CalcLineLength(ECHO_ALLPASS_LENGTH
, totalSamples
,
327 frequency
, 0, &State
->Echo
.ApDelay
);
328 totalSamples
+= CalcLineLength(AL_EAXREVERB_MAX_ECHO_TIME
, totalSamples
,
329 frequency
, 0, &State
->Echo
.Delay
);
331 if(totalSamples
!= State
->TotalSamples
)
333 TRACE("New reverb buffer length: %u samples (%f sec)\n", totalSamples
, totalSamples
/(float)frequency
);
334 newBuffer
= realloc(State
->SampleBuffer
, sizeof(ALfloat
) * totalSamples
);
335 if(newBuffer
== NULL
)
337 State
->SampleBuffer
= newBuffer
;
338 State
->TotalSamples
= totalSamples
;
341 // Update all delays to reflect the new sample buffer.
342 RealizeLineOffset(State
->SampleBuffer
, &State
->Delay
);
343 RealizeLineOffset(State
->SampleBuffer
, &State
->Decorrelator
);
344 for(index
= 0;index
< 4;index
++)
346 RealizeLineOffset(State
->SampleBuffer
, &State
->Early
.Delay
[index
]);
347 RealizeLineOffset(State
->SampleBuffer
, &State
->Late
.ApDelay
[index
]);
348 RealizeLineOffset(State
->SampleBuffer
, &State
->Late
.Delay
[index
]);
350 RealizeLineOffset(State
->SampleBuffer
, &State
->Mod
.Delay
);
351 RealizeLineOffset(State
->SampleBuffer
, &State
->Echo
.ApDelay
);
352 RealizeLineOffset(State
->SampleBuffer
, &State
->Echo
.Delay
);
354 // Clear the sample buffer.
355 for(index
= 0;index
< State
->TotalSamples
;index
++)
356 State
->SampleBuffer
[index
] = 0.0f
;
361 static ALboolean
ALreverbState_deviceUpdate(ALreverbState
*State
, ALCdevice
*Device
)
363 ALuint frequency
= Device
->Frequency
, index
;
365 // Allocate the delay lines.
366 if(!AllocLines(frequency
, State
))
369 // Calculate the modulation filter coefficient. Notice that the exponent
370 // is calculated given the current sample rate. This ensures that the
371 // resulting filter response over time is consistent across all sample
373 State
->Mod
.Coeff
= powf(MODULATION_FILTER_COEFF
,
374 MODULATION_FILTER_CONST
/ frequency
);
376 // The early reflection and late all-pass filter line lengths are static,
377 // so their offsets only need to be calculated once.
378 for(index
= 0;index
< 4;index
++)
380 State
->Early
.Offset
[index
] = fastf2u(EARLY_LINE_LENGTH
[index
] * frequency
);
381 State
->Late
.ApOffset
[index
] = fastf2u(ALLPASS_LINE_LENGTH
[index
] * frequency
);
384 // The echo all-pass filter line length is static, so its offset only
385 // needs to be calculated once.
386 State
->Echo
.ApOffset
= fastf2u(ECHO_ALLPASS_LENGTH
* frequency
);
391 /**************************************
393 **************************************/
395 // Calculate a decay coefficient given the length of each cycle and the time
396 // until the decay reaches -60 dB.
397 static inline ALfloat
CalcDecayCoeff(ALfloat length
, ALfloat decayTime
)
399 return powf(0.001f
/*-60 dB*/, length
/decayTime
);
402 // Calculate a decay length from a coefficient and the time until the decay
404 static inline ALfloat
CalcDecayLength(ALfloat coeff
, ALfloat decayTime
)
406 return log10f(coeff
) * decayTime
/ log10f(0.001f
)/*-60 dB*/;
409 // Calculate an attenuation to be applied to the input of any echo models to
410 // compensate for modal density and decay time.
411 static inline ALfloat
CalcDensityGain(ALfloat a
)
413 /* The energy of a signal can be obtained by finding the area under the
414 * squared signal. This takes the form of Sum(x_n^2), where x is the
415 * amplitude for the sample n.
417 * Decaying feedback matches exponential decay of the form Sum(a^n),
418 * where a is the attenuation coefficient, and n is the sample. The area
419 * under this decay curve can be calculated as: 1 / (1 - a).
421 * Modifying the above equation to find the squared area under the curve
422 * (for energy) yields: 1 / (1 - a^2). Input attenuation can then be
423 * calculated by inverting the square root of this approximation,
424 * yielding: 1 / sqrt(1 / (1 - a^2)), simplified to: sqrt(1 - a^2).
426 return sqrtf(1.0f
- (a
* a
));
429 // Calculate the mixing matrix coefficients given a diffusion factor.
430 static inline ALvoid
CalcMatrixCoeffs(ALfloat diffusion
, ALfloat
*x
, ALfloat
*y
)
434 // The matrix is of order 4, so n is sqrt (4 - 1).
436 t
= diffusion
* atanf(n
);
438 // Calculate the first mixing matrix coefficient.
440 // Calculate the second mixing matrix coefficient.
444 // Calculate the limited HF ratio for use with the late reverb low-pass
446 static ALfloat
CalcLimitedHfRatio(ALfloat hfRatio
, ALfloat airAbsorptionGainHF
, ALfloat decayTime
)
450 /* Find the attenuation due to air absorption in dB (converting delay
451 * time to meters using the speed of sound). Then reversing the decay
452 * equation, solve for HF ratio. The delay length is cancelled out of
453 * the equation, so it can be calculated once for all lines.
455 limitRatio
= 1.0f
/ (CalcDecayLength(airAbsorptionGainHF
, decayTime
) *
456 SPEEDOFSOUNDMETRESPERSEC
);
457 /* Using the limit calculated above, apply the upper bound to the HF
458 * ratio. Also need to limit the result to a minimum of 0.1, just like the
459 * HF ratio parameter. */
460 return clampf(limitRatio
, 0.1f
, hfRatio
);
463 // Calculate the coefficient for a HF (and eventually LF) decay damping
465 static inline ALfloat
CalcDampingCoeff(ALfloat hfRatio
, ALfloat length
, ALfloat decayTime
, ALfloat decayCoeff
, ALfloat cw
)
469 // Eventually this should boost the high frequencies when the ratio
474 // Calculate the low-pass coefficient by dividing the HF decay
475 // coefficient by the full decay coefficient.
476 g
= CalcDecayCoeff(length
, decayTime
* hfRatio
) / decayCoeff
;
478 // Damping is done with a 1-pole filter, so g needs to be squared.
480 if(g
< 0.9999f
) /* 1-epsilon */
482 /* Be careful with gains < 0.001, as that causes the coefficient
483 * head towards 1, which will flatten the signal. */
485 coeff
= (1 - g
*cw
- sqrtf(2*g
*(1-cw
) - g
*g
*(1 - cw
*cw
))) /
489 // Very low decay times will produce minimal output, so apply an
490 // upper bound to the coefficient.
491 coeff
= minf(coeff
, 0.98f
);
496 // Update the EAX modulation index, range, and depth. Keep in mind that this
497 // kind of vibrato is additive and not multiplicative as one may expect. The
498 // downswing will sound stronger than the upswing.
499 static ALvoid
UpdateModulator(ALfloat modTime
, ALfloat modDepth
, ALuint frequency
, ALreverbState
*State
)
503 /* Modulation is calculated in two parts.
505 * The modulation time effects the sinus applied to the change in
506 * frequency. An index out of the current time range (both in samples)
507 * is incremented each sample. The range is bound to a reasonable
508 * minimum (1 sample) and when the timing changes, the index is rescaled
509 * to the new range (to keep the sinus consistent).
511 range
= maxu(fastf2u(modTime
*frequency
), 1);
512 State
->Mod
.Index
= (ALuint
)(State
->Mod
.Index
* (ALuint64
)range
/
514 State
->Mod
.Range
= range
;
516 /* The modulation depth effects the amount of frequency change over the
517 * range of the sinus. It needs to be scaled by the modulation time so
518 * that a given depth produces a consistent change in frequency over all
519 * ranges of time. Since the depth is applied to a sinus value, it needs
520 * to be halfed once for the sinus range and again for the sinus swing
521 * in time (half of it is spent decreasing the frequency, half is spent
524 State
->Mod
.Depth
= modDepth
* MODULATION_DEPTH_COEFF
* modTime
/ 2.0f
/
528 // Update the offsets for the initial effect delay line.
529 static ALvoid
UpdateDelayLine(ALfloat earlyDelay
, ALfloat lateDelay
, ALuint frequency
, ALreverbState
*State
)
531 // Calculate the initial delay taps.
532 State
->DelayTap
[0] = fastf2u(earlyDelay
* frequency
);
533 State
->DelayTap
[1] = fastf2u((earlyDelay
+ lateDelay
) * frequency
);
536 // Update the early reflections mix and line coefficients.
537 static ALvoid
UpdateEarlyLines(ALfloat lateDelay
, ALreverbState
*State
)
541 // Calculate the early reflections with a constant attenuation of 0.5.
542 State
->Early
.Gain
= 0.5f
;
544 // Calculate the gain (coefficient) for each early delay line using the
545 // late delay time. This expands the early reflections to the start of
547 for(index
= 0;index
< 4;index
++)
548 State
->Early
.Coeff
[index
] = CalcDecayCoeff(EARLY_LINE_LENGTH
[index
],
552 // Update the offsets for the decorrelator line.
553 static ALvoid
UpdateDecorrelator(ALfloat density
, ALuint frequency
, ALreverbState
*State
)
558 /* The late reverb inputs are decorrelated to smooth the reverb tail and
559 * reduce harsh echos. The first tap occurs immediately, while the
560 * remaining taps are delayed by multiples of a fraction of the smallest
561 * cyclical delay time.
563 * offset[index] = (FRACTION (MULTIPLIER^index)) smallest_delay
565 for(index
= 0;index
< 3;index
++)
567 length
= (DECO_FRACTION
* powf(DECO_MULTIPLIER
, (ALfloat
)index
)) *
568 LATE_LINE_LENGTH
[0] * (1.0f
+ (density
* LATE_LINE_MULTIPLIER
));
569 State
->DecoTap
[index
] = fastf2u(length
* frequency
);
573 // Update the late reverb mix, line lengths, and line coefficients.
574 static ALvoid
UpdateLateLines(ALfloat xMix
, ALfloat density
, ALfloat decayTime
, ALfloat diffusion
, ALfloat echoDepth
, ALfloat hfRatio
, ALfloat cw
, ALuint frequency
, ALreverbState
*State
)
579 /* Calculate the late reverb gain. Since the output is tapped prior to the
580 * application of the next delay line coefficients, this gain needs to be
581 * attenuated by the 'x' mixing matrix coefficient as well. Also attenuate
582 * the late reverb when echo depth is high and diffusion is low, so the
583 * echo is slightly stronger than the decorrelated echos in the reverb
586 State
->Late
.Gain
= xMix
* (1.0f
- (echoDepth
*0.5f
*(1.0f
- diffusion
)));
588 /* To compensate for changes in modal density and decay time of the late
589 * reverb signal, the input is attenuated based on the maximal energy of
590 * the outgoing signal. This approximation is used to keep the apparent
591 * energy of the signal equal for all ranges of density and decay time.
593 * The average length of the cyclcical delay lines is used to calculate
594 * the attenuation coefficient.
596 length
= (LATE_LINE_LENGTH
[0] + LATE_LINE_LENGTH
[1] +
597 LATE_LINE_LENGTH
[2] + LATE_LINE_LENGTH
[3]) / 4.0f
;
598 length
*= 1.0f
+ (density
* LATE_LINE_MULTIPLIER
);
599 State
->Late
.DensityGain
= CalcDensityGain(
600 CalcDecayCoeff(length
, decayTime
)
603 // Calculate the all-pass feed-back and feed-forward coefficient.
604 State
->Late
.ApFeedCoeff
= 0.5f
* powf(diffusion
, 2.0f
);
606 for(index
= 0;index
< 4;index
++)
608 // Calculate the gain (coefficient) for each all-pass line.
609 State
->Late
.ApCoeff
[index
] = CalcDecayCoeff(
610 ALLPASS_LINE_LENGTH
[index
], decayTime
613 // Calculate the length (in seconds) of each cyclical delay line.
614 length
= LATE_LINE_LENGTH
[index
] *
615 (1.0f
+ (density
* LATE_LINE_MULTIPLIER
));
617 // Calculate the delay offset for each cyclical delay line.
618 State
->Late
.Offset
[index
] = fastf2u(length
* frequency
);
620 // Calculate the gain (coefficient) for each cyclical line.
621 State
->Late
.Coeff
[index
] = CalcDecayCoeff(length
, decayTime
);
623 // Calculate the damping coefficient for each low-pass filter.
624 State
->Late
.LpCoeff
[index
] = CalcDampingCoeff(
625 hfRatio
, length
, decayTime
, State
->Late
.Coeff
[index
], cw
628 // Attenuate the cyclical line coefficients by the mixing coefficient
630 State
->Late
.Coeff
[index
] *= xMix
;
634 // Update the echo gain, line offset, line coefficients, and mixing
636 static ALvoid
UpdateEchoLine(ALfloat echoTime
, ALfloat decayTime
, ALfloat diffusion
, ALfloat echoDepth
, ALfloat hfRatio
, ALfloat cw
, ALuint frequency
, ALreverbState
*State
)
638 // Update the offset and coefficient for the echo delay line.
639 State
->Echo
.Offset
= fastf2u(echoTime
* frequency
);
641 // Calculate the decay coefficient for the echo line.
642 State
->Echo
.Coeff
= CalcDecayCoeff(echoTime
, decayTime
);
644 // Calculate the energy-based attenuation coefficient for the echo delay
646 State
->Echo
.DensityGain
= CalcDensityGain(State
->Echo
.Coeff
);
648 // Calculate the echo all-pass feed coefficient.
649 State
->Echo
.ApFeedCoeff
= 0.5f
* powf(diffusion
, 2.0f
);
651 // Calculate the echo all-pass attenuation coefficient.
652 State
->Echo
.ApCoeff
= CalcDecayCoeff(ECHO_ALLPASS_LENGTH
, decayTime
);
654 // Calculate the damping coefficient for each low-pass filter.
655 State
->Echo
.LpCoeff
= CalcDampingCoeff(hfRatio
, echoTime
, decayTime
,
656 State
->Echo
.Coeff
, cw
);
658 /* Calculate the echo mixing coefficient. This is applied to the output mix
659 * only, not the feedback.
661 State
->Echo
.MixCoeff
= echoDepth
;
664 // Update the early and late 3D panning gains.
665 static ALvoid
UpdateDirectPanning(const ALCdevice
*Device
, const ALfloat
*ReflectionsPan
, const ALfloat
*LateReverbPan
, ALfloat Gain
, ALfloat EarlyGain
, ALfloat LateGain
, ALreverbState
*State
)
667 ALfloat AmbientGains
[MAX_OUTPUT_CHANNELS
];
668 ALfloat DirGains
[MAX_OUTPUT_CHANNELS
];
669 ALfloat coeffs
[MAX_AMBI_COEFFS
];
673 /* Apply a boost of about 3dB to better match the expected stereo output volume. */
674 Gain
*= 1.414213562f
;
675 ComputeAmbientGains(Device
->AmbiCoeffs
, Device
->NumChannels
, Gain
, AmbientGains
);
677 memset(State
->Early
.PanGain
, 0, sizeof(State
->Early
.PanGain
));
678 length
= sqrtf(ReflectionsPan
[0]*ReflectionsPan
[0] + ReflectionsPan
[1]*ReflectionsPan
[1] + ReflectionsPan
[2]*ReflectionsPan
[2]);
679 if(!(length
> FLT_EPSILON
))
681 for(i
= 0;i
< Device
->NumChannels
;i
++)
682 State
->Early
.PanGain
[i
&3][i
] = AmbientGains
[i
] * EarlyGain
;
686 /* Note that EAX Reverb's panning vectors are using right-handed
687 * coordinates, rather that the OpenAL's left-handed coordinates.
688 * Negate Z to fix this.
691 ReflectionsPan
[0] / length
,
692 ReflectionsPan
[1] / length
,
693 -ReflectionsPan
[2] / length
,
695 length
= minf(length
, 1.0f
);
697 CalcDirectionCoeffs(pan
, coeffs
);
698 ComputePanningGains(Device
->AmbiCoeffs
, Device
->NumChannels
, coeffs
, Gain
, DirGains
);
699 for(i
= 0;i
< Device
->NumChannels
;i
++)
700 State
->Early
.PanGain
[i
&3][i
] = lerp(AmbientGains
[i
], DirGains
[i
], length
) * EarlyGain
;
703 memset(State
->Late
.PanGain
, 0, sizeof(State
->Late
.PanGain
));
704 length
= sqrtf(LateReverbPan
[0]*LateReverbPan
[0] + LateReverbPan
[1]*LateReverbPan
[1] + LateReverbPan
[2]*LateReverbPan
[2]);
705 if(!(length
> FLT_EPSILON
))
707 for(i
= 0;i
< Device
->NumChannels
;i
++)
708 State
->Late
.PanGain
[i
&3][i
] = AmbientGains
[i
] * LateGain
;
713 LateReverbPan
[0] / length
,
714 LateReverbPan
[1] / length
,
715 -LateReverbPan
[2] / length
,
717 length
= minf(length
, 1.0f
);
719 CalcDirectionCoeffs(pan
, coeffs
);
720 ComputePanningGains(Device
->AmbiCoeffs
, Device
->NumChannels
, coeffs
, Gain
, DirGains
);
721 for(i
= 0;i
< Device
->NumChannels
;i
++)
722 State
->Late
.PanGain
[i
&3][i
] = lerp(AmbientGains
[i
], DirGains
[i
], length
) * LateGain
;
726 static ALvoid
Update3DPanning(const ALCdevice
*Device
, const ALfloat
*ReflectionsPan
, const ALfloat
*LateReverbPan
, ALfloat Gain
, ALfloat EarlyGain
, ALfloat LateGain
, ALreverbState
*State
)
728 static const ALfloat PanDirs
[4][3] = {
729 { -0.707106781f
, 0.0f
, -0.707106781f
}, /* Front left */
730 { 0.707106781f
, 0.0f
, -0.707106781f
}, /* Front right */
731 { 0.707106781f
, 0.0f
, 0.707106781f
}, /* Back right */
732 { -0.707106781f
, 0.0f
, 0.707106781f
} /* Back left */
734 ALfloat coeffs
[MAX_AMBI_COEFFS
];
739 /* 0.5 would be the gain scaling when the panning vector is 0. This also
740 * equals sqrt(1/4), a nice gain scaling for the four virtual points
741 * producing an "ambient" response.
743 gain
[0] = gain
[1] = gain
[2] = gain
[3] = 0.5f
;
744 length
= sqrtf(ReflectionsPan
[0]*ReflectionsPan
[0] + ReflectionsPan
[1]*ReflectionsPan
[1] + ReflectionsPan
[2]*ReflectionsPan
[2]);
748 ReflectionsPan
[0] / length
,
749 ReflectionsPan
[1] / length
,
750 -ReflectionsPan
[2] / length
,
754 ALfloat dotp
= pan
[0]*PanDirs
[i
][0] + pan
[1]*PanDirs
[i
][1] + pan
[2]*PanDirs
[i
][2];
755 gain
[i
] = dotp
*0.5f
+ 0.5f
;
758 else if(length
> FLT_EPSILON
)
762 ALfloat dotp
= ReflectionsPan
[0]*PanDirs
[i
][0] + ReflectionsPan
[1]*PanDirs
[i
][1] +
763 -ReflectionsPan
[2]*PanDirs
[i
][2];
764 gain
[i
] = dotp
*0.5f
+ 0.5f
;
769 CalcDirectionCoeffs(PanDirs
[i
], coeffs
);
770 ComputePanningGains(Device
->AmbiCoeffs
, Device
->NumChannels
, coeffs
,
771 Gain
*EarlyGain
*gain
[i
], State
->Early
.PanGain
[i
]);
774 gain
[0] = gain
[1] = gain
[2] = gain
[3] = 0.5f
;
775 length
= sqrtf(LateReverbPan
[0]*LateReverbPan
[0] + LateReverbPan
[1]*LateReverbPan
[1] + LateReverbPan
[2]*LateReverbPan
[2]);
779 LateReverbPan
[0] / length
,
780 LateReverbPan
[1] / length
,
781 -LateReverbPan
[2] / length
,
786 ALfloat dotp
= pan
[0]*PanDirs
[i
][0] + pan
[1]*PanDirs
[i
][1] + pan
[2]*PanDirs
[i
][2];
787 gain
[i
] = dotp
*0.5f
+ 0.5f
;
790 else if(length
> FLT_EPSILON
)
794 ALfloat dotp
= LateReverbPan
[0]*PanDirs
[i
][0] + LateReverbPan
[1]*PanDirs
[i
][1] +
795 -LateReverbPan
[2]*PanDirs
[i
][2];
796 gain
[i
] = dotp
*0.5f
+ 0.5f
;
801 CalcDirectionCoeffs(PanDirs
[i
], coeffs
);
802 ComputePanningGains(Device
->AmbiCoeffs
, Device
->NumChannels
, coeffs
,
803 Gain
*LateGain
*gain
[i
], State
->Late
.PanGain
[i
]);
807 static ALvoid
ALreverbState_update(ALreverbState
*State
, const ALCdevice
*Device
, const ALeffectslot
*Slot
)
809 const ALeffectProps
*props
= &Slot
->EffectProps
;
810 ALuint frequency
= Device
->Frequency
;
811 ALfloat lfscale
, hfscale
, hfRatio
;
812 ALfloat gain
, gainlf
, gainhf
;
815 if(Slot
->EffectType
== AL_EFFECT_EAXREVERB
&& !EmulateEAXReverb
)
816 State
->IsEax
= AL_TRUE
;
817 else if(Slot
->EffectType
== AL_EFFECT_REVERB
|| EmulateEAXReverb
)
818 State
->IsEax
= AL_FALSE
;
820 // Calculate the master filters
821 hfscale
= props
->Reverb
.HFReference
/ frequency
;
822 gainhf
= maxf(props
->Reverb
.GainHF
, 0.0001f
);
823 ALfilterState_setParams(&State
->LpFilter
, ALfilterType_HighShelf
,
824 gainhf
, hfscale
, calc_rcpQ_from_slope(gainhf
, 0.75f
));
825 lfscale
= props
->Reverb
.LFReference
/ frequency
;
826 gainlf
= maxf(props
->Reverb
.GainLF
, 0.0001f
);
827 ALfilterState_setParams(&State
->HpFilter
, ALfilterType_LowShelf
,
828 gainlf
, lfscale
, calc_rcpQ_from_slope(gainlf
, 0.75f
));
830 // Update the modulator line.
831 UpdateModulator(props
->Reverb
.ModulationTime
, props
->Reverb
.ModulationDepth
,
834 // Update the initial effect delay.
835 UpdateDelayLine(props
->Reverb
.ReflectionsDelay
, props
->Reverb
.LateReverbDelay
,
838 // Update the early lines.
839 UpdateEarlyLines(props
->Reverb
.LateReverbDelay
, State
);
841 // Update the decorrelator.
842 UpdateDecorrelator(props
->Reverb
.Density
, frequency
, State
);
844 // Get the mixing matrix coefficients (x and y).
845 CalcMatrixCoeffs(props
->Reverb
.Diffusion
, &x
, &y
);
846 // Then divide x into y to simplify the matrix calculation.
847 State
->Late
.MixCoeff
= y
/ x
;
849 // If the HF limit parameter is flagged, calculate an appropriate limit
850 // based on the air absorption parameter.
851 hfRatio
= props
->Reverb
.DecayHFRatio
;
852 if(props
->Reverb
.DecayHFLimit
&& props
->Reverb
.AirAbsorptionGainHF
< 1.0f
)
853 hfRatio
= CalcLimitedHfRatio(hfRatio
, props
->Reverb
.AirAbsorptionGainHF
,
854 props
->Reverb
.DecayTime
);
856 cw
= cosf(F_TAU
* hfscale
);
857 // Update the late lines.
858 UpdateLateLines(x
, props
->Reverb
.Density
, props
->Reverb
.DecayTime
,
859 props
->Reverb
.Diffusion
, props
->Reverb
.EchoDepth
,
860 hfRatio
, cw
, frequency
, State
);
862 // Update the echo line.
863 UpdateEchoLine(props
->Reverb
.EchoTime
, props
->Reverb
.DecayTime
,
864 props
->Reverb
.Diffusion
, props
->Reverb
.EchoDepth
,
865 hfRatio
, cw
, frequency
, State
);
867 gain
= props
->Reverb
.Gain
* Slot
->Gain
* ReverbBoost
;
868 // Update early and late 3D panning.
869 if(Device
->Hrtf
|| Device
->FmtChans
== DevFmtBFormat3D
)
870 Update3DPanning(Device
, props
->Reverb
.ReflectionsPan
,
871 props
->Reverb
.LateReverbPan
, gain
,
872 props
->Reverb
.ReflectionsGain
,
873 props
->Reverb
.LateReverbGain
, State
);
875 UpdateDirectPanning(Device
, props
->Reverb
.ReflectionsPan
,
876 props
->Reverb
.LateReverbPan
, gain
,
877 props
->Reverb
.ReflectionsGain
,
878 props
->Reverb
.LateReverbGain
, State
);
882 /**************************************
883 * Effect Processing *
884 **************************************/
886 // Basic delay line input/output routines.
887 static inline ALfloat
DelayLineOut(DelayLine
*Delay
, ALuint offset
)
889 return Delay
->Line
[offset
&Delay
->Mask
];
892 static inline ALvoid
DelayLineIn(DelayLine
*Delay
, ALuint offset
, ALfloat in
)
894 Delay
->Line
[offset
&Delay
->Mask
] = in
;
897 // Given an input sample, this function produces modulation for the late
899 static inline ALfloat
EAXModulation(ALreverbState
*State
, ALuint offset
, ALfloat in
)
901 ALfloat sinus
, frac
, fdelay
;
905 // Calculate the sinus rythm (dependent on modulation time and the
906 // sampling rate). The center of the sinus is moved to reduce the delay
907 // of the effect when the time or depth are low.
908 sinus
= 1.0f
- cosf(F_TAU
* State
->Mod
.Index
/ State
->Mod
.Range
);
910 // Step the modulation index forward, keeping it bound to its range.
911 State
->Mod
.Index
= (State
->Mod
.Index
+ 1) % State
->Mod
.Range
;
913 // The depth determines the range over which to read the input samples
914 // from, so it must be filtered to reduce the distortion caused by even
915 // small parameter changes.
916 State
->Mod
.Filter
= lerp(State
->Mod
.Filter
, State
->Mod
.Depth
,
919 // Calculate the read offset and fraction between it and the next sample.
920 frac
= modff(State
->Mod
.Filter
*sinus
+ 1.0f
, &fdelay
);
921 delay
= fastf2u(fdelay
);
923 // Get the two samples crossed by the offset, and feed the delay line
924 // with the next input sample.
925 out0
= DelayLineOut(&State
->Mod
.Delay
, offset
- delay
);
926 out1
= DelayLineOut(&State
->Mod
.Delay
, offset
- delay
- 1);
927 DelayLineIn(&State
->Mod
.Delay
, offset
, in
);
929 // The output is obtained by linearly interpolating the two samples that
930 // were acquired above.
931 return lerp(out0
, out1
, frac
);
934 // Given some input sample, this function produces four-channel outputs for the
935 // early reflections.
936 static inline ALvoid
EarlyReflection(ALreverbState
*State
, ALuint todo
, ALfloat (*restrict out
)[4])
938 ALfloat d
[4], v
, f
[4];
941 for(i
= 0;i
< todo
;i
++)
943 ALuint offset
= State
->Offset
+i
;
945 // Obtain the decayed results of each early delay line.
946 d
[0] = DelayLineOut(&State
->Early
.Delay
[0], offset
-State
->Early
.Offset
[0]) * State
->Early
.Coeff
[0];
947 d
[1] = DelayLineOut(&State
->Early
.Delay
[1], offset
-State
->Early
.Offset
[1]) * State
->Early
.Coeff
[1];
948 d
[2] = DelayLineOut(&State
->Early
.Delay
[2], offset
-State
->Early
.Offset
[2]) * State
->Early
.Coeff
[2];
949 d
[3] = DelayLineOut(&State
->Early
.Delay
[3], offset
-State
->Early
.Offset
[3]) * State
->Early
.Coeff
[3];
951 /* The following uses a lossless scattering junction from waveguide
952 * theory. It actually amounts to a householder mixing matrix, which
953 * will produce a maximally diffuse response, and means this can
954 * probably be considered a simple feed-back delay network (FDN).
962 v
= (d
[0] + d
[1] + d
[2] + d
[3]) * 0.5f
;
963 // The junction is loaded with the input here.
964 v
+= DelayLineOut(&State
->Delay
, offset
-State
->DelayTap
[0]);
966 // Calculate the feed values for the delay lines.
972 // Re-feed the delay lines.
973 DelayLineIn(&State
->Early
.Delay
[0], offset
, f
[0]);
974 DelayLineIn(&State
->Early
.Delay
[1], offset
, f
[1]);
975 DelayLineIn(&State
->Early
.Delay
[2], offset
, f
[2]);
976 DelayLineIn(&State
->Early
.Delay
[3], offset
, f
[3]);
978 // Output the results of the junction for all four channels.
979 out
[i
][0] = State
->Early
.Gain
* f
[0];
980 out
[i
][1] = State
->Early
.Gain
* f
[1];
981 out
[i
][2] = State
->Early
.Gain
* f
[2];
982 out
[i
][3] = State
->Early
.Gain
* f
[3];
986 // Basic attenuated all-pass input/output routine.
987 static inline ALfloat
AllpassInOut(DelayLine
*Delay
, ALuint outOffset
, ALuint inOffset
, ALfloat in
, ALfloat feedCoeff
, ALfloat coeff
)
991 out
= DelayLineOut(Delay
, outOffset
);
992 feed
= feedCoeff
* in
;
993 DelayLineIn(Delay
, inOffset
, (feedCoeff
* (out
- feed
)) + in
);
995 // The time-based attenuation is only applied to the delay output to
996 // keep it from affecting the feed-back path (which is already controlled
997 // by the all-pass feed coefficient).
998 return (coeff
* out
) - feed
;
1001 // All-pass input/output routine for late reverb.
1002 static inline ALfloat
LateAllPassInOut(ALreverbState
*State
, ALuint offset
, ALuint index
, ALfloat in
)
1004 return AllpassInOut(&State
->Late
.ApDelay
[index
],
1005 offset
- State
->Late
.ApOffset
[index
],
1006 offset
, in
, State
->Late
.ApFeedCoeff
,
1007 State
->Late
.ApCoeff
[index
]);
1010 // Low-pass filter input/output routine for late reverb.
1011 static inline ALfloat
LateLowPassInOut(ALreverbState
*State
, ALuint index
, ALfloat in
)
1013 in
= lerp(in
, State
->Late
.LpSample
[index
], State
->Late
.LpCoeff
[index
]);
1014 State
->Late
.LpSample
[index
] = in
;
1018 // Given four decorrelated input samples, this function produces four-channel
1019 // output for the late reverb.
1020 static inline ALvoid
LateReverb(ALreverbState
*State
, ALuint todo
, ALfloat (*restrict out
)[4])
1025 for(i
= 0;i
< todo
;i
++)
1027 ALuint offset
= State
->Offset
+i
;
1029 f
[0] = DelayLineOut(&State
->Decorrelator
, offset
);
1030 f
[1] = DelayLineOut(&State
->Decorrelator
, offset
-State
->DecoTap
[0]);
1031 f
[2] = DelayLineOut(&State
->Decorrelator
, offset
-State
->DecoTap
[1]);
1032 f
[3] = DelayLineOut(&State
->Decorrelator
, offset
-State
->DecoTap
[2]);
1034 // Obtain the decayed results of the cyclical delay lines, and add the
1035 // corresponding input channels. Then pass the results through the
1036 // low-pass filters.
1037 f
[0] += DelayLineOut(&State
->Late
.Delay
[0], offset
-State
->Late
.Offset
[0]) * State
->Late
.Coeff
[0];
1038 f
[1] += DelayLineOut(&State
->Late
.Delay
[1], offset
-State
->Late
.Offset
[1]) * State
->Late
.Coeff
[1];
1039 f
[2] += DelayLineOut(&State
->Late
.Delay
[2], offset
-State
->Late
.Offset
[2]) * State
->Late
.Coeff
[2];
1040 f
[3] += DelayLineOut(&State
->Late
.Delay
[3], offset
-State
->Late
.Offset
[3]) * State
->Late
.Coeff
[3];
1042 // This is where the feed-back cycles from line 0 to 1 to 3 to 2 and
1044 d
[0] = LateLowPassInOut(State
, 2, f
[2]);
1045 d
[1] = LateLowPassInOut(State
, 0, f
[0]);
1046 d
[2] = LateLowPassInOut(State
, 3, f
[3]);
1047 d
[3] = LateLowPassInOut(State
, 1, f
[1]);
1049 // To help increase diffusion, run each line through an all-pass filter.
1050 // When there is no diffusion, the shortest all-pass filter will feed
1051 // the shortest delay line.
1052 d
[0] = LateAllPassInOut(State
, offset
, 0, d
[0]);
1053 d
[1] = LateAllPassInOut(State
, offset
, 1, d
[1]);
1054 d
[2] = LateAllPassInOut(State
, offset
, 2, d
[2]);
1055 d
[3] = LateAllPassInOut(State
, offset
, 3, d
[3]);
1057 /* Late reverb is done with a modified feed-back delay network (FDN)
1058 * topology. Four input lines are each fed through their own all-pass
1059 * filter and then into the mixing matrix. The four outputs of the
1060 * mixing matrix are then cycled back to the inputs. Each output feeds
1061 * a different input to form a circlular feed cycle.
1063 * The mixing matrix used is a 4D skew-symmetric rotation matrix
1064 * derived using a single unitary rotational parameter:
1066 * [ d, a, b, c ] 1 = a^2 + b^2 + c^2 + d^2
1071 * The rotation is constructed from the effect's diffusion parameter,
1072 * yielding: 1 = x^2 + 3 y^2; where a, b, and c are the coefficient y
1073 * with differing signs, and d is the coefficient x. The matrix is
1076 * [ x, y, -y, y ] n = sqrt(matrix_order - 1)
1077 * [ -y, x, y, y ] t = diffusion_parameter * atan(n)
1078 * [ y, -y, x, y ] x = cos(t)
1079 * [ -y, -y, -y, x ] y = sin(t) / n
1081 * To reduce the number of multiplies, the x coefficient is applied
1082 * with the cyclical delay line coefficients. Thus only the y
1083 * coefficient is applied when mixing, and is modified to be: y / x.
1085 f
[0] = d
[0] + (State
->Late
.MixCoeff
* ( d
[1] + -d
[2] + d
[3]));
1086 f
[1] = d
[1] + (State
->Late
.MixCoeff
* (-d
[0] + d
[2] + d
[3]));
1087 f
[2] = d
[2] + (State
->Late
.MixCoeff
* ( d
[0] + -d
[1] + d
[3]));
1088 f
[3] = d
[3] + (State
->Late
.MixCoeff
* (-d
[0] + -d
[1] + -d
[2] ));
1090 // Output the results of the matrix for all four channels, attenuated by
1091 // the late reverb gain (which is attenuated by the 'x' mix coefficient).
1092 out
[i
][0] = State
->Late
.Gain
* f
[0];
1093 out
[i
][1] = State
->Late
.Gain
* f
[1];
1094 out
[i
][2] = State
->Late
.Gain
* f
[2];
1095 out
[i
][3] = State
->Late
.Gain
* f
[3];
1097 // Re-feed the cyclical delay lines.
1098 DelayLineIn(&State
->Late
.Delay
[0], offset
, f
[0]);
1099 DelayLineIn(&State
->Late
.Delay
[1], offset
, f
[1]);
1100 DelayLineIn(&State
->Late
.Delay
[2], offset
, f
[2]);
1101 DelayLineIn(&State
->Late
.Delay
[3], offset
, f
[3]);
1105 // Given an input sample, this function mixes echo into the four-channel late
1107 static inline ALvoid
EAXEcho(ALreverbState
*State
, ALuint todo
, ALfloat (*restrict late
)[4])
1112 for(i
= 0;i
< todo
;i
++)
1114 ALuint offset
= State
->Offset
+i
;
1116 // Get the latest attenuated echo sample for output.
1117 feed
= DelayLineOut(&State
->Echo
.Delay
, offset
-State
->Echo
.Offset
) *
1120 // Mix the output into the late reverb channels.
1121 out
= State
->Echo
.MixCoeff
* feed
;
1127 // Mix the energy-attenuated input with the output and pass it through
1128 // the echo low-pass filter.
1129 feed
+= DelayLineOut(&State
->Delay
, offset
-State
->DelayTap
[1]) *
1130 State
->Echo
.DensityGain
;
1131 feed
= lerp(feed
, State
->Echo
.LpSample
, State
->Echo
.LpCoeff
);
1132 State
->Echo
.LpSample
= feed
;
1134 // Then the echo all-pass filter.
1135 feed
= AllpassInOut(&State
->Echo
.ApDelay
, offset
-State
->Echo
.ApOffset
,
1136 offset
, feed
, State
->Echo
.ApFeedCoeff
,
1137 State
->Echo
.ApCoeff
);
1139 // Feed the delay with the mixed and filtered sample.
1140 DelayLineIn(&State
->Echo
.Delay
, offset
, feed
);
1144 // Perform the non-EAX reverb pass on a given input sample, resulting in
1145 // four-channel output.
1146 static inline ALvoid
VerbPass(ALreverbState
*State
, ALuint todo
, const ALfloat
*in
, ALfloat (*restrict early
)[4], ALfloat (*restrict late
)[4])
1150 // Low-pass filter the incoming samples.
1151 for(i
= 0;i
< todo
;i
++)
1152 DelayLineIn(&State
->Delay
, State
->Offset
+i
,
1153 ALfilterState_processSingle(&State
->LpFilter
, in
[i
])
1156 // Calculate the early reflection from the first delay tap.
1157 EarlyReflection(State
, todo
, early
);
1159 // Feed the decorrelator from the energy-attenuated output of the second
1161 for(i
= 0;i
< todo
;i
++)
1163 ALuint offset
= State
->Offset
+i
;
1164 ALfloat sample
= DelayLineOut(&State
->Delay
, offset
- State
->DelayTap
[1]) *
1165 State
->Late
.DensityGain
;
1166 DelayLineIn(&State
->Decorrelator
, offset
, sample
);
1169 // Calculate the late reverb from the decorrelator taps.
1170 LateReverb(State
, todo
, late
);
1172 // Step all delays forward one sample.
1173 State
->Offset
+= todo
;
1176 // Perform the EAX reverb pass on a given input sample, resulting in four-
1178 static inline ALvoid
EAXVerbPass(ALreverbState
*State
, ALuint todo
, const ALfloat
*input
, ALfloat (*restrict early
)[4], ALfloat (*restrict late
)[4])
1182 // Band-pass and modulate the incoming samples.
1183 for(i
= 0;i
< todo
;i
++)
1185 ALfloat sample
= input
[i
];
1186 sample
= ALfilterState_processSingle(&State
->LpFilter
, sample
);
1187 sample
= ALfilterState_processSingle(&State
->HpFilter
, sample
);
1189 // Perform any modulation on the input.
1190 sample
= EAXModulation(State
, State
->Offset
+i
, sample
);
1192 // Feed the initial delay line.
1193 DelayLineIn(&State
->Delay
, State
->Offset
+i
, sample
);
1196 // Calculate the early reflection from the first delay tap.
1197 EarlyReflection(State
, todo
, early
);
1199 // Feed the decorrelator from the energy-attenuated output of the second
1201 for(i
= 0;i
< todo
;i
++)
1203 ALuint offset
= State
->Offset
+i
;
1204 ALfloat sample
= DelayLineOut(&State
->Delay
, offset
- State
->DelayTap
[1]) *
1205 State
->Late
.DensityGain
;
1206 DelayLineIn(&State
->Decorrelator
, offset
, sample
);
1209 // Calculate the late reverb from the decorrelator taps.
1210 LateReverb(State
, todo
, late
);
1212 // Calculate and mix in any echo.
1213 EAXEcho(State
, todo
, late
);
1215 // Step all delays forward.
1216 State
->Offset
+= todo
;
1219 static ALvoid
ALreverbState_processStandard(ALreverbState
*State
, ALuint SamplesToDo
, const ALfloat
*restrict SamplesIn
, ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALuint NumChannels
)
1221 ALfloat (*restrict early
)[4] = State
->EarlySamples
;
1222 ALfloat (*restrict late
)[4] = State
->ReverbSamples
;
1223 ALuint index
, c
, i
, l
;
1226 /* Process reverb for these samples. */
1227 for(index
= 0;index
< SamplesToDo
;)
1229 ALuint todo
= minu(SamplesToDo
-index
, MAX_UPDATE_SAMPLES
);
1231 VerbPass(State
, todo
, &SamplesIn
[index
], early
, late
);
1233 for(l
= 0;l
< 4;l
++)
1235 for(c
= 0;c
< NumChannels
;c
++)
1237 gain
= State
->Early
.PanGain
[l
][c
];
1238 if(fabsf(gain
) > GAIN_SILENCE_THRESHOLD
)
1240 for(i
= 0;i
< todo
;i
++)
1241 SamplesOut
[c
][index
+i
] += gain
*early
[i
][l
];
1243 gain
= State
->Late
.PanGain
[l
][c
];
1244 if(fabsf(gain
) > GAIN_SILENCE_THRESHOLD
)
1246 for(i
= 0;i
< todo
;i
++)
1247 SamplesOut
[c
][index
+i
] += gain
*late
[i
][l
];
1256 static ALvoid
ALreverbState_processEax(ALreverbState
*State
, ALuint SamplesToDo
, const ALfloat
*restrict SamplesIn
, ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALuint NumChannels
)
1258 ALfloat (*restrict early
)[4] = State
->EarlySamples
;
1259 ALfloat (*restrict late
)[4] = State
->ReverbSamples
;
1260 ALuint index
, c
, i
, l
;
1263 /* Process reverb for these samples. */
1264 for(index
= 0;index
< SamplesToDo
;)
1266 ALuint todo
= minu(SamplesToDo
-index
, MAX_UPDATE_SAMPLES
);
1268 EAXVerbPass(State
, todo
, &SamplesIn
[index
], early
, late
);
1270 for(l
= 0;l
< 4;l
++)
1272 for(c
= 0;c
< NumChannels
;c
++)
1274 gain
= State
->Early
.PanGain
[l
][c
];
1275 if(fabsf(gain
) > GAIN_SILENCE_THRESHOLD
)
1277 for(i
= 0;i
< todo
;i
++)
1278 SamplesOut
[c
][index
+i
] += gain
*early
[i
][l
];
1280 gain
= State
->Late
.PanGain
[l
][c
];
1281 if(fabsf(gain
) > GAIN_SILENCE_THRESHOLD
)
1283 for(i
= 0;i
< todo
;i
++)
1284 SamplesOut
[c
][index
+i
] += gain
*late
[i
][l
];
1293 static ALvoid
ALreverbState_process(ALreverbState
*State
, ALuint SamplesToDo
, const ALfloat (*restrict SamplesIn
)[BUFFERSIZE
], ALfloat (*restrict SamplesOut
)[BUFFERSIZE
], ALuint NumChannels
)
1296 ALreverbState_processEax(State
, SamplesToDo
, SamplesIn
[0], SamplesOut
, NumChannels
);
1298 ALreverbState_processStandard(State
, SamplesToDo
, SamplesIn
[0], SamplesOut
, NumChannels
);
1302 typedef struct ALreverbStateFactory
{
1303 DERIVE_FROM_TYPE(ALeffectStateFactory
);
1304 } ALreverbStateFactory
;
1306 static ALeffectState
*ALreverbStateFactory_create(ALreverbStateFactory
* UNUSED(factory
))
1308 ALreverbState
*state
;
1311 state
= ALreverbState_New(sizeof(*state
));
1312 if(!state
) return NULL
;
1313 SET_VTABLE2(ALreverbState
, ALeffectState
, state
);
1315 state
->TotalSamples
= 0;
1316 state
->SampleBuffer
= NULL
;
1318 ALfilterState_clear(&state
->LpFilter
);
1319 ALfilterState_clear(&state
->HpFilter
);
1321 state
->Mod
.Delay
.Mask
= 0;
1322 state
->Mod
.Delay
.Line
= NULL
;
1323 state
->Mod
.Index
= 0;
1324 state
->Mod
.Range
= 1;
1325 state
->Mod
.Depth
= 0.0f
;
1326 state
->Mod
.Coeff
= 0.0f
;
1327 state
->Mod
.Filter
= 0.0f
;
1329 state
->Delay
.Mask
= 0;
1330 state
->Delay
.Line
= NULL
;
1331 state
->DelayTap
[0] = 0;
1332 state
->DelayTap
[1] = 0;
1334 state
->Early
.Gain
= 0.0f
;
1335 for(index
= 0;index
< 4;index
++)
1337 state
->Early
.Coeff
[index
] = 0.0f
;
1338 state
->Early
.Delay
[index
].Mask
= 0;
1339 state
->Early
.Delay
[index
].Line
= NULL
;
1340 state
->Early
.Offset
[index
] = 0;
1343 state
->Decorrelator
.Mask
= 0;
1344 state
->Decorrelator
.Line
= NULL
;
1345 state
->DecoTap
[0] = 0;
1346 state
->DecoTap
[1] = 0;
1347 state
->DecoTap
[2] = 0;
1349 state
->Late
.Gain
= 0.0f
;
1350 state
->Late
.DensityGain
= 0.0f
;
1351 state
->Late
.ApFeedCoeff
= 0.0f
;
1352 state
->Late
.MixCoeff
= 0.0f
;
1353 for(index
= 0;index
< 4;index
++)
1355 state
->Late
.ApCoeff
[index
] = 0.0f
;
1356 state
->Late
.ApDelay
[index
].Mask
= 0;
1357 state
->Late
.ApDelay
[index
].Line
= NULL
;
1358 state
->Late
.ApOffset
[index
] = 0;
1360 state
->Late
.Coeff
[index
] = 0.0f
;
1361 state
->Late
.Delay
[index
].Mask
= 0;
1362 state
->Late
.Delay
[index
].Line
= NULL
;
1363 state
->Late
.Offset
[index
] = 0;
1365 state
->Late
.LpCoeff
[index
] = 0.0f
;
1366 state
->Late
.LpSample
[index
] = 0.0f
;
1369 for(l
= 0;l
< 4;l
++)
1371 for(index
= 0;index
< MAX_OUTPUT_CHANNELS
;index
++)
1373 state
->Early
.PanGain
[l
][index
] = 0.0f
;
1374 state
->Late
.PanGain
[l
][index
] = 0.0f
;
1378 state
->Echo
.DensityGain
= 0.0f
;
1379 state
->Echo
.Delay
.Mask
= 0;
1380 state
->Echo
.Delay
.Line
= NULL
;
1381 state
->Echo
.ApDelay
.Mask
= 0;
1382 state
->Echo
.ApDelay
.Line
= NULL
;
1383 state
->Echo
.Coeff
= 0.0f
;
1384 state
->Echo
.ApFeedCoeff
= 0.0f
;
1385 state
->Echo
.ApCoeff
= 0.0f
;
1386 state
->Echo
.Offset
= 0;
1387 state
->Echo
.ApOffset
= 0;
1388 state
->Echo
.LpCoeff
= 0.0f
;
1389 state
->Echo
.LpSample
= 0.0f
;
1390 state
->Echo
.MixCoeff
= 0.0f
;
1394 return STATIC_CAST(ALeffectState
, state
);
1397 DEFINE_ALEFFECTSTATEFACTORY_VTABLE(ALreverbStateFactory
);
1399 ALeffectStateFactory
*ALreverbStateFactory_getFactory(void)
1401 static ALreverbStateFactory ReverbFactory
= { { GET_VTABLE2(ALreverbStateFactory
, ALeffectStateFactory
) } };
1403 return STATIC_CAST(ALeffectStateFactory
, &ReverbFactory
);
1407 void ALeaxreverb_setParami(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALint val
)
1409 ALeffectProps
*props
= &effect
->Props
;
1412 case AL_EAXREVERB_DECAY_HFLIMIT
:
1413 if(!(val
>= AL_EAXREVERB_MIN_DECAY_HFLIMIT
&& val
<= AL_EAXREVERB_MAX_DECAY_HFLIMIT
))
1414 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1415 props
->Reverb
.DecayHFLimit
= val
;
1419 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1422 void ALeaxreverb_setParamiv(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, const ALint
*vals
)
1424 ALeaxreverb_setParami(effect
, context
, param
, vals
[0]);
1426 void ALeaxreverb_setParamf(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat val
)
1428 ALeffectProps
*props
= &effect
->Props
;
1431 case AL_EAXREVERB_DENSITY
:
1432 if(!(val
>= AL_EAXREVERB_MIN_DENSITY
&& val
<= AL_EAXREVERB_MAX_DENSITY
))
1433 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1434 props
->Reverb
.Density
= val
;
1437 case AL_EAXREVERB_DIFFUSION
:
1438 if(!(val
>= AL_EAXREVERB_MIN_DIFFUSION
&& val
<= AL_EAXREVERB_MAX_DIFFUSION
))
1439 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1440 props
->Reverb
.Diffusion
= val
;
1443 case AL_EAXREVERB_GAIN
:
1444 if(!(val
>= AL_EAXREVERB_MIN_GAIN
&& val
<= AL_EAXREVERB_MAX_GAIN
))
1445 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1446 props
->Reverb
.Gain
= val
;
1449 case AL_EAXREVERB_GAINHF
:
1450 if(!(val
>= AL_EAXREVERB_MIN_GAINHF
&& val
<= AL_EAXREVERB_MAX_GAINHF
))
1451 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1452 props
->Reverb
.GainHF
= val
;
1455 case AL_EAXREVERB_GAINLF
:
1456 if(!(val
>= AL_EAXREVERB_MIN_GAINLF
&& val
<= AL_EAXREVERB_MAX_GAINLF
))
1457 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1458 props
->Reverb
.GainLF
= val
;
1461 case AL_EAXREVERB_DECAY_TIME
:
1462 if(!(val
>= AL_EAXREVERB_MIN_DECAY_TIME
&& val
<= AL_EAXREVERB_MAX_DECAY_TIME
))
1463 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1464 props
->Reverb
.DecayTime
= val
;
1467 case AL_EAXREVERB_DECAY_HFRATIO
:
1468 if(!(val
>= AL_EAXREVERB_MIN_DECAY_HFRATIO
&& val
<= AL_EAXREVERB_MAX_DECAY_HFRATIO
))
1469 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1470 props
->Reverb
.DecayHFRatio
= val
;
1473 case AL_EAXREVERB_DECAY_LFRATIO
:
1474 if(!(val
>= AL_EAXREVERB_MIN_DECAY_LFRATIO
&& val
<= AL_EAXREVERB_MAX_DECAY_LFRATIO
))
1475 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1476 props
->Reverb
.DecayLFRatio
= val
;
1479 case AL_EAXREVERB_REFLECTIONS_GAIN
:
1480 if(!(val
>= AL_EAXREVERB_MIN_REFLECTIONS_GAIN
&& val
<= AL_EAXREVERB_MAX_REFLECTIONS_GAIN
))
1481 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1482 props
->Reverb
.ReflectionsGain
= val
;
1485 case AL_EAXREVERB_REFLECTIONS_DELAY
:
1486 if(!(val
>= AL_EAXREVERB_MIN_REFLECTIONS_DELAY
&& val
<= AL_EAXREVERB_MAX_REFLECTIONS_DELAY
))
1487 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1488 props
->Reverb
.ReflectionsDelay
= val
;
1491 case AL_EAXREVERB_LATE_REVERB_GAIN
:
1492 if(!(val
>= AL_EAXREVERB_MIN_LATE_REVERB_GAIN
&& val
<= AL_EAXREVERB_MAX_LATE_REVERB_GAIN
))
1493 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1494 props
->Reverb
.LateReverbGain
= val
;
1497 case AL_EAXREVERB_LATE_REVERB_DELAY
:
1498 if(!(val
>= AL_EAXREVERB_MIN_LATE_REVERB_DELAY
&& val
<= AL_EAXREVERB_MAX_LATE_REVERB_DELAY
))
1499 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1500 props
->Reverb
.LateReverbDelay
= val
;
1503 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF
:
1504 if(!(val
>= AL_EAXREVERB_MIN_AIR_ABSORPTION_GAINHF
&& val
<= AL_EAXREVERB_MAX_AIR_ABSORPTION_GAINHF
))
1505 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1506 props
->Reverb
.AirAbsorptionGainHF
= val
;
1509 case AL_EAXREVERB_ECHO_TIME
:
1510 if(!(val
>= AL_EAXREVERB_MIN_ECHO_TIME
&& val
<= AL_EAXREVERB_MAX_ECHO_TIME
))
1511 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1512 props
->Reverb
.EchoTime
= val
;
1515 case AL_EAXREVERB_ECHO_DEPTH
:
1516 if(!(val
>= AL_EAXREVERB_MIN_ECHO_DEPTH
&& val
<= AL_EAXREVERB_MAX_ECHO_DEPTH
))
1517 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1518 props
->Reverb
.EchoDepth
= val
;
1521 case AL_EAXREVERB_MODULATION_TIME
:
1522 if(!(val
>= AL_EAXREVERB_MIN_MODULATION_TIME
&& val
<= AL_EAXREVERB_MAX_MODULATION_TIME
))
1523 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1524 props
->Reverb
.ModulationTime
= val
;
1527 case AL_EAXREVERB_MODULATION_DEPTH
:
1528 if(!(val
>= AL_EAXREVERB_MIN_MODULATION_DEPTH
&& val
<= AL_EAXREVERB_MAX_MODULATION_DEPTH
))
1529 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1530 props
->Reverb
.ModulationDepth
= val
;
1533 case AL_EAXREVERB_HFREFERENCE
:
1534 if(!(val
>= AL_EAXREVERB_MIN_HFREFERENCE
&& val
<= AL_EAXREVERB_MAX_HFREFERENCE
))
1535 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1536 props
->Reverb
.HFReference
= val
;
1539 case AL_EAXREVERB_LFREFERENCE
:
1540 if(!(val
>= AL_EAXREVERB_MIN_LFREFERENCE
&& val
<= AL_EAXREVERB_MAX_LFREFERENCE
))
1541 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1542 props
->Reverb
.LFReference
= val
;
1545 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR
:
1546 if(!(val
>= AL_EAXREVERB_MIN_ROOM_ROLLOFF_FACTOR
&& val
<= AL_EAXREVERB_MAX_ROOM_ROLLOFF_FACTOR
))
1547 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1548 props
->Reverb
.RoomRolloffFactor
= val
;
1552 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1555 void ALeaxreverb_setParamfv(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, const ALfloat
*vals
)
1557 ALeffectProps
*props
= &effect
->Props
;
1560 case AL_EAXREVERB_REFLECTIONS_PAN
:
1561 if(!(isfinite(vals
[0]) && isfinite(vals
[1]) && isfinite(vals
[2])))
1562 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1563 LockContext(context
);
1564 props
->Reverb
.ReflectionsPan
[0] = vals
[0];
1565 props
->Reverb
.ReflectionsPan
[1] = vals
[1];
1566 props
->Reverb
.ReflectionsPan
[2] = vals
[2];
1567 UnlockContext(context
);
1569 case AL_EAXREVERB_LATE_REVERB_PAN
:
1570 if(!(isfinite(vals
[0]) && isfinite(vals
[1]) && isfinite(vals
[2])))
1571 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1572 LockContext(context
);
1573 props
->Reverb
.LateReverbPan
[0] = vals
[0];
1574 props
->Reverb
.LateReverbPan
[1] = vals
[1];
1575 props
->Reverb
.LateReverbPan
[2] = vals
[2];
1576 UnlockContext(context
);
1580 ALeaxreverb_setParamf(effect
, context
, param
, vals
[0]);
1585 void ALeaxreverb_getParami(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALint
*val
)
1587 const ALeffectProps
*props
= &effect
->Props
;
1590 case AL_EAXREVERB_DECAY_HFLIMIT
:
1591 *val
= props
->Reverb
.DecayHFLimit
;
1595 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1598 void ALeaxreverb_getParamiv(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALint
*vals
)
1600 ALeaxreverb_getParami(effect
, context
, param
, vals
);
1602 void ALeaxreverb_getParamf(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat
*val
)
1604 const ALeffectProps
*props
= &effect
->Props
;
1607 case AL_EAXREVERB_DENSITY
:
1608 *val
= props
->Reverb
.Density
;
1611 case AL_EAXREVERB_DIFFUSION
:
1612 *val
= props
->Reverb
.Diffusion
;
1615 case AL_EAXREVERB_GAIN
:
1616 *val
= props
->Reverb
.Gain
;
1619 case AL_EAXREVERB_GAINHF
:
1620 *val
= props
->Reverb
.GainHF
;
1623 case AL_EAXREVERB_GAINLF
:
1624 *val
= props
->Reverb
.GainLF
;
1627 case AL_EAXREVERB_DECAY_TIME
:
1628 *val
= props
->Reverb
.DecayTime
;
1631 case AL_EAXREVERB_DECAY_HFRATIO
:
1632 *val
= props
->Reverb
.DecayHFRatio
;
1635 case AL_EAXREVERB_DECAY_LFRATIO
:
1636 *val
= props
->Reverb
.DecayLFRatio
;
1639 case AL_EAXREVERB_REFLECTIONS_GAIN
:
1640 *val
= props
->Reverb
.ReflectionsGain
;
1643 case AL_EAXREVERB_REFLECTIONS_DELAY
:
1644 *val
= props
->Reverb
.ReflectionsDelay
;
1647 case AL_EAXREVERB_LATE_REVERB_GAIN
:
1648 *val
= props
->Reverb
.LateReverbGain
;
1651 case AL_EAXREVERB_LATE_REVERB_DELAY
:
1652 *val
= props
->Reverb
.LateReverbDelay
;
1655 case AL_EAXREVERB_AIR_ABSORPTION_GAINHF
:
1656 *val
= props
->Reverb
.AirAbsorptionGainHF
;
1659 case AL_EAXREVERB_ECHO_TIME
:
1660 *val
= props
->Reverb
.EchoTime
;
1663 case AL_EAXREVERB_ECHO_DEPTH
:
1664 *val
= props
->Reverb
.EchoDepth
;
1667 case AL_EAXREVERB_MODULATION_TIME
:
1668 *val
= props
->Reverb
.ModulationTime
;
1671 case AL_EAXREVERB_MODULATION_DEPTH
:
1672 *val
= props
->Reverb
.ModulationDepth
;
1675 case AL_EAXREVERB_HFREFERENCE
:
1676 *val
= props
->Reverb
.HFReference
;
1679 case AL_EAXREVERB_LFREFERENCE
:
1680 *val
= props
->Reverb
.LFReference
;
1683 case AL_EAXREVERB_ROOM_ROLLOFF_FACTOR
:
1684 *val
= props
->Reverb
.RoomRolloffFactor
;
1688 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1691 void ALeaxreverb_getParamfv(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat
*vals
)
1693 const ALeffectProps
*props
= &effect
->Props
;
1696 case AL_EAXREVERB_REFLECTIONS_PAN
:
1697 LockContext(context
);
1698 vals
[0] = props
->Reverb
.ReflectionsPan
[0];
1699 vals
[1] = props
->Reverb
.ReflectionsPan
[1];
1700 vals
[2] = props
->Reverb
.ReflectionsPan
[2];
1701 UnlockContext(context
);
1703 case AL_EAXREVERB_LATE_REVERB_PAN
:
1704 LockContext(context
);
1705 vals
[0] = props
->Reverb
.LateReverbPan
[0];
1706 vals
[1] = props
->Reverb
.LateReverbPan
[1];
1707 vals
[2] = props
->Reverb
.LateReverbPan
[2];
1708 UnlockContext(context
);
1712 ALeaxreverb_getParamf(effect
, context
, param
, vals
);
1717 DEFINE_ALEFFECT_VTABLE(ALeaxreverb
);
1719 void ALreverb_setParami(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALint val
)
1721 ALeffectProps
*props
= &effect
->Props
;
1724 case AL_REVERB_DECAY_HFLIMIT
:
1725 if(!(val
>= AL_REVERB_MIN_DECAY_HFLIMIT
&& val
<= AL_REVERB_MAX_DECAY_HFLIMIT
))
1726 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1727 props
->Reverb
.DecayHFLimit
= val
;
1731 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1734 void ALreverb_setParamiv(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, const ALint
*vals
)
1736 ALreverb_setParami(effect
, context
, param
, vals
[0]);
1738 void ALreverb_setParamf(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat val
)
1740 ALeffectProps
*props
= &effect
->Props
;
1743 case AL_REVERB_DENSITY
:
1744 if(!(val
>= AL_REVERB_MIN_DENSITY
&& val
<= AL_REVERB_MAX_DENSITY
))
1745 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1746 props
->Reverb
.Density
= val
;
1749 case AL_REVERB_DIFFUSION
:
1750 if(!(val
>= AL_REVERB_MIN_DIFFUSION
&& val
<= AL_REVERB_MAX_DIFFUSION
))
1751 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1752 props
->Reverb
.Diffusion
= val
;
1755 case AL_REVERB_GAIN
:
1756 if(!(val
>= AL_REVERB_MIN_GAIN
&& val
<= AL_REVERB_MAX_GAIN
))
1757 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1758 props
->Reverb
.Gain
= val
;
1761 case AL_REVERB_GAINHF
:
1762 if(!(val
>= AL_REVERB_MIN_GAINHF
&& val
<= AL_REVERB_MAX_GAINHF
))
1763 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1764 props
->Reverb
.GainHF
= val
;
1767 case AL_REVERB_DECAY_TIME
:
1768 if(!(val
>= AL_REVERB_MIN_DECAY_TIME
&& val
<= AL_REVERB_MAX_DECAY_TIME
))
1769 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1770 props
->Reverb
.DecayTime
= val
;
1773 case AL_REVERB_DECAY_HFRATIO
:
1774 if(!(val
>= AL_REVERB_MIN_DECAY_HFRATIO
&& val
<= AL_REVERB_MAX_DECAY_HFRATIO
))
1775 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1776 props
->Reverb
.DecayHFRatio
= val
;
1779 case AL_REVERB_REFLECTIONS_GAIN
:
1780 if(!(val
>= AL_REVERB_MIN_REFLECTIONS_GAIN
&& val
<= AL_REVERB_MAX_REFLECTIONS_GAIN
))
1781 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1782 props
->Reverb
.ReflectionsGain
= val
;
1785 case AL_REVERB_REFLECTIONS_DELAY
:
1786 if(!(val
>= AL_REVERB_MIN_REFLECTIONS_DELAY
&& val
<= AL_REVERB_MAX_REFLECTIONS_DELAY
))
1787 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1788 props
->Reverb
.ReflectionsDelay
= val
;
1791 case AL_REVERB_LATE_REVERB_GAIN
:
1792 if(!(val
>= AL_REVERB_MIN_LATE_REVERB_GAIN
&& val
<= AL_REVERB_MAX_LATE_REVERB_GAIN
))
1793 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1794 props
->Reverb
.LateReverbGain
= val
;
1797 case AL_REVERB_LATE_REVERB_DELAY
:
1798 if(!(val
>= AL_REVERB_MIN_LATE_REVERB_DELAY
&& val
<= AL_REVERB_MAX_LATE_REVERB_DELAY
))
1799 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1800 props
->Reverb
.LateReverbDelay
= val
;
1803 case AL_REVERB_AIR_ABSORPTION_GAINHF
:
1804 if(!(val
>= AL_REVERB_MIN_AIR_ABSORPTION_GAINHF
&& val
<= AL_REVERB_MAX_AIR_ABSORPTION_GAINHF
))
1805 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1806 props
->Reverb
.AirAbsorptionGainHF
= val
;
1809 case AL_REVERB_ROOM_ROLLOFF_FACTOR
:
1810 if(!(val
>= AL_REVERB_MIN_ROOM_ROLLOFF_FACTOR
&& val
<= AL_REVERB_MAX_ROOM_ROLLOFF_FACTOR
))
1811 SET_ERROR_AND_RETURN(context
, AL_INVALID_VALUE
);
1812 props
->Reverb
.RoomRolloffFactor
= val
;
1816 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1819 void ALreverb_setParamfv(ALeffect
*effect
, ALCcontext
*context
, ALenum param
, const ALfloat
*vals
)
1821 ALreverb_setParamf(effect
, context
, param
, vals
[0]);
1824 void ALreverb_getParami(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALint
*val
)
1826 const ALeffectProps
*props
= &effect
->Props
;
1829 case AL_REVERB_DECAY_HFLIMIT
:
1830 *val
= props
->Reverb
.DecayHFLimit
;
1834 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1837 void ALreverb_getParamiv(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALint
*vals
)
1839 ALreverb_getParami(effect
, context
, param
, vals
);
1841 void ALreverb_getParamf(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat
*val
)
1843 const ALeffectProps
*props
= &effect
->Props
;
1846 case AL_REVERB_DENSITY
:
1847 *val
= props
->Reverb
.Density
;
1850 case AL_REVERB_DIFFUSION
:
1851 *val
= props
->Reverb
.Diffusion
;
1854 case AL_REVERB_GAIN
:
1855 *val
= props
->Reverb
.Gain
;
1858 case AL_REVERB_GAINHF
:
1859 *val
= props
->Reverb
.GainHF
;
1862 case AL_REVERB_DECAY_TIME
:
1863 *val
= props
->Reverb
.DecayTime
;
1866 case AL_REVERB_DECAY_HFRATIO
:
1867 *val
= props
->Reverb
.DecayHFRatio
;
1870 case AL_REVERB_REFLECTIONS_GAIN
:
1871 *val
= props
->Reverb
.ReflectionsGain
;
1874 case AL_REVERB_REFLECTIONS_DELAY
:
1875 *val
= props
->Reverb
.ReflectionsDelay
;
1878 case AL_REVERB_LATE_REVERB_GAIN
:
1879 *val
= props
->Reverb
.LateReverbGain
;
1882 case AL_REVERB_LATE_REVERB_DELAY
:
1883 *val
= props
->Reverb
.LateReverbDelay
;
1886 case AL_REVERB_AIR_ABSORPTION_GAINHF
:
1887 *val
= props
->Reverb
.AirAbsorptionGainHF
;
1890 case AL_REVERB_ROOM_ROLLOFF_FACTOR
:
1891 *val
= props
->Reverb
.RoomRolloffFactor
;
1895 SET_ERROR_AND_RETURN(context
, AL_INVALID_ENUM
);
1898 void ALreverb_getParamfv(const ALeffect
*effect
, ALCcontext
*context
, ALenum param
, ALfloat
*vals
)
1900 ALreverb_getParamf(effect
, context
, param
, vals
);
1903 DEFINE_ALEFFECT_VTABLE(ALreverb
);