Article posted on: 2022-03-29 20:51
Last edited on: 2022-04-02 14:40
Written by: Sylvain Gauthier
sndc is a sound compiler a bit like LaTeX
is a document compiler. You give it a .sndc
file and it will output a sound
from it, always the same sound bit for bit on any machine regardless of the
processing power.
It aims at being a suckless way of quickly hacking sound effects and potentially
even music. It consists of a core, static library libsndc.a
that you can
easily import into other projects or if you wish to build a different interface
on top of it, as well as a sndc
executable to perform the actual sound
compilation, and two wrappers sndc_play
and sndc_export
to respectively play
sndc
’s output using aplay
and export it into whatever audio format using
sox
.
I’ve been working on it for about a year now. It is inspired by sfxr, a small program to quickly create video game sound effects. I won’t number versions as I expect it will be a continuous rolling-release as more modules are added.
Dependencies:
libfftw3
$ git clone https://pedantic.software/git/sndc
$ cd sndc
$ make install PREFIX=<path_to_installation> # PREFIX defaults to /usr/local
sndc
files can be imported as modules into other sndc
files.SNDCPATH
environment variable to look for module libraries, you
can build yourself a complete library of sound effects to import in new
projects.float32
in the standard output,
delegating playing/converting the audio to specialized software.reverb
- Implementation of the Freeverb algorithm.filter
- Generic FFT-based lowpass / highpass filter.simplelp
- Low pass filter using simple and fast diff equation.gaussbp
- Band pass filter using gaussian convolution.envelop
- Apply envelop to input signal.mix
- Mixer for up to 8 input buffers.print
- Prints input buffer to specified file for plotting/analysis.drumbox
- Simple drum machine that sequences its input samples.keyboard
- Melodic sequencer for a given instrument node.layout
- A generic layout helper to mix layers together.var
- Variable, copies its input value to its output value.osc
- A generator for sine, saw and square waves.noise
- Noise generator.convol
- Computes convolution product of its input buffers.func
- A generator for mathematical functions.binop
- Binary operation between two buffers or numbers.sndc
files are a simple description of a node stack. Each node
is an
instance of a module
, either builtin or imported from another sndc
file.
nodes
have input and output data
. data
can be either float
, buffer
(of
floats) or string
. A node
is only called once during the stack processing,
will consume its inputs and produce its outputs. nodes
are processed
sequentially in the same order as they appear in the sndc
file.
nodes
inputs can be literal floats
or strings
or they can be connected to
the output of nodes
above them in the file. Connecting the input of a node
to the output of a node after it will produce an error.
sndc
will dump the first buffer of the last node
in the file given to it as
an argument, as a raw stream of binary float32
.
The README.md
file gives more details on the exact syntax of the language, and
the examples
folder gives plenty of examples including complex melodies with
external keyboard file and layout file.
I might start a series of blog posts on how to properly use each module, the workflow I came up with to design sounds with it and how to write C modules.