Knight's Tour Sonification — Complete Guide

Mathematical audio processing: maps knight's chess piece movements to stereo panning and amplitude modulation, creating dynamic spatial audio experiences with real-time visualization.

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

What this does

This script implements knight's tour sonification — an advanced audio processing technique that maps the mathematical knight's tour puzzle onto audio parameters. The system divides your audio into 64 segments (matching chessboard squares) and applies dynamic stereo panning and amplitude modulation based on the knight's movement pattern across the board.

Key Features:

What is knight's tour sonification? Traditional audio processing: manual automation, fixed patterns. Knight's tour sonification: Uses mathematical chess puzzles to control audio parameters algorithmically. Advantages: (1) Mathematical beauty: Applies elegant mathematical patterns to sound. (2) Spatial complexity: Creates intricate stereo movement patterns. (3) Visual correlation: Clear relationship between visual path and audio result. (4) Algorithmic variation: Different tours create completely different sonic experiences. (5) Educational value: Demonstrates mathematical concepts through sound. Use cases: Experimental music composition, sound design for media, mathematical education, algorithmic art, spatial audio research.

Technical Implementation: (1) Tour Selection: Loads predefined knight's tour paths. (2) Parameter Mapping: Converts chess coordinates to audio parameters. (3) Segment Processing: Divides audio into 64 equal segments. (4) Real-time Visualization: Displays progressive chessboard and parameter graphs. (5) Audio Processing: Applies panning and amplitude to each segment. (6) Stereo Synthesis: Uses constant-power panning for natural spatialization. (7) Quality Control: Parameter validation and progress monitoring.

Quick start

  1. In Praat, select exactly one Sound object.
  2. Run script…knights_tour_sonification.praat.
  3. Choose tourPreset for knight's movement pattern.
  4. Set intensityMin/Max for loudness variation range.
  5. Set stereoMin/Max for panning position range.
  6. Enable playDuringProcessing for real-time preview.
  7. Adjust visualizationDelay for animation speed.
  8. Click OK — real-time visualization appears and processing begins.
  9. Watch the knight move while hearing the processed audio.
  10. Final result appears as "KnightsTour_originalname".
Quick tip: Start with Warnsdorff (Classic) preset for traditional knight's tour. Use headphones to appreciate the stereo panning effects. The visualization shows: Top = chessboard with knight's path, Bottom = parameter curves over time. Red curve = stereo position, Blue curve = intensity. The knight's X position (1-8) controls left-right panning, Y position (1-8) controls loudness. Each of the 64 chess squares corresponds to one audio segment.
Important: PROCESSING TIME — Creates 64 individual audio segments + real-time visualization. Long audio files will take significant time. MEMORY USAGE — High segment count requires substantial RAM. REAL-TIME CONSTRAINTS — Visualization delay affects total processing time. PARAMETER VALIDATION — Script validates intensity and stereo ranges to prevent errors. STEREO OUTPUT — Always creates stereo output, even from mono input. ORIGINAL PRESERVATION — Original sound remains unchanged; new object created.

Knight's Tour Theory

What is a Knight's Tour?

♞ Mathematical Chess Puzzle

Definition: Sequence of knight moves that visits each square exactly once

Chess context: Knight moves in "L-shape" (2 squares one direction, 1 square perpendicular)

Mathematical significance: Classic problem in graph theory and combinatorics

Knight movement rules:

Chess knight moves in L-patterns: (±2, ±1) or (±1, ±2) Possible moves from any position: (x+2, y+1), (x+2, y-1), (x-2, y+1), (x-2, y-1) (x+1, y+2), (x+1, y-2), (x-1, y+2), (x-1, y-2) Constraints: Must stay on 8×8 board (1≤x≤8, 1≤y≤8) Cannot revisit squares Must visit all 64 squares exactly once Mathematical properties: Number of possible tours: ~26,534,728,821,064 First studied by Euler (1759) Applications in computer science and mathematics

Historical Context

Mathematical Heritage

Knight's tour history:

9th century: First documented in Arabic chess manuscripts 18th century: Euler publishes systematic analysis 19th century: Interest in closed tours (return to start) 20th century: Computer algorithms developed 21st century: Applications in cryptography and algorithms Key figures: Al-Adli (9th century Arabic scholar) Leonhard Euler (1707-1783) H. C. von Warnsdorff (1823 heuristic) Modern computer scientists Mathematical significance: - Graph theory applications - Hamiltonian path problem - Algorithm design - Computational complexity

Tour Types and Properties

Open vs Closed Tours

Tour classification:

Tour TypeDefinitionPropertiesAudio Effect
Open TourStart and end different squaresMore common, easier to findAsymmetric parameter evolution
Closed TourStart and end squares connected by knight moveRarer, mathematically elegantCyclic, could loop seamlessly
SymmetricalExhibits board symmetriesAesthetically pleasingBalanced stereo image
RandomNo particular patternMaximum unpredictabilityChaotic spatial movement

Audio Mapping System

Coordinate to Parameter Mapping

🎵 Chess Coordinates to Audio Parameters

Fundamental mapping: X-position → stereo panning, Y-position → amplitude

Time division: 64 equal segments for 64 squares

User control: Customizable parameter ranges

Mapping mathematics:

For each step k (1 to 64): Raw stereo = (x[k] - 1) / 7 # Map 1-8 to 0-1 Stereo[k] = stereoMin + rawStereo × (stereoMax - stereoMin) Raw intensity = (y[k] - 1) / 7 # Map 1-8 to 0-1 Intensity[k] = intensityMin + rawIntensity × (intensityMax - intensityMin) Time[k] = (k - 1) × duration / 64 SegmentDur[k] = duration / 64 Where: x[k], y[k] = knight position at step k stereoMin, stereoMax = user-defined panning range intensityMin, intensityMax = user-defined loudness range duration = original sound duration

Stereo Panning System

Constant-Power Panning

Natural spatial positioning:

Constant-power panning formula: panAngle = stereo[k] × (π / 2) leftGain = cos(panAngle) rightGain = sin(panAngle) Where stereo[k] ranges: 0.0 = full left (leftGain=1.0, rightGain=0.0) 0.5 = center (leftGain=0.707, rightGain=0.707) 1.0 = full right (leftGain=0.0, rightGain=1.0) Advantages over linear panning: - Constant perceived loudness across panorama - Smooth transitions between channels - Professional audio standard - Natural spatial perception User range mapping: stereoMin=0.0, stereoMax=1.0 → full stereo field stereoMin=0.25, stereoMax=0.75 → restricted center region

Amplitude Modulation

Dynamic Loudness Control

Intensity mapping:

Amplitude scaling: output_sample = input_sample × intensity[k] Where intensity[k] ranges: intensityMin = minimum amplification (e.g., 0.3 = 30% volume) intensityMax = maximum amplification (e.g., 1.0 = 100% volume) Examples: Knight at bottom (y=1): intensity ≈ intensityMin (quiet) Knight at top (y=8): intensity ≈ intensityMax (loud) Knight middle (y=4-5): moderate volume Musical effects: - Creates dynamic expression - Emphasizes certain path sections - Can create rhythmic patterns - Adds musical phrasing

Time Segmentation

64 Equal Audio Segments

Temporal structure:

Time division: total_duration = original sound length segment_duration = total_duration / 64 segment_start[k] = (k - 1) × segment_duration segment_end[k] = k × segment_duration Audio processing per segment: 1. Extract segment from original sound 2. Apply intensity scaling (amplitude) 3. Create left and right channels with panning gains 4. Combine into stereo segment 5. Concatenate with previous segments Quality considerations: - Rectangular window for clean segmentation - No crossfade between segments - Maintains original timing precisely - Potential clicks at segment boundaries (intentional)

Parameter Range Examples

SettingintensityMin-MaxstereoMin-MaxAudio Character
Subtle0.7-1.00.3-0.7Gentle variations, centered
Dynamic0.3-1.00.0-1.0Strong contrasts, full stereo
Left-heavy0.5-1.00.0-0.5Quieter right, left emphasis
Rhythmic0.1-1.00.5-0.5Strong volume changes, mono
Spatial0.8-1.00.0-1.0Constant volume, wide stereo

Real-time Visualization System

Dual-Panel Display

👁️ Progressive Visualization

Top panel: Chessboard with knight's path evolution

Bottom panel: Parameter curves showing stereo and intensity over time

Real-time updates: Display updates with each processing step

Visualization components:

PANEL A: Chessboard Visualization - 8×8 grid representing chessboard - Progressive path drawing as knight moves - Step numbers on each visited square - Color coding: Red=start, Blue=current, Black=completed - Animated line showing knight's path PANEL B: Parameter Visualization - Time on X-axis (0 to duration) - Parameter values on Y-axis (0-1) - Red curve: stereo position over time - Blue curve: intensity over time - User range indicators (lime/magenta) - Progressive drawing as processing advances Real-time features: - Current step highlighted on both displays - Time marker shows processing progress - Visual feedback during audio playback - Complete final visualization

Chessboard Display Details

Progressive Path Visualization

Step-by-step board evolution:

At each step k: Draw completed path segments (steps 1 to k-1) Draw all visited squares (steps 1 to k) Highlight current square (step k) Show step numbers on all visited squares Maintain start and end point colors Visual elements: Grid lines: light gray, thin Path lines: black, thick Start square: red circle, thick Current square: blue circle, very thick Step numbers: black text Completed squares: black circles, medium Educational value: - Shows knight's movement pattern clearly - Demonstrates mathematical path-finding - Provides visual correlation with audio - Helps understand parameter mapping

