Dynamic Distortion — User Guide

Envelope‑following distortion: drive amount changes with signal amplitude for expressive, touch‑responsive saturation effects.

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 dynamic distortion — a responsive saturation effect where the amount of distortion (drive) varies with the input signal's amplitude. An envelope follower tracks the audio level, and this envelope controls the distortion intensity. Key features: (1) Envelope‑following drive: Drive = Base_Drive + (Envelope × Sensitivity). (2) Adjustable response: Control envelope follower speed (Response_Speed_Hz). (3) 4 Built‑in Presets: Touch‑sensitive, Drum pumping, Gated crunch, Expressive lead. (4) Comprehensive visualization: Shows original, distorted, envelope, computed drive, and transfer functions. (5) Stereo‑container processing: Efficient single‑pass algorithm using multichannel trickery.

Key Features:

What is dynamic distortion? Traditional distortion applies constant saturation regardless of input level. Dynamic distortion (sometimes called "touch‑sensitive" or "envelope‑controlled" distortion) varies the saturation amount based on how loud the input is. This creates more expressive, natural‑sounding effects: quiet passages remain clean or lightly saturated, while loud passages get heavily distorted. The envelope follower extracts amplitude information, which then modulates the distortion drive parameter. This mimics how tube amplifiers naturally compress and saturate more at higher volumes. Use cases: Expressive guitar/bass playing, vocal saturation, drum processing, dynamic sound design, and any application where you want distortion that "breathes" with the music.

Technical Implementation: (1) Envelope extraction: Convert to mono → absolute value → low‑pass filter (Response_Speed_Hz) → smoothed envelope. (2) Stereo container creation: Combine original audio (channel 1) and envelope (channel 2) into single stereo object. (3) Dynamic distortion formula: For each sample: Drive = Base_Drive + (envelope_sample × Sensitivity), Output = tanh(audio_sample × Drive) × Output_Gain. (4) Efficient processing: Uses Praat's Formula with row/col indexing to process both channels simultaneously. (5) Visualization: Five‑panel display showing: original waveform, distorted result, envelope signal, computed drive over time, and transfer function comparison (low vs high drive).

Quick start

  1. In Praat, select exactly one Sound object.
  2. Run script…apply_dynamic_distortion.praat.
  3. Choose a Preset (overrides sliders) or "Manual" to use sliders.
  4. Adjust Base_Drive (minimum distortion when quiet).
  5. Set Sensitivity (how much envelope adds to drive).
  6. Choose Response_Speed_Hz (envelope follower speed).
  7. Set Output_Gain for volume compensation.
  8. Enable Draw_visualization to see all analysis panels.
  9. Click OK — effect applied, result named "originalname_DynDist_presetname".
Quick tip: Start with Touch Sensitive Drive preset for expressive guitar/vocal effects. Use Drum Pumper for aggressive drum bus compression/distortion. Gated Crunch creates silence between hits (negative Base_Drive). Expressive Lead has slow envelope for legato phrases. Enable visualization to understand the envelope→drive relationship. Higher Sensitivity makes distortion more responsive to level changes. Lower Response_Speed_Hz (5‑20 Hz) creates smooth, musical modulation; higher (50‑100 Hz) creates aggressive, percussive response. Negative Base_Drive (< 0) creates gating: signal must reach threshold before distortion engages.
Important: DYNAMIC PROCESSING — distortion amount changes over time based on input amplitude. This can create unexpected results if envelope follower mis‑tracks (e.g., on very transient‑rich material). Very high Sensitivity can cause extreme distortion jumps. Negative Base_Drive can create silence/gating effects. Response_Speed_Hz too low may cause distortion to "lag" behind transients. Response_Speed_Hz too high may cause distortion to "pump" with waveform cycles. Visualization shows envelope (green) and computed drive (brown) — verify they track as expected. Output may be quieter due to tanh saturation — adjust Output_Gain (0.8‑1.2 typical).

Dynamic Distortion Theory

Core Algorithm

📈 Envelope‑Following Distortion Pipeline

STEP 1: Extract envelope env(t) = LPFilter( |audio(t)| , Response_Speed_Hz ) Where: |·| = absolute value (rectification) LPFilter = low‑pass filter (Hann band, 0 to Response_Speed_Hz) Response_Speed_Hz = cutoff frequency (controls envelope speed) STEP 2: Compute dynamic drive drive(t) = Base_Drive + Sensitivity × env(t) Where: Base_Drive = minimum drive (when env(t) = 0) Sensitivity = scaling factor (how much envelope increases drive) STEP 3: Apply distortion output(t) = Output_Gain × tanh( audio(t) × drive(t) ) Where: tanh() = hyperbolic tangent (soft clipping function) Output_Gain = overall volume scaling

