home/ atoms/ nn-tilde-source-separation-scripting

A deep source separation model can be wrapped in nn~ to split live audio into stems in real time

The unmix.py scripting example shows how to wrap an existing pre-trained source separation model (e.g. Open-Unmix) into a nn~ method. The wrapper class (Unmix) loads a pretrained TorchScript model, registers a single ‘forward’ method with 1 input channel and 4 output channels (drums, bass, vocals, others), then delegates inference to the pretrained model. A preprocess() helper resamples and reshapes audio to match the model’s expected sample rate and channel format (including duplicating mono to stereo). The result is a Max/Pd object that takes a mono audio signal and outputs four parallel stems, enabling live use cases like stem-specific effects or reactive visuals per stem.

Examples

In Max: nn~ unmix.ts forward 8192 with 1 inlet and 4 outlets. Route the bass outlet to a sub-filter and the drums outlet to a transient shaper, all in real time from a single input signal.

Assessment

Explain why the preprocess() function is needed even when the input is already mono audio. What is the role of out_channels=4 in register_method? Design a Max patch using this model that applies different reverb to each stem.

“unmix.py : Advanced scripting example for integrating a deep waveform-to-waveform model. # # We provide here a simple example of how to use nn~ in order to transform incoming audio.”
corpus · nn-nn-tilde-run-rave-neural-models-live-in-max-msp-and-pure · chunk 35