Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::dsp::PmPulse Class Reference

A pulse oscillator with phase modulation: pitch, width, anchor, index and the PM signal over a PhasePulse. More...

Detailed Description

A pulse oscillator with phase modulation: pitch, width, anchor, index and the PM signal over a PhasePulse.

The composition owns a PhaseAccumulator and drives a PhasePulse<> with its phase and step, from the parts in pm.hpp, which a component with cores of its own uses directly. The accumulator holds the phase as a 32-bit count of the cycle, so it gathers no rounding error; each frame's step is the frequency rounded to fs / 2^32. It makes the one conversion from each port to the core's natural units, pitch through math::frequency(). Its ports are process() arguments after the frame count, in the order PORTS declares (common/transport.hpp):

  • pitch, octaves relative to Tune. The frequency is capped at MAX_FREQUENCY and is never negative; negative steps come from PM.
  • width, the fraction of the cycle the pulse is high, [0, 1].
  • anchor, where width acts, [-1, 1]: -1 holds the rise at the wrap, 0 the center, +1 the fall (PhasePulse).
  • index, the PM depth, bipolar: index_cycles() maps it to cycles of phase offset per unit of the PM signal, MAX_INDEX x|x| at full scale, reduced with pitch above TAMING_CORNER as Plaits reduces its FM amount (plaits/dsp/engine/fm_engine.cc:76-78). It is not clamped; past 1 the depth keeps growing, under the core's per-frame bound.
  • phase_mod, the PM signal, a block, nominally bipolar and not clamped. The core's phase offset is the index in cycles times it, given at SUBSTEPS steps a frame: a SincUpsampler interpolates the signal between frames, PM_LATENCY frames late, so an offset that curves within a frame is followed closely. Left off, there is no PM.

Pitch, width, anchor and index as blocks are used as given, one value per frame. As scalars each moves to its value over RAMP_FRAMES; the first scalar a port is given jumps. A port left off holds and a ramp in progress continues; phase_mod left off is zero.

Phase is linear within each step of a frame: an edge is timed on the segment between two steps' phases, so a pulse born and closed within a step is not seen. Without modulation the core takes the frame as one segment. The step, the offset's change included, is bounded at the core's MAX_STEP in each part; with the reduction, a sine at up to twice the pitch stays inside it at full index at every pitch.

Tune is a parameter: the frequency at zero pitch in cycles per frame, set once by the app from Hz and the target's sample rate, so the component holds no sample rate. TAMING_CORNER is in cycles per frame for the same reason, 1.05 kHz at 48 kHz: an octave under Plaits' corner.

Out-of-range port values are handled by the core; a non-finite pitch or index counts as 0, and a non-finite PM sample holds the last finite one. Output is the core's, nominally [-1, 1], LATENCY frames late, with the DC the width and the modulation carry; an app follows it with a DcBlock. On the default kernel a step overshoots by 8.2 % of its height, so a pulse reaches 1.16. Output does not depend on block size: every ramp is a fixed number of frames.

Definition at line 76 of file pm_pulse.hpp.

#include <pm_pulse.hpp>

Public Types

using Core = PhasePulse<>
 

Public Member Functions

 PmPulse ()
 No Tune and no PM until set; every scalar port ramps over RAMP_FRAMES.
 
void set_tune (float cycles_per_frame)
 Parameter: the frequency at zero pitch.
 
template<class... Ports>
void process (float *out, uint16_t frames, Ports... ports)
 One block, the ports in PORTS' order, any trailing ones left off.
 
void reset ()
 Phase and offset to zero, the PM signal's history cleared, every ramp at its target, corrections dropped.
 
float frequency () const
 The frequency of the last frame, cycles per frame, as the accumulator took it.
 
float phase () const
 The accumulator's phase after the last frame, before the offset.
 

Static Public Member Functions

static float index_cycles (float index, float octaves_above_corner)
 The PM depth in cycles for an index and a pitch.
 

Static Public Attributes

static constexpr uint8_t LATENCY = Core::LATENCY
 
static constexpr float MAX_FREQUENCY = PM_MAX_FREQUENCY
 
static constexpr float MAX_INDEX = PM_MAX_INDEX
 
static constexpr float TAMING_CORNER = PM_TAMING_CORNER
 
static constexpr float TAMING_PER_OCTAVE = PM_TAMING_PER_OCTAVE
 
static constexpr uint16_t RAMP_FRAMES = 64
 
static constexpr uint8_t SUBSTEPS = PM_SUBSTEPS
 
static constexpr uint8_t PM_LATENCY = sbl::dsp::PM_LATENCY
 
static constexpr transport::Port PORTS []
 The ports, in the order process() takes them.
 
static constexpr transport::Parameter< PmPulse > PARAMETERS []
 The parameters, for tools.
 

Member Typedef Documentation

◆ Core

the core, on the default kernel

Definition at line 78 of file pm_pulse.hpp.

Constructor & Destructor Documentation

◆ PmPulse()

sbl::dsp::PmPulse::PmPulse ( )
inline

No Tune and no PM until set; every scalar port ramps over RAMP_FRAMES.

Definition at line 90 of file pm_pulse.hpp.

References RAMP_FRAMES.

Referenced by process().

Member Function Documentation

◆ index_cycles()

static float sbl::dsp::PmPulse::index_cycles ( float  index,
float  octaves_above_corner 
)
inlinestatic

The PM depth in cycles for an index and a pitch.