Key insight: The envelope env(t) tracks the audio's amplitude. This envelope then modulates the distortion amount in real time. When audio is loud (env(t) large), drive(t) increases → more distortion. When audio is quiet (env(t) small), drive(t) approaches Base_Drive → less distortion.

Envelope Follower Design

Rectification + Low‑Pass Filter

Classic envelope follower: 1. Full‑wave rectification: |x(t)| 2. Low‑pass filtering: y(t) = ∫ |x(τ)| h(t-τ) dτ Implementation in Praat: selectObject: sound Convert to mono Formula: ~ abs(self) # Rectification Filter (pass Hann band): 0, fc, 20 # Low‑pass at fc Hz Where fc = Response_Speed_Hz controls: • Attack/release characteristics • Smoothness vs. responsiveness • Ability to track transients

Response Speed Interpretation

Response_Speed_Hz effects:

1‑5 Hz: Very slow, "laggy" envelope • Good for: Slow volume swells, ambient textures • Sounds like: Compression with slow attack/release

10‑30 Hz: Musical, natural tracking • Good for: Most instruments, vocals, guitar • Sounds like: Tube‑amp‑like responsiveness

40‑80 Hz: Fast, aggressive tracking • Good for: Drums, percussion, transient‑rich material • Sounds like: Aggressive pumping, "breathing" effects

100+ Hz: Very fast, may track individual cycles • Good for: Extreme effects, ring‑mod‑like sounds • Sounds like: Waveform‑cycle distortion modulation

Drive Computation

Base_Drive (Minimum Distortion)

Effect: Drive value when envelope = 0 (silent portions).

Typical range: 0.5‑2.0 for normal use; negative values for gating.

Behavior: • Base_Drive > 0: Always some distortion, even during silence • Base_Drive = 0: No distortion when silent • Base_Drive < 0: Negative drive until envelope overcomes it → gating effect

Sensitivity (Envelope→Drive Scaling)

Effect: How much the envelope increases distortion.

Typical range: 2‑10 (higher = more responsive).

Mathematical: ΔDrive = Sensitivity × Envelope. If envelope ranges 0‑0.5 and Sensitivity=6, drive increases by 0‑3.0.

Total Drive Range

Formula: Drive_min = Base_Drive (when envelope=0)

Formula: Drive_max = Base_Drive + Sensitivity × Envelope_max

Example: Base_Drive=1.0, Sensitivity=5, Envelope_max=0.4 → Drive ranges 1.0‑3.0

Audible effect: Wide range = dramatic distortion changes; narrow range = subtle modulation.

Stereo‑Container Processing Trick

Efficient Implementation: Instead of processing audio and envelope separately (requiring sample‑by‑sample loops), this script uses Praat's multichannel capabilities: (1) Create stereo object where channel 1 = audio, channel 2 = envelope. (2) Use Formula command with row/col indexing to access both channels simultaneously. (3) Apply distortion formula that reads envelope from channel 2, processes audio in channel 1. This is computationally efficient and allows visualization of intermediate signals.
Praat Formula for stereo container: if row = 1 then tanh(self * (Base_Drive + (object[containerID, 2, col] * Sensitivity))) * Output_Gain else self # Keep envelope unchanged in channel 2 fi Where: row = 1 (audio channel), row = 2 (envelope channel) object[containerID, 2, col] = envelope sample at current column (time) self = audio sample (when row=1)

Visualization System

Five‑panel display:

Panel 1 (Original): Gray waveform — input signal
Panel 2 (Result): Red waveform — distorted output
Panel 3 (Envelope): Green curve — extracted amplitude envelope
Panel 4 (Drive): Brown curve — computed drive over time (Base_Drive + Sensitivity×Envelope)
Panel 5 (Transfer): Gray/red curves — tanh transfer functions for low/high drive

Interpretation: Watch how envelope (Panel 3) tracks audio peaks. See how drive (Panel 4) follows envelope. Note transfer function changes in Panel 5 — gray curve = low drive (quiet), red curve = high drive (loud).

Parameters & Presets

Common Parameters

ParameterTypeDefaultDescription
PresetoptionmenuManual4 built‑in presets or manual control
Base_Drivereal1.0Minimum drive when quiet
Sensitivityreal5.0How much envelope adds to drive
Response_Speed_Hzreal20.0Envelope follower speed (Hz)
Output_Gainreal0.9Post‑distortion volume
Draw_visualizationboolean1 (yes)Show 5‑panel analysis display
Play_resultboolean1 (yes)Auto‑play after processing

Built‑in Presets

