Asymmetric Soft Clipping — User Guide

Tube-style asymmetric distortion using hyperbolic tangent (tanh) with independent positive/negative shaping, bias control, and visual transfer function display.

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 asymmetric soft clipping — a tube/tape-style distortion effect using a hyperbolic tangent (tanh) transfer function with independent shaping for positive and negative halves of the waveform. Key features: (1) Drive: Pre‑gain before clipping. (2) Bias: DC offset pushing signal into different regions of the tanh curve. (3) Positive/Negative Shape: Separate coefficients for upper/lower halves, creating asymmetric distortion. (4) Output Gain: Post‑clipping volume adjustment. (5) 5 Built‑in Presets: From subtle warmth to hard fuzz. (6) Visualization: Displays original vs. distorted waveform and the transfer function (input‑output curve).

Key Features:

What is asymmetric soft clipping? Traditional symmetric clipping (e.g., diode clippers) applies the same nonlinearity to both positive and negative halves. Asymmetric clipping uses different curves for each half, mimicking vacuum‑tube or tape‑saturation behavior where positive and negative saturation differ. The hyperbolic tangent (tanh) is a smooth saturating function that avoids harsh aliasing. By adding a bias (DC offset) and independent shape coefficients, complex, musically‑rich distortion textures can be created. Use cases: Guitar/bass overdrive, vocal warmth, synth saturation, lo‑fi effects, creative sound design.

Technical Implementation: (1) Signal path: Input × Drive + Bias → conditional shape selection (positive vs. negative) → tanh(…) × Output Gain. (2) Formula generation: The script constructs a string formula dynamically: tanh((self*drive + bias) * ((in>=0)*pos_Shape + (in<0)*neg_Shape)) * output_Gain. (3) Visualization: Three‑panel display: original waveform, distorted waveform, and transfer function (input‑output mapping from −1.5 to +1.5). (4) Processing: Applied sample‑by‑sample via Praat’s Formula command. (5) Presets: Override manual sliders with curated settings for common distortion characters.

Quick start

  1. In Praat, select exactly one Sound object.
  2. Run script…apply_asymmetric_clipping.praat.
  3. Choose a Preset (overrides sliders) or "Manual" to use sliders.
  4. Adjust Drive (pre‑gain), Bias (DC offset), Pos_Shape/Neg_Shape (asymmetry), Output_Gain (volume).
  5. Enable Draw_visualization to see waveforms and transfer curve.
  6. Enable Play_result to audition after processing.
  7. Click OK — effect applied, result named "originalname_Tube_presetname".
Quick tip: Start with Warm Tube Saturation preset for subtle harmonic enhancement. Use Asymmetric Fuzz for aggressive, splattery distortion. Broken/Gated Bias silences quiet passages (good for glitch effects). Enable Draw_visualization to understand how parameters affect the transfer curve. Higher Drive pushes more signal into saturation. Bias shifts the operating point on the tanh curve. Pos_Shape & Neg_Shape control asymmetry—different values create even‑order harmonics. Output_Gain compensates for level loss after clipping.
Important: NONLINEAR DISTORTION — introduces harmonics and alters waveform permanently. High Drive values can cause extreme saturation and loss of dynamic range. Bias > 0 pushes signal into flat region of tanh, potentially silencing quiet passages. Asymmetric shaping (Pos_Shape ≠ Neg_Shape) creates even‑order harmonics (musical, "warm"). Symmetric shaping (Pos_Shape = Neg_Shape) creates odd‑order harmonics (harsh, "metallic"). Output may be quieter due to clipping—use Output_Gain to compensate. Visualization shows transfer function from −1.5 to +1.5; real audio may exceed this range.

Distortion Theory

Hyperbolic Tangent (tanh) as Soft Clipper

Mathematical Form

