Genetic Recomposer — User Guide

Evolutionary audio recombination: uses genetic algorithms to automatically slice, reorder, and reassemble audio segments, evolving new sonic organisms through fitness-based selection.

Author: Shai Cohen Version: 2.0 (2024) License: MIT License Category: Evolutionary Audio & Algorithmic Composition
Contents:

What this does

This script implements evolutionary audio recombination — a genetic algorithm approach to sound transformation that treats audio segments as genetic material to be sliced, recombined, and evolved over generations. The process: (1) Segment Extraction: Automatically slices input audio into variable-length segments based on genome parameters. (2) Population Initialization: Creates multiple "individuals" with different segmentation, reordering, and processing characteristics. (3) Fitness Evaluation: Scores each individual based on rhythmicity, continuity, and novelty. (4) Evolutionary Loop: Selects best performers, breeds new individuals through crossover and mutation. (5) Convergence: Over 10-15 generations, evolves toward optimal recombination based on fitness criteria.

Key Features:

What are genetic algorithms in audio? Traditional audio processing: deterministic transformations with predictable outcomes. Evolutionary audio: stochastic exploration of transformation space. Advantages: (1) Creative discovery: Finds unexpected recombinations. (2) Optimization: Automatically seeks "best" results based on criteria. (3) Variation: Produces unique results each run. (4) Complexity handling: Manages multi-parameter optimization. (5) Emergent behavior: Simple rules produce complex outcomes. Use cases: Sound design (generative textures), music composition (algorithmic recombination), experimental audio (glitch art), research (evolutionary aesthetics), teaching (genetic algorithm visualization).

Technical Implementation: (1) Genome Representation: Each individual defined by 8 parameters: segment min/max, bias, reorder probability, crossfade length, silence probability, silence min/max. (2) Fitness Function: Three components: rhythm (event rate from silence detection), continuity (waveform consistency), novelty (DC ratio). (3) Evolution Operators: Tournament selection, blend crossover, Gaussian mutation. (4) Strength Mapping: User's effect strength (1-10) nonlinearly maps to parameter ranges. (5) Real-time Synthesis: Each generation synthesizes all individuals for evaluation. Key insight: The algorithm doesn't just randomly reorder — it evolves toward combinations that satisfy multiple aesthetic criteria simultaneously.

Quick start

  1. In Praat, select any Sound object (speech, music, field recording).
  2. Run script…genetic_recomposer.praat.
  3. Choose preset based on desired effect (start with "Granular Shimmer").
  4. Set target_duration_s (output length, default 8.0s).
  5. Adjust effect_strength (1=subtle, 10=extreme).
  6. Set pop_size (population size, default 10) and generations (default 10).
  7. Click OK — watch evolution progress in Info window.
  8. Final output named "GA_Recombine_best" appears in Objects window.
Quick tip: Start with preset 3 (Granular Shimmer) for smooth, musical results. Use effect_strength = 3-6 for balanced transformations. For rhythmic material, set fitness_stride = 2 to evaluate rhythm every generation. Watch the Info window during evolution — fitness scores show progress. The algorithm runs faster with smaller pop_size (8-12). Each generation synthesizes pop_size sounds — complex sounds may take longer. Result varies each run due to randomness — run multiple times for different outcomes. Enable play_result = 1 to hear best result automatically.
Important: COMPUTATION INTENSIVE — Each generation synthesizes pop_size sounds. Large populations (15+) with long target durations (15s+) may be slow. Evolution is stochastic — different runs produce different results even with same settings. Not all source material works equally — rhythmic/structured audio evolves better than pure noise. Effect strength nonlinearly controls multiple parameters — higher values shorten segments, increase reordering, add more silence. Target duration should be reasonable relative to source — very short outputs from long sources may lose coherence. Fitness function optimizes for balance — not necessarily "musical" in traditional sense. Silence insertion can create rhythmic gaps — control with max_silence_prob.

Genetic Algorithm Basics

🧬 The Evolutionary Process

1. Initialization: Create random population of individuals (audio recombination strategies)

2. Evaluation: Synthesize audio for each individual, calculate fitness score

3. Selection: Choose best individuals as parents for next generation

4. Reproduction: Create new individuals through crossover (mixing parent traits) and mutation (random changes)

5. Iteration: Repeat evaluation-selection-reproduction for specified generations

6. Convergence: Population evolves toward higher fitness solutions

Population Dynamics