PresetBase_DriveSensitivityResponse_SpeedOutput_GainCharacter
Touch Sensitive Drive0.83.015 Hz0.9Expressive, guitar‑amp‑like responsiveness
Drum Pumper1.08.050 Hz0.8Aggressive, transient‑heavy drum compression
Gated Crunch-0.510.080 Hz1.0Silence between hits, explosive on transients
Expressive Lead1.24.010 Hz0.9Smooth, legato‑friendly envelope tracking

Parameter Interaction Guide

Base_Drive + Sensitivity balance: For natural‑sounding dynamic range, set Base_Drive for desired "always‑on" saturation, then adjust Sensitivity so drive_max = Base_Drive + (Sensitivity × env_max) gives desired maximum distortion.
Response_Speed_Hz matching: Match envelope speed to material: Slow (10‑20 Hz) for vocals/guitar, Medium (30‑50 Hz) for rhythmic material, Fast (60‑100 Hz) for drum transients.
Negative Base_Drive gating: When Base_Drive < 0, signal must reach threshold = |Base_Drive|/Sensitivity before distortion engages. Example: Base_Drive=-0.5, Sensitivity=10 → threshold = 0.05 envelope.

Preset Design Philosophy

🎸 Preset Characteristics Explained

Touch Sensitive Drive: • Moderate Base_Drive (0.8) = light always‑on saturation • Low Sensitivity (3.0) = subtle dynamic response • Medium Response (15 Hz) = natural envelope tracking • Ideal for: Guitar solos, expressive vocals

Drum Pumper: • Higher Base_Drive (1.0) = noticeable saturation • High Sensitivity (8.0) = dramatic dynamic changes • Fast Response (50 Hz) = tracks drum transients • Lower Output_Gain (0.8) = compensates for peak saturation

Gated Crunch: • Negative Base_Drive (-0.5) = gating effect • Very High Sensitivity (10.0) = explosive when threshold crossed • Very Fast Response (80 Hz) = instant on transients • Output_Gain=1.0 = preserve dynamics

Expressive Lead: • Higher Base_Drive (1.2) = rich saturation • Moderate Sensitivity (4.0) = controlled dynamics • Slow Response (10 Hz) = smooth envelope, ignores fast variations • Ideal for: Legato synth leads, sustained instruments

Applications

Expressive Guitar/Bass Processing

Use case: Touch‑responsive amp simulation

Technique: Use Touch Sensitive Drive preset

Tip: Adjust Sensitivity to match playing dynamics; lower for subtle, higher for dramatic

Advanced: Chain with static distortion before dynamic stage for complex saturation

Drum Bus Compression‑Distortion

Use case: Aggressive drum bus processing

Technique: Use Drum Pumper preset

Tip: Fast Response_Speed_Hz (40‑60 Hz) tracks transients; high Sensitivity (6‑10) creates pumping

Advanced: Blend dry signal with processed for parallel compression effect

Vocal Saturation with Dynamics

Use case: Natural‑sounding vocal warmth

Technique: Use Expressive Lead preset with slower Response_Speed_Hz (10‑15)

Tip: Low Base_Drive (0.5‑0.8) for subtle saturation; moderate Sensitivity (3‑5) for phrase‑based dynamics

Advanced: Apply to vocal bus rather than individual tracks for cohesion

Gated/Noise‑Gate Distortion Effects

Use case: "Dying battery" or noise‑gate‑into‑distortion effects

Technique: Use Gated Crunch preset or set Base_Drive negative

Tip: Negative Base_Drive = -0.3 to -1.0; high Sensitivity = 8‑12 for explosive bursts

Advanced: Combine with tremolo or autopan for rhythmic gating effects

Synth & Sound Design

Use case: Dynamic textures for electronic music

Technique: Experiment with extreme Response_Speed_Hz (1‑100 Hz)

Tip: Very slow Response (1‑5 Hz) creates evolving saturation over seconds

Advanced: Automate Sensitivity parameter over time for evolving dynamic response

Practical Workflow Examples

🎸 Live Guitar Tone

Goal: Dynamic amp‑like distortion that cleans up with volume knob

Settings:

  • Preset: Touch Sensitive Drive (modified)
  • Base_Drive: 0.6 (clean headroom)
  • Sensitivity: 4.0 (responsive to picking)
  • Response_Speed_Hz: 20 Hz (natural tracking)
  • Output_Gain: 1.0

Result: Light crunch at normal playing, heavy distortion when digging in

🥁 Drum Room Ambience

Goal: Distort only drum room/ambience, not close mics

Settings:

  • Preset: Drum Pumper
  • Base_Drive: 0.3 (subtle on quiet ambience)
  • Sensitivity: 12.0 (explosive on drum hits)
  • Response_Speed_Hz: 60 Hz (fast transient tracking)
  • Output_Gain: 0.7 (reduce level)

Result: Room mics "bloom" with saturation on each hit, clean between

🔊 Glitch/Gated Textures

Goal: Broken, intermittent distortion for glitch effects

