6#ifndef SBL_DSP_OSCILLATORS_PHASE_SAW_HPP_
7#define SBL_DSP_OSCILLATORS_PHASE_SAW_HPP_
106template<
class Kernel = math::Sinc16>
111 static constexpr uint8_t
LATENCY = Kernel::LATENCY;
146 const float offsets[1] = {
offset};
164 template<u
int8_t SUBSTEPS>
165 float process(
float phase,
float step,
const float (&offsets)[SUBSTEPS]) {
166 static_assert(SUBSTEPS > 0,
"SBL ERROR: a frame has at least one part");
167 const float width0 = width_;
168 const float rise0 =
rise(width_, anchor_);
169 const float fall0 =
fall(width_, anchor_);
170 width_ = width_target_;
171 anchor_ = anchor_target_;
172 const float rise1 =
rise(width_, anchor_);
173 const float fall1 =
fall(width_, anchor_);
174 float rise_from = rise0;
175 float fall_from = fall0;
176 float width_from = width0;
179 start(s, rise_from, fall_from, width_from);
182 const float rise_to = s.
last ? rise1 : rise0 + (rise1 - rise0) * s.
through;
183 const float fall_to = s.
last ? fall1 : fall0 + (fall1 - fall0) * s.
through;
184 const float width_to = s.
last ? width_ : width0 + (width_ - width0) * s.
through;
185 corner(s, rise_from, rise_to, width_from, width_to, 1.0f);
186 corner(s, fall_from, fall_to, width_from, width_to, -1.0f);
189 width_from = width_to;
191 return corrector_.process(
shape(walk_.
phase(), rise1, fall1, width_));
226 template<
class... Ports>
227 void process(
float* out, uint16_t frames, Ports... ports) {
229 "SBL ERROR: PhaseSaw takes phase and step (blocks), then width, anchor and offset "
230 "(blocks or scalars)");
231 const auto phase = transport::arg<0>(ports...);
232 const auto step = transport::arg<1>(ports...);
233 const auto width = transport::arg<2>(ports...);
234 const auto anchor = transport::arg<3>(ports...);
235 const auto offset = transport::arg<4>(ports...);
236 if constexpr (transport::is_scalar_v<
decltype(
width)>) {
239 if constexpr (transport::is_scalar_v<
decltype(
anchor)>) {
242 for (uint16_t i = 0; i < frames; ++i) {
243 if constexpr (transport::is_block_v<
decltype(
width)>) {
246 if constexpr (transport::is_block_v<
decltype(
anchor)>) {
249 if constexpr (transport::is_block_v<
decltype(
offset)>) {
251 }
else if constexpr (transport::is_scalar_v<
decltype(
offset)>) {
267 width_ = width_target_;
268 anchor_ = anchor_target_;
278 float width()
const {
return width_target_; }
280 float anchor()
const {
return anchor_target_; }
314 return 1.0f - 2.0f * past / (1.0f -
width);
329 const float slope = rising ? 2.0f /
width : -2.0f / (1.0f -
width);
331 corrector_.corner(t < 1.0f ? t : math::POLYBLEP_T_MAX, slope * speed);
341 void corner(
const PhaseWalk::Segment& s,
float c0,
float c1,
float w0,
float w1,
float sign) {
343 const float into = 1.0f - (t - s.before) / s.part;
344 const float w = w0 + (w1 - w0) * into;
345 corrector_.corner(t, sign * std::fabs(speed) * 2.0f / (w * (1.0f - w)));
349 float width_target_ = 0.5f;
351 float anchor_target_ = 0.0f;
352 float anchor_ = 0.0f;
353 bool starting_ =
true;
355 BlepCorrector<Kernel> corrector_{};
The correction buffer behind a band-limited edge, over a BLEP kernel.
A band-limited slope shape driven by a signed phase, from a falling saw through a triangle to a risin...
float process(float phase, float step)
One frame with no offset: an offset carried before moves back to zero, as phase modulation.
static constexpr float MAX_STEP
float offset() const
The offset the core read last frame, in cycles.
float phase() const
The phase the core read last frame, the offset included.
static float shape(float phase, float rise, float fall, float width)
The naive shape at a phase.
float width() const
The width set for the next frame.
float anchor() const
The anchor set for the next frame.
static constexpr uint8_t LATENCY
static constexpr transport::Port PORTS[]
The ports, in the order the buffer call takes them, as PhasePulse's.
void process(float *out, uint16_t frames, Ports... ports)
A buffer of frames: phase and step per frame, then width, anchor and offset, which may be left off.
static constexpr float rise(float width, float anchor)
The trough, where the shape starts to rise, as PhasePulse::rise().
void set_width(float fraction_of_cycle)
Set the rising segment's share of the cycle. Takes effect next frame.
void set_anchor(float anchor)
Set where width acts. Takes effect next frame.
float process(float phase, float step, const float(&offsets)[SUBSTEPS])
One frame in SUBSTEPS equal parts, the offset given at the end of each, as PhasePulse's.
static constexpr float fall(float width, float anchor)
The peak, where the shape starts to fall, as PhasePulse::fall().
void reset(float phase=0.0f, float offset=0.0f)
Move to a phase plus an offset; width and anchor to their targets, corrections dropped.
static constexpr float WIDTH_FLOOR
float process(float phase, float step, float offset)
One frame: the corrected sample LATENCY frames back.
void reset(float phase=0.0f, float offset=0.0f)
Move to a phase plus an offset, the offset kept as the last part's.
static constexpr float MAX_STEP
void frame(float phase, float step, const float(&offsets)[SUBSTEPS], OnSegment &&on_segment)
One frame in SUBSTEPS equal parts, each given to on_segment as a Segment.
float phase() const
The phase the last part ended on, the offset included, in [0, 1).
static void crossings(const Segment &s, float c0, float c1, OnCrossing &&on_crossing)
Report every image of a threshold crossed by a segment while the threshold moved c0 -> c1.
float offset() const
The offset the last part ended on, in cycles.
Finiteness of a float, read from its bits, and a fallback for a value that is not finite.
float finite_or(float x, float fallback)
x, or fallback when x is an infinity or a NaN.
constexpr T clamp(T x, T lo, T hi)
x held to [lo, hi]; a NaN goes to lo.
A modulated phase walked frame by frame as segments, and the crossings of moving thresholds on them.
Polynomial BLEP kernels, and the sub-frame time of a crossing.
One part of a frame: the phase moving linearly from start to end plus wraps cycles.
The processing call's shape as a checked contract.