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
32 #include "alc/effects/base.h"
34 #include "alnumbers.h"
35 #include "alnumeric.h"
37 #include "core/ambidefs.h"
38 #include "core/bufferline.h"
39 #include "core/context.h"
40 #include "core/devformat.h"
41 #include "core/device.h"
42 #include "core/effectslot.h"
43 #include "core/filters/biquad.h"
44 #include "core/filters/splitter.h"
45 #include "core/mixer.h"
46 #include "core/mixer/defs.h"
47 #include "intrusive_ptr.h"
48 #include "opthelpers.h"
54 using uint
= unsigned int;
56 constexpr float MaxModulationTime
{4.0f
};
57 constexpr float DefaultModulationTime
{0.25f
};
59 #define MOD_FRACBITS 24
60 #define MOD_FRACONE (1<<MOD_FRACBITS)
61 #define MOD_FRACMASK (MOD_FRACONE-1)
65 static constexpr size_t sTableBits
{8};
66 static constexpr size_t sTableSteps
{1 << sTableBits
};
67 static constexpr size_t sTableMask
{sTableSteps
- 1};
69 std::array
<float,sTableSteps
*2 + 1> mFilter
{};
71 constexpr CubicFilter()
73 /* This creates a lookup table for a cubic spline filter, with 256
74 * steps between samples. Only half the coefficients are needed, since
75 * Coeff2 is just Coeff1 in reverse and Coeff3 is just Coeff0 in
78 for(size_t i
{0};i
< sTableSteps
;++i
)
80 const double mu
{static_cast<double>(i
) / double{sTableSteps
}};
81 const double mu2
{mu
*mu
}, mu3
{mu2
*mu
};
82 const double a0
{-0.5*mu3
+ mu2
+ -0.5*mu
};
83 const double a1
{ 1.5*mu3
+ -2.5*mu2
+ 1.0f
};
84 mFilter
[i
] = static_cast<float>(a1
);
85 mFilter
[sTableSteps
+i
] = static_cast<float>(a0
);
89 [[nodiscard
]] constexpr auto getCoeff0(size_t i
) const noexcept
-> float
90 { return mFilter
[sTableSteps
+i
]; }
91 [[nodiscard
]] constexpr auto getCoeff1(size_t i
) const noexcept
-> float
92 { return mFilter
[i
]; }
93 [[nodiscard
]] constexpr auto getCoeff2(size_t i
) const noexcept
-> float
94 { return mFilter
[sTableSteps
-i
]; }
95 [[nodiscard
]] constexpr auto getCoeff3(size_t i
) const noexcept
-> float
96 { return mFilter
[sTableSteps
*2-i
]; }
98 constexpr CubicFilter gCubicTable
;
101 /* Max samples per process iteration. Used to limit the size needed for
102 * temporary buffers. Must be a multiple of 4 for SIMD alignment.
104 constexpr size_t MAX_UPDATE_SAMPLES
{256};
106 /* The number of spatialized lines or channels to process. Four channels allows
107 * for a 3D A-Format response. NOTE: This can't be changed without taking care
108 * of the conversion matrices, and a few places where the length arrays are
109 * assumed to have 4 elements.
111 constexpr size_t NUM_LINES
{4u};
114 /* This coefficient is used to define the maximum frequency range controlled by
115 * the modulation depth. The current value of 0.05 will allow it to swing from
116 * 0.95x to 1.05x. This value must be below 1. At 1 it will cause the sampler
117 * to stall on the downswing, and above 1 it will cause it to sample backwards.
118 * The value 0.05 seems be nearest to Creative hardware behavior.
120 constexpr float MODULATION_DEPTH_COEFF
{0.05f
};
123 /* The B-Format to (W-normalized) A-Format conversion matrix. This produces a
124 * tetrahedral array of discrete signals (boosted by a factor of sqrt(3), to
125 * reduce the error introduced in the conversion).
127 alignas(16) constexpr std::array
<std::array
<float,NUM_LINES
>,NUM_LINES
> B2A
{{
129 {{ 0.5f
, 0.5f
, 0.5f
, 0.5f
}}, /* A0 */
130 {{ 0.5f
, -0.5f
, -0.5f
, 0.5f
}}, /* A1 */
131 {{ 0.5f
, 0.5f
, -0.5f
, -0.5f
}}, /* A2 */
132 {{ 0.5f
, -0.5f
, 0.5f
, -0.5f
}} /* A3 */
135 /* Converts (W-normalized) A-Format to B-Format for early reflections (scaled
136 * by 1/sqrt(3) to compensate for the boost in the B2A matrix).
138 alignas(16) constexpr std::array
<std::array
<float,NUM_LINES
>,NUM_LINES
> EarlyA2B
{{
140 {{ 0.5f
, 0.5f
, 0.5f
, 0.5f
}}, /* W */
141 {{ 0.5f
, -0.5f
, 0.5f
, -0.5f
}}, /* Y */
142 {{ 0.5f
, -0.5f
, -0.5f
, 0.5f
}}, /* Z */
143 {{ 0.5f
, 0.5f
, -0.5f
, -0.5f
}} /* X */
146 /* Converts (W-normalized) A-Format to B-Format for late reverb (scaled
147 * by 1/sqrt(3) to compensate for the boost in the B2A matrix). The response
148 * is rotated around Z (ambisonic X) so that the front lines are placed
149 * horizontally in front, and the rear lines are placed vertically in back.
151 constexpr auto InvSqrt2
= static_cast<float>(1.0/al::numbers::sqrt2
);
152 alignas(16) constexpr std::array
<std::array
<float,NUM_LINES
>,NUM_LINES
> LateA2B
{{
154 {{ 0.5f
, 0.5f
, 0.5f
, 0.5f
}}, /* W */
155 {{ InvSqrt2
, -InvSqrt2
, 0.0f
, 0.0f
}}, /* Y */
156 {{ 0.0f
, 0.0f
, -InvSqrt2
, InvSqrt2
}}, /* Z */
157 {{ 0.5f
, 0.5f
, -0.5f
, -0.5f
}} /* X */
160 /* The all-pass and delay lines have a variable length dependent on the
161 * effect's density parameter, which helps alter the perceived environment
162 * size. The size-to-density conversion is a cubed scale:
164 * density = min(1.0, pow(size, 3.0) / DENSITY_SCALE);
166 * The line lengths scale linearly with room size, so the inverse density
167 * conversion is needed, taking the cube root of the re-scaled density to
168 * calculate the line length multiplier:
170 * length_mult = max(5.0, cbrt(density*DENSITY_SCALE));
172 * The density scale below will result in a max line multiplier of 50, for an
173 * effective size range of 5m to 50m.
175 constexpr float DENSITY_SCALE
{125000.0f
};
177 /* All delay line lengths are specified in seconds.
179 * To approximate early reflections, we break them up into primary (those
180 * arriving from the same direction as the source) and secondary (those
181 * arriving from the opposite direction).
183 * The early taps decorrelate the 4-channel signal to approximate an average
184 * room response for the primary reflections after the initial early delay.
186 * Given an average room dimension (d_a) and the speed of sound (c) we can
187 * calculate the average reflection delay (r_a) regardless of listener and
188 * source positions as:
193 * This can extended to finding the average difference (r_d) between the
194 * maximum (r_1) and minimum (r_0) reflection delays:
205 * As can be determined by integrating the 1D model with a source (s) and
206 * listener (l) positioned across the dimension of length (d_a):
208 * r_d = int_(l=0)^d_a (int_(s=0)^d_a |2 d_a - 2 (l + s)| ds) dl / c
210 * The initial taps (T_(i=0)^N) are then specified by taking a power series
211 * that ranges between r_0 and half of r_1 less r_0:
213 * R_i = 2^(i / (2 N - 1)) r_d
214 * = r_0 + (2^(i / (2 N - 1)) - 1) r_d
217 * = (2^(i / (2 N - 1)) - 1) r_d
219 * Assuming an average of 1m, we get the following taps:
221 constexpr std::array
<float,NUM_LINES
> EARLY_TAP_LENGTHS
{{
222 0.0000000e+0f
, 2.0213520e-4f
, 4.2531060e-4f
, 6.7171600e-4f
225 /* The early all-pass filter lengths are based on the early tap lengths:
229 * Where a is the approximate maximum all-pass cycle limit (20).
231 constexpr std::array
<float,NUM_LINES
> EARLY_ALLPASS_LENGTHS
{{
232 9.7096800e-5f
, 1.0720356e-4f
, 1.1836234e-4f
, 1.3068260e-4f
235 /* The early delay lines are used to transform the primary reflections into
236 * the secondary reflections. The A-format is arranged in such a way that
237 * the channels/lines are spatially opposite:
239 * C_i is opposite C_(N-i-1)
241 * The delays of the two opposing reflections (R_i and O_i) from a source
242 * anywhere along a particular dimension always sum to twice its full delay:
246 * With that in mind we can determine the delay between the two reflections
247 * and thus specify our early line lengths (L_(i=0)^N) using:
249 * O_i = 2 r_a - R_(N-i-1)
250 * L_i = O_i - R_(N-i-1)
251 * = 2 (r_a - R_(N-i-1))
252 * = 2 (r_a - T_(N-i-1) - r_0)
253 * = 2 r_a (1 - (2 / 3) 2^((N - i - 1) / (2 N - 1)))
255 * Using an average dimension of 1m, we get:
257 constexpr std::array
<float,NUM_LINES
> EARLY_LINE_LENGTHS
{{
258 0.0000000e+0f
, 4.9281100e-4f
, 9.3916180e-4f
, 1.3434322e-3f
261 /* The late all-pass filter lengths are based on the late line lengths:
263 * A_i = (5 / 3) L_i / r_1
265 constexpr std::array
<float,NUM_LINES
> LATE_ALLPASS_LENGTHS
{{
266 1.6182800e-4f
, 2.0389060e-4f
, 2.8159360e-4f
, 3.2365600e-4f
269 /* The late lines are used to approximate the decaying cycle of recursive
272 * Splitting the lines in half, we start with the shortest reflection paths
275 * L_i = 2^(i / (N - 1)) r_d
277 * Then for the opposite (longest) reflection paths (L_(i=N/2)^N):
279 * L_i = 2 r_a - L_(i-N/2)
280 * = 2 r_a - 2^((i - N / 2) / (N - 1)) r_d
282 * For our 1m average room, we get:
284 constexpr std::array
<float,NUM_LINES
> LATE_LINE_LENGTHS
{{
285 1.9419362e-3f
, 2.4466860e-3f
, 3.3791220e-3f
, 3.8838720e-3f
289 using ReverbUpdateLine
= std::array
<float,MAX_UPDATE_SAMPLES
>;
292 /* The delay lines use interleaved samples, with the lengths being powers
293 * of 2 to allow the use of bit-masking instead of a modulus for wrapping.
298 /* Given the allocated sample buffer, this function updates each delay line
301 void realizeLineOffset(float *sampleBuffer
) noexcept
302 { Line
= sampleBuffer
; }
304 /* Calculate the length of a delay line and store its mask and offset. */
305 size_t calcLineLength(const float length
, const float frequency
, const uint extra
)
307 /* All line lengths are powers of 2, calculated from their lengths in
308 * seconds, rounded up.
310 uint samples
{float2uint(std::ceil(length
*frequency
))};
311 samples
= NextPowerOf2(samples
+ extra
);
313 /* All lines share a single sample buffer. */
316 /* Return the sample count for accumulation. */
317 return samples
*NUM_LINES
;
321 auto &get(size_t i
, size_t chan
) const noexcept
{ return Line
[i
*NUM_LINES
+ chan
]; }
322 void set(size_t i
, const std::array
<float,NUM_LINES
> in
) const noexcept
323 { std::copy_n(in
.begin(), NUM_LINES
, Line
+ i
*NUM_LINES
); }
330 void realizeLineOffset(float *sampleBuffer
) noexcept
331 { Line
= sampleBuffer
; }
333 size_t calcLineLength(const float length
, const float frequency
, const uint extra
)
335 uint samples
{float2uint(std::ceil(length
*frequency
))};
336 samples
= NextPowerOf2(samples
+ extra
);
340 return samples
*NUM_LINES
;
344 auto get(size_t chan
) const noexcept
{ return al::span
{Line
+ chan
*(Mask
+1), Mask
+1}; }
346 void write(size_t offset
, const size_t c
, const float *in
, const size_t count
) const noexcept
349 float *RESTRICT out
{al::assume_aligned
<16>(Line
+ c
*(Mask
+1))};
350 for(size_t i
{0u};i
< count
;)
353 const size_t td
{std::min(Mask
+1 - offset
, count
- i
)};
354 std::copy_n(in
+i
, td
, out
+offset
);
360 /* Writes the given input lines to the delay buffer, applying a geometric
361 * reflection. This effectively applies the matrix
363 * [ +1/2 -1/2 -1/2 -1/2 ]
364 * [ -1/2 +1/2 -1/2 -1/2 ]
365 * [ -1/2 -1/2 +1/2 -1/2 ]
366 * [ -1/2 -1/2 -1/2 +1/2 ]
368 * to the four input lines when writing to the delay buffer. The effect on
369 * the B-Format signal is negating W, applying a 180-degree phase shift and
370 * moving each response to its spatially opposite location.
372 void writeReflected(size_t offset
, const al::span
<const ReverbUpdateLine
,NUM_LINES
> in
,
373 const size_t count
) const noexcept
375 const size_t stride
{Mask
+1};
377 for(size_t i
{0u};i
< count
;)
380 size_t td
{std::min(Mask
+1 - offset
, count
- i
)};
382 const std::array src
{in
[0][i
], in
[1][i
], in
[2][i
], in
[3][i
]};
386 (src
[0] - src
[1] - src
[2] - src
[3]) * 0.5f
,
387 (src
[1] - src
[0] - src
[2] - src
[3]) * 0.5f
,
388 (src
[2] - src
[0] - src
[1] - src
[3]) * 0.5f
,
389 (src
[3] - src
[0] - src
[1] - src
[2] ) * 0.5f
391 Line
[0*stride
+ offset
] = f
[0];
392 Line
[1*stride
+ offset
] = f
[1];
393 Line
[2*stride
+ offset
] = f
[2];
394 Line
[3*stride
+ offset
] = f
[3];
404 std::array
<size_t,NUM_LINES
> Offset
{};
406 void process(const al::span
<ReverbUpdateLine
,NUM_LINES
> samples
, size_t offset
,
407 const float xCoeff
, const float yCoeff
, const size_t todo
) noexcept
;
413 std::array
<size_t,NUM_LINES
> Offset
{};
415 void process(const al::span
<ReverbUpdateLine
,NUM_LINES
> samples
, const size_t offset
,
416 const size_t todo
) noexcept
;
420 /* Two filters are used to adjust the signal. One to control the low
421 * frequencies, and one to control the high frequencies.
424 BiquadFilter HFFilter
, LFFilter
;
426 void calcCoeffs(const float length
, const float lfDecayTime
, const float mfDecayTime
,
427 const float hfDecayTime
, const float lf0norm
, const float hf0norm
);
429 /* Applies the two T60 damping filter sections. */
430 void process(const al::span
<float> samples
)
431 { DualBiquad
{HFFilter
, LFFilter
}.process(samples
, samples
.data()); }
433 void clear() noexcept
{ HFFilter
.clear(); LFFilter
.clear(); }
436 struct EarlyReflections
{
439 /* An echo line is used to complete the second half of the early
443 std::array
<size_t,NUM_LINES
> Offset
{};
444 std::array
<float,NUM_LINES
> Coeff
{};
446 /* The gain for each output channel based on 3D panning. */
448 std::array
<float,MaxAmbiChannels
> Current
{};
449 std::array
<float,MaxAmbiChannels
> Target
{};
451 std::array
<OutGains
,NUM_LINES
> Gains
{};
453 void updateLines(const float density_mult
, const float diffusion
, const float decayTime
,
454 const float frequency
);
459 /* The vibrato time is tracked with an index over a (MOD_FRACONE)
462 uint Index
{}, Step
{};
464 /* The depth of frequency change, in samples. */
467 std::array
<uint
,MAX_UPDATE_SAMPLES
> ModDelays
{};
469 void updateModulator(float modTime
, float modDepth
, float frequency
);
471 void calcDelays(size_t todo
);
475 /* A recursive delay line is used fill in the reverb tail. */
477 std::array
<size_t,NUM_LINES
> Offset
{};
479 /* Attenuation to compensate for the modal density and decay rate of the
482 float DensityGain
{0.0f
};
484 /* T60 decay filters are used to simulate absorption. */
485 std::array
<T60Filter
,NUM_LINES
> T60
;
489 /* A Gerzon vector all-pass filter is used to simulate diffusion. */
492 /* The gain for each output channel based on 3D panning. */
494 std::array
<float,MaxAmbiChannels
> Current
{};
495 std::array
<float,MaxAmbiChannels
> Target
{};
497 std::array
<OutGains
,NUM_LINES
> Gains
{};
499 void updateLines(const float density_mult
, const float diffusion
, const float lfDecayTime
,
500 const float mfDecayTime
, const float hfDecayTime
, const float lf0norm
,
501 const float hf0norm
, const float frequency
);
503 void clear() noexcept
505 for(auto &filter
: T60
)
510 struct ReverbPipeline
{
511 /* Master effect filters */
516 std::array
<FilterPair
,NUM_LINES
> mFilter
;
518 /* Late reverb input delay line (early reflections feed this, and late
519 * reverb taps from it).
521 DelayLineU mLateDelayIn
;
523 /* Tap points for early reflection input delay. */
524 std::array
<std::array
<size_t,2>,NUM_LINES
> mEarlyDelayTap
{};
525 std::array
<std::array
<float,2>,NUM_LINES
> mEarlyDelayCoeff
{};
527 /* Tap points for late reverb feed and delay. */
528 std::array
<std::array
<size_t,2>,NUM_LINES
> mLateDelayTap
{};
530 /* Coefficients for the all-pass and line scattering matrices. */
534 EarlyReflections mEarly
;
538 std::array
<std::array
<BandSplitter
,NUM_LINES
>,2> mAmbiSplitter
;
540 size_t mFadeSampleCount
{1};
542 void updateDelayLine(const float gain
, const float earlyDelay
, const float lateDelay
,
543 const float density_mult
, const float decayTime
, const float frequency
);
544 void update3DPanning(const al::span
<const float,3> ReflectionsPan
,
545 const al::span
<const float,3> LateReverbPan
, const float earlyGain
, const float lateGain
,
546 const bool doUpmix
, const MixParams
*mainMix
);
548 void processEarly(const DelayLineU
&main_delay
, size_t offset
, const size_t samplesToDo
,
549 const al::span
<ReverbUpdateLine
,NUM_LINES
> tempSamples
,
550 const al::span
<FloatBufferLine
,NUM_LINES
> outSamples
);
551 void processLate(size_t offset
, const size_t samplesToDo
,
552 const al::span
<ReverbUpdateLine
,NUM_LINES
> tempSamples
,
553 const al::span
<FloatBufferLine
,NUM_LINES
> outSamples
);
555 void clear() noexcept
557 for(auto &filter
: mFilter
)
563 for(auto &filters
: mAmbiSplitter
)
565 for(auto &filter
: filters
)
571 struct ReverbState final
: public EffectState
{
572 /* All delay lines are allocated as a single buffer to reduce memory
573 * fragmentation and management code.
575 al::vector
<float,16> mSampleBuffer
;
578 /* Calculated parameters which indicate if cross-fading is needed after
582 float Diffusion
{1.0f
};
583 float DecayTime
{1.49f
};
584 float HFDecayTime
{0.83f
* 1.49f
};
585 float LFDecayTime
{1.0f
* 1.49f
};
586 float ModulationTime
{0.25f
};
587 float ModulationDepth
{0.0f
};
588 float HFReference
{5000.0f
};
589 float LFReference
{250.0f
};
592 enum PipelineState
: uint8_t {
599 PipelineState mPipelineState
{DeviceClear
};
600 bool mCurrentPipeline
{false};
602 /* Core delay line (early reflections tap from this). */
603 DelayLineU mMainDelay
;
605 std::array
<ReverbPipeline
,2> mPipelines
;
607 /* The current write offset for all delay lines. */
610 /* Temporary storage used when processing. */
611 alignas(16) FloatBufferLine mTempLine
{};
612 alignas(16) std::array
<ReverbUpdateLine
,NUM_LINES
> mTempSamples
{};
614 alignas(16) std::array
<FloatBufferLine
,NUM_LINES
> mEarlySamples
{};
615 alignas(16) std::array
<FloatBufferLine
,NUM_LINES
> mLateSamples
{};
617 std::array
<float,MaxAmbiOrder
+1> mOrderScales
{};
619 bool mUpmixOutput
{false};
622 void MixOutPlain(ReverbPipeline
&pipeline
, const al::span
<FloatBufferLine
> samplesOut
,
623 const size_t todo
) const
627 /* When not upsampling, the panning gains convert to B-Format and pan
630 auto inBuffer
= mEarlySamples
.cbegin();
631 for(auto &gains
: pipeline
.mEarly
.Gains
)
633 MixSamples(al::span
{inBuffer
->cbegin(), todo
}, samplesOut
, gains
.Current
.data(),
634 gains
.Target
.data(), todo
, 0);
637 inBuffer
= mLateSamples
.cbegin();
638 for(auto &gains
: pipeline
.mLate
.Gains
)
640 MixSamples(al::span
{inBuffer
->cbegin(), todo
}, samplesOut
, gains
.Current
.data(),
641 gains
.Target
.data(), todo
, 0);
646 void MixOutAmbiUp(ReverbPipeline
&pipeline
, const al::span
<FloatBufferLine
> samplesOut
,
651 auto DoMixRow
= [](const al::span
<float> OutBuffer
, const al::span
<const float,4> Gains
,
652 const al::span
<const FloatBufferLine
,4> InSamples
)
654 auto inBuffer
= InSamples
.cbegin();
655 std::fill(OutBuffer
.begin(), OutBuffer
.end(), 0.0f
);
656 for(const float gain
: Gains
)
658 const float *RESTRICT input
{al::assume_aligned
<16>(inBuffer
->data())};
661 if(!(std::fabs(gain
) > GainSilenceThreshold
))
664 auto mix_sample
= [gain
](const float sample
, const float in
) noexcept
-> float
665 { return sample
+ in
*gain
; };
666 std::transform(OutBuffer
.begin(), OutBuffer
.end(), input
, OutBuffer
.begin(),
671 /* When upsampling, the B-Format conversion needs to be done separately
672 * so the proper HF scaling can be applied to each B-Format channel.
673 * The panning gains then pan and upsample the B-Format channels.
675 const al::span
<float> tmpspan
{al::assume_aligned
<16>(mTempLine
.data()), todo
};
676 float hfscale
{mOrderScales
[0]};
677 auto splitter
= pipeline
.mAmbiSplitter
[0].begin();
678 auto a2bcoeffs
= EarlyA2B
.cbegin();
679 for(auto &gains
: pipeline
.mEarly
.Gains
)
681 DoMixRow(tmpspan
, *(a2bcoeffs
++), mEarlySamples
);
683 /* Apply scaling to the B-Format's HF response to "upsample" it to
684 * higher-order output.
686 splitter
->processHfScale(tmpspan
, hfscale
);
687 ++splitter
; hfscale
= mOrderScales
[1];
689 MixSamples(tmpspan
, samplesOut
, gains
.Current
.data(), gains
.Target
.data(), todo
, 0);
691 hfscale
= mOrderScales
[0];
692 splitter
= pipeline
.mAmbiSplitter
[1].begin();
693 a2bcoeffs
= LateA2B
.cbegin();
694 for(auto &gains
: pipeline
.mLate
.Gains
)
696 DoMixRow(tmpspan
, *(a2bcoeffs
++), mLateSamples
);
698 splitter
->processHfScale(tmpspan
, hfscale
);
699 ++splitter
; hfscale
= mOrderScales
[1];
701 MixSamples(tmpspan
, samplesOut
, gains
.Current
.data(), gains
.Target
.data(), todo
, 0);
705 void mixOut(ReverbPipeline
&pipeline
, const al::span
<FloatBufferLine
> samplesOut
, const size_t todo
)
708 MixOutAmbiUp(pipeline
, samplesOut
, todo
);
710 MixOutPlain(pipeline
, samplesOut
, todo
);
713 void allocLines(const float frequency
);
715 void deviceUpdate(const DeviceBase
*device
, const BufferStorage
*buffer
) override
;
716 void update(const ContextBase
*context
, const EffectSlot
*slot
, const EffectProps
*props
,
717 const EffectTarget target
) override
;
718 void process(const size_t samplesToDo
, const al::span
<const FloatBufferLine
> samplesIn
,
719 const al::span
<FloatBufferLine
> samplesOut
) override
;
722 /**************************************
724 **************************************/
726 inline float CalcDelayLengthMult(float density
)
727 { return std::max(5.0f
, std::cbrt(density
*DENSITY_SCALE
)); }
729 /* Calculates the delay line metrics and allocates the shared sample buffer
730 * for all lines given the sample rate (frequency).
732 void ReverbState::allocLines(const float frequency
)
734 /* Multiplier for the maximum density value, i.e. density=1, which is
735 * actually the least density...
737 const float multiplier
{CalcDelayLengthMult(1.0f
)};
739 /* The modulator's line length is calculated from the maximum modulation
740 * time and depth coefficient, and halfed for the low-to-high frequency
743 static constexpr float max_mod_delay
{MaxModulationTime
*MODULATION_DEPTH_COEFF
/ 2.0f
};
745 std::array
<size_t,11> lineoffsets
{};
748 size_t totalSamples
{0u};
749 /* The main delay length includes the maximum early reflection delay and
750 * the largest early tap width. It must also be extended by the update size
751 * (BufferLineSize) for block processing.
753 float length
{ReverbMaxReflectionsDelay
+ EARLY_TAP_LENGTHS
.back()*multiplier
};
754 size_t count
{mMainDelay
.calcLineLength(length
, frequency
, BufferLineSize
)};
755 lineoffsets
[oidx
++] = totalSamples
;
756 totalSamples
+= count
;
757 for(auto &pipeline
: mPipelines
)
759 static constexpr float LateDiffAvg
{(LATE_LINE_LENGTHS
.back()-LATE_LINE_LENGTHS
.front()) /
761 length
= ReverbMaxLateReverbDelay
+ LateDiffAvg
*multiplier
;
762 count
= pipeline
.mLateDelayIn
.calcLineLength(length
, frequency
, BufferLineSize
);
763 lineoffsets
[oidx
++] = totalSamples
;
764 totalSamples
+= count
;
766 /* The early vector all-pass line. */
767 length
= EARLY_ALLPASS_LENGTHS
.back() * multiplier
;
768 count
= pipeline
.mEarly
.VecAp
.Delay
.calcLineLength(length
, frequency
, 0);
769 lineoffsets
[oidx
++] = totalSamples
;
770 totalSamples
+= count
;
772 /* The early reflection line. */
773 length
= EARLY_LINE_LENGTHS
.back() * multiplier
;
774 count
= pipeline
.mEarly
.Delay
.calcLineLength(length
, frequency
, MAX_UPDATE_SAMPLES
);
775 lineoffsets
[oidx
++] = totalSamples
;
776 totalSamples
+= count
;
778 /* The late vector all-pass line. */
779 length
= LATE_ALLPASS_LENGTHS
.back() * multiplier
;
780 count
= pipeline
.mLate
.VecAp
.Delay
.calcLineLength(length
, frequency
, 0);
781 lineoffsets
[oidx
++] = totalSamples
;
782 totalSamples
+= count
;
784 /* The late delay lines are calculated from the largest maximum density
785 * line length, and the maximum modulation delay. Four additional
786 * samples are needed for resampling the modulator delay.
788 length
= LATE_LINE_LENGTHS
.back()*multiplier
+ max_mod_delay
;
789 count
= pipeline
.mLate
.Delay
.calcLineLength(length
, frequency
, 4);
790 lineoffsets
[oidx
++] = totalSamples
;
791 totalSamples
+= count
;
793 assert(oidx
== lineoffsets
.size());
795 if(totalSamples
!= mSampleBuffer
.size())
796 decltype(mSampleBuffer
)(totalSamples
).swap(mSampleBuffer
);
798 /* Clear the sample buffer. */
799 std::fill(mSampleBuffer
.begin(), mSampleBuffer
.end(), decltype(mSampleBuffer
)::value_type
{});
801 /* Update all delays to reflect the new sample buffer. */
803 mMainDelay
.realizeLineOffset(mSampleBuffer
.data() + lineoffsets
[oidx
++]);
804 for(auto &pipeline
: mPipelines
)
806 pipeline
.mLateDelayIn
.realizeLineOffset(mSampleBuffer
.data() + lineoffsets
[oidx
++]);
807 pipeline
.mEarly
.VecAp
.Delay
.realizeLineOffset(mSampleBuffer
.data() + lineoffsets
[oidx
++]);
808 pipeline
.mEarly
.Delay
.realizeLineOffset(mSampleBuffer
.data() + lineoffsets
[oidx
++]);
809 pipeline
.mLate
.VecAp
.Delay
.realizeLineOffset(mSampleBuffer
.data() + lineoffsets
[oidx
++]);
810 pipeline
.mLate
.Delay
.realizeLineOffset(mSampleBuffer
.data() + lineoffsets
[oidx
++]);
814 void ReverbState::deviceUpdate(const DeviceBase
*device
, const BufferStorage
*)
816 const auto frequency
= static_cast<float>(device
->Frequency
);
818 /* Allocate the delay lines. */
819 allocLines(frequency
);
821 for(auto &pipeline
: mPipelines
)
823 /* Clear filters and gain coefficients since the delay lines were all
824 * just cleared (if not reallocated).
826 for(auto &filter
: pipeline
.mFilter
)
832 for(auto &coeffs
: pipeline
.mEarlyDelayCoeff
)
835 pipeline
.mLate
.DensityGain
= 0.0f
;
836 for(auto &t60
: pipeline
.mLate
.T60
)
839 t60
.HFFilter
.clear();
840 t60
.LFFilter
.clear();
843 pipeline
.mLate
.Mod
.Index
= 0;
844 pipeline
.mLate
.Mod
.Step
= 1;
845 pipeline
.mLate
.Mod
.Depth
= 0.0f
;
847 for(auto &gains
: pipeline
.mEarly
.Gains
)
849 gains
.Current
.fill(0.0f
);
850 gains
.Target
.fill(0.0f
);
852 for(auto &gains
: pipeline
.mLate
.Gains
)
854 gains
.Current
.fill(0.0f
);
855 gains
.Target
.fill(0.0f
);
858 mPipelineState
= DeviceClear
;
860 /* Reset offset base. */
863 if(device
->mAmbiOrder
> 1)
866 mOrderScales
= AmbiScale::GetHFOrderScales(1, device
->mAmbiOrder
, device
->m2DMixing
);
870 mUpmixOutput
= false;
871 mOrderScales
.fill(1.0f
);
873 mPipelines
[0].mAmbiSplitter
[0][0].init(device
->mXOverFreq
/ frequency
);
874 for(auto &pipeline
: mPipelines
)
876 std::fill(pipeline
.mAmbiSplitter
[0].begin(), pipeline
.mAmbiSplitter
[0].end(),
877 pipeline
.mAmbiSplitter
[0][0]);
878 std::fill(pipeline
.mAmbiSplitter
[1].begin(), pipeline
.mAmbiSplitter
[1].end(),
879 pipeline
.mAmbiSplitter
[0][0]);
883 /**************************************
885 **************************************/
887 /* Calculate a decay coefficient given the length of each cycle and the time
888 * until the decay reaches -60 dB.
890 inline float CalcDecayCoeff(const float length
, const float decayTime
)
891 { return std::pow(ReverbDecayGain
, length
/decayTime
); }
893 /* Calculate a decay length from a coefficient and the time until the decay
896 inline float CalcDecayLength(const float coeff
, const float decayTime
)
898 constexpr float log10_decaygain
{-3.0f
/*std::log10(ReverbDecayGain)*/};
899 return std::log10(coeff
) * decayTime
/ log10_decaygain
;
902 /* Calculate an attenuation to be applied to the input of any echo models to
903 * compensate for modal density and decay time.
905 inline float CalcDensityGain(const float a
)
907 /* The energy of a signal can be obtained by finding the area under the
908 * squared signal. This takes the form of Sum(x_n^2), where x is the
909 * amplitude for the sample n.
911 * Decaying feedback matches exponential decay of the form Sum(a^n),
912 * where a is the attenuation coefficient, and n is the sample. The area
913 * under this decay curve can be calculated as: 1 / (1 - a).
915 * Modifying the above equation to find the area under the squared curve
916 * (for energy) yields: 1 / (1 - a^2). Input attenuation can then be
917 * calculated by inverting the square root of this approximation,
918 * yielding: 1 / sqrt(1 / (1 - a^2)), simplified to: sqrt(1 - a^2).
920 return std::sqrt(1.0f
- a
*a
);
923 /* Calculate the scattering matrix coefficients given a diffusion factor. */
924 inline void CalcMatrixCoeffs(const float diffusion
, float *x
, float *y
)
926 /* The matrix is of order 4, so n is sqrt(4 - 1). */
927 constexpr float n
{al::numbers::sqrt3_v
<float>};
928 const float t
{diffusion
* std::atan(n
)};
930 /* Calculate the first mixing matrix coefficient. */
932 /* Calculate the second mixing matrix coefficient. */
933 *y
= std::sin(t
) / n
;
936 /* Calculate the limited HF ratio for use with the late reverb low-pass
939 float CalcLimitedHfRatio(const float hfRatio
, const float airAbsorptionGainHF
,
940 const float decayTime
)
942 /* Find the attenuation due to air absorption in dB (converting delay
943 * time to meters using the speed of sound). Then reversing the decay
944 * equation, solve for HF ratio. The delay length is cancelled out of
945 * the equation, so it can be calculated once for all lines.
947 float limitRatio
{1.0f
/ SpeedOfSoundMetersPerSec
/
948 CalcDecayLength(airAbsorptionGainHF
, decayTime
)};
950 /* Using the limit calculated above, apply the upper bound to the HF ratio. */
951 return std::min(limitRatio
, hfRatio
);
955 /* Calculates the 3-band T60 damping coefficients for a particular delay line
956 * of specified length, using a combination of two shelf filter sections given
957 * decay times for each band split at two reference frequencies.
959 void T60Filter::calcCoeffs(const float length
, const float lfDecayTime
,
960 const float mfDecayTime
, const float hfDecayTime
, const float lf0norm
,
963 const float mfGain
{CalcDecayCoeff(length
, mfDecayTime
)};
964 const float lfGain
{CalcDecayCoeff(length
, lfDecayTime
) / mfGain
};
965 const float hfGain
{CalcDecayCoeff(length
, hfDecayTime
) / mfGain
};
968 LFFilter
.setParamsFromSlope(BiquadType::LowShelf
, lf0norm
, lfGain
, 1.0f
);
969 HFFilter
.setParamsFromSlope(BiquadType::HighShelf
, hf0norm
, hfGain
, 1.0f
);
972 /* Update the early reflection line lengths and gain coefficients. */
973 void EarlyReflections::updateLines(const float density_mult
, const float diffusion
,
974 const float decayTime
, const float frequency
)
976 /* Calculate the all-pass feed-back/forward coefficient. */
977 VecAp
.Coeff
= diffusion
*diffusion
* InvSqrt2
;
979 for(size_t i
{0u};i
< NUM_LINES
;i
++)
981 /* Calculate the delay length of each all-pass line. */
982 float length
{EARLY_ALLPASS_LENGTHS
[i
] * density_mult
};
983 VecAp
.Offset
[i
] = float2uint(length
* frequency
);
985 /* Calculate the delay length of each delay line. */
986 length
= EARLY_LINE_LENGTHS
[i
] * density_mult
;
987 Offset
[i
] = float2uint(length
* frequency
);
989 /* Calculate the gain (coefficient) for each line. */
990 Coeff
[i
] = CalcDecayCoeff(length
, decayTime
);
994 /* Update the EAX modulation step and depth. Keep in mind that this kind of
995 * vibrato is additive and not multiplicative as one may expect. The downswing
996 * will sound stronger than the upswing.
998 void Modulation::updateModulator(float modTime
, float modDepth
, float frequency
)
1000 /* Modulation is calculated in two parts.
1002 * The modulation time effects the sinus rate, altering the speed of
1003 * frequency changes. An index is incremented for each sample with an
1004 * appropriate step size to generate an LFO, which will vary the feedback
1007 Step
= std::max(fastf2u(MOD_FRACONE
/ (frequency
* modTime
)), 1u);
1009 /* The modulation depth effects the amount of frequency change over the
1010 * range of the sinus. It needs to be scaled by the modulation time so that
1011 * a given depth produces a consistent change in frequency over all ranges
1012 * of time. Since the depth is applied to a sinus value, it needs to be
1013 * halved once for the sinus range and again for the sinus swing in time
1014 * (half of it is spent decreasing the frequency, half is spent increasing
1017 if(modTime
>= DefaultModulationTime
)
1019 /* To cancel the effects of a long period modulation on the late
1020 * reverberation, the amount of pitch should be varied (decreased)
1021 * according to the modulation time. The natural form is varying
1022 * inversely, in fact resulting in an invariant.
1024 Depth
= MODULATION_DEPTH_COEFF
/ 4.0f
* DefaultModulationTime
* modDepth
* frequency
;
1027 Depth
= MODULATION_DEPTH_COEFF
/ 4.0f
* modTime
* modDepth
* frequency
;
1030 /* Update the late reverb line lengths and T60 coefficients. */
1031 void LateReverb::updateLines(const float density_mult
, const float diffusion
,
1032 const float lfDecayTime
, const float mfDecayTime
, const float hfDecayTime
,
1033 const float lf0norm
, const float hf0norm
, const float frequency
)
1035 /* Scaling factor to convert the normalized reference frequencies from
1036 * representing 0...freq to 0...max_reference.
1038 constexpr float MaxHFReference
{20000.0f
};
1039 const float norm_weight_factor
{frequency
/ MaxHFReference
};
1041 const float late_allpass_avg
{
1042 std::accumulate(LATE_ALLPASS_LENGTHS
.begin(), LATE_ALLPASS_LENGTHS
.end(), 0.0f
) /
1045 /* To compensate for changes in modal density and decay time of the late
1046 * reverb signal, the input is attenuated based on the maximal energy of
1047 * the outgoing signal. This approximation is used to keep the apparent
1048 * energy of the signal equal for all ranges of density and decay time.
1050 * The average length of the delay lines is used to calculate the
1051 * attenuation coefficient.
1053 float length
{std::accumulate(LATE_LINE_LENGTHS
.begin(), LATE_LINE_LENGTHS
.end(), 0.0f
) /
1054 float{NUM_LINES
} + late_allpass_avg
};
1055 length
*= density_mult
;
1056 /* The density gain calculation uses an average decay time weighted by
1057 * approximate bandwidth. This attempts to compensate for losses of energy
1058 * that reduce decay time due to scattering into highly attenuated bands.
1060 const float decayTimeWeighted
{
1061 lf0norm
*norm_weight_factor
*lfDecayTime
+
1062 (hf0norm
- lf0norm
)*norm_weight_factor
*mfDecayTime
+
1063 (1.0f
- hf0norm
*norm_weight_factor
)*hfDecayTime
};
1064 DensityGain
= CalcDensityGain(CalcDecayCoeff(length
, decayTimeWeighted
));
1066 /* Calculate the all-pass feed-back/forward coefficient. */
1067 VecAp
.Coeff
= diffusion
*diffusion
* InvSqrt2
;
1069 for(size_t i
{0u};i
< NUM_LINES
;i
++)
1071 /* Calculate the delay length of each all-pass line. */
1072 length
= LATE_ALLPASS_LENGTHS
[i
] * density_mult
;
1073 VecAp
.Offset
[i
] = float2uint(length
* frequency
);
1075 /* Calculate the delay length of each feedback delay line. A cubic
1076 * resampler is used for modulation on the feedback delay, which
1077 * includes one sample of delay. Reduce by one to compensate.
1079 length
= LATE_LINE_LENGTHS
[i
] * density_mult
;
1080 Offset
[i
] = std::max(float2uint(length
*frequency
+ 0.5f
), 1u) - 1u;
1082 /* Approximate the absorption that the vector all-pass would exhibit
1083 * given the current diffusion so we don't have to process a full T60
1084 * filter for each of its four lines. Also include the average
1085 * modulation delay (depth is half the max delay in samples).
1087 length
+= lerpf(LATE_ALLPASS_LENGTHS
[i
], late_allpass_avg
, diffusion
)*density_mult
+
1088 Mod
.Depth
/frequency
;
1090 /* Calculate the T60 damping coefficients for each line. */
1091 T60
[i
].calcCoeffs(length
, lfDecayTime
, mfDecayTime
, hfDecayTime
, lf0norm
, hf0norm
);
1096 /* Update the offsets for the main effect delay line. */
1097 void ReverbPipeline::updateDelayLine(const float gain
, const float earlyDelay
,
1098 const float lateDelay
, const float density_mult
, const float decayTime
, const float frequency
)
1100 /* Early reflection taps are decorrelated by means of an average room
1101 * reflection approximation described above the definition of the taps.
1102 * This approximation is linear and so the above density multiplier can
1103 * be applied to adjust the width of the taps. A single-band decay
1104 * coefficient is applied to simulate initial attenuation and absorption.
1106 * Late reverb taps are based on the late line lengths to allow a zero-
1107 * delay path and offsets that would continue the propagation naturally
1108 * into the late lines.
1110 for(size_t i
{0u};i
< NUM_LINES
;i
++)
1112 float length
{EARLY_TAP_LENGTHS
[i
]*density_mult
};
1113 mEarlyDelayTap
[i
][1] = float2uint((earlyDelay
+length
) * frequency
);
1114 mEarlyDelayCoeff
[i
][1] = CalcDecayCoeff(length
, decayTime
) * gain
;
1116 /* Reduce the late delay tap by the shortest early delay line length to
1117 * compensate for the late line input being fed by the delayed early
1120 length
= (LATE_LINE_LENGTHS
[i
] - LATE_LINE_LENGTHS
.front())/float{NUM_LINES
}*density_mult
+
1122 mLateDelayTap
[i
][1] = float2uint(length
* frequency
);
1126 /* Creates a transform matrix given a reverb vector. The vector pans the reverb
1127 * reflections toward the given direction, using its magnitude (up to 1) as a
1128 * focal strength. This function results in a B-Format transformation matrix
1129 * that spatially focuses the signal in the desired direction.
1131 std::array
<std::array
<float,4>,4> GetTransformFromVector(const al::span
<const float,3> vec
)
1133 /* Normalize the panning vector according to the N3D scale, which has an
1134 * extra sqrt(3) term on the directional components. Converting from OpenAL
1135 * to B-Format also requires negating X (ACN 1) and Z (ACN 3). Note however
1136 * that the reverb panning vectors use left-handed coordinates, unlike the
1137 * rest of OpenAL which use right-handed. This is fixed by negating Z,
1138 * which cancels out with the B-Format Z negation.
1140 std::array
<float,3> norm
;
1141 float mag
{std::sqrt(vec
[0]*vec
[0] + vec
[1]*vec
[1] + vec
[2]*vec
[2])};
1144 const float scale
{al::numbers::sqrt3_v
<float> / mag
};
1145 norm
[0] = vec
[0] * -scale
;
1146 norm
[1] = vec
[1] * scale
;
1147 norm
[2] = vec
[2] * scale
;
1152 /* If the magnitude is less than or equal to 1, just apply the sqrt(3)
1153 * term. There's no need to renormalize the magnitude since it would
1154 * just be reapplied in the matrix.
1156 norm
[0] = vec
[0] * -al::numbers::sqrt3_v
<float>;
1157 norm
[1] = vec
[1] * al::numbers::sqrt3_v
<float>;
1158 norm
[2] = vec
[2] * al::numbers::sqrt3_v
<float>;
1161 return std::array
<std::array
<float,4>,4>{{
1162 {{1.0f
, 0.0f
, 0.0f
, 0.0f
}},
1163 {{norm
[0], 1.0f
-mag
, 0.0f
, 0.0f
}},
1164 {{norm
[1], 0.0f
, 1.0f
-mag
, 0.0f
}},
1165 {{norm
[2], 0.0f
, 0.0f
, 1.0f
-mag
}}
1169 /* Update the early and late 3D panning gains. */
1170 void ReverbPipeline::update3DPanning(const al::span
<const float,3> ReflectionsPan
,
1171 const al::span
<const float,3> LateReverbPan
, const float earlyGain
, const float lateGain
,
1172 const bool doUpmix
, const MixParams
*mainMix
)
1174 /* Create matrices that transform a B-Format signal according to the
1177 const auto earlymat
= GetTransformFromVector(ReflectionsPan
);
1178 const auto latemat
= GetTransformFromVector(LateReverbPan
);
1180 const auto [earlycoeffs
, latecoeffs
] = [&]{
1183 /* When upsampling, combine the early and late transforms with the
1184 * first-order upsample matrix. This results in panning gains that
1185 * apply the panning transform to first-order B-Format, which is
1188 auto mult_matrix
= [](const al::span
<const std::array
<float,4>,4> mtx1
)
1190 std::array
<std::array
<float,MaxAmbiChannels
>,NUM_LINES
> res
{};
1191 const auto mtx2
= al::span
{AmbiScale::FirstOrderUp
};
1193 for(size_t i
{0};i
< mtx1
[0].size();++i
)
1195 const al::span dst
{res
[i
]};
1196 static_assert(dst
.size() >= std::tuple_size_v
<decltype(mtx2
)::element_type
>);
1197 for(size_t k
{0};k
< mtx1
.size();++k
)
1199 const float a
{mtx1
[k
][i
]};
1200 std::transform(mtx2
[k
].begin(), mtx2
[k
].end(), dst
.begin(), dst
.begin(),
1201 [a
](const float in
, const float out
) noexcept
-> float
1202 { return a
*in
+ out
; });
1208 return std::make_pair(mult_matrix(earlymat
), mult_matrix(latemat
));
1211 /* When not upsampling, combine the early and late A-to-B-Format
1212 * conversions with their respective transform. This results panning
1213 * gains that convert A-Format to B-Format, which is then panned.
1215 auto mult_matrix
= [](const al::span
<const std::array
<float,NUM_LINES
>,4> mtx1
,
1216 const al::span
<const std::array
<float,4>,4> mtx2
)
1218 std::array
<std::array
<float,MaxAmbiChannels
>,NUM_LINES
> res
{};
1220 for(size_t i
{0};i
< mtx1
[0].size();++i
)
1222 const al::span dst
{res
[i
]};
1223 static_assert(dst
.size() >= std::tuple_size_v
<decltype(mtx2
)::element_type
>);
1224 for(size_t k
{0};k
< mtx1
.size();++k
)
1226 const float a
{mtx1
[k
][i
]};
1227 std::transform(mtx2
[k
].begin(), mtx2
[k
].end(), dst
.begin(), dst
.begin(),
1228 [a
](const float in
, const float out
) noexcept
-> float
1229 { return a
*in
+ out
; });
1235 return std::make_pair(mult_matrix(EarlyA2B
, earlymat
), mult_matrix(LateA2B
, latemat
));
1238 auto earlygains
= mEarly
.Gains
.begin();
1239 for(auto &coeffs
: earlycoeffs
)
1240 ComputePanGains(mainMix
, coeffs
, earlyGain
, (earlygains
++)->Target
);
1241 auto lategains
= mLate
.Gains
.begin();
1242 for(auto &coeffs
: latecoeffs
)
1243 ComputePanGains(mainMix
, coeffs
, lateGain
, (lategains
++)->Target
);
1246 void ReverbState::update(const ContextBase
*Context
, const EffectSlot
*Slot
,
1247 const EffectProps
*props_
, const EffectTarget target
)
1249 auto &props
= std::get
<ReverbProps
>(*props_
);
1250 const DeviceBase
*Device
{Context
->mDevice
};
1251 const auto frequency
= static_cast<float>(Device
->Frequency
);
1253 /* If the HF limit parameter is flagged, calculate an appropriate limit
1254 * based on the air absorption parameter.
1256 float hfRatio
{props
.DecayHFRatio
};
1257 if(props
.DecayHFLimit
&& props
.AirAbsorptionGainHF
< 1.0f
)
1258 hfRatio
= CalcLimitedHfRatio(hfRatio
, props
.AirAbsorptionGainHF
, props
.DecayTime
);
1260 /* Calculate the LF/HF decay times. */
1261 constexpr float MinDecayTime
{0.1f
}, MaxDecayTime
{20.0f
};
1262 const float lfDecayTime
{std::clamp(props
.DecayTime
*props
.DecayLFRatio
, MinDecayTime
,
1264 const float hfDecayTime
{std::clamp(props
.DecayTime
*hfRatio
, MinDecayTime
, MaxDecayTime
)};
1266 /* Determine if a full update is required. */
1267 const bool fullUpdate
{mPipelineState
== DeviceClear
||
1268 /* Density is essentially a master control for the feedback delays, so
1269 * changes the offsets of many delay lines.
1271 mParams
.Density
!= props
.Density
||
1272 /* Diffusion and decay times influences the decay rate (gain) of the
1273 * late reverb T60 filter.
1275 mParams
.Diffusion
!= props
.Diffusion
||
1276 mParams
.DecayTime
!= props
.DecayTime
||
1277 mParams
.HFDecayTime
!= hfDecayTime
||
1278 mParams
.LFDecayTime
!= lfDecayTime
||
1279 /* Modulation time and depth both require fading the modulation delay. */
1280 mParams
.ModulationTime
!= props
.ModulationTime
||
1281 mParams
.ModulationDepth
!= props
.ModulationDepth
||
1282 /* HF/LF References control the weighting used to calculate the density
1285 mParams
.HFReference
!= props
.HFReference
||
1286 mParams
.LFReference
!= props
.LFReference
};
1289 mParams
.Density
= props
.Density
;
1290 mParams
.Diffusion
= props
.Diffusion
;
1291 mParams
.DecayTime
= props
.DecayTime
;
1292 mParams
.HFDecayTime
= hfDecayTime
;
1293 mParams
.LFDecayTime
= lfDecayTime
;
1294 mParams
.ModulationTime
= props
.ModulationTime
;
1295 mParams
.ModulationDepth
= props
.ModulationDepth
;
1296 mParams
.HFReference
= props
.HFReference
;
1297 mParams
.LFReference
= props
.LFReference
;
1299 mPipelineState
= (mPipelineState
!= DeviceClear
) ? StartFade
: Normal
;
1300 mCurrentPipeline
= !mCurrentPipeline
;
1302 auto &oldpipeline
= mPipelines
[!mCurrentPipeline
];
1303 for(size_t j
{0};j
< NUM_LINES
;++j
)
1304 oldpipeline
.mEarlyDelayCoeff
[j
][1] = 0.0f
;
1306 auto &pipeline
= mPipelines
[mCurrentPipeline
];
1308 /* The density-based room size (delay length) multiplier. */
1309 const float density_mult
{CalcDelayLengthMult(props
.Density
)};
1311 /* Update the main effect delay and associated taps. */
1312 pipeline
.updateDelayLine(props
.Gain
, props
.ReflectionsDelay
, props
.LateReverbDelay
,
1313 density_mult
, props
.DecayTime
, frequency
);
1315 /* Update early and late 3D panning. */
1316 mOutTarget
= target
.Main
->Buffer
;
1317 const float gain
{Slot
->Gain
* ReverbBoost
};
1318 pipeline
.update3DPanning(props
.ReflectionsPan
, props
.LateReverbPan
, props
.ReflectionsGain
*gain
,
1319 props
.LateReverbGain
*gain
, mUpmixOutput
, target
.Main
);
1321 /* Calculate the master filters */
1322 float hf0norm
{std::min(props
.HFReference
/frequency
, 0.49f
)};
1323 pipeline
.mFilter
[0].Lp
.setParamsFromSlope(BiquadType::HighShelf
, hf0norm
, props
.GainHF
, 1.0f
);
1324 float lf0norm
{std::min(props
.LFReference
/frequency
, 0.49f
)};
1325 pipeline
.mFilter
[0].Hp
.setParamsFromSlope(BiquadType::LowShelf
, lf0norm
, props
.GainLF
, 1.0f
);
1326 for(size_t i
{1u};i
< NUM_LINES
;i
++)
1328 pipeline
.mFilter
[i
].Lp
.copyParamsFrom(pipeline
.mFilter
[0].Lp
);
1329 pipeline
.mFilter
[i
].Hp
.copyParamsFrom(pipeline
.mFilter
[0].Hp
);
1334 /* Update the early lines. */
1335 pipeline
.mEarly
.updateLines(density_mult
, props
.Diffusion
, props
.DecayTime
, frequency
);
1337 /* Get the mixing matrix coefficients. */
1338 CalcMatrixCoeffs(props
.Diffusion
, &pipeline
.mMixX
, &pipeline
.mMixY
);
1340 /* Update the modulator rate and depth. */
1341 pipeline
.mLate
.Mod
.updateModulator(props
.ModulationTime
, props
.ModulationDepth
, frequency
);
1343 /* Update the late lines. */
1344 pipeline
.mLate
.updateLines(density_mult
, props
.Diffusion
, lfDecayTime
, props
.DecayTime
,
1345 hfDecayTime
, lf0norm
, hf0norm
, frequency
);
1348 /* Calculate the gain at the start of the late reverb stage, and the gain
1349 * difference from the decay target (0.001, or -60dB).
1351 const float decayBase
{props
.ReflectionsGain
* props
.LateReverbGain
};
1352 const float decayDiff
{ReverbDecayGain
/ decayBase
};
1354 /* Given the DecayTime (the amount of time for the late reverb to decay by
1355 * -60dB), calculate the time to decay to -60dB from the start of the late
1358 * Otherwise, if the late reverb already starts at -60dB or less, only
1359 * include the time to get to the late reverb.
1361 const float diffTime
{!(decayDiff
< 1.0f
) ? 0.0f
1362 : (std::log10(decayDiff
)*(20.0f
/ -60.0f
) * props
.DecayTime
)};
1364 const float decaySamples
{(props
.ReflectionsDelay
+props
.LateReverbDelay
+diffTime
)
1366 /* Limit to 100,000 samples (a touch over 2 seconds at 48khz) to avoid
1367 * excessive double-processing.
1369 pipeline
.mFadeSampleCount
= static_cast<size_t>(std::min(decaySamples
, 100'000.0f
));
1373 /**************************************
1374 * Effect Processing *
1375 **************************************/
1377 /* Applies a scattering matrix to the 4-line (vector) input. This is used
1378 * for both the below vector all-pass model and to perform modal feed-back
1379 * delay network (FDN) mixing.
1381 * The matrix is derived from a skew-symmetric matrix to form a 4D rotation
1382 * matrix with a single unitary rotational parameter:
1384 * [ d, a, b, c ] 1 = a^2 + b^2 + c^2 + d^2
1389 * The rotation is constructed from the effect's diffusion parameter,
1394 * Where a, b, and c are the coefficient y with differing signs, and d is the
1395 * coefficient x. The final matrix is thus:
1397 * [ x, y, -y, y ] n = sqrt(matrix_order - 1)
1398 * [ -y, x, y, y ] t = diffusion_parameter * atan(n)
1399 * [ y, -y, x, y ] x = cos(t)
1400 * [ -y, -y, -y, x ] y = sin(t) / n
1402 * Any square orthogonal matrix with an order that is a power of two will
1403 * work (where ^T is transpose, ^-1 is inverse):
1407 * Using that knowledge, finding an appropriate matrix can be accomplished
1408 * naively by searching all combinations of:
1412 * Where D is a diagonal matrix (of x), and S is a triangular matrix (of y)
1413 * whose combination of signs are being iterated.
1415 inline auto VectorPartialScatter(const std::array
<float,NUM_LINES
> &RESTRICT in
,
1416 const float xCoeff
, const float yCoeff
) noexcept
1419 xCoeff
*in
[0] + yCoeff
*( in
[1] + -in
[2] + in
[3]),
1420 xCoeff
*in
[1] + yCoeff
*(-in
[0] + in
[2] + in
[3]),
1421 xCoeff
*in
[2] + yCoeff
*( in
[0] + -in
[1] + in
[3]),
1422 xCoeff
*in
[3] + yCoeff
*(-in
[0] + -in
[1] + -in
[2] )
1426 /* Utilizes the above, but also applies a line-based reflection on the input
1427 * channels (swapping 0<->3 and 1<->2).
1429 void VectorScatterRev(const float xCoeff
, const float yCoeff
,
1430 const al::span
<ReverbUpdateLine
,NUM_LINES
> samples
, const size_t count
) noexcept
1434 for(size_t i
{0u};i
< count
;++i
)
1436 std::array src
{samples
[0][i
], samples
[1][i
], samples
[2][i
], samples
[3][i
]};
1438 src
= VectorPartialScatter(std::array
{src
[3], src
[2], src
[1], src
[0]}, xCoeff
, yCoeff
);
1439 samples
[0][i
] = src
[0];
1440 samples
[1][i
] = src
[1];
1441 samples
[2][i
] = src
[2];
1442 samples
[3][i
] = src
[3];
1446 /* This applies a Gerzon multiple-in/multiple-out (MIMO) vector all-pass
1447 * filter to the 4-line input.
1449 * It works by vectorizing a regular all-pass filter and replacing the delay
1450 * element with a scattering matrix (like the one above) and a diagonal
1451 * matrix of delay elements.
1453 void VecAllpass::process(const al::span
<ReverbUpdateLine
,NUM_LINES
> samples
, size_t offset
,
1454 const float xCoeff
, const float yCoeff
, const size_t todo
) noexcept
1456 const DelayLineI delay
{Delay
};
1457 const float feedCoeff
{Coeff
};
1461 std::array
<size_t,NUM_LINES
> vap_offset
;
1462 for(size_t j
{0u};j
< NUM_LINES
;j
++)
1463 vap_offset
[j
] = offset
- Offset
[j
];
1464 for(size_t i
{0u};i
< todo
;)
1466 for(size_t j
{0u};j
< NUM_LINES
;j
++)
1467 vap_offset
[j
] &= delay
.Mask
;
1468 offset
&= delay
.Mask
;
1470 size_t maxoff
{offset
};
1471 for(size_t j
{0u};j
< NUM_LINES
;j
++)
1472 maxoff
= std::max(maxoff
, vap_offset
[j
]);
1473 size_t td
{std::min(delay
.Mask
+1 - maxoff
, todo
- i
)};
1476 std::array
<float,NUM_LINES
> f
;
1477 for(size_t j
{0u};j
< NUM_LINES
;j
++)
1479 const float input
{samples
[j
][i
]};
1480 const float out
{delay
.get(vap_offset
[j
]++, j
) - feedCoeff
*input
};
1481 f
[j
] = input
+ feedCoeff
*out
;
1483 samples
[j
][i
] = out
;
1487 delay
.set(offset
++, VectorPartialScatter(f
, xCoeff
, yCoeff
));
1492 /* This applies a more typical all-pass to each line, without the scattering
1495 void Allpass4::process(const al::span
<ReverbUpdateLine
,NUM_LINES
> samples
, const size_t offset
,
1496 const size_t todo
) noexcept
1498 const DelayLineU delay
{Delay
};
1499 const float feedCoeff
{Coeff
};
1503 for(size_t j
{0u};j
< NUM_LINES
;j
++)
1505 float *buffer
{delay
.get(j
).data()};
1506 size_t dstoffset
{offset
};
1507 size_t vap_offset
{offset
- Offset
[j
]};
1508 for(size_t i
{0u};i
< todo
;)
1510 vap_offset
&= delay
.Mask
;
1511 dstoffset
&= delay
.Mask
;
1513 const size_t maxoff
{std::max(dstoffset
, vap_offset
)};
1514 size_t td
{std::min(delay
.Mask
+1 - maxoff
, todo
- i
)};
1517 const float x
{samples
[j
][i
]};
1518 const float y
{buffer
[vap_offset
++] - feedCoeff
*x
};
1519 buffer
[dstoffset
++] = x
+ feedCoeff
*y
;
1521 samples
[j
][i
++] = y
;
1528 /* This generates early reflections.
1530 * This is done by obtaining the primary reflections (those arriving from the
1531 * same direction as the source) from the main delay line. These are
1532 * attenuated and all-pass filtered (based on the diffusion parameter).
1534 * The early lines are then reflected about the origin to create the secondary
1535 * reflections (those arriving from the opposite direction as the source).
1537 * The early response is then completed by combining the primary reflections
1538 * with the delayed and attenuated output from the early lines.
1540 * Finally, the early response is reflected, scattered (based on diffusion),
1541 * and fed into the late reverb section of the main delay line.
1543 void ReverbPipeline::processEarly(const DelayLineU
&main_delay
, size_t offset
,
1544 const size_t samplesToDo
, const al::span
<ReverbUpdateLine
, NUM_LINES
> tempSamples
,
1545 const al::span
<FloatBufferLine
, NUM_LINES
> outSamples
)
1547 const DelayLineU early_delay
{mEarly
.Delay
};
1548 const DelayLineU in_delay
{main_delay
};
1549 const float mixX
{mMixX
};
1550 const float mixY
{mMixY
};
1552 ASSUME(samplesToDo
> 0);
1554 for(size_t base
{0};base
< samplesToDo
;)
1556 const size_t todo
{std::min(samplesToDo
-base
, MAX_UPDATE_SAMPLES
)};
1558 /* First, load decorrelated samples from the main delay line as the
1559 * primary reflections.
1561 const float fadeStep
{1.0f
/ static_cast<float>(todo
)};
1562 for(size_t j
{0u};j
< NUM_LINES
;j
++)
1564 const float *input
{in_delay
.get(j
).data()};
1565 size_t early_delay_tap0
{offset
- mEarlyDelayTap
[j
][0]};
1566 size_t early_delay_tap1
{offset
- mEarlyDelayTap
[j
][1]};
1567 mEarlyDelayTap
[j
][0] = mEarlyDelayTap
[j
][1];
1568 const float coeff0
{mEarlyDelayCoeff
[j
][0]};
1569 const float coeff1
{mEarlyDelayCoeff
[j
][1]};
1570 mEarlyDelayCoeff
[j
][0] = mEarlyDelayCoeff
[j
][1];
1571 const float coeffStep
{(coeff1
-coeff0
)*fadeStep
};
1572 float fadeCount
{0.0f
};
1574 for(size_t i
{0u};i
< todo
;)
1576 early_delay_tap0
&= in_delay
.Mask
;
1577 early_delay_tap1
&= in_delay
.Mask
;
1578 const size_t max_tap
{std::max(early_delay_tap0
, early_delay_tap1
)};
1579 size_t td
{std::min(in_delay
.Mask
+1 - max_tap
, todo
-i
)};
1581 tempSamples
[j
][i
++] = lerpf(input
[early_delay_tap0
++]*coeff0
,
1582 input
[early_delay_tap1
++]*coeff1
, coeffStep
*fadeCount
);
1587 /* Band-pass the incoming samples. */
1588 auto&& filter
= DualBiquad
{mFilter
[j
].Lp
, mFilter
[j
].Hp
};
1589 filter
.process({tempSamples
[j
].data(), todo
}, tempSamples
[j
].data());
1592 /* Apply an all-pass, to help color the initial reflections. */
1593 mEarly
.VecAp
.process(tempSamples
, offset
, todo
);
1595 /* Apply a delay and bounce to generate secondary reflections, combine
1596 * with the primary reflections and write out the result for mixing.
1598 early_delay
.writeReflected(offset
, tempSamples
, todo
);
1599 for(size_t j
{0u};j
< NUM_LINES
;j
++)
1601 const float *input
{early_delay
.get(j
).data()};
1602 size_t feedb_tap
{offset
- mEarly
.Offset
[j
]};
1603 const float feedb_coeff
{mEarly
.Coeff
[j
]};
1604 float *RESTRICT out
{al::assume_aligned
<16>(outSamples
[j
].data() + base
)};
1606 for(size_t i
{0u};i
< todo
;)
1608 feedb_tap
&= early_delay
.Mask
;
1609 size_t td
{std::min(early_delay
.Mask
+1 - feedb_tap
, todo
- i
)};
1611 float sample
{input
[feedb_tap
++]};
1612 out
[i
] = tempSamples
[j
][i
] + sample
*feedb_coeff
;
1613 tempSamples
[j
][i
] = sample
;
1619 /* Finally, write the result to the late delay line input for the late
1620 * reverb stage to pick up at the appropriate time, applying a scatter
1621 * and bounce to improve the initial diffusion in the late reverb.
1623 VectorScatterRev(mixX
, mixY
, tempSamples
, todo
);
1624 for(size_t j
{0u};j
< NUM_LINES
;j
++)
1625 mLateDelayIn
.write(offset
, j
, tempSamples
[j
].data(), todo
);
1632 void Modulation::calcDelays(size_t todo
)
1635 const uint step
{Step
};
1636 const float depth
{Depth
* float{gCubicTable
.sTableSteps
}};
1637 for(size_t i
{0};i
< todo
;++i
)
1640 const float x
{static_cast<float>(idx
&MOD_FRACMASK
) * (1.0f
/MOD_FRACONE
)};
1641 /* Approximate sin(x*2pi). As long as it roughly fits a sinusoid shape
1642 * and stays within [-1...+1], it needn't be perfect.
1644 const float lfo
{!(idx
&(MOD_FRACONE
>>1))
1645 ? ((-16.0f
* x
* x
) + (8.0f
* x
))
1646 : ((16.0f
* x
* x
) + (-8.0f
* x
) + (-16.0f
* x
) + 8.0f
)};
1647 ModDelays
[i
] = float2uint((lfo
+1.0f
) * depth
);
1653 /* This generates the reverb tail using a modified feed-back delay network
1656 * Results from the early reflections are mixed with the output from the
1657 * modulated late delay lines.
1659 * The late response is then completed by T60 and all-pass filtering the mix.
1661 * Finally, the lines are reversed (so they feed their opposite directions)
1662 * and scattered with the FDN matrix before re-feeding the delay lines.
1664 void ReverbPipeline::processLate(size_t offset
, const size_t samplesToDo
,
1665 const al::span
<ReverbUpdateLine
, NUM_LINES
> tempSamples
,
1666 const al::span
<FloatBufferLine
, NUM_LINES
> outSamples
)
1668 const DelayLineU late_delay
{mLate
.Delay
};
1669 const DelayLineU in_delay
{mLateDelayIn
};
1670 const float mixX
{mMixX
};
1671 const float mixY
{mMixY
};
1673 ASSUME(samplesToDo
> 0);
1675 for(size_t base
{0};base
< samplesToDo
;)
1677 const size_t todo
{std::min(std::min(mLate
.Offset
[0], MAX_UPDATE_SAMPLES
),
1681 /* First, calculate the modulated delays for the late feedback. */
1682 mLate
.Mod
.calcDelays(todo
);
1684 /* Now load samples from the feedback delay lines. Filter the signal to
1685 * apply its frequency-dependent decay.
1687 for(size_t j
{0u};j
< NUM_LINES
;++j
)
1689 const float *input
{late_delay
.get(j
).data()};
1690 size_t late_feedb_tap
{offset
- mLate
.Offset
[j
]};
1691 const float midGain
{mLate
.T60
[j
].MidGain
};
1693 for(size_t i
{0u};i
< todo
;++i
)
1695 /* Calculate the read offset and offset between it and the next
1698 const size_t idelay
{mLate
.Mod
.ModDelays
[i
]};
1699 const size_t delay
{late_feedb_tap
- (idelay
>>gCubicTable
.sTableBits
)};
1700 const size_t delayoffset
{idelay
& gCubicTable
.sTableMask
};
1703 /* Get the samples around by the delayed offset. */
1704 const float out0
{input
[(delay
) & late_delay
.Mask
]};
1705 const float out1
{input
[(delay
-1) & late_delay
.Mask
]};
1706 const float out2
{input
[(delay
-2) & late_delay
.Mask
]};
1707 const float out3
{input
[(delay
-3) & late_delay
.Mask
]};
1709 const float out
{out0
*gCubicTable
.getCoeff0(delayoffset
)
1710 + out1
*gCubicTable
.getCoeff1(delayoffset
)
1711 + out2
*gCubicTable
.getCoeff2(delayoffset
)
1712 + out3
*gCubicTable
.getCoeff3(delayoffset
)};
1713 tempSamples
[j
][i
] = out
* midGain
;
1716 mLate
.T60
[j
].process({tempSamples
[j
].data(), todo
});
1719 /* Next load decorrelated samples from the main delay lines. */
1720 const float fadeStep
{1.0f
/ static_cast<float>(todo
)};
1721 for(size_t j
{0u};j
< NUM_LINES
;++j
)
1723 const float *input
{in_delay
.get(j
).data()};
1724 size_t late_delay_tap0
{offset
- mLateDelayTap
[j
][0]};
1725 size_t late_delay_tap1
{offset
- mLateDelayTap
[j
][1]};
1726 const float densityGain
{mLate
.DensityGain
};
1727 const float densityStep
{late_delay_tap0
!= late_delay_tap1
?
1728 densityGain
*fadeStep
: 0.0f
};
1729 float fadeCount
{0.0f
};
1731 for(size_t i
{0u};i
< todo
;)
1733 late_delay_tap0
&= in_delay
.Mask
;
1734 late_delay_tap1
&= in_delay
.Mask
;
1735 size_t td
{std::min(in_delay
.Mask
+1 - std::max(late_delay_tap0
, late_delay_tap1
),
1738 const float fade0
{densityGain
- densityStep
*fadeCount
};
1739 const float fade1
{densityStep
*fadeCount
};
1741 tempSamples
[j
][i
] += input
[late_delay_tap0
++]*fade0
+
1742 input
[late_delay_tap1
++]*fade1
;
1746 mLateDelayTap
[j
][0] = mLateDelayTap
[j
][1];
1749 /* Apply a vector all-pass to improve micro-surface diffusion, and
1750 * write out the results for mixing.
1752 mLate
.VecAp
.process(tempSamples
, offset
, mixX
, mixY
, todo
);
1753 for(size_t j
{0u};j
< NUM_LINES
;++j
)
1754 std::copy_n(tempSamples
[j
].begin(), todo
, outSamples
[j
].begin()+base
);
1756 /* Finally, scatter and bounce the results to refeed the feedback buffer. */
1757 VectorScatterRev(mixX
, mixY
, tempSamples
, todo
);
1758 for(size_t j
{0u};j
< NUM_LINES
;++j
)
1759 late_delay
.write(offset
, j
, tempSamples
[j
].data(), todo
);
1766 void ReverbState::process(const size_t samplesToDo
, const al::span
<const FloatBufferLine
> samplesIn
, const al::span
<FloatBufferLine
> samplesOut
)
1768 const size_t offset
{mOffset
};
1770 ASSUME(samplesToDo
> 0);
1772 auto &oldpipeline
= mPipelines
[!mCurrentPipeline
];
1773 auto &pipeline
= mPipelines
[mCurrentPipeline
];
1775 /* Convert B-Format to A-Format for processing. */
1776 const size_t numInput
{std::min(samplesIn
.size(), NUM_LINES
)};
1777 const al::span
<float> tmpspan
{al::assume_aligned
<16>(mTempLine
.data()), samplesToDo
};
1778 for(size_t c
{0u};c
< NUM_LINES
;++c
)
1780 std::fill(tmpspan
.begin(), tmpspan
.end(), 0.0f
);
1781 for(size_t i
{0};i
< numInput
;++i
)
1783 const float gain
{B2A
[c
][i
]};
1784 const float *RESTRICT input
{al::assume_aligned
<16>(samplesIn
[i
].data())};
1786 auto mix_sample
= [gain
](const float sample
, const float in
) noexcept
-> float
1787 { return sample
+ in
*gain
; };
1788 std::transform(tmpspan
.begin(), tmpspan
.end(), input
, tmpspan
.begin(), mix_sample
);
1791 mMainDelay
.write(offset
, c
, tmpspan
.cbegin(), samplesToDo
);
1794 if(mPipelineState
< Fading
)
1795 mPipelineState
= Fading
;
1797 /* Process reverb for these samples. and mix them to the output. */
1798 pipeline
.processEarly(mMainDelay
, offset
, samplesToDo
, mTempSamples
, mEarlySamples
);
1799 pipeline
.processLate(offset
, samplesToDo
, mTempSamples
, mLateSamples
);
1800 mixOut(pipeline
, samplesOut
, samplesToDo
);
1802 if(mPipelineState
!= Normal
)
1804 if(mPipelineState
== Cleanup
)
1806 size_t numSamples
{mSampleBuffer
.size()/2};
1807 size_t pipelineOffset
{numSamples
* (!mCurrentPipeline
)};
1808 std::fill_n(mSampleBuffer
.data()+pipelineOffset
, numSamples
,
1809 decltype(mSampleBuffer
)::value_type
{});
1811 oldpipeline
.clear();
1812 mPipelineState
= Normal
;
1816 /* If this is the final mix for this old pipeline, set the target
1817 * gains to 0 to ensure a complete fade out, and set the state to
1818 * Cleanup so the next invocation cleans up the delay buffers and
1821 if(samplesToDo
>= oldpipeline
.mFadeSampleCount
)
1823 for(auto &gains
: oldpipeline
.mEarly
.Gains
)
1824 std::fill(gains
.Target
.begin(), gains
.Target
.end(), 0.0f
);
1825 for(auto &gains
: oldpipeline
.mLate
.Gains
)
1826 std::fill(gains
.Target
.begin(), gains
.Target
.end(), 0.0f
);
1827 oldpipeline
.mFadeSampleCount
= 0;
1828 mPipelineState
= Cleanup
;
1831 oldpipeline
.mFadeSampleCount
-= samplesToDo
;
1833 /* Process the old reverb for these samples. */
1834 oldpipeline
.processEarly(mMainDelay
, offset
, samplesToDo
, mTempSamples
, mEarlySamples
);
1835 oldpipeline
.processLate(offset
, samplesToDo
, mTempSamples
, mLateSamples
);
1836 mixOut(oldpipeline
, samplesOut
, samplesToDo
);
1840 mOffset
= offset
+ samplesToDo
;
1844 struct ReverbStateFactory final
: public EffectStateFactory
{
1845 al::intrusive_ptr
<EffectState
> create() override
1846 { return al::intrusive_ptr
<EffectState
>{new ReverbState
{}}; }
1849 struct StdReverbStateFactory final
: public EffectStateFactory
{
1850 al::intrusive_ptr
<EffectState
> create() override
1851 { return al::intrusive_ptr
<EffectState
>{new ReverbState
{}}; }
1856 EffectStateFactory
*ReverbStateFactory_getFactory()
1858 static ReverbStateFactory ReverbFactory
{};
1859 return &ReverbFactory
;
1862 EffectStateFactory
*StdReverbStateFactory_getFactory()
1864 static StdReverbStateFactory ReverbFactory
{};
1865 return &ReverbFactory
;