Spectral Painter — User Guide

Advanced spectral‑domain processing: applies frequency‑dependent gain patterns (sine, triangle, square, exponential, random) across the spectrum to create complex tonal transformations—from musical phasing to extreme spectral carving.

Technique: Spectral Gain Modulation Implementation: Praat Script Category: Advanced Spectral Processing Version: Experimental Edition License: MIT License
Contents:

What this does

This script implements spectral painting — a technique that applies frequency‑dependent gain patterns directly to the magnitude spectrum of a sound. Unlike traditional equalization (static gain per frequency band) or filtering (smooth curves), spectral painting uses mathematical waveforms (sine, triangle, square, sawtooth, exponential, logarithmic, random) as gain templates across the frequency axis. The gain at each frequency bin is determined by evaluating the waveform function at that frequency: gain(f) = center + depth × waveform(f/divisor). This creates complex, structured spectral modifications that can produce effects ranging from subtle phasing to extreme spectral reconstruction.

Key Features:

What is spectral gain modulation? Traditional audio effects work in the time domain (delay, reverb) or apply simple frequency‑domain operations (EQ, filtering). Spectral gain modulation treats the frequency axis as a canvas and "paints" gain patterns across it:
  • Frequency‑dependent gain: Each frequency bin gets its own gain value
  • Patterned structure: Gain follows mathematical waveform (e.g., sine wave across frequency)
  • Musical relationships: Logarithmic spacing matches human pitch perception (octaves equally spaced)
  • Extreme possibilities: Square wave creates "brick‑wall" comb filtering, random creates spectral diffusion
The result is not subtle EQ but dramatic spectral reconstruction that can make sounds metallic, hollow, shimmering, or completely transformed.

Technical Implementation: The script follows a three‑step FFT‑based process: (1) Convert to Spectrum: Uses Praat's To Spectrum with Hann windowing. (2) Apply gain pattern: Builds a formula that multiplies each spectral bin by center + depth × waveform(frequency/divisor), where waveform is one of nine mathematical functions. The formula is applied via Praat's Formula command to the spectrum's magnitude values. (3) Convert back to Sound: Uses To Sound to return to time domain. A cutoff frequency allows limiting the effect to lower frequencies only. Phase inversion detection warns when gain becomes negative (which inverts phase in those frequency bands).

Quick start

  1. In Praat, select exactly one Sound object to process.
  2. Run script…spectral_painter.praat.
  3. Choose a Preset (Metallic Ring, High Shimmer, Comb Filter, etc.).
  4. Or select Custom and choose modulation_type manually.
  5. Adjust basic parameters if desired (cutoff_frequency, modulation_center/depth, etc.).
  6. Set warn_phase_inversion (recommended: yes for safety).
  7. Set scale_peak and play_after_processing.
  8. Click OK — script converts to spectrum, applies gain pattern, converts back.
  9. If phase inversion detected, you'll be warned (continue or abort).
  10. Output appears as: originalName_mod.
Quick tip: Start with Metallic Ring preset on a vocal or speech sound — creates classic "robot voice" effect. Try High Shimmer on cymbals or bright textures for sparkling enhancement. Comb Filter creates extreme metallic/ringing effects (use sparingly). Musical Phaser uses logarithmic spacing for perceptually uniform modulation across octaves. For experimental textures, try Random Spectral Carving or Chaotic Wobble. Watch the Info window for processing confirmation and warnings. The script preserves phase relationships except when phase inversion occurs (negative gain). For subtle effects, reduce modulation_depth to 0.2‑0.4.
Important: SELECT EXACTLY ONE SOUND — script exits with error if 0 or >1 sounds selected. PHASE INVERSION RISK — if modulation_center - |modulation_depth| < 0, gain becomes negative in some bands, inverting phase. This creates "hollow" flanged effects but can destroy signal coherence. The safety warning can be disabled but is recommended. SPECTRAL PROCESSING ARTIFACTS — FFT‑based processing can cause pre‑echo, time‑smearing, or phase issues, especially with extreme settings. CUTOFF_FREQUENCY above Nyquist (sample_rate/2) will be ignored. LONG SOUNDS may cause memory issues during FFT conversion. STEREO SOUNDS are processed channel‑by‑channel (mono‑compatible but not true stereo spectral processing).

