Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::signal::units Namespace Reference

Enumerations

enum class  Division : std::uint8_t {
  whole = 0 , whole_dotted = 1 , whole_triplet = 2 , half = 3 ,
  half_dotted = 4 , half_triplet = 5 , quarter = 6 , quarter_dotted = 7 ,
  quarter_triplet = 8 , eighth = 9 , eighth_dotted = 10 , eighth_triplet = 11 ,
  sixteenth = 12 , sixteenth_dotted = 13 , sixteenth_triplet = 14 , thirty_second = 15 ,
  thirty_second_dotted = 16 , thirty_second_triplet = 17 , sixty_fourth = 18 , sixty_fourth_dotted = 19 ,
  sixty_fourth_triplet = 20 , count = 21
}
 Shared serialized musical-division vocabulary. More...

Functions

template<typename T>
T db_to_linear (T db)
 Amplitude dB → linear gain. 0 dB → 1, −6.0206 dB → 0.5.
template<typename T>
T linear_to_db (T linear)
 Linear gain → amplitude dB, floored at kDbFloorAmplitude so silence maps to a finite −200 dB rather than −inf.
template<typename T>
T midi_to_hz (T note)
 MIDI note number → Hz (note 69 = 440 Hz).
template<typename T>
T hz_to_midi (T hz)
 Hz → MIDI note number.
template<typename T>
T semitones_to_ratio (T semitones)
 Semitones → frequency ratio. +12 → 2, −12 → 0.5.
template<typename T>
T ratio_to_semitones (T ratio)
 Frequency ratio → semitones. Inverse of semitones_to_ratio.
template<typename T>
T cents_to_ratio (T cents)
 Cents → frequency ratio. +100 → 2^(1/12), +1200 → 2.
template<typename T>
T ratio_to_cents (T ratio)
 Frequency ratio → cents. Inverse of cents_to_ratio.
template<typename T>
T volts_to_semitones (T volts)
 Pitch CV volts → semitones, on the 1 V/octave standard.
template<typename T>
T semitones_to_volts (T semitones)
 Semitones → pitch CV volts, on the 1 V/octave standard.
template<typename T>
T ms_to_samples (T ms, T sample_rate)
 Milliseconds → samples at sample_rate Hz.
template<typename T>
T samples_to_ms (T samples, T sample_rate)
 Samples → milliseconds at sample_rate Hz.
template<typename T>
T hz_to_period_samples (T hz, T sample_rate)
 Frequency → its period in samples. A 100 Hz tone at 48 kHz is 480 samples.
template<typename T>
T period_samples_to_hz (T samples, T sample_rate)
 A period in samples → its frequency in Hz.
template<typename T>
T hz_to_cycles_per_sample (T hz, T sample_rate)
 Hz → normalised frequency in cycles per sample (f / fs) — the unit a phase accumulator increments by.
template<typename T>
T hz_to_radians_per_sample (T hz, T sample_rate)
 Hz → radians per sample (2π·f / fs) — the unit a sin/cos oscillator and most filter design formulas want.
template<typename T>
T ms_to_onepole_coef (T ms, T sample_rate)
 A time constant in ms → the a in the one-pole smoother y += a·(x − y), i.e.
template<typename T>
T ms_to_onepole_pole (T ms, T sample_rate)
 The complementary pole of ms_to_onepole_coef: p = 1 − a = exp(−1/(τ·fs)), the p in y = p·y + (1 − p)·x.
template<typename T>
T t60_ms_to_tau_ms (T t60_ms)
 A 60 dB decay time in ms → the one-pole time constant τ in ms that produces it.
template<typename T>
T taper_log (T u, T lo, T hi)
 Geometric ("log") taper: maps a normalised knob position u ∈ [0, 1] onto [lo, hi] so equal knob travel is equal RATIO — the right law for anything heard geometrically (frequency, delay time, drive).
template<typename T>
T untaper_log (T value, T lo, T hi)
 Inverse of taper_log: a value in [lo, hi] → its knob position in [0, 1].