Settings:

  • Preset: Gated Crunch (modified)
  • Base_Drive: -0.8 (strong gating)
  • Sensitivity: 15.0 (extremely responsive)
  • Response_Speed_Hz: 100 Hz (instant response)
  • Output_Gain: 1.2 (boost bursts)

Result: Silence punctuated by explosive distortion bursts

Advanced Techniques

Envelope Shaping before Distortion: Process the envelope signal before using it to modulate drive. Options: (1) Apply compression to envelope for more consistent drive. (2) Apply expansion to exaggerate dynamics. (3) Apply low‑pass filtering (slower than Response_Speed_Hz) for ultra‑smooth modulation. (4) Apply high‑pass filtering to ignore low‑frequency envelope components.
Multi‑band Dynamic Distortion: Split signal into bands, apply dynamic distortion to each band with different parameters. Example: Low band = slow response, high Sensitivity; high band = fast response, low Sensitivity. Recombine for complex spectral dynamics.
Sidechain Modulation: Use a different audio source to generate the envelope. Example: Use kick drum to modulate distortion on bass guitar (classic sidechain compression but with distortion instead of volume).
Parameter Automation: Animate Sensitivity or Response_Speed_Hz over time for evolving dynamic characteristics. Use Praat scripting to create parameter curves that follow musical structure.

Troubleshooting Common Issues

Problem: Distortion "pumps" or "breaths" unnaturally
Cause: Response_Speed_Hz too fast, tracking waveform cycles instead of amplitude envelope
Solution: Lower Response_Speed_Hz (10‑30 Hz for most material)
Problem: Distortion changes too slowly, misses transients
Cause: Response_Speed_Hz too slow, envelope lags behind audio
Solution: Increase Response_Speed_Hz (40‑80 Hz for percussive material)
Problem: Too much/too little dynamic range in distortion
Cause: Sensitivity too high/low relative to envelope range
Solution: Adjust Sensitivity while watching envelope display (Panel 3). Aim for drive range that sounds musical.
Problem: Gating effect too strong/weak
Cause: Base_Drive negative value inappropriate for signal level
Solution:
Problem: Output too quiet/loud
Cause: Output_Gain inappropriate for amount of saturation
Solution: Adjust Output_Gain (0.7‑1.3 typical). Heavy saturation reduces peaks → may need gain > 1.0.

Mathematical Deep Dive

Envelope Follower Analysis

Full‑wave rectification + 1‑pole low‑pass filter: Rectification: r(t) = |x(t)| Low‑pass filter (differential equation): τ dy/dt + y = r(t) Where τ = time constant = 1/(2πfc), fc = Response_Speed_Hz Discrete‑time implementation (approximation): y[n] = α r[n] + (1-α) y[n-1] Where α = 1 - exp(-2πfc/fs), fs = sampling rate This creates exponential attack/release: • Attack time: ≈ 2.2τ = 0.35/fc seconds • Release time: ≈ 2.2τ = 0.35/fc seconds Example: fc = 20 Hz → attack/release ≈ 17.5 ms fc = 5 Hz → attack/release ≈ 70 ms

Dynamic Distortion Harmonic Analysis

For sinusoid with time‑varying drive:

Input: x(t) = A sin(ωt) Drive: d(t) = d₀ + d₁ e(t) where e(t) = envelope of x(t) Output: y(t) = tanh(A sin(ωt) × d(t)) For slowly varying e(t) (compared to ω), approximate as: y(t) ≈ tanh(A d(t) sin(ωt)) Expand tanh as power series: tanh(z) ≈ z - z³/3 + 2z⁵/15 - ... So: y(t) ≈ A d(t) sin(ωt) - [A d(t)]³ sin³(ωt)/3 + ... Using sin³θ = (3 sinθ - sin3θ)/4: y(t) ≈ A d(t) sin(ωt) - [A d(t)]³ (3 sin(ωt) - sin(3ωt))/12 + ... Thus harmonics amplitude depends on d(t), which itself depends on envelope e(t). Key insight: Harmonic content varies with amplitude → richer distortion on loud parts.

Negative Base_Drive Gating Analysis

When Base_Drive < 0: d(t) = B + S e(t), where B < 0, S > 0 Distortion occurs when d(t) > 0: B + S e(t) > 0 e(t) > -B/S Threshold amplitude: e_threshold = -B/S Interpretation: • When envelope e(t) < e_threshold: d(t) < 0 → tanh(negative×input) = negative×tanh(positive) = phase inversion • When envelope e(t) > e_threshold: d(t) > 0 → normal distortion • The phase inversion for quiet signals often perceived as gating/volume reduction For B = -0.5, S = 10: e_threshold = 0.05 Signal must exceed 5% of maximum to engage distortion