Parameter Graph Details

Dual-Curve Time Display

Real-time parameter tracking:

Graph elements: X-axis: time from 0 to sound duration Y-axis: parameter values from 0 to 1 Reference lines: 0, 0.5, 1.0 (gray) User range indicators: dotted lines (lime/magenta) Stereo curve: red line with points Intensity curve: blue line with points Current time marker: vertical black line Progressive drawing: Steps 1 to k-1: complete curves Step k: current point highlighted Real-time correlation with audio playback Final display shows complete evolution Information display: - Shows parameter ranges clearly - Demonstrates time mapping - Provides immediate feedback - Helps tune parameter bounds

Animation Control

Visualization Timing

Controlling display speed:

visualizationDelay parameter: Purpose: Controls pause between steps Range: 0.0 (fast) to 1.0 (slow) Default: 0.05 seconds Effect: Longer delay = slower animation Total processing time: base_time = audio processing time animation_time = 64 × visualizationDelay total_time = base_time + animation_time Usage scenarios: visualizationDelay = 0.0: Maximum speed, minimal animation visualizationDelay = 0.05: Balanced, watchable animation visualizationDelay = 0.2: Slow, educational demonstration visualizationDelay = 0.5: Very slow, detailed observation Considerations: - Longer delays increase total processing time - Shorter delays may be too fast to follow - Adjust based on purpose and audio length

Tour Presets

Preset 1: Warnsdorff (Classic)

♞ Traditional Algorithm

Algorithm: Warnsdorff's heuristic (1823)

Path character: Systematic, efficient coverage

Audio effect: Balanced, musical evolution

Warnsdorff heuristic:

Warnsdorff's Rule (1823): "Always move the knight to the square from which it will have the fewest onward moves" Properties: - Simple yet effective heuristic - Often finds complete tours - Creates relatively smooth paths - Good for demonstration purposes Audio characteristics: - Smooth parameter transitions - Good stereo balance - Musical phrasing emerges - Predictable yet interesting Historical significance: - One of earliest heuristic algorithms - Still used in computer implementations - Foundation for more advanced methods

Preset 2: Spiral Pattern

🌀 Outward Spiral

Pattern: Moves from center outward in spiral

Path character: Concentric, expanding

Audio effect: Growing intensity and widening stereo

Preset 3: Diagonal Heavy

↗️ Diagonal Emphasis

Pattern: Prefers diagonal movements

Path character: Angular, diagonal bias

Audio effect: Correlated stereo and intensity changes

Preset 4: Center-Out

🎯 Center Starting Point

Pattern: Begins in center, explores outward

Path character: Radial exploration

Audio effect: Centered start with expanding spatialization

Preset 5: Alternating Sides

⚖️ Left-Right Alternation

Pattern: Jumps frequently between left and right sides

Path character: Lateral, side-to-side

Audio effect: Rapid stereo panning with stable volume

Preset Comparison Table

PresetPath PatternStereo BehaviorIntensity BehaviorBest For
WarnsdorffSystematic coverageBalanced movementGradual changesGeneral use, education
SpiralOutward expansionWidening fieldGrowing intensityCrescendo effects
DiagonalDiagonal emphasisCorrelated panningLinked to positionCoordinated changes
Center-OutRadial explorationCenter to edgesVariable levelsSpatial expansion
AlternatingSide-to-sideRapid panningRelatively stableStereo excitement

Mathematical Properties of Presets

Path Analysis

Statistical characteristics:

Path smoothness metrics: Warnsdorff: Medium smoothness, few long jumps Spiral: High smoothness, gradual movement Diagonal: Low smoothness, frequent direction changes Center-Out: Medium smoothness, radial pattern Alternating: Low smoothness, lateral jumps Coverage patterns: Warnsdorff: Even coverage, no strong biases Spiral: Center-heavy early, edge-heavy late Diagonal: Prefers central diagonals Center-Out: Radial coverage from center Alternating: Alternating side coverage Audio implications: Smooth paths = gradual parameter changes Jumpy paths = abrupt parameter changes Biased coverage = parameter clustering Even coverage = balanced parameter use

Applications

Experimental Music Composition

Use case: Creating algorithmically controlled spatial music

Technique: Process musical phrases with different tour presets

Presets: Warnsdorff for balanced results, Alternating for excitement

Sound Design for Media

Use case: Generating dynamic spatial effects for film/games

Technique: Apply to sound effects with extreme parameter ranges

Presets: Spiral for growing effects, Alternating for chaotic movement

Mathematical Education

