Skip to main content

Module midi_clock

Module midi_clock 

Source
Expand description

24-PPQN MIDI clock — generation and consumption.

MIDI transmits 24 timing-clock bytes (0xF8) per quarter note. One clock therefore lasts (60 / bpm) / 24 seconds. This module both generates the stream (how many clock pulses fall inside a wall-clock time slice) and consumes it (estimate BPM from the interval between received pulses, smoothed over a small fixed window so jitter on a single interval does not throw the tempo). No allocation; all state lives on the stack.

Structs§

ClockSync
A 24-PPQN clock that both emits pulses over time and estimates incoming BPM.

Constants§

CLOCKS_PER_QUARTER
Clock pulses per quarter note, per the MIDI spec.
CONTINUE
MIDI System Real-Time: Continue.
START
MIDI System Real-Time: Start.
STOP
MIDI System Real-Time: Stop.
TIMING_CLOCK
MIDI System Real-Time: Timing Clock (24 per quarter note).

Functions§

bpm_from_clock_period
Recover BPM from the interval (seconds) between two clock pulses.
clock_period_seconds
Seconds between consecutive clock pulses at a given tempo.