Parameters
indexThe index port's value; bipolar, the sign kept
octaves_above_cornerThe pitch in octaves above TAMING_CORNER; below it there is no reduction
Returns
pm_depth(index) * pm_taming(octaves_above_corner), in cycles per unit of PM

Definition at line 103 of file pm_pulse.hpp.

References sbl::dsp::pm_depth(), and sbl::dsp::pm_taming().

Referenced by process().

◆ set_tune()

void sbl::dsp::PmPulse::set_tune ( float  cycles_per_frame)
inline

Parameter: the frequency at zero pitch.

Parameters
cycles_per_frameTune in cycles per frame; non-finite or negative counts as 0
Context
Same thread as process(); real-time safe.

Definition at line 113 of file pm_pulse.hpp.

References sbl::math::finite_or(), sbl::dsp::math::octaves_from_ratio(), and TAMING_CORNER.

◆ process()

template<class... Ports>
void sbl::dsp::PmPulse::process ( float *  out,
uint16_t  frames,
Ports...  ports 
)
inline

One block, the ports in PORTS' order, any trailing ones left off.

Template Parameters
PortsA block or an arithmetic scalar for each of pitch, width, anchor and index; a block for phase_mod
Parameters
[out]outOutput buffer, frames long
framesFrame count
portspitch in octaves over Tune; width in [0, 1]; anchor in [-1, 1]; index, bipolar; phase_mod, the PM signal
Context
Audio thread; real-time safe.

Definition at line 139 of file pm_pulse.hpp.

References sbl::dsp::PhaseAccumulator::advance(), sbl::math::finite_or(), sbl::transport::fits_v, index_cycles(), PmPulse(), sbl::dsp::PmInput::process(), sbl::dsp::Ramp::ramping(), sbl::dsp::PhasePulse< Kernel >::set_anchor(), sbl::dsp::PhaseAccumulator::set_step(), sbl::dsp::PhasePulse< Kernel >::set_width(), SUBSTEPS, and sbl::dsp::Ramp::value().

◆ reset()

void sbl::dsp::PmPulse::reset ( )
inline

Phase and offset to zero, the PM signal's history cleared, every ramp at its target, corrections dropped.

Definition at line 179 of file pm_pulse.hpp.

References sbl::dsp::PmInput::reset(), sbl::dsp::PhaseAccumulator::reset(), and sbl::dsp::PhasePulse< Kernel >::reset().

◆ frequency()

float sbl::dsp::PmPulse::frequency ( ) const
inline

The frequency of the last frame, cycles per frame, as the accumulator took it.

Definition at line 189 of file pm_pulse.hpp.

◆ phase()

float sbl::dsp::PmPulse::phase ( ) const
inline

The accumulator's phase after the last frame, before the offset.

Definition at line 192 of file pm_pulse.hpp.

References sbl::dsp::PhaseAccumulator::phase().

Member Data Documentation

◆ LATENCY

constexpr uint8_t sbl::dsp::PmPulse::LATENCY = Core::LATENCY
staticconstexpr

frames the output trails

Definition at line 80 of file pm_pulse.hpp.

◆ MAX_FREQUENCY

constexpr float sbl::dsp::PmPulse::MAX_FREQUENCY = PM_MAX_FREQUENCY
staticconstexpr

cycles per frame

Definition at line 81 of file pm_pulse.hpp.

◆ MAX_INDEX

constexpr float sbl::dsp::PmPulse::MAX_INDEX = PM_MAX_INDEX
staticconstexpr

cycles of offset per unit of PM at index 1

Definition at line 82 of file pm_pulse.hpp.

◆ TAMING_CORNER

constexpr float sbl::dsp::PmPulse::TAMING_CORNER = PM_TAMING_CORNER
staticconstexpr

cycles per frame

Definition at line 83 of file pm_pulse.hpp.

Referenced by set_tune().

◆ TAMING_PER_OCTAVE

constexpr float sbl::dsp::PmPulse::TAMING_PER_OCTAVE = PM_TAMING_PER_OCTAVE
staticconstexpr

as pm_taming()

Definition at line 84 of file pm_pulse.hpp.

◆ RAMP_FRAMES

constexpr uint16_t sbl::dsp::PmPulse::RAMP_FRAMES = 64
staticconstexpr

a scalar port arrives after this many frames

Definition at line 85 of file pm_pulse.hpp.

Referenced by PmPulse().

◆ SUBSTEPS

constexpr uint8_t sbl::dsp::PmPulse::SUBSTEPS = PM_SUBSTEPS
staticconstexpr

offsets given each frame

Definition at line 86 of file pm_pulse.hpp.

Referenced by process().

◆ PM_LATENCY

constexpr uint8_t sbl::dsp::PmPulse::PM_LATENCY = sbl::dsp::PM_LATENCY
staticconstexpr

frames the PM signal trails

Definition at line 87 of file pm_pulse.hpp.

◆ PORTS

constexpr transport::Port sbl::dsp::PmPulse::PORTS[]
staticconstexpr
Initial value:
= {
{"pitch"}, {"width"}, {"anchor"}, {"index"}, {"phase_mod", transport::Spelling::Block},
}

The ports, in the order process() takes them.

Definition at line 120 of file pm_pulse.hpp.

◆ PARAMETERS

constexpr transport::Parameter<PmPulse> sbl::dsp::PmPulse::PARAMETERS[]
staticconstexpr
Initial value:
= {
}
void set_tune(float cycles_per_frame)
Parameter: the frequency at zero pitch.
Definition pm_pulse.hpp:113

The parameters, for tools.

Definition at line 125 of file pm_pulse.hpp.


The documentation for this class was generated from the following file: