3. The voice

I. From a sound to a voice

The voice

A note plays each sample its keygroups give it on a voice: one of the sixteen the sampler's channels share. The voice reads the sample at the note's pitch, faster or slower than it was recorded, and then shapes it as a synthesizer's voice shapes an oscillator: through a filter with an envelope of its own, an amplifier with another, and an LFO that moves the pitch, the cutoff, and the level. Most of what's on the program page is here. The voice's last trick is the S900's: playing a sample at twelve bits.

Open the window on the chapter's first song, a piano note climbing four octaves:

zig build run-studio -- manual/sampler/03-voice/sweep --view device

Reading between the frames

20 50 100 200 500 1k 2k 5k 10k 20k 0 1 2 3 4 5 6 7 8 s −100 0 dB two octaves up three and a half up −40 −50 −60 −70 −80 −90 −100 −110 −120 20 50 100 200 500 1k 2k 5k 10k 20k

0.0 / 8.0 s

peak -1.6 dBFS

Fig. 3.1 The piano's C5, looped, played on C7 while tune climbs from −24 to 24 semitones in eight seconds: from the sample's root to four octaves above it. Up to two octaves, at 4 seconds, every line rises and fades before the top. Past them, lines fold back and fall from the top, in view from about 6 seconds, crossing the rising ones. The spectra are two moments of it, two octaves up and three and a half: look past 20 kHz, and between the partials.

openzig build run-studio -- manual/sampler/03-voice/sweep

renderzig build run-studio -- render manual/sampler/03-voice/sweep sweep.wav

sweep/song.json
{
  "tempo": 120,
  "end": "5",
  "devices": [{
    "name": "S1000",
    "type": "sampler",
    "state": {
      "channels": [{ "channel": 1, "program": 1 }],
      "programs": [{
        "program": 1,
        "name": "sweep",
        "sound": { "tune": -24, "release": 0.05 },
        "keygroups": [{ "keys": "C-1 G9", "zones": [{ "sample": "C5" }] }]
      }],
      "samples": {
        "C5": {
          "file": "SalamanderGrandPianoV3_48khz24bit/48khz24bit/C5v16.wav", "root": "C5",
          "mode": "in_release", "loops": ["48000 96000 24000 hold"]
        }
      }
    }
  }],
  "tracks": [{
    "name": "piano",
    "device": "S1000",
    "channel": 1,
    "clips": [{ "at": "1", "length": "4.0.0", "notes": "held" }],
    "lanes": { "tune": ["1 -24 linear", "5 24"] }
  }],
  "notes": {
    "held": { "length": "4.0.0", "notes": ["1.1.0 C7 3.3.0 127"] }
  }
}

Played on a key other than its root, a sample is read at another rate: an octave up, two frames for each the output plays, and a semitone up, a little over one. Between the recorded frames, the voice has to work out what the wave was, and how it does it decides what the note sounds like far from its root.

Played higher, every partial of the recording rises with it, and those pushed above half the output's sample rate, 24 kHz, can't be played. A reader that ignores them folds them back down, as aliases: partials that fall as the note rises, out of tune with everything. The plan for the sampler started it on 4-point Hermite interpolation, a common choice, and measured it on a sample of every harmonic of 1234.5 Hz: its loudest alias was 24 dB under the fundamental an octave up, 18 dB two octaves up, and 36 dB an octave down, plainly heard (sampler/voice.zig).

So the voice reads through a windowed sinc: each output frame is a sum of the recorded frames around it, each weighted by the sinc function times a Kaiser window, 12 zero crossings to each side. The sinc is a low-pass filter too, and its cutoff is set where nothing can fold: at 0.88 of the highest frequency the sound's own rate holds, and above the root, falling as the pitch rises, so it takes away whatever would land past 21 kHz before it gets there. In the spectrogram the partials climb and fade before they reach the top, because the cutoff stays just below it. The tests measure it on the same sample of every harmonic: from an octave below the root to two above, no alias comes within 70 dB of the fundamental (sampler/tests.zig). Two octaves below the root, this piano note has nothing above 5 kHz within 107 dB of its loudest partial.

