Multi-Band Onset Detector — User Guide

Spectral event separation: isolates transient attacks from sustained content using multi-band energy analysis, with specialized modes for music and speech processing.

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

What this does

This script implements multi-band onset detection and separation — an advanced signal processing technique that isolates transient events from sustained content by analyzing energy changes across multiple frequency bands. Unlike simple amplitude-based detection, this method provides: (1) Multi-band analysis: Detects onsets across the entire frequency spectrum. (2) Energy-based detection: Identifies rapid energy increases characteristic of attacks. (3) Dual-mode operation: Music mode for percussive/tonal separation, Speech mode for consonant/vowel separation. (4) Temporal shaping: Adjustable attack and release windows for natural-sounding results. (5) Performance optimization: Configurable downsampling for efficient processing. Process analyzes audio across logarithmically-spaced frequency bands, computes combined energy envelope, detects onsets via differentiation, creates temporal mask, and separates transients from sustained content. Result: clean separation of attack transients from sustained resonances with applications in sound design, music analysis, and audio restoration.

Key Features:

What is multi-band onset detection? Traditional onset detection: Simple amplitude thresholding or spectral flux measurement. Multi-band onset detection: Sophisticated analysis that considers energy changes across multiple frequency regions simultaneously. Key characteristics: (1) Frequency awareness: Differentiates between low-frequency thumps and high-frequency clicks. (2) Energy-based: Detects actual energy increases rather than just amplitude changes. (3) Temporal precision: Preserves timing relationships between events. (4) Adaptive operation: Automatically adjusts to input signal characteristics. Advantages: (1) Accuracy: More reliable detection of musical attacks and speech consonants. (2) Flexibility: Works across different sound types and genres. (3) Musical relevance: Separates perceptually distinct sound components. (4) Creative potential: Enables novel sound design techniques. Use cases: Sound design (attack/resonance separation), music production (drum processing, transient shaping), audio restoration (click removal, noise reduction), music analysis (rhythm extraction, event detection), speech processing (consonant/vowel separation), experimental composition (spectromorphological manipulation).

Technical Implementation: (1) Preprocessing: Convert to mono and optional downsampling for performance. (2) Multi-band filtering: Split audio into logarithmically-spaced frequency bands. (3) Envelope extraction: Compute energy envelope for each band via rectification and smoothing. (4) Onset detection: Differentiate combined envelope to find energy increases. (5) Mask creation: Threshold onset function and apply temporal shaping. (6) Separation: Multiply original audio by mask and inverse mask. (7) Post-processing: Resample back to original rate and normalize. Key insight: Musical attacks and speech consonants create rapid energy increases across multiple frequency bands simultaneously, while sustained tones and vowels exhibit relatively stable energy distributions, enabling reliable separation based on temporal energy characteristics.

Quick start

  1. In Praat, select exactly one Sound object.
  2. Run script…multi_band_onset_detector.praat.
  3. Set Transient_threshold for detection sensitivity (-20 to -40 dB typical).
  4. Adjust Attack_window and Release_window for temporal shaping.
  5. Set frequency range appropriate for your audio.
  6. Choose Number_of_bands (3-6 recommended).
  7. For long files, set Working_sample_rate for faster processing.
  8. Enable Swap_outputs_for_speech for vocal/consonant separation.
  9. Choose which outputs to create and enable normalization.
  10. Click OK — processing completes with separated components.
Quick tip: Use Music mode (swap disabled) for percussive sounds, instruments, and general audio — this puts attacks in transients and sustained tones in sustain. Use Speech mode (swap enabled) for vocals and speech — this puts consonants in transients and vowels in sustain. Set threshold around -30 dB for balanced detection. Use 3-6 bands for most material — more bands for complex sounds, fewer for simpler material. Adjust attack window to capture the sharpness of onsets (10-30ms typical). Set release window to control how long transients last (30-100ms typical). For long files, use working sample rate of 4000-8000 Hz for much faster processing. Always listen to both outputs to verify separation quality.
Important: PERFORMANCE TRADEOFFS — higher number of bands and higher working sample rates provide better quality but slower processing. Very low thresholds may capture noise as false transients. Very short attack windows may miss gradual onsets. The method works best on sounds with clear attack-sustain characteristics — continuously evolving sounds may produce less distinct separation. Downsampling reduces high-frequency content in the detection process but full quality is restored in output. Always check that the separation makes perceptual sense for your audio material. The algorithm detects energy increases — sustained sounds with fluctuating amplitude may produce false detections. For complex mixes, results may vary depending on the density and overlapping of sound events.

