Stochastic Time Folding — User Guide
Probabilistic temporal mangling: iteratively averages samples with randomly-offset neighbors based on adaptive probability thresholds, creating glitchy, stuttering, time-smeared textures through stochastic sample-level processing.
What this does
This script implements stochastic time folding — a destructive audio mangling technique that "folds" time by averaging each sample with temporally distant samples selected at random offsets. Process operates iteratively (default 6 passes): for each iteration, (1) Generate probability mask (random 0-1 per sample), (2) If mask < threshold: fold sample = average with forward-offset sample + backward-offset sample (temporal averaging), (3) Else: apply random amplitude variation (0.7-1.2×), (4) Adapt threshold (drifts each iteration). Result: glitchy stutters, temporal smearing, buffer-like artifacts, rhythmic disruption, sample-level chaos. "Folding" = bringing distant time points together (like folding paper). Stochastic = probabilistic, not deterministic. Each run creates different result due to randomness.
Key Features:
- Iterative Processing — 4-12 folding passes (default 6)
- Adaptive Threshold — Probability changes over iterations
- Random Fold Distances — Temporal offsets vary (3-12 samples typical)
- Probabilistic Gating — Each sample randomly folded or varied
- Temporal Averaging — Mixes current + future + past samples
- 4 Presets — Default, Gentle, Aggressive, Micro Glitch
Technical Implementation: (1) Copy input sound (non-destructive), (2) Iteration loop (fold_iterations times, default 6): Update adaptive threshold: threshold += random(variation_min, variation_max), constrain to limits (0.1-0.9), Calculate fold distance: samples / random(distance_min, distance_max), Generate probability mask: random(0,1) per sample, Apply conditional formula: IF mask < threshold: output = (current + forward_offset + backward_offset) / divisor, ELSE: output = current × random_amplitude(0.7-1.2). (3) Normalize to scale_peak 0.96. Key insight: Stochastic gating means some samples folded, others not → creates irregular, glitchy texture. Adaptive threshold means folding probability changes over iterations → evolving character. Random distances means temporal offsets unpredictable → chaotic rather than rhythmic. Averaging three samples (current + future + past) → smooths some samples while leaving others intact → mix of coherence and chaos.
Quick start
- In Praat, select exactly one Sound object.
- Run script… →
Stochastic_Time_Folding.praat. - Choose Preset: Default (balanced), Gentle Folds, Aggressive Folds, Micro Glitch, or Custom.
- If Custom: adjust fold_iterations (6), initial_adaptive_threshold (0.5), threshold variations, fold distances, amplitude ranges, divisors.
- Click OK — processing applies iterative stochastic folding, auto-plays mangled result.
Time Folding Theory
Temporal Averaging Concept
What is Time Folding?
Metaphor: Folding paper brings distant points into contact
Why Averaging (Not Replacement)?
Averaging = smoothing:
- Pure replacement: output = sample[offset] (complete discontinuity)
- Averaging: output = (current + offsets) / N (partial blend)
- Maintains some original character while adding artifacts
- Creates "smeared" rather than "jumped" temporal structure
Stochastic Gating
Probability-Based Processing
Concept: Each sample randomly folded or varied based on threshold
Adaptive Threshold Evolution
Concept: Threshold changes between iterations
Why adaptive?
- Static threshold = same effect each iteration (boring)
- Adaptive = character evolves (interesting)
- Typically drifts upward = increasing destruction
- But constrained by min/max limits (0.1-0.9 default)
Random Fold Distances
Variable Temporal Offsets
Formula: distance = total_samples / random(min, max)
Forward vs Backward Distances
Asymmetric averaging:
Iterative Compounding
Multi-Pass Processing
Each iteration processes already-folded audio
Why Multiple Iterations?
Single iteration:
- Subtle effect (only some samples folded once)
- Original largely intact
- Sparse glitches
Multiple iterations:
- Compounding effect (folded samples get folded again)
- Original increasingly obscured
- Dense, complex glitches
- Emergent textures from repeated averaging
Amplitude Variation (Non-Folded Samples)
Purpose
When sample not folded, apply random amplitude scaling
Complete Processing Algorithm
Comparison to Other Temporal Effects
| Effect | Temporal Logic | Predictability | Character |
|---|---|---|---|
| Delay/Echo | Fixed offset, mix | High | Rhythmic repeats |
| Reverb | Multiple delays + filtering | High | Space simulation |
| Time Stretch | Playback rate change | High | Pitch/speed change |
| Granular | Windowed chunks | Medium | Textures, clouds |
| Buffer Shuffle | Chunk reordering | Medium | Stutters, jumps |
| Stochastic Folding | Random sample mixing | Low | Glitches, chaos |
Parameters & Presets
Preset Options
🎵 Default (balanced)
Parameters: 6 iterations, threshold 0.5→0.9, distances 3-12, amps 0.7-1.2
Character: Moderate glitching, balanced destruction
Best for: General glitch effects, experimental processing
💫 Gentle Folds
Parameters: 4 iterations, threshold 0.4→0.85, distances 5-15, amps 0.9-1.1
Character: Subtle artifacts, minimal destruction
Best for: Adding texture without heavy mangling, mixing applications
🔥 Aggressive Folds
Parameters: 9 iterations, threshold 0.6→0.95, distances 2-10, amps 0.5-1.5
Character: Heavy destruction, extreme stuttering
Best for: Harsh glitch, sound design, experimental music
⚡ Micro Glitch
Parameters: 12 iterations, threshold 0.55→0.90, distances 2-6, amps 0.6-1.4
Character: Dense, rapid micro-glitches, digital artifacts
Best for: IDM, glitch electronica, extreme sound design
Custom Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| Preset | option | Default | Choose preset configuration |
| fold_iterations | natural | 6 | Number of processing passes |
| initial_adaptive_threshold | positive | 0.5 | Starting probability (0-1) |
| threshold_variation_min | positive | 0.2 | Minimum threshold increase |
| threshold_variation_max | positive | 0.2 | Maximum threshold increase |
| threshold_min_limit | positive | 0.1 | Threshold floor |
| threshold_max_limit | positive | 0.9 | Threshold ceiling |
| fold_distance_min | positive | 3 | Minimum divisor for fold offset |
| fold_distance_max | positive | 12 | Maximum divisor for fold offset |
| amplitude_min | positive | 0.7 | Minimum amplitude variation |
| amplitude_max | positive | 1.2 | Maximum amplitude variation |
| fold_average_divisor | positive | 3 | Divisor for 3-sample average |
| fold_backward_divisor | positive | 2 | Backward offset scaling |
| scale_peak | positive | 0.96 | Output normalization level |
| play_after_processing | boolean | yes | Auto-play result |
Parameter Details
fold_iterations
Range: 1-20 (practical 3-12)
Default: 6
Effect:
- 1-3: Subtle glitching, mostly recognizable
- 4-8: Moderate mangling, clear artifacts
- 8-12: Heavy destruction, dense glitches
- >12: Extreme, possibly noise-like
initial_adaptive_threshold
Range: 0.1-0.9
Default: 0.5 (50% folding probability)
Effect: Starting point for probability. Lower = less folding initially. Higher = more folding from start. Drifts upward over iterations.
threshold_variation_min & max
Range: 0.0-0.5
Defaults: 0.2 (both)
Effect: Controls how much threshold increases each iteration. Higher values = faster approach to max threshold. Min=Max = consistent increase. Min Range: 2-50 Defaults: 3, 12 Effect: Temporal offset range. Lower = shorter distances (tight glitches). Higher = longer distances (obvious delays). Formula: samples / random(min,max) Range: 0.3-2.0 Defaults: 0.7, 1.2 Effect: Volume variation for non-folded samples. Narrow range (0.9-1.1) = subtle. Wide range (0.5-1.5) = obvious fluctuations. Range: 2-5 Default: 3 (averaging 3 samples) Effect: Lower = louder folds (less division). Higher = quieter folds (more division). Typically 3 (current + forward + backward) / 3. Range: 1-4 Default: 2 (backward = forward/2) Effect: Controls backward offset relative to forward. Higher = shorter backward offset. Creates asymmetric temporal blur.fold_distance_min & max
amplitude_min & max
fold_average_divisor
fold_backward_divisor