The cutoff falls with the pitch only so far: to a quarter of where it starts, two octaves up, where the sinc already reads four times as many frames as at the root. Past it, what's above the cutoff folds. The first lines fold just under 24 kHz, above what the plot shows, and fall as the note rises; from about three octaves up they cross the rising partials, and the note sounds sour. In the spectra, the note in the 0.4 s before it reaches two octaves up has nothing above 21.5 kHz within 98 dB of its loudest partial; three and a half octaves up, what folded fills that band 46 dB down, and the floor between the partials below rises with it. A sample meant to play more than two octaves above its root wants a keygroup of its own, with a sample recorded higher. At its root, on a file at the output's 48 kHz, the voice reads each frame as it is.

The filter

open cutoff 1 kHz and resonance 80% −20 −30 −40 −50 −60 −70 −80 −90 −100 20 50 100 200 500 1k 2k 5k 10k 20k

0.0 / 6.0 s

peak -1.0 dBFS

Fig. 3.2 The same two seconds of the sea three times: with the filter open, closed to 1 kHz, and closed to 1 kHz with resonance at 80%. Listen for the surf losing its hiss, then gaining a whistle at the cutoff.

openzig build run-studio -- manual/sampler/03-voice/filter

renderzig build run-studio -- render manual/sampler/03-voice/filter filter.wav

filter/song.json
{
  "tempo": 120,
  "end": "4",
  "devices": [{
    "name": "S1000",
    "type": "sampler",
    "state": {
      "channels": [
        { "channel": 1, "program": 1 },
        { "channel": 2, "program": 2 },
        { "channel": 3, "program": 3 }
      ],
      "programs": [
        { "program": 1, "name": "open",
          "keygroups": [{ "keys": "C-1 G9", "zones": [{ "sample": "sea" }] }] },
        { "program": 2, "name": "1 kHz", "sound": { "cutoff": 1000 },
          "keygroups": [{ "keys": "C-1 G9", "zones": [{ "sample": "sea" }] }] },
        { "program": 3, "name": "1 kHz resonant", "sound": { "cutoff": 1000, "resonance": 80 },
          "keygroups": [{ "keys": "C-1 G9", "zones": [{ "sample": "sea" }] }] }
      ],
      "samples": {
        "sea": { "file": "sea/sea-waves.wav", "root": "C4", "start": 504000, "end": 600000 }
      }
    }
  }],
  "tracks": [
    { "name": "open", "device": "S1000", "channel": 1, "clips": [{ "at": "1", "length": "1.0.0", "notes": "wave" }] },
    { "name": "1 kHz", "device": "S1000", "channel": 2, "clips": [{ "at": "2", "length": "1.0.0", "notes": "wave" }] },
    { "name": "resonant", "device": "S1000", "channel": 3, "clips": [{ "at": "3", "length": "1.0.0", "notes": "wave" }] }
  ],
  "notes": {
    "wave": { "length": "1.0.0", "notes": ["1.1.0 C4 0.3.480 127"] }
  }
}

The filter is a low-pass of 18 dB an octave, as the S1000's was: a two-pole state-variable filter and a one-pole after it. cutoff sets where it starts, from 30 Hz to 20 kHz, where it's open. At the cutoff the sea here is 9 dB down, and each octave above it about 18 dB further: 21 dB at 2 kHz, 37 dB at 4 kHz, 56 dB at 8 kHz. resonance lifts the partials at the cutoff, here 12 dB at 80%, until near the top it rings. The S1000 had none; its manual, on page 54: "Unlike the filters on some synthesizers, however, there is no resonance control, and the filter cannot go into self-oscillation."

