Hard Clip (Variable Knee) — User Guide

Variable‑knee hard clipper/limiter with three‑region processing: linear, quadratic knee, and hard ceiling.

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 hard clipping with variable knee — a versatile clipping/limiting effect that smoothly transitions from linear to hard‑limited regions via a configurable quadratic knee. Three processing zones: (1) Linear: Below threshold‑knee, signal passes unchanged. (2) Knee: Between threshold±knee, quadratic curve provides smooth transition. (3) Hard Clip: Above threshold+knee, signal is hard‑limited to threshold. Key features: (1) Variable Knee Width: From 0.001 (near‑hard) to 0.5 (very soft). (2) 5 Built‑in Presets: Brickwall limiter, soft clipper, hard distortion, subtle glue, Fuzz Face emulation. (3) Drive + Threshold: Independent control of input gain and clipping ceiling. (4) Mathematical precision: Uses boolean logic for efficient three‑zone processing. (5) Visualization: Shows transfer function with knee region highlighted.

Key Features:

What is variable‑knee clipping? Traditional hard clipping abruptly limits signals above a threshold, creating harsh harmonics and potential aliasing. Variable‑knee clipping introduces a smooth transition region (the "knee") where the gain reduction gradually increases from 0 dB to full limiting. This produces more musical results with fewer harsh artifacts. The knee is implemented as a quadratic Bézier curve, providing continuous first derivative (smooth transition). Use cases: Mastering limiting, drum bus clipping, guitar distortion, vocal protection, and any application where you need controlled saturation with adjustable "hardness".

Technical Implementation: (1) Absolute value processing: Process absolute amplitude, then restore sign. (2) Three‑zone logic: Boolean switches determine zone: linear, knee, or hard clip. (3) Knee mathematics: Quadratic curve: y = T − ((T+K − |x|)² / (4K)) where T=threshold, K=knee width. (4) Formula construction: Dynamically builds Praat formula string using boolean algebra. (5) Efficient processing: Single‑pass Formula application with all logic embedded. (6) Visualization: Plots transfer function showing all three zones with threshold lines.

Quick start

  1. In Praat, select exactly one Sound object.
  2. Run script…apply_hard_clip.praat.
  3. Choose a Preset (overrides sliders) or "Manual" to use sliders.
  4. Adjust Drive (input gain before clipping).
  5. Set Threshold (clipping ceiling level).
  6. Choose Knee_Width (transition softness: 0.01=hard, 0.5=soft).
  7. Set Output_Gain for volume compensation.
  8. Enable Draw_visualization to see transfer function.
  9. Click OK — effect applied, result named "originalname_Clip_presetname".
Quick tip: Start with Soft Clipper preset for musical saturation. Use Brickwall Limiter for peak control without audible distortion. Hard Distortion creates aggressive guitar‑like clipping. Subtle Glue provides transparent loudness enhancement. Fuzz Face emulates classic low‑threshold fuzz. Enable visualization to see knee behavior — wider knee = smoother curve, narrower knee = sharper corner. Drive controls how much signal hits the clipper; higher Drive = more clipping. Threshold sets the clipping ceiling; lower Threshold = more aggressive limiting. Knee_Width < 0.1 creates near‑hard clipping; > 0.3 creates very soft transitions.
Important: HARD CLIPPING GENERATES HARMONICS — creates rich harmonic content but can cause aliasing with high‑frequency content. Very narrow knee widths (< 0.05) approach hard clipping → potentially harsh sound. Very low thresholds (< 0.3) cause heavy distortion. High Drive values can cause extreme gain reduction and loss of dynamic range. Output_Gain often needs adjustment after clipping — clipped peaks are lower than input peaks. Visualization shows absolute transfer function; actual output includes sign restoration. Threshold and Knee_Width are in absolute amplitude units (0‑1 scale). Drive > 1 amplifies input, increasing likelihood of clipping.

Clipping Theory

Three‑Zone Processing Model

📊 Processing Zones

