Skip to content

Commit

Permalink
Use ScopedValue for level detectors (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 authored Feb 14, 2024
1 parent f405ad2 commit d3fa9a5
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ struct PeakDetector
{
for (auto [ch, data] : buffer_iters::channels (buffer))
{
ScopedValue _z { z[ch] };
for (auto& x : data)
{
const auto abs_x = std::abs (x);
const auto b0 = abs_x > z[ch] ? attackCoeffs.b0 : releaseCoeffs.b0;
z[ch] += b0 * (abs_x - z[ch]);
x = z[ch];
const auto b0 = abs_x > _z.get() ? attackCoeffs.b0 : releaseCoeffs.b0;
_z.get() += b0 * (abs_x - _z.get());
x = _z.get();
}
}
}
Expand All @@ -47,13 +48,14 @@ struct PeakRtTDetector
{
for (auto [ch, data] : buffer_iters::channels (buffer))
{
ScopedValue _z { z[ch] };
for (auto& x : data)
{
const auto abs_x = std::abs (x);
const auto b0 = abs_x > z[ch] ? attackCoeffs.b0 : releaseCoeffs.b0;
const auto x_eff = abs_x > z[ch] ? abs_x : thresholdGain;
z[ch] += b0 * (x_eff - z[ch]);
x = z[ch];
const auto b0 = abs_x > _z.get() ? attackCoeffs.b0 : releaseCoeffs.b0;
const auto x_eff = abs_x > _z.get() ? abs_x : thresholdGain;
_z.get() += b0 * (x_eff - _z.get());
x = _z.get();
}
}
}
Expand All @@ -67,12 +69,13 @@ struct RMSDetector
{
for (auto [ch, data] : buffer_iters::channels (buffer))
{
ScopedValue _z { z[ch] };
for (auto& x : data)
{
const auto sq_x = x * x;
const auto& coeffs = sq_x > z[ch] ? attackCoeffs : releaseCoeffs;
z[ch] = coeffs.a1 * z[ch] + coeffs.b0 * sq_x;
x = z[ch];
const auto& coeffs = sq_x > _z.get() ? attackCoeffs : releaseCoeffs;
_z.get() = coeffs.a1 * _z.get() + coeffs.b0 * sq_x;
x = _z.get();
}
}

Expand Down

0 comments on commit d3fa9a5

Please sign in to comment.