Markov Soundscape Weaver — User Guide
Markov-based audio resynthesis using overlapping acoustic analysis, k-means texture states, first- or second-order transition models, state-conditioned grain selection, temporal variation, stereo decorrelation, and normalized overlap-add rendering.
What this does
This script analyzes one Sound as a sequence of overlapping acoustic grains, groups those grains into texture states with k-means, and models state-to-state transitions with either a first-order or second-order Markov chain. A new state sequence is then generated from the learned transition model, and each state selects source grains for resynthesis.
Key Features:
- Overlapping analysis grains — analysis hop is determined by Analysis_overlap
- 4D acoustic feature space — spectral centroid, spectral bandwidth, pitch, HNR
- Per-feature z-score normalization
- k-means texture states with empty-cluster reseeding and final pruning
- First- or second-order Markov chains
- Randomness control — explicit probability of bypassing the learned transition and jumping by state occupancy
- State-conditioned grain emission
- Source-position jitter and output-onset density variation
- Varispeed scatter — pitch, speed, and grain duration change together
- Stereo decorrelation continuum from identical event lists to fully independent walks
- Normalized arbitrary-overlap OLA with accumulated analytic envelope
- Exact requested output duration
- Random_seed for reproducibility
- Suite-standard visualization
Technical Implementation: (1) Convert the source to mono. (2) Extract overlapping 4D analysis grains. (3) Z-score each feature independently. (4) Run k-means with empty-state reseeding. (5) Build either a first-order transition matrix or a second-order transition tensor with first-order backoff. (6) Generate one event list containing state, source grain, source position, varispeed ratio, and output onset. (7) Derive the right-channel event list according to Stereo_decorrelation. (8) Render each channel into audio and envelope buffers. (9) Divide by the accumulated envelope, trim to the exact duration, apply boundary fades, combine stereo if required, and peak-scale to 0.99.
Quick start
- Select exactly one Sound object in Praat.
- Run
Markov_Soundscape_Weaver.praat. - Choose a preset or Manual.
- For Manual, set Grain_size_ms, Analysis_overlap, Number_of_states, Markov_order, Randomness, Output_duration_sec, Synthesis_overlap, Varispeed_scatter_semitones, Position_jitter, Density_variation, Stereo_decorrelation, and Random_seed.
- Enable visualization if you want to inspect the generated state path, transition matrix, state populations, and waveform comparison.
- Click OK. Output is named
<source>_MarkovWeave_<preset>.
Markov Theory
First-Order Chain
Observed state-to-state transitions in the source are counted and each row is normalized. Empty target states are excluded. A row with no usable observed transitions falls back to a distribution over active states.
Second-Order Chain
The second-order model uses a K×K context pair and a successor state. Generation is seeded from a state pair that actually occurred in the source sequence. If a context pair was never observed, the script backs off to the learned first-order distribution conditioned on the current state. If that row is also unavailable, active-state occupancy is used.
Randomness
Therefore Randomness = 0 follows the learned grammar exclusively, while higher values progressively inject occupancy-weighted state jumps.
Initial State
First-order generation starts from an active state sampled by state occupancy. Second-order generation starts from an observed adjacent state pair rather than two unrelated random states.
Grammar Time Scale
If the two overlaps differ, the learned sequence is played at a different event rate. A ratio below 1 compresses the grammar in time; above 1 expands it. This is an intentional compositional parameter interaction, not an error.
Analysis Phase
Overlapping Grain Grid
Analysis_overlap is clamped to 0–0.95. The source must be at least four grain lengths long and must provide at least twice as many analysis grains as requested states.
4D Feature Space
Spectral Centroid
Centre of gravity of a Gaussian-windowed spectrogram slice. The spectrogram is analyzed up to 8 kHz.
Spectral Bandwidth
Spectral standard deviation around the centroid. This is a bandwidth descriptor, not a direct noisiness metric.
Pitch
F0 from Praat Pitch, 75–600 Hz. Undefined or unvoiced grains receive 0 Hz.
Harmonicity
Praat Harmonicity (cc). Undefined HNR receives -50 dB.
Z-Score Normalization
K-Means Texture States
After clustering, any state that somehow remains empty is pruned from the Markov chain: it cannot be an initial state, successor state, or grain-emitting state.
Synthesis Phase
State-Conditioned Grain Selection
Position_jitter therefore changes where the source is read. It does not change the output onset.
Varispeed Scatter
This is varispeed: pitch, playback speed, and grain duration change together.
Density Variation
Density_variation changes the output event timing. Position_jitter changes the source read position. They are different controls.
Stereo Decorrelation
| Value | Behavior |
|---|---|
| < 0 | Mono output |
| 0 | Stereo output with right event list copied exactly from left |
| 0…1 | That approximate fraction of right-channel events is re-decided; the rest is copied from left |
| 1 | Fully independent right-channel Markov walk and grain/event decisions |
Normalized Overlap-Add Rendering
The renderer supports arbitrary overlap, density jitter, and variable grain durations after varispeed. The old block-based concatenate system no longer exists.
Final Output
Parameters & Presets
Manual Parameters
| Parameter | Default | Meaning / validation |
|---|---|---|
| Grain_size_ms | 80 | Analysis/render grain duration |
| Analysis_overlap | 0.5 | Clamped 0–0.95; determines analysis hop |
| Number_of_states | 5 | K-means state count |
| Markov_order | First Order | First or Second Order |
| Randomness | 0 | Clamped 0–1; probability of occupancy-weighted state jump |
| Output_duration_sec | 15 | Exact requested duration |
| Synthesis_overlap | 0.5 | Clamped 0–0.95; determines synthesis hop |
| Varispeed_scatter_semitones | 0 | Negative values become 0 |
| Position_jitter | 0.1 | Clamped 0–1; source-centre perturbation as fraction of grain duration |
| Density_variation | 0 | Clamped 0–1; output-onset perturbation as fraction of synthesis hop |
| Stereo_decorrelation | 0.3 | <0 = mono; 0 = identical stereo; 1 = independent right walk |
| Random_seed | 0 | 0 = unpredictable; positive integer = reproducible stochastic run |
| Draw_visualization | On | Draw v0.8 diagnostic page |
| Play_result | On | Play output after generation |
Script-Level Edge Taper
Built-in Presets
| Preset | Grain | Ana. ovlp | K | Order | Rand. | Output | Synth ovlp | Varispeed | Pos. jitter | Density | Stereo dec. |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Ambient Flow | 100 ms | 60% | 4 | 1st | .10 | 20 s | 60% | 0 | .10 | .05 | .40 |
| Rhythmic Pulse | 50 ms | 30% | 6 | 1st | .05 | 12 s | 30% | 0 | 0 | 0 | .20 |
| Dense Texture | 40 ms | 70% | 8 | 2nd | .15 | 15 s | 70% | ±.3 st | .20 | .10 | .50 |
| Sparse Minimal | 150 ms | 40% | 3 | 1st | .20 | 25 s | 40% | 0 | .15 | .10 | .30 |
| Evolving Landscape | 120 ms | 50% | 5 | 2nd | .10 | 30 s | 60% | ±.2 st | .10 | .08 | .60 |
| Chaotic Transitions | 60 ms | 50% | 10 | 1st | .50 | 12 s | 50% | ±.8 st | .30 | .15 | .70 |
Visualization
v0.8 Diagnostic Page
Applications
Texture-State Resequencing
Generate new arrangements of a source's acoustic texture states while retaining transition tendencies learned from that source.
Soundscape Variation
Environmental, instrumental, vocal, or mixed recordings can produce useful generative textures when their local spectral/pitch/HNR patterns form recurring state transitions.
First- vs Second-Order Grammar Experiments
Compare the same source under first-order and second-order transition models to hear how conditioning on the previous two states changes local continuity.
Temporal Rescaling of Learned Grammar
Changing Analysis_overlap and Synthesis_overlap independently changes the event-rate relationship between learned and rendered sequences without altering the source feature model itself.
Stereo Texture Design
Stereo_decorrelation provides a controlled continuum from duplicated mono-in-stereo to independent probabilistic walks.
Troubleshooting
The script requires at least
2 × Number_of_states analysis grains. Reduce K, reduce grain size, increase analysis overlap, or use a longer source.
Increase Randomness, try a different K, or use a source with more state diversity. Very strong self-transition probabilities in the learned chain will naturally repeat.
Reduce Randomness, lower Stereo_decorrelation, reduce Density_variation, or use a more structured source.
Varispeed_scatter_semitones changes pitch, playback speed, and grain duration together.
Both channels use the same event list. Use a value above 0 for increasing channel divergence, or a negative value for mono output.
It controls k-means initialization, state transitions, grain selection, jitter, varispeed, and stereo-decorrelation decisions.