SynthMaker Manual Help Open SynthMaker (opens in a new tab)
Code

Code modules

A Code module is a module you write yourself: a few lines of maths that run for every sample of every note. Read it as code, as a graph of the maths, or both.

Pro: anyone can open any module and read its code, parts list or patch. Writing your own, or changing one, needs SynthMaker Pro. Turning its knobs is free.

New words

A Code module is a module you write yourself: a few lines of maths, run for every sample of every note.

Smooth's inside: its code beside its graph of primitives, and a keyboard below.
Play the keys, then change the maths and play again. Open the example sound: Smooth Pluck ↗ (opens in a new tab)

1Start from code

  1. In the Code view choose + Start from code, or find Start from code under Custom modules in + Add a module.
  2. It goes into the wire to the Output, so you hear it at once: Smooth, a one-pole low-pass.
  3. Open it (or double-click its box) to read and change its code: Code, Graph or Both at the top.
  4. Play and turn Smooth's Cutoff knob down: the sound gets darker. Up: brighter.
  1. Step 1: Choose Code. Code, above the Patch. (larger)
  2. Step 2: + Start from code. Start from code, in the bar above the code. (larger)
  3. Step 3: Smooth joins the last wire. The new line smooth = Smooth(), and smooth in the last wire, into the Output. (larger)
  4. Step 4: Open it: its inside. Acid Starter › Smooth: inside the new module, with Code, Graph and Both. (larger)
The Patch: the Filter into Smooth, a Code module showing its first lines, into the VCA.
Smooth, in the wire after the Filter.
  1. The Code module, with its first lines.

2What the lines mean

  • in x, out y and setting cutoff: 800 Hz, from 20 Hz to 20 kHz are its ports and its knob, as the Patch shows them.
  • setting mode: Low-pass, one of Low-pass, Band-pass, High-pass is a knob that picks one of its names, as a Filter's Mode does. In the maths it's a number: 0 for the first name, 1 for the next. Put a name with a space in quotes: "1 bar".
  • The rest run in order, every sample: name = expression.
  • y' is y one sample ago. That's what makes a filter remember.
  • pi, rate (samples per second) and the voice's freq, gate, velocity and note are there to use.
  • Functions such as sin, exp, log, sqrt, abs, min, max, clamp, wrap and noise(), and if c then a else b for a choice.
  1. Step 1: in x and out y. in x: its input. out y: its output. (larger)
  2. Step 2: setting: a knob. setting cutoff: 800 Hz, from 20 Hz to 20 kHz: a knob and its range. (larger)
  3. Step 3: a, from the cutoff. a = exp(-2 * pi * cutoff / rate): how much of the last value to keep. (larger)
  4. Step 4: y′: one sample ago. y = x + (y' - x) * a: each sample, y moves part of the way from where it was towards x. (larger)

Read the last line as: each sample, start from the new input x and keep a share a of the gap back to where y was. Near 1, y hardly moves, so fast changes (high frequencies) are smoothed away: dark. Near 0, y follows x closely: bright. Take y' away (y = x) and the module just passes the sound through: remembering is what makes a filter.

Smooth · its code
module Smooth  in x  out y  setting cutoff: 800 Hz, from 20 Hz to 20 kHz  a = exp(-2 * pi * cutoff / rate)  y = x + (y' - x) * aend
Smooth's code beside its graph.
Its lines, and the maths they make.

3Code, Graph or Both

Graph draws the maths as boxes: every operator, number, input, setting and output, and y' as a one-sample delay with its feedback wire dashed back. It follows the code as you type. In SynthMaker, choose a box and its code lights; put the cursor in the code and its box is chosen.

The graph of Smooth: -2, π, the cutoff setting and rate multiplied and divided into exp, x and y' into a subtraction and a multiplication, and a dashed orange wire, y → y': one sample later.
The same lines, as a graph.

4Mistakes

A line that can't run turns red, with what's wrong, and the sound keeps its last good version. A Code module with a problem plays silence; the rest of the patch plays on.

You'll seeBecause
I don't know “b” hereA name that isn't an input, a setting, or set by a line.
out y is never setEvery output needs a line that sets it.
y is set twiceEach name is set once per sample: give the second one a new name.
tanh isn't a function SMPL knowsOnly the functions in the maths are there; the message lists them.
The code with the line y = x + (y' - x) * b in red and under it: Line 6: I don't know "b" here (this module has x, y, cutoff, rate); the graph beside it dimmed.
A name the module doesn't have.

Try it

  1. Open Smooth Pluck, then Smooth.
  2. Change the last line to y = x + (y'' - x) * a: two samples ago, a different filter.
  3. Turn its Cutoff knob on Smooth's card and listen.
Open the example sound: Smooth Pluck ↗ (opens in a new tab)

On the Mac, a Code module opens the same way, as Code, Graph or Both.

Remember