Four more controls move the cutoff for each note, in octaves, and add up:

  • env, in the filter column, from −6 to 6 octaves: how far the filter envelope takes it at its peak.
  • key: how far it follows the key, from C4: at 100% an octave for every octave, so the cutoff keeps its place among each note's partials.
  • velocity, in the filter column: how much darker a softer note is. At 100%, a note struck at 64 is two octaves darker than one at 127, and one at 1 nearly four.
  • A keygroup's own cutoff, from −8 to 8 octaves, for the samples it plays.

The cutoff they make stays between 20 Hz and 21.6 kHz.

The envelopes

20 50 100 200 500 1k 2k 5k 10k 20k 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 s −100 0 dB 0 −12 −24 −36 −48 −60 −72 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 s rms −8.5 dBFS

0.0 / 6.0 s

peak -2.0 dBFS

Fig. 3.3 The sea through a filter at 300 Hz that its envelope opens 5 octaves over 1.5 seconds and closes over another 1.5 to 30%, with the amplifier's attack at half a second and its release at 2 seconds. The key is held for three seconds.

openzig build run-studio -- manual/sampler/03-voice/swell

renderzig build run-studio -- render manual/sampler/03-voice/swell swell.wav

swell/song.json
{
  "tempo": 120,
  "end": "4",
  "devices": [{
    "name": "S1000",
    "type": "sampler",
    "state": {
      "channels": [{ "channel": 1, "program": 1 }],
      "programs": [{
        "program": 1,
        "name": "swell",
        "sound": {
          "cutoff": 300, "filter_env": 5,
          "filter_attack": 1.5, "filter_decay": 1.5, "filter_sustain": 30, "filter_release": 1,
          "attack": 0.5, "release": 2
        },
        "keygroups": [{ "keys": "C-1 G9", "zones": [{ "sample": "sea" }] }]
      }],
      "samples": {
        "sea": { "file": "sea/sea-waves.wav", "root": "C4", "start": 192000 }
      }
    }
  }],
  "tracks": [{
    "name": "sea", "device": "S1000", "channel": 1,
    "clips": [{ "at": "1", "length": "3.0.0", "notes": "held" }]
  }],
  "notes": {
    "held": { "length": "3.0.0", "notes": ["1.1.0 C4 1.2.0 127"] }
  }
}