Spectral Modulation Theory

The Core Equation

🎨 Spectral Gain Formula

General form:

For each frequency bin f (Hz): gain(f) = modulation_center + modulation_depth × waveform(f / modulation_frequency_divisor) Where: • modulation_center = baseline gain (typically 1.0 = unity) • modulation_depth = amplitude of waveform variation (0‑1 typically) • waveform() = mathematical function (sine, triangle, square, etc.) • modulation_frequency_divisor = scales waveform across frequency axis (small divisor = many cycles across spectrum, large = few cycles) Applied to spectrum magnitude: magnitude_out(f) = magnitude_in(f) × gain(f) Phase is preserved unless gain(f) < 0, which causes phase inversion (180° shift).

Frequency‑Domain vs. Time‑Domain Interpretation

🔄 Two Perspectives on Same Effect

Spectral domain view (what the script does):

Input spectrum: |X(f)|
Gain pattern:   G(f) = center + depth × wave(f/divisor)
Output spectrum: |Y(f)| = |X(f)| × G(f)
Phase: ∠Y(f) = ∠X(f) (or ∠X(f) + π if G(f) < 0)
    

Time‑domain equivalent (conceptual):

Gain pattern G(f) in frequency domain corresponds to
convolution with impulse response g(t) in time domain.

For sine wave gain pattern:
  G(f) = 1 + d × sin(2πf/Ω)  (Ω = modulation_frequency_divisor)
  
Time‑domain equivalent:
  y(t) = x(t) + (d/2) × [x(t - 1/Ω) - x(t + 1/Ω)]
  
This is a comb‑filter‑like operation with delayed/advanced copies.
Different waveforms create different convolution kernels.
    

Thus, spectral painting is equivalent to applying a specific, structured convolution filter to the time‑domain signal.

Linear vs. Logarithmic Frequency Scaling

Linear spacing (modulation_type = 1): waveform argument = f / divisor Example: divisor=100, f=100 Hz → argument=1, f=1000 Hz → argument=10 Effect: Equal number of waveform cycles per Hz Perception: More modulation at high frequencies (may sound "top‑heavy") Logarithmic spacing (modulation_type = 2): waveform argument = ln(f) × density Example: density=15, f=100 Hz → ln(100)×15≈69, f=1000 Hz → ln(1000)×15≈104 Effect: Equal number of waveform cycles per octave Perception: Musically uniform spacing (matches pitch perception) Human hearing perceives frequency ratios (octaves = 2:1 ratio), not differences Why logarithmic matters: • Linear: 100‑200 Hz (1 octave) vs 1000‑1100 Hz (much less than octave) • Logarithmic: Both intervals treated similarly in perceptual space • Musical phasing, harmonic enhancement work better with log spacing

FFT Processing Pipeline

STEP 1: TIME → FREQUENCY DOMAIN selectObject: sound spec = To Spectrum: "yes" # Hann window, FFT size auto‑determined Praat's To Spectrum: • Applies Hann window to avoid spectral leakage • Zero‑pads if needed for efficient FFT size • Computes complex spectrum (magnitude + phase) STEP 2: APPLY GAIN PATTERN selectObject: spec # Build formula based on modulation_type formula$ = "if x < cutoff then self * (center + depth * waveform(x/divisor)) else self fi" Formula: formula$ Notes: • x = frequency in Hz (spectrum's horizontal axis) • self = complex spectrum value at that frequency • Multiplication affects magnitude, preserves phase (unless gain<0) • cutoff_frequency limits effect to frequencies below cutoff STEP 3: FREQUENCY → TIME DOMAIN processed_sound = To Sound # Inverse FFT (Praat handles windowing/overlap‑add) STEP 4: FINALIZE Scale peak: scale_peak Rename: originalName + "_mod"

Gain Range and Phase Considerations

📈 Gain Calculations

Gain range:

For waveform values between -1 and 1 (sine, triangle, etc.): min_gain = modulation_center - |modulation_depth| max_gain = modulation_center + |modulation_depth| Examples: center=1.0, depth=0.5 → gain range: 0.5 to 1.5 (-6 dB to +3.5 dB) center=0.8, depth=0.6 → gain range: 0.2 to 1.4 (-14 dB to +3 dB) center=0.5, depth=0.6 → gain range: -0.1 to 1.1 (negative!)

