Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ScopedValue for level detector internals #490

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading