Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
blep.hpp
Go to the documentation of this file.
1#pragma once
2
69
70#include <cmath>
71
73
80inline constexpr double kNoDiscontinuity = -1.0;
81
89struct Correction {
91 double before = 0.0;
93 double after = 0.0;
94};
95
114inline double blep_residual(double x) noexcept {
115 if (x < -1.0 || x >= 1.0) return 0.0;
116 if (x < 0.0) return 0.5 * x * x + x + 0.5;
117 return x - 0.5 * x * x - 0.5;
118}
119
129inline double blamp_residual(double x) noexcept {
130 if (x < -1.0 || x >= 1.0) return 0.0;
131 if (x < 0.0) return x * x * x / 6.0 + 0.5 * x * x + 0.5 * x + 1.0 / 6.0;
132 return 0.5 * x * x - x * x * x / 6.0 - 0.5 * x + 1.0 / 6.0;
133}
134
177inline Correction poly_blep(double d, double height) noexcept {
178 if (!(d >= 0.0 && d <= 1.0)) return {0.0, 0.0};
179 // Before tap at x = -d, always in [-1, 0]: the pre-step branch, which is
180 // `0.5x^2 + x + 0.5` rewritten in d.
181 const double before = 0.5 * d * d - d + 0.5;
182 // After tap at x = 1 - d, always in [0, 1]: the post-step branch.
183 const double x = 1.0 - d;
184 const double after = x - 0.5 * x * x - 0.5;
185 return {height * before, height * after};
186}
187
206inline Correction poly_blamp(double d, double slope_change) noexcept {
207 if (!(d >= 0.0 && d <= 1.0)) return {0.0, 0.0};
208 return {slope_change * blamp_residual(-d), slope_change * blamp_residual(1.0 - d)};
209}
210
237inline double wrap_position(double phase_after, double increment) noexcept {
238 if (!(increment > 0.0)) return kNoDiscontinuity;
239 const double d = 1.0 - phase_after / increment;
240 return std::isfinite(d) ? d : kNoDiscontinuity;
241}
242
243} // namespace pulp::signal::osc
Definition blep.hpp:72
Correction poly_blep(double d, double height) noexcept
polyBLEP correction for a step in the VALUE.
Definition blep.hpp:177
Correction poly_blamp(double d, double slope_change) noexcept
polyBLAMP correction for a break in the SLOPE.
Definition blep.hpp:206
double wrap_position(double phase_after, double increment) noexcept
Sub-sample position of a period wrap, for a phase accumulator that has just wrapped through its bound...
Definition blep.hpp:237
constexpr double kNoDiscontinuity
A sub-sample position that means "no discontinuity here".
Definition blep.hpp:80
double blep_residual(double x) noexcept
Unit BLEP residual at x, the signed distance from the discontinuity to the sample,...
Definition blep.hpp:114
double blamp_residual(double x) noexcept
Unit BLAMP residual at x — the integral of blep_residual, and the correction that turns a trivial ram...
Definition blep.hpp:129
A discontinuity's correction, split across the two samples it touches.
Definition blep.hpp:89
double after
Add to the sample following it.
Definition blep.hpp:93
double before
Add to the sample preceding the discontinuity.
Definition blep.hpp:91