Tzopilotl
Docs
GitHub

Writing SynthDefs

6. Basic Units: fs, T, inlet, outlet, debug

FunctionDescription
fs()The sample rate, as an init-rate signal. Never hard-code 44100/48000 — graphs are compiled independent of the device rate.
T()The sample duration, 1/fs(). The natural increment for phase accumulators: freq * T() is cycles per sample.
inlet(typ, chans = 1, name = "in")Declare an audio input port. typ is a NumType (usually FLOAT32). A synthdef with inlets is an effect: the engine patches other nodes' outputs into it with connect.
outlet(a, name = "out")Declare an output port carrying a. Every synthdef needs at least one; multiple named outlets are allowed. The outlet's channel count is the signal's.
debug(input, label = "debug", period = 4096, consecutive = 1)Periodically dump the signal's value(s) to stderr: every period samples, print the next consecutive samples of all channels with the absolute sample time and label. Returns its input unchanged, so it drops into a pipeline: x debug("x", 1024, 4).
-- A stereo effect: soft-clip whatever is patched in
fn warmth() S {
    let x = inlet(FLOAT32, 2);
    let drive = control("drive", ControlSpec { lo: 1.0, hi: 20.0, init: 2.0, warp: ControlWarp.exponential });
    (x * drive) distort |> outlet
}
↑ Back to top