Onset Detection Theory

Multi-Band Energy Analysis

Spectral-Temporal Processing

Band-splitting and envelope extraction:

Logarithmic band spacing: band_edge[i] = low_freq × (high_freq / low_freq)^(i / n_bands) For i = 0 to n_bands Creates perceptually-spaced frequency bands Per-band processing: FOR each band i: band_signal = BandpassFilter(original, band_edge[i-1], band_edge[i]) rectified = |band_signal| (absolute value) envelope = LowPassFilter(rectified, 50 Hz) (smoothing) Combined envelope: combined_env = Σ envelope[i] across all bands Represents total energy across frequency spectrum Onset function: onset[n] = max(0, combined_env[n] - combined_env[n-1]) Positive derivative = energy increase Zero or negative = stable or decreasing energy Temporal characteristics: Attacks create sharp peaks in onset function Sustained sounds produce near-zero onset values Noise produces low-level random fluctuations

Why Multi-Band Approach?

Advantages over broadband detection:

Onset Detection Mathematics

Energy-Based Detection

Computing the onset function:

Signal representation: x[n] = audio signal at sample n F_band[i] = bandpass filter for band i Band energy: band_energy[i][n] = |(x ∗ F_band[i])[n]| (rectified) Smoothed envelope: envelope[i][n] = (band_energy[i] ∗ F_lowpass)[n] Where F_lowpass = 50 Hz low-pass filter Combined energy: E_combined[n] = Σ envelope[i][n] Onset function: O[n] = max(0, E_combined[n] - E_combined[n-1]) Only positive differences (energy increases) Negative differences set to zero (energy decays) Thresholding: O_threshold[n] = 1 if O[n] > threshold, else 0 threshold = 10^(dB_threshold/20) × max(O[n]) Temporal shaping: Apply attack/release envelope to binary mask Creates smooth transitions between states

Temporal Mask Properties

Attack and release shaping:

Binary mask creation:
Initial mask: 1 where onset > threshold, 0 elsewhere
Creates abrupt transitions that sound artificial

Attack window (10-30ms typical):
Linear ramp from 0 to 1 over attack duration
Preserves sharpness of attack perception
Shorter = more precise timing, longer = smoother

Release window (30-100ms typical):
Exponential decay from 1 to 0 over release duration
Natural-sounding decay of transient energy
Shorter = tighter transients, longer = more sustain bleed

Convolution implementation:
Mask convolved with attack/release envelope
Efficient computation of shaped mask
Mathematically equivalent to sample-by-sample shaping

Perceptual benefits:
Smooth transitions prevent clicks and artifacts
Natural amplitude envelopes for separated components
Musical timing preservation

🎵 Perceptual Intuition

Transients (attacks):

Rapid energy increases across frequencies

Percussive hits, instrument attacks, consonants

Short duration, broadband energy

Sustain (resonance):

Stable or slowly changing energy

Instrument bodies, vowel sounds, reverberation

Long duration, tonal character

Detection principle:

Find moments when energy rapidly increases

Separate these from stable energy periods

Dual-Mode Operation

Music vs Speech Processing

Mode-dependent output assignment:

Music Mode (swap_outputs_for_speech = 0): transients = original × mask sustain = original × (1 - mask) Where mask = 1 during detected onsets Result: • Transients contain attacks, percussive elements • Sustain contains tonal bodies, resonances Speech Mode (swap_outputs_for_speech = 1): transients = original × (1 - mask) sustain = original × mask Inverse mask assignment Result: • Transients contain consonants, fricatives, bursts • Sustain contains vowels, voiced segments Rationale for swapping: Music: We want to separate attacks from sustained tones Speech: We want to separate consonants from vowels Same detection, different interpretation of results Mask properties: mask = shaped onset detection function ∈ [0,1] Smooth transitions prevent artifacts Temporal shaping preserves natural sound

Why Dual Modes Matter

Perceptual differences:

Complete Processing Pipeline