ParameterDefaultEffectTrade-off
pop_size10Number of individuals per generationLarger = better exploration but slower
generations10Evolution cyclesMore = better optimization but slower
elite_count2Best individuals preserved unchangedPreserves good solutions, reduces diversity
mutation_rate0.30Probability of random changesHigher = more exploration, less convergence

Crossover and Mutation

CROSSOVER (Blend Inheritance): child_param = blend × parent1_param + (1-blend) × parent2_param blend = randomUniform(0, 1) # different blend per parameter Example: parent1.segMin = 50ms, parent2.segMin = 100ms, blend = 0.3 child.segMin = 0.3×50 + 0.7×100 = 15 + 70 = 85ms MUTATION (Gaussian Noise): param = param + randomGauss(0, scale) Example (segment length mutation): scale = (max_seg_ms - min_seg_ms) × 0.12 segMinMs = segMinMs + randomGauss(0, 30) # ±30ms typical CLAMPING: All parameters clamped to valid ranges after mutation

Evolutionary Timeline

⏱️ Generation-by-Generation Progress

Generation 1: Random population, wide diversity, low average fitness

Generations 2-4: Rapid improvement, convergence toward viable strategies

Generations 5-8: Slower refinement, exploitation of good solutions

Generations 9-10+: Stabilization, minor improvements, potential stagnation

Typical fitness progression: 0.3 → 0.6 → 0.8 → 0.85 → 0.87...

Preset Styles

🎨 Preset 1: Custom

Character: Manual control, use form values exactly as specified

Use when: You know exactly what parameters you want

Effect strength: As specified in form

Segment range: min_seg_ms to max_seg_ms

🌫️ Preset 2: Subtle Texture

Character: Gentle granulation, minimal disruption

Parameters: strength=3, pop=8, gen=8, xfade=8ms, silence=15%

Best for: Adding subtle motion to static sounds, background textures

Example source: Pads, drones, ambient field recordings

✨ Preset 3: Granular Shimmer

Character: Smooth granular synthesis with musical crossfades

Parameters: strength=5, pop=12, gen=12, xfade=12ms, silence=20%

Best for: Evolving textures, melodic fragmentation, cloud-like effects

Example source: Vocal phrases, piano, string sections

🌀 Preset 4: Glitch / Stutter

Character: Aggressive cuts, digital artifacts, rhythmic stutters

Parameters: strength=8, pop=10, gen=10, xfade=3ms, silence=45%

Best for: Glitch art, IDM, experimental percussion

Example source: Drum breaks, spoken word, synth sequences

💥 Preset 5: Extreme Fragmentation

Character: Maximum chaos, micro-sounds, rapid-fire sequencing

Parameters: strength=10, seg=10-80ms, pop=15, gen=15, xfade=2ms, silence=50%

Best for: Sound design, noise music, abstract composition

Example source: Anything — results will be highly abstracted

🎵 Preset 6: Rhythmic Loops

Character: Longer segments, musical phrases, loop-friendly

Parameters: strength=6, seg=50-250ms, pop=12, gen=12, xfade=10ms, silence=30%

Best for: Beat construction, phrase sampling, loop generation

Example source: Funk guitars, drum loops, basslines

Preset Selection Guide

Desired OutcomeRecommended PresetStrengthNotes
Subtle background texture2 (Subtle Texture)2-4Works with any source
Musical granular clouds3 (Granular Shimmer)4-7Best with tonal material
Glitch effects4 (Glitch/Stutter)7-9Rhythmic sources work best
Abstract sound design5 (Extreme Fragmentation)8-10Expect radical transformation
Loop construction6 (Rhythmic Loops)5-7Use with musical phrases
Complete control1 (Custom)AnySet all parameters manually

Genome Structure

🧬 The 8 Genetic Parameters

Each individual in the population is defined by these 8 traits:

  1. segMinMs / segMaxMs: Minimum and maximum segment length (ms)
  2. segBias: Distribution bias (-0.8 to 0.8, negative=shorter bias)
  3. reorderProb: Probability of reordering segments (0-1)
  4. crossfadeMs: Crossfade length between segments (ms)
  5. silenceProb: Probability of inserting silence (0-0.6)
  6. silenceMin / silenceMax: Minimum and maximum silence length (ms)

Segment Generation Algorithm

