Latent Folding — Topological Manifold Navigation — User Guide

Treats the learned latent audio space as a deformable manifold. Three topologies: Mirror (reflection), Möbius (twist/inversion), Torus (seamless wrap). As the observer traverses the space, boundaries fold or invert acoustic identity — not time-reversal, but identity-reversal. Creates "Recursive Spectralism."

Author: Shai Cohen Affiliation: Department of Music, Bar-Ilan University, Israel Version: 1.0 (2025) License: MIT License Citation: Cohen, S. (2025). Praat AudioTools Repo: https://github.com/ShaiCohen-ops/Praat-plugin_AudioTools
Contents:

What this does

This script implements Latent Folding — a topological manifold navigation engine that treats the learned latent audio space as a deformable manifold. Three topologies are available: Mirror (reflection at boundaries), Möbius (twist/inversion), and Torus (seamless wrap). As the observer traverses the space, boundaries fold or invert acoustic identity — creating what might be called "Recursive Spectralism."

🧭 What is Topological Manifold Navigation?

This approach treats the latent space as a geometric object that can be folded, twisted, or wrapped:

  • Mirror topology: When the observer reaches a boundary, the space reflects — like a mirrored room. Acoustic identity flips.
  • Möbius topology: Crossing a boundary twists the space, inverting polarity and flipping acoustic properties (bright↔dark, noisy↔tonal).
  • Torus topology: The space wraps seamlessly — exiting one side re-enters the opposite side, creating endless loops.

The result is a journey through a folded acoustic universe where identities invert and recur, creating "Recursive Spectralism."

Key Features:

Technical Implementation: (1) Event Segmentation: Praat segments audio into 200ms–3s events. (2) Mel Patches: 40×32 log-mel patches per event. (3) Autoencoder: Train on-the-fly, encode to latent space Z. (4) Manifold Boundaries: Compute bounding box and principal axes. (5) Folding Engine: Traverse manifold with topology-specific boundary behaviors. (6) Reconstruction: Concatenate selected events with crossfades. (7) Stats & Visualization.

Quick start

  1. In Praat, select exactly one Sound object (any duration, any content).
  2. Run script… → select latent_folding.praat.
  3. Choose Preset (2-7 for specific strategies, 1 for custom).
  4. Set latent size and learning steps.
  5. Choose manifold type, fold density, curvature, permutation intensity, symmetry, speed.
  6. Enable Draw_visualization for analysis display.
  7. Click OK — engine segments, trains autoencoder, folds manifold, reconstructs.
Quick tip: Start with Gentle Mirror preset on a 10-20 second recording with varied texture. Enable visualization — you'll see event boundaries (red lines) on the input waveform, and topology stats. Listen to how the sound folds back on itself, creating reflections and inversions. The output appears as "source_fold" in the Objects window.
Important: PYTHON DEPENDENCIES — Requires numpy, soundfile, scipy (no scikit-learn). AUTOENCODER TRAINING happens on-the-fly and may take 30-60 seconds. FOLD DENSITY controls how many folds occur — higher = more frequent boundary crossings. CURVATURE affects fold sharpness — low values create smooth, Escher-like transitions; high values create abrupt flips. SYMMETRY creates palindromic structures — first half, then inverted second half.

Topological Manifold Theory

The Three Topologies

🪞 Mirror Topology (Reflection)

When coordinate exceeds boundary: phase = (val - lo) % (2 * fold_span) if phase > fold_span: new_val = lo + (2 * fold_span - phase) else: new_val = lo + phase Effect: The space reflects like a mirrored room — when you hit a boundary, you bounce back. Acoustic identity flips at each reflection.

🌀 Möbius Topology (Twist)

Crossing a boundary flips polarity: n_crossings = floor((val - lo) / fold_span) if n_crossings % 2 == 1: polarity = -polarity When polarity flips: z_folded = center + (center - z) Effect: A twist in the space inverts acoustic properties — bright becomes dark, noisy becomes tonal.

⭕ Torus Topology (Wrap)

When coordinate exceeds boundary: new_val = lo + (val - lo) % span Effect: Seamless wrap — exiting one side re-enters the opposite side. Endless loop through acoustic space.

Folding Parameters

📐 Fold Density

Number of folds in the manifold:

