Remove some unnecessary enums
[openal-soft.git] / alc / effects / reverb.cpp
blob11541285ed5b15dedbd95b9da3ca6888d1935e58
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 <cassert>
26 #include <cmath>
27 #include <cstdint>
28 #include <cstdio>
29 #include <functional>
30 #include <numeric>
31 #include <utility>
32 #include <variant>
34 #include "alc/effects/base.h"
35 #include "alnumbers.h"
36 #include "alnumeric.h"
37 #include "alspan.h"
38 #include "core/ambidefs.h"
39 #include "core/bufferline.h"
40 #include "core/context.h"
41 #include "core/cubic_tables.h"
42 #include "core/device.h"
43 #include "core/effects/base.h"
44 #include "core/effectslot.h"
45 #include "core/filters/biquad.h"
46 #include "core/filters/splitter.h"
47 #include "core/mixer.h"
48 #include "core/mixer/defs.h"
49 #include "intrusive_ptr.h"
50 #include "opthelpers.h"
51 #include "vector.h"
53 struct BufferStorage;
55 namespace {
57 using uint = unsigned int;
59 constexpr float MaxModulationTime{4.0f};
60 constexpr float DefaultModulationTime{0.25f};
62 #define MOD_FRACBITS 24
63 #define MOD_FRACONE (1<<MOD_FRACBITS)
64 #define MOD_FRACMASK (MOD_FRACONE-1)
67 /* Max samples per process iteration. Used to limit the size needed for
68 * temporary buffers. Must be a multiple of 4 for SIMD alignment.
70 constexpr size_t MAX_UPDATE_SAMPLES{256};
72 /* The number of spatialized lines or channels to process. Four channels allows
73 * for a 3D A-Format response. NOTE: This can't be changed without taking care
74 * of the conversion matrices, and a few places where the length arrays are
75 * assumed to have 4 elements.
77 constexpr size_t NUM_LINES{4u};
80 /* This coefficient is used to define the maximum frequency range controlled by
81 * the modulation depth. The current value of 0.05 will allow it to swing from
82 * 0.95x to 1.05x. This value must be below 1. At 1 it will cause the sampler
83 * to stall on the downswing, and above 1 it will cause it to sample backwards.
84 * The value 0.05 seems be nearest to Creative hardware behavior.
86 constexpr float MODULATION_DEPTH_COEFF{0.05f};
89 /* The B-Format to (W-normalized) A-Format conversion matrix. This produces a
90 * tetrahedral array of discrete signals (boosted by a factor of sqrt(3), to
91 * reduce the error introduced in the conversion).
93 alignas(16) constexpr std::array<std::array<float,NUM_LINES>,NUM_LINES> B2A{{
94 /* W Y Z X */
95 {{ 0.5f, 0.5f, 0.5f, 0.5f }}, /* A0 */
96 {{ 0.5f, -0.5f, -0.5f, 0.5f }}, /* A1 */
97 {{ 0.5f, 0.5f, -0.5f, -0.5f }}, /* A2 */
98 {{ 0.5f, -0.5f, 0.5f, -0.5f }} /* A3 */
99 }};
101 /* Converts (W-normalized) A-Format to B-Format for early reflections (scaled
102 * by 1/sqrt(3) to compensate for the boost in the B2A matrix).
104 alignas(16) constexpr std::array<std::array<float,NUM_LINES>,NUM_LINES> EarlyA2B{{
105 /* A0 A1 A2 A3 */
106 {{ 0.5f, 0.5f, 0.5f, 0.5f }}, /* W */
107 {{ 0.5f, -0.5f, 0.5f, -0.5f }}, /* Y */
108 {{ 0.5f, -0.5f, -0.5f, 0.5f }}, /* Z */
109 {{ 0.5f, 0.5f, -0.5f, -0.5f }} /* X */
112 /* Converts (W-normalized) A-Format to B-Format for late reverb (scaled
113 * by 1/sqrt(3) to compensate for the boost in the B2A matrix). The response
114 * is rotated around Z (ambisonic X) so that the front lines are placed
115 * horizontally in front, and the rear lines are placed vertically in back.
117 constexpr auto InvSqrt2 = static_cast<float>(1.0/al::numbers::sqrt2);
118 alignas(16) constexpr std::array<std::array<float,NUM_LINES>,NUM_LINES> LateA2B{{
119 /* A0 A1 A2 A3 */
120 {{ 0.5f, 0.5f, 0.5f, 0.5f }}, /* W */
121 {{ InvSqrt2, -InvSqrt2, 0.0f, 0.0f }}, /* Y */
122 {{ 0.0f, 0.0f, -InvSqrt2, InvSqrt2 }}, /* Z */
123 {{ 0.5f, 0.5f, -0.5f, -0.5f }} /* X */
126 /* The all-pass and delay lines have a variable length dependent on the
127 * effect's density parameter, which helps alter the perceived environment
128 * size. The size-to-density conversion is a cubed scale:
130 * density = min(1.0, pow(size, 3.0) / DENSITY_SCALE);
132 * The line lengths scale linearly with room size, so the inverse density
133 * conversion is needed, taking the cube root of the re-scaled density to
134 * calculate the line length multiplier:
136 * length_mult = max(5.0, cbrt(density*DENSITY_SCALE));
138 * The density scale below will result in a max line multiplier of 50, for an
139 * effective size range of 5m to 50m.
141 constexpr float DENSITY_SCALE{125000.0f};
143 /* All delay line lengths are specified in seconds.
145 * To approximate early reflections, we break them up into primary (those
146 * arriving from the same direction as the source) and secondary (those
147 * arriving from the opposite direction).
149 * The early taps decorrelate the 4-channel signal to approximate an average
150 * room response for the primary reflections after the initial early delay.
152 * Given an average room dimension (d_a) and the speed of sound (c) we can
153 * calculate the average reflection delay (r_a) regardless of listener and
154 * source positions as:
156 * r_a = d_a / c
157 * c = 343.3
159 * This can extended to finding the average difference (r_d) between the
160 * maximum (r_1) and minimum (r_0) reflection delays:
162 * r_0 = 2 / 3 r_a
163 * = r_a - r_d / 2
164 * = r_d
165 * r_1 = 4 / 3 r_a
166 * = r_a + r_d / 2
167 * = 2 r_d
168 * r_d = 2 / 3 r_a
169 * = r_1 - r_0
171 * As can be determined by integrating the 1D model with a source (s) and
172 * listener (l) positioned across the dimension of length (d_a):
174 * r_d = int_(l=0)^d_a (int_(s=0)^d_a |2 d_a - 2 (l + s)| ds) dl / c
176 * The initial taps (T_(i=0)^N) are then specified by taking a power series
177 * that ranges between r_0 and half of r_1 less r_0:
179 * R_i = 2^(i / (2 N - 1)) r_d
180 * = r_0 + (2^(i / (2 N - 1)) - 1) r_d
181 * = r_0 + T_i
182 * T_i = R_i - r_0
183 * = (2^(i / (2 N - 1)) - 1) r_d
185 * Assuming an average of 1m, we get the following taps:
187 constexpr std::array<float,NUM_LINES> EARLY_TAP_LENGTHS{{
188 0.0000000e+0f, 2.0213520e-4f, 4.2531060e-4f, 6.7171600e-4f
191 /* The early all-pass filter lengths are based on the early tap lengths:
193 * A_i = R_i / a
195 * Where a is the approximate maximum all-pass cycle limit (20).
197 constexpr std::array<float,NUM_LINES> EARLY_ALLPASS_LENGTHS{{
198 9.7096800e-5f, 1.0720356e-4f, 1.1836234e-4f, 1.3068260e-4f
201 /* The early delay lines are used to transform the primary reflections into
202 * the secondary reflections. The A-format is arranged in such a way that
203 * the channels/lines are spatially opposite:
205 * C_i is opposite C_(N-i-1)
207 * The delays of the two opposing reflections (R_i and O_i) from a source
208 * anywhere along a particular dimension always sum to twice its full delay:
210 * 2 r_a = R_i + O_i
212 * With that in mind we can determine the delay between the two reflections
213 * and thus specify our early line lengths (L_(i=0)^N) using:
215 * O_i = 2 r_a - R_(N-i-1)
216 * L_i = O_i - R_(N-i-1)
217 * = 2 (r_a - R_(N-i-1))
218 * = 2 (r_a - T_(N-i-1) - r_0)
219 * = 2 r_a (1 - (2 / 3) 2^((N - i - 1) / (2 N - 1)))
221 * Using an average dimension of 1m, we get:
223 constexpr std::array<float,NUM_LINES> EARLY_LINE_LENGTHS{{
224 0.0000000e+0f, 4.9281100e-4f, 9.3916180e-4f, 1.3434322e-3f
227 /* The late all-pass filter lengths are based on the late line lengths:
229 * A_i = (5 / 3) L_i / r_1
231 constexpr std::array<float,NUM_LINES> LATE_ALLPASS_LENGTHS{{
232 1.6182800e-4f, 2.0389060e-4f, 2.8159360e-4f, 3.2365600e-4f
235 /* The late lines are used to approximate the decaying cycle of recursive
236 * late reflections.
238 * Splitting the lines in half, we start with the shortest reflection paths
239 * (L_(i=0)^(N/2)):
241 * L_i = 2^(i / (N - 1)) r_d
243 * Then for the opposite (longest) reflection paths (L_(i=N/2)^N):
245 * L_i = 2 r_a - L_(i-N/2)
246 * = 2 r_a - 2^((i - N / 2) / (N - 1)) r_d
248 * For our 1m average room, we get:
250 constexpr std::array<float,NUM_LINES> LATE_LINE_LENGTHS{{
251 1.9419362e-3f, 2.4466860e-3f, 3.3791220e-3f, 3.8838720e-3f
255 using ReverbUpdateLine = std::array<float,MAX_UPDATE_SAMPLES>;
257 struct DelayLineI {
258 /* The delay lines use interleaved samples, with the lengths being powers
259 * of 2 to allow the use of bit-masking instead of a modulus for wrapping.
261 al::span<float> mLine;
263 /* Given the allocated sample buffer, this function updates each delay line
264 * offset.
266 void realizeLineOffset(al::span<float> sampleBuffer) noexcept
267 { mLine = sampleBuffer; }
269 /* Calculate the length of a delay line and store its mask and offset. */
270 static
271 auto calcLineLength(const float length, const float frequency, const uint extra) -> size_t
273 /* All line lengths are powers of 2, calculated from their lengths in
274 * seconds, rounded up.
276 uint samples{float2uint(std::ceil(length*frequency))};
277 samples = NextPowerOf2(samples + extra);
279 /* Return the sample count for accumulation. */
280 return samples*NUM_LINES;
284 struct DelayLineU {
285 al::span<float> mLine;
287 void realizeLineOffset(al::span<float> sampleBuffer) noexcept
289 assert(sampleBuffer.size() > 4 && !(sampleBuffer.size() & (sampleBuffer.size()-1)));
290 mLine = sampleBuffer;
293 static
294 auto calcLineLength(const float length, const float frequency, const uint extra) -> size_t
296 uint samples{float2uint(std::ceil(length*frequency))};
297 samples = NextPowerOf2(samples + extra);
299 return samples*NUM_LINES;
302 [[nodiscard]]
303 auto get(size_t chan) const noexcept
305 const size_t stride{mLine.size() / NUM_LINES};
306 return mLine.subspan(chan*stride, stride);
309 void write(size_t offset, const size_t c, al::span<const float> in) const noexcept
311 const size_t stride{mLine.size() / NUM_LINES};
312 const auto output = mLine.subspan(c*stride);
313 while(!in.empty())
315 offset &= stride-1;
316 const size_t td{std::min(stride - offset, in.size())};
317 std::copy_n(in.begin(), td, output.begin() + ptrdiff_t(offset));
318 offset += td;
319 in = in.subspan(td);
323 /* Writes the given input lines to the delay buffer, applying a geometric
324 * reflection. This effectively applies the matrix
326 * [ +1/2 -1/2 -1/2 -1/2 ]
327 * [ -1/2 +1/2 -1/2 -1/2 ]
328 * [ -1/2 -1/2 +1/2 -1/2 ]
329 * [ -1/2 -1/2 -1/2 +1/2 ]
331 * to the four input lines when writing to the delay buffer. The effect on
332 * the B-Format signal is negating W, applying a 180-degree phase shift and
333 * moving each response to its spatially opposite location.
335 void writeReflected(size_t offset, const al::span<const ReverbUpdateLine,NUM_LINES> in,
336 const size_t count) const noexcept
338 const size_t stride{mLine.size() / NUM_LINES};
339 for(size_t i{0u};i < count;)
341 offset &= stride-1;
342 size_t td{std::min(stride - offset, count - i)};
343 do {
344 const std::array src{in[0][i], in[1][i], in[2][i], in[3][i]};
345 ++i;
347 const std::array f{
348 (src[0] - src[1] - src[2] - src[3]) * 0.5f,
349 (src[1] - src[0] - src[2] - src[3]) * 0.5f,
350 (src[2] - src[0] - src[1] - src[3]) * 0.5f,
351 (src[3] - src[0] - src[1] - src[2] ) * 0.5f
353 mLine[0*stride + offset] = f[0];
354 mLine[1*stride + offset] = f[1];
355 mLine[2*stride + offset] = f[2];
356 mLine[3*stride + offset] = f[3];
357 ++offset;
358 } while(--td);
363 struct VecAllpass {
364 DelayLineI Delay;
365 float Coeff{0.0f};
366 std::array<size_t,NUM_LINES> Offset{};
368 void process(const al::span<ReverbUpdateLine,NUM_LINES> samples, size_t offset,
369 const float xCoeff, const float yCoeff, const size_t todo) const noexcept;
372 struct Allpass4 {
373 DelayLineU Delay;
374 float Coeff{0.0f};
375 std::array<size_t,NUM_LINES> Offset{};
377 void process(const al::span<ReverbUpdateLine,NUM_LINES> samples, const size_t offset,
378 const size_t todo) const noexcept;
381 struct T60Filter {
382 /* Two filters are used to adjust the signal. One to control the low
383 * frequencies, and one to control the high frequencies.
385 float MidGain{0.0f};
386 BiquadFilter HFFilter, LFFilter;
388 void calcCoeffs(const float length, const float lfDecayTime, const float mfDecayTime,
389 const float hfDecayTime, const float lf0norm, const float hf0norm);
391 /* Applies the two T60 damping filter sections. */
392 void process(const al::span<float> samples)
393 { DualBiquad{HFFilter, LFFilter}.process(samples, samples); }
395 void clear() noexcept { HFFilter.clear(); LFFilter.clear(); }
398 struct EarlyReflections {
399 Allpass4 VecAp;
401 /* An echo line is used to complete the second half of the early
402 * reflections.
404 DelayLineU Delay;
405 std::array<size_t,NUM_LINES> Offset{};
406 std::array<float,NUM_LINES> Coeff{};
408 /* The gain for each output channel based on 3D panning. */
409 struct OutGains {
410 std::array<float,MaxAmbiChannels> Current{};
411 std::array<float,MaxAmbiChannels> Target{};
413 void clear() { Current.fill(0.0f); Target.fill(0.0); }
415 std::array<OutGains,NUM_LINES> Gains{};
417 void updateLines(const float density_mult, const float diffusion, const float decayTime,
418 const float frequency);
420 void clear()
422 std::for_each(Gains.begin(), Gains.end(), std::mem_fn(&OutGains::clear));
427 struct Modulation {
428 /* The vibrato time is tracked with an index over a (MOD_FRACONE)
429 * normalized range.
431 uint Index{0u}, Step{1u};
433 /* The depth of frequency change, in samples. */
434 float Depth{0.0f};
436 std::array<uint,MAX_UPDATE_SAMPLES> ModDelays{};
438 void updateModulator(float modTime, float modDepth, float frequency);
440 auto calcDelays(size_t todo) -> al::span<const uint>;
442 void clear() noexcept
444 Index = 0u;
445 Step = 1u;
446 Depth = 0.0f;
450 struct LateReverb {
451 /* A recursive delay line is used fill in the reverb tail. */
452 DelayLineU Delay;
453 std::array<size_t,NUM_LINES> Offset{};
455 /* Attenuation to compensate for the modal density and decay rate of the
456 * late lines.
458 float DensityGain{0.0f};
460 /* T60 decay filters are used to simulate absorption. */
461 std::array<T60Filter,NUM_LINES> T60;
463 Modulation Mod;
465 /* A Gerzon vector all-pass filter is used to simulate diffusion. */
466 VecAllpass VecAp;
468 /* The gain for each output channel based on 3D panning. */
469 struct OutGains {
470 std::array<float,MaxAmbiChannels> Current{};
471 std::array<float,MaxAmbiChannels> Target{};
473 void clear() { Current.fill(0.0f); Target.fill(0.0); }
475 std::array<OutGains,NUM_LINES> Gains{};
477 void updateLines(const float density_mult, const float diffusion, const float lfDecayTime,
478 const float mfDecayTime, const float hfDecayTime, const float lf0norm,
479 const float hf0norm, const float frequency);
481 void clear()
483 std::for_each(T60.begin(), T60.end(), std::mem_fn(&T60Filter::clear));
484 Mod.clear();
485 std::for_each(Gains.begin(), Gains.end(), std::mem_fn(&OutGains::clear));
489 struct ReverbPipeline {
490 /* Master effect filters */
491 struct FilterPair {
492 BiquadFilter Lp;
493 BiquadFilter Hp;
494 void clear() noexcept { Lp.clear(); Hp.clear(); }
496 std::array<FilterPair,NUM_LINES> mFilter;
498 /* Late reverb input delay line (early reflections feed this, and late
499 * reverb taps from it).
501 DelayLineU mLateDelayIn;
503 /* Tap points for early reflection input delay. */
504 std::array<std::array<size_t,2>,NUM_LINES> mEarlyDelayTap{};
505 std::array<std::array<float,2>,NUM_LINES> mEarlyDelayCoeff{};
507 /* Tap points for late reverb feed and delay. */
508 std::array<std::array<size_t,2>,NUM_LINES> mLateDelayTap{};
510 /* Coefficients for the all-pass and line scattering matrices. */
511 float mMixX{1.0f};
512 float mMixY{0.0f};
514 EarlyReflections mEarly;
516 LateReverb mLate;
518 std::array<std::array<BandSplitter,NUM_LINES>,2> mAmbiSplitter;
520 size_t mFadeSampleCount{1};
522 void updateDelayLine(const float gain, const float earlyDelay, const float lateDelay,
523 const float density_mult, const float decayTime, const float frequency);
524 void update3DPanning(const al::span<const float,3> ReflectionsPan,
525 const al::span<const float,3> LateReverbPan, const float earlyGain, const float lateGain,
526 const bool doUpmix, const MixParams *mainMix);
528 void processEarly(const DelayLineU &main_delay, size_t offset, const size_t samplesToDo,
529 const al::span<ReverbUpdateLine,NUM_LINES> tempSamples,
530 const al::span<FloatBufferLine,NUM_LINES> outSamples);
531 void processLate(size_t offset, const size_t samplesToDo,
532 const al::span<ReverbUpdateLine,NUM_LINES> tempSamples,
533 const al::span<FloatBufferLine,NUM_LINES> outSamples);
535 void clear() noexcept
537 std::for_each(mFilter.begin(), mFilter.end(), std::mem_fn(&FilterPair::clear));
538 mEarlyDelayTap = {};
539 mEarlyDelayCoeff = {};
540 mLateDelayTap = {};
541 mEarly.clear();
542 mLate.clear();
543 auto clear_filters = [](const al::span<BandSplitter,NUM_LINES> filters)
544 { std::for_each(filters.begin(), filters.end(), std::mem_fn(&BandSplitter::clear)); };
545 std::for_each(mAmbiSplitter.begin(), mAmbiSplitter.end(), clear_filters);
549 struct ReverbState final : public EffectState {
550 /* All delay lines are allocated as a single buffer to reduce memory
551 * fragmentation and management code.
553 al::vector<float,16> mSampleBuffer;
555 struct Params {
556 /* Calculated parameters which indicate if cross-fading is needed after
557 * an update.
559 float Density{1.0f};
560 float Diffusion{1.0f};
561 float DecayTime{1.49f};
562 float HFDecayTime{0.83f * 1.49f};
563 float LFDecayTime{1.0f * 1.49f};
564 float ModulationTime{0.25f};
565 float ModulationDepth{0.0f};
566 float HFReference{5000.0f};
567 float LFReference{250.0f};
569 Params mParams;
571 enum PipelineState : uint8_t {
572 DeviceClear,
573 StartFade,
574 Fading,
575 Cleanup,
576 Normal,
578 PipelineState mPipelineState{DeviceClear};
579 bool mCurrentPipeline{false};
581 /* Core delay line (early reflections tap from this). */
582 DelayLineU mMainDelay;
584 std::array<ReverbPipeline,2> mPipelines;
586 /* The current write offset for all delay lines. */
587 size_t mOffset{};
589 /* Temporary storage used when processing. */
590 alignas(16) FloatBufferLine mTempLine{};
591 alignas(16) std::array<ReverbUpdateLine,NUM_LINES> mTempSamples{};
593 alignas(16) std::array<FloatBufferLine,NUM_LINES> mEarlySamples{};
594 alignas(16) std::array<FloatBufferLine,NUM_LINES> mLateSamples{};
596 std::array<float,MaxAmbiOrder+1> mOrderScales{};
598 bool mUpmixOutput{false};
601 void MixOutPlain(ReverbPipeline &pipeline, const al::span<FloatBufferLine> samplesOut,
602 const size_t todo) const
604 /* When not upsampling, the panning gains convert to B-Format and pan
605 * at the same time.
607 auto inBuffer = mEarlySamples.cbegin();
608 for(auto &gains : pipeline.mEarly.Gains)
610 MixSamples(al::span{*inBuffer++}.first(todo), samplesOut, gains.Current, gains.Target,
611 todo, 0);
613 inBuffer = mLateSamples.cbegin();
614 for(auto &gains : pipeline.mLate.Gains)
616 MixSamples(al::span{*inBuffer++}.first(todo), samplesOut, gains.Current, gains.Target,
617 todo, 0);
621 void MixOutAmbiUp(ReverbPipeline &pipeline, const al::span<FloatBufferLine> samplesOut,
622 const size_t todo)
624 auto DoMixRow = [](const al::span<float> OutBuffer, const al::span<const float,4> Gains,
625 const al::span<const FloatBufferLine,4> InSamples)
627 auto inBuffer = InSamples.cbegin();
628 std::fill(OutBuffer.begin(), OutBuffer.end(), 0.0f);
629 for(const float gain : Gains)
631 if(std::fabs(gain) > GainSilenceThreshold)
633 auto mix_sample = [gain](const float sample, const float in) noexcept -> float
634 { return sample + in*gain; };
635 std::transform(OutBuffer.begin(), OutBuffer.end(), inBuffer->cbegin(),
636 OutBuffer.begin(), mix_sample);
638 ++inBuffer;
642 /* When upsampling, the B-Format conversion needs to be done separately
643 * so the proper HF scaling can be applied to each B-Format channel.
644 * The panning gains then pan and upsample the B-Format channels.
646 const auto tmpspan = al::span{mTempLine}.first(todo);
647 auto hfscale = float{mOrderScales[0]};
648 auto splitter = pipeline.mAmbiSplitter[0].begin();
649 auto a2bcoeffs = EarlyA2B.cbegin();
650 for(auto &gains : pipeline.mEarly.Gains)
652 DoMixRow(tmpspan, *(a2bcoeffs++), mEarlySamples);
654 /* Apply scaling to the B-Format's HF response to "upsample" it to
655 * higher-order output.
657 (splitter++)->processHfScale(tmpspan, hfscale);
658 hfscale = mOrderScales[1];
660 MixSamples(tmpspan, samplesOut, gains.Current, gains.Target, todo, 0);
662 hfscale = mOrderScales[0];
663 splitter = pipeline.mAmbiSplitter[1].begin();
664 a2bcoeffs = LateA2B.cbegin();
665 for(auto &gains : pipeline.mLate.Gains)
667 DoMixRow(tmpspan, *(a2bcoeffs++), mLateSamples);
669 (splitter++)->processHfScale(tmpspan, hfscale);
670 hfscale = mOrderScales[1];
672 MixSamples(tmpspan, samplesOut, gains.Current, gains.Target, todo, 0);
676 void mixOut(ReverbPipeline &pipeline, const al::span<FloatBufferLine> samplesOut, const size_t todo)
678 if(mUpmixOutput)
679 MixOutAmbiUp(pipeline, samplesOut, todo);
680 else
681 MixOutPlain(pipeline, samplesOut, todo);
684 void allocLines(const float frequency);
686 void deviceUpdate(const DeviceBase *device, const BufferStorage *buffer) override;
687 void update(const ContextBase *context, const EffectSlot *slot, const EffectProps *props,
688 const EffectTarget target) override;
689 void process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn,
690 const al::span<FloatBufferLine> samplesOut) override;
693 /**************************************
694 * Device Update *
695 **************************************/
697 inline float CalcDelayLengthMult(float density)
698 { return std::max(5.0f, std::cbrt(density*DENSITY_SCALE)); }
700 /* Calculates the delay line metrics and allocates the shared sample buffer
701 * for all lines given the sample rate (frequency).
703 void ReverbState::allocLines(const float frequency)
705 /* Multiplier for the maximum density value, i.e. density=1, which is
706 * actually the least density...
708 const float multiplier{CalcDelayLengthMult(1.0f)};
710 /* The modulator's line length is calculated from the maximum modulation
711 * time and depth coefficient, and halfed for the low-to-high frequency
712 * swing.
714 static constexpr float max_mod_delay{MaxModulationTime*MODULATION_DEPTH_COEFF / 2.0f};
716 std::array<size_t,11> linelengths{};
717 size_t oidx{0};
719 size_t totalSamples{0u};
720 /* The main delay length includes the maximum early reflection delay and
721 * the largest early tap width. It must also be extended by the update size
722 * (BufferLineSize) for block processing.
724 float length{ReverbMaxReflectionsDelay + EARLY_TAP_LENGTHS.back()*multiplier};
725 size_t count{mMainDelay.calcLineLength(length, frequency, BufferLineSize)};
726 linelengths[oidx++] = count;
727 totalSamples += count;
728 for(auto &pipeline : mPipelines)
730 static constexpr float LateDiffAvg{(LATE_LINE_LENGTHS.back()-LATE_LINE_LENGTHS.front()) /
731 float{NUM_LINES}};
732 length = ReverbMaxLateReverbDelay + LateDiffAvg*multiplier;
733 count = pipeline.mLateDelayIn.calcLineLength(length, frequency, BufferLineSize);
734 linelengths[oidx++] = count;
735 totalSamples += count;
737 /* The early vector all-pass line. */
738 length = EARLY_ALLPASS_LENGTHS.back() * multiplier;
739 count = pipeline.mEarly.VecAp.Delay.calcLineLength(length, frequency, 0);
740 linelengths[oidx++] = count;
741 totalSamples += count;
743 /* The early reflection line. */
744 length = EARLY_LINE_LENGTHS.back() * multiplier;
745 count = pipeline.mEarly.Delay.calcLineLength(length, frequency, MAX_UPDATE_SAMPLES);
746 linelengths[oidx++] = count;
747 totalSamples += count;
749 /* The late vector all-pass line. */
750 length = LATE_ALLPASS_LENGTHS.back() * multiplier;
751 count = pipeline.mLate.VecAp.Delay.calcLineLength(length, frequency, 0);
752 linelengths[oidx++] = count;
753 totalSamples += count;
755 /* The late delay lines are calculated from the largest maximum density
756 * line length, and the maximum modulation delay. Four additional
757 * samples are needed for resampling the modulator delay.
759 length = LATE_LINE_LENGTHS.back()*multiplier + max_mod_delay;
760 count = pipeline.mLate.Delay.calcLineLength(length, frequency, 4);
761 linelengths[oidx++] = count;
762 totalSamples += count;
764 assert(oidx == linelengths.size());
766 if(totalSamples != mSampleBuffer.size())
767 decltype(mSampleBuffer)(totalSamples).swap(mSampleBuffer);
769 /* Clear the sample buffer. */
770 std::fill(mSampleBuffer.begin(), mSampleBuffer.end(), 0.0f);
772 /* Update all delays to reflect the new sample buffer. */
773 auto bufferspan = al::span{mSampleBuffer};
774 oidx = 0;
775 mMainDelay.realizeLineOffset(bufferspan.first(linelengths[oidx]));
776 bufferspan = bufferspan.subspan(linelengths[oidx++]);
777 for(auto &pipeline : mPipelines)
779 pipeline.mLateDelayIn.realizeLineOffset(bufferspan.first(linelengths[oidx]));
780 bufferspan = bufferspan.subspan(linelengths[oidx++]);
781 pipeline.mEarly.VecAp.Delay.realizeLineOffset(bufferspan.first(linelengths[oidx]));
782 bufferspan = bufferspan.subspan(linelengths[oidx++]);
783 pipeline.mEarly.Delay.realizeLineOffset(bufferspan.first(linelengths[oidx]));
784 bufferspan = bufferspan.subspan(linelengths[oidx++]);
785 pipeline.mLate.VecAp.Delay.realizeLineOffset(bufferspan.first(linelengths[oidx]));
786 bufferspan = bufferspan.subspan(linelengths[oidx++]);
787 pipeline.mLate.Delay.realizeLineOffset(bufferspan.first(linelengths[oidx]));
788 bufferspan = bufferspan.subspan(linelengths[oidx++]);
790 assert(oidx == linelengths.size());
793 void ReverbState::deviceUpdate(const DeviceBase *device, const BufferStorage*)
795 const auto frequency = static_cast<float>(device->Frequency);
797 /* Allocate the delay lines. */
798 allocLines(frequency);
800 std::for_each(mPipelines.begin(), mPipelines.end(), std::mem_fn(&ReverbPipeline::clear));
801 mPipelineState = DeviceClear;
803 /* Reset offset base. */
804 mOffset = 0;
806 if(device->mAmbiOrder > 1)
808 mUpmixOutput = true;
809 mOrderScales = AmbiScale::GetHFOrderScales(1, device->mAmbiOrder, device->m2DMixing);
811 else
813 mUpmixOutput = false;
814 mOrderScales.fill(1.0f);
817 auto splitter = BandSplitter{device->mXOverFreq / frequency};
818 auto set_splitters = [&splitter](ReverbPipeline &pipeline)
820 std::fill(pipeline.mAmbiSplitter[0].begin(), pipeline.mAmbiSplitter[0].end(), splitter);
821 std::fill(pipeline.mAmbiSplitter[1].begin(), pipeline.mAmbiSplitter[1].end(), splitter);
823 std::for_each(mPipelines.begin(), mPipelines.end(), set_splitters);
826 /**************************************
827 * Effect Update *
828 **************************************/
830 /* Calculate a decay coefficient given the length of each cycle and the time
831 * until the decay reaches -60 dB.
833 inline float CalcDecayCoeff(const float length, const float decayTime)
834 { return std::pow(ReverbDecayGain, length/decayTime); }
836 /* Calculate a decay length from a coefficient and the time until the decay
837 * reaches -60 dB.
839 inline float CalcDecayLength(const float coeff, const float decayTime)
841 constexpr float log10_decaygain{-3.0f/*std::log10(ReverbDecayGain)*/};
842 return std::log10(coeff) * decayTime / log10_decaygain;
845 /* Calculate an attenuation to be applied to the input of any echo models to
846 * compensate for modal density and decay time.
848 inline float CalcDensityGain(const float a)
850 /* The energy of a signal can be obtained by finding the area under the
851 * squared signal. This takes the form of Sum(x_n^2), where x is the
852 * amplitude for the sample n.
854 * Decaying feedback matches exponential decay of the form Sum(a^n),
855 * where a is the attenuation coefficient, and n is the sample. The area
856 * under this decay curve can be calculated as: 1 / (1 - a).
858 * Modifying the above equation to find the area under the squared curve
859 * (for energy) yields: 1 / (1 - a^2). Input attenuation can then be
860 * calculated by inverting the square root of this approximation,
861 * yielding: 1 / sqrt(1 / (1 - a^2)), simplified to: sqrt(1 - a^2).
863 return std::sqrt(1.0f - a*a);
866 /* Calculate the scattering matrix coefficients given a diffusion factor. */
867 inline void CalcMatrixCoeffs(const float diffusion, float *x, float *y)
869 /* The matrix is of order 4, so n is sqrt(4 - 1). */
870 constexpr float n{al::numbers::sqrt3_v<float>};
871 const float t{diffusion * std::atan(n)};
873 /* Calculate the first mixing matrix coefficient. */
874 *x = std::cos(t);
875 /* Calculate the second mixing matrix coefficient. */
876 *y = std::sin(t) / n;
879 /* Calculate the limited HF ratio for use with the late reverb low-pass
880 * filters.
882 float CalcLimitedHfRatio(const float hfRatio, const float airAbsorptionGainHF,
883 const float decayTime)
885 /* Find the attenuation due to air absorption in dB (converting delay
886 * time to meters using the speed of sound). Then reversing the decay
887 * equation, solve for HF ratio. The delay length is cancelled out of
888 * the equation, so it can be calculated once for all lines.
890 float limitRatio{1.0f / SpeedOfSoundMetersPerSec /
891 CalcDecayLength(airAbsorptionGainHF, decayTime)};
893 /* Using the limit calculated above, apply the upper bound to the HF ratio. */
894 return std::min(limitRatio, hfRatio);
898 /* Calculates the 3-band T60 damping coefficients for a particular delay line
899 * of specified length, using a combination of two shelf filter sections given
900 * decay times for each band split at two reference frequencies.
902 void T60Filter::calcCoeffs(const float length, const float lfDecayTime,
903 const float mfDecayTime, const float hfDecayTime, const float lf0norm,
904 const float hf0norm)
906 const float mfGain{CalcDecayCoeff(length, mfDecayTime)};
907 const float lfGain{CalcDecayCoeff(length, lfDecayTime) / mfGain};
908 const float hfGain{CalcDecayCoeff(length, hfDecayTime) / mfGain};
910 MidGain = mfGain;
911 LFFilter.setParamsFromSlope(BiquadType::LowShelf, lf0norm, lfGain, 1.0f);
912 HFFilter.setParamsFromSlope(BiquadType::HighShelf, hf0norm, hfGain, 1.0f);
915 /* Update the early reflection line lengths and gain coefficients. */
916 void EarlyReflections::updateLines(const float density_mult, const float diffusion,
917 const float decayTime, const float frequency)
919 /* Calculate the all-pass feed-back/forward coefficient. */
920 VecAp.Coeff = diffusion*diffusion * InvSqrt2;
922 for(size_t i{0u};i < NUM_LINES;i++)
924 /* Calculate the delay length of each all-pass line. */
925 float length{EARLY_ALLPASS_LENGTHS[i] * density_mult};
926 VecAp.Offset[i] = float2uint(length * frequency);
928 /* Calculate the delay length of each delay line. */
929 length = EARLY_LINE_LENGTHS[i] * density_mult;
930 Offset[i] = float2uint(length * frequency);
932 /* Calculate the gain (coefficient) for each line. */
933 Coeff[i] = CalcDecayCoeff(length, decayTime);
937 /* Update the EAX modulation step and depth. Keep in mind that this kind of
938 * vibrato is additive and not multiplicative as one may expect. The downswing
939 * will sound stronger than the upswing.
941 void Modulation::updateModulator(float modTime, float modDepth, float frequency)
943 /* Modulation is calculated in two parts.
945 * The modulation time effects the sinus rate, altering the speed of
946 * frequency changes. An index is incremented for each sample with an
947 * appropriate step size to generate an LFO, which will vary the feedback
948 * delay over time.
950 Step = std::max(fastf2u(MOD_FRACONE / (frequency * modTime)), 1u);
952 /* The modulation depth effects the amount of frequency change over the
953 * range of the sinus. It needs to be scaled by the modulation time so that
954 * a given depth produces a consistent change in frequency over all ranges
955 * of time. Since the depth is applied to a sinus value, it needs to be
956 * halved once for the sinus range and again for the sinus swing in time
957 * (half of it is spent decreasing the frequency, half is spent increasing
958 * it).
960 if(modTime >= DefaultModulationTime)
962 /* To cancel the effects of a long period modulation on the late
963 * reverberation, the amount of pitch should be varied (decreased)
964 * according to the modulation time. The natural form is varying
965 * inversely, in fact resulting in an invariant.
967 Depth = MODULATION_DEPTH_COEFF / 4.0f * DefaultModulationTime * modDepth * frequency;
969 else
970 Depth = MODULATION_DEPTH_COEFF / 4.0f * modTime * modDepth * frequency;
973 /* Update the late reverb line lengths and T60 coefficients. */
974 void LateReverb::updateLines(const float density_mult, const float diffusion,
975 const float lfDecayTime, const float mfDecayTime, const float hfDecayTime,
976 const float lf0norm, const float hf0norm, const float frequency)
978 /* Scaling factor to convert the normalized reference frequencies from
979 * representing 0...freq to 0...max_reference.
981 constexpr float MaxHFReference{20000.0f};
982 const float norm_weight_factor{frequency / MaxHFReference};
984 const float late_allpass_avg{
985 std::accumulate(LATE_ALLPASS_LENGTHS.begin(), LATE_ALLPASS_LENGTHS.end(), 0.0f) /
986 float{NUM_LINES}};
988 /* To compensate for changes in modal density and decay time of the late
989 * reverb signal, the input is attenuated based on the maximal energy of
990 * the outgoing signal. This approximation is used to keep the apparent
991 * energy of the signal equal for all ranges of density and decay time.
993 * The average length of the delay lines is used to calculate the
994 * attenuation coefficient.
996 float length{std::accumulate(LATE_LINE_LENGTHS.begin(), LATE_LINE_LENGTHS.end(), 0.0f) /
997 float{NUM_LINES} + late_allpass_avg};
998 length *= density_mult;
999 /* The density gain calculation uses an average decay time weighted by
1000 * approximate bandwidth. This attempts to compensate for losses of energy
1001 * that reduce decay time due to scattering into highly attenuated bands.
1003 const float decayTimeWeighted{
1004 lf0norm*norm_weight_factor*lfDecayTime +
1005 (hf0norm - lf0norm)*norm_weight_factor*mfDecayTime +
1006 (1.0f - hf0norm*norm_weight_factor)*hfDecayTime};
1007 DensityGain = CalcDensityGain(CalcDecayCoeff(length, decayTimeWeighted));
1009 /* Calculate the all-pass feed-back/forward coefficient. */
1010 VecAp.Coeff = diffusion*diffusion * InvSqrt2;
1012 for(size_t i{0u};i < NUM_LINES;i++)
1014 /* Calculate the delay length of each all-pass line. */
1015 length = LATE_ALLPASS_LENGTHS[i] * density_mult;
1016 VecAp.Offset[i] = float2uint(length * frequency);
1018 /* Calculate the delay length of each feedback delay line. A cubic
1019 * resampler is used for modulation on the feedback delay, which
1020 * includes one sample of delay. Reduce by one to compensate.
1022 length = LATE_LINE_LENGTHS[i] * density_mult;
1023 Offset[i] = std::max(float2uint(length*frequency + 0.5f), 1u) - 1u;
1025 /* Approximate the absorption that the vector all-pass would exhibit
1026 * given the current diffusion so we don't have to process a full T60
1027 * filter for each of its four lines. Also include the average
1028 * modulation delay (depth is half the max delay in samples).
1030 length += lerpf(LATE_ALLPASS_LENGTHS[i], late_allpass_avg, diffusion)*density_mult +
1031 Mod.Depth/frequency;
1033 /* Calculate the T60 damping coefficients for each line. */
1034 T60[i].calcCoeffs(length, lfDecayTime, mfDecayTime, hfDecayTime, lf0norm, hf0norm);
1039 /* Update the offsets for the main effect delay line. */
1040 void ReverbPipeline::updateDelayLine(const float gain, const float earlyDelay,
1041 const float lateDelay, const float density_mult, const float decayTime, const float frequency)
1043 /* Early reflection taps are decorrelated by means of an average room
1044 * reflection approximation described above the definition of the taps.
1045 * This approximation is linear and so the above density multiplier can
1046 * be applied to adjust the width of the taps. A single-band decay
1047 * coefficient is applied to simulate initial attenuation and absorption.
1049 * Late reverb taps are based on the late line lengths to allow a zero-
1050 * delay path and offsets that would continue the propagation naturally
1051 * into the late lines.
1053 for(size_t i{0u};i < NUM_LINES;i++)
1055 float length{EARLY_TAP_LENGTHS[i]*density_mult};
1056 mEarlyDelayTap[i][1] = float2uint((earlyDelay+length) * frequency);
1057 mEarlyDelayCoeff[i][1] = CalcDecayCoeff(length, decayTime) * gain;
1059 /* Reduce the late delay tap by the shortest early delay line length to
1060 * compensate for the late line input being fed by the delayed early
1061 * output.
1063 length = (LATE_LINE_LENGTHS[i] - LATE_LINE_LENGTHS.front())/float{NUM_LINES}*density_mult +
1064 lateDelay;
1065 mLateDelayTap[i][1] = float2uint(length * frequency);
1069 /* Creates a transform matrix given a reverb vector. The vector pans the reverb
1070 * reflections toward the given direction, using its magnitude (up to 1) as a
1071 * focal strength. This function results in a B-Format transformation matrix
1072 * that spatially focuses the signal in the desired direction.
1074 std::array<std::array<float,4>,4> GetTransformFromVector(const al::span<const float,3> vec)
1076 /* Normalize the panning vector according to the N3D scale, which has an
1077 * extra sqrt(3) term on the directional components. Converting from OpenAL
1078 * to B-Format also requires negating X (ACN 1) and Z (ACN 3). Note however
1079 * that the reverb panning vectors use left-handed coordinates, unlike the
1080 * rest of OpenAL which use right-handed. This is fixed by negating Z,
1081 * which cancels out with the B-Format Z negation.
1083 std::array<float,3> norm;
1084 float mag{std::sqrt(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2])};
1085 if(mag > 1.0f)
1087 const float scale{al::numbers::sqrt3_v<float> / mag};
1088 norm[0] = vec[0] * -scale;
1089 norm[1] = vec[1] * scale;
1090 norm[2] = vec[2] * scale;
1091 mag = 1.0f;
1093 else
1095 /* If the magnitude is less than or equal to 1, just apply the sqrt(3)
1096 * term. There's no need to renormalize the magnitude since it would
1097 * just be reapplied in the matrix.
1099 norm[0] = vec[0] * -al::numbers::sqrt3_v<float>;
1100 norm[1] = vec[1] * al::numbers::sqrt3_v<float>;
1101 norm[2] = vec[2] * al::numbers::sqrt3_v<float>;
1104 return std::array<std::array<float,4>,4>{{
1105 {{1.0f, 0.0f, 0.0f, 0.0f}},
1106 {{norm[0], 1.0f-mag, 0.0f, 0.0f}},
1107 {{norm[1], 0.0f, 1.0f-mag, 0.0f}},
1108 {{norm[2], 0.0f, 0.0f, 1.0f-mag}}
1112 /* Update the early and late 3D panning gains. */
1113 void ReverbPipeline::update3DPanning(const al::span<const float,3> ReflectionsPan,
1114 const al::span<const float,3> LateReverbPan, const float earlyGain, const float lateGain,
1115 const bool doUpmix, const MixParams *mainMix)
1117 /* Create matrices that transform a B-Format signal according to the
1118 * panning vectors.
1120 const auto earlymat = GetTransformFromVector(ReflectionsPan);
1121 const auto latemat = GetTransformFromVector(LateReverbPan);
1123 const auto [earlycoeffs, latecoeffs] = [&]{
1124 if(doUpmix)
1126 /* When upsampling, combine the early and late transforms with the
1127 * first-order upsample matrix. This results in panning gains that
1128 * apply the panning transform to first-order B-Format, which is
1129 * then upsampled.
1131 auto mult_matrix = [](const al::span<const std::array<float,4>,4> mtx1)
1133 std::array<std::array<float,MaxAmbiChannels>,NUM_LINES> res{};
1134 const auto mtx2 = al::span{AmbiScale::FirstOrderUp};
1136 for(size_t i{0};i < mtx1[0].size();++i)
1138 const al::span dst{res[i]};
1139 static_assert(dst.size() >= std::tuple_size_v<decltype(mtx2)::element_type>);
1140 for(size_t k{0};k < mtx1.size();++k)
1142 const float a{mtx1[k][i]};
1143 std::transform(mtx2[k].begin(), mtx2[k].end(), dst.begin(), dst.begin(),
1144 [a](const float in, const float out) noexcept -> float
1145 { return a*in + out; });
1149 return res;
1151 return std::make_pair(mult_matrix(earlymat), mult_matrix(latemat));
1154 /* When not upsampling, combine the early and late A-to-B-Format
1155 * conversions with their respective transform. This results panning
1156 * gains that convert A-Format to B-Format, which is then panned.
1158 auto mult_matrix = [](const al::span<const std::array<float,NUM_LINES>,4> mtx1,
1159 const al::span<const std::array<float,4>,4> mtx2)
1161 std::array<std::array<float,MaxAmbiChannels>,NUM_LINES> res{};
1163 for(size_t i{0};i < mtx1[0].size();++i)
1165 const al::span dst{res[i]};
1166 static_assert(dst.size() >= std::tuple_size_v<decltype(mtx2)::element_type>);
1167 for(size_t k{0};k < mtx1.size();++k)
1169 const float a{mtx1[k][i]};
1170 std::transform(mtx2[k].begin(), mtx2[k].end(), dst.begin(), dst.begin(),
1171 [a](const float in, const float out) noexcept -> float
1172 { return a*in + out; });
1176 return res;
1178 return std::make_pair(mult_matrix(EarlyA2B, earlymat), mult_matrix(LateA2B, latemat));
1179 }();
1181 auto earlygains = mEarly.Gains.begin();
1182 for(auto &coeffs : earlycoeffs)
1183 ComputePanGains(mainMix, coeffs, earlyGain, (earlygains++)->Target);
1184 auto lategains = mLate.Gains.begin();
1185 for(auto &coeffs : latecoeffs)
1186 ComputePanGains(mainMix, coeffs, lateGain, (lategains++)->Target);
1189 void ReverbState::update(const ContextBase *Context, const EffectSlot *Slot,
1190 const EffectProps *props_, const EffectTarget target)
1192 auto &props = std::get<ReverbProps>(*props_);
1193 const DeviceBase *Device{Context->mDevice};
1194 const auto frequency = static_cast<float>(Device->Frequency);
1196 /* If the HF limit parameter is flagged, calculate an appropriate limit
1197 * based on the air absorption parameter.
1199 float hfRatio{props.DecayHFRatio};
1200 if(props.DecayHFLimit && props.AirAbsorptionGainHF < 1.0f)
1201 hfRatio = CalcLimitedHfRatio(hfRatio, props.AirAbsorptionGainHF, props.DecayTime);
1203 /* Calculate the LF/HF decay times. */
1204 constexpr float MinDecayTime{0.1f}, MaxDecayTime{20.0f};
1205 const float lfDecayTime{std::clamp(props.DecayTime*props.DecayLFRatio, MinDecayTime,
1206 MaxDecayTime)};
1207 const float hfDecayTime{std::clamp(props.DecayTime*hfRatio, MinDecayTime, MaxDecayTime)};
1209 /* Determine if a full update is required. */
1210 const bool fullUpdate{mPipelineState == DeviceClear ||
1211 /* Density is essentially a master control for the feedback delays, so
1212 * changes the offsets of many delay lines.
1214 mParams.Density != props.Density ||
1215 /* Diffusion and decay times influences the decay rate (gain) of the
1216 * late reverb T60 filter.
1218 mParams.Diffusion != props.Diffusion ||
1219 mParams.DecayTime != props.DecayTime ||
1220 mParams.HFDecayTime != hfDecayTime ||
1221 mParams.LFDecayTime != lfDecayTime ||
1222 /* Modulation time and depth both require fading the modulation delay. */
1223 mParams.ModulationTime != props.ModulationTime ||
1224 mParams.ModulationDepth != props.ModulationDepth ||
1225 /* HF/LF References control the weighting used to calculate the density
1226 * gain.
1228 mParams.HFReference != props.HFReference ||
1229 mParams.LFReference != props.LFReference};
1230 if(fullUpdate)
1232 mParams.Density = props.Density;
1233 mParams.Diffusion = props.Diffusion;
1234 mParams.DecayTime = props.DecayTime;
1235 mParams.HFDecayTime = hfDecayTime;
1236 mParams.LFDecayTime = lfDecayTime;
1237 mParams.ModulationTime = props.ModulationTime;
1238 mParams.ModulationDepth = props.ModulationDepth;
1239 mParams.HFReference = props.HFReference;
1240 mParams.LFReference = props.LFReference;
1242 mPipelineState = (mPipelineState != DeviceClear) ? StartFade : Normal;
1243 mCurrentPipeline = !mCurrentPipeline;
1245 auto &oldpipeline = mPipelines[!mCurrentPipeline];
1246 for(size_t j{0};j < NUM_LINES;++j)
1247 oldpipeline.mEarlyDelayCoeff[j][1] = 0.0f;
1249 auto &pipeline = mPipelines[mCurrentPipeline];
1251 /* The density-based room size (delay length) multiplier. */
1252 const float density_mult{CalcDelayLengthMult(props.Density)};
1254 /* Update the main effect delay and associated taps. */
1255 pipeline.updateDelayLine(props.Gain, props.ReflectionsDelay, props.LateReverbDelay,
1256 density_mult, props.DecayTime, frequency);
1258 /* Update early and late 3D panning. */
1259 mOutTarget = target.Main->Buffer;
1260 const float gain{Slot->Gain * ReverbBoost};
1261 pipeline.update3DPanning(props.ReflectionsPan, props.LateReverbPan, props.ReflectionsGain*gain,
1262 props.LateReverbGain*gain, mUpmixOutput, target.Main);
1264 /* Calculate the master filters */
1265 float hf0norm{std::min(props.HFReference/frequency, 0.49f)};
1266 pipeline.mFilter[0].Lp.setParamsFromSlope(BiquadType::HighShelf, hf0norm, props.GainHF, 1.0f);
1267 float lf0norm{std::min(props.LFReference/frequency, 0.49f)};
1268 pipeline.mFilter[0].Hp.setParamsFromSlope(BiquadType::LowShelf, lf0norm, props.GainLF, 1.0f);
1269 for(size_t i{1u};i < NUM_LINES;i++)
1271 pipeline.mFilter[i].Lp.copyParamsFrom(pipeline.mFilter[0].Lp);
1272 pipeline.mFilter[i].Hp.copyParamsFrom(pipeline.mFilter[0].Hp);
1275 if(fullUpdate)
1277 /* Update the early lines. */
1278 pipeline.mEarly.updateLines(density_mult, props.Diffusion, props.DecayTime, frequency);
1280 /* Get the mixing matrix coefficients. */
1281 CalcMatrixCoeffs(props.Diffusion, &pipeline.mMixX, &pipeline.mMixY);
1283 /* Update the modulator rate and depth. */
1284 pipeline.mLate.Mod.updateModulator(props.ModulationTime, props.ModulationDepth, frequency);
1286 /* Update the late lines. */
1287 pipeline.mLate.updateLines(density_mult, props.Diffusion, lfDecayTime, props.DecayTime,
1288 hfDecayTime, lf0norm, hf0norm, frequency);
1291 /* Calculate the gain at the start of the late reverb stage, and the gain
1292 * difference from the decay target (0.001, or -60dB).
1294 const float decayBase{props.ReflectionsGain * props.LateReverbGain};
1295 const float decayDiff{ReverbDecayGain / decayBase};
1297 /* Given the DecayTime (the amount of time for the late reverb to decay by
1298 * -60dB), calculate the time to decay to -60dB from the start of the late
1299 * reverb.
1301 * Otherwise, if the late reverb already starts at -60dB or less, only
1302 * include the time to get to the late reverb.
1304 const float diffTime{!(decayDiff < 1.0f) ? 0.0f
1305 : (std::log10(decayDiff)*(20.0f / -60.0f) * props.DecayTime)};
1307 const float decaySamples{(props.ReflectionsDelay+props.LateReverbDelay+diffTime)
1308 * frequency};
1309 /* Limit to 100,000 samples (a touch over 2 seconds at 48khz) to avoid
1310 * excessive double-processing.
1312 pipeline.mFadeSampleCount = static_cast<size_t>(std::min(decaySamples, 100'000.0f));
1316 /**************************************
1317 * Effect Processing *
1318 **************************************/
1320 /* Applies a scattering matrix to the 4-line (vector) input. This is used
1321 * for both the below vector all-pass model and to perform modal feed-back
1322 * delay network (FDN) mixing.
1324 * The matrix is derived from a skew-symmetric matrix to form a 4D rotation
1325 * matrix with a single unitary rotational parameter:
1327 * [ d, a, b, c ] 1 = a^2 + b^2 + c^2 + d^2
1328 * [ -a, d, c, -b ]
1329 * [ -b, -c, d, a ]
1330 * [ -c, b, -a, d ]
1332 * The rotation is constructed from the effect's diffusion parameter,
1333 * yielding:
1335 * 1 = x^2 + 3 y^2
1337 * Where a, b, and c are the coefficient y with differing signs, and d is the
1338 * coefficient x. The final matrix is thus:
1340 * [ x, y, -y, y ] n = sqrt(matrix_order - 1)
1341 * [ -y, x, y, y ] t = diffusion_parameter * atan(n)
1342 * [ y, -y, x, y ] x = cos(t)
1343 * [ -y, -y, -y, x ] y = sin(t) / n
1345 * Any square orthogonal matrix with an order that is a power of two will
1346 * work (where ^T is transpose, ^-1 is inverse):
1348 * M^T = M^-1
1350 * Using that knowledge, finding an appropriate matrix can be accomplished
1351 * naively by searching all combinations of:
1353 * M = D + S - S^T
1355 * Where D is a diagonal matrix (of x), and S is a triangular matrix (of y)
1356 * whose combination of signs are being iterated.
1358 inline auto VectorPartialScatter(const std::array<float,NUM_LINES> &in, const float xCoeff,
1359 const float yCoeff) noexcept -> std::array<float,NUM_LINES>
1361 return std::array{
1362 xCoeff*in[0] + yCoeff*( in[1] + -in[2] + in[3]),
1363 xCoeff*in[1] + yCoeff*(-in[0] + in[2] + in[3]),
1364 xCoeff*in[2] + yCoeff*( in[0] + -in[1] + in[3]),
1365 xCoeff*in[3] + yCoeff*(-in[0] + -in[1] + -in[2] )
1369 /* Utilizes the above, but also applies a line-based reflection on the input
1370 * channels (swapping 0<->3 and 1<->2).
1372 void VectorScatterRev(const float xCoeff, const float yCoeff,
1373 const al::span<ReverbUpdateLine,NUM_LINES> samples, const size_t count) noexcept
1375 ASSUME(count > 0);
1377 for(size_t i{0u};i < count;++i)
1379 std::array src{samples[0][i], samples[1][i], samples[2][i], samples[3][i]};
1381 src = VectorPartialScatter(std::array{src[3], src[2], src[1], src[0]}, xCoeff, yCoeff);
1382 samples[0][i] = src[0];
1383 samples[1][i] = src[1];
1384 samples[2][i] = src[2];
1385 samples[3][i] = src[3];
1389 /* This applies a Gerzon multiple-in/multiple-out (MIMO) vector all-pass
1390 * filter to the 4-line input.
1392 * It works by vectorizing a regular all-pass filter and replacing the delay
1393 * element with a scattering matrix (like the one above) and a diagonal
1394 * matrix of delay elements.
1396 void VecAllpass::process(const al::span<ReverbUpdateLine,NUM_LINES> samples, size_t main_offset,
1397 const float xCoeff, const float yCoeff, const size_t todo) const noexcept
1399 const auto linelen = size_t{Delay.mLine.size()/NUM_LINES};
1400 const float feedCoeff{Coeff};
1402 ASSUME(todo > 0);
1404 for(size_t i{0u};i < todo;)
1406 std::array<size_t,NUM_LINES> vap_offset;
1407 std::transform(Offset.cbegin(), Offset.cend(), vap_offset.begin(),
1408 [main_offset,mask=linelen-1](const size_t delay) noexcept -> size_t
1409 { return (main_offset-delay) & mask; });
1410 main_offset &= linelen-1;
1412 const auto maxoff = std::accumulate(vap_offset.cbegin(), vap_offset.cend(), main_offset,
1413 [](const size_t offset, const size_t apoffset) { return std::max(offset, apoffset); });
1414 size_t td{std::min(linelen - maxoff, todo - i)};
1416 auto delayIn = Delay.mLine.begin();
1417 auto delayOut = Delay.mLine.begin() + ptrdiff_t(main_offset*NUM_LINES);
1418 main_offset += td;
1420 do {
1421 std::array<float,NUM_LINES> f;
1422 for(size_t j{0u};j < NUM_LINES;j++)
1424 const float input{samples[j][i]};
1425 const float out{delayIn[vap_offset[j]*NUM_LINES + j] - feedCoeff*input};
1426 f[j] = input + feedCoeff*out;
1428 samples[j][i] = out;
1430 delayIn += NUM_LINES;
1431 ++i;
1433 f = VectorPartialScatter(f, xCoeff, yCoeff);
1434 delayOut = std::copy_n(f.cbegin(), f.size(), delayOut);
1435 } while(--td);
1439 /* This applies a more typical all-pass to each line, without the scattering
1440 * matrix.
1442 void Allpass4::process(const al::span<ReverbUpdateLine,NUM_LINES> samples, const size_t offset,
1443 const size_t todo) const noexcept
1445 const DelayLineU delay{Delay};
1446 const float feedCoeff{Coeff};
1448 ASSUME(todo > 0);
1450 for(size_t j{0u};j < NUM_LINES;j++)
1452 auto smpiter = samples[j].begin();
1453 const auto buffer = delay.get(j);
1454 size_t dstoffset{offset};
1455 size_t vap_offset{offset - Offset[j]};
1456 for(size_t i{0u};i < todo;)
1458 vap_offset &= buffer.size()-1;
1459 dstoffset &= buffer.size()-1;
1461 const size_t maxoff{std::max(dstoffset, vap_offset)};
1462 const size_t td{std::min(buffer.size() - maxoff, todo - i)};
1464 auto proc_sample = [buffer,feedCoeff,&vap_offset,&dstoffset](const float x) -> float
1466 const float y{buffer[vap_offset++] - feedCoeff*x};
1467 buffer[dstoffset++] = x + feedCoeff*y;
1468 return y;
1470 smpiter = std::transform(smpiter, smpiter+td, smpiter, proc_sample);
1471 i += td;
1477 /* This generates early reflections.
1479 * This is done by obtaining the primary reflections (those arriving from the
1480 * same direction as the source) from the main delay line. These are
1481 * attenuated and all-pass filtered (based on the diffusion parameter).
1483 * The early lines are then reflected about the origin to create the secondary
1484 * reflections (those arriving from the opposite direction as the source).
1486 * The early response is then completed by combining the primary reflections
1487 * with the delayed and attenuated output from the early lines.
1489 * Finally, the early response is reflected, scattered (based on diffusion),
1490 * and fed into the late reverb section of the main delay line.
1492 void ReverbPipeline::processEarly(const DelayLineU &main_delay, size_t offset,
1493 const size_t samplesToDo, const al::span<ReverbUpdateLine, NUM_LINES> tempSamples,
1494 const al::span<FloatBufferLine, NUM_LINES> outSamples)
1496 const DelayLineU early_delay{mEarly.Delay};
1497 const DelayLineU in_delay{main_delay};
1498 const float mixX{mMixX};
1499 const float mixY{mMixY};
1501 ASSUME(samplesToDo <= BufferLineSize);
1503 for(size_t base{0};base < samplesToDo;)
1505 const size_t todo{std::min(samplesToDo-base, MAX_UPDATE_SAMPLES)};
1507 /* First, load decorrelated samples from the main delay line as the
1508 * primary reflections.
1510 const auto fadeStep = float{1.0f / static_cast<float>(todo)};
1511 for(size_t j{0_uz};j < NUM_LINES;j++)
1513 const auto input = in_delay.get(j);
1514 auto early_delay_tap0 = size_t{offset - mEarlyDelayTap[j][0]};
1515 auto early_delay_tap1 = size_t{offset - mEarlyDelayTap[j][1]};
1516 mEarlyDelayTap[j][0] = mEarlyDelayTap[j][1];
1517 const auto coeff0 = float{mEarlyDelayCoeff[j][0]};
1518 const auto coeff1 = float{mEarlyDelayCoeff[j][1]};
1519 mEarlyDelayCoeff[j][0] = mEarlyDelayCoeff[j][1];
1520 auto fadeCount = float{0.0f};
1522 auto tmp = tempSamples[j].begin();
1523 for(size_t i{0_uz};i < todo;)
1525 early_delay_tap0 &= input.size()-1;
1526 early_delay_tap1 &= input.size()-1;
1527 const auto max_tap = size_t{std::max(early_delay_tap0, early_delay_tap1)};
1528 const auto td = size_t{std::min(input.size()-max_tap, todo-i)};
1529 const auto intap0 = input.subspan(early_delay_tap0, td);
1530 const auto intap1 = input.subspan(early_delay_tap1, td);
1532 auto do_blend = [coeff0,coeff1,fadeStep,&fadeCount](const float in0,
1533 const float in1) noexcept -> float
1535 const auto ret = lerpf(in0*coeff0, in1*coeff1, fadeStep*fadeCount);
1536 fadeCount += 1.0f;
1537 return ret;
1539 tmp = std::transform(intap0.begin(), intap0.end(), intap1.begin(), tmp, do_blend);
1540 early_delay_tap0 += td;
1541 early_delay_tap1 += td;
1542 i += td;
1545 /* Band-pass the incoming samples. */
1546 auto&& filter = DualBiquad{mFilter[j].Lp, mFilter[j].Hp};
1547 filter.process(al::span{tempSamples[j]}.first(todo), tempSamples[j]);
1550 /* Apply an all-pass, to help color the initial reflections. */
1551 mEarly.VecAp.process(tempSamples, offset, todo);
1553 /* Apply a delay and bounce to generate secondary reflections. */
1554 early_delay.writeReflected(offset, tempSamples, todo);
1555 for(size_t j{0_uz};j < NUM_LINES;j++)
1557 const auto input = early_delay.get(j);
1558 auto feedb_tap = size_t{offset - mEarly.Offset[j]};
1559 const auto feedb_coeff = float{mEarly.Coeff[j]};
1560 auto out = outSamples[j].begin() + base;
1561 auto tmp = tempSamples[j].begin();
1563 for(size_t i{0_uz};i < todo;)
1565 feedb_tap &= input.size()-1;
1567 const auto td = size_t{std::min(input.size() - feedb_tap, todo - i)};
1568 const auto delaySrc = input.subspan(feedb_tap, td);
1570 /* Combine the main input with the attenuated delayed echo for
1571 * the early output.
1573 out = std::transform(delaySrc.begin(), delaySrc.end(), tmp, out,
1574 [feedb_coeff](const float delayspl, const float mainspl) noexcept -> float
1575 { return delayspl*feedb_coeff + mainspl; });
1577 /* Move the (non-attenuated) delayed echo to the temp buffer
1578 * for feeding the late reverb.
1580 tmp = std::copy_n(delaySrc.begin(), delaySrc.size(), tmp);
1581 feedb_tap += td;
1582 i += td;
1586 /* Finally, apply a scatter and bounce to improve the initial diffusion
1587 * in the late reverb, writing the result to the late delay line input.
1589 VectorScatterRev(mixX, mixY, tempSamples, todo);
1590 for(size_t j{0_uz};j < NUM_LINES;j++)
1591 mLateDelayIn.write(offset, j, al::span{tempSamples[j]}.first(todo));
1593 base += todo;
1594 offset += todo;
1598 auto Modulation::calcDelays(size_t todo) -> al::span<const uint>
1600 auto idx = uint{Index};
1601 const auto step = uint{Step};
1602 const auto depth = float{Depth * float{gCubicTable.sTableSteps}};
1603 const auto delays = al::span{ModDelays}.first(todo);
1604 std::generate(delays.begin(), delays.end(), [step,depth,&idx]
1606 idx += step;
1607 const auto x = float{static_cast<float>(idx&MOD_FRACMASK) * (1.0f/MOD_FRACONE)};
1608 /* Approximate sin(x*2pi). As long as it roughly fits a sinusoid shape
1609 * and stays within [-1...+1], it needn't be perfect.
1611 const auto lfo = float{!(idx&(MOD_FRACONE>>1))
1612 ? ((-16.0f * x * x) + (8.0f * x))
1613 : ((16.0f * x * x) + (-8.0f * x) + (-16.0f * x) + 8.0f)};
1614 return float2uint((lfo+1.0f) * depth);
1616 Index = idx;
1617 return delays;
1621 /* This generates the reverb tail using a modified feed-back delay network
1622 * (FDN).
1624 * Results from the early reflections are mixed with the output from the
1625 * modulated late delay lines.
1627 * The late response is then completed by T60 and all-pass filtering the mix.
1629 * Finally, the lines are reversed (so they feed their opposite directions)
1630 * and scattered with the FDN matrix before re-feeding the delay lines.
1632 void ReverbPipeline::processLate(size_t offset, const size_t samplesToDo,
1633 const al::span<ReverbUpdateLine, NUM_LINES> tempSamples,
1634 const al::span<FloatBufferLine, NUM_LINES> outSamples)
1636 const DelayLineU late_delay{mLate.Delay};
1637 const DelayLineU in_delay{mLateDelayIn};
1638 const float mixX{mMixX};
1639 const float mixY{mMixY};
1641 ASSUME(samplesToDo <= BufferLineSize);
1643 for(size_t base{0};base < samplesToDo;)
1645 const size_t todo{std::min(std::min(mLate.Offset[0], MAX_UPDATE_SAMPLES),
1646 samplesToDo-base)};
1647 ASSUME(todo > 0);
1649 /* First, calculate the modulated delays for the late feedback. */
1650 const auto delays = mLate.Mod.calcDelays(todo);
1652 /* Now load samples from the feedback delay lines. Filter the signal to
1653 * apply its frequency-dependent decay.
1655 for(size_t j{0_uz};j < NUM_LINES;++j)
1657 const auto input = late_delay.get(j);
1658 const auto midGain = float{mLate.T60[j].MidGain};
1659 auto late_feedb_tap = size_t{offset - mLate.Offset[j]};
1661 auto proc_sample = [input,midGain,&late_feedb_tap](const size_t idelay) -> float
1663 /* Calculate the read sample offset and sub-sample offset
1664 * between it and the next sample.
1666 const auto delay = size_t{late_feedb_tap - (idelay>>gCubicTable.sTableBits)};
1667 const auto delayoffset = size_t{idelay & gCubicTable.sTableMask};
1668 ++late_feedb_tap;
1670 /* Get the samples around the delayed offset, interpolated for
1671 * output.
1673 const auto out0 = float{input[(delay ) & (input.size()-1)]};
1674 const auto out1 = float{input[(delay-1) & (input.size()-1)]};
1675 const auto out2 = float{input[(delay-2) & (input.size()-1)]};
1676 const auto out3 = float{input[(delay-3) & (input.size()-1)]};
1678 const auto out = float{out0*gCubicTable.getCoeff0(delayoffset)
1679 + out1*gCubicTable.getCoeff1(delayoffset)
1680 + out2*gCubicTable.getCoeff2(delayoffset)
1681 + out3*gCubicTable.getCoeff3(delayoffset)};
1682 return out * midGain;
1684 std::transform(delays.begin(), delays.end(), tempSamples[j].begin(), proc_sample);
1686 mLate.T60[j].process(al::span{tempSamples[j]}.first(todo));
1689 /* Next load decorrelated samples from the main delay lines. */
1690 const float fadeStep{1.0f / static_cast<float>(todo)};
1691 for(size_t j{0_uz};j < NUM_LINES;++j)
1693 const auto input = in_delay.get(j);
1694 auto late_delay_tap0 = size_t{offset - mLateDelayTap[j][0]};
1695 auto late_delay_tap1 = size_t{offset - mLateDelayTap[j][1]};
1696 mLateDelayTap[j][0] = mLateDelayTap[j][1];
1697 const auto densityGain = float{mLate.DensityGain};
1698 const auto densityStep = float{late_delay_tap0 != late_delay_tap1
1699 ? densityGain*fadeStep : 0.0f};
1700 auto fadeCount = float{0.0f};
1702 auto samples = tempSamples[j].begin();
1703 for(size_t i{0u};i < todo;)
1705 late_delay_tap0 &= input.size()-1;
1706 late_delay_tap1 &= input.size()-1;
1707 const auto td = size_t{std::min(todo - i,
1708 input.size() - std::max(late_delay_tap0, late_delay_tap1))};
1710 auto proc_sample = [input,densityGain,densityStep,&late_delay_tap0,
1711 &late_delay_tap1,&fadeCount](const float sample) noexcept -> float
1713 const auto fade0 = float{densityGain - densityStep*fadeCount};
1714 const auto fade1 = float{densityStep*fadeCount};
1715 fadeCount += 1.0f;
1716 return input[late_delay_tap0++]*fade0 + input[late_delay_tap1++]*fade1
1717 + sample;
1719 samples = std::transform(samples, samples+ptrdiff_t(td), samples, proc_sample);
1720 i += td;
1724 /* Apply a vector all-pass to improve micro-surface diffusion, and
1725 * write out the results for mixing.
1727 mLate.VecAp.process(tempSamples, offset, mixX, mixY, todo);
1728 for(size_t j{0_uz};j < NUM_LINES;++j)
1729 std::copy_n(tempSamples[j].begin(), todo, outSamples[j].begin()+base);
1731 /* Finally, scatter and bounce the results to refeed the feedback buffer. */
1732 VectorScatterRev(mixX, mixY, tempSamples, todo);
1733 for(size_t j{0_uz};j < NUM_LINES;++j)
1734 late_delay.write(offset, j, al::span{tempSamples[j]}.first(todo));
1736 base += todo;
1737 offset += todo;
1741 void ReverbState::process(const size_t samplesToDo, const al::span<const FloatBufferLine> samplesIn, const al::span<FloatBufferLine> samplesOut)
1743 const size_t offset{mOffset};
1745 ASSUME(samplesToDo <= BufferLineSize);
1747 auto &oldpipeline = mPipelines[!mCurrentPipeline];
1748 auto &pipeline = mPipelines[mCurrentPipeline];
1750 /* Convert B-Format to A-Format for processing. */
1751 const size_t numInput{std::min(samplesIn.size(), NUM_LINES)};
1752 const al::span<float> tmpspan{al::assume_aligned<16>(mTempLine.data()), samplesToDo};
1753 for(size_t c{0u};c < NUM_LINES;++c)
1755 std::fill(tmpspan.begin(), tmpspan.end(), 0.0f);
1756 for(size_t i{0};i < numInput;++i)
1758 const float gain{B2A[c][i]};
1760 auto mix_sample = [gain](const float sample, const float in) noexcept -> float
1761 { return sample + in*gain; };
1762 std::transform(tmpspan.begin(), tmpspan.end(), samplesIn[i].begin(), tmpspan.begin(),
1763 mix_sample);
1766 mMainDelay.write(offset, c, tmpspan);
1769 if(mPipelineState < Fading)
1770 mPipelineState = Fading;
1772 /* Process reverb for these samples. and mix them to the output. */
1773 pipeline.processEarly(mMainDelay, offset, samplesToDo, mTempSamples, mEarlySamples);
1774 pipeline.processLate(offset, samplesToDo, mTempSamples, mLateSamples);
1775 mixOut(pipeline, samplesOut, samplesToDo);
1777 if(mPipelineState != Normal)
1779 if(mPipelineState == Cleanup)
1781 size_t numSamples{mSampleBuffer.size()/2};
1782 const auto bufferspan = al::span{mSampleBuffer}.subspan(numSamples * !mCurrentPipeline,
1783 numSamples);
1784 std::fill_n(bufferspan.begin(), bufferspan.size(), 0.0f);
1786 oldpipeline.clear();
1787 mPipelineState = Normal;
1789 else
1791 /* If this is the final mix for this old pipeline, set the target
1792 * gains to 0 to ensure a complete fade out, and set the state to
1793 * Cleanup so the next invocation cleans up the delay buffers and
1794 * filters.
1796 if(samplesToDo >= oldpipeline.mFadeSampleCount)
1798 for(auto &gains : oldpipeline.mEarly.Gains)
1799 std::fill(gains.Target.begin(), gains.Target.end(), 0.0f);
1800 for(auto &gains : oldpipeline.mLate.Gains)
1801 std::fill(gains.Target.begin(), gains.Target.end(), 0.0f);
1802 oldpipeline.mFadeSampleCount = 0;
1803 mPipelineState = Cleanup;
1805 else
1806 oldpipeline.mFadeSampleCount -= samplesToDo;
1808 /* Process the old reverb for these samples. */
1809 oldpipeline.processEarly(mMainDelay, offset, samplesToDo, mTempSamples, mEarlySamples);
1810 oldpipeline.processLate(offset, samplesToDo, mTempSamples, mLateSamples);
1811 mixOut(oldpipeline, samplesOut, samplesToDo);
1815 mOffset = offset + samplesToDo;
1819 struct ReverbStateFactory final : public EffectStateFactory {
1820 al::intrusive_ptr<EffectState> create() override
1821 { return al::intrusive_ptr<EffectState>{new ReverbState{}}; }
1824 } // namespace
1826 EffectStateFactory *ReverbStateFactory_getFactory()
1828 static ReverbStateFactory ReverbFactory{};
1829 return &ReverbFactory;