Negative gain consequences:

  • gain < 0 → magnitude multiplied by negative number
  • Equivalent to: magnitude × |gain|, phase shifted by π (180°)
  • Creates destructive interference with other frequency components
  • Results in "hollow", "flanged", or "phase‑cancelled" sound
  • Can completely cancel signal if gain = -1 and other components interfere

Modulation Types (Waveforms)

Type 1: Sine Wave (Linear)

📐 Classic Sinusoidal Modulation

Formula: center + depth × sin(f/divisor + phase_offset)

Waveform characteristics: Smooth, periodic oscillation between -1 and 1.

Spectral effect: Creates alternating bands of boost and cut across frequency spectrum. The most "musical" and natural‑sounding modulation type.

Frequency interpretation: divisor controls modulation density: small divisor = many cycles across spectrum (dense comb filtering), large divisor = few cycles (broad tonal shaping).

Phase_offset: Shifts entire pattern along frequency axis (0‑2π).

Default for presets: Metallic Ring, Deep Resonance, High Shimmer, Inverted Valleys.

Type 2: Sine Wave (Logarithmic/Musical)

🎵 Perceptually Uniform Spacing

Formula: center + depth × sin(ln(f) × density + phase_offset)

Waveform characteristics: Sine wave evaluated on logarithmic frequency scale.

Spectral effect: Equal modulation density per octave rather than per Hz. Creates musically meaningful patterns where each octave gets similar treatment.

Why logarithmic?: Human hearing perceives frequency ratios (octave = 2:1 ratio) not differences. 100‑200 Hz sounds like similar interval as 1000‑2000 Hz to our ears.

density parameter: Derived from modulation_frequency_divisor/10. Higher density = more cycles per octave.

Default for preset: Musical Phaser.

Type 3: Triangle Wave

📊 Linear Ramps

Formula: center + depth × (2×|(f/divisor - floor(f/divisor + 0.5))| - 1)

Waveform characteristics: Linear ramps up and down, sharp corners at peaks.

Spectral effect: Creates smoothly changing gain that reverses direction abruptly. Less "ringy" than sine, more systematic than random.

Sound character: Metallic but less resonant than sine. Good for synthetic, digital‑sounding effects.

Type 4: Square Wave (Stepped)

🧱 Brick‑Wall Comb Filtering

Formula: center + depth × (if sin(f/divisor) > 0 then 1 else -1 fi)

Waveform characteristics: Instant jumps between +1 and -1 (or +depth and -depth).

Spectral effect: Creates alternating bands of maximum boost and maximum cut (possibly phase inversion). Extreme "comb filter" effect.

Phase coherence: Uses sine test to ensure 0‑crossings align, avoiding random phase jumps.

Sound character: Harsh, metallic, ringing. Can create strong resonances at band edges.

Default for preset: Comb Filter (Harsh).

Type 5: Sawtooth Wave

📈 Linear Ramps with Instant Reset

Formula: center + depth × (2×((f/divisor) - floor(f/divisor + 0.5)))

Waveform characteristics: Linear ramp upward, instant drop back to start.

Spectral effect: Creates continuously increasing gain across frequency bands, then sudden reset. Produces "sweeping filter" sensation.

Sound character: Whooshing, sweeping effects. Good for creating motion across frequency spectrum.

Default for presets: Frequency Stairs, Pulsing Bands.

Type 6: Exponential Decay

📉 Natural High‑Frequency Roll‑Off

Formula: center + depth × exp(-f/divisor)

Waveform characteristics: Starts at maximum at f=0, decays exponentially toward 0 as f increases.

Spectral effect: Strong low‑frequency boost/emphasis that smoothly decreases toward high frequencies. Mimics natural acoustic roll‑off or "warmth" curve.

Sound character: Warm, bass‑emphasized, natural‑sounding spectral tilt.

Default for presets: Harmonic Series, Exponential Sweep.

Type 7: Logarithmic Growth

📈 Gentle High‑Frequency Emphasis

Formula: center + depth × ln(1 + f/divisor)

Waveform characteristics: Starts at 0 at f=0, grows logarithmically (slowly) as f increases.

Spectral effect: Subtle high‑frequency emphasis that increases slowly with frequency. Opposite of exponential decay.

Sound character: Brightening, air‑adding, gentle high‑frequency enhancement.

Type 8: Random (Per‑Bin Diffusion)

🎲 Stochastic Spectral Carving

Formula: center + depth × (sin(f/divisor) + randomness_amount × randomGauss(0,1))

Waveform characteristics: Sine wave with added Gaussian noise at each frequency bin.

Spectral effect: Creates "fuzzy" or "glassy" spectral texture. Each frequency bin gets slightly randomized gain, breaking up coherent patterns.

Note: randomGauss(0,1) generates new random value for each frequency bin during formula evaluation.

Sound character: Diffused, granular, textured. Can sound like broken glass or stochastic resonance.

Default for presets: Chaotic Wobble, Random Spectral Carving.

Type 9: Dual Sine (Interference)

🌊 Two‑Frequency Beat Patterns

Formula: center + depth × (sin(f/divisor) + 0.5×sin(f/second_divisor)) / 1.5

Waveform characteristics: Sum of two sine waves with different frequencies.

Spectral effect: Creates complex interference pattern with beating. The two sine waves interact, producing reinforcement and cancellation at different frequencies.

Sound character: Richer, more complex than single sine. Can sound like dual‑comb‑filter or chorus‑like effect.

Default for preset: Dual Wave Interference.

Waveform Comparison Table

TypeFormulaRangeSmoothnessSonic CharacterPreset Use
Sine (Linear)sin(f/d)[-1,1]Very smoothMusical, resonantMetallic Ring, etc.
Sine (Log)sin(ln(f)×k)[-1,1]Very smoothPerceptually uniformMusical Phaser
Triangletriangle(f/d)[-1,1]Piece‑wise linearDigital, metallic
Squaresign(sin(f/d)){-1,1}DiscontinuousHarsh, ringingComb Filter
Sawtoothsaw(f/d)[-1,1]Piece‑wise linearSweeping, whooshingFrequency Stairs
Exponentialexp(-f/d)[0,1]Very smoothWarm, natural decayHarmonic Series
Logarithmicln(1+f/d)[0,∞)SmoothBrightening
Randomsin+noise(-∞,∞)StochasticFuzzy, glassyChaotic Wobble
Dual Sinesin(f/d₁)+sin(f/d₂)[-1.5,1.5]SmoothComplex, beatingDual Wave

Preset Characters

Category 1: Musical & Natural

Preset 2: Metallic Ring (Linear)

🤖 Classic "Robot Voice" Effect

Settings:

  • Modulation type: Sine Wave (Linear)
  • Modulation depth: 0.9 (strong)
  • Modulation frequency divisor: 100
  • Cutoff frequency: 10000 Hz

Mechanism: Sine wave gain pattern across linear frequency scale creates alternating boost/cut bands. The relatively high divisor (100) gives moderate‑density comb filtering.

Sonic character: Classic vocoder/robot voice effect. Makes speech sound synthetic and metallic while remaining intelligible. Also works on instruments for "ring modulator"‑like effects.

Best for: Vocal processing for sci‑fi effects, syntheticizing acoustic instruments.

Preset 3: Deep Resonance

🎻 Bass‑Focused Spectral Enhancement

Settings:

  • Modulation type: Sine Wave (Linear)
  • Modulation depth: 0.95 (very strong)
  • Modulation frequency divisor: 400 (low density)
  • Cutoff frequency: 5000 Hz (affects only lower frequencies)

Mechanism: Low‑density sine pattern (divisor=400) creates broad boost/cut regions across low frequencies. High depth (0.95) creates strong resonances.

Sonic character: Adds weight and resonance to bass frequencies. Can make kicks thicker, basslines more powerful, or add "chest" resonance to vocals.

Best for: Bass enhancement, low‑frequency thickening, adding warmth.

Preset 4: High Shimmer

✨ Treble Sparkle & Air

Settings:

  • Modulation type: Sine Wave (Linear)
  • Modulation depth: 0.6 (moderate)
  • Modulation frequency divisor: 50 (high density)
  • Cutoff frequency: 20000 Hz (affects full range)

Mechanism: High‑density sine pattern (divisor=50) creates many narrow boost/cut bands in high frequencies. Moderate depth avoids extreme peaks.

Sonic character: Adds sparkle, air, and shimmer to high frequencies. Makes cymbals more detailed, vocals more present, or adds "fairy dust" to pads.