Use case: Teaching graph theory and algorithms through sound

Technique: Use visualization with educational commentary

Presets: Warnsdorff for algorithm demonstration

Algorithmic Art

Use case: Creating audio-visual installations

Technique: Combine with visual projections of knight's movement

Presets: All presets for variety in long-duration works

Spatial Audio Research

Use case: Studying perception of spatial movement in audio

Technique: Systematic testing with different path patterns

Presets: Different patterns for comparative studies

Practical Workflow Examples

🎼 Musical Phrase Processing

Goal: Add spatial interest to musical phrases

Settings:

  • Preset: Warnsdorff or Spiral
  • Intensity: 0.7-1.0 (subtle dynamics)
  • Stereo: 0.2-0.8 (avoid hard panning)
  • Play during processing: Yes
  • Visualization delay: 0.05s

Result: Musically satisfying spatial enhancement

🎬 Sci-Fi Sound Effects

Goal: Create alien or technological spatial effects

Settings:

  • Preset: Alternating Sides
  • Intensity: 0.3-1.0 (strong dynamics)
  • Stereo: 0.0-1.0 (full spatial range)
  • Play during processing: Yes
  • Visualization delay: 0.1s (watch the pattern)

Result: Dramatic, unpredictable spatial movement

🏫 Mathematics Demonstration

Goal: Teach knight's tour concepts

Settings:

  • Preset: Warnsdorff (classic algorithm)
  • Intensity: 0.5-1.0 (clear audio)
  • Stereo: 0.0-1.0 (full stereo demonstration)
  • Play during processing: No (focus on visualization)
  • Visualization delay: 0.2s (slow, educational)

Result: Clear demonstration of algorithm with audio feedback

Creative Techniques

Parameter combination strategies:
  • Correlated parameters: Use similar ranges for coordinated effects
  • Anti-correlated parameters: Use opposite ranges for contrasting effects
  • Restricted ranges: Narrow ranges for subtle effects
  • Extreme ranges: Wide ranges for dramatic effects
  • Asymmetric ranges: Different min-max for biased effects
Advanced processing ideas:
  • Layered processing: Apply multiple tours to same audio
  • Parameter automation: Change ranges during processing
  • Hybrid approaches: Combine with other processing methods
  • Custom tours: Create your own knight's tour paths
  • Multi-channel: Extend to surround sound formats

Troubleshooting Common Issues

Problem: Processing takes extremely long time
Cause: Long audio file, high visualization delay
Solution: Use shorter audio, reduce visualization delay
Problem: Audio has clicks or gaps between segments
Cause: Rectangular windowing, no crossfade
Solution: This is intentional for clear segmentation
Problem: Stereo effect too subtle or extreme
Cause: Incorrect stereoMin/Max settings
Solution: Adjust stereo range parameters
Problem: Volume variations too strong or weak
Cause: Incorrect intensityMin/Max settings
Solution: Adjust intensity range parameters
Problem: Visualization too fast or slow to follow
Cause: Incorrect visualizationDelay setting
Solution: Adjust visualization delay parameter

Technical Reference

Complete Parameter Reference

ParameterTypeDefaultDescription
tourPresetoptionmenu1Knight's tour path algorithm
intensityMinreal0.3Minimum intensity (amplitude scaling)
intensityMaxreal1.0Maximum intensity (amplitude scaling)
stereoMinreal0.0Minimum stereo position (left)
stereoMaxreal1.0Maximum stereo position (right)
playDuringProcessingboolean1Play audio during processing
visualizationDelaypositive0.05Delay between steps for visualization (s)

Output Specifications

Generated Sound Properties

Technical details:

Output object: "KnightsTour_originalname" Type: Stereo Sound (always 2 channels) Duration: Same as original sound Sampling frequency: Same as original Content: 64 segments with applied panning and amplitude Segment properties: Each segment has constant panning and amplitude No crossfade between segments Rectangular window segmentation Constant-power panning law Quality considerations: - Maintains original audio quality within segments - Potential clicks at segment boundaries (feature) - No sample rate conversion or resampling - Original timing preserved exactly

Performance Characteristics

Processing Time Factors

Major time consumers:

1. Segment extraction: 64× O(segment_length) 2. Amplitude scaling: 64× O(segment_length) 3. Panning application: 128× O(segment_length) (2 channels) 4. Stereo combination: 64× O(segment_length) 5. Concatenation: O(total_length) 6. Visualization: 64× drawing operations Total complexity: O(total_length + 64×visualization) Typical performance: 1-minute audio: 2-3 minutes with visualization 5-minute audio: 10-15 minutes with visualization 30-minute audio: 1-2 hours with visualization Memory usage: Peak: ~2× original size during processing Final: same as original (stereo vs possibly mono)