Basic symmetric tanh clipping: y = tanh(x) Properties: • Smooth S‑shape (C‑infinity) • Limits: tanh(x) → ±1 as x → ±∞ • Linear near zero: tanh(x) ≈ x for |x| ≪ 1 • Monotonic, continuous derivative Asymmetric extension: y = tanh(x * shape) where shape = pos_Shape if x ≥ 0, else neg_Shape Full signal chain: x_in = input sample x_scaled = x_in * drive + bias shape = (x_scaled ≥ 0) ? pos_Shape : neg_Shape y = tanh(x_scaled * shape) * output_Gain

Why tanh?

Advantages over hard clipping or polynomials:

Parameter Roles

Drive (Pre‑Gain)

Effect: Multiplies input before clipping. Higher Drive pushes more signal into nonlinear region.

Range: 1.0 (no gain) to 10+ (heavy saturation).

Audible result: Increases distortion intensity, adds harmonics, reduces dynamic range.

Bias (DC Offset)

Effect: Adds constant offset, shifting operating point on tanh curve.

Range: −1.0 to +1.0 (typical). Positive bias pushes signal toward positive saturation.

Audible result: Can create gating/starved‑tube effects; changes symmetry of distortion.

Pos_Shape / Neg_Shape (Asymmetry)

Effect: Different coefficients for positive/negative halves.

Range: 0.1 (gentle curve) to 5.0 (hard clipping).

Audible result: Pos_Shape > Neg_Shape: positive peaks clip more → even‑order harmonics ("warm"). Equal values: symmetric odd‑order harmonics ("metallic").

Output_Gain (Volume Compensation)

Effect: Multiplies after clipping to adjust overall level.

Range: 0.0 to 2.0 (typical).

Audible result: Restores loudness lost to clipping; can be used for boost/cut.

Transfer Function Visualization

Understanding the graph:

Axes: X = input amplitude (−1.5 to +1.5), Y = output amplitude
Diagonal gray line: Linear transfer (no distortion, y = x)
Colored curve: Actual input‑output mapping
Shape interpretation:
• Steep slope near zero = high gain
• Flat regions = saturation (clipping)
• Asymmetry around zero = different positive/negative behavior
• Bias shifts curve left/right
• Drive stretches input horizontally

Harmonic Generation

How distortion creates harmonics:

Sine wave input: x(t) = A sin(ωt) After asymmetric tanh: y(t) = tanh(drive * x(t) + bias * shape) Fourier series of y(t) contains: • Fundamental (ω) • Even harmonics (2ω, 4ω, …) — from asymmetry • Odd harmonics (3ω, 5ω, …) — from symmetry More drive → more harmonics More asymmetry (pos_Shape ≠ neg_Shape) → stronger even harmonics Bias changes harmonic balance

Preset Designs

🎸 Preset Characteristics

Warm Tube Saturation: Low drive, small bias, slight asymmetry → gentle even harmonics, "analog warmth."

Hard Overdrive: High drive, no bias, symmetric shaping → aggressive odd harmonics, "amp‑like crunch."

Asymmetric Fuzz: Medium drive, positive bias, strong asymmetry → splattery, gated fuzz with rich even harmonics.

Broken/Gated Bias: High bias pushes quiet signals into flat region → silence below threshold, "dying battery" effect.

Subtle Warmer: Minimal drive, tiny bias, near‑linear → just a hint of saturation, "mastering‑style enhancement."

Parameters & Presets

Common Parameters

ParameterTypeDefaultDescription
PresetoptionmenuManual5 built‑in presets or manual control
Drivereal2.0Pre‑clipping gain (1.0 = no gain)
Biasreal0.1DC offset (−1.0 to +1.0)
Pos_Shapereal1.0Positive‑half shaping coefficient
Neg_Shapereal3.0Negative‑half shaping coefficient
Output_Gainreal0.8Post‑clipping volume (0.0‑2.0)
Draw_visualizationboolean1 (yes)Show waveforms & transfer curve
Play_resultboolean1 (yes)Auto‑play after processing

Built‑in Presets

