Home

Some nasty music...

A signal processing system -- Some of its output -- How to play OGG Vorbis -- Sample generation -- ALSA -- Sound-related stuff

A hacker's noise pollution system

The signal processing system sndsys

The following software package was created for no better reason than producing home-made heavy metal music. It is experimental software, and probably always will be. It is imaginatively named "sndsys" and guaranteed to be the umpteenth program of that name. Apart from creating sound you could also do quite different things with it, but quite possibly wouldn't want to.

sndsys is written in "hardcore stone-age" C, complete with pointers, type casts, printfs, variable parameter lists and other stuff from the nightmares of today's wimpy programmers. As a consequence, it runs fast, uses little memory, compiles fast enough to escape Al Qaeda and crashes politely to tell you you did something wrong.

The default compiler in the distribution Makefile is gcc, but I actually use icc from Intel which is free unless you do it for money. It cut compile time by nearly half compared to gcc and somewhat reduced runtime as well. Anyhow, sndsys also compiles with gcc. Here it is:

Download version from October 10 2007

If the obnoxious sales blurb above hasn't put you off, you could have a look at the following documents: The sndsys tutorial and the sndsys readme file. The former is an introduction which does not require much in the way of programming skills. It contains a description of what sound processing you can do with sndsys, in particular of those things which are not usually part of sound processing programs. The readme is a brief but fairly complete description of how sndsys works - how data are passed around, how processing steps are implemented and so on. It is likely to be of interest for programmers or scientists rather than people who want to create music.

Some not so nasty music

For starters I wrote a small jazzy tune to test sndsys and get the hang of writing instruments. It is unimaginatively titled "Capricious bass" for reasons which may or may not be obvious. It is a nice tune written for electric bass and (sort of) saxophone and has the dubious distinction of being one of very few tunes having been created to acquire the know-how to produce heavy metal music with a homebrew sound processing program.

OGG Vorbis of "Capricious bass"

Next comes an unnamed piece for electric guitar, bass, drums and electrically amplified and distorted violin (aka violent violin).

OGG Vorbis of "Unnamed" featuring violent violin

How to play OGG Vorbis

Now how to play the obscure (to some) file format of the sound files above? OGG Vorbis is an open and unpatented audio compression format. It has been consistently found in listening tests to be among the best lossy sound compression formats in terms of quality against compression rate. (See Wikipedia for links to up-to-date tests.) Available players are listed here and here.

Sample generation with mksam

Short samples are little use for simulating a musical instrument, as repeating one or several waveforms sounds very artificial to the human ear. Longer samples which can be repeated (looped) without any audible artifacts can be generated from short ones by Fourier transforming, stretching Fourier space and reverse transforming. The mksam program does just that. In addition, it allows to interpolate the Fourier coefficients, and to blur the peaks in Fourier space, which creates choir-like sound (see here). For Fourier transforms, the FFTW3 library is used, so its library and header files have to be present for compilation.

Here's the source code for mksam.

The current version automatically recognises a multi-processor/-core system and spawns a number of threads to exploit this when computing convolutions.

A close look at ALSA

ALSA is the library with which all modern Linux programs access sound cards. My web page about ALSA attempts to explain the concepts behind it and document its configuration more thoroughly than that is done elsewhere. Besides, there are solutions to problems I encountered and a program which helps solve them.

Sound-related utilities

How to play a CD without a drive-sound card cable?

The old-school way to play an audio CD on your Linux box is to connect it to your sound card with a cable and use a utility like pcd or playcd. But this has a number of disadvantages: you have to buy the cable, you have to always use the same sound card, and you cannot use ALSA and its advanced features for processing output. The alternative is to use cdparanoia or a similar tool to rip the CD and pipe its output right into a wave file player, for instance the ALSA player aplay:

cdparanoia 1- - | aplay

Doing this, I found that my CD-ROM drive took so long to spin up the CD that this caused buffer underruns for aplay. To solve this problem, I wrote a buffering program fifo (source code here) which first fills its buffer completely, then starts passing data through. Its basic usage for our purpose is:

cdparanoia 1- - | fifo | aplay

(This assumes you installed the executable somewhere in your PATH; otherwise you have to give its path explicitly.) fifo optionally accepts a buffer size and a chunk size on the command line. The latter is the maximum amount of data output to the downstream client (aplay) in one go, which helps to prevent the CD-ROM drive from spinning down during playback. A comment at the top of the source code says how to compile fifo, and a brief usage message can be obtained with fifo -h. fifo probably also has other applications wherever timely availability of streaming data is required.

How to split a wave file?

Here is the source code of a small program which splits .wav files up into parts. It is intended for splitting audio from cassettes and records digitised via your sound card up into tracks. Gramofile is supposed to be the tool for that, but it can do anything but actually split the .wav file. I actually used snd for determining track boundaries by hand, because it takes less time than finding the right parameters to do it automatically ;). snd is actually smart enough not to try loading half a gigabyte of sound data into 386M of RAM. But marking tracks as a block takes forever because you can't mark the start and the end separately but have to pull the mark over the whole track.

PS: I have since found out that there are two packages which can also split or otherwise process wav files: wavsplit is more comfortable to use but seems to have problems with stereo wav files. The wavtools contain a powerful tool, wavcutter, which cannot exactly split wav files but can extract several pieces and concatenate them, and can also deal with stereo.

Digital sound links