Best for: High‑frequency enhancement, adding air and sparkle, brightening dull mixes.

Category 2: Extreme & Experimental

Preset 5: Comb Filter (Harsh)

🔊 Brick‑Wall Spectral Processing

Settings:

  • Modulation type: Square Wave (Stepped)
  • Modulation depth: 1.0 (maximum)
  • Modulation frequency divisor: 200
  • Cutoff frequency: 12000 Hz
  • Modulation center: 1.0

Mechanism: Square wave creates instantaneous jumps between +1 and -1 gain (phase inversion in cut bands). Maximum depth creates extreme contrast.

Sonic character: Harsh, metallic, ringing. Creates strong resonances at band edges. Can sound like extreme comb filtering or broken speaker.

Best for: Extreme sound design, industrial music, distortion effects. Use sparingly.

Preset 6: Harmonic Series

🎼 Exponential Spectral Tilt

Settings:

  • Modulation type: Exponential Decay
  • Modulation depth: 0.7
  • Modulation frequency divisor: 100
  • Cutoff frequency: 8000 Hz

Mechanism: Exponential decay gain pattern: strong at low frequencies, decreasing toward highs. Mimics natural harmonic amplitude distribution.

Sonic character: Warm, natural‑sounding spectral balance. Emphasizes fundamental and lower harmonics, gently rolls off highs.

Best for: Adding warmth, naturalizing synthetic sounds, vintage emulation.

Preset 7: Chaotic Wobble

🌀 Stochastic Spectral Diffusion

Settings:

  • Modulation type: Random (Per‑Bin Diffusion)
  • Modulation depth: 0.85
  • Randomness amount: 0.5
  • Cutoff frequency: 10000 Hz

Mechanism: Sine wave with added Gaussian noise at each frequency bin. Creates "fuzzy" gain pattern that breaks up coherent spectral structure.

Sonic character: Glassy, textured, diffused. Sounds like broken glass, stochastic resonance, or granular texture.

Best for: Experimental textures, granular synthesis effects, adding complexity to static sounds.

Preset 8: Dual Wave Interference

🌊 Complex Beat Patterns

Settings:

  • Modulation type: Dual Sine (Interference)
  • Modulation depth: 0.7
  • Modulation frequency divisor: 100
  • Second divisor: 250
  • Cutoff frequency: 12000 Hz

Mechanism: Sum of two sine waves with frequencies in ratio 100:250 (2:5). Creates complex interference pattern with beating.

Sonic character: Richer, more complex than single sine. Sounds like dual comb filters or chorus‑like effect. Creates moving, evolving spectral patterns.

Best for: Adding complexity to modulation effects, creating evolving textures, chorus‑like widening.

Preset 9: Frequency Stairs

📶 Stepped Digital Filtering

Settings:

  • Modulation type: Sawtooth
  • Modulation depth: 0.8
  • Modulation frequency divisor: 300
  • Cutoff frequency: 15000 Hz

Mechanism: Sawtooth wave creates linear gain increase across frequency bands, then instant reset. Creates "stepped" or "quantized" spectral effect.

Sonic character: Digital, steppy, like low‑resolution spectral processing or bit‑crushed frequency domain.

Best for: Digital distortion effects, retro computer sounds, quantization artifacts.

Category 3: Phase‑Based Effects

Preset 10: Inverted Valleys (Phase Flip)

🔄 Negative Gain Bands

Settings:

  • Modulation type: Sine Wave (Linear)
  • Modulation center: 0.8
  • Modulation depth: -0.6 (negative!)
  • Modulation frequency divisor: 200
  • Cutoff frequency: 10000 Hz

Mechanism: Negative depth with center=0.8 creates gain range: 0.2 to 1.4. The "valleys" (gain < 1) can go as low as 0.2, but more importantly, the sine wave oscillates around 0.8, not 1.0.

Phase inversion warning: This preset triggers phase inversion warning because min_gain = 0.8 - 0.6 = 0.2 (positive, so no actual phase flip despite warning threshold).

Sonic character: Creates alternating bands of moderate boost and strong cut. "Valleys" are deeper than "peaks" are high.

Best for: Creating hollow, scooped effects without actual phase inversion.

Preset 11: Random Spectral Carving

