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

The module language

Everything a Code module can say: its inputs, outputs and knobs, what it remembers, and the maths. Three small modules show each idea, and each one plays.

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.

1Inputs, outputs and knobs

The first lines of a Code module say what its box has: in lines are its inputs, out lines its outputs and setting lines its knobs. The lines after them are the maths.

  1. Step 1: in: an input. in freq: 440 Hz: an input, with the value it has when nothing is wired to it. (larger)
  2. Step 2: out: an output. out y: the output. (larger)
  3. Step 3: setting: a knob. setting bright: 0.3, from 0 to 2: a knob and its range. (larger)
  4. Step 4: The box shows them. SineWave in the Patch, with its input, its output and its knob. (larger)
LineMeans
in xAn input. Unwired, it reads 0.
in freq: 440 HzAn input with the value it reads when nothing is wired to it.
out yAn output. A module can have several outputs and several inputs.
setting cutoff: 800 Hz, from 20 Hz to 20 kHzA knob, with its default and its range. Units: Hz, kHz, ms, s, ct, oct, st, or none.
setting mode: Low-pass, one of Low-pass, Band-pass, High-passA knob that picks a name. In the maths it's a number: 0 for the first name, 1 for the next.

In the sound's code the box is used like any module, with its own settings: smooth = Smooth(cutoff: 1.2 kHz). A plain wire goes into its first input and comes out of its first output; name the others with a dot, such as env -> echo.x.

2Remembering: y′, and further back

A name with ' is its value one sample ago, and reading it is what makes a module remember. history keeps a name further back, and y@(n) reads it n samples ago: a delay line. Here an echo is three lines of maths: each sample adds back what y was time seconds ago.

  1. Step 1: history: keep a second. history y: 1 s keeps the last second of y. (larger)
  2. Step 2: y@(n): n samples ago. y = x + feedback * y@(time * rate): the echo reads y from time ago. (larger)
  3. Step 3: busy: still ringing. busy: the voice keeps running while the echo still sounds. (larger)
  4. Step 4: The delay, as a graph. Echo’s graph: y@ is a delay line, fed back. (larger)
The Echo module's inside: its code beside its graph, and a keyboard below.
Play short notes and listen to the repeats. Change time * rate to time * rate / 2: twice as fast. Open the example sound: Code Echo ↗ (opens in a new tab)
WriteMeans
y'y one sample ago.
y''y two samples ago.
history y: 1 s and y@(n)y n samples ago (n can be fractional). history says how far back to keep, up to 10 s.
on note: level = 1When a note starts in this voice, the next sample reads level' as 1.
on start: phase = 0The same, only when the voice starts from silence.
busy: y' > 0.0001 or y' < -0.0001Keeps the voice sounding after its key is let go, while the condition holds: an echo's tail. It may read only remembered values (with ') and numbers.
Echo · a delay line in code
module Echo  # y@(n) is y n samples ago: a delay line. history says how far back to keep.  in x  out y  setting time: 300 ms, from 20 ms to 1 s  setting feedback: 0.5, from 0 to 0.9  history y: 1 s  busy: y' > 0.0001 or y' < -0.0001  y = x + feedback * y@(time * rate)end

3The maths

Every line is name = expression, run in order, every sample. This one bends a sound with soft clipping: d / (1 + abs(d)) gets close to 1 but never past it, and bends gently on the way, so turning Drive up adds warmth before it adds fuzz.

  1. Step 1: drive: a knob. setting drive: 4, from 1 to 30. (larger)
  2. Step 2: Multiply by drive. d = x * drive. (larger)
  3. Step 3: Bend: d / (1 + |d|). y = d / (1 + abs(d)): close to 1, never past it. (larger)
  4. Step 4: The maths as boxes. Soft’s maths as a graph. (larger)
The Soft module's inside: its code beside its graph, and a keyboard below.
Play low notes, then change d = x * drive to d = x * drive * 4: more fuzz. Open the example sound: Soft Drive ↗ (opens in a new tab)
KindYou can write
Arithmetic+ - * /, ^ for powers, parentheses, pi (π and · read too)
Comparisons and logic< <= > >= == !=, and, or, not. True is 1, false is 0.
A choiceif x > 0 then x else 0: always a value, never a jump.
Functionssin cos tan asin exp exp2 log log2 sqrt abs floor, min(a, b), max(a, b), clamp(x, lo, hi), wrap(x) (the part after the point, 0 to 1: a phase), noise() (white noise, −1 to 1, each voice its own)
What the voice knowsfreq (Hz), gate (1 while the key is down), velocity, note, touch, bend, mod
The sample raterate: samples a second
Soft · soft clipping
module Soft  # Soft clipping: x / (1 + |x|) never goes past 1, and bends gently on the way.  in x  out y  setting drive: 4, from 1 to 30  d = x * drive  y = d / (1 + abs(d))end

4An oscillator from scratch

A Code module doesn't need a sound coming in: it can make its own. This one keeps a phase that ramps from 0 to 1, freq times a second (wrap brings it back to 0). The sine of that phase is a sine wave. Bright bends the phase by the wave itself, which adds harmonics as you turn it up.

  1. Step 1: A phase ramps 0 to 1. phase = wrap(phase' + freq / rate): up by freq / rate each sample, back to 0 at 1. (larger)
  2. Step 2: Its sine: a wave. y = sin(2 * pi * phase + bright * sin(2 * pi * phase)). (larger)
  3. Step 3: The phase loops back. The graph: the phase goes round through its one-sample delay. (larger)
The SineWave module's inside: its code beside its graph, and a keyboard below.
Play, then change bright * sin to 3 * sin in the last line: much brighter. Open the example sound: Hand-made Sine ↗ (opens in a new tab)
SineWave · an oscillator in two lines
module SineWave  # A ramp from 0 to 1, freq times a second: the phase. Its sine is a sine wave.  # bright bends the phase by the wave itself: more harmonics as you turn it up.  in freq: 440 Hz  out y  setting bright: 0.3, from 0 to 2  phase = wrap(phase' + freq / rate)  y = sin(2 * pi * phase + bright * sin(2 * pi * phase))end

Try it

  1. Open Code Echo and double-click its Echo box.
  2. Turn Feedback up to 0.9 and play short notes: the repeats last much longer.
  3. In the line busy: y' > 0.0001 or y' < -0.0001, change both 0.0001 to 0.1: once you let go of a key, its echoes stop as soon as they get quiet.
Open the example sound: Code Echo ↗ (opens in a new tab)

Turning Feedback is free. Changing the code needs SynthMaker Pro.

On the Mac, Code modules read and run the same text.

Remember