fold_span = (hi - lo) / fold_density Higher density = more frequent boundary crossings → more folding events.

📈 Curvature

Controls fold sharpness (0 = smooth, 1 = sharp):

alpha = curvature^0.5 final_z = z_original × (1-alpha) + z_folded × alpha Low curvature → smooth, Escher-like transitions High curvature → abrupt flips at boundaries

🔄 Permutation Intensity

Lateral drift during traversal:

lateral_motion = secondary_axis × sin(phase) × intensity × median_dist × 0.3 Creates exploration away from the principal axis.

Symmetry / Palindromic Structure

When symmetry > 0.5: First half: traverse manifold normally Second half: traverse in reverse, but with topological inversion: inverted_z = center + (center - z) × symmetry + optional rotation (permutation_intensity) Result: The second half is an identity-inverted mirror of the first half, creating palindromic structure at the acoustic identity level.

LRU Event Selection

At each step, select event minimizing: score = distance_to_path + LRU_penalty LRU_penalty[i] = (4 - recency) × median_dist × 0.4 (if recency < 4) This prevents the same event from being chosen repeatedly.

Preset Strategies

Preset 2: Gentle Mirror

🪞 Soft Reflections

Manifold: Mirror | Fold density: 2 | Curvature: 0.3

Permutation: 0.3 | Symmetry: 0.0 | Speed: 0.4

Latent: 8 | Steps: 100

Character: Gentle reflections with low curvature — smooth, gradual identity flips

Use on: Ambient, subtle transformations

Preset 3: Sharp Mirror

⚡ Abrupt Reflections

Manifold: Mirror | Fold density: 5 | Curvature: 0.9

Permutation: 0.7 | Symmetry: 0.0 | Speed: 0.6

Character: Many sharp folds, high permutation — dramatic, abrupt flips

Use on: Glitch, abrupt transformations

Preset 4: Möbius Twist

🌀 Identity Inversion

Manifold: Möbius | Fold density: 3 | Curvature: 0.6

Permutation: 0.5 | Symmetry: 0.0 | Speed: 0.5

Latent: 10 | Steps: 120

Character: Moderate twists — polarity inversions flip acoustic identity

Use on: Transformative material, exploring opposites

Preset 5: Torus Loop

⭕ Endless Wrap

Manifold: Torus | Fold density: 2 | Curvature: 0.4

Permutation: 0.4 | Symmetry: 0.0 | Speed: 0.5

Character: Seamless wrapping — cycles endlessly through acoustic space

Use on: Loops, cycles, infinite variations

Preset 6: Palindromic Mirror

🔄 Recursive Structure

Manifold: Mirror | Fold density: 3 | Curvature: 0.5

Permutation: 0.5 | Symmetry: 1.0 | Speed: 0.5

Latent: 10 | Steps: 120

Character: First half traverses, second half is inverted palindrome — recursive structure

Use on: Recursive forms, self-similar structures

Preset 7: Palindromic Möbius

🎭 Recursive Inversion

Manifold: Möbius | Fold density: 4 | Curvature: 0.7

Permutation: 0.6 | Symmetry: 1.0 | Speed: 0.6

Latent: 12 | Steps: 150

Character: Möbius twists plus palindromic structure — maximum recursion

Use on: Complex recursive forms, "Recursive Spectralism"

Parameters & Controls

Manifold Parameters

ParameterDefaultDescription
Latent_size8Autoencoder latent dimensions (2–32)
Learning_steps100Training iterations (10–500)
Manifold_typeMirrorMirror (reflection), Möbius (twist), Torus (wrap)
Fold_density3Number of folds in manifold (1–12)
Curvature0.5Fold sharpness (0 = smooth, 1 = sharp)
Permutation_intensity0.5Lateral drift strength (0–1)
Symmetry0.0Palindromic symmetry (0 = off, 1 = full)
Speed0.5Traversal speed (0.1–3.0)

Output

ParameterDefaultDescription
Seed42Random seed for reproducibility
Draw_visualization1Generate 5-panel analysis display
Play_result1Audition after processing

Visualization & Analysis

5-Panel Display

