Nodes/More Math/Audio math
ComfyUI Node

Audio math

Waveform math with per-sample variables, not just a volume knob

By mcDandy·Created about a year ago·Updated 4 days ago· 5
Audio math
  • V
  • F
  • Expression
  • stack
  • AUDIO
  • STACK
length_mismatcherror
batching0
remember_stackfalse
use_compute_devicetrue

Audio in ComfyUI is a real thing these days, but the stock nodes mostly give you load, save, and maybe a volume control. Audio math from More Math is a full per-sample expression evaluator over your waveforms: mix tracks with a formula, apply an envelope that follows the sample position, build a fade that's a mathematical curve instead of a fixed ramp.

How it works

The node evaluates your expression for every sample of every channel. What makes it worth your time is the audio-specific variables: S is the current sample index, T is the total sample count, R is the sample rate, C is the current channel, N is the channel count, B the batch index. That means a fade-in is literally I0 * (S/T), a pan is I0 * (C - (N-1)/2), and a slow tremolo is I0 * (0.5 + 0.5*sin(2*pi*5*S/R)) - no dedicated modulation nodes needed. All the shared functions apply too: clamp, smoothstep, abs, exp, plus FFT (fft/ifft) for frequency-domain experiments.

The default expression is the pack's a*(1-w)+b*w-style lerp - in the autogrow dialect that's I0*(1-F0)+I1*F0, a crossfade between audio V0 and V1 by float F0.

Inputs and outputs

V is the autogrow list of audio inputs (V0, V1, ...), F the floats, Expression the formula. length_mismatch (error default, plus tile and pad) decides what happens when inputs have different sample counts - the tooltip spells it out: tile repeats the shorter, pad treats missing samples as zero. batching controls frames per pass.

Outputs are AUDIO (a list) and STACK. The audio feeds the usual audio sinks - a save node, or the pack's own spectrogram converter.

Installing it

Standard for the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/mcDandy/more_math
cd more_math
pip install -r requirements.txt

Restart ComfyUI, or grab "More math" from ComfyUI Manager. Dependency is antlr4-python3-runtime on top of torch. No model downloads.

Gotchas

Per-sample evaluation of a long clip is a lot of iterations; keep heavy loops out of the expression and let the vectorized functions do the work. Watch length_mismatch - mixing a 44.1kHz and 48kHz clip hits the default error immediately, and no amount of tile fixes a fundamentally different sample rate. And amplitudes: audio isn't normalized, so I0*2 genuinely doubles the volume and can clip on playback. The pack is new and solo-maintained, so the audio path is early-adopter territory - but for anyone doing generative sound design or sample math, it's the most capable node of its kind in the ecosystem right now.

CategoryMore math

Inputs (8)

NameTypeDefaultDescription
VCOMFY_AUTOGROW_V3
FCOMFY_AUTOGROW_V3
ExpressionSTRING,SYNTAX_TREEV0Expression to apply on weights
length_mismatchCOMBOerrorHow to handle mismatched audio shapes. tile: repeat shorter inputs; error: raise error on mismatch; pad: treat missing samples as zero.
batchingINT0
remember_stackBOOLEANfalseIf enabled, stack is copied at output leading to changes being remembered during batch operations (node runs multiple times in sucession). If disabled each batch gets it's own copy of the stack.
use_compute_deviceBOOLEANtrueTemporarily copies audio tensors to the compute device for math and moves the result back afterwards.
stackoptSTACKAccess stack between nodes

Outputs (2)

NameTypeDescription
AUDIOAUDIO
STACKSTACK