PSEUDOCODE: time = 0 while time < inputDuration: # Generate segment length with bias rand = randomUniform(0, 1) if bias < 0: rand = rand ^ (1 - bias) # bias toward shorter elif bias > 0: rand = 1 - (1 - rand) ^ (1 + bias) # bias toward longer segLength = segMin + rand × (segMax - segMin) store segment [time, time+segLength] time = time + segLength EXAMPLE (bias = -0.5): rand = 0.7 → rand' = 0.7^(1.5) = 0.59 → shorter segment rand = 0.3 → rand' = 0.3^(1.5) = 0.16 → even shorter EXAMPLE (bias = 0.5): rand = 0.7 → rand' = 1 - (1-0.7)^1.5 = 1 - 0.16 = 0.84 → longer rand = 0.3 → rand' = 1 - (1-0.3)^1.5 = 1 - 0.59 = 0.41 → medium

Segment Reordering

reorderProb = 0.3 # 30% chance segments will be reordered if reorderProb > 0: numToSwap = floor(totalSegments × reorderProb) for i to numToSwap: # Pick random segment s1 = randomInteger(1, totalSegments) # Pick nearby segment (±25% of total) range = max(2, floor(totalSegments × 0.25)) s2 = s1 + randomInteger(-range, range) clamp s2 to 1..totalSegments swap segmentOrder[s1] with segmentOrder[s2] EFFECT: reorderProb = 0.0 → segments in chronological order reorderProb = 0.3 → ~30% of segments swapped with neighbors reorderProb = 1.0 → complete randomization (rare)

Silence Insertion

silenceProb = 0.25 # 25% chance after each segment for each segment position: if randomUniform(0,1) < silenceProb: silenceLength = randomUniform(silenceMin, silenceMax) insert silence of that length EXAMPLE WITH silMin=20ms, silMax=80ms: 25% chance of inserting 20-80ms of silence Creates rhythmic gaps, stutter effects WHY SILENCE?: • Creates rhythmic structure • Prevents density overload • Allows "breathing" in texture • Can be evolved as musical rests

Crossfade Smoothing

crossfadeMs = 6 # 6ms crossfade between segments # Safety check: don't crossfade more than half shortest segment minPartDur = minimum(partDurations) safeXfade = min(crossfadeMs, minPartDur/2 - 0.5ms) if safeXfade > 1ms: Concatenate with overlap: safeXfade else: Concatenate (no crossfade) EFFECT: crossfadeMs = 0 → hard cuts, clicks possible crossfadeMs = 6 → smooth 6ms transitions crossfadeMs = 12 → very smooth, granular-like

Strength Mapping

User sets effect_strength = 1..10 Normalize: strength = (effect_strength - 1) / 9 # 0..1 EFFECT ON PARAMETERS: • segMinMs = segMinMs - 8 × effect_strength (shorter) • segMaxMs = segMaxMs - 10 × effect_strength (shorter) • reorderProb = 0.10 + 0.05 × effect_strength (more reordering) • silenceProb = base × (0.5 + 0.08 × effect_strength) (more silence) • crossfadeMs = crossfadeMs - 0.4 × effect_strength (shorter xfade) EXAMPLE (strength=8): Original segMin=50ms → eff_segMin = 50 - 8×8 = 50-64 = -14 → clamp to 10ms Original xfade=8ms → eff_xfade = 8 - 0.4×8 = 8-3.2 = 4.8ms More fragmentation, more reordering, less smoothing

Fitness Evaluation

🏆 Multi-Objective Fitness Function

Total fitness = rhythm_weight × rhythmScore + continuity_weight × continuityScore + novelty_weight × noveltyScore

Default weights: rhythm=1.0, continuity=0.8, novelty=1.0

Goal: Evolve individuals that balance rhythmic interest, smooth continuity, and novelty

Rhythm Score (Event Rate Analysis)

PROCESS: 1. Detect silences using Praat's "To TextGrid (silences)" 2. Count "sounding" intervals (non-silent regions) 3. Calculate events per second = count / duration SCORING: If eventRate < 2 events/sec: score = eventRate / 2 (too sparse) If eventRate > 10 events/sec: score = 1 - (eventRate-10)/10 (too dense) Else (2-10 events/sec): score = 1.0 (optimal range) EXAMPLE: eventRate = 0.5 → score = 0.25 (too sparse, penalized) eventRate = 5.0 → score = 1.0 (optimal, rewarded) eventRate = 15.0 → score = 0.5 (too dense, penalized)

Continuity Score (Waveform Consistency)

PROCESS: 1. Calculate mean, standard deviation, RMS of waveform 2. Compute ratio = standard_deviation / RMS 3. score = max(0, 1.0 - ratio) INTERPRETATION: ratio = 0.1 → score = 0.9 (very consistent) ratio = 0.5 → score = 0.5 (moderate variation) ratio = 1.0 → score = 0.0 (highly variable/choppy) PHYSICAL MEANING: Low ratio: steady amplitude, smooth transitions High ratio: abrupt changes, jumps, discontinuities

