Fast Envelope Shaper — User Guide

Real-time amplitude modulation: uses efficient RMS envelope extraction to create dynamic effects like gates, expanders, and reverse-envelope swells without complex processing.

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 fast envelope shaping — a real-time amplitude modulation technique that extracts the RMS envelope of a signal and uses it to dynamically control the signal's own amplitude. The system provides two complementary effects: (1) Expander/Gate mode: Amplifies loud sections and attenuates quiet sections, emphasizing transients and creating punch. (2) Reverse envelope mode: Attenuates loud sections and amplifies quiet sections, creating swelling "ghost" effects and bringing out background content. The implementation uses an efficient "square-and-smooth" RMS method that avoids computationally expensive FFT processing while maintaining high quality.

Key Features:

What is envelope shaping? Envelope shaping uses a signal's own amplitude envelope to dynamically control its gain. In expander mode, the envelope acts as a control signal: when amplitude is high, gain increases; when amplitude is low, gain decreases. This emphasizes transients and creates punch. In reverse mode, the relationship is inverted: high amplitude reduces gain, low amplitude increases gain. This creates swelling effects and reveals background content. The RMS (Root Mean Square) method provides an accurate representation of perceived loudness by measuring power rather than peak amplitude. Advantages: (1) Musical dynamics: Creates natural-sounding compression/expansion. (2) Content-aware: Automatically adapts to signal characteristics. (3) Efficient processing: No complex analysis required. (4) Versatile applications: Useful for music production, sound design, and audio restoration.

Technical Implementation: (1) Signal preparation: Convert stereo to mono, optionally downsample for speed. (2) Envelope extraction: Square samples (power calculation), apply lowpass filter (smoothing), take square root (RMS conversion). (3) Mode selection: Apply envelope directly or reverse it based on user choice. (4) Modulation: Multiply original signal by envelope control signal. (5) Output processing: Normalize peak level, cleanup intermediate objects. The system uses Praat's efficient filtering and interpolation to handle sample rate differences automatically, ensuring smooth operation even when downsampling is used for performance.

Quick start

  1. In Praat, select exactly one Sound object (mono or stereo).
  2. Run script…Fast_Envelope_Shaper.praat.
  3. Choose Reverse_envelope mode (unchecked for expander, checked for reverse).
  4. Enable Use_downsampling for faster processing (recommended).
  5. Set Processing_sample_rate (16000 Hz works for most material).
  6. Adjust Envelope_smoothness_Hz (10-50 Hz typical range).
  7. Set Scale_peak output level (0.99 prevents clipping).
  8. Enable Play_after_processing to audition results.
  9. Click OK — processing completes almost instantly.
  10. Output appears as "originalname_Expander" or "originalname_RevEnv".
Quick tip: Start with expander mode (Reverse_envelope unchecked) for drums and percussive material to add punch. Use reverse mode (checked) for pads and ambient sounds to create swelling effects. Always enable downsampling for fastest processing — 16000 Hz is sufficient for envelope tracking. Lower smoothness (10-20 Hz) for gradual, musical envelope following. Higher smoothness (30-50 Hz) for tight, responsive transient shaping. For stereo files, processing converts to mono for envelope calculation but applies to original stereo, preserving spatial image. The effect is most dramatic on material with strong dynamic variation.
Important: MONO ENVELOPE EXTRACTION — stereo files are converted to mono for envelope calculation, then applied to original stereo. Extreme settings may cause pumping artifacts or excessive noise amplification. Very low smoothness (<10 Hz) may cause sluggish response missing transients. Very high smoothness (>100 Hz) may introduce modulation artifacts. Downsampling uses 50Hz transition bandwidth — avoid if processing very low-frequency content. Reverse mode can significantly amplify noise in quiet sections. Output normalization to 0.99 prevents clipping but original dynamic relationships are preserved. Test on short segments first to hear the effect character.

Envelope Shaping Theory

RMS Envelope Fundamentals

Square-and-Smooth Method

Mathematical envelope extraction:

RMS (Root Mean Square) calculation: Traditional: RMS = sqrt( (1/N) * Σ x[i]² ) Continuous approximation: envelope = lowpass( sqrt( lowpass( x² ) ) ) Three-step process: 1. SQUARE: y1[n] = x[n] * x[n] (instantaneous power) 2. SMOOTH: y2[n] = lowpass(y1[n]) (average power) 3. LINEARIZE: y3[n] = sqrt(y2[n]) (RMS amplitude) Why this works: Squaring converts amplitude to power Lowpass filtering computes moving average Square root returns to amplitude domain Result tracks perceived loudness accurately Implementation advantages: No FFT required → computational efficiency Simple operations → real-time capability Natural sound → matches human perception

Why RMS Over Peak Detection?

Perceptual advantages:

Dual Processing Modes

Expander/Gate Mode

Dynamic range expansion:

Operation: output = input * envelope Behavior: High amplitude → large envelope → high gain → louder output Low amplitude → small envelope → low gain → quieter output Result: emphasized dynamics, enhanced transients Applications: Drum enhancement → added punch and impact Speech intelligibility → clearer consonants Dynamic restoration → reversing compression artifacts Transient shaping → sharper attacks Example: Drum loop processing Original: consistent amplitude throughout Processed: drum hits louder, tails quieter Effect: more punchy and rhythmic

Reverse Envelope Mode

Inverse amplitude relationship:

Operation: output = input * (1 - envelope) [after normalization] Behavior: High amplitude → large envelope → low gain → quieter output Low amplitude → small envelope → high gain → louder output Result: swelling effects, background emphasis Applications: Ambient creation → ghostly, swelling textures Noise reduction → attenuating loud sections Sound design → unconventional dynamic effects Background revelation → bringing out quiet content Example: Pad processing Original: sustained chords with some movement Processed: loud sections fade, quiet sections swell Effect: breathing, evolving texture

📊 RMS Envelope Intuition

For speech "Hello World":

"H" consonant → high frequency energy → medium envelope

"e" vowel → sustained tone → high envelope

"llo" → lower energy → medium envelope

Silence between words → near-zero envelope


Expander mode: "e" vowel gets louder, silences get quieter

Reverse mode: "e" vowel gets quieter, silences get louder

Smoothness Control System

Envelope Response Time

Lowpass filter characteristics:

Smoothness parameter: envelope_smoothness_Hz (25 Hz default) Lower values → slower response → smoother envelope Higher values → faster response → tighter envelope Filter implementation: Hann bandpass 0-smoothness_Hz Effectively a lowpass filter at smoothness_Hz 20Hz transition bandwidth for smooth rolloff Temporal interpretation: Smoothness = 10 Hz → ~100ms response time Smoothness = 25 Hz → ~40ms response time Smoothness = 50 Hz → ~20ms response time Perceptual effects: Slow response (10-20 Hz): musical, gradual dynamics Medium response (25-35 Hz): natural, balanced Fast response (40-60 Hz): tight, transient-focused

Why Adjustable Smoothness?

Application-specific tuning:

Performance Optimization

Intelligent Downsampling

Speed vs quality tradeoff:

Downsampling logic: Original SR → 44100 Hz (typical) Target SR → processing_sample_rate (16000 Hz default) Ratio → ~2.76x speed increase Why it works for envelopes: Envelope bandwidth << audio bandwidth Nyquist for envelope: ~100 Hz maximum 16000 Hz SR provides 8000 Hz Nyquist → ample margin Praat interpolation handles SR conversion smoothly Quality preservation: Envelope calculation at lower SR Application to original at full SR No loss in final output quality Significant processing speed improvement Implementation: Resample: processing_sample_rate, 50 (50Hz transition) Process envelope at lower SR Praat automatically interpolates when applying to original

When to Avoid Downsampling

Special cases:

Processing Pipeline

🔧 Eight-Stage Envelope Processing

Complete signal path from input to shaped output:

Stage 1: Signal Preparation

StepOperationPurpose
1.1Check single sound selectionInput validation
1.2Extract original propertiesSR, channels, duration
1.3Stereo to mono conversionEnvelope calculation

Stage 2: Performance Optimization

StepOperationPurpose
2.1Check downsampling optionUser preference
2.2Resample to processing SRSpeed improvement
2.3Update working copyEfficient processing

Stage 3: RMS Envelope Extraction

StepOperationPurpose
3.1Square samples (x²)Instantaneous power
3.2Lowpass filterSmooth power average
3.3Square root (√)RMS amplitude

Stage 4: Mode Selection

StepOperationPurpose
4.1Check reverse_envelopeUser mode selection
4.2Apply reverse if selectedEffect direction
4.3Set output suffixResult identification