Define: x = input amplitude (after Drive) T = Threshold K = Knee_Width y = output amplitude (before Output_Gain) Three zones based on |x|: 1. LINEAR ZONE (|x| ≤ T−K) y = |x| No gain reduction, signal passes unchanged 2. KNEE ZONE (T−K < |x| < T+K) y = T − ((T+K − |x|)² / (4K)) Quadratic transition, smooth gain reduction 3. HARD CLIP ZONE (|x| ≥ T+K) y = T Hard limiting, constant output Finally restore sign and apply gain: output = y × sign(x) × Output_Gain

Visual interpretation: The knee creates a smooth "rounded corner" between the linear region and the hard‑clipped ceiling. Wider knee = more gradual transition, softer sound. Narrower knee = sharper transition, harder sound.

Knee Mathematics

Quadratic Bézier Implementation

Knee curve derivation: We want a quadratic curve that: 1. Matches linear region at |x| = T−K (position and slope) 2. Matches hard clip at |x| = T+K (position only) 3. Is continuous with continuous first derivative Solution: Quadratic Bézier with: P0 = (T−K, T−K) [start of knee] P1 = (T, T) [control point] P2 = (T+K, T) [end of knee] Parametric form (t from 0 to 1): x(t) = (1−t)²(T−K) + 2(1−t)t(T) + t²(T+K) y(t) = (1−t)²(T−K) + 2(1−t)t(T) + t²(T) Solve for y as function of x: y = T − ((T+K − |x|)² / (4K)) Properties: • At |x| = T−K: y = T−K, dy/dx = 1 (matches linear) • At |x| = T+K: y = T, dy/dx = 0 (matches hard clip) • Always continuous with continuous derivative

Knee Width Interpretation

Knee_Width effects (T=0.7):

K=0.01 (Near‑hard): • Knee region: 0.69‑0.71 • Very sharp transition • Sounds like: Classic hard clipping, rich odd harmonics

K=0.1 (Moderate): • Knee region: 0.6‑0.8 • Noticeable rounding • Sounds like: Musical soft clipping, balanced harmonics

K=0.3 (Wide): • Knee region: 0.4‑1.0 • Very gradual transition • Sounds like: Gentle saturation, minimal distortion

K=0.5 (Very wide): • Knee region: 0.2‑1.2 • Extremely soft • Sounds like: Transparent limiting, "glue" effect

Boolean Logic Implementation

⚡ Efficient Zone Selection

Praat Formula implementation uses boolean logic: Define boolean switches (1 if true, 0 if false): is_linear = (|x| ≤ T−K) is_knee = (T−K < |x| < T+K) is_flat = (|x| ≥ T+K) Compute output for each zone: y_linear = |x| y_knee = T − ((T+K − |x|)² / (4K)) y_flat = T Combine using boolean multiplication: y_abs = (is_linear × y_linear) + (is_knee × y_knee) + (is_flat × y_flat) Restore sign: sign = (x>0) − (x<0) # Returns 1, 0, or -1 Final: output = y_abs × sign × Output_Gain

Why boolean logic? This allows all three zones to be computed in a single Praat Formula command without conditional statements (if/then), which Praat's Formula doesn't support directly. The boolean switches act as "gates" that only allow one zone's contribution at a time.

Parameter Interactions

Drive (Input Gain)

Effect: Multiplies input before clipping threshold detection.

Mathematical: Effective input to clipper = original × Drive.

Interaction: Higher Drive pushes more signal into knee/clip zones. With Threshold fixed, increasing Drive increases amount of clipping.

Threshold (Clipping Ceiling)

Effect: Maximum output amplitude before Output_Gain.

Mathematical: Hard ceiling at y = Threshold in clip zone.

Interaction: Lower Threshold causes earlier/more clipping. With Drive fixed, lowering Threshold increases clipping.

Knee_Width (Transition Softness)

Effect: Width of quadratic transition region.

Mathematical: Determines range T±K where knee operates.

Interaction: Affects harmonic content — narrower = more odd harmonics, wider = more even harmonics.