template<typename T>
T taper_linear (T u, T lo, T hi)
 Linear taper — the arithmetic counterpart of taper_log, present so a parameter table can name its law instead of open-coding a lerp.
template<typename T>
T untaper_linear (T value, T lo, T hi)
 Inverse of taper_linear.
template<typename T>
T taper_log_inverse (T value, T lo, T hi)
 Compatibility spelling used by the shared modulation toolkit.
template<typename T>
T t60_to_per_sample_gain (T t60_seconds, T sample_rate)
 Per-sample gain for a feedback path that decays by 60 dB in t60_seconds.
template<typename T>
T beats_to_seconds (T beats, T bpm)
template<typename T>
T seconds_to_beats (T seconds, T bpm)
constexpr timebase::BeatDivision to_beat_division (Division division) noexcept
 Converts the legacy signal spelling to the canonical timebase vocabulary.
constexpr float division_to_beats (Division division)
constexpr float division_to_beats (int index)
float division_to_seconds (Division division, float bpm)
double division_to_samples (Division division, float bpm, double sample_rate)
float division_to_hz (Division division, float bpm)

Variables

constexpr double kDbFloorAmplitude = 1e-10
 Amplitude floor used when converting to dB.
constexpr double kMidiA4 = 69.0
 MIDI note number of concert A. Fixed by the MIDI specification.
constexpr double kA4Hz = 440.0
 Frequency of concert A in Hz — the tuning reference for midi_to_hz.
constexpr double kSemitonesPerOctave = 12.0
 Semitones per octave, and cents per semitone. Fixed by 12-TET notation.
constexpr double kCentsPerSemitone = 100.0
constexpr double kSemitonesPerVolt = kSemitonesPerOctave
 Semitones per volt on the 1 V/octave pitch-CV standard.
constexpr int kDivisionCount = static_cast<int>(Division::count)

Enumeration Type Documentation

◆ Division

enum class pulp::signal::units::Division : std::uint8_t
strong

Shared serialized musical-division vocabulary.

Order is ABI/preset state: append before count; never reorder existing entries.

Enumerator
whole 
whole_dotted 
whole_triplet 
half 
half_dotted 
half_triplet 
quarter 
quarter_dotted 
quarter_triplet 
eighth 
eighth_dotted 
eighth_triplet 
sixteenth 
sixteenth_dotted 
sixteenth_triplet 
thirty_second 
thirty_second_dotted 
thirty_second_triplet 
sixty_fourth 
sixty_fourth_dotted 
sixty_fourth_triplet 
count 

Function Documentation

◆ beats_to_seconds()

template<typename T>
T pulp::signal::units::beats_to_seconds ( T beats,
T bpm )
inline

◆ cents_to_ratio()

template<typename T>
T pulp::signal::units::cents_to_ratio ( T cents)
inline

Cents → frequency ratio. +100 → 2^(1/12), +1200 → 2.

◆ db_to_linear()

template<typename T>
T pulp::signal::units::db_to_linear ( T db)
inline

Amplitude dB → linear gain. 0 dB → 1, −6.0206 dB → 0.5.

◆ division_to_beats() [1/2]

float pulp::signal::units::division_to_beats ( Division division)
constexpr

◆ division_to_beats() [2/2]

float pulp::signal::units::division_to_beats ( int index)
constexpr

◆ division_to_hz()

float pulp::signal::units::division_to_hz ( Division division,
float bpm )
inline

◆ division_to_samples()

double pulp::signal::units::division_to_samples ( Division division,
float bpm,
double sample_rate )
inline

◆ division_to_seconds()

float pulp::signal::units::division_to_seconds ( Division division,
float bpm )
inline

◆ hz_to_cycles_per_sample()

template<typename T>
T pulp::signal::units::hz_to_cycles_per_sample ( T hz,
T sample_rate )
inline

Hz → normalised frequency in cycles per sample (f / fs) — the unit a phase accumulator increments by.

