Markov Rhythm Generator — User Guide
A cyclic rhythm-template generator in which each Markov state is a complete binary rhythm necklace. State changes occur once per completed pattern cycle, and transition probabilities are derived from rhythmic Hamming distance.
What this does
The generator uses eight binary rhythm templates as the states of a Markov chain. A template such as 10001010 is read on a regular pulse grid: 1 means onset and 0 means silence.
The important unit is the whole pattern cycle. The selected state remains active for one complete necklace, all of its onsets are rendered, and only then is the next Markov state chosen.
All eight states inside one preset have the same number of steps. This keeps tempo and subdivision explicit instead of compressing patterns of different lengths into the same beat.
Quick start
- Run
Markov_Rhythm_Generator.praat. No input Sound is required. - Choose Custom or one of the eight rhythm families.
- Set Duration, Sample rate, Tempo, Base frequency, Decay rate, Wood character, and optional Canon mode.
- Open Edit Markov rhythm details for Steps per beat, Transition temperature, State persistence, Swing, Metric accent, Master amplitude, Edge fade, and Random seed.
- Run the script. One Markov rhythm realization is created first; canon voices, if selected, reuse that exact realization with delayed entries.
Rhythm states as necklaces
Each Markov state is a cyclic binary pattern. The cycle duration is:
beatDuration = 60 / Tempo stepDuration = beatDuration / StepsPerBeat cycleDuration = PatternLength × stepDuration
For example, an 8-step pattern at 2 steps per beat lasts four beats; a 16-step pattern at 4 steps per beat also lasts four beats.
State-density compensation
Different states can contain different numbers of onsets. To prevent a denser pattern from becoming louder merely because it triggers more attacks, every state receives an approximate energy compensation:
stateGain = sqrt(meanOnsetCount / stateOnsetCount)
A state with many hits is therefore reduced relative to a sparse state. This is a density-balancing heuristic, not loudness normalization.
Metric accent
If an onset lands on the first grid step of a beat, its amplitude is multiplied by:
1 + MetricAccent
Other subdivisions keep their unaccented value.
Markov transition model
The transition matrix is calculated from the binary similarity between rhythm templates. For each pair of states, the normalized Hamming distance is:
d(i,j) = mismatching steps / pattern length
The current state receives an exact self-transition probability equal to State persistence. The remaining probability is distributed among the seven alternative states according to their Hamming distance.
P(i,i) = persistence P(i,j) = (1 - persistence) × normalizedWeight(i,j) for j ≠ i
Transition temperature
Lower temperature concentrates the remaining transition probability on rhythmically similar necklaces. Higher temperature makes distant templates more competitive.
Version 0.5.2 uses a numerically stable shifted exponential:
weight(i,j) =
exp(-(d(i,j) - dNearestAlternative) / temperature)
Subtracting the nearest alternative distance does not change the normalized probability ratios. It prevents every alternative weight in a row from underflowing to zero when a very small positive temperature is used.
Theoretical versus realized persistence
State persistence is the theoretical probability of remaining in the same state at each cycle boundary. A finite realization may have a different empirical self-transition rate, especially when Duration contains only a few pattern cycles. The Info output reports both values.
Random seed
Random seed = 0 uses an unpredictable random state. A positive seed reproduces the initial state and the subsequent Markov choices for identical settings.
Tempo, grid, and swing
Steps per beat
Steps per beat is a real metric subdivision, not a display setting. It determines the duration of every binary step and therefore the total cycle duration.
Swing
Swing is available only when the grid has exactly two steps per beat. The second subdivision of each beat moves from the straight midpoint toward two-thirds of the beat:
offbeat delay = SwingAmount × beatDuration / 6
Thus:
- Swing = 0: offbeat at 1/2 beat.
- Swing = 1: offbeat at 2/3 beat.
The rhythm pattern itself is unchanged; swing changes onset timing.
Pulse sound
Every onset triggers the same compact synthetic woody transient. It is intentionally not presented as a physical model of actual claves or woodblocks.
The source contains three exponentially decaying resonant components:
fundamental: f wood resonance: 2.76 × f click component: 4.00 × f
The approximate source is:
0.70 × exp(-Decay × t) × sin(2π f t)
+
0.42 × WoodCharacter
× exp(-1.45 × Decay × t) × sin(2π 2.76f t)
+
0.18 × exp(-3.5 × Decay × t) × sin(2π 4f t)
Wood character controls only the strength of the 2.76× inharmonic resonance. It does not change decay time, pitch, or the 4× click component.
Pulse duration
The local rendering window is derived from Decay rate:
pulseDuration =
min(0.14,
max(0.025, 6 / DecayRate))
Each pulse is rendered only inside that short local region rather than creating a full-duration temporary Sound.
Frequency safety
The script reserves 0.45 × Fs as safe sampling headroom and includes the highest 4× resonance and the highest canon register multiplier when calculating a common frequency scale.
frequencyScale =
min(1,
safeTop /
(4 × maxCanonMultiplier × BaseFrequency))
The same scale is applied to the complete resonant model. If protection would move the effective base below 80 Hz, the script stops instead.
Rhythmic canon
The canon modes do not generate independent Markov chains. One base realization is generated and copied exactly into delayed voices.
| Mode | Voices | Register multipliers | Spatial positions |
|---|---|---|---|
| No Canon | 1 | 1.00× | Mono |
| Canon 2 voices | 2 | 1.00×, 1.25× | Left, right |
| Canon 3 voices | 3 | 1.00×, 1.25×, 0.80× | Left, center, right |
Canon delay is measured in beats
canonDelaySeconds =
CanonDelayBeats × 60 / Tempo
This preserves the musical delay when tempo changes. The output duration becomes:
No canon: Duration 2 voices: Duration + 1 × canonDelay 3 voices: Duration + 2 × canonDelay
The base Markov realization itself still occupies exactly the requested base Duration; only the delayed canon entries extend the final Sound.
Stereo canon voices use equal-power panning. The two-voice canon places its voices at the stereo extremes; the three-voice canon adds a centered middle voice.
Controls
| Control | Default / range | Behavior |
|---|---|---|
| Duration | 12 s; max 180 s | Base Markov realization duration before any delayed canon tail. |
| Sample rate | 44.1 kHz; 8–192 kHz | Direct synthesis and final output rate. |
| Tempo | 120 BPM; 20–400 | Determines beat, grid-step, cycle, and canon-delay timing. |
| Base frequency | 1800 Hz | Fundamental of the woody transient before common headroom scaling. |
| Decay rate | 60; >0–1000 | Exponential decay constant and basis for pulse rendering duration. |
| Wood character | .40; 0–1 | Amplitude of the 2.76× inharmonic mode. |
| Canon mode | No Canon | One, two, or three copies of the same rhythm realization. |
| Canon delay | 1 beat | Metric delay between canon entries; converted to seconds after tempo is known. |
Markov / timing details
| Control | Default | Behavior |
|---|---|---|
| Steps per beat | 4 | Metric subdivision; 1–16. |
| Transition temperature | .24 | Controls how strongly Hamming similarity favors nearby alternative states; >0–5. |
| State persistence | .42 | Exact theoretical self-transition probability; 0–1. |
| Swing amount | 0 | Timing displacement for the offbeat; 0–1 and only valid with 2 steps/beat. |
| Metric accent | .18 | Extra gain on onsets at the beginning of each beat. |
| Master amplitude | .58 | Global pulse gain before overlap compensation and final protection. |
| Edge fade | .015 s | Common linear fade-in/out, capped at 10% of complete output duration. |
| Random seed | 0 | 0 = unpredictable; positive = reproducible Markov realization. |
Presets
| Preset | Pattern/grid design | Main overrides |
|---|---|---|
| Simple March | Eight 8-step necklaces; 2 steps/beat | 100 BPM; 1500 Hz; decay 50; wood .30; temperature .18; persistence .55 |
| Complex Funk | Eight 16-step necklaces; 4 steps/beat | 110 BPM; 2000 Hz; decay 70; wood .50; temperature .28; persistence .30 |
| Techno Grid | Eight 16-step necklaces; 4 steps/beat | 130 BPM; 1200 Hz; decay 80; wood .20; temperature .22; persistence .45 |
| Swing Feel | Eight 8-step necklaces; 2 steps/beat | 90 BPM; 1600 Hz; decay 55; wood .40; temperature .22; persistence .38; swing .92 |
| Broken Beat | Eight 16-step necklaces; 4 steps/beat | 140 BPM; 1900 Hz; decay 65; wood .50; temperature .36; persistence .25 |
| Clave / Timeline Geometry | Eight 16-step timeline-related necklaces; 4 steps/beat | 120 BPM; 2200 Hz; decay 75; wood .60; temperature .18; persistence .40 |
| 3:4 Composite Grid | Eight rotations of a 12-step composite necklace; 3 steps/beat | 100 BPM; 1700 Hz; decay 60; wood .40; temperature .30; persistence .35 |
| Euclidean E(5,8) Rotations | Eight cyclic rotations of E(5,8)=10110110; 2 steps/beat | 110 BPM; 1800 Hz; decay 65; wood .50; temperature .16; persistence .30 |
Clave / Timeline Geometry
This is an analytical binary-timeline family, not a claim of generating an “authentic Latin clave.” The first state is the Son-clave representation 1001001000101000; the remaining states provide related timeline patterns and rotations for the Markov rhythm-space comparison.
Euclidean E(5,8)
The Euclidean preset uses the rhythm E(5,8) = 10110110 and its cyclic rotations as the eight Markov states. The implementation treats rotations as distinct chain states without claiming that every rotation has the same metrical or cultural function.
Output and level
Overlap compensation
The script estimates total pulse-duration load across every canon voice:
overlapLoad =
totalRenderedPulses × pulseDuration
/ totalOutputDuration
overlapGain =
1 / sqrt(max(1, overlapLoad))
This reduces dense overlapping realizations but does not normalize them to a fixed peak or RMS.
| Property | Behavior |
|---|---|
| Input | No selected Sound is required. |
| Duration | Requested base Duration, plus explicit canon delays when canon is enabled. |
| Sample rate | Exactly the selected 8–192 kHz rate. |
| Channels | Mono without canon; stereo for 2- and 3-voice canon. |
| Pulse limit | Maximum 12000 rendered pulses across all canon voices; larger realizations stop with an explicit message. |
| Peak protection | If enabled and the mixed peak exceeds .92, the complete Sound is scaled down once to .92. |
| Normalization | No upward normalization. If the peak is already ≤ .92, its generated level is preserved. |
| Object name | MarkovRhythm_<preset name>, with spaces replaced by underscores. |
Visualization and QC
| Panel | What it shows |
|---|---|
| A — Actual Rhythm Necklaces | The initial, most-visited, and final realized Markov states drawn as circular binary necklaces. |
| B — Markov Model / Realization | Left: expected 8×8 transition matrix. Right: the actual state timeline across the base Duration. |
| C — Actual Onset Raster | The complete base pulse sequence and its delayed copies for each canon voice. |
| D — Sound Model → Measurement | Measured spectrogram of a representative output channel with guides for the fundamental and 2.76× woody resonance of each canon register. |
For stereo canon output, Panel D analyzes whichever complete output channel has the higher RMS.
The QC block reports cycle count, theoretical versus realized persistence, mean realized Hamming jump, base/canon pulse counts, canon delay, overlap load, swing amount, effective base frequency, Nyquist scaling, pre-protection peak/RMS, protection status, and seed.
Further reading
These references are directly relevant to the binary-rhythm geometry and Euclidean-rhythm ideas used by the rhythm families:
- Toussaint, G. T. (2013). The Geometry of Musical Rhythm: What Makes a “Good” Rhythm Good? CRC Press. ISBN 978-1-4665-1202-3.
- Toussaint, G. (2005). “The Euclidean Algorithm Generates Traditional Musical Rhythms.” Renaissance Banff: Mathematics, Music, Art, Culture, Bridges Conference, pp. 47–56. Bridges Archive.