Output_Gain (Volume Compensation)

Effect: Multiplies after clipping.

Mathematical: Final output = clipped_signal × Output_Gain.

Interaction: After heavy clipping, peaks are reduced; Output_Gain can restore perceived loudness.

Harmonic Generation Analysis

🎵 Harmonic Characteristics

Hard Clip (K→0): • Rich odd harmonics (3rd, 5th, 7th...) • Sharp corners → high‑frequency content • Can cause aliasing • Classic "digital" distortion sound

Soft Clip (K=0.2‑0.3): • More even harmonics (2nd, 4th...) • Smooth transition → fewer high harmonics • Less aliasing • "Analog" warmth character

Very Soft (K>0.4): • Minimal harmonics • Gentle saturation • Primarily dynamic range control • "Glue" or "warmth" without obvious distortion

Low Threshold + High Drive: • Heavy harmonic generation • Complex intermodulation • "Fuzz" or "overdrive" character • Can become noisy/mushy

Parameters & Presets

Common Parameters

ParameterTypeDefaultDescription
PresetoptionmenuManual5 built‑in presets or manual control
Drivereal1.0Input gain before clipping (multiplier)
Thresholdreal0.5Clipping ceiling (0‑1 scale)
Knee_Widthreal0.2Transition softness (0.001‑0.5)
Output_Gainreal0.9Post‑clipping volume compensation
Draw_visualizationboolean1 (yes)Show transfer function plot
Play_resultboolean1 (yes)Auto‑play after processing

Built‑in Presets

PresetDriveThresholdKnee_WidthOutput_GainCharacter
Brickwall Limiter1.20.80.050.95Transparent peak control, minimal distortion
Soft Clipper2.00.60.40.8Musical saturation, analog‑like warmth
Hard Distortion5.00.40.010.6Aggressive guitar‑style clipping
Subtle Glue1.00.70.51.0Gentle loudness enhancement, "glue" effect
Fuzz Face (Low Thresh)8.00.10.10.5Classic fuzz‑style heavy distortion

Preset Design Philosophy

🎛️ Preset Characteristics Explained

Brickwall Limiter: • High Threshold (0.8) = clips only extreme peaks • Very narrow Knee (0.05) = near‑instant limiting • Moderate Drive (1.2) = gentle gain boost into limiter • High Output_Gain (0.95) = minimal level reduction • Use: Final mastering, peak protection

Soft Clipper: • Moderate Threshold (0.6) = noticeable saturation • Wide Knee (0.4) = smooth, musical transition • Higher Drive (2.0) = pushes signal into knee • Lower Output_Gain (0.8) = compensates for saturation • Use: Analog‑style saturation, warmth addition

Hard Distortion: • Lower Threshold (0.4) = aggressive clipping • Very narrow Knee (0.01) = near‑hard clipping • High Drive (5.0) = heavy signal boost • Low Output_Gain (0.6) = level reduction after heavy clipping • Use: Guitar distortion, aggressive sound design

Subtle Glue: • Moderate Threshold (0.7) = gentle limiting • Very wide Knee (0.5) = extremely soft transition • Unity Drive (1.0) = no additional gain • Unity Output_Gain (1.0) = level preservation • Use: Mix bus "glue", gentle loudness enhancement

Fuzz Face: • Very low Threshold (0.1) = constant heavy clipping • Moderate Knee (0.1) = some rounding • Very high Drive (8.0) = massive gain boost • Low Output_Gain (0.5) = volume reduction for safety • Use: Classic fuzz tones, extreme distortion

Parameter Relationships

Drive × Threshold relationship: The product Drive × (input peak) determines how much signal exceeds Threshold. Example: Input peaks at 0.5, Drive=2.0 → effective peak=1.0. If Threshold=0.7, signal exceeds threshold by 0.3 → clipping occurs.
Knee_Width relative to Threshold: Knee_Width should be considered relative to Threshold. For Threshold=0.5, Knee_Width=0.2 means knee operates from 0.3‑0.7 (40% of threshold range). For Threshold=0.8, same Knee_Width=0.2 means 0.6‑1.0 (25% of range).
Output_Gain compensation: After clipping, peak amplitude ≈ Threshold (in hard clip zone). Output_Gain can be set to ≈ 1/Threshold to restore peaks to near‑original level, or adjusted for creative effect.

