Class thl::dsp::metronome::MetronomePlayerImpl#
-
class MetronomePlayerImpl : public thl::dsp::BaseProcessor#
Inheritance diagram for thl::dsp::metronome::MetronomePlayerImpl:
Collaboration diagram for thl::dsp::metronome::MetronomePlayerImpl:
Sample-accurate metronome processor driven by a TransportClock.
Mixes its output into the buffer (additive), so it can be placed anywhere in the audio processing chain without silencing upstream signal. Uses a voice pool with ADSR-shaped decaying sines for click sounds.
Two sounds: Accent — bar downbeat: 800 Hz, 20 ms exponential decay Click — beat/division: 1200 Hz, 12 ms exponential decay
Override trigger_accent(), trigger_click(), and tick_voices() to replace the built-in sine clicks with custom sounds (e.g. sample playback).
- Lifetime
The TransportClock reference passed in must outlive this player.
- Modulation
The Rhythm parameter is sampled once per process() block; sub-block change points are not honored. Gain and Enabled may modulate per-trigger.
- Real-Time Safety
process() is real-time safe — no allocation, no locks.
Public Functions
-
explicit MetronomePlayerImpl(transport::TransportClock &clock)#
-
virtual void prepare(const double &sample_rate, const size_t &samples_per_block, const size_t &num_channels) override#
-
virtual void process(thl::core::BufferView buffer, uint32_t modulation_offset = 0) override#
Protected Types
Protected Functions
-
virtual void trigger_accent()#
Called at the exact sample where a bar boundary falls.
-
virtual void trigger_click()#
Called at the exact sample where a rhythm boundary falls.
-
virtual float tick_voices()#
Render one sample from all active voices. Called once per sample.
Protected Attributes
-
std::array<Voice, k_num_voices> m_voices#
Protected Static Attributes
-
static constexpr int k_num_voices = 4#
Number of voices in the pool.
Each trigger claims the quietest voice, so overlapping clicks fade out naturally without phase discontinuities. 4 is generous headroom — at most 2 clicks overlap in practice, but 4 keeps us safe if decay times are extended or divisions are very fast.
-
static constexpr float k_attack_ms = 1.5f#
-
static constexpr float k_accent_freq = 800.0f#
-
static constexpr float k_accent_decay_ms = 20.0f#
-
static constexpr float k_click_freq = 1200.0f#
-
static constexpr float k_click_decay_ms = 12.0f#
-
static constexpr float k_accent_gain_factor = 1.0f#
Accent gain relative to master. Bar downbeat is louder than subdivision.
-
static constexpr float k_click_gain_factor = 0.6f#