🎲 Extreme Stochastic Processing

Settings:

  • Modulation type: Random (Per‑Bin Diffusion)
  • Modulation depth: 0.9
  • Randomness amount: 0.8 (high)
  • Cutoff frequency: 18000 Hz

Mechanism: High randomness amount (0.8) dominates over sine component, creating nearly random gain per frequency bin.

Sonic character: Extreme spectral diffusion, almost like spectral scrambling. Can completely transform source material into textured noise.

Best for: Extreme sound destruction, noise art, complete spectral reconstruction.

Preset 12: Pulsing Bands

💓 Rhythmic Spectral Sweeps

Settings:

  • Modulation type: Sawtooth
  • Modulation depth: 0.95
  • Modulation frequency divisor: 150
  • Cutoff frequency: 12000 Hz

Mechanism: Sawtooth creates linear gain increase across frequency, then instant drop. Creates sensation of sweeping filter bands.

Sonic character: Rhythmic, pulsing spectral motion. Like automated filter sweeps repeating across frequency axis.

Best for: Adding rhythmic interest, creating automatic filter modulation effects.

Preset 13: Exponential Sweep

📉 Natural High‑Frequency Roll‑Off

Settings:

  • Modulation type: Exponential Decay
  • Modulation depth: 0.8
  • Modulation frequency divisor: 80
  • Cutoff frequency: 15000 Hz

Mechanism: Exponential decay with divisor=80 creates relatively fast roll‑off starting at moderate frequencies.

Sonic character: Natural‑sounding high‑frequency attenuation. Like gentle low‑pass filtering but with smooth exponential curve.

Best for: Warming up digital sounds, vintage emulation, taming harsh highs.

Preset 14: Musical Phaser (Logarithmic)

🎶 Perceptually Uniform Modulation

Settings:

  • Modulation type: Sine Wave (Logarithmic)
  • Modulation depth: 0.75
  • Modulation frequency divisor: 150
  • Cutoff frequency: 15000 Hz

Mechanism: Sine wave evaluated on logarithmic frequency scale (ln(f)). Creates equal modulation density per octave.

Sonic character: Musically pleasing phasing effect where each octave gets similar treatment. Sounds more "natural" and musical than linear spacing.

Best for: Musical applications, phaser/flanger‑like effects, harmonic enhancement.

Preset Summary Table

PresetMod TypeDepthDivisorCutoffCharacterCategory
Metallic RingSine (Lin)0.910010000Robot voiceMusical
Deep ResonanceSine (Lin)0.954005000Bass emphasisMusical
High ShimmerSine (Lin)0.65020000Treble sparkleMusical
Comb FilterSquare1.020012000Harsh ringingExtreme
Harmonic SeriesExponential0.71008000Warm tiltNatural
Chaotic WobbleRandom0.8510010000Glassy textureExperimental
Dual WaveDual Sine0.7100/25012000Complex beatingComplex
Frequency StairsSawtooth0.830015000Digital steppedDigital
Inverted ValleysSine (Lin)-0.620010000Hollow scoopedPhase‑based
Random CarvingRandom0.910018000Extreme diffusionExperimental
Pulsing BandsSawtooth0.9515012000Rhythmic sweepsRhythmic
Exponential SweepExponential0.88015000Natural roll‑offNatural
Musical PhaserSine (Log)0.7515015000Uniform phasingMusical

Phase Inversion & Safety System

Understanding Phase Inversion

🔄 What Happens When Gain Becomes Negative?

Mathematical representation:

Complex spectrum: X(f) = |X(f)| × e^(i·φ(f))
Gain: G(f) (real number, can be positive or negative)

Output: Y(f) = |X(f)| × G(f) × e^(i·φ(f))

If G(f) > 0: Y(f) = |X(f)|×|G(f)| × e^(i·φ(f))  (phase unchanged)
If G(f) < 0: Y(f) = |X(f)|×|G(f)| × e^(i·(φ(f) + π))  (phase shifted by π)
    

Physical interpretation: Negative gain multiplies the waveform by a negative number, which is equivalent to flipping it upside‑down (180° phase shift).

Sonic consequence: When mixed with other frequency components (some phase‑shifted, some not), destructive interference occurs, creating "hollow", "thin", or "phase‑cancelled" sound. In extreme cases, complete cancellation can occur.

