CLM Instruments#
pysndlib ships the classic CLM instrument collection. An instrument
is simply a function that is called inside a pysndlib.clm.Sound
context and writes samples (see Sound Context Manager):
import pysndlib.clm as clm
from pysndlib.instruments import fm_violin
with clm.Sound('violin.wav', channels=1, srate=44100):
fm_violin(0.0, 2.0, 440.0, 0.4)
Instruments can be freely mixed in one Sound; each writes into the
current output at its own start time.
Where to find them#
The instruments live in two modules:
pysndlib.instruments– the classic collection (~48 instruments, ported from clm-ins.scm, generators.scm, and related files in the sndlib distribution). The instrument files are compiled with cython when pysndlib is built, so they run at native speed.pysndlib.clm_ins– additional translations (vox,drone,canter).
Note
Import instruments directly, e.g.:
from pysndlib.instruments import fm_violin
Do not use import pysndlib.instruments.fm_violin – the
package __init__ re-exports each instrument function, which
shadows the submodule of the same name; the plain import binds the
function rather than the module.
Reverb instruments#
The reverb instruments (jc_reverb, nrev, jl_reverb) are
not called directly: they are handed to Sound via the reverb
argument, and pysndlib runs them over an intermediate reverb file:
from pysndlib.instruments import jc_reverb, fm_bell
with clm.Sound('bells.wav', channels=1, srate=44100,
reverb=jc_reverb, reverb_data={'decay_time': 2.0},
reverb_channels=1, revfile='bells.rev'):
fm_bell(0.0, 2.0, 440.0, 0.4)
The instrument table#
Descriptions follow the original sndlib sources (clm-ins.scm, generators.scm, and the STK-derived instruments by Perry Cook).
Instrument |
Description |
Module |
|---|---|---|
|
attractor-based additive synthesis (clm-ins.scm) |
|
|
a bird song from an envelope-encoded spectrogram (bird.scm;
module |
|
|
SSB tone with a bouncing (vibrato-rate) modulation |
|
|
brass-like tone via the |
|
|
brass instrument whose brightness follows its amplitude (FM) |
|
|
cello-like tones (STK CelloN: pulse train through a bank of formant resonators) |
|
|
sampling-rate conversion of a sound file with an envelope controlling the conversion ratio |
|
|
slowly evolving waveform drone (wavetable lookup with modulated vibrato) |
|
|
a ser tone based on the raised-cosine ( |
|
|
granular expansion of a sound file (clm-ins exp-snd) |
|
|
inharmonic FM bell with a decaying index envelope |
|
|
FM drum: rapid index sweep on a low carrier |
|
|
insect wing tone via FM |
|
|
two-note brass FM with brightness following amplitude |
|
|
Chowning’s FM violin (vibrato, index envelope) |
|
|
vocal synthesis with vibrato (jcvoi.scm) |
|
|
formant synthesis (FOF) of a vowel-like voice tone |
|
|
glassy clang via the |
|
|
struck, detuned gong (bank of oscillators) |
|
|
granular synthesis with control over grain duration and interval |
|
|
Hammond-organ-like tone (clm-ins.scm) |
|
|
the classic Chowning/Schottstedt plate reverb (jcrev.scm);
use as |
|
|
a comb-based reverb variant (clm-ins.scm) |
|
|
piano tones with hammer noise component (clm-ins.scm) |
|
|
additive tone via a cosine bank ( |
|
|
machine-like tone via FM single sideband ( |
|
|
metallic struck tone from detuned oscillators |
|
|
K-sine summation bank tone with vibrato ( |
|
|
the standard CLM “new” reverb (nrev); use as
|
|
|
oboe-like tone |
|
|
organ-like FM tone |
|
|
piano variants (wavetable with bounce modulation) |
|
|
Karplus-Strong plucked string |
|
|
phase-quadrature waveshaping (pqw-vox): sine and cosine channels driven by envelopes |
|
|
noise-driven resonant filter bank sweep |
|
|
formant-filtered voice-like resonance with envelope-skewed formants |
|
|
Fender Rhodes electric piano (STK Rhodey.cpp) |
|
|
turntable-style scratch of a sound file (back-and-forth playback between cue points) |
|
|
wavetable additive synthesis with amplitude-weighted partials |
|
|
physical-model flute with noise bursts and vibrato |
|
|
delay-line plucked/struck string |
|
|
telephone DTMF touch tones from a digit string |
|
|
tubular bell (STK TubeBell.cpp) |
|
|
two wavetables crossfaded via an envelope |
|
|
singing voice: interpolated formant tables driven by a phoneme list |
|
|
Wurlitzer electric piano (STK Wurley.cpp) |
|
|
pulse train through an all-pass with a time-varying length
(feedback/feedforward variants: |
|
Writing your own instrument#
An instrument is just a function that computes its own sample loop
and writes with clm.outa and friends:
def sine_bell(beg, dur, freq, amp):
start = clm.seconds2samples(beg)
length = clm.seconds2samples(dur)
osc = clm.make_oscil(freq)
ampe = clm.make_env([0, 0, 5, 1, 100, 0], scaler=amp, duration=dur)
for i in range(start, start + length):
clm.outa(i, clm.env(ampe) * clm.oscil(osc))
The notebooks include a full introduction – writing an instrument,
using the shipped collection, and speeding up your own instruments
with cython (notebooks 04 and 05 in the repository’s notebooks/
directory).