SETUP: Select Sound object Set detection parameters and mode Extract audio properties PREPROCESSING: Convert to mono if multichannel Optionally downsample for performance working_sound = Resample(original, working_sample_rate) MULTI-BAND ANALYSIS: Calculate logarithmic band edges FOR each frequency band i: filtered = BandPass(working_sound, band_edge[i-1], band_edge[i]) rectified = |filtered| (absolute value) envelope = LowPass(rectified, 50 Hz) (smoothing) combined_envelope += envelope (sum across bands) ONSET DETECTION: onset_function = diff(combined_envelope) (positive differences) threshold = 10^(dB_threshold/20) × max(onset_function) binary_mask = onset_function > threshold (1 where above threshold) TEMPORAL SHAPING: Create attack/release envelope shaped_mask = convolve(binary_mask, envelope) (smoothing) Clip shaped_mask to [0,1] range SEPARATION: IF music mode: transients = working_sound × shaped_mask sustain = working_sound × (1 - shaped_mask) ELSE speech mode: transients = working_sound × (1 - shaped_mask) sustain = working_sound × shaped_mask POST-PROCESSING: Resample outputs back to original sample rate Normalize peaks if requested Clean up temporary objects OUTPUT: Separated transient and sustain components Comprehensive processing summary

Processing Modes

Music Mode

🎵 Attack-Sustain Separation

Character: Normal operation for musical sounds

Output assignment: Transients = attacks, Sustain = resonances

Best for: Instruments, percussive sounds, general audio

Music mode applications:

Sound TypeTransients ContentSustain ContentTypical Use
Drums/PercussionAttack transients, stick hitsBody resonance, ringDrum replacement, transient shaping
Plucked StringsPick noise, string attackString vibration, body resonanceArticulation control, re-amping
Piano/KeysHammer noise, key attackString sustain, harmonic contentDynamic control, note editing
Brass/WoodwindsTonguing, air burstsInstrument body, tone sustainArticulation analysis, phrase shaping

Speech Mode

🗣️ Consonant-Vowel Separation

Character: Swapped outputs for speech analysis

Output assignment: Transients = consonants, Sustain = vowels

Best for: Voice, speech, vocal recordings

Speech mode applications:

Speech ElementTransients ContentSustain ContentTypical Use
Plosives (p,t,k,b,d,g)Burst release, aspirationVoicing (if present)Speech analysis, consonant enhancement
Fricatives (f,v,s,z,sh)Turbulent noiseVoicing (if present)De-essing, noise reduction
Affricates (ch,j)Stop + fricative portionsTransition regionsArticulation study
Vowels (a,e,i,o,u)Onset/offset transitionsVowel formants, voicingProsody analysis, vowel modification

Mode Selection Guide

🎯 Choosing the Right Mode

Music mode: When you want to separate attacks from sustained tones

Speech mode: When you want to separate consonants from vowels

Consider content: What perceptual separation makes sense for your audio?

Experiment: Try both modes and listen to which produces more useful results

Parameters

Detection Parameters

ParameterTypeDefaultDescription
Transient_threshold_(dB)real-30Sensitivity of onset detection
Attack_window_(ms)real20Duration of attack ramp in mask
Release_window_(ms)real50Duration of release decay in mask

Frequency Parameters

ParameterTypeDefaultDescription
Low_frequency_(Hz)real100Lowest frequency band edge
High_frequency_(Hz)real8000Highest frequency band edge
Number_of_bandsinteger4Number of frequency bands (3-6 recommended)

Performance Parameters

ParameterTypeDefaultDescription
Working_sample_rate_(Hz)real8000Processing sample rate for speed

Output Parameters

ParameterTypeDefaultDescription
Create_transient_soundboolean1 (on)Generate transient component output
Create_sustain_soundboolean1 (on)Generate sustain component output
Swap_outputs_for_speechboolean0 (off)Swap outputs for speech processing
Normalize_outputsboolean1 (on)Normalize output levels
Peak_amplitudereal0.99Target peak level for normalization

Applications

Sound Design and Music Production

Use case: Creative processing and effect generation

Technique: Process transients and sustain separately with different effects

Example: Add reverb only to sustain, compression only to transients

Audio Restoration and Enhancement

Use case: Targeted processing of specific sound components

Technique: Isolate problematic elements for selective treatment

Workflow:

Music Analysis and Education

Use case: Studying articulation and performance technique

Advantages:

Example: Analyze piano touch by examining transient-sustain relationship

Speech Processing and Analysis

Use case: Speech analysis and modification

Technique: Use speech mode for consonant-vowel separation

Application: Speech therapy, accent modification, voice transformation

Practical Workflow Examples

🎵 Drum Processing

Goal: Separate drum attacks from body resonance for individual processing

