Math Operations Between Sounds — User Guide
Comprehensive audio signal mathematics: 18 curated presets and 30+ operations for creative mixing, modulation, distortion, and synthesis effects through mathematical combination of two audio signals.
What this does
This script implements mathematical operations between two audio signals — a comprehensive toolkit for sample-by-sample mathematical combination of two sounds. With 18 curated presets and over 30 individual operations across four categories (Basic, Modulation, Non-linear, Advanced), it enables everything from simple mixing to complex synthesis effects, all through mathematical formulas applied to audio waveforms.
Key Features:
- 18 Curated Presets — From clean mixing to extreme sound design
- Four Operation Categories — Basic, Modulation, Non-linear, Advanced transforms
- Priority-Based Processing — Advanced > Non-linear > Modulation > Basic
- Sample-Accurate Math — Mathematical formulas applied to each sample pair
- Automatic Duration Matching — Truncates to shortest sound's length
- Normalization & Scaling — Output level control and peak normalization
- Real-time Preview — Auto-plays result after processing
Technical Implementation: (1) Input validation: Check exactly 2 sounds selected, matching sample rates. (2) Duration matching: Extract equal-length portions from both sounds. (3) Preset logic: 18 presets configure specific operation combinations. (4) Priority system: Advanced transforms override non-linear, which override modulation, which override basic. (5) Formula application: Praat's Formula command applies mathematical expressions to sample arrays. (6) Output processing: Scaling and normalization. (7) Cleanup: Remove temporary objects, select result. Key insight: All audio effects fundamentally reduce to mathematical operations on sample values — this script exposes those operations directly.
Quick start
- In Praat Objects window, select two Sound objects (order matters: Sound1 then Sound2).
- Open script:
math_operations_between_sounds.praat - Choose approach:
- Option A (Presets): Select from 18 curated presets (Clean Add to Rectify Distortion)
- Option B (Custom): Set Preset = "Custom", then configure operations manually
- If using Custom mode, configure four operation categories:
- Basic operation: Add, Subtract, Multiply, etc. (9 options)
- Modulation operation: AM, FM, tremolo, etc. (8 options)
- Non-linear operation: Wavefold, bitcrush, frequency shift, etc. (7 options)
- Advanced operation: Sqrt domain, vector morph, chaotic, etc. (7 options)
- Adjust parameters:
- Modulation_depth: Strength of modulation effects (0.1-5.0)
- Nonlinear_intensity: Intensity of non-linear effects (0.0-2.0)
- Output_scaling: Overall output volume (0.1-5.0)
- Normalize_output: Auto-normalize peak to 0.99 (recommended)
- Click OK — script processes, creates result, auto-plays
- Output named "Sound1_operation_Sound2" appears in Objects window
Signal Math Theory
Digital Audio Fundamentals
📊 Audio as Numerical Arrays
Digital audio representation:
Mathematical operations (sample-by-sample):
Amplitude considerations:
- Addition: Can exceed [-1, 1] range → potential clipping
- Multiplication: Stays within range (product of numbers ≤1)
- Normalization: Scale peak to 0.99 prevents clipping
- DC offset: Operations can introduce DC component
Priority Processing System
🔝 Operation Hierarchy
Four-level priority system:
- Advanced Transforms (highest priority)
- Non-linear Operations
- Modulation Operations
- Basic Operations (lowest priority)
Implementation logic:
Design rationale:
- Prevents conflicting operations: Only one formula applied
- Advanced overrides basic: Complex transforms take precedence
- Clear mental model: User knows which operation will execute
- Preset-friendly: Presets set specific operations without conflict
Example scenario:
- User sets: Basic=Add, Modulation=AM, Non-linear=Wavefold, Advanced=Sqrt
- Only Sqrt domain mix executes (highest priority)
- Other three operations are ignored
- To use multiple effects, chain operations in separate passes
Mathematical Foundations
Amplitude Ranges and Normalization
- Input range: Typically [-1.0, 1.0] for normalized audio
- Operation effects:
- Addition: Can produce [-2.0, 2.0] range
- Multiplication: Produces [-1.0, 1.0] range (product of ≤1 values)
- Non-linear ops: Can exceed original range
- Normalization: Scale peak to 0.99 (just below clipping)
- Output_scaling: Multiply result by this factor before normalization
- Practical tip: Always use normalize_output=1 unless intentionally creating clipped/distorted sound
Presets Gallery
18 Curated Presets
1. Clean Add
Operation: Basic Addition
Effect: Simple mixing of two sounds
Use: Basic audio mixing, layering
Result: s1 + s2
2. Clean Multiply (Ring Mod)
Operation: Basic Multiplication
Effect: Classic ring modulation
Use: Metallic, bell-like tones
Result: s1 × s2
3. Tremolo Effect
Operation: Modulation: Tremolo
Effect: Amplitude modulation
Use: Rhythmic volume changes
Result: s1 × (1 + s2 × 0.5)
4. Crunch Mod (Arctan)
Operation: Modulation: Arctan
Effect: Soft clipping distortion
Use: Warm overdrive, saturation
Result: (2/π) × arctan(s1 × s2 × 20)
5. FM Synthesis
Operation: Modulation: FM-like
Effect: Frequency modulation simulation
Use: Synthetic, complex timbres
Result: sin(s1 × 5π) × s2
6. Double FM
Operation: Modulation: Double FM
Effect: Dual sine modulation
Use: Complex metallic tones
Result: sin(s1 × 7.5π) × sin(s2 × 7.5π)
7. Wavefold Distortion
Operation: Non-linear: Wavefold
Effect: Aliasing/foldover distortion
Use: Digital grit, bit-reduction
Result: fold(s1 + s2, threshold=1.3)
8. Bitcrush Lo-Fi
Operation: Non-linear: Bitcrush 8-bit
Effect: 8-bit quantization
Use: Lo-fi, retro video game sounds
Result: round((s1 + s2) × 8) ÷ 8
9. Frequency Shifter
Operation: Non-linear: Freq shift sim
Effect: Pitch shifting illusion
Use: Unnatural pitch effects
Result: s1 × cos(2π × s2 × 120)
10. Hard Sync
Operation: Non-linear: Hard sync sim
Effect: Oscillator sync simulation
Use: Aggressive synth tones
Result: Hard sync algorithm
11. Chaotic Mix
Operation: Advanced: Logistic chaos
Effect: Chaotic system behavior
Use: Unpredictable, evolving textures
Result: (s1 + s2) × (3.5 - 3.5 × |s1| × |s2|)
12. Spectral Blur
Operation: Non-linear: Soft normalize mix
Effect: Spectral averaging, blurring
Use: Smearing, time-stretching effect
Result: (s1 + s2) ÷ (1 + 0.8 × (|s1| + |s2|))
13. Phase Vocoder-like
Operation: Advanced: Pseudo phase-vocoder
Effect: Phase manipulation simulation
Use: Time-stretch/pitch-shift effects
Result: s1 × cos(50π × s2) + s2 × sin(50π × s1)
14. Granular Scatter
Operation: Advanced: Random scatter
Effect: Randomized mixing
Use: Granular texture effects
Result: (s1 + s2) × (0.8 + 0.4 × random)
15. Sqrt Domain
Operation: Advanced: Sqrt domain mix
Effect: Square root compression
Use: Dynamic range compression
Result: √|s1| × √|s2| × 10
16. Vector Morph
Operation: Advanced: Vector morph
Effect: Linear crossfade/morphing
Use: Smooth transitions between sounds
Result: s1 × 0.5 + s2 × 0.5
17. Rectify Distortion
Operation: Advanced: Rectify & mix
Effect: Full-wave rectification
Use: Distortion, octave effects
Result: |s1| - |s2|
18. Custom (manual settings)
Operation: User-defined combination
Effect: Whatever you configure
Use: Experimental exploration
Result: Based on your settings
Preset Selection Guide
| Desired Effect | Recommended Preset | Notes |
|---|---|---|
| Simple mixing | Clean Add (1) | Basic audio combination |
| Metallic/robotic | Clean Multiply (2) | Classic ring modulation |
| Rhythmic pulsing | Tremolo Effect (3) | Use rhythmic sound as s2 |
| Warm distortion | Crunch Mod (4) | Arctan soft clipping |
| Synthetic tones | FM Synthesis (5) | FM-like timbres |
| Digital grit | Bitcrush Lo-Fi (8) | 8-bit quantization |
| Pitch effects | Frequency Shifter (9) | Unnatural pitch shifts |
| Evolving textures | Chaotic Mix (11) | Unpredictable behavior |
| Smooth transitions | Vector Morph (16) | Linear crossfade |
| Distortion/octaves | Rectify Distortion (17) | Full-wave rectification |
Operations Guide
Basic Operations (9 Options)
➕ Basic Arithmetic
| Operation | Formula | Effect | Notes |
|---|---|---|---|
| Add (+) | s1 + s2 | Simple mixing | Can clip, use normalization |
| Subtract (-) | s1 - s2 | Difference, phase cancellation | Can create nulls when similar |
| Multiply (*) | s1 × s2 | Ring modulation | Classic metallic/robotic effect |
| Divide (/) | s1 ÷ (s2 + ε) | Ratio, extreme dynamics | ε=1e-10 prevents divide-by-zero |
| Average | (s1 + s2) ÷ 2 | Equal mix | Same as Add then halve |
| Minimum | min(s1, s2) | Lower envelope | Keeps minimum of each sample pair |
| Maximum | max(s1, s2) | Upper envelope | Keeps maximum of each sample pair |
| Absolute difference | |s1 - s2| | Magnitude of difference | Always positive, rectified |
| XOR-like | sign-based mixing | Phase-aware mixing | Mixes magnitudes, inverts when signs differ |
Use cases:
- Add/Average: Basic audio mixing
- Multiply: Ring modulation for metallic sounds
- Subtract: Phase cancellation, noise reduction
- Min/Max: Envelope extraction, gating
- Absolute diff: Change detection, novelty
Modulation Operations (8 Options)
📡 Modulation Effects
| Operation | Formula | Effect | modulation_depth |
|---|---|---|---|
| AM: sin(S2) | s1 × (0.5 + 0.5×sin(s2×10π×depth)) | Amplitude modulation with sine | Controls modulation frequency |
| AM: cos(S2) | s1 × (0.5 + 0.5×cos(s2×10π×depth)) | AM with cosine (90° phase shift) | Same as above, different phase |
| FM-like: sin(S1)×S2 | sin(s1×5π×depth) × s2 | Frequency modulation simulation | Controls modulation index |
| FM-like: cos(S1)×S2 | cos(s1×5π×depth) × s2 | FM with cosine carrier | Different harmonic structure |
| Double FM | sin(s1×5π×depth) × sin(s2×5π×depth) | Dual sine modulation | Complex metallic tones |
| Soft clip: tan | (2/π)×arctan(s1×s2×10×depth) | Arctan soft clipping | Distortion amount |
| Power mod | sign(s1)×|s1|^(1+s2×depth) | Dynamic waveshaping | Exponent control |
| Tremolo | s1 × (1 + s2×depth) | Simple amplitude modulation | Tremolo depth |
Parameter guidance:
- modulation_depth = 0.5: Subtle modulation
- modulation_depth = 1.0: Standard modulation
- modulation_depth = 2.0: Strong modulation
- modulation_depth = 5.0: Extreme modulation (may alias)
Non-linear Operations (7 Options)
🌀 Non-linear Transformations
| Operation | Description | Effect | nonlinear_intensity |
|---|---|---|---|
| Freq shift sim | s1 × cos(2π×s2×100×intensity) | Pitch shifting simulation | Shift amount |
| AM depth control | s1 × (1 + s2×intensity) | Dynamic AM depth | Depth modulation |
| Wavefold | Fold s1+s2 at threshold | Aliasing/foldover distortion | Folding threshold |
| Hard sync sim | Oscillator sync simulation | Aggressive synth reset | Sync strength |
| Bitcrush 8-bit | round((s1+s2)×8) ÷ 8 | 8-bit quantization | Fixed (not used) |
| Vector crossfade | s1×(1-i×|s2|) + s2×i | Amplitude-dependent crossfade | Crossfade amount |
| Soft normalize mix | (s1+s2) ÷ (1+i×(|s1|+|s2|)) | Automatic gain control | Compression amount |
Technical details:
- Wavefold: Creates foldover distortion when sum exceeds threshold
- Bitcrush: 8-bit = 256 levels (round to nearest 1/8)
- Hard sync: When |s2| > |s1|×intensity, reset to s2's sign
- Soft normalize: Divides by sum of magnitudes, prevents clipping
Advanced Operations (7 Options)
🚀 Advanced Transforms
| Operation | Formula | Effect | Mathematical Basis |
|---|---|---|---|
| Sqrt domain mix | √|s1| × √|s2| × 10 | Square root compression | Dynamic range reduction |
| Exp domain mix | exp(ln|s1| + ln|s2|) × 0.1 | Logarithmic mixing | Multiplicative in log domain |
| Vector morph | s1×(1-d) + s2×d | Linear interpolation | Vector space morphing |
| Logistic chaos | (s1+s2)×(3.5-3.5×|s1|×|s2|) | Chaotic system | Logistic map variation |
| Rectify & mix | |s1| - |s2| | Full-wave rectification | Absolute value difference |
| Pseudo phase-vocoder | s1×cos(50π×s2) + s2×sin(50π×s1) | Phase manipulation | Trigonometric recombination |
| Random scatter | (s1+s2)×(0.8+0.4×random) | Randomized gain | Stochastic process |
Advanced concepts:
- Domain transforms: Change mathematical domain (linear→sqrt→log)
- Chaotic systems: Simple logistic map creates unpredictable behavior
- Phase manipulation: Simulates phase vocoder time-stretching
- Vector operations: Treat samples as vectors in n-dimensional space
Operation Categories
Category 1: Basic Arithmetic
🔢 Linear Operations
Characteristics:
- Linearity: f(a×s1 + b×s2) = a×f(s1) + b×f(s2)
- Predictability: Output directly proportional to inputs
- Simplicity: Easy to understand mathematically
- Range effects: Addition can exceed [-1,1], multiplication stays within
Audio effects:
- Add/Subtract: Mixing, phase cancellation
- Multiply: Ring modulation (sum/difference frequencies)
- Min/Max: Envelope following, gating
- Average: Equal-power mixing
Mathematical properties:
Category 2: Modulation Operations
📻 Signal Modulation
Core concept: Use one signal to modify parameter of another
Types of modulation:
- AM (Amplitude Modulation): Carrier amplitude varied by modulator
- FM (Frequency Modulation): Carrier frequency varied by modulator
- Tremolo: Low-frequency AM (typically < 20Hz)
- Waveshaping: Non-linear function applied to signal
Mathematical forms:
Sidebands creation:
- AM: Creates carrier ± modulator frequencies
- FM: Creates infinite sidebands at carrier ± n×modulator
- Ring modulation: Creates sum and difference frequencies (no carrier)
Category 3: Non-linear Operations
⚡ Non-linear Transformations
Core concept: Operations that don't satisfy superposition principle
Characteristics:
- Non-linearity: f(a×s1 + b×s2) ≠ a×f(s1) + b×f(s2)
- Harmonic generation: Creates new frequencies not in input
- Memoryless: Output at time t depends only on input at time t
- Waveshaping: Apply function f(x) to signal
Common non-linear functions:
Harmonic distortion:
- Symmetrical non-linearity: Creates odd harmonics
- Asymmetrical non-linearity: Creates even and odd harmonics
- Quantization: Creates harmonic distortion + noise
- Wavefolding: Creates aliasing/foldover distortion
Category 4: Advanced Transforms
🧮 Advanced Mathematical Operations
Core concept: Complex mathematical transformations beyond basic signal processing
Types of transforms:
- Domain changes: Square root, logarithmic, exponential domains
- Vector operations: Treat signals as vectors, apply linear algebra
- Chaotic systems: Simple deterministic chaos
- Stochastic processes: Introduce randomness
- Phase manipulation: Simulate phase vocoder operations
Mathematical foundations:
Audio effects:
- Dynamic range compression: Square root/logarithm
- Morphing: Vector interpolation between sounds
- Texture generation: Chaotic systems create evolving sounds
- Granular effects: Randomized mixing
Applications
Sound Design & Synthesis
Use case: Create new timbres from existing sounds
Techniques:
- Ring modulation: Multiply voice with sine tone for robotic effect
- FM synthesis: Use one sound to modulate another's "frequency"
- Waveshaping: Apply non-linear functions for distortion/saturation
- Bitcrushing: Add lo-fi digital grit
Example workflow:
- Sound1: Vocal recording
- Sound2: 100Hz sine tone (create in Praat)
- Preset: Clean Multiply (ring modulation)
- Result: Robotic, metallic vocal effect
- Variation: Try different modulator frequencies (50Hz, 200Hz, 440Hz)
Audio Effects Processing
Use case: Create custom audio effects through mathematical combination
Effect types:
- Tremolo: Use low-frequency oscillator (LFO) as Sound2
- Amplitude modulation: Modulate with audio-rate signal
- Distortion: Arctan or wavefold for saturation
- Frequency shifting: Cosine modulation creates pitch illusion
Practical example - Tremolo:
Experimental Composition
Use case: Algorithmic music creation through mathematical operations
Techniques:
- Chaotic systems: Create evolving, unpredictable textures
- Vector morphing: Smooth transitions between sound objects
- Random processes: Introduce controlled randomness
- Phase manipulation: Create time-stretch-like effects
Composition strategy:
- Create sound palette (6-8 source sounds)
- Systematically combine using different operations
- Vary operation parameters over time (multiple script runs)
- Layer results for complex textures
- Use output as material for further processing
Audio Restoration & Analysis
Use case: Extract information through mathematical comparison
Techniques:
- Difference: Subtract reference from recording to isolate changes
- Absolute difference: Magnitude of change (always positive)
- Minimum/Maximum: Extract envelope characteristics
- Division: Ratio analysis between signals
Example - Noise reduction analysis:
Educational Demonstrations
Use case: Teach digital audio and signal processing concepts
Learning objectives:
- Basic arithmetic: Show how addition/multiplication affect audio
- Modulation: Demonstrate AM, FM, ring modulation
- Non-linearity: Show harmonic generation through distortion
- Domain transforms: Demonstrate dynamic range compression
- Phase effects: Show cancellation with subtraction
Classroom exercise:
- Create two simple sine waves at different frequencies
- Try all basic operations, listen to results
- Explain frequency domain effects (sum/difference tones)
- Move to more complex sounds, explore non-linear operations
- Discuss musical/sound design applications
Practical Example Configurations
🎤 Vocal Processing Chain
Goal: Transform dry vocal into textured, effected sound
Step 1 - Add warmth:
- Sound1: Dry vocal
- Sound2: Low sine tone (80Hz, amplitude 0.3)
- Operation: Add
- Effect: Adds bass warmth
Step 2 - Add modulation:
- Take result from Step 1
- Sound2: 0.5Hz sine (LFO)
- Preset: Tremolo Effect (depth=0.3)
- Effect: Subtle amplitude modulation
Step 3 - Add grit:
- Take result from Step 2
- Sound2: White noise (low amplitude)
- Preset: Crunch Mod (depth=0.5)
- Effect: Subtle distortion/saturation
🎹 Synthetic Texture Creation
Goal: Create evolving pad sound from simple sources
Sources:
- Sound1: 220Hz sine wave (A3)
- Sound2: 277Hz sine wave (C#4)
Process:
- First pass: Preset = Double FM (creates metallic tones)
- Second pass: Take result + new 329Hz sine (E4), Preset = Vector Morph (creates evolving mix)
- Third pass: Take result + filtered noise, Preset = Spectral Blur (adds texture)
- Final: Three-layer composite creates rich, evolving pad
🔊 Drum Processing
Goal: Add punch and character to drum loop
Technique 1 - Parallel compression:
- Sound1: Original drum loop
- Sound2: Compressed version of same loop
- Operation: Add (parallel compression)
- Adjust output_scaling to control blend
Technique 2 - Bitcrush effect:
- Sound1: Drum loop
- Sound2: Same loop at lower amplitude (0.3)
- Preset: Bitcrush Lo-Fi
- Result: Drums with lo-fi grit blended in
Technique 3 - Rhythmic gating:
- Sound1: Drum loop
- Sound2: Rhythmic pulse (e.g., 16th notes)
- Operation: Multiply (ring modulation)
- Result: Rhythmically gated drums
Complete Workflow
Step-by-Step Script Execution
🔧 Processing Pipeline
Phase 1: Input Validation
Phase 2: Preset Logic
Phase 3: Duration Matching
Phase 4: Mathematical Processing
Phase 5: Post-Processing
Phase 6: Cleanup & Finalization
Sound Selection Strategies
| Desired Effect | Sound1 (Carrier/Base) | Sound2 (Modulator/Effect) | Recommended Operation |
|---|---|---|---|
| Robotic voice | Speech | Sine tone (100-300Hz) | Multiply (Ring Mod) |
| Tremolo | Any audio | Low sine (1-10Hz) | Tremolo (modulation) |
| Metallic texture | Complex sound | High sine (1000Hz+) | Double FM |
| Lo-fi effect | Clean audio | Noise or same audio | Bitcrush |
| Phase cancellation | Recording | Same recording shifted | Subtract |
| Dynamic morph | Sound A | Sound B | Vector Morph |
| Warm distortion | Audio source | Same audio (louder) | Crunch Mod (Arctan) |
Troubleshooting Common Issues
Causes: 0, 1, or 3+ sounds selected
Solutions: • Select exactly 2 Sound objects
• Check Objects window selection count
• Use Ctrl+click to select multiple in Praat
Causes: Sounds have different sample rates (e.g., 44100Hz vs 48000Hz)
Solutions: • Resample one sound to match the other
• Use Praat's Convert → Resample...
• Choose common rate (e.g., 44100Hz for both)
Causes: Priority system, operation override, parameter issues
Solutions: • Check priority: Advanced > Non-linear > Modulation > Basic
• If advanced operation selected, others ignored
• Verify operation parameters (depth, intensity)
• Try preset first to confirm script works
Causes: Amplitude exceeded range, no normalization
Solutions: • Enable normalize_output (default is on)
• Reduce output_scaling (try 0.5 instead of 1.0)
• Use non-linear operations that stay in range (multiply, bitcrush)
• For addition, ensure input amplitudes are low (e.g., 0.5 each)
Causes: Phase cancellation, division by large values, low output_scaling
Solutions: • For subtraction: Similar sounds can cancel
• For division: Divisor may be large → small result
• Check output_scaling (increase to 2.0-5.0)
• Try different sound pairings
Advanced Workflow: Chaining Operations
Example: Rich modulated texture:
Workflow tips:
- Save intermediate results: Rename clearly (e.g., "step1_FM", "step2_addNoise")
- Vary parameters: Use different modulation_depth values each pass
- Combine operation types: Linear + non-linear + modulation
- Use normalization: Each pass can normalize to maintain level
- Experiment systematically: Document settings for reproducible results