◆ hz_to_midi()

template<typename T>
T pulp::signal::units::hz_to_midi ( T hz)
inline

Hz → MIDI note number.

Non-positive input would be −inf, so it is floored at the dB amplitude floor's frequency analogue: the result saturates rather than returning −inf, keeping a tracker's output finite on silence.

◆ hz_to_period_samples()

template<typename T>
T pulp::signal::units::hz_to_period_samples ( T hz,
T sample_rate )
inline

Frequency → its period in samples. A 100 Hz tone at 48 kHz is 480 samples.

◆ hz_to_radians_per_sample()

template<typename T>
T pulp::signal::units::hz_to_radians_per_sample ( T hz,
T sample_rate )
inline

Hz → radians per sample (2π·f / fs) — the unit a sin/cos oscillator and most filter design formulas want.

◆ linear_to_db()

template<typename T>
T pulp::signal::units::linear_to_db ( T linear)
inline

Linear gain → amplitude dB, floored at kDbFloorAmplitude so silence maps to a finite −200 dB rather than −inf.

Takes the magnitude, so a negative gain reports its level rather than NaN.

◆ midi_to_hz()

template<typename T>
T pulp::signal::units::midi_to_hz ( T note)
inline

MIDI note number → Hz (note 69 = 440 Hz).

Fractional notes are meaningful: 69.5 is a quarter-tone above A4.

◆ ms_to_onepole_coef()

template<typename T>
T pulp::signal::units::ms_to_onepole_coef ( T ms,
T sample_rate )
inline

A time constant in ms → the a in the one-pole smoother y += a·(x − y), i.e.

a = 1 − exp(−1 / (τ·fs)) with τ in seconds. a ∈ (0, 1].

τ is the 63.2 % point — the time for a step response to cover 1 − 1/e of the distance. The other two readings people mean by "the smoothing time" are one multiply away, so state which one you mean and convert:

  • 60 dB decay: t60 = τ·ln(1000) ≈ 6.908·τ
  • 10–90 % rise: t90 − t10 = τ·ln 9 ≈ 2.197·τ

ms <= 0 returns 1 (instant), which is what a caller asking for zero smoothing means; it never divides by zero.

◆ ms_to_onepole_pole()

template<typename T>
T pulp::signal::units::ms_to_onepole_pole ( T ms,
T sample_rate )
inline

The complementary pole of ms_to_onepole_coef: p = 1 − a = exp(−1/(τ·fs)), the p in y = p·y + (1 − p)·x.

Same τ convention.

◆ ms_to_samples()

template<typename T>
T pulp::signal::units::ms_to_samples ( T ms,
T sample_rate )
inline

Milliseconds → samples at sample_rate Hz.

Fractional — callers that need an integer delay decide their own rounding, because a delay line that interpolates and one that does not want different answers.

◆ period_samples_to_hz()

template<typename T>
T pulp::signal::units::period_samples_to_hz ( T samples,
T sample_rate )
inline

A period in samples → its frequency in Hz.

◆ ratio_to_cents()

template<typename T>
T pulp::signal::units::ratio_to_cents ( T ratio)
inline

Frequency ratio → cents. Inverse of cents_to_ratio.

◆ ratio_to_semitones()

template<typename T>
T pulp::signal::units::ratio_to_semitones ( T ratio)
inline

Frequency ratio → semitones. Inverse of semitones_to_ratio.

◆ samples_to_ms()

template<typename T>
T pulp::signal::units::samples_to_ms ( T samples,
T sample_rate )
inline

Samples → milliseconds at sample_rate Hz.

◆ seconds_to_beats()

template<typename T>
T pulp::signal::units::seconds_to_beats ( T seconds,
T bpm )
inline

◆ semitones_to_ratio()

template<typename T>
T pulp::signal::units::semitones_to_ratio ( T semitones)
inline

Semitones → frequency ratio. +12 → 2, −12 → 0.5.