Safety Check Algorithm

# Calculate minimum possible gain: min_gain = modulation_center - abs(modulation_depth) max_gain = modulation_center + abs(modulation_depth) # Check for phase inversion: if min_gain < 0: # Warning triggered Show dialog with gain range information User chooses: Abort or Continue # Example calculations: # 1. center=1.0, depth=0.5 → min=0.5 (positive, no inversion) # 2. center=0.8, depth=1.0 → min=-0.2 (negative, inversion warning) # 3. center=0.5, depth=0.6 → min=-0.1 (negative, inversion warning) # 4. center=1.2, depth=0.3 → min=0.9 (positive, no inversion)

When Phase Inversion is Desirable

Creative uses of phase inversion:
  • Flanger/phaser effects: Classic flangers use phase cancellation to create notches
  • Hollow, scooped sounds: Removing midrange via phase cancellation
  • Extreme sound design: Creating "underwater" or "telephone" effects
  • Comb filtering: Delayed copies create natural phase cancellation at certain frequencies

Why the warning exists: Phase inversion can unintentionally destroy signal coherence, especially on complex sounds like full mixes. The warning ensures users understand they're entering "extreme effect" territory.

Inverted Valleys preset: Interestingly, this preset has center=0.8, depth=-0.6 → min_gain=0.2 (positive), so it shouldn't trigger phase inversion despite the name. The "inverted" refers to the sine wave being "upside‑down" (negative depth) relative to usual, not actual phase inversion.

Disabling the Warning

Set warn_phase_inversion = 0 to bypass the safety check. Useful for:

Warning: Disabling means you won't be alerted if your settings accidentally create phase inversion that might ruin your sound.

Parameters & Controls

Form Parameters

🎛️ User‑Adjustable Settings

ParameterTypeDefaultRangeDescription
presetoptionmenuCustom1‑14Preset configuration (affects multiple parameters)
modulation_typeoptionmenuSine Wave (Linear)1‑9Waveform shape for gain pattern
cutoff_frequencypositive1500020‑sample_rate/2Maximum frequency affected (Hz)
modulation_centerpositive1.00‑10Baseline gain (typically 0.5‑2.0)
modulation_depthpositive0.80‑5Amplitude of waveform variation
modulation_frequency_divisorpositive1501‑1000Scales waveform across frequency (lower=faster)
phase_offsetpositive0.010‑6.28Phase shift of waveform (radians)
second_divisorpositive3001‑1000Second frequency for dual sine interference
randomness_amountpositive0.30‑2Amount of random noise added (for random type)
warn_phase_inversionboolean10/1Show warning if gain becomes negative
scale_peakpositive0.950.1‑1.0Output peak normalization level
play_after_processingboolean10/1Auto‑play result

Parameter Relationships

modulation_frequency_divisor interpretation: • For sine wave: period in Hz = divisor • Example: divisor=100 → waveform repeats every 100 Hz • Number of cycles up to cutoff: cycles = cutoff_frequency / divisor • Small divisor (e.g., 50) → many cycles → dense comb filtering • Large divisor (e.g., 400) → few cycles → broad tonal shaping modulation_center typical values: • 1.0: Unity gain baseline (most common) • 0.5‑0.8: Overall attenuation (darker result) • 1.2‑1.5: Overall boost (brighter result) • <0.5: Significant overall attenuation • >2.0: Significant overall boost (may clip) modulation_depth typical values: • 0‑0.3: Subtle effect • 0.3‑0.6: Moderate effect • 0.6‑0.9: Strong effect • 0.9‑1.2: Extreme effect • >1.2: Very extreme (likely phase inversion) cutoff_frequency guidelines: • Speech: 4000‑8000 Hz (telephone effect range) • Full range: sample_rate/2 (Nyquist) • Bass only: 200‑500 Hz • Treble only: 5000‑15000 Hz

Derived & Internal Variables

VariableSourceDescription
original_srGet sampling frequencyOriginal sound's sample rate
min_gain, max_gaincenter ± |depth|Calculated gain range for safety check
densitydivisor/10 (for log sine)Density parameter for logarithmic spacing
formula$Built based on modulation_typePraat formula applied to spectrum
outName$originalName$ + "_mod"Output sound name

Sonic Applications

Creative Sound Design

