Direct Formula Markov Synthesis — User Guide
Markov chain-controlled synthesis: generates evolving sequences using stochastic state transitions, where each state defines distinct sonic characteristics (frequency, duration, amplitude) with direct formula construction for maximum efficiency.
What this does
This script implements Markov chain synthesis — generating structured yet unpredictable sequences using stochastic state transitions. Process: (1) Creates N states (typically 8) with defined sonic properties (frequency, duration, amplitude, bandwidth), (2) Starts in random state, (3) For each event: generates sound based on current state properties, (4) Transitions to next state based on Markov rules (4 types available), (5) Builds single massive formula containing all events, (6) Synthesizes sound directly from formula, (7) Applies spectral filtering for polish. The result is structured sequences with controlled randomness, where state transitions follow probabilistic rules rather than pure randomness.
Key Features:
- 4 Markov Transition Types — Simple chain, circular chain, random walk, biased chain
- State-Based Synthesis — Each state has distinct frequency, duration, amplitude characteristics
- Direct Formula Construction — Single massive formula for all events (no chunking needed)
- Harmonic Content Control — Optional addition of 3 harmonics per state
- Envelope Options — Hanning or exponential envelopes per event
- Transition Randomness Control — Adjustable probability of random vs structured transitions
- Real-time Formula Building — Progress updates during construction
Technical Implementation: (1) State initialization: Create arrays for state properties: frequency (logarithmic spread from base), duration (increasing with state), amplitude (increasing with state), bandwidth (increasing with state). (2) Formula building: Start with formula$ = "0". While time < duration: get current state properties, build event formula with conditionals (if x >= time and x < time+duration), add harmonics if enabled, add envelope (Hanning or exponential), concatenate to formula$. (3) State transition: Apply Markov rules based on markov_type. (4) Synthesis: Create Sound from formula with the complete formula string. (5) Post-processing: Filter with Hann bandpass, normalize amplitude. Key innovation: Direct formula construction avoids object creation overhead, though formula length can become extreme for long durations/high densities.
Quick start
- In Praat, ensure no objects selected (generates from scratch).
- Run script… →
direct_formula_markov_synthesis.praat. - Set Duration (12 seconds typical, shorter for testing).
- Set Number_states (8 recommended for first try).
- Set Base_frequency (100Hz for bass, 440Hz for mid-range).
- Set Event_density (5 events/sec for sparse, 15+ for dense).
- Choose Markov_type (Simple_chain recommended for first try).
- Enable Enable_harmonics for richer sounds.
- Enable Enable_envelopes for smoother events.
- Adjust Transition_randomness (0.3 for balanced).
- Click OK — formula builds with progress updates.
- Output named "Markov_Synthesis" appears in Objects window.
- Output automatically played when complete.
Markov Chain Theory
Markov Process Fundamentals
What is a Markov Chain?
⛓️ Markov Chain Properties
Memoryless property: P(next state | all past states) = P(next state | current state)
State space: Finite set of states S = {s₁, s₂, ..., sₙ}
Transition probabilities: Pᵢⱼ = P(stateⱼ at t+1 | stateᵢ at t)
Transition matrix: Square matrix P where Pᵢⱼ ≥ 0 and Σⱼ Pᵢⱼ = 1
Initial distribution: Probability distribution over initial state
Musical Markov Chains
States = musical parameters (pitch, rhythm, timbre, etc.)
Transitions = compositional rules
Example: Pitch Markov Chain
States: C, D, E, F, G, A, B
Transition probabilities:
C → D: 0.3, C → E: 0.2, C → G: 0.4, C → C: 0.1
D → E: 0.4, D → F: 0.3, D → A: 0.2, D → D: 0.1
etc.
Result: Melodies that follow probabilistic rules
Not purely random, not purely deterministic
"Composed" feeling with controlled variation
Script Implementation
Discrete-Time Markov Process
State-Dependent Sound Generation
🎵 State to Sound Mapping
Each state defines:
- Frequency (pitch center)
- Duration (event length)
- Amplitude (loudness)
- Bandwidth (spectral width, used in filtering)
Per-event variations:
- Duration: ±30% random variation
- Amplitude: ±20% random variation
- Harmonics: optional 3 harmonics
- Envelope: Hanning or exponential
Result: Each state has characteristic sound but with natural variation
Mathematical Formulation
State Property Calculation
Event Count Calculation
State System Design
State Property Ranges
🎚️ State Parameter Ranges (for n=8 states)
Frequency (logarithmic spread):
100Hz
109Hz
119Hz
130Hz
142Hz
155Hz
170Hz
188Hz
Duration: 0.15s → 0.35s (linear increase)
Amplitude: 0.4 → 0.8 (linear increase)
Bandwidth: 0.1 → 0.5 (linear increase)
State Property Calculations
| State | Frequency (Hz) base=100, n=8 | Duration (s) | Amplitude | Bandwidth | Musical Interval from State 1 |
|---|---|---|---|---|---|
| 1 | 100.0 | 0.150 | 0.400 | 0.100 | Unison |
| 2 | 109.0 | 0.175 | 0.450 | 0.163 | Minor 2nd |
| 3 | 119.2 | 0.200 | 0.500 | 0.225 | Major 2nd |
| 4 | 130.0 | 0.225 | 0.550 | 0.288 | Minor 3rd |
| 5 | 141.8 | 0.250 | 0.600 | 0.350 | Major 3rd |
| 6 | 154.8 | 0.275 | 0.650 | 0.413 | Perfect 4th |
| 7 | 169.0 | 0.300 | 0.700 | 0.475 | Tritone |
| 8 | 188.0 | 0.325 | 0.750 | 0.538 | Perfect 5th |
| 9* | 200.0 | 0.350 | 0.800 | 0.600 | Octave |
*State 9 shown for comparison (would require n=9 states)
Per-Event Variations
Harmonic Content Generation
Envelope Options
Transition Types
Type 1: Simple Chain
🔗 Simple Chain (Markov_type = 1)
Transition logic:
Probability structure:
- Stay: 0.6 - randomness/2 (default 0.45 with randomness=0.3)
- Adjacent: 0.3 - randomness/3 (default 0.2 with randomness=0.3)
- Random jump: 0.1 + randomness/6 (default 0.15 with randomness=0.3)
Character: Mostly stays in same state, sometimes moves to neighbors, rarely jumps randomly
Sonic result: Stable with occasional small changes, rare surprises
Best for: Stable textures, minimal evolution, background patterns
Type 2: Circular Chain
🔄 Circular Chain (Markov_type = 2)
Transition logic:
Deterministic cycle: 1 → 2 → 3 → ... → n → 1 → 2 → ...
No randomness: Completely predictable sequence
Musical pattern: Ascending frequency pattern that cycles
Duration effect: Events get progressively longer (state duration increases)
Amplitude effect: Events get progressively louder
Character: Predictable, cyclical, pattern-based
Sonic result: Rising sequence that cycles, getting longer and louder each cycle
Best for: Pattern-based music, ostinatos, rhythmic sequences
Type 3: Random Walk
🎲 Random Walk (Markov_type = 3)
Transition logic:
Step distribution: -2, -1, 0, 1, 2 with equal probability
Boundary handling: Clamped to [1, number_states]
Movement character: Can stay, move ±1, or jump ±2
Random walk properties: Drifts through state space, tends to explore all states
No attraction: No tendency to return to center or previous states
Character: Exploratory, wandering, unpredictable but bounded
Sonic result: Meandering through frequencies, unpredictable but not extreme
Best for: Exploratory textures, wandering melodies, abstract patterns
Type 4: Biased Chain
⚖️ Biased Chain (Markov_type = 4)
Transition logic:
Center attraction: Always moves toward center state when not at center
Center behavior: Mostly stays at center, occasionally perturbs
Mathematical form: Ornstein-Uhlenbeck process (mean-reverting random walk)
Stability property: Returns to center after perturbations
Character: Stable with excursions, home-seeking, centered
Sonic result: Mostly centered around middle frequency, with occasional excursions that return
Best for: Stable backgrounds with variation, centered textures, tension-release patterns
Transition Type Comparison
| Type | Randomness | Predictability | Movement Pattern | State Coverage | Sonic Character |
|---|---|---|---|---|---|
| Simple Chain | Medium | Medium | Mostly static, small steps | Local | Stable, occasional changes |
| Circular Chain | None | High | Deterministic cycle | All (systematic) | Patterned, cyclical |
| Random Walk | High | Low | Wandering, unbounded* | All (eventually) | Explor |