A voice has two envelopes, each an attack, a decay, a sustain level, and a release: the amplifier's shapes the level, and the filter envelope moves the cutoff, as far as env says. They're the synth's envelopes, whose stages bend as a capacitor's charge does, each decay and release timed to fall 60 dB (the synth's chapter 3). The attack runs from 1 ms to 10 s, the decay from 10 ms to 30 s, and the release from 5 ms to 30 s. A keygroup's own times, set on the keygroups page, take the place of the amplifier's for its notes, as the piano's top keys keep a longer release.

A sample's own shape comes first: an envelope can only take away from it. A piano note decays on its own whatever the sustain says, and a sample without a loop ends when its frames do. A one-shot sample ignores the key coming up, so its release never starts. The release goes on until the level is 120 dB down, so a voice stays busy for up to twice its release time after the key comes up.

The LFO

0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 s 526.5 Hz C5 +10.8¢ −80¢ −60¢ −40¢ −20¢ C5 +20¢ +40¢ +60¢ +80¢

0.0 / 4.0 s

peak -1.6 dBFS

Fig. 3.4 The piano's looped C5 with the LFO on its pitch: a triangle at 5.5 Hz, half a semitone deep, faded in over a second by delay.

openzig build run-studio -- manual/sampler/03-voice/lfo

renderzig build run-studio -- render manual/sampler/03-voice/lfo lfo.wav

lfo/song.json
{
  "tempo": 120,
  "end": "3",
  "devices": [{
    "name": "S1000",
    "type": "sampler",
    "state": {
      "channels": [{ "channel": 1, "program": 1 }],
      "programs": [{
        "program": 1,
        "name": "vibrato",
        "sound": { "lfo_rate": 5.5, "lfo_delay": 1, "lfo_pitch": 0.5, "release": 0.3 },
        "keygroups": [{ "keys": "C-1 G9", "zones": [{ "sample": "C5" }] }]
      }],
      "samples": {
        "C5": {
          "file": "SalamanderGrandPianoV3_48khz24bit/48khz24bit/C5v16.wav", "root": "C5",
          "mode": "in_release", "loops": ["48000 96000 24000 hold"]
        }
      }
    }
  }],
  "tracks": [{
    "name": "piano", "device": "S1000", "channel": 1,
    "clips": [{ "at": "1", "length": "2.0.0", "notes": "held" }]
  }],
  "notes": {
    "held": { "length": "2.0.0", "notes": ["1.1.0 C5 1.3.0 127"] }
  }
}

Each voice has an LFO, the synth's, restarting with its note: rate, from 0.05 to 20 Hz; wave, a triangle, a square, a random level held each cycle, or noise; and delay, the seconds it takes to fade in from the note's start (the synth's chapter 4). It moves three things, each as far as its control says: pitch, up to 12 semitones either way, for vibrato; cutoff, up to 4 octaves either way, for wah; and level, for tremolo, at 100% from full to silence.

Velocity

0 −12 −24 −36 −48 −60 −72 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 s rms −12.9 dBFS

0.0 / 6.0 s

peak -4.5 dBFS

Fig. 3.5 One recording of the piano's C4 struck at velocities 127, 64, and 32, with velocity at 75%: the second peaks 7.1 dB under the first, and the third 10.5 dB.

openzig build run-studio -- manual/sampler/03-voice/velocity

renderzig build run-studio -- render manual/sampler/03-voice/velocity velocity.wav

velocity/song.json
{
  "tempo": 120,
  "end": "4",
  "devices": [{
    "name": "S1000",
    "type": "sampler",
    "state": {
      "channels": [{ "channel": 1, "program": 1 }],
      "programs": [{
        "program": 1,
        "name": "one strike",
        "keygroups": [{ "keys": "C-1 G9", "zones": [{ "sample": "C4" }] }]
      }],
      "samples": {
        "C4": { "file": "SalamanderGrandPianoV3_48khz24bit/48khz24bit/C4v11.wav", "root": "C4" }
      }
    }
  }],
  "tracks": [{
    "name": "piano", "device": "S1000", "channel": 1,
    "clips": [{ "at": "1", "length": "3.0.0", "notes": "softer" }]
  }],
  "notes": {
    "softer": { "length": "3.0.0", "notes": ["1.1.0 C4 0.3.0 127", "2.1.0 C4 0.3.0 64", "3.1.0 C4 0.3.0 32"] }
  }
}

velocity, in the pitch and level column, sets how much a note's velocity sets its level: at 0%, not at all; at 100%, as the square of the velocity, so a note at 64 plays 12 dB under one at 127. A new program has it at 75%, which leaves a quarter of the level whatever the velocity: a note at 64 plays 7.1 dB under one at 127, at 32 10.5 dB, and at 1 12 dB. With zones of velocity, a harder note also plays a louder recording (chapter 2); the piano's program has its velocity at 73%.

The S900's grain

16-bit 12-bit −40 −50 −60 −70 −80 −90 −100 −110 −120 20 50 100 200 500 1k 2k 5k 10k 20k

0.0 / 4.0 s

peak -13.4 dBFS

Fig. 3.6 The piano's softest C4 recording played at 16 bits, then with grain at 12-bit, the spectra a second into each note. Listen for a rough hiss under the second note's decay.

openzig build run-studio -- manual/sampler/03-voice/grain

renderzig build run-studio -- render manual/sampler/03-voice/grain grain.wav

grain/song.json
{
  "tempo": 120,
  "end": "3",
  "devices": [{
    "name": "S1000",
    "type": "sampler",
    "state": {
      "channels": [
        { "channel": 1, "program": 1 },
        { "channel": 2, "program": 2 }
      ],
      "programs": [
        { "program": 1, "name": "16-bit",
          "keygroups": [{ "keys": "C-1 G9", "zones": [{ "sample": "C4" }] }] },
        { "program": 2, "name": "12-bit", "sound": { "grain": "12-bit" },
          "keygroups": [{ "keys": "C-1 G9", "zones": [{ "sample": "C4" }] }] }
      ],
      "samples": {
        "C4": { "file": "SalamanderGrandPianoV3_48khz24bit/48khz24bit/C4v3.wav", "root": "C4" }
      }
    }
  }],
  "tracks": [
    { "name": "16-bit", "device": "S1000", "channel": 1, "clips": [{ "at": "1", "length": "1.0.0", "notes": "soft" }] },
    { "name": "12-bit", "device": "S1000", "channel": 2, "clips": [{ "at": "2", "length": "1.0.0", "notes": "soft" }] }
  ],
  "notes": {
    "soft": { "length": "1.0.0", "notes": ["1.1.0 C4 0.3.0 127"] }
  }
}

grain, in the program and pads column, plays the program's samples at 12 bits, as the S900 recorded them: as each frame is read, its low four bits are dropped. Twelve bits leave a floor of noise about 72 dB under the recording's full scale, wherever the note is, so it's heard as the sound falls toward it. This recording peaks 13 dB under full scale, and a second into its decay the noise is 25 dB under it. The noise follows the sample, not the output: a sample turned up with gain brings its floor up with it.

Voices

The sixteen voices are the sampler's, shared by all its channels. A note takes a voice for each zone it plays, two in a crossfade, and a program's voices says how many a channel playing it holds at once. A note that needs a voice takes, past its program's voices, the oldest voice on its channel; otherwise a free voice, or the oldest still releasing, or the oldest of all. The voice it takes starts the new sample at once, without a fade, so a loud sound stolen clicks. The header counts the voices playing.

The pitch wheel bends every voice of the channel two semitones either way, the bend in the pitch and level column, which the wheel plays rather than sets. The hold pedal keeps the channel's voices playing after their keys come up, until it's let go. Each voice works out its pitch, filter, and LFO every eight samples.

The program page's controls

NameRangeDefaultCurveFor
tune-24 semitones to 24 semitones0 semitoneslineareach channel
bend-1 to 10lineareach channel
cutoff30 Hz to 20000 Hz20000 Hzexponentialeach channel
resonance0% to 100%0%lineareach channel
filter_env-6 octaves to 6 octaves0 octaveslineareach channel
filter_attack0.001 s to 10 s0.001 sexponentialeach channel
filter_decay0.01 s to 30 s1 sexponentialeach channel
filter_sustain0% to 100%100%lineareach channel
filter_release0.005 s to 30 s0.3 sexponentialeach channel
key_follow0% to 100%0%lineareach channel
velocity_cutoff0% to 100%0%lineareach channel
velocity_level0% to 100%75%lineareach channel
attack0.001 s to 10 s0.001 sexponentialeach channel
decay0.01 s to 30 s1 sexponentialeach channel
sustain0% to 100%100%lineareach channel
release0.005 s to 30 s0.3 sexponentialeach channel
lfo_rate0.05 Hz to 20 Hz5 Hzexponentialeach channel
lfo_wavetriangle / square / random / noisetriangleswitcheach channel
lfo_delay0 s to 5 s0 scubeeach channel
lfo_pitch0 semitones to 12 semitones0 semitonescubeeach channel
lfo_cutoff0 octaves to 4 octaves0 octavescubeeach channel
lfo_level0% to 100%0%cubeeach channel
grain16-bit / 12-bit16-bitswitcheach channel

tune turns the program up or down, in semitones; a keygroup's and a zone's tuning add to it. level and pan, in the same column, are the channel's, in chapter 4's table.

Next: chapter 4, pads and breaks, the MPC60's sixteen pads, a drum break chopped onto them, and ways to play them.