Settings:

  • Mode: Music (swap disabled)
  • Threshold: -25 dB (sensitive for sharp attacks)
  • Attack: 15 ms (fast capture)
  • Release: 40 ms (medium decay)
  • Bands: 5 (good frequency resolution)
  • Sample rate: 8000 Hz (balanced performance)

Result: Clean separation of drum hits from ring/resonance

🗣️ Speech De-essing

Goal: Reduce sibilance in vocal recordings

Settings:

  • Mode: Speech (swap enabled)
  • Threshold: -35 dB (sensitive for fricatives)
  • Attack: 10 ms (fast consonant capture)
  • Release: 30 ms (quick release)
  • Bands: 4 (adequate for speech)
  • Sample rate: 8000 Hz (speech bandwidth adequate)

Processing: Apply EQ/compression to transients (sibilance) only

🎻 Instrument Analysis

Goal: Study bowing/plucking technique in string instruments

Settings:

  • Mode: Music (swap disabled)
  • Threshold: -30 dB (balanced detection)
  • Attack: 20 ms (capture bow attack)
  • Release: 60 ms (capture initial decay)
  • Bands: 6 (detailed frequency analysis)
  • Sample rate: 16000 Hz (full quality for analysis)

Result: Clear view of articulation separate from tone sustain

Advanced Techniques

Creative processing strategies:
  • Layered effects: Apply different effects to transients vs sustain
  • Cross-synthesis: Use transients from one sound with sustain from another
  • Rhythmic manipulation: Time-stretch sustain while keeping transients tight
  • Spectral morphing: Process frequency content separately in each component
  • Dynamic mixing: Automate blend between processed components

The separation enables entirely new processing possibilities

Parameter optimization guide:
  • Sharp attacks: Lower threshold, shorter attack window
  • Gradual onsets: Higher threshold, longer attack window
  • Percussive material: More bands for frequency resolution
  • Tonal material: Fewer bands for smoother operation
  • Fast processing: Lower working sample rate, fewer bands
  • High quality: Higher working sample rate, more bands
  • Clean separation: Higher threshold, shorter release
  • Smooth transition: Lower threshold, longer release

Troubleshooting Common Issues

Problem: Too much content in transients
Cause: Threshold too low, capturing non-attack content
Solution: Increase threshold, check if speech mode should be enabled
Problem: Missed attacks or consonants
Cause: Threshold too high, attack window too short
Solution: Decrease threshold, increase attack window
Problem: Artifacts or clicks in output
Cause: Abrupt mask transitions, insufficient smoothing
Solution: Increase attack/release windows, ensure normalization
Problem: Poor separation quality
Cause: Audio not suitable for attack-sustain model
Solution: Try different mode, adjust parameters, consider alternative approaches

Technical Deep Dive

Algorithm Performance

Computational Complexity

Processing time analysis:

Time complexity: Let N = number of samples Let B = number of bands Band filtering: O(B × N) per filter operation Typically 3 filter operations per band: Bandpass → Rectification → Lowpass smoothing Total: O(3 × B × N) Downsampling effect: Original samples: N_original Working samples: N_work = N_original × (working_rate / original_rate) Processing time reduction: (working_rate / original_rate)² Example: 44100 → 8000 Hz: (8000/44100)² ≈ 0.033 = 3.3% time Memory requirements: Working sound: N_work samples Band signals: B × N_work samples Temporary objects: ~3 × B × N_work samples peak Practical performance: 1-minute audio at 44100 Hz: N = 2,646,000 samples With B=4 bands, working_rate=8000 Hz: N_work = 480,000 samples (18% of original) Processing time: seconds to minutes depending on computer

Detection Accuracy Metrics

Evaluation criteria:

Temporal precision:
Ability to locate onset times accurately
Measured in milliseconds deviation from actual onset
This implementation: Typically 5-20 ms precision

Detection rate:
Percentage of actual onsets correctly detected
Depends on threshold setting and audio content
Typical: 80-95% with optimized parameters

False positive rate:
Percentage of detected onsets that are not actual onsets
Controlled by threshold setting
Lower threshold → higher detection but more false positives

Separation quality:
How cleanly transients are separated from sustain
Subjective but can be measured via spectral analysis
This method: Good for percussive sounds, fair for complex mixes

Comparative performance:
Multi-band vs single-band: Better for complex sounds
Energy-based vs spectral flux: More robust to timbre changes
This implementation: Balanced approach for general use