Applications

Mastering & Final Limiting

Use case: Transparent peak control for mastering

Technique: Use Brickwall Limiter preset

Tip: Set Threshold just above program peaks, minimal Drive (1.0‑1.3), very narrow Knee (0.01‑0.05)

Advanced: Use in series with compression: compress for dynamics, then clip for final peaks

Analog‑Style Saturation

Use case: Adding warmth and harmonics

Technique: Use Soft Clipper preset

Tip: Moderate Drive (1.5‑3.0), Threshold around 0.6‑0.7, wide Knee (0.3‑0.5)

Advanced: Apply to individual tracks rather than mix bus for controlled saturation

Guitar & Bass Distortion

Use case: Amp‑like distortion tones

Technique: Use Hard Distortion or Fuzz Face presets

Tip: High Drive (4‑10), low Threshold (0.1‑0.4), narrow‑medium Knee (0.05‑0.2)

Advanced: Chain multiple instances: soft clip → hard clip for complex distortion

Drum & Percussion Processing

Use case: Drum bus "smash" or transient shaping

Technique: Moderate Drive (2‑4), Threshold around transients, adjust Knee for hardness

Tip: Fast‑attack clipping can tame drum transients; parallel process for blend control

Advanced: Use envelope follower to modulate Threshold for dynamic drum processing

Vocal "In‑Your‑Face" Effect

Use case: Aggressive vocal presence

Technique: Moderate Drive (1.5‑2.5), Threshold just above average level

Tip: Use wider Knee (0.3‑0.4) for vocal smoothness, narrower for aggression

Advanced: De‑ess before clipping to prevent sibilance distortion

Practical Workflow Examples

🎚️ Mastering Chain Clipper

Goal: Final peak control without audible distortion

Settings:

  • Preset: Brickwall Limiter (modified)
  • Drive: 1.1 (gentle boost)
  • Threshold: 0.85 (clip only highest peaks)
  • Knee_Width: 0.02 (very sharp)
  • Output_Gain: 0.98 (minimal reduction)

Result: Transparent 1‑2 dB peak reduction, no audible distortion

🎸 Rock Guitar Rhythm

Goal: Crunchy rhythm guitar tone

Settings:

  • Preset: Hard Distortion (modified)
  • Drive: 3.5
  • Threshold: 0.5
  • Knee_Width: 0.15 (some rounding)
  • Output_Gain: 0.8

Result: Aggressive but defined rhythm distortion, not too fizzy

🥁 Parallel Drum Smash

Goal: Aggressive parallel drum compression via clipping

Settings:

  • Preset: Soft Clipper (modified)
  • Drive: 4.0
  • Threshold: 0.4
  • Knee_Width: 0.25
  • Output_Gain: 0.6

Technique: Process copy of drum bus, blend 10‑30% with dry

Result: Punchy, aggressive drums without losing transients

Advanced Techniques

Multi‑band Clipping: Split signal into frequency bands, apply different clipping settings to each band. Example: Hard clip lows for punch, soft clip highs for smoothness, no clip mids for clarity. Recombine with phase alignment.
Dynamic Knee Width: Use envelope follower to modulate Knee_Width based on signal level. Louder = wider knee (softer), quieter = narrower knee (harder). Creates more natural dynamic response.
Oversampling: For high‑frequency content or extreme clipping, oversample before processing (2× or 4×), clip, then downsample. Reduces aliasing artifacts from hard clipping.
Look‑ahead Clipping: Delay audio slightly, analyze upcoming peaks, adjust Threshold dynamically. Requires additional buffering but allows more transparent limiting.

Troubleshooting Common Issues