Novelty Score (DC Bias Detection)

PROCESS: 1. Calculate mean (DC offset) and RMS 2. Compute dcRatio = abs(mean) / RMS 3. score = max(0, 1.0 - dcRatio) INTERPRETATION: dcRatio = 0.0 → score = 1.0 (balanced, no DC bias) dcRatio = 0.5 → score = 0.5 (moderate DC bias) dcRatio = 1.0 → score = 0.0 (strong DC bias) PHYSICAL MEANING: Low DC bias: waveform centered around zero, good dynamics High DC bias: waveform offset, potentially less dynamic

Fitness Stride Optimization

fitness_stride = 3 # Calculate rhythm every 3 generations WHY?: • Rhythm calculation is expensive (requires silence detection) • Continuity/novelty are cheap (waveform statistics) • Fitness_stride = 1: rhythm every generation (accurate, slow) • Fitness_stride = 3: rhythm every 3 generations (fast, approximate) • Fitness_stride = 999: rhythm only first generation (fastest) TRADEOFF: Higher stride = faster evolution, less accurate rhythm assessment Lower stride = slower evolution, more accurate rhythm tracking

Interpreting Fitness Values

Total FitnessInterpretationTypical Characteristics
0.0 - 0.3PoorToo sparse/too dense, choppy, DC-biased
0.3 - 0.6FairImbalanced in one or more dimensions
0.6 - 0.8GoodBalanced, musically interesting
0.8 - 1.0ExcellentOptimal rhythm, smooth, novel
1.0+Theoretical maxPerfect scores in all dimensions

Creative Applications

Generative Sound Design

🎨 Evolving Textures from Source Material

Workflow:

  1. Start with simple source (sine wave, noise, single instrument)
  2. Use preset 3 (Granular Shimmer) with strength 4-6
  3. Run evolution for 12-15 generations
  4. Take best result, use as source for another evolution
  5. Repeat 2-3 times for complex emergent textures

Result: Rich, evolving soundscapes with history of transformations

Algorithmic Remixing

🔄 Intelligent Audio Recombination

Workflow:

  1. Select musical phrase (vocal, melody, chord progression)
  2. Use preset 6 (Rhythmic Loops) with strength 5-7
  3. Set target_duration to original length or multiple
  4. Evolve for 10+ generations
  5. Best result often retains musicality while introducing variation

Result: Algorithmic remix that balances familiarity and novelty

Evolutionary Composition

🎼 Generative Music Construction

Workflow:

  1. Create short musical elements (notes, chords, rhythms)
  2. Concatenate into source sound
  3. Evolve with preset 3 or 6
  4. Export best results, arrange in DAW
  5. Use as raw material for further composition

Result: Unique musical materials with algorithmic character

Advanced Techniques

Serial Evolution (Deep Evolution):
  1. Run evolution on source, save best result
  2. Use best result as new source
  3. Run evolution again with different parameters
  4. Repeat 3-5 times
  5. Final result often has complex, layered character

Example: Source → Granular Shimmer → Glitch/Stutter → Rhythmic Loops

Parameter Exploration:
  • Population size exploration: Run with pop_size=5,10,15, compare results
  • Generation depth: Run for 5,10,20 generations, observe convergence
  • Strength sweep: Run same source at strength 3,6,9, compare transformations
  • Preset comparison: Run all 6 presets on same source, collect best of each

Troubleshooting Common Issues

Problem: Evolution stalls (fitness stops improving)
Causes: Population too small, mutation rate too low, fitness plateau
Solutions: Increase pop_size (12-15), increase mutation_rate (0.4-0.5), try different source material
Problem: Results too similar to source
Causes: Effect strength too low, segments too long, reordering too little
Solutions: Increase effect_strength (7-10), decrease max_seg_ms (50-100ms), increase max_silence_prob (0.4-0.5)
Problem: Results too chaotic/unmusical
Causes: Effect strength too high, segments too short, too much silence
Solutions: Decrease effect_strength (2-4), increase min_seg_ms (50-100ms), decrease max_silence_prob (0.1-0.2)
Problem: Processing too slow
Causes: Large population, many generations, long target duration
Solutions: Reduce pop_size (8-10), reduce generations (8), reduce target_duration_s (4-6s), increase fitness_stride (3-4)

Performance Optimization

SettingFasterSlower (Better)Sweet Spot
pop_size5-812-1510
generations5-815-2010-12
fitness_stride4-51-23
target_duration_s4-612-158
min_seg_ms10-2050-10020-50