PresetDriveBiasPos_ShapeNeg_ShapeOutput_GainCharacter
Warm Tube Saturation1.50.050.81.20.9Gentle even harmonics, analog warmth
Hard Overdrive5.00.02.02.00.5Aggressive symmetric crunch
Asymmetric Fuzz3.50.35.00.50.6Splattery, gated, rich even harmonics
Broken/Gated Bias4.00.84.00.50.6Quiet passages silent, "dying battery"
Subtle Warmer1.10.020.50.60.95Just‑noticeable saturation, mastering‑style

Parameter Interaction Tips

Drive + Bias: High Drive with positive Bias pushes signal into positive saturation, creating asymmetric clipping even if Pos_Shape = Neg_Shape.
Pos_Shape vs. Neg_Shape: Larger difference → stronger even‑order harmonics (warmth). Equal values → odd‑order harmonics (harshness).
Output_Gain compensation: After heavy clipping, peak amplitude is ~1.0. Use Output_Gain ≈ 1.0 / max(abs(tanh(…))) to normalize, or lower for headroom.

Applications

Guitar/Bass Overdrive

Use case: Amp‑like distortion for electric instruments

Technique: Use Warm Tube Saturation or Hard Overdrive presets

Tip: Adjust Drive to match playing dynamics; add Bias for "starved‑tube" character

Vocal Warmth/Saturation

Use case: Adding harmonic richness to vocals

Technique: Subtle Warmer preset, very low Drive (1.1‑1.3), slight asymmetry

Tip: Use high‑pass filter before clipping to avoid low‑end mud

Synth & Drum Processing

Use case: Aggressive sound design for electronic music

Technique: Asymmetric Fuzz or Broken Bias presets

Tip: Process drum buses for "crunchy" texture; use Bias to gate quieter hits

Lo‑Fi & Degradation Effects

Use case: Emulating tape saturation, cassette wow‑and‑flutter

Technique: Moderate Drive (2‑3), positive Bias (0.1‑0.3), asymmetric shaping

Tip: Add slight noise after clipping for authentic lo‑fi character

Creative Sound Design

Use case: Extreme distortion for experimental textures

Technique: High Drive (>5), extreme asymmetry (e.g., Pos_Shape=10, Neg_Shape=0.2)

Tip: Visualize transfer curve to understand shaping

Practical Workflow Examples

🎸 Guitar Rhythm Track

Goal: Classic rock overdrive

Settings:

  • Preset: Warm Tube Saturation
  • Drive: 1.8 (adjust to playing)
  • Bias: 0.1
  • Pos_Shape: 1.0, Neg_Shape: 1.5
  • Output_Gain: 0.9

Result: Warm, dynamic overdrive with singing sustain

🎙️ Vocal Thickening

Goal: Subtle harmonic enhancement

Settings:

  • Preset: Subtle Warmer
  • Drive: 1.2
  • Bias: 0.0
  • Pos_Shape: 0.7, Neg_Shape: 0.9
  • Output_Gain: 0.95

Result: Vocal sounds "larger" without obvious distortion

⚡ Glitch/Noise Effects

Goal: Broken, gated distortion

Settings:

  • Preset: Broken/Gated Bias
  • Drive: 4.5
  • Bias: 0.7
  • Pos_Shape: 3.0, Neg_Shape: 0.3
  • Output_Gain: 0.7

Result: Quiet passages disappear, loud parts explode with splattery distortion

Troubleshooting Common Issues

Problem: Too quiet after processing
Cause: Clipping reduces peak amplitude; Output_Gain too low
Solution: Increase Output_Gain (0.8‑1.2 typical), or normalize after processing
Problem: Harsh, metallic sound
Cause: Symmetric shaping (Pos_Shape ≈ Neg_Shape) producing odd harmonics
Solution: Increase asymmetry (e.g., Pos_Shape=1.0, Neg_Shape=2.0)
Problem: Quiet passages disappear
Cause: High Bias pushes signal into flat region of tanh
Solution: Reduce Bias to 0.0‑0.2, or increase Drive
Problem: Distortion too extreme/uncontrollable
Cause: Drive too high, or shaping coefficients extreme
Solution: Reduce Drive (1.5‑3.0 for moderate), keep Pos_Shape/Neg_Shape between 0.5‑3.0

