Hotswapping
Overview
The process of hotswapping
in this context refers to
method used to update patches on-the-fly.
The way it works: there are two subpatches. One subpatch is the one that is running, the other is the one that can be appended to and built up. When that patch is finished, it sends a signal to the audio rendering thread that it is ready to be swapped. The audio rendering thread gets the message, and swaps the subpatches. The subpatch previously running gets reset and becomes the subpatch to write to, and the other patch now becomes the running patch.
Crossfading
With this approach, crossfading is also possible. Crossfading is ideal for hotswapping because to some extent it can prevent audible clicks from occuring. The trick here is to use a counter and defer resetting the old subpatch for the duration of the counter. During this time, both the old and new subpatches are computed, and mixed together based on the counter position and crossfade time.
The hotswapping technique forms the basis for what we would consider as a livecoding environment for music.
Implementation
The working implementation for hotswapping can be found in Monolith 5.2. Hot Swapping. This implementation has a few small constructs on top of graforge, and should be relatively portable.
Monolith uses the monolith_cable
type for hotswapping, one
for reading a patch (the one you hear), and the other for
writing (the one "on deck"). Each monolith has a subpatch
containing the audio graph, it's own allocated audio buffer
for an audio signal. The output cable takes in an input
signal and copies it to the local buffer.