🎨 Spectral Transformation Toolkit

Vocal processing:

  • Robot voices: Metallic Ring preset (depth=0.9, divisor=100)
  • Telephone effect: Custom with cutoff_frequency=3500, sine modulation
  • Vocal thickening: Dual Wave Interference for chorus‑like effect
  • Whisper enhancement: High Shimmer to add air and presence

Instrument processing:

  • Guitar/bass: Deep Resonance for added weight
  • Drums: Exponential Sweep to add warmth to kicks
  • Synths: Chaotic Wobble for evolving textures
  • Piano/keys: Musical Phaser for chorusing effect

Music Production

Mix enhancement:

Special effects:

Experimental & Educational

Spectral manipulation demonstrations:

Practical Workflow Examples

🎬 Film: "AI Character Voice Design"

Character: Ancient synthetic intelligence awakening

Voice processing chain:

  1. Base recording: Neutral spoken dialogue
  2. Step 1 - Metallic Ring: Add synthetic quality (depth=0.7, divisor=120)
  3. Step 2 - Dual Wave Interference: Add complexity (depth=0.4, divisors=100/220)
  4. Step 3 - Exponential Sweep: Roll off extreme highs (cutoff=6000)
  5. Step 4 - Subtle Random: Add slight instability (depth=0.2, randomness=0.3)

Result: Synthetic yet ancient‑sounding, complex, slightly unstable AI voice.

🎵 Track: "Spectral Evolution Composition"

Concept: Piece where same motif transforms spectrally over time

Structure:

  • Section A (0:00‑1:00): Clean piano → Harmonic Series (warmth)
  • Section B (1:00‑2:00): Same piano → High Shimmer (sparkle)
  • Section C (2:00‑3:00): Same piano → Chaotic Wobble (breakdown)
  • Section D (3:00‑4:00): Same piano → Random Spectral Carving (destruction)
  • Section E (4:00‑5:00): All versions layered → Musical Phaser (unification)

Thematic: Spectral transformation as musical narrative device.

Advanced Techniques & Customization

Creating Custom Formulas

Modify the formula construction section: Each modulation_type builds a formula string. You can create new types by adding conditions:

# Example: Custom "bell curve" modulation elsif modulation_type = 10 # Gaussian bell curve centered at 1000 Hz formula$ = "if x < " + string$(cutoff_frequency) + " then self * (" + string$(modulation_center) + " + " + string$(modulation_depth) + " * exp(-((x-1000)^2)/(2*500^2))) else self fi" appendInfoLine: "Applied: Gaussian bell curve (centered at 1000 Hz)" # Add to optionmenu in form: # option Bell Curve (Gaussian)

Parameter Automation

Make parameters time‑varying: Process sound in segments with changing parameters:

# Pseudocode for evolving modulation: for segment from 1 to 10 current_depth = 0.1 + 0.8 * (segment/10) # Ramp up current_divisor = 200 - 180 * (segment/10) # Ramp down # Extract segment, process with current parameters # Concatenate results endfor

Combining with Other Processing

Spectral painting chain: Process sound multiple times with different settings:

sound1 = original → Metallic Ring (subtle) sound2 = sound1 → High Shimmer (moderate) sound3 = sound2 → Musical Phaser (subtle) # Creates complex, layered spectral transformation

Hybrid time‑frequency processing: Apply spectral painting, then time‑domain effects:

spectral_painted = original → Spectral Painter with_reverb = spectral_painted → Reverb compressed = with_reverb → Compression # Spectral character preserved through effects chain

Troubleshooting

Problem: Output is completely different from input (extreme transformation)
Causes: modulation_depth too high, extreme modulation_type (square, random)
Solutions: Reduce modulation_depth to 0.3‑0.5, try sine or triangle modulation
Problem: Output has metallic ringing or resonances
Causes: modulation_frequency_divisor too small creating dense comb filtering
Solutions: Increase divisor (200‑400), reduce depth, try exponential/logarithmic types
Problem: Processing is very slow
Causes: Long sounds, high sample rate, complex formula
Solutions: Process shorter segments, reduce sample rate (resample first), simplify formula
Problem: Phase inversion warning appears unexpectedly
Causes: modulation_center too low relative to depth
Solutions: Increase modulation_center (e.g., 1.0), reduce depth, or continue if effect desired