|
Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
|
The BLEP oscillator core: one phase, three waveform parts, band-limited edges. More...
The BLEP oscillator core: one phase, three waveform parts, band-limited edges.
One phase accumulator drives a saw with a movable knee, a pulse of variable width and a triangle with a variable peak position. The naive output is the weighted sum of the three; every step and corner in it is corrected at its sub-frame time through a BlepCorrector over the Kernel, so the output trails the naive waveform by LATENCY frames and a harmonic at f is scaled by the kernel's response. The kernel is a compile-time choice (dsp/math/polyblep.hpp): the default is math::Sinc16; math::Bspline4 and math::Linear2 never overshoot.
The core is below the signal transport: its inputs are natural units, set by the composition that owns it, which carries the ports and does the one conversion. Frequency is cycles per frame, so the core holds no sample rate.
Inputs and their handling, per frame:
Output is nominally [-1, 1] per part. With Bspline4 or Linear2, kernels that never overshoot, the peak cannot exceed the sum of the weights' magnitudes; with Sinc16 a step overshoots by 8.2 % of its height (polyblep.hpp). The pulse is low before its edge and high after it, as in Plaits, so it shares the saw's drop at the wrap and a saw-to-pulse blend morphs without a dip. A pulse with its edge at w carries a mean of 1 - 2w; the core removes no DC.
Output does not depend on how the stream is split into calls: all state advances per frame.
| Kernel | The BLEP kernel; math::Sinc16 by default |
Definition at line 75 of file blep_osc.hpp.
#include <blep_osc.hpp>
Public Member Functions | |
| BlepOsc () | |
| A saw at zero frequency until set; blend, knee and peak changes ramp over RAMP_FRAMES. | |
| void | set_frequency (float cycles_per_frame) |
| Set the frequency. Takes effect at the next frame. | |
| void | set_pulse_width (float fraction_of_cycle) |
| Set where the pulse's rising edge falls in the cycle. Takes effect next frame as a moving edge. | |
| void | set_saw_knee (float fraction_of_cycle) |
| Set where the saw's phase bends. Ramps over RAMP_FRAMES. | |
| void | set_triangle_peak (float fraction_of_cycle) |
| Set where the triangle peaks within the cycle. Ramps over RAMP_FRAMES. | |
| void | set_blend (float saw, float pulse, float triangle) |
| Set the weights of the three parts in the sum. Ramp over RAMP_FRAMES. | |
| float | process () |
| One frame. | |
| template<class... Ports> | |
| void | process (float *out, uint16_t frames, Ports... ports) |
| A buffer of frames, the ports in PORTS' order, any trailing ones left off. | |
| void | reset () |
| Phase to zero, ramps to their targets, corrections dropped. | |
| float | phase () const |
| The phase after the last frame, in [0, 1). | |
| float | frequency () const |
| The frequency, in cycles per frame. | |
Static Public Attributes | |
| static constexpr float | MAX_FREQUENCY = 0.25f |
| static constexpr float | MIN_BREAKPOINT = 1.0f / 32.0f |
| static constexpr uint16_t | RAMP_FRAMES = 64 |
| static constexpr uint8_t | LATENCY = Kernel::LATENCY |
| static constexpr transport::Port | PORTS [] |
| The ports, in the order the buffer call takes them; each sets the quantity of the setter of its name. | |
|
inline |
A saw at zero frequency until set; blend, knee and peak changes ramp over RAMP_FRAMES.
Definition at line 83 of file blep_osc.hpp.
References sbl::dsp::BlepOsc< Kernel >::RAMP_FRAMES.
Referenced by sbl::dsp::BlepOsc< Kernel >::process().
|
inline |
Set the frequency. Takes effect at the next frame.
| cycles_per_frame | Frequency in cycles per frame, clamped to [0, MAX_FREQUENCY]; non-finite counts as zero |
Definition at line 95 of file blep_osc.hpp.
References sbl::math::clamp(), sbl::math::finite_or(), and sbl::dsp::BlepOsc< Kernel >::MAX_FREQUENCY.
Referenced by sbl::dsp::BlepOsc< Kernel >::process().
|
inline |
Set where the pulse's rising edge falls in the cycle. Takes effect next frame as a moving edge.
| fraction_of_cycle | Edge position, clamped to [0, 1]: low before it, high from it to the wrap; non-finite counts as 0.5 |
Definition at line 106 of file blep_osc.hpp.
References sbl::math::clamp(), and sbl::math::finite_or().
Referenced by sbl::dsp::BlepOsc< Kernel >::process(), and sbl::dsp::Vco::process().
|
inline |
Set where the saw's phase bends. Ramps over RAMP_FRAMES.
| fraction_of_cycle | Knee, clamped to [MIN_BREAKPOINT, 1 - MIN_BREAKPOINT]; 0.5 is the plain saw; non-finite counts as 0.5 |
Definition at line 117 of file blep_osc.hpp.
References sbl::math::clamp(), sbl::math::finite_or(), sbl::dsp::BlepOsc< Kernel >::MIN_BREAKPOINT, and sbl::dsp::Ramp::set().
Referenced by sbl::dsp::BlepOsc< Kernel >::process(), and sbl::dsp::Vco::process().
|
inline |
Set where the triangle peaks within the cycle. Ramps over RAMP_FRAMES.
| fraction_of_cycle | Peak, clamped to [MIN_BREAKPOINT, 1 - MIN_BREAKPOINT]; non-finite counts as 0.5 |
Definition at line 128 of file blep_osc.hpp.
References sbl::math::clamp(), sbl::math::finite_or(), sbl::dsp::BlepOsc< Kernel >::MIN_BREAKPOINT, and sbl::dsp::Ramp::set().
Referenced by sbl::dsp::BlepOsc< Kernel >::process().
|
inline |
Set the weights of the three parts in the sum. Ramp over RAMP_FRAMES.
| saw | Weight of the saw; non-finite counts as zero |
| pulse | Weight of the pulse; non-finite counts as zero |
| triangle | Weight of the triangle; non-finite counts as zero |
Definition at line 141 of file blep_osc.hpp.
References sbl::math::finite_or(), and sbl::dsp::Ramp::set().
Referenced by sbl::dsp::Vco::process().
|
inline |
One frame.
Definition at line 153 of file blep_osc.hpp.
References sbl::math::clamp(), sbl::dsp::BlepOsc< Kernel >::MIN_BREAKPOINT, sbl::dsp::math::polyblep_time(), and sbl::dsp::Ramp::step().
Referenced by sbl::dsp::BlepOsc< Kernel >::process().
|
inline |
A buffer of frames, the ports in PORTS' order, any trailing ones left off.
Frequency and pulse width as blocks are set each frame: the audio-rate FM and PWM paths. As scalars they are set once, before the block's first frame, and take effect as their setters say. The knee, the blend weights and the triangle peak are scalars and ramp over RAMP_FRAMES. A port left off holds its last value.
| Ports | A block or an arithmetic scalar for frequency and pulse_width; scalars for the rest |
| [out] | out | Output buffer, frames long |
| frames | Frame count | |
| ports | frequency in cycles per frame, pulse_width, saw_knee, saw, pulse, triangle, triangle_peak, as their setters take them |
Definition at line 242 of file blep_osc.hpp.
References sbl::dsp::BlepOsc< Kernel >::BlepOsc(), sbl::math::finite_or(), sbl::transport::fits_v, sbl::dsp::BlepOsc< Kernel >::frequency(), sbl::dsp::BlepOsc< Kernel >::process(), sbl::dsp::Ramp::set(), sbl::dsp::BlepOsc< Kernel >::set_frequency(), sbl::dsp::BlepOsc< Kernel >::set_pulse_width(), sbl::dsp::BlepOsc< Kernel >::set_saw_knee(), and sbl::dsp::BlepOsc< Kernel >::set_triangle_peak().
|
inline |
Phase to zero, ramps to their targets, corrections dropped.
Definition at line 286 of file blep_osc.hpp.
References sbl::dsp::Ramp::jump(), sbl::dsp::Ramp::target(), and sbl::dsp::Ramp::value().
Referenced by sbl::dsp::Vco::reset().
|
inline |
The phase after the last frame, in [0, 1).
Definition at line 300 of file blep_osc.hpp.
|
inline |
The frequency, in cycles per frame.
Definition at line 302 of file blep_osc.hpp.
Referenced by sbl::dsp::Vco::frequency(), and sbl::dsp::BlepOsc< Kernel >::process().
|
staticconstexpr |
cycles per frame: fs/4
Definition at line 77 of file blep_osc.hpp.
Referenced by sbl::dsp::BlepOsc< Kernel >::set_frequency().
|
staticconstexpr |
the knee's and the peak's distance from either end
Definition at line 78 of file blep_osc.hpp.
Referenced by sbl::dsp::BlepOsc< Kernel >::process(), sbl::dsp::BlepOsc< Kernel >::set_saw_knee(), and sbl::dsp::BlepOsc< Kernel >::set_triangle_peak().
|
staticconstexpr |
blend and peak changes ramp over this many frames
Definition at line 79 of file blep_osc.hpp.
Referenced by sbl::dsp::BlepOsc< Kernel >::BlepOsc().
|
staticconstexpr |
frames the output trails the naive waveform
Definition at line 80 of file blep_osc.hpp.
|
staticconstexpr |
The ports, in the order the buffer call takes them; each sets the quantity of the setter of its name.
Definition at line 216 of file blep_osc.hpp.