Always fade the main early and late delay taps
[openal-soft.git] / alc / effects / reverb.cpp
blob01b70339dabcbfcbf115b26638fd2a97ac6fb081
1 /**
2 * Ambisonic reverb engine for the OpenAL cross platform audio library
3 * Copyright (C) 2008-2017 by Chris Robinson and 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
21 #include "config.h"
23 #include <algorithm>
24 #include <array>
25 #include <cstdio>
26 #include <functional>
27 #include <iterator>
28 #include <numeric>
29 #include <stdint.h>
31 #include "alc/effects/base.h"
32 #include "almalloc.h"
33 #include "alnumbers.h"
34 #include "alnumeric.h"
35 #include "alspan.h"
36 #include "core/ambidefs.h"
37 #include "core/bufferline.h"
38 #include "core/context.h"
39 #include "core/devformat.h"
40 #include "core/device.h"
41 #include "core/effectslot.h"
42 #include "core/filters/biquad.h"
43 #include "core/filters/splitter.h"
44 #include "core/mixer.h"
45 #include "core/mixer/defs.h"
46 #include "intrusive_ptr.h"
47 #include "opthelpers.h"
48 #include "vecmat.h"
49 #include "vector.h"
51 /* This is a user config option for modifying the overall output of the reverb
52 * effect.
54 float ReverbBoost = 1.0f;
56 namespace {
58 using uint = unsigned int;
60 constexpr float MaxModulationTime{4.0f};
61 constexpr float DefaultModulationTime{0.25f};
63 #define MOD_FRACBITS 24
64 #define MOD_FRACONE (1<<MOD_FRACBITS)
65 #define MOD_FRACMASK (MOD_FRACONE-1)
68 using namespace std::placeholders;
70 /* Max samples per process iteration. Used to limit the size needed for
71 * temporary buffers. Must be a multiple of 4 for SIMD alignment.
73 constexpr size_t MAX_UPDATE_SAMPLES{256};
75 /* The number of spatialized lines or channels to process. Four channels allows
76 * for a 3D A-Format response. NOTE: This can't be changed without taking care
77 * of the conversion matrices, and a few places where the length arrays are
78 * assumed to have 4 elements.
80 constexpr size_t NUM_LINES{4u};
83 /* This coefficient is used to define the maximum frequency range controlled by
84 * the modulation depth. The current value of 0.05 will allow it to swing from
85 * 0.95x to 1.05x. This value must be below 1. At 1 it will cause the sampler
86 * to stall on the downswing, and above 1 it will cause it to sample backwards.
87 * The value 0.05 seems be nearest to Creative hardware behavior.
89 constexpr float MODULATION_DEPTH_COEFF{0.05f};
92 /* The B-Format to A-Format conversion matrix. The arrangement of rows is
93 * deliberately chosen to align the resulting lines to their spatial opposites
94 * (0:above front left <-> 3:above back right, 1:below front right <-> 2:below
95 * back left). It's not quite opposite, since the A-Format results in a
96 * tetrahedron, but it's close enough. Should the model be extended to 8-lines
97 * in the future, true opposites can be used.
99 alignas(16) constexpr float B2A[NUM_LINES][NUM_LINES]{
100 { 0.5f, 0.5f, 0.5f, 0.5f },
101 { 0.5f, -0.5f, -0.5f, 0.5f },
102 { 0.5f, 0.5f, -0.5f, -0.5f },
103 { 0.5f, -0.5f, 0.5f, -0.5f }
106 /* Converts A-Format to B-Format for early reflections. */
107 alignas(16) constexpr std::array<std::array<float,NUM_LINES>,NUM_LINES> EarlyA2B{{
108 {{ 0.5f, 0.5f, 0.5f, 0.5f }},
109 {{ 0.5f, -0.5f, 0.5f, -0.5f }},
110 {{ 0.5f, -0.5f, -0.5f, 0.5f }},
111 {{ 0.5f, 0.5f, -0.5f, -0.5f }}
114 /* Converts A-Format to B-Format for late reverb. */
115 constexpr auto InvSqrt2 = static_cast<float>(1.0/al::numbers::sqrt2);
116 alignas(16) constexpr std::array<std::array<float,NUM_LINES>,NUM_LINES> LateA2B{{
117 {{ 0.5f, 0.5f, 0.5f, 0.5f }},
118 {{ InvSqrt2, -InvSqrt2, 0.0f, 0.0f }},
119 {{ 0.0f, 0.0f, InvSqrt2, -InvSqrt2 }},
120 {{ 0.5f, 0.5f, -0.5f, -0.5f }}
123 /* The all-pass and delay lines have a variable length dependent on the
124 * effect's density parameter, which helps alter the perceived environment
125 * size. The size-to-density conversion is a cubed scale:
127 * density = min(1.0, pow(size, 3.0) / DENSITY_SCALE);
129 * The line lengths scale linearly with room size, so the inverse density
130 * conversion is needed, taking the cube root of the re-scaled density to
131 * calculate the line length multiplier:
133 * length_mult = max(5.0, cbrt(density*DENSITY_SCALE));
135 * The density scale below will result in a max line multiplier of 50, for an
136 * effective size range of 5m to 50m.
138 constexpr float DENSITY_SCALE{125000.0f};
140 /* All delay line lengths are specified in seconds.
142 * To approximate early reflections, we break them up into primary (those
143 * arriving from the same direction as the source) and secondary (those
144 * arriving from the opposite direction).
146 * The early taps decorrelate the 4-channel signal to approximate an average
147 * room response for the primary reflections after the initial early delay.
149 * Given an average room dimension (d_a) and the speed of sound (c) we can
150 * calculate the average reflection delay (r_a) regardless of listener and
151 * source positions as:
153 * r_a = d_a / c
154 * c = 343.3
156 * This can extended to finding the average difference (r_d) between the
157 * maximum (r_1) and minimum (r_0) reflection delays:
159 * r_0 = 2 / 3 r_a
160 * = r_a - r_d / 2
161 * = r_d
162 * r_1 = 4 / 3 r_a
163 * = r_a + r_d / 2
164 * = 2 r_d
165 * r_d = 2 / 3 r_a
166 * = r_1 - r_0
168 * As can be determined by integrating the 1D model with a source (s) and
169 * listener (l) positioned across the dimension of length (d_a):
171 * r_d = int_(l=0)^d_a (int_(s=0)^d_a |2 d_a - 2 (l + s)| ds) dl / c
173 * The initial taps (T_(i=0)^N) are then specified by taking a power series
174 * that ranges between r_0 and half of r_1 less r_0:
176 * R_i = 2^(i / (2 N - 1)) r_d
177 * = r_0 + (2^(i / (2 N - 1)) - 1) r_d
178 * = r_0 + T_i
179 * T_i = R_i - r_0
180 * = (2^(i / (2 N - 1)) - 1) r_d
182 * Assuming an average of 1m, we get the following taps:
184 constexpr std::array<float,NUM_LINES> EARLY_TAP_LENGTHS{{
185 0.0000000e+0f, 2.0213520e-4f, 4.2531060e-4f, 6.7171600e-4f
188 /* The early all-pass filter lengths are based on the early tap lengths:
190 * A_i = R_i / a
192 * Where a is the approximate maximum all-pass cycle limit (20).
194 constexpr std::array<float,NUM_LINES> EARLY_ALLPASS_LENGTHS{{
195 9.7096800e-5f, 1.0720356e-4f, 1.1836234e-4f, 1.3068260e-4f
198 /* The early delay lines are used to transform the primary reflections into
199 * the secondary reflections. The A-format is arranged in such a way that
200 * the channels/lines are spatially opposite:
202 * C_i is opposite C_(N-i-1)
204 * The delays of the two opposing reflections (R_i and O_i) from a source
205 * anywhere along a particular dimension always sum to twice its full delay:
207 * 2 r_a = R_i + O_i
209 * With that in mind we can determine the delay between the two reflections
210 * and thus specify our early line lengths (L_(i=0)^N) using:
212 * O_i = 2 r_a - R_(N-i-1)
213 * L_i = O_i - R_(N-i-1)
214 * = 2 (r_a - R_(N-i-1))
215 * = 2 (r_a - T_(N-i-1) - r_0)
216 * = 2 r_a (1 - (2 / 3) 2^((N - i - 1) / (2 N - 1)))
218 * Using an average dimension of 1m, we get:
220 constexpr std::array<float,NUM_LINES> EARLY_LINE_LENGTHS{{
221 5.9850400e-4f, 1.0913150e-3f, 1.5376658e-3f, 1.9419362e-3f
224 /* The late all-pass filter lengths are based on the late line lengths:
226 * A_i = (5 / 3) L_i / r_1
228 constexpr std::array<float,NUM_LINES> LATE_ALLPASS_LENGTHS{{
229 1.6182800e-4f, 2.0389060e-4f, 2.8159360e-4f, 3.2365600e-4f
232 /* The late lines are used to approximate the decaying cycle of recursive
233 * late reflections.
235 * Splitting the lines in half, we start with the shortest reflection paths
236 * (L_(i=0)^(N/2)):
238 * L_i = 2^(i / (N - 1)) r_d
240 * Then for the opposite (longest) reflection paths (L_(i=N/2)^N):
242 * L_i = 2 r_a - L_(i-N/2)
243 * = 2 r_a - 2^((i - N / 2) / (N - 1)) r_d
245 * For our 1m average room, we get:
247 constexpr std::array<float,NUM_LINES> LATE_LINE_LENGTHS{{
248 1.9419362e-3f, 2.4466860e-3f, 3.3791220e-3f, 3.8838720e-3f
252 using ReverbUpdateLine = std::array<float,MAX_UPDATE_SAMPLES>;
254 struct DelayLineI {
255 /* The delay lines use interleaved samples, with the lengths being powers
256 * of 2 to allow the use of bit-masking instead of a modulus for wrapping.
258 size_t Mask{0u};
259 union {
260 uintptr_t LineOffset{0u};
261 std::array<float,NUM_LINES> *Line;
264 /* Given the allocated sample buffer, this function updates each delay line
265 * offset.
267 void realizeLineOffset(std::array<float,NUM_LINES> *sampleBuffer) noexcept
268 { Line = sampleBuffer + LineOffset; }
270 /* Calculate the length of a delay line and store its mask and offset. */
271 uint calcLineLength(const float length, const uintptr_t offset, const float frequency,
272 const uint extra)
274 /* All line lengths are powers of 2, calculated from their lengths in
275 * seconds, rounded up.
277 uint samples{float2uint(std::ceil(length*frequency))};
278 samples = NextPowerOf2(samples + extra);
280 /* All lines share a single sample buffer. */
281 Mask = samples - 1;
282 LineOffset = offset;
284 /* Return the sample count for accumulation. */
285 return samples;
288 void write(size_t offset, const size_t c, const float *RESTRICT in, const size_t count) const noexcept
290 ASSUME(count > 0);
291 for(size_t i{0u};i < count;)
293 offset &= Mask;
294 size_t td{minz(Mask+1 - offset, count - i)};
295 do {
296 Line[offset++][c] = in[i++];
297 } while(--td);
302 struct VecAllpass {
303 DelayLineI Delay;
304 float Coeff{0.0f};
305 size_t Offset[NUM_LINES][2]{};
307 void processFaded(const al::span<ReverbUpdateLine,NUM_LINES> samples, size_t offset,
308 const float xCoeff, const float yCoeff, float fadeCount, const float fadeStep,
309 const size_t todo);
310 void processUnfaded(const al::span<ReverbUpdateLine,NUM_LINES> samples, size_t offset,
311 const float xCoeff, const float yCoeff, const size_t todo);
314 struct T60Filter {
315 /* Two filters are used to adjust the signal. One to control the low
316 * frequencies, and one to control the high frequencies.
318 float MidGain[2]{0.0f, 0.0f};
319 BiquadFilter HFFilter, LFFilter;
321 void calcCoeffs(const float length, const float lfDecayTime, const float mfDecayTime,
322 const float hfDecayTime, const float lf0norm, const float hf0norm);
324 /* Applies the two T60 damping filter sections. */
325 void process(const al::span<float> samples)
326 { DualBiquad{HFFilter, LFFilter}.process(samples, samples.data()); }
329 struct EarlyReflections {
330 /* A Gerzon vector all-pass filter is used to simulate initial diffusion.
331 * The spread from this filter also helps smooth out the reverb tail.
333 VecAllpass VecAp;
335 /* An echo line is used to complete the second half of the early
336 * reflections.
338 DelayLineI Delay;
339 size_t Offset[NUM_LINES][2]{};
340 float Coeff[NUM_LINES][2]{};
342 /* The gain for each output channel based on 3D panning. */
343 float CurrentGain[NUM_LINES][MaxAmbiChannels]{};
344 float PanGain[NUM_LINES][MaxAmbiChannels]{};
346 void updateLines(const float density_mult, const float diffusion, const float decayTime,
347 const float frequency);
351 struct Modulation {
352 /* The vibrato time is tracked with an index over a (MOD_FRACONE)
353 * normalized range.
355 uint Index, Step;
357 /* The depth of frequency change, in samples. */
358 float Depth[2];
360 float ModDelays[MAX_UPDATE_SAMPLES];
362 void updateModulator(float modTime, float modDepth, float frequency);
364 void calcDelays(size_t todo);
365 void calcFadedDelays(size_t todo, float fadeCount, float fadeStep);
368 struct LateReverb {
369 /* A recursive delay line is used fill in the reverb tail. */
370 DelayLineI Delay;
371 size_t Offset[NUM_LINES][2]{};
373 /* Attenuation to compensate for the modal density and decay rate of the
374 * late lines.
376 float DensityGain[2]{0.0f, 0.0f};
378 /* T60 decay filters are used to simulate absorption. */
379 T60Filter T60[NUM_LINES];
381 Modulation Mod;
383 /* A Gerzon vector all-pass filter is used to simulate diffusion. */
384 VecAllpass VecAp;
386 /* The gain for each output channel based on 3D panning. */
387 float CurrentGain[NUM_LINES][MaxAmbiChannels]{};
388 float PanGain[NUM_LINES][MaxAmbiChannels]{};
390 void updateLines(const float density_mult, const float diffusion, const float lfDecayTime,
391 const float mfDecayTime, const float hfDecayTime, const float lf0norm,
392 const float hf0norm, const float frequency);
395 struct ReverbState final : public EffectState {
396 /* All delay lines are allocated as a single buffer to reduce memory
397 * fragmentation and management code.
399 al::vector<std::array<float,NUM_LINES>,16> mSampleBuffer;
401 struct {
402 /* Calculated parameters which indicate if cross-fading is needed after
403 * an update.
405 float Density{1.0f};
406 float Diffusion{1.0f};
407 float DecayTime{1.49f};
408 float HFDecayTime{0.83f * 1.49f};
409 float LFDecayTime{1.0f * 1.49f};
410 float ModulationTime{0.25f};
411 float ModulationDepth{0.0f};
412 float HFReference{5000.0f};
413 float LFReference{250.0f};
414 } mParams;
416 /* Master effect filters */
417 struct {
418 BiquadFilter Lp;
419 BiquadFilter Hp;
420 } mFilter[NUM_LINES];
422 /* Core delay line (early reflections and late reverb tap from this). */
423 DelayLineI mEarlyDelayIn;
424 DelayLineI mLateDelayIn;
426 /* Tap points for early reflection delay. */
427 size_t mEarlyDelayTap[NUM_LINES][2]{};
428 float mEarlyDelayCoeff[NUM_LINES][2]{};
430 /* Tap points for late reverb feed and delay. */
431 size_t mLateDelayTap[NUM_LINES][2]{};
433 /* Coefficients for the all-pass and line scattering matrices. */
434 float mMixX{0.0f};
435 float mMixY{0.0f};
437 EarlyReflections mEarly;
439 LateReverb mLate;
441 bool mDoFading{};
443 /* The current write offset for all delay lines. */
444 size_t mOffset{};
446 /* Temporary storage used when processing. */
447 union {
448 alignas(16) FloatBufferLine mTempLine{};
449 alignas(16) std::array<ReverbUpdateLine,NUM_LINES> mTempSamples;
451 alignas(16) std::array<FloatBufferLine,NUM_LINES> mEarlySamples{};
452 alignas(16) std::array<FloatBufferLine,NUM_LINES> mLateSamples{};
455 bool mUpmixOutput{false};
456 std::array<float,MaxAmbiOrder+1> mOrderScales{};
457 std::array<std::array<BandSplitter,NUM_LINES>,2> mAmbiSplitter;
460 static void DoMixRow(const al::span<float> OutBuffer, const al::span<const float,4> Gains,
461 const float *InSamples, const size_t InStride)
463 std::fill(OutBuffer.begin(), OutBuffer.end(), 0.0f);
464 for(const float gain : Gains)
466 const float *RESTRICT input{al::assume_aligned<16>(InSamples)};
467 InSamples += InStride;
469 if(!(std::fabs(gain) > GainSilenceThreshold))
470 continue;
472 for(float &sample : OutBuffer)
474 sample += *input * gain;
475 ++input;
481 void MixOutPlain(const al::span<FloatBufferLine> samplesOut, const size_t todo)
483 ASSUME(todo > 0);
485 /* When not upsampling, the panning gains convert to B-Format and pan
486 * at the same time.
488 for(size_t c{0u};c < NUM_LINES;c++)
490 const al::span<float> tmpspan{mEarlySamples[c].data(), todo};
491 MixSamples(tmpspan, samplesOut, mEarly.CurrentGain[c], mEarly.PanGain[c], todo, 0);
493 for(size_t c{0u};c < NUM_LINES;c++)
495 const al::span<float> tmpspan{mLateSamples[c].data(), todo};
496 MixSamples(tmpspan, samplesOut, mLate.CurrentGain[c], mLate.PanGain[c], todo, 0);
500 void MixOutAmbiUp(const al::span<FloatBufferLine> samplesOut, const size_t todo)
502 ASSUME(todo > 0);
504 /* When upsampling, the B-Format conversion needs to be done separately
505 * so the proper HF scaling can be applied to each B-Format channel.
506 * The panning gains then pan and upsample the B-Format channels.
508 const al::span<float> tmpspan{al::assume_aligned<16>(mTempLine.data()), todo};
509 for(size_t c{0u};c < NUM_LINES;c++)
511 DoMixRow(tmpspan, EarlyA2B[c], mEarlySamples[0].data(), mEarlySamples[0].size());
513 /* Apply scaling to the B-Format's HF response to "upsample" it to
514 * higher-order output.
516 const float hfscale{(c==0) ? mOrderScales[0] : mOrderScales[1]};
517 mAmbiSplitter[0][c].processHfScale(tmpspan, hfscale);
519 MixSamples(tmpspan, samplesOut, mEarly.CurrentGain[c], mEarly.PanGain[c], todo, 0);
521 for(size_t c{0u};c < NUM_LINES;c++)
523 DoMixRow(tmpspan, LateA2B[c], mLateSamples[0].data(), mLateSamples[0].size());
525 const float hfscale{(c==0) ? mOrderScales[0] : mOrderScales[1]};
526 mAmbiSplitter[1][c].processHfScale(tmpspan, hfscale);
528 MixSamples(tmpspan, samplesOut, mLate.CurrentGain[c], mLate.PanGain[c], todo, 0);
532 void mixOut(const al::span<FloatBufferLine> samplesOut, const size_t todo)
534 if(mUpmixOutput)
535 MixOutAmbiUp(samplesOut, todo);
536 else
537 MixOutPlain(samplesOut, todo);
540 void allocLines(const float frequency);
542 void updateDelayLine(const float earlyDelay, const float lateDelay, const float density_mult,
543 const float decayTime, const float frequency);
544 void update3DPanning(const float *ReflectionsPan, const float *LateReverbPan,
545 const float earlyGain, const float lateGain, const EffectTarget &target);
547 void earlyUnfaded(size_t offset, const size_t samplesToDo);
548 void earlyFaded(size_t offset, const size_t samplesToDo, const float fadeStep);
550 void lateUnfaded(size_t offset, const size_t samplesToDo);
551 void lateFaded(size_t offset, const size_t samplesToDo, const float fadeStep);
553 void deviceUpdate(const DeviceBase *device, const Buffer &buffer) override;
554 void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props,
555 const EffectTarget target) override;
556 void process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn,
557 const al::span<FloatBufferLine> samplesOut) override;
559 DEF_NEWDEL(ReverbState)
562 /**************************************
563 * Device Update *
564 **************************************/
566 inline float CalcDelayLengthMult(float density)
567 { return maxf(5.0f, std::cbrt(density*DENSITY_SCALE)); }
569 /* Calculates the delay line metrics and allocates the shared sample buffer
570 * for all lines given the sample rate (frequency).
572 void ReverbState::allocLines(const float frequency)
574 /* All delay line lengths are calculated to accomodate the full range of
575 * lengths given their respective paramters.
577 size_t totalSamples{0u};
579 /* Multiplier for the maximum density value, i.e. density=1, which is
580 * actually the least density...
582 const float multiplier{CalcDelayLengthMult(1.0f)};
584 /* The main delay length includes the maximum early reflection delay, the
585 * largest early tap width, the maximum late reverb delay, and the
586 * largest late tap width. Finally, it must also be extended by the
587 * update size (BufferLineSize) for block processing.
589 float length{ReverbMaxReflectionsDelay + EARLY_TAP_LENGTHS.back()*multiplier};
590 totalSamples += mEarlyDelayIn.calcLineLength(length, totalSamples, frequency, BufferLineSize);
592 constexpr float LateLineDiffAvg{(LATE_LINE_LENGTHS.back()-LATE_LINE_LENGTHS.front()) /
593 float{NUM_LINES}};
594 length = ReverbMaxLateReverbDelay + LateLineDiffAvg*multiplier;
595 totalSamples += mLateDelayIn.calcLineLength(length, totalSamples, frequency, BufferLineSize);
597 /* The early vector all-pass line. */
598 length = EARLY_ALLPASS_LENGTHS.back() * multiplier;
599 totalSamples += mEarly.VecAp.Delay.calcLineLength(length, totalSamples, frequency, 0);
601 /* The early reflection line. */
602 length = EARLY_LINE_LENGTHS.back() * multiplier;
603 totalSamples += mEarly.Delay.calcLineLength(length, totalSamples, frequency,
604 MAX_UPDATE_SAMPLES);
606 /* The late vector all-pass line. */
607 length = LATE_ALLPASS_LENGTHS.back() * multiplier;
608 totalSamples += mLate.VecAp.Delay.calcLineLength(length, totalSamples, frequency, 0);
610 /* The modulator's line length is calculated from the maximum modulation
611 * time and depth coefficient, and halfed for the low-to-high frequency
612 * swing.
614 constexpr float max_mod_delay{MaxModulationTime*MODULATION_DEPTH_COEFF / 2.0f};
616 /* The late delay lines are calculated from the largest maximum density
617 * line length, and the maximum modulation delay. An additional sample is
618 * added to keep it stable when there is no modulation.
620 length = LATE_LINE_LENGTHS.back()*multiplier + max_mod_delay;
621 totalSamples += mLate.Delay.calcLineLength(length, totalSamples, frequency, 1);
623 if(totalSamples != mSampleBuffer.size())
624 decltype(mSampleBuffer)(totalSamples).swap(mSampleBuffer);
626 /* Clear the sample buffer. */
627 std::fill(mSampleBuffer.begin(), mSampleBuffer.end(), decltype(mSampleBuffer)::value_type{});
629 /* Update all delays to reflect the new sample buffer. */
630 mEarlyDelayIn.realizeLineOffset(mSampleBuffer.data());
631 mLateDelayIn.realizeLineOffset(mSampleBuffer.data());
632 mEarly.VecAp.Delay.realizeLineOffset(mSampleBuffer.data());
633 mEarly.Delay.realizeLineOffset(mSampleBuffer.data());
634 mLate.VecAp.Delay.realizeLineOffset(mSampleBuffer.data());
635 mLate.Delay.realizeLineOffset(mSampleBuffer.data());
638 void ReverbState::deviceUpdate(const DeviceBase *device, const Buffer&)
640 const auto frequency = static_cast<float>(device->Frequency);
642 /* Allocate the delay lines. */
643 allocLines(frequency);
645 /* Clear filters and gain coefficients since the delay lines were all just
646 * cleared (if not reallocated).
648 for(auto &filter : mFilter)
650 filter.Lp.clear();
651 filter.Hp.clear();
654 for(auto &coeff : mEarlyDelayCoeff)
655 std::fill(std::begin(coeff), std::end(coeff), 0.0f);
656 for(auto &coeff : mEarly.Coeff)
657 std::fill(std::begin(coeff), std::end(coeff), 0.0f);
659 mLate.DensityGain[0] = 0.0f;
660 mLate.DensityGain[1] = 0.0f;
661 for(auto &t60 : mLate.T60)
663 t60.MidGain[0] = 0.0f;
664 t60.MidGain[1] = 0.0f;
665 t60.HFFilter.clear();
666 t60.LFFilter.clear();
669 mLate.Mod.Index = 0;
670 mLate.Mod.Step = 1;
671 std::fill(std::begin(mLate.Mod.Depth), std::end(mLate.Mod.Depth), 0.0f);
673 for(auto &gains : mEarly.CurrentGain)
674 std::fill(std::begin(gains), std::end(gains), 0.0f);
675 for(auto &gains : mEarly.PanGain)
676 std::fill(std::begin(gains), std::end(gains), 0.0f);
677 for(auto &gains : mLate.CurrentGain)
678 std::fill(std::begin(gains), std::end(gains), 0.0f);
679 for(auto &gains : mLate.PanGain)
680 std::fill(std::begin(gains), std::end(gains), 0.0f);
682 /* Reset fading and offset base. */
683 mDoFading = true;
684 mOffset = 0;
686 if(device->mAmbiOrder > 1)
688 mUpmixOutput = true;
689 mOrderScales = AmbiScale::GetHFOrderScales(1, true);
691 else
693 mUpmixOutput = false;
694 mOrderScales.fill(1.0f);
696 mAmbiSplitter[0][0].init(device->mXOverFreq / frequency);
697 std::fill(mAmbiSplitter[0].begin()+1, mAmbiSplitter[0].end(), mAmbiSplitter[0][0]);
698 std::fill(mAmbiSplitter[1].begin(), mAmbiSplitter[1].end(), mAmbiSplitter[0][0]);
701 /**************************************
702 * Effect Update *
703 **************************************/
705 /* Calculate a decay coefficient given the length of each cycle and the time
706 * until the decay reaches -60 dB.
708 inline float CalcDecayCoeff(const float length, const float decayTime)
709 { return std::pow(ReverbDecayGain, length/decayTime); }
711 /* Calculate a decay length from a coefficient and the time until the decay
712 * reaches -60 dB.
714 inline float CalcDecayLength(const float coeff, const float decayTime)
716 constexpr float log10_decaygain{-3.0f/*std::log10(ReverbDecayGain)*/};
717 return std::log10(coeff) * decayTime / log10_decaygain;
720 /* Calculate an attenuation to be applied to the input of any echo models to
721 * compensate for modal density and decay time.
723 inline float CalcDensityGain(const float a)
725 /* The energy of a signal can be obtained by finding the area under the
726 * squared signal. This takes the form of Sum(x_n^2), where x is the
727 * amplitude for the sample n.
729 * Decaying feedback matches exponential decay of the form Sum(a^n),
730 * where a is the attenuation coefficient, and n is the sample. The area
731 * under this decay curve can be calculated as: 1 / (1 - a).
733 * Modifying the above equation to find the area under the squared curve
734 * (for energy) yields: 1 / (1 - a^2). Input attenuation can then be
735 * calculated by inverting the square root of this approximation,
736 * yielding: 1 / sqrt(1 / (1 - a^2)), simplified to: sqrt(1 - a^2).
738 return std::sqrt(1.0f - a*a);
741 /* Calculate the scattering matrix coefficients given a diffusion factor. */
742 inline void CalcMatrixCoeffs(const float diffusion, float *x, float *y)
744 /* The matrix is of order 4, so n is sqrt(4 - 1). */
745 constexpr float n{al::numbers::sqrt3_v<float>};
746 const float t{diffusion * std::atan(n)};
748 /* Calculate the first mixing matrix coefficient. */
749 *x = std::cos(t);
750 /* Calculate the second mixing matrix coefficient. */
751 *y = std::sin(t) / n;
754 /* Calculate the limited HF ratio for use with the late reverb low-pass
755 * filters.
757 float CalcLimitedHfRatio(const float hfRatio, const float airAbsorptionGainHF,
758 const float decayTime)
760 /* Find the attenuation due to air absorption in dB (converting delay
761 * time to meters using the speed of sound). Then reversing the decay
762 * equation, solve for HF ratio. The delay length is cancelled out of
763 * the equation, so it can be calculated once for all lines.
765 float limitRatio{1.0f / SpeedOfSoundMetersPerSec /
766 CalcDecayLength(airAbsorptionGainHF, decayTime)};
768 /* Using the limit calculated above, apply the upper bound to the HF ratio. */
769 return minf(limitRatio, hfRatio);
773 /* Calculates the 3-band T60 damping coefficients for a particular delay line
774 * of specified length, using a combination of two shelf filter sections given
775 * decay times for each band split at two reference frequencies.
777 void T60Filter::calcCoeffs(const float length, const float lfDecayTime,
778 const float mfDecayTime, const float hfDecayTime, const float lf0norm,
779 const float hf0norm)
781 const float mfGain{CalcDecayCoeff(length, mfDecayTime)};
782 const float lfGain{CalcDecayCoeff(length, lfDecayTime) / mfGain};
783 const float hfGain{CalcDecayCoeff(length, hfDecayTime) / mfGain};
785 MidGain[1] = mfGain;
786 LFFilter.setParamsFromSlope(BiquadType::LowShelf, lf0norm, lfGain, 1.0f);
787 HFFilter.setParamsFromSlope(BiquadType::HighShelf, hf0norm, hfGain, 1.0f);
790 /* Update the early reflection line lengths and gain coefficients. */
791 void EarlyReflections::updateLines(const float density_mult, const float diffusion,
792 const float decayTime, const float frequency)
794 /* Calculate the all-pass feed-back/forward coefficient. */
795 VecAp.Coeff = diffusion*diffusion * InvSqrt2;
797 for(size_t i{0u};i < NUM_LINES;i++)
799 /* Calculate the delay length of each all-pass line. */
800 float length{EARLY_ALLPASS_LENGTHS[i] * density_mult};
801 VecAp.Offset[i][1] = float2uint(length * frequency);
803 /* Calculate the delay length of each delay line. */
804 length = EARLY_LINE_LENGTHS[i] * density_mult;
805 Offset[i][1] = float2uint(length * frequency);
807 /* Calculate the gain (coefficient) for each line. */
808 Coeff[i][1] = CalcDecayCoeff(length, decayTime);
812 /* Update the EAX modulation step and depth. Keep in mind that this kind of
813 * vibrato is additive and not multiplicative as one may expect. The downswing
814 * will sound stronger than the upswing.
816 void Modulation::updateModulator(float modTime, float modDepth, float frequency)
818 /* Modulation is calculated in two parts.
820 * The modulation time effects the sinus rate, altering the speed of
821 * frequency changes. An index is incremented for each sample with an
822 * appropriate step size to generate an LFO, which will vary the feedback
823 * delay over time.
825 Step = maxu(fastf2u(MOD_FRACONE / (frequency * modTime)), 1);
827 /* The modulation depth effects the amount of frequency change over the
828 * range of the sinus. It needs to be scaled by the modulation time so that
829 * a given depth produces a consistent change in frequency over all ranges
830 * of time. Since the depth is applied to a sinus value, it needs to be
831 * halved once for the sinus range and again for the sinus swing in time
832 * (half of it is spent decreasing the frequency, half is spent increasing
833 * it).
835 if(modTime >= DefaultModulationTime)
837 /* To cancel the effects of a long period modulation on the late
838 * reverberation, the amount of pitch should be varied (decreased)
839 * according to the modulation time. The natural form is varying
840 * inversely, in fact resulting in an invariant.
842 Depth[1] = MODULATION_DEPTH_COEFF / 4.0f * DefaultModulationTime * modDepth * frequency;
844 else
845 Depth[1] = MODULATION_DEPTH_COEFF / 4.0f * modTime * modDepth * frequency;
848 /* Update the late reverb line lengths and T60 coefficients. */
849 void LateReverb::updateLines(const float density_mult, const float diffusion,
850 const float lfDecayTime, const float mfDecayTime, const float hfDecayTime,
851 const float lf0norm, const float hf0norm, const float frequency)
853 /* Scaling factor to convert the normalized reference frequencies from
854 * representing 0...freq to 0...max_reference.
856 constexpr float MaxHFReference{20000.0f};
857 const float norm_weight_factor{frequency / MaxHFReference};
859 const float late_allpass_avg{
860 std::accumulate(LATE_ALLPASS_LENGTHS.begin(), LATE_ALLPASS_LENGTHS.end(), 0.0f) /
861 float{NUM_LINES}};
863 /* To compensate for changes in modal density and decay time of the late
864 * reverb signal, the input is attenuated based on the maximal energy of
865 * the outgoing signal. This approximation is used to keep the apparent
866 * energy of the signal equal for all ranges of density and decay time.
868 * The average length of the delay lines is used to calculate the
869 * attenuation coefficient.
871 float length{std::accumulate(LATE_LINE_LENGTHS.begin(), LATE_LINE_LENGTHS.end(), 0.0f) /
872 float{NUM_LINES} + late_allpass_avg};
873 length *= density_mult;
874 /* The density gain calculation uses an average decay time weighted by
875 * approximate bandwidth. This attempts to compensate for losses of energy
876 * that reduce decay time due to scattering into highly attenuated bands.
878 const float decayTimeWeighted{
879 lf0norm*norm_weight_factor*lfDecayTime +
880 (hf0norm - lf0norm)*norm_weight_factor*mfDecayTime +
881 (1.0f - hf0norm*norm_weight_factor)*hfDecayTime};
882 DensityGain[1] = CalcDensityGain(CalcDecayCoeff(length, decayTimeWeighted));
884 /* Calculate the all-pass feed-back/forward coefficient. */
885 VecAp.Coeff = diffusion*diffusion * InvSqrt2;
887 for(size_t i{0u};i < NUM_LINES;i++)
889 /* Calculate the delay length of each all-pass line. */
890 length = LATE_ALLPASS_LENGTHS[i] * density_mult;
891 VecAp.Offset[i][1] = float2uint(length * frequency);
893 /* Calculate the delay length of each feedback delay line. */
894 length = LATE_LINE_LENGTHS[i] * density_mult;
895 Offset[i][1] = float2uint(length*frequency + 0.5f);
897 if(i == 0)
899 /* Limit the modulation depth to avoid underflowing the read offset. */
900 if(Offset[0][1] <= MAX_UPDATE_SAMPLES)
901 Mod.Depth[1] = 0.0f;
902 else
904 const auto maxdepth = static_cast<float>(Offset[0][1] - MAX_UPDATE_SAMPLES);
905 if(Mod.Depth[1] > maxdepth) Mod.Depth[1] = maxdepth;
909 /* Approximate the absorption that the vector all-pass would exhibit
910 * given the current diffusion so we don't have to process a full T60
911 * filter for each of its four lines. Also include the average
912 * modulation delay (depth is half the max delay in samples).
914 length += lerpf(LATE_ALLPASS_LENGTHS[i], late_allpass_avg, diffusion)*density_mult +
915 Mod.Depth[1]/frequency;
917 /* Calculate the T60 damping coefficients for each line. */
918 T60[i].calcCoeffs(length, lfDecayTime, mfDecayTime, hfDecayTime, lf0norm, hf0norm);
923 /* Update the offsets for the main effect delay line. */
924 void ReverbState::updateDelayLine(const float earlyDelay, const float lateDelay,
925 const float density_mult, const float decayTime, const float frequency)
927 /* Early reflection taps are decorrelated by means of an average room
928 * reflection approximation described above the definition of the taps.
929 * This approximation is linear and so the above density multiplier can
930 * be applied to adjust the width of the taps. A single-band decay
931 * coefficient is applied to simulate initial attenuation and absorption.
933 * Late reverb taps are based on the late line lengths to allow a zero-
934 * delay path and offsets that would continue the propagation naturally
935 * into the late lines.
937 for(size_t i{0u};i < NUM_LINES;i++)
939 float length{EARLY_TAP_LENGTHS[i]*density_mult};
940 mEarlyDelayTap[i][1] = float2uint((earlyDelay+length) * frequency);
941 mEarlyDelayCoeff[i][1] = CalcDecayCoeff(length, decayTime);
943 length = (LATE_LINE_LENGTHS[i] - LATE_LINE_LENGTHS.front())/float{NUM_LINES}*density_mult +
944 lateDelay;
945 mLateDelayTap[i][1] = float2uint(length * frequency);
949 /* Creates a transform matrix given a reverb vector. The vector pans the reverb
950 * reflections toward the given direction, using its magnitude (up to 1) as a
951 * focal strength. This function results in a B-Format transformation matrix
952 * that spatially focuses the signal in the desired direction.
954 std::array<std::array<float,4>,4> GetTransformFromVector(const float *vec)
956 /* Normalize the panning vector according to the N3D scale, which has an
957 * extra sqrt(3) term on the directional components. Converting from OpenAL
958 * to B-Format also requires negating X (ACN 1) and Z (ACN 3). Note however
959 * that the reverb panning vectors use left-handed coordinates, unlike the
960 * rest of OpenAL which use right-handed. This is fixed by negating Z,
961 * which cancels out with the B-Format Z negation.
963 float norm[3];
964 float mag{std::sqrt(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2])};
965 if(mag > 1.0f)
967 norm[0] = vec[0] / mag * -al::numbers::sqrt3_v<float>;
968 norm[1] = vec[1] / mag * al::numbers::sqrt3_v<float>;
969 norm[2] = vec[2] / mag * al::numbers::sqrt3_v<float>;
970 mag = 1.0f;
972 else
974 /* If the magnitude is less than or equal to 1, just apply the sqrt(3)
975 * term. There's no need to renormalize the magnitude since it would
976 * just be reapplied in the matrix.
978 norm[0] = vec[0] * -al::numbers::sqrt3_v<float>;
979 norm[1] = vec[1] * al::numbers::sqrt3_v<float>;
980 norm[2] = vec[2] * al::numbers::sqrt3_v<float>;
983 return std::array<std::array<float,4>,4>{{
984 {{1.0f, 0.0f, 0.0f, 0.0f}},
985 {{norm[0], 1.0f-mag, 0.0f, 0.0f}},
986 {{norm[1], 0.0f, 1.0f-mag, 0.0f}},
987 {{norm[2], 0.0f, 0.0f, 1.0f-mag}}
991 /* Update the early and late 3D panning gains. */
992 void ReverbState::update3DPanning(const float *ReflectionsPan, const float *LateReverbPan,
993 const float earlyGain, const float lateGain, const EffectTarget &target)
995 /* Create matrices that transform a B-Format signal according to the
996 * panning vectors.
998 const std::array<std::array<float,4>,4> earlymat{GetTransformFromVector(ReflectionsPan)};
999 const std::array<std::array<float,4>,4> latemat{GetTransformFromVector(LateReverbPan)};
1001 if(mUpmixOutput)
1003 /* When upsampling, combine the early and late transforms with the
1004 * first-order upsample matrix. This results in panning gains that
1005 * apply the panning transform to first-order B-Format, which is then
1006 * upsampled.
1008 auto mult_matrix = [](const al::span<const std::array<float,4>,4> mtx1)
1010 auto&& mtx2 = AmbiScale::FirstOrderUp;
1011 std::array<std::array<float,MaxAmbiChannels>,NUM_LINES> res{};
1013 for(size_t i{0};i < mtx1[0].size();++i)
1015 for(size_t j{0};j < mtx2[0].size();++j)
1017 double sum{0.0};
1018 for(size_t k{0};k < mtx1.size();++k)
1019 sum += double{mtx1[k][i]} * mtx2[k][j];
1020 res[i][j] = static_cast<float>(sum);
1024 return res;
1026 auto earlycoeffs = mult_matrix(earlymat);
1027 auto latecoeffs = mult_matrix(latemat);
1029 mOutTarget = target.Main->Buffer;
1030 for(size_t i{0u};i < NUM_LINES;i++)
1031 ComputePanGains(target.Main, earlycoeffs[i].data(), earlyGain, mEarly.PanGain[i]);
1032 for(size_t i{0u};i < NUM_LINES;i++)
1033 ComputePanGains(target.Main, latecoeffs[i].data(), lateGain, mLate.PanGain[i]);
1035 else
1037 /* When not upsampling, combine the early and late A-to-B-Format
1038 * conversions with their respective transform. This results panning
1039 * gains that convert A-Format to B-Format, which is then panned.
1041 auto mult_matrix = [](const al::span<const std::array<float,NUM_LINES>,4> mtx1,
1042 const al::span<const std::array<float,4>,4> mtx2)
1044 std::array<std::array<float,MaxAmbiChannels>,NUM_LINES> res{};
1046 for(size_t i{0};i < mtx1[0].size();++i)
1048 for(size_t j{0};j < mtx2.size();++j)
1050 double sum{0.0};
1051 for(size_t k{0};k < mtx1.size();++k)
1052 sum += double{mtx1[k][i]} * mtx2[j][k];
1053 res[i][j] = static_cast<float>(sum);
1057 return res;
1059 auto earlycoeffs = mult_matrix(EarlyA2B, earlymat);
1060 auto latecoeffs = mult_matrix(LateA2B, latemat);
1062 mOutTarget = target.Main->Buffer;
1063 for(size_t i{0u};i < NUM_LINES;i++)
1064 ComputePanGains(target.Main, earlycoeffs[i].data(), earlyGain, mEarly.PanGain[i]);
1065 for(size_t i{0u};i < NUM_LINES;i++)
1066 ComputePanGains(target.Main, latecoeffs[i].data(), lateGain, mLate.PanGain[i]);
1070 void ReverbState::update(const ContextBase *Context, const EffectSlot *Slot,
1071 const EffectProps *props, const EffectTarget target)
1073 const DeviceBase *Device{Context->mDevice};
1074 const auto frequency = static_cast<float>(Device->Frequency);
1076 /* Calculate the master filters */
1077 float hf0norm{minf(props->Reverb.HFReference/frequency, 0.49f)};
1078 mFilter[0].Lp.setParamsFromSlope(BiquadType::HighShelf, hf0norm, props->Reverb.GainHF, 1.0f);
1079 float lf0norm{minf(props->Reverb.LFReference/frequency, 0.49f)};
1080 mFilter[0].Hp.setParamsFromSlope(BiquadType::LowShelf, lf0norm, props->Reverb.GainLF, 1.0f);
1081 for(size_t i{1u};i < NUM_LINES;i++)
1083 mFilter[i].Lp.copyParamsFrom(mFilter[0].Lp);
1084 mFilter[i].Hp.copyParamsFrom(mFilter[0].Hp);
1087 /* The density-based room size (delay length) multiplier. */
1088 const float density_mult{CalcDelayLengthMult(props->Reverb.Density)};
1090 /* Update the main effect delay and associated taps. */
1091 updateDelayLine(props->Reverb.ReflectionsDelay, props->Reverb.LateReverbDelay,
1092 density_mult, props->Reverb.DecayTime, frequency);
1094 /* Update the early lines. */
1095 mEarly.updateLines(density_mult, props->Reverb.Diffusion, props->Reverb.DecayTime, frequency);
1097 /* Get the mixing matrix coefficients. */
1098 CalcMatrixCoeffs(props->Reverb.Diffusion, &mMixX, &mMixY);
1100 /* If the HF limit parameter is flagged, calculate an appropriate limit
1101 * based on the air absorption parameter.
1103 float hfRatio{props->Reverb.DecayHFRatio};
1104 if(props->Reverb.DecayHFLimit && props->Reverb.AirAbsorptionGainHF < 1.0f)
1105 hfRatio = CalcLimitedHfRatio(hfRatio, props->Reverb.AirAbsorptionGainHF,
1106 props->Reverb.DecayTime);
1108 /* Calculate the LF/HF decay times. */
1109 constexpr float MinDecayTime{0.1f}, MaxDecayTime{20.0f};
1110 const float lfDecayTime{clampf(props->Reverb.DecayTime*props->Reverb.DecayLFRatio,
1111 MinDecayTime, MaxDecayTime)};
1112 const float hfDecayTime{clampf(props->Reverb.DecayTime*hfRatio, MinDecayTime, MaxDecayTime)};
1114 /* Update the modulator rate and depth. */
1115 mLate.Mod.updateModulator(props->Reverb.ModulationTime, props->Reverb.ModulationDepth,
1116 frequency);
1118 /* Update the late lines. */
1119 mLate.updateLines(density_mult, props->Reverb.Diffusion, lfDecayTime,
1120 props->Reverb.DecayTime, hfDecayTime, lf0norm, hf0norm, frequency);
1122 /* Update early and late 3D panning. */
1123 const float gain{props->Reverb.Gain * Slot->Gain * ReverbBoost};
1124 update3DPanning(props->Reverb.ReflectionsPan, props->Reverb.LateReverbPan,
1125 props->Reverb.ReflectionsGain*gain, props->Reverb.LateReverbGain*gain, target);
1127 /* Determine if delay-line cross-fading is required. Density is essentially
1128 * a master control for the feedback delays, so changes the offsets of many
1129 * delay lines.
1131 mDoFading |= (mParams.Density != props->Reverb.Density ||
1132 /* Diffusion and decay times influences the decay rate (gain) of the
1133 * late reverb T60 filter.
1135 mParams.Diffusion != props->Reverb.Diffusion ||
1136 mParams.DecayTime != props->Reverb.DecayTime ||
1137 mParams.HFDecayTime != hfDecayTime ||
1138 mParams.LFDecayTime != lfDecayTime ||
1139 /* Modulation time and depth both require fading the modulation delay. */
1140 mParams.ModulationTime != props->Reverb.ModulationTime ||
1141 mParams.ModulationDepth != props->Reverb.ModulationDepth ||
1142 /* HF/LF References control the weighting used to calculate the density
1143 * gain.
1145 mParams.HFReference != props->Reverb.HFReference ||
1146 mParams.LFReference != props->Reverb.LFReference);
1147 if(mDoFading)
1149 mParams.Density = props->Reverb.Density;
1150 mParams.Diffusion = props->Reverb.Diffusion;
1151 mParams.DecayTime = props->Reverb.DecayTime;
1152 mParams.HFDecayTime = hfDecayTime;
1153 mParams.LFDecayTime = lfDecayTime;
1154 mParams.ModulationTime = props->Reverb.ModulationTime;
1155 mParams.ModulationDepth = props->Reverb.ModulationDepth;
1156 mParams.HFReference = props->Reverb.HFReference;
1157 mParams.LFReference = props->Reverb.LFReference;
1162 /**************************************
1163 * Effect Processing *
1164 **************************************/
1166 /* Applies a scattering matrix to the 4-line (vector) input. This is used
1167 * for both the below vector all-pass model and to perform modal feed-back
1168 * delay network (FDN) mixing.
1170 * The matrix is derived from a skew-symmetric matrix to form a 4D rotation
1171 * matrix with a single unitary rotational parameter:
1173 * [ d, a, b, c ] 1 = a^2 + b^2 + c^2 + d^2
1174 * [ -a, d, c, -b ]
1175 * [ -b, -c, d, a ]
1176 * [ -c, b, -a, d ]
1178 * The rotation is constructed from the effect's diffusion parameter,
1179 * yielding:
1181 * 1 = x^2 + 3 y^2
1183 * Where a, b, and c are the coefficient y with differing signs, and d is the
1184 * coefficient x. The final matrix is thus:
1186 * [ x, y, -y, y ] n = sqrt(matrix_order - 1)
1187 * [ -y, x, y, y ] t = diffusion_parameter * atan(n)
1188 * [ y, -y, x, y ] x = cos(t)
1189 * [ -y, -y, -y, x ] y = sin(t) / n
1191 * Any square orthogonal matrix with an order that is a power of two will
1192 * work (where ^T is transpose, ^-1 is inverse):
1194 * M^T = M^-1
1196 * Using that knowledge, finding an appropriate matrix can be accomplished
1197 * naively by searching all combinations of:
1199 * M = D + S - S^T
1201 * Where D is a diagonal matrix (of x), and S is a triangular matrix (of y)
1202 * whose combination of signs are being iterated.
1204 inline auto VectorPartialScatter(const std::array<float,NUM_LINES> &RESTRICT in,
1205 const float xCoeff, const float yCoeff) -> std::array<float,NUM_LINES>
1207 return std::array<float,NUM_LINES>{{
1208 xCoeff*in[0] + yCoeff*( in[1] + -in[2] + in[3]),
1209 xCoeff*in[1] + yCoeff*(-in[0] + in[2] + in[3]),
1210 xCoeff*in[2] + yCoeff*( in[0] + -in[1] + in[3]),
1211 xCoeff*in[3] + yCoeff*(-in[0] + -in[1] + -in[2] )
1215 /* Utilizes the above, but reverses the input channels. */
1216 void VectorScatterRevDelayIn(const DelayLineI delay, size_t offset, const float xCoeff,
1217 const float yCoeff, const al::span<const ReverbUpdateLine,NUM_LINES> in, const size_t count)
1219 ASSUME(count > 0);
1221 for(size_t i{0u};i < count;)
1223 offset &= delay.Mask;
1224 size_t td{minz(delay.Mask+1 - offset, count-i)};
1225 do {
1226 std::array<float,NUM_LINES> f;
1227 for(size_t j{0u};j < NUM_LINES;j++)
1228 f[NUM_LINES-1-j] = in[j][i];
1229 ++i;
1231 delay.Line[offset++] = VectorPartialScatter(f, xCoeff, yCoeff);
1232 } while(--td);
1236 /* This applies a Gerzon multiple-in/multiple-out (MIMO) vector all-pass
1237 * filter to the 4-line input.
1239 * It works by vectorizing a regular all-pass filter and replacing the delay
1240 * element with a scattering matrix (like the one above) and a diagonal
1241 * matrix of delay elements.
1243 * Two static specializations are used for transitional (cross-faded) delay
1244 * line processing and non-transitional processing.
1246 void VecAllpass::processUnfaded(const al::span<ReverbUpdateLine,NUM_LINES> samples, size_t offset,
1247 const float xCoeff, const float yCoeff, const size_t todo)
1249 const DelayLineI delay{Delay};
1250 const float feedCoeff{Coeff};
1252 ASSUME(todo > 0);
1254 size_t vap_offset[NUM_LINES];
1255 for(size_t j{0u};j < NUM_LINES;j++)
1256 vap_offset[j] = offset - Offset[j][0];
1257 for(size_t i{0u};i < todo;)
1259 for(size_t j{0u};j < NUM_LINES;j++)
1260 vap_offset[j] &= delay.Mask;
1261 offset &= delay.Mask;
1263 size_t maxoff{offset};
1264 for(size_t j{0u};j < NUM_LINES;j++)
1265 maxoff = maxz(maxoff, vap_offset[j]);
1266 size_t td{minz(delay.Mask+1 - maxoff, todo - i)};
1268 do {
1269 std::array<float,NUM_LINES> f;
1270 for(size_t j{0u};j < NUM_LINES;j++)
1272 const float input{samples[j][i]};
1273 const float out{delay.Line[vap_offset[j]++][j] - feedCoeff*input};
1274 f[j] = input + feedCoeff*out;
1276 samples[j][i] = out;
1278 ++i;
1280 delay.Line[offset++] = VectorPartialScatter(f, xCoeff, yCoeff);
1281 } while(--td);
1284 void VecAllpass::processFaded(const al::span<ReverbUpdateLine,NUM_LINES> samples, size_t offset,
1285 const float xCoeff, const float yCoeff, float fadeCount, const float fadeStep,
1286 const size_t todo)
1288 const DelayLineI delay{Delay};
1289 const float feedCoeff{Coeff};
1291 ASSUME(todo > 0);
1293 size_t vap_offset[NUM_LINES][2];
1294 for(size_t j{0u};j < NUM_LINES;j++)
1296 vap_offset[j][0] = offset - Offset[j][0];
1297 vap_offset[j][1] = offset - Offset[j][1];
1299 for(size_t i{0u};i < todo;)
1301 for(size_t j{0u};j < NUM_LINES;j++)
1303 vap_offset[j][0] &= delay.Mask;
1304 vap_offset[j][1] &= delay.Mask;
1306 offset &= delay.Mask;
1308 size_t maxoff{offset};
1309 for(size_t j{0u};j < NUM_LINES;j++)
1310 maxoff = maxz(maxoff, maxz(vap_offset[j][0], vap_offset[j][1]));
1311 size_t td{minz(delay.Mask+1 - maxoff, todo - i)};
1313 do {
1314 fadeCount += 1.0f;
1315 const float fade{fadeCount * fadeStep};
1317 std::array<float,NUM_LINES> f;
1318 for(size_t j{0u};j < NUM_LINES;j++)
1319 f[j] = delay.Line[vap_offset[j][0]++][j]*(1.0f-fade) +
1320 delay.Line[vap_offset[j][1]++][j]*fade;
1322 for(size_t j{0u};j < NUM_LINES;j++)
1324 const float input{samples[j][i]};
1325 const float out{f[j] - feedCoeff*input};
1326 f[j] = input + feedCoeff*out;
1328 samples[j][i] = out;
1330 ++i;
1332 delay.Line[offset++] = VectorPartialScatter(f, xCoeff, yCoeff);
1333 } while(--td);
1337 /* This generates early reflections.
1339 * This is done by obtaining the primary reflections (those arriving from the
1340 * same direction as the source) from the main delay line. These are
1341 * attenuated and all-pass filtered (based on the diffusion parameter).
1343 * The early lines are then fed in reverse (according to the approximately
1344 * opposite spatial location of the A-Format lines) to create the secondary
1345 * reflections (those arriving from the opposite direction as the source).
1347 * The early response is then completed by combining the primary reflections
1348 * with the delayed and attenuated output from the early lines.
1350 * Finally, the early response is reversed, scattered (based on diffusion),
1351 * and fed into the late reverb section of the main delay line.
1353 * Two static specializations are used for transitional (cross-faded) delay
1354 * line processing and non-transitional processing.
1356 void ReverbState::earlyUnfaded(size_t offset, const size_t samplesToDo)
1358 const DelayLineI early_delay{mEarly.Delay};
1359 const DelayLineI in_delay{mEarlyDelayIn};
1360 const float mixX{mMixX};
1361 const float mixY{mMixY};
1363 ASSUME(samplesToDo > 0);
1365 for(size_t base{0};base < samplesToDo;)
1367 const size_t todo{minz(samplesToDo-base, MAX_UPDATE_SAMPLES)};
1369 /* First, load decorrelated samples from the main delay line as the
1370 * primary reflections.
1372 const float fadeStep{1.0f / static_cast<float>(todo)};
1373 for(size_t j{0u};j < NUM_LINES;j++)
1375 size_t early_delay_tap0{offset - mEarlyDelayTap[j][0]};
1376 size_t early_delay_tap1{offset - mEarlyDelayTap[j][1]};
1377 const float coeff{mEarlyDelayCoeff[j][0]};
1378 const float coeffStep{early_delay_tap0 != early_delay_tap1 ? coeff*fadeStep : 0.0f};
1379 float fadeCount{0.0f};
1381 for(size_t i{0u};i < todo;)
1383 early_delay_tap0 &= in_delay.Mask;
1384 early_delay_tap1 &= in_delay.Mask;
1385 const size_t max_tap{maxz(early_delay_tap0, early_delay_tap1)};
1386 size_t td{minz(in_delay.Mask+1 - max_tap, todo-i)};
1387 do {
1388 const float fade0{coeff - coeffStep*fadeCount};
1389 const float fade1{coeffStep*fadeCount};
1390 fadeCount += 1.0f;
1391 mTempSamples[j][i++] = in_delay.Line[early_delay_tap0++][j]*fade0 +
1392 in_delay.Line[early_delay_tap1++][j]*fade1;
1393 } while(--td);
1396 mEarlyDelayTap[j][0] = mEarlyDelayTap[j][1];
1399 /* Apply a vector all-pass, to help color the initial reflections based
1400 * on the diffusion strength.
1402 mEarly.VecAp.processUnfaded(mTempSamples, offset, mixX, mixY, todo);
1404 /* Apply a delay and bounce to generate secondary reflections, combine
1405 * with the primary reflections and write out the result for mixing.
1407 for(size_t j{0u};j < NUM_LINES;j++)
1408 early_delay.write(offset, NUM_LINES-1-j, mTempSamples[j].data(), todo);
1409 for(size_t j{0u};j < NUM_LINES;j++)
1411 size_t feedb_tap{offset - mEarly.Offset[j][0]};
1412 const float feedb_coeff{mEarly.Coeff[j][0]};
1413 float *out{al::assume_aligned<16>(mEarlySamples[j].data() + base)};
1415 for(size_t i{0u};i < todo;)
1417 feedb_tap &= early_delay.Mask;
1418 size_t td{minz(early_delay.Mask+1 - feedb_tap, todo - i)};
1419 do {
1420 mTempSamples[j][i] += early_delay.Line[feedb_tap++][j]*feedb_coeff;
1421 out[i] = mTempSamples[j][i];
1422 ++i;
1423 } while(--td);
1427 /* Finally, write the result to the late delay line input for the late
1428 * reverb stage to pick up at the appropriate time, applying a scatter
1429 * and bounce to improve the initial diffusion in the late reverb.
1431 VectorScatterRevDelayIn(mLateDelayIn, offset, mixX, mixY, mTempSamples, todo);
1433 base += todo;
1434 offset += todo;
1437 void ReverbState::earlyFaded(size_t offset, const size_t samplesToDo, const float fadeStep)
1439 const DelayLineI early_delay{mEarly.Delay};
1440 const DelayLineI in_delay{mEarlyDelayIn};
1441 const float mixX{mMixX};
1442 const float mixY{mMixY};
1444 ASSUME(samplesToDo > 0);
1446 for(size_t base{0};base < samplesToDo;)
1448 const size_t todo{minz(samplesToDo-base, MAX_UPDATE_SAMPLES)};
1449 const float fade{static_cast<float>(base)};
1451 for(size_t j{0u};j < NUM_LINES;j++)
1453 size_t early_delay_tap0{offset - mEarlyDelayTap[j][0]};
1454 size_t early_delay_tap1{offset - mEarlyDelayTap[j][1]};
1455 const float oldCoeff{mEarlyDelayCoeff[j][0]};
1456 const float oldCoeffStep{-oldCoeff * fadeStep};
1457 const float newCoeffStep{mEarlyDelayCoeff[j][1] * fadeStep};
1458 float fadeCount{fade};
1460 for(size_t i{0u};i < todo;)
1462 early_delay_tap0 &= in_delay.Mask;
1463 early_delay_tap1 &= in_delay.Mask;
1464 const size_t max_tap{maxz(early_delay_tap0, early_delay_tap1)};
1465 size_t td{minz(in_delay.Mask+1 - max_tap, todo-i)};
1466 do {
1467 fadeCount += 1.0f;
1468 const float fade0{oldCoeff + oldCoeffStep*fadeCount};
1469 const float fade1{newCoeffStep*fadeCount};
1470 mTempSamples[j][i++] = in_delay.Line[early_delay_tap0++][j]*fade0 +
1471 in_delay.Line[early_delay_tap1++][j]*fade1;
1472 } while(--td);
1476 mEarly.VecAp.processFaded(mTempSamples, offset, mixX, mixY, fade, fadeStep, todo);
1478 for(size_t j{0u};j < NUM_LINES;j++)
1479 early_delay.write(offset, NUM_LINES-1-j, mTempSamples[j].data(), todo);
1480 for(size_t j{0u};j < NUM_LINES;j++)
1482 size_t feedb_tap0{offset - mEarly.Offset[j][0]};
1483 size_t feedb_tap1{offset - mEarly.Offset[j][1]};
1484 const float feedb_oldCoeff{mEarly.Coeff[j][0]};
1485 const float feedb_oldCoeffStep{-feedb_oldCoeff * fadeStep};
1486 const float feedb_newCoeffStep{mEarly.Coeff[j][1] * fadeStep};
1487 float *out{mEarlySamples[j].data() + base};
1488 float fadeCount{fade};
1490 for(size_t i{0u};i < todo;)
1492 feedb_tap0 &= early_delay.Mask;
1493 feedb_tap1 &= early_delay.Mask;
1494 size_t td{minz(early_delay.Mask+1 - maxz(feedb_tap0, feedb_tap1), todo - i)};
1496 do {
1497 fadeCount += 1.0f;
1498 const float fade0{feedb_oldCoeff + feedb_oldCoeffStep*fadeCount};
1499 const float fade1{feedb_newCoeffStep*fadeCount};
1500 mTempSamples[j][i] += early_delay.Line[feedb_tap0++][j]*fade0 +
1501 early_delay.Line[feedb_tap1++][j]*fade1;
1502 out[i] = mTempSamples[j][i];
1503 ++i;
1504 } while(--td);
1508 VectorScatterRevDelayIn(mLateDelayIn, offset, mixX, mixY, mTempSamples, todo);
1510 base += todo;
1511 offset += todo;
1516 void Modulation::calcDelays(size_t todo)
1518 constexpr float mod_scale{al::numbers::pi_v<float> * 2.0f / MOD_FRACONE};
1519 uint idx{Index};
1520 const uint step{Step};
1521 const float depth{Depth[0]};
1522 for(size_t i{0};i < todo;++i)
1524 idx += step;
1525 const float lfo{std::sin(static_cast<float>(idx&MOD_FRACMASK) * mod_scale)};
1526 ModDelays[i] = (lfo+1.0f) * depth;
1528 Index = idx;
1531 void Modulation::calcFadedDelays(size_t todo, float fadeCount, float fadeStep)
1533 constexpr float mod_scale{al::numbers::pi_v<float> * 2.0f / MOD_FRACONE};
1534 uint idx{Index};
1535 const uint step{Step};
1536 const float depth{Depth[0]};
1537 const float depthStep{(Depth[1]-depth) * fadeStep};
1538 for(size_t i{0};i < todo;++i)
1540 fadeCount += 1.0f;
1541 idx += step;
1542 const float lfo{std::sin(static_cast<float>(idx&MOD_FRACMASK) * mod_scale)};
1543 ModDelays[i] = (lfo+1.0f) * (depth + depthStep*fadeCount);
1545 Index = idx;
1549 /* This generates the reverb tail using a modified feed-back delay network
1550 * (FDN).
1552 * Results from the early reflections are mixed with the output from the
1553 * modulated late delay lines.
1555 * The late response is then completed by T60 and all-pass filtering the mix.
1557 * Finally, the lines are reversed (so they feed their opposite directions)
1558 * and scattered with the FDN matrix before re-feeding the delay lines.
1560 * Two variations are made, one for for transitional (cross-faded) delay line
1561 * processing and one for non-transitional processing.
1563 void ReverbState::lateUnfaded(size_t offset, const size_t samplesToDo)
1565 const DelayLineI late_delay{mLate.Delay};
1566 const DelayLineI in_delay{mLateDelayIn};
1567 const float mixX{mMixX};
1568 const float mixY{mMixY};
1570 ASSUME(samplesToDo > 0);
1572 for(size_t base{0};base < samplesToDo;)
1574 const size_t todo{minz(samplesToDo-base, minz(mLate.Offset[0][0], MAX_UPDATE_SAMPLES))};
1575 ASSUME(todo > 0);
1577 /* First, calculate the modulated delays for the late feedback. */
1578 mLate.Mod.calcDelays(todo);
1580 /* Next, load decorrelated samples from the main and feedback delay
1581 * lines. Filter the signal to apply its frequency-dependent decay.
1583 const float fadeStep{1.0f / static_cast<float>(todo)};
1584 for(size_t j{0u};j < NUM_LINES;j++)
1586 size_t late_delay_tap0{offset - mLateDelayTap[j][0]};
1587 size_t late_delay_tap1{offset - mLateDelayTap[j][1]};
1588 size_t late_feedb_tap{offset - mLate.Offset[j][0]};
1589 const float midGain{mLate.T60[j].MidGain[0]};
1590 const float densityGain{mLate.DensityGain[0] * midGain};
1591 const float densityStep{late_delay_tap0 != late_delay_tap1 ?
1592 densityGain*fadeStep : 0.0f};
1593 float fadeCount{0.0f};
1595 for(size_t i{0u};i < todo;)
1597 late_delay_tap0 &= in_delay.Mask;
1598 late_delay_tap1 &= in_delay.Mask;
1599 size_t td{minz(todo-i, in_delay.Mask+1 - maxz(late_delay_tap0, late_delay_tap1))};
1600 do {
1601 /* Calculate the read offset and fraction between it and
1602 * the next sample.
1604 const float fdelay{mLate.Mod.ModDelays[i]};
1605 const size_t delay{float2uint(fdelay)};
1606 const float frac{fdelay - static_cast<float>(delay)};
1608 /* Get the two samples crossed by the delayed offset. */
1609 const float out0{late_delay.Line[(late_feedb_tap-delay) & late_delay.Mask][j]};
1610 const float out1{late_delay.Line[(late_feedb_tap-delay-1) & late_delay.Mask][j]};
1611 ++late_feedb_tap;
1613 /* The output is obtained by linearly interpolating the two
1614 * samples that were acquired above, and combined with the
1615 * main delay tap.
1617 const float fade0{densityGain - densityStep*fadeCount};
1618 const float fade1{densityStep*fadeCount};
1619 fadeCount += 1.0f;
1620 mTempSamples[j][i] = lerpf(out0, out1, frac)*midGain +
1621 in_delay.Line[late_delay_tap0++][j]*fade0 +
1622 in_delay.Line[late_delay_tap1++][j]*fade1;
1623 ++i;
1624 } while(--td);
1626 mLateDelayTap[j][0] = mLateDelayTap[j][1];
1628 mLate.T60[j].process({mTempSamples[j].data(), todo});
1631 /* Apply a vector all-pass to improve micro-surface diffusion, and
1632 * write out the results for mixing.
1634 mLate.VecAp.processUnfaded(mTempSamples, offset, mixX, mixY, todo);
1635 for(size_t j{0u};j < NUM_LINES;j++)
1636 std::copy_n(mTempSamples[j].begin(), todo, mLateSamples[j].begin()+base);
1638 /* Finally, scatter and bounce the results to refeed the feedback buffer. */
1639 VectorScatterRevDelayIn(late_delay, offset, mixX, mixY, mTempSamples, todo);
1641 base += todo;
1642 offset += todo;
1645 void ReverbState::lateFaded(size_t offset, const size_t samplesToDo, const float fadeStep)
1647 const DelayLineI late_delay{mLate.Delay};
1648 const DelayLineI in_delay{mLateDelayIn};
1649 const float mixX{mMixX};
1650 const float mixY{mMixY};
1652 ASSUME(samplesToDo > 0);
1654 for(size_t base{0};base < samplesToDo;)
1656 const size_t min_offset{mLate.Offset[0][0] ? minz(mLate.Offset[0][0], mLate.Offset[0][1])
1657 : mLate.Offset[0][1]};
1658 const size_t todo{minz(minz(samplesToDo-base, min_offset), MAX_UPDATE_SAMPLES)};
1659 ASSUME(todo > 0);
1661 const float fade{static_cast<float>(base)};
1663 mLate.Mod.calcFadedDelays(todo, fade, fadeStep);
1665 for(size_t j{0u};j < NUM_LINES;j++)
1667 const float oldMidGain{mLate.T60[j].MidGain[0]};
1668 const float midGain{mLate.T60[j].MidGain[1]};
1669 const float oldMidStep{-oldMidGain * fadeStep};
1670 const float midStep{midGain * fadeStep};
1671 const float oldDensityGain{mLate.DensityGain[0] * oldMidGain};
1672 const float densityGain{mLate.DensityGain[1] * midGain};
1673 const float oldDensityStep{-oldDensityGain * fadeStep};
1674 const float densityStep{densityGain * fadeStep};
1675 size_t late_delay_tap0{offset - mLateDelayTap[j][0]};
1676 size_t late_delay_tap1{offset - mLateDelayTap[j][1]};
1677 size_t late_feedb_tap0{offset - mLate.Offset[j][0]};
1678 size_t late_feedb_tap1{offset - mLate.Offset[j][1]};
1679 float fadeCount{fade};
1681 for(size_t i{0u};i < todo;)
1683 late_delay_tap0 &= in_delay.Mask;
1684 late_delay_tap1 &= in_delay.Mask;
1685 size_t td{minz(todo-i, in_delay.Mask+1 - maxz(late_delay_tap0, late_delay_tap1))};
1686 do {
1687 fadeCount += 1.0f;
1689 const float fdelay{mLate.Mod.ModDelays[i]};
1690 const size_t delay{float2uint(fdelay)};
1691 const float frac{fdelay - static_cast<float>(delay)};
1693 const size_t late_mask{late_delay.Mask};
1694 const float out00{late_delay.Line[(late_feedb_tap0-delay) & late_mask][j]};
1695 const float out01{late_delay.Line[(late_feedb_tap0-delay-1) & late_mask][j]};
1696 ++late_feedb_tap0;
1697 const float out10{late_delay.Line[(late_feedb_tap1-delay) & late_mask][j]};
1698 const float out11{late_delay.Line[(late_feedb_tap1-delay-1) & late_mask][j]};
1699 ++late_feedb_tap1;
1701 const float fade0{oldDensityGain + oldDensityStep*fadeCount};
1702 const float fade1{densityStep*fadeCount};
1703 const float gfade0{oldMidGain + oldMidStep*fadeCount};
1704 const float gfade1{midStep*fadeCount};
1705 mTempSamples[j][i] = lerpf(out00, out01, frac)*gfade0 +
1706 lerpf(out10, out11, frac)*gfade1 +
1707 in_delay.Line[late_delay_tap0++][j]*fade0 +
1708 in_delay.Line[late_delay_tap1++][j]*fade1;
1709 ++i;
1710 } while(--td);
1712 mLate.T60[j].process({mTempSamples[j].data(), todo});
1715 mLate.VecAp.processFaded(mTempSamples, offset, mixX, mixY, fade, fadeStep, todo);
1716 for(size_t j{0u};j < NUM_LINES;j++)
1717 std::copy_n(mTempSamples[j].begin(), todo, mLateSamples[j].begin()+base);
1719 VectorScatterRevDelayIn(late_delay, offset, mixX, mixY, mTempSamples, todo);
1721 base += todo;
1722 offset += todo;
1726 void ReverbState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut)
1728 size_t offset{mOffset};
1730 ASSUME(samplesToDo > 0);
1732 /* Convert B-Format to A-Format for processing. */
1733 const size_t numInput{minz(samplesIn.size(), NUM_LINES)};
1734 const al::span<float> tmpspan{al::assume_aligned<16>(mTempLine.data()), samplesToDo};
1735 for(size_t c{0u};c < NUM_LINES;c++)
1737 std::fill(tmpspan.begin(), tmpspan.end(), 0.0f);
1738 for(size_t i{0};i < numInput;++i)
1740 const float gain{B2A[c][i]};
1741 const float *RESTRICT input{al::assume_aligned<16>(samplesIn[i].data())};
1743 for(float &sample : tmpspan)
1745 sample += *input * gain;
1746 ++input;
1750 /* Band-pass the incoming samples and feed the initial delay line. */
1751 DualBiquad{mFilter[c].Lp, mFilter[c].Hp}.process(tmpspan, tmpspan.data());
1752 mEarlyDelayIn.write(offset, c, tmpspan.cbegin(), samplesToDo);
1755 /* Process reverb for these samples. */
1756 if LIKELY(!mDoFading)
1758 /* Generate non-faded early reflections and late reverb. */
1759 earlyUnfaded(offset, samplesToDo);
1760 lateUnfaded(offset, samplesToDo);
1762 /* Finally, mix early reflections and late reverb. */
1763 mixOut(samplesOut, samplesToDo);
1765 else
1767 const float fadeStep{1.0f / static_cast<float>(samplesToDo)};
1769 /* Generate cross-faded early reflections and late reverb. */
1770 earlyFaded(offset, samplesToDo, fadeStep);
1771 lateFaded(offset, samplesToDo, fadeStep);
1773 mixOut(samplesOut, samplesToDo);
1776 /* Update the cross-fading delay line taps. */
1777 for(size_t c{0u};c < NUM_LINES;c++)
1779 mEarlyDelayTap[c][0] = mEarlyDelayTap[c][1];
1780 mEarlyDelayCoeff[c][0] = mEarlyDelayCoeff[c][1];
1781 mLateDelayTap[c][0] = mLateDelayTap[c][1];
1782 mEarly.VecAp.Offset[c][0] = mEarly.VecAp.Offset[c][1];
1783 mEarly.Offset[c][0] = mEarly.Offset[c][1];
1784 mEarly.Coeff[c][0] = mEarly.Coeff[c][1];
1785 mLate.Offset[c][0] = mLate.Offset[c][1];
1786 mLate.T60[c].MidGain[0] = mLate.T60[c].MidGain[1];
1787 mLate.VecAp.Offset[c][0] = mLate.VecAp.Offset[c][1];
1789 mLate.DensityGain[0] = mLate.DensityGain[1];
1790 mLate.Mod.Depth[0] = mLate.Mod.Depth[1];
1791 mDoFading = false;
1793 mOffset += samplesToDo;
1797 struct ReverbStateFactory final : public EffectStateFactory {
1798 al::intrusive_ptr<EffectState> create() override
1799 { return al::intrusive_ptr<EffectState>{new ReverbState{}}; }
1802 struct StdReverbStateFactory final : public EffectStateFactory {
1803 al::intrusive_ptr<EffectState> create() override
1804 { return al::intrusive_ptr<EffectState>{new ReverbState{}}; }
1807 } // namespace
1809 EffectStateFactory *ReverbStateFactory_getFactory()
1811 static ReverbStateFactory ReverbFactory{};
1812 return &ReverbFactory;
1815 EffectStateFactory *StdReverbStateFactory_getFactory()
1817 static StdReverbStateFactory ReverbFactory{};
1818 return &ReverbFactory;