Processing Pipeline

🔄 Asymmetric Soft Clipping Processing Flow

START: User Selects Sound
  │
  ▼
INPUT VALIDATION
  │  • Check exactly one Sound selected
  │  • Exit with error if not
  │
  ▼
FORM PROCESSING
  │  • Load user parameters from form
  │  • Apply preset overrides if selected
  │  • Convert preset names (spaces removed)
  │
  ▼
PRESET HANDLING
  │
  ├── Manual ────────────┐
  │   • Use form values  │
  │                      │
  ├── Warm Tube ────────┤
  │   • Drive = 1.5     │
  │   • Bias = 0.05     │
  │   • Pos = 0.8       │
  │   • Neg = 1.2       │
  │   • Gain = 0.9      │
  │                      │
  ├── Hard Overdrive ───┤
  │   • Drive = 5.0     │
  │   • Bias = 0.0      │
  │   • Pos = 2.0       │
  │   • Neg = 2.0       │
  │   • Gain = 0.5      │
  │                      │
  ├── Asymmetric Fuzz ──┤
  │   • Drive = 3.5     │
  │   • Bias = 0.3      │
  │   • Pos = 5.0       │
  │   • Neg = 0.5       │
  │   • Gain = 0.6      │
  │                      │
  ├── Broken Bias ──────┤
  │   • Drive = 4.0     │
  │   • Bias = 0.8      │
  │   • Pos = 4.0       │
  │   • Neg = 0.5       │
  │   • Gain = 0.6      │
  │                      │
  └── Subtle Warmer ────┘
      • Drive = 1.1
      • Bias = 0.02
      • Pos = 0.5
      • Neg = 0.6
      • Gain = 0.95
  │
  ▼
SOUND PREPARATION
  │  • Get original sound properties
  │  • Create copy: originalname_Tube_presetname
  │  • Select copy for processing
  │
  ▼
FORMULA GENERATION ENGINE
  │  • Convert parameters to strings
  │  • Build input expression: (self * drive + bias)
  │  • Build shape logic: ((in>=0)*pos + (in<0)*neg)
  │  • Combine: tanh(input * shape) * output_gain
  │  • Construct final formula string
  │
  ▼
CORE PROCESSING
  │  • Apply formula via Praat's Formula command
  │  • Sample-by-sample processing:
  │     1. Scale by Drive, add Bias
  │     2. Select shape based on sign
  │     3. Apply tanh nonlinearity
  │     4. Scale by Output_Gain
  │
  ▼
VISUALIZATION PIPELINE
  │
  ├── TITLE PANEL
  │   • Display effect name and source
  │
  ├── ORIGINAL WAVEFORM
  │   • Gray curve
  │   • Time axis 0‑duration
  │
  ├── DISTORTED WAVEFORM
  │   • Red curve (0.8, 0.4, 0.4)
  │   • Time axis with labels
  │
  ├── TRANSFER FUNCTION
  │   • Input range: -1.5 to 1.5
  │   • Calculate curve points
  │   • Draw colored transfer curve
  │   • Add threshold/grid lines
  │
  └── PARAMETER DISPLAY
      • Preset name
      • Parameter values
      • Drive, Bias, Shape, Gain
  │
  ▼
TRANSFER FUNCTION CALCULATION
  │  • For 100 points from -1.5 to 1.5:
  │     1. val_in = x * drive + bias
  │     2. shape = pos if val_in>=0 else neg
  │     3. y = tanh(val_in * shape) * output_gain
  │     4. Draw line segments
  │
  ▼
OUTPUT FINALIZATION
  │  • Play result if enabled
  │  • Write InfoLine summary
  │  • Keep processed sound selected
  │
  ▼
