home/ modules/ deploying-neural-audio-into-max-and-pd

Deploying Neural Audio Models into Max/MSP and Pure Data

  • learner can load a TorchScript model as an nn~ object and route audio through its methods
  • learner can export RAVE for nn~/VST and control it live via attributes and latent splitting
  • learner can reason about circular-buffer latency and waveform-to-waveform pass-through

Build a Max/MSP (or PD) patch that runs your exported RAVE model live: load the .ts via nn~, split encode/decode to manipulate individual latent dimensions in performance, expose model attributes as live controls, and document the circular-buffer size you chose, the latency it adds, and how the forward path behaves as a waveform-to-waveform effect. Also demonstrate the same model as a RAVE VST in a DAW.

This module crosses the gap that stops most people who train a RAVE model: getting it out of Python and onto a stage. The whole task is a performance-ready Max/MSP or Pure Data patch where your own timbre model runs live — the setting is an improvised electronic set where you sing or play into the model and sculpt its output in real time, with the same model doubling as a VST insert in a DAW session. TorchScript is the lingua franca here: understanding why a .ts file needs no Python is what makes the whole deployment story make sense.

The arc starts fully supported. First, install nn~ and load a pre-trained model (see “nn~ is a Max/PureData external that bridges trained neural audio models”) and get sound through the default forward path (“The forward method runs a neural model as an audio effect”) — a waveform-to-waveform pipe, audio in and audio out of the same length. Then swap in your own exported model, and open the hood: replace forward with separate encode/decode so the latent dimensions appear as signal outlets you can slider, LFO, and cross-fade (“Splitting RAVE encode and decode in nn~”). Add attribute messages for live control, then make a deliberate engineering choice — buffer size versus latency — which you must document in the capstone.

Every required atom gates that patch: methods, attributes, the circular buffer, waveform-to-waveform pass-through, and the VST workflow are each exercised directly. Supporting atoms widen the picture — the in_ratio/out_ratio contract that explains why latents run slower than audio, hot-swapping models mid-set with void mode, pre-trained model packs, offline batch generation, and ONNX as an alternative export — useful, but the capstone stands without them.

Runnable examples

Generated from the context/ instrument corpus by concept (redistributable idioms only). Do not edit — regenerate with gen-module-examples.mjs.

live-hot-swap

live_loop :x do; play 60; sleep 1; end

sonicpi-0048 · CC0

Ndef(\a, { SinOsc.ar(220) * 0.1 }).play

supercollider-0037 · CC0

Atoms in this module

Required — these gate the capstone

nn~ is a translation layer that runs any TorchScript (.ts) model as a live Max/MSP or Pure Data object
Concept L2 First instrument KN
nn~ is a Max/PureData external that bridges trained neural audio models (RAVE, vschaos2) into a patching environment
Procedure L3 Craft KN
nn~ exposes RAVE encode, decode, and forward as Max/MSP or Pure Data audio-rate methods
Procedure L2 First instrument KN
Splitting RAVE encode and decode in nn~ lets performers process individual latent dimensions live
Procedure L3 Craft KM
A nn~ model's methods each define a distinct processing pipeline with its own inlet/outlet count
Concept L2 First instrument KN
The forward method runs a neural model as an audio effect: audio in, neural-transformed audio out
Procedure L3 Craft KB
nn~ model attributes are model-defined, live-controllable parameters set via 'set NAME VALUE' messages
Concept L2 First instrument KN
nn~'s circular buffer amortizes neural model compute across time, at the cost of added latency
Concept L2 First instrument KN
Waveform-to-waveform nn~ models have equal in_ratio and out_ratio and pass audio through uncompressed
Concept L2 First instrument KN
The RAVE VST loads a .ts model in any DAW as an audio effect that re-timbres incoming audio
Procedure L2 First instrument KNM
TorchScript (.ts) files are the portable, runtime-independent format for deploying PyTorch models without Python
Concept L2 First instrument KN

Supporting — enrichment, not gating

in_ratio and out_ratio in nn~ method registration define the temporal compression between audio and model outputs
Concept L3 Craft KN
nn~'s void/lazy mode lets you fix inlet/outlet count before attaching a model
Concept L3 Craft KN
Pre-trained RAVE streaming models are available for immediate use without training
Fact L1 Foundations KN
RAVE's generate script applies a model to large collections of audio files offline in batch mode
Procedure L2 First instrument K
RAVE can be exported to ONNX format for deployment in environments that do not support TorchScript
Fact L3 Craft KN