Stage 5: Modulation Application

StepOperationPurpose
5.1Copy original soundPreserve source
5.2Apply envelope multiplicationAmplitude modulation
5.3Automatic interpolationHandle SR differences

Stage 6: Output Finalization

StepOperationPurpose
6.1Peak normalizationPrevent clipping
6.2Rename outputClear identification
6.3Optional playbackResult audition

Stage 7: Resource Cleanup

StepOperationPurpose
7.1Remove envelope objectMemory management
7.2Remove working copiesClean object list
7.3Select final outputUser convenience

Complete Signal Flow

INPUT SOUND (mono/stereo) ↓ MONO CONVERSION: Stereo → mono for envelope ↓ OPTIONAL DOWNSAMPLING: SR reduction for speed ↓ ENVELOPE EXTRACTION: Square → Lowpass → Root ↓ MODE SELECTION: Direct or Reverse envelope ↓ MODULATION: Original × Envelope (auto-interpolated) ↓ PEAK NORMALIZATION: Scale to prevent clipping ↓ OUTPUT: "originalname_Expander" or "originalname_RevEnv"

Parameters Guide

⚙️ Complete Parameter Reference

Detailed explanation of all user-controllable parameters:

Direction Parameters

ParameterDefaultOptionsDescription
Reverse_envelope00/1Expander mode (0) or Reverse mode (1)

Performance Parameters

ParameterDefaultRangeDescription
Use_downsampling10/1Enable processing speed optimization
Processing_sample_rate160008000-44100Target SR for envelope calculation

Envelope Parameters

ParameterDefaultRangeDescription
Envelope_smoothness_Hz255-100Envelope response speed in Hz

Output Parameters

ParameterDefaultRangeDescription
Scale_peak0.990.1-1.0Output peak normalization level
Play_after_processing10/1Auto-play result after processing

Parameter Interactions

Key relationships:
  • Reverse_envelope defines effect character: Expander vs Reverse
  • Smoothness affects temporal response: Lower = more gradual
  • Downsampling improves speed: Enabled for most applications
  • Processing SR balances speed/quality: 16000 Hz optimal

Simple parameter set enables wide range of effects

Recommended Settings

🥁 Drum Expander

Goal: Add punch and impact to drums

Settings:

  • Reverse_envelope: 0 (Expander)
  • Use_downsampling: 1
  • Processing_sample_rate: 16000
  • Envelope_smoothness_Hz: 40

🌊 Ambient Swell

Goal: Create breathing, evolving textures

Settings:

  • Reverse_envelope: 1 (Reverse)
  • Use_downsampling: 1
  • Processing_sample_rate: 16000
  • Envelope_smoothness_Hz: 15

🎙️ Speech Clarifier

Goal: Improve speech intelligibility

Settings:

  • Reverse_envelope: 0 (Expander)
  • Use_downsampling: 1
  • Processing_sample_rate: 16000
  • Envelope_smoothness_Hz: 30

Applications

Music Production

Use case: Enhance dynamics and transients

Technique: Expander mode on drums and percussion

Example: Add punch to drum loops without compression artifacts

Sound Design

Use case: Create evolving textures and effects

Technique: Reverse mode on pads and ambient material

Example: Transform static pads into breathing, swelling textures

Audio Restoration

Use case: Improve intelligibility of recorded material

Technique: Expander mode on speech and dialogue

Example: Enhance consonant clarity in podcast recordings

Live Processing

Use case: Real-time dynamic effects

Technique: Fast processing enables live use

Example: Live vocal processing for performance enhancement

💡 Creative Techniques

Advanced applications:

  • Serial processing: Apply both modes sequentially
  • Frequency splitting: Process different bands separately
  • Sidechain effects: Use one sound's envelope on another
  • Automation: Vary parameters over time for evolving effects

Troubleshooting Common Issues

Problem: Pumping artifacts
Cause: Smoothness too high for material
Solution: Reduce envelope_smoothness_Hz
Problem: Noise amplification in quiet sections
Cause: Reverse mode with noisy source
Solution: Use expander mode or pre-clean source
Problem: Sluggish transient response
Cause: Smoothness too low
Solution: Increase envelope_smoothness_Hz
Problem: Stereo image issues
Cause: Mono envelope on complex stereo
Solution: Process channels separately if needed