Nodes/ComfyUI-AudioReactive/Quantize (Audio Op)
ComfyUI Node

Quantize (Audio Op)

Quantize — bucket a signal into k discrete levels with k-means (stub warning)

By dmarx·Created 3 years ago·Updated 2 years ago· 11
Quantize (Audio Op)
  • signal
  • SIGNAL

OpQuantize (display name "Quantize (Audio Op)") is supposed to snap a continuous signal into a small set of discrete levels - "quantize to 4 steps" - using k-means clustering. The source is one of the more interesting things in the pack: it takes the nonzero values, runs sklearn.cluster.KMeans over them, and replaces every value with the centroid of its cluster. Result: the smooth analog curve becomes a staircase of k distinct heights.

Why would you want a staircase? Because stepped animation reads as designed rather than organic. If your audio-reactive parameter glides, it feels like a VU meter; if it jumps between a few clean levels, it feels like a sequencer - punchy, gated, techno. Quantizing an RMS or onset curve before it hits your animation driver is a legit aesthetic choice, and the author even left a note that they considered k-medoids (more robust to outliers) instead of k-means means. It was ChatGPT-generated code, and the comment says so.

Here's the honest part: the node doesn't work yet. Same wrapper disease as Bandpass, Clamp, Modulo, Pow, Smooth, and Sustain.

What's actually going on

quantize is a factory - quantize(k=1) returns a function that does the clustering. The node wrapper calls every operator as f(y, sr), so it calls quantize(y, sr) with the signal as k. That doesn't quantize anything; it returns a closure parked in the SIGNAL's y slot, and the pack happily passes that function object downstream until real math throws a TypeError. The info_schema confirms it: only a signal input, no k. Unusable as shipped.

What to do instead

  • If a workflow has "Quantize (Audio Op)" in it, it's broken; route around it.
  • Want stepped animation today? Take a feature curve (Rms, Novelty) through SignalToCurve and snap to levels in the curve/keyframe domain - most scheduler tooling has step/hold modes that give you the same aesthetic with way less math.
  • Watch the repo. The backend is a complete idea; it needs a k input wired to the wrapper. Also note the dependency it'd pull when it lands: it uses scikit-learn, which is already in the pack's auto-install list.

Inputs and outputs

As shipped:

  • signal (SIGNAL) - in.
  • SIGNAL - out, containing a function object, not a quantized curve. Don't build on it.

Installing it

Manager (search "AudioReactive") or:

cd ComfyUI/custom_nodes
git clone https://github.com/dmarx/ComfyUI-AudioReactive

Restart and let the first-load auto-install of scipy, scikit-learn, librosa, loguru finish (scikit-learn is what k-means needs, and librosa brings numba). ModuleNotFoundError: No module named 'keyframed' on load → pip install keyframed.

The takeaway

Quantize is a fun idea wrapped in a broken shell - emblematic of this pack being a fresh, single-commit port of dmarx's video-killed-the-radio-star notebook. Build on the working operators; treat the parameterized family as placeholders until the wrappers get finished. Skim nodes/audio_utils.py to see which is which at a glance.

CategoryAudioReactive/Operators

Inputs (1)

NameTypeDefaultDescription
signalSIGNAL

Outputs (1)

NameTypeDescription
SIGNALSIGNAL