CLEANUP
  │  • (No temporary objects to clean)
  │  • Return to Praat Objects window
  │
END: Processed sound ready for use

Formula Generation Details

Dynamic String Construction: 1. Parameter Conversion: drive_str$ = string$(drive) bias_str$ = string$(bias) pos_str$ = string$(pos_Shape) neg_str$ = string$(neg_Shape) gain_str$ = string$(output_Gain) 2. Input Expression: in$ = "(self * " + drive_str$ + " + " + bias_str$ + ")" 3. Shape Logic: shape_logic$ = "((" + in$ + " >= 0) * " + pos_str$ + " + (" + in$ + " < 0) * " + neg_str$ + ")" 4. Final Formula: formula$ = "tanh(" + in$ + " * " + shape_logic$ + ") * " + gain_str$ 5. Application: Formula: formula$

Visualization Architecture

📊 Multi‑Panel Display System

Viewport Management: • Panel 1: 0,8 × 0.1,0.5 → Title • Panel 2: 0,8 × 0.6,1.6 → Original waveform • Panel 3: 0,8 × 1.7,2.7 → Distorted waveform • Panel 4: 0,8 × 2.9,5.0 → Transfer function • Panel 5: 0,8 × 5.1,5.5 → Parameter display

Color Scheme: • Original: Gray {0.6, 0.6, 0.6} • Distorted: Red {0.8, 0.4, 0.4} • Transfer: Green {0.2, 0.5, 0.2} • Grid: Light gray {0.8, 0.8, 0.8} • Text: Black

Curve Plotting: • 100‑point resolution • Line width: 2.5 for transfer function • Previous/current point connection • Anti‑aliased drawing

Performance Characteristics

Computational Complexity: O(n) where n = number of samples. Each sample requires: one multiplication, one addition, one comparison, one tanh(), and one multiplication.
Memory Usage: Creates one copy of the original sound. No additional large buffers. Visualization uses Praat's drawing system (minimal memory).
Real‑time Feasibility: The tanh() function is computationally moderate. For real‑time use, consider table‑based approximation or polynomial approximation of tanh.

Mathematical Deep Dive

Hyperbolic Tangent Properties

Definition: tanh(x) = (eˣ − e⁻ˣ) / (eˣ + e⁻ˣ) Derivative (slope): d/dx tanh(x) = 1 − tanh²(x) Series expansion (near zero): tanh(x) ≈ x − x³/3 + 2x⁵/15 − 17x⁷/315 + … Odd function: tanh(−x) = −tanh(x) Bounds: −1 < tanh(x) < 1 for all real x Asymptotic behavior: tanh(x) → 1 as x → +∞ tanh(x) → −1 as x → −∞

Harmonic Analysis of Asymmetric tanh

For a sine wave input A sin(ωt):

Let F(x) = tanh(shape(x) · (drive·x + bias)) Where shape(x) = pos_Shape if x ≥ 0, else neg_Shape Fourier coefficients: a₀ = (1/2π) ∫ F(A sinθ) dθ (DC component from bias) aₙ = (1/π) ∫ F(A sinθ) cos(nθ) dθ bₙ = (1/π) ∫ F(A sinθ) sin(nθ) dθ Even n (2, 4, …) nonzero when: • pos_Shape ≠ neg_Shape (asymmetry) • bias ≠ 0 (DC offset) Odd n (1, 3, 5, …) always present Amplitude of harmonics decreases with n Drive increases harmonic content Bias shifts harmonic balance

Digital Implementation Considerations

Aliasing: Nonlinear functions generate harmonics above Nyquist tanh is band‑limited but still produces aliasing at high drive Mitigation: • Oversample before distortion (2× or 4×) • Use gentle settings (drive < 3.0) for Nyquist‑rate processing • Add low‑pass filter after distortion Computational cost: tanh() is transcendental function (moderate cost) Praat's Formula command evaluates per sample For long files, chunked processing with progress display