Latent Folding Visualization: Panel 1: TITLE • Script name, source name, preset, manifold, fold count Panel 2: INPUT WAVEFORM • Gray waveform with red dotted lines = event boundaries • Title: "Original (N events)" Panel 3: OUTPUT WAVEFORM • Purple waveform = folded output • Title: "Folded" • X-axis: Time (s) Panel 4: ORIGINAL SPECTROGRAM • 0-5000 Hz spectrogram of original • Title: "Original spectrogram" Panel 5: OUTPUT SPECTROGRAM • 0-5000 Hz spectrogram of folded output • Title: "Folded spectrogram" Panel 6: TOPOLOGY STATS PANEL • Manifold type, fold density, curvature, permutation • Fold events: total, mirrors, twists, wraps • Palindromic symmetry status and score • Title: "Topology:" Panel 7: SUMMARY PANEL • Steps, unique events, repetition rate, average travel • Autoencoder loss (initial → final), latent size • Duration in/out, RMS comparison • Top events (most frequently selected) • Warnings if any

Reading Topology Stats

What the numbers mean:
  • Fold density: How many folds in the manifold
  • Curvature: 0 = smooth, 1 = sharp folds
  • Fold events: Number of times boundaries were crossed:
    • Mirrors: Reflection events
    • Twists: Polarity inversions (Möbius)
    • Wraps: Seamless wraps (Torus)
  • Symmetry: If ON, second half is identity-inverted mirror of first half
  • Palindromic score: How different the second half's events are from first half (higher = more inverted)

Applications

Electroacoustic Composition

Use case: Creating recursive, folded structures from source material

Technique: Palindromic Mirror or Palindromic Möbius presets

Workflow:

Recursive Spectralism

Use case: Creating compositions where acoustic identities invert and recur

Technique: Möbius topology with symmetry

Concept: "Recursive Spectralism" — the idea that musical material can be folded back on itself, with identities inverting at each fold, creating infinite regress.

Sound Design for Media

Use case: Creating surreal, Escher-like soundscapes

Technique: Torus Loop with low curvature for smooth wraps

Applications:

Research & Education

Use case: Studying topological spaces, manifold navigation

Technique: Compare presets on same source, examine fold events

Learning outcomes:

Practical Workflow Examples

🎬 Film Scene: Recursive Nightmare

Goal: Create 60-second cue representing recursive nightmare logic

Settings:

  • Source: 30-second drone with voice
  • Preset: Palindromic Möbius
  • Custom: curvature=0.8 (sharp twists), fold_density=5

Result: Voice inverts, recurses, creating unsettling recursive nightmare

🎚️ Electronic Music: Infinite Loop

Goal: Create endless loop from 4-bar phrase

Settings:

  • Source: 8-second phrase
  • Preset: Torus Loop
  • Custom: speed=0.3 (slow wrap), curvature=0.2 (smooth)

Result: Phrase wraps seamlessly, creating infinite variation

🎙️ Voice Processing: Identity Inversion

Goal: Transform voice into its opposite

Settings:

  • Source: 10-second vocal phrase
  • Preset: Möbius Twist
  • Custom: symmetry=0.0, curvature=0.5

Result: At each twist, voice inverts — bright↔dark, noisy↔tonal, creating surreal effect

Troubleshooting Common Issues

Problem: Python not found or missing packages
Cause: Python not installed, or packages missing
Solution: Install Python and required packages: pip install numpy soundfile scipy
Problem: Too few events detected
Cause: Source has few intensity peaks, or segmentation parameters inappropriate
Solution: Use source with more dynamic variation, or adjust min/max event duration in script
Problem: Autoencoder loss not decreasing
Cause: Too few steps, too small latent size, or data too complex
Solution: Increase learning_steps, increase latent_size, or use simpler source
Problem: No fold events detected
Cause: Fold density too low, or traversal never reaches boundaries
Solution: Increase fold_density, increase speed, check manifold type
Problem: Output has clicks
Cause: Crossfade insufficient at splice points
Solution: Increase XFADE_SEC in Python script (currently 8ms)

Advanced Techniques

Custom topologies:

In Python script, add new manifold types by implementing new fold functions and adding to generate_folding_path().

Boundary detection tuning:

Modify thresholds for detecting fold events (currently median_dist * 0.1) to change sensitivity.

LRU memory adjustment:

Change recency window (currently 4) and penalty scaling to control repetition avoidance.

Multi-channel output:

The script preserves input channels. For multi-channel input, output maintains same number of channels.