◆ semitones_to_volts()

template<typename T>
T pulp::signal::units::semitones_to_volts ( T semitones)
inline

Semitones → pitch CV volts, on the 1 V/octave standard.

◆ t60_ms_to_tau_ms()

template<typename T>
T pulp::signal::units::t60_ms_to_tau_ms ( T t60_ms)
inline

A 60 dB decay time in ms → the one-pole time constant τ in ms that produces it.

Pair with ms_to_onepole_coef when a spec states a t60 rather than a τ.

◆ t60_to_per_sample_gain()

template<typename T>
T pulp::signal::units::t60_to_per_sample_gain ( T t60_seconds,
T sample_rate )
inline

Per-sample gain for a feedback path that decays by 60 dB in t60_seconds.

◆ taper_linear()

template<typename T>
T pulp::signal::units::taper_linear ( T u,
T lo,
T hi )
inline

Linear taper — the arithmetic counterpart of taper_log, present so a parameter table can name its law instead of open-coding a lerp.

◆ taper_log()

template<typename T>
T pulp::signal::units::taper_log ( T u,
T lo,
T hi )
inline

Geometric ("log") taper: maps a normalised knob position u ∈ [0, 1] onto [lo, hi] so equal knob travel is equal RATIO — the right law for anything heard geometrically (frequency, delay time, drive).

u = 0.5 lands on the geometric mean sqrt(lo·hi), not the arithmetic midpoint.

Requires lo > 0; a taper through zero has no geometric midpoint. Returns lo unchanged if that precondition fails rather than producing a NaN.

◆ taper_log_inverse()

template<typename T>
T pulp::signal::units::taper_log_inverse ( T value,
T lo,
T hi )
inline

Compatibility spelling used by the shared modulation toolkit.

◆ to_beat_division()

timebase::BeatDivision pulp::signal::units::to_beat_division ( Division division)
constexprnoexcept

Converts the legacy signal spelling to the canonical timebase vocabulary.

Both enums are persisted, append-only ordinal contracts.

◆ untaper_linear()

template<typename T>
T pulp::signal::units::untaper_linear ( T value,
T lo,
T hi )
inline

Inverse of taper_linear.

◆ untaper_log()

template<typename T>
T pulp::signal::units::untaper_log ( T value,
T lo,
T hi )
inline

Inverse of taper_log: a value in [lo, hi] → its knob position in [0, 1].

◆ volts_to_semitones()

template<typename T>
T pulp::signal::units::volts_to_semitones ( T volts)
inline

Pitch CV volts → semitones, on the 1 V/octave standard.

Variable Documentation

◆ kA4Hz

double pulp::signal::units::kA4Hz = 440.0
inlineconstexpr

Frequency of concert A in Hz — the tuning reference for midi_to_hz.

◆ kCentsPerSemitone

double pulp::signal::units::kCentsPerSemitone = 100.0
inlineconstexpr

◆ kDbFloorAmplitude

double pulp::signal::units::kDbFloorAmplitude = 1e-10
inlineconstexpr

Amplitude floor used when converting to dB.

Guards log10(0); any value far below the quietest amplitude anyone measures works. [design parameter] default 1e-10 (−200 dBFS), range 1e-15 .. 1e-6.

◆ kDivisionCount

int pulp::signal::units::kDivisionCount = static_cast<int>(Division::count)
inlineconstexpr

◆ kMidiA4

double pulp::signal::units::kMidiA4 = 69.0
inlineconstexpr

MIDI note number of concert A. Fixed by the MIDI specification.

◆ kSemitonesPerOctave

double pulp::signal::units::kSemitonesPerOctave = 12.0
inlineconstexpr

Semitones per octave, and cents per semitone. Fixed by 12-TET notation.

◆ kSemitonesPerVolt

double pulp::signal::units::kSemitonesPerVolt = kSemitonesPerOctave
inlineconstexpr

Semitones per volt on the 1 V/octave pitch-CV standard.