Problem: Harsh, "digital" sounding distortion
Cause: Knee_Width too narrow (< 0.05), creating near‑hard clipping
Solution: Increase Knee_Width to 0.1‑0.3 for smoother transition
Problem: Too much distortion, loss of clarity
Cause: Threshold too low and/or Drive too high
Solution: Increase Threshold, decrease Drive, or both
Problem: Not enough effect, hard to hear clipping
Cause: Threshold too high relative to signal level
Solution: Decrease Threshold or increase Drive
Problem: Output too quiet after processing
Cause: Output_Gain too low after peak reduction
Solution: Increase Output_Gain (try 1/Threshold as starting point)
Problem: Aliasing/distortion artifacts on high frequencies
Cause: Hard clipping of high‑frequency content
Solution: Increase Knee_Width, reduce Drive, or use oversampling

Mathematical Deep Dive

Transfer Function Analysis

Complete transfer function: Let x = input × Drive Define zones: Zone 1 (|x| ≤ T−K): f₁(x) = |x| Zone 2 (T−K < |x| < T+K): f₂(x) = T − ((T+K − |x|)²/(4K)) Zone 3 (|x| ≥ T+K): f₃(x) = T Output: y = [zone selector] × sign(x) × Output_Gain Derivatives (slopes): f₁'(x) = ±1 (linear) f₂'(x) = (T+K − |x|)/(2K) (quadratic, varies linearly) f₃'(x) = 0 (flat) Continuity check: At |x| = T−K: f₁ = T−K, f₂ = T−K, f₁' = 1, f₂' = 1 ✓ At |x| = T+K: f₂ = T, f₃ = T, f₂' = 0, f₃' = 0 ✓

Harmonic Analysis of Knee Clipping

For sinusoid input A sin(ωt):

Let effective input after Drive: B = A × Drive Three cases: 1. B ≤ T−K (no clipping): Output = B sin(ωt) × Output_Gain No harmonics generated 2. T−K < B < T+K (knee region): Output is piecewise: For |B sin(ωt)| ≤ T−K: linear For |B sin(ωt)| > T−K: quadratic knee Fourier series contains even and odd harmonics. Harmonic amplitudes depend on B, T, K. Generally: More even harmonics than hard clip. 3. B ≥ T+K (hard clip region): Output clipped at ±T during peaks. Classic hard‑clipped waveform. Rich in odd harmonics. Harmonic amplitudes: aₙ = (4T/π) [sin(nθ)/n − cos(nθ)sin(θ)/(n²−1)] where θ = arcsin(T/B)

Aliasing Considerations

Hard clipping creates sharp corners → high‑frequency content. Nyquist theorem: Content above fs/2 aliases down. For sine wave at frequency f₀: Hard‑clipped waveform has harmonics at nf₀. Highest harmonic: f_max = floor(fs/(2f₀)) × f₀ Harmonics above fs/2 alias to: f_alias = |nf₀ − kfs| where k integer Knee smoothing reduces high harmonics: With knee, waveform has continuous derivative. High‑frequency roll‑off: ∼ 1/f² for quadratic knee vs. ∼ constant for hard clip. Less aliasing with wider knees. Oversampling benefit: Process at 2× or 4× original rate. High harmonics appear above original fs/2 but below oversampled fs/2. Downsample with anti‑alias filter → clean result.

Boolean Logic Implementation Details

Praat Formula limitations: No if/then/else in Formula command. Boolean expressions return 1 (true) or 0 (false). Implementation trick: (condition) returns 1 if true, 0 if false. Multiplication by boolean acts as gate. Example: is_linear = (abs(x) <= T−K) # 1 if true, 0 if false contribution_linear = is_linear × f₁(x) Similarly for other zones. Zone combination: Since zones are mutually exclusive: is_linear + is_knee + is_flat = 1 (exactly one true) So: output = is_linear×f₁ + is_knee×f₂ + is_flat×f₃ Sign restoration: sign = (x>0) − (x<0) # Praat boolean arithmetic This gives: 1 if x>0, −1 if x<0, 0 if x=0