6#ifndef SBL_DSP_OSCILLATORS_VCO_HPP_
7#define SBL_DSP_OSCILLATORS_VCO_HPP_
79 return (1.0f - evens) / (1.0f + evens);
131 template<
class... Ports>
132 void process(
float* out, uint16_t frames, Ports... ports) {
134 "SBL ERROR: Vco takes pitch (a block or a scalar), then wave and shape (scalars)");
135 const auto pitch = transport::arg<0>(ports...);
136 const auto wave = transport::arg<1>(ports...);
137 const auto shape = transport::arg<2>(ports...);
138 if constexpr (transport::is_scalar_v<
decltype(wave)>) {
139 const float pulse =
pulse_amount(
static_cast<float>(wave));
140 osc_.
set_blend(1.0f - pulse, pulse, 0.0f);
142 if constexpr (transport::is_scalar_v<
decltype(shape)>) {
143 const float knee =
knee_for(
static_cast<float>(shape));
147 if constexpr (transport::is_block_v<
decltype(
pitch)>) {
148 render(out,
pitch, frames);
150 if constexpr (transport::is_scalar_v<
decltype(
pitch)>) {
151 aim(
static_cast<float>(
pitch));
178 void render(
float* out,
const float*
pitch, uint16_t frames) {
180 while (pos < frames) {
181 const uint16_t n = chunk(frames - pos);
182 for (uint16_t i = 0; i < n; ++i) {
183 frequency_[i] = frequency_for(
pitch[pos + i]);
185 osc_.
process(out + pos, n, frequency_);
194 void render(
float* out, uint16_t frames) {
196 while (pos < frames && pitch_.
ramping()) {
197 const uint16_t n = chunk(frames - pos);
198 for (uint16_t i = 0; i < n; ++i) {
199 frequency_[i] = frequency_for(pitch_.
step());
201 osc_.
process(out + pos, n, frequency_);
206 osc_.
process(out + pos,
static_cast<uint16_t
>(frames - pos));
The BLEP oscillator core: one phase, three waveform parts, band-limited edges.
The BLEP oscillator core: one phase, three waveform parts, band-limited edges.
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_blend(float saw, float pulse, float triangle)
Set the weights of the three parts in the sum. Ramp over RAMP_FRAMES.
static constexpr uint16_t RAMP_FRAMES
float frequency() const
The frequency, in cycles per frame.
void set_frequency(float cycles_per_frame)
Set the frequency. Takes effect at the next frame.
static constexpr uint8_t LATENCY
void set_saw_knee(float fraction_of_cycle)
Set where the saw's phase bends. Ramps over RAMP_FRAMES.
static constexpr float MIN_BREAKPOINT
float process()
One frame.
void reset()
Phase to zero, ramps to their targets, corrections dropped.
float target() const
The value the ramp heads for.
void head(float target)
set(), except that the first value given since construction, by head() or jump(), is arrived at at on...
float value() const
The current value.
void jump(float value)
Arrive at a value at once.
void set_length(uint16_t frames)
Set how many frames a ramp takes.
bool ramping() const
True while a ramp is in progress.
An oscillator: Tune, and pitch, Wave and Shape as ports over a BlepOsc.
void set_tune(float cycles_per_frame)
Parameter: the frequency at zero pitch.
Vco()
No Tune until set; a scalar pitch ramps over RAMP_FRAMES.
static constexpr float MIN_KNEE
void process(float *out, uint16_t frames, Ports... ports)
One block, the ports in PORTS' order, any trailing ones left off.
static constexpr transport::Port PORTS[]
The ports, in the order process() takes them.
float pitch() const
The pitch the ramp is at, octaves.
static float knee_for(float shape)
The saw's knee and the pulse's width for a Shape setting: 0.5 halved SHAPE_OCTAVES times across the k...
static constexpr transport::Parameter< Vco > PARAMETERS[]
The parameters, for tools.
static constexpr uint8_t LATENCY
static constexpr float WAVE_EVENS_DB_PER_UNIT
static constexpr uint16_t CHUNK_FRAMES
void reset()
Phase to zero, every ramp at its target, corrections dropped.
float frequency() const
The core's frequency after the last process(), cycles per frame.
static float pulse_amount(float wave)
The pulse's weight for a Wave setting, with the saw's weight 1 minus it.
static constexpr float SHAPE_OCTAVES
static constexpr uint16_t RAMP_FRAMES
Finiteness of a float, read from its bits, and a fallback for a value that is not finite.
float frequency(float reference, float octaves)
A reference frequency moved by an interval in octaves.
float finite_or(float x, float fallback)
x, or fallback when x is an infinity or a NaN.
constexpr T clamp01(T x)
x held to [0, 1]; a NaN goes to 0.
Pitch as octaves and ratios: from an interval to a frequency and back.
A linear ramp to a target over a fixed number of frames.
The processing call's shape as a checked contract.