Virtual Drum Machine


vdm is a simple drum machine.

It works for little endian/linux kind of machines. You may let it work on others machines, but you probably will get troubles with it. You definitely need oss (or maybe alsa) for sound output, and a posix-like operating system. To let it work on a big endian machine should be painful.

You write a rhythm, then you compile it, then you are able to play it to your sound card or save it to a file.

The Virtual Drum Machine is made of

The Virtual Drum Machine is in the public domain. Who needs a license? money makers? Protection against robbery? let me laugh... Read any text of law, you will see where the robbers reside.

A simple file would look like :

void main_rhythm(void)
        tempo = 120;
        * a
                . b
                . b
        * a
        * a
                . b
                . b
        * a c
                . b



Do a "./configure" in the drums directory, then "make", then "make install", it should be alright. You can listen to some examples in the examples/ directory.

You may want more samples, so try (1,466,881 bytes). You can configure the rc.conf file to use any samples you want.

How to use it?

Write a rhythm. Compile it with "rc". Run the produced program. You are done.

See the examples/ directory to get the point.

When you run an example, try "-h" to get the available options.

It should be self-explanatory.

The rhythm compiler has several options. By running "rc --help", all should be clear.

Technical details

How does the compiler work?

The compiler will parse the input file line by line.

If a line starts with "*" or "." (not counting leading white spaces), the whole line is seen as a rhythm line, and is transformed into C code. If not, it is passed as is to the C file.

Beware! You MUST NOT start any C code line by "*" or "."!

What is the structure of a rhythm file?

You can create as much functions as you want, write any C code you want. But remember that a line starting by "*" or "." is seen as a rhythm line and is translated by "rc" into C code.

You must provide a "void main_rhythm(void)" function, that will be called by the library. It is the starting point of your rhythm. It can be "void main_rhythm(int argc, char *argv[])" too, with common meaning for those parameters (non-C coders will have trouble with the Virtual Drum Machine).

Available controls

You can change the tempo (ex. "tempo=100;") or the volume (ex "vol=0.4;") at any time. Each sample comes with its own volume and panning (ex. "a.vol = 0.1;" "a.pan=-0.8;"). Volumes range from 0 to what you want. 1 is for the normal volume. Panning ranges from -1 (left) to 1 (right). 0 is center. All values are double. You can use "volume" instead of "vol", and "panning" instead of "pan". There is no global panning, if you want all left, set all samples to left.

To run in stereo mode, don't forget "-s" when running the generated program. It is mono by default.

You absolutely need to compile and run the examples, and read them to get the point out of it!

The configuration file

The "rc.conf" file contains configuration informations. You specify the sample by "sample" followed by its name (the one you will use in your rhythm files), then the file that will be played. The name of the sample must start by a letter, followed by letters and/or numbers (it must be a valid C identifier, without "_" though). The configuration file contains the install directory, used by "rc" to compile your rhythms. Take a look at the one that is provided to see how to use it.

What samples may be used?

The sound files are simple wav files. They all should be of the same rate, which can be specified to the generated program, using the "-f" option (44100 is the default). (The library only handles very basic wav files, if yours don't work, you probably will have to modify the library for the program to handle it.)

When you add a sample, you must modify "rc.conf" for the changes to appear. The samples are hard-linked to the produced program, so if you change "sample a /some/dir/file1.wav" by "sample a /one/other/dir/file2.wav" in the configuration file, the previously generated programs will still use "/some/dir/file1.wav". You will have to compile them again to take the changes into account.

What is a rhythm?

A rhythm is just a succession of notes and sub-notes.

At each note (or sub-note), you output some sound.

A note is started with "*". You then can divide it into several sub-notes, each having the same duration, by using ".". So "* . . . * . . ." would create two notes, each divided into four sub-notes. See the examples, it should become clear.

What is a polyrhythm?

Take poly.r in the examples/ directory. It contains :

  for (i=0; i<5; i++) {
  * ( b . b . b ) ( a . a )

You see a new construction "(" and ")". This introduces the concept of polyrhythm. Each chunk between "(" and ")" is a division of the note. So here, we have 2 divisions, one made of 3 sub-notes and the other made of 2 sub-notes. So you will listen to 3 "b" and 2 "a" in the same amount of time, thus leading to a polyrhythm.

If it is not clear, think of each chunk as a movement of one part of a drummer's body. The first chunk might be the left arm and the second the right arm. Each arm will act independently of the other, dividing a time into as much sub-notes as the drummer wants. This is very useful I think to write some complex rhythms. Not perfect, because there are still some stuff I have troubles to write with only those constructs, but it is better with it than without it.

Is it bug-free?

No. If you find a strange behaviour, send your rhythm file to me (and the rc.conf if you modified this one). If you crash something at sometime, do the same.

One bug is the way we handle tempo. When we want to put a fraction of note, we have to put a non-integer number of samples, but we truncate this number, so in the long term we are not perfectly synchronized with the tempo. We should handle in a better way this stuff.

Another strange behavior may be the messages given by gcc if your input is buggy. The line numbering scheme is a hack, it probably is wrong.

Poly-rhythm has not been widely tested. The code to handle it may be full of bugs.


A drum machine using gtk. Not tested. Seems too classical, so too hard to use for me. Virtual Drum Machine has been done because I was unable to use properly existing drum machines. As a coder, I needed a more coder-friendly tool. (Well, seems to be some more drum machines available online, I won't add any more links.)

Where I re-found the idea of polyrhythms (I though of it earlier in the development stage of this program and gave up for I don't remember why...)

Sound & MIDI Software For Linux
The definite resource for sound and linux.

They rule the world.

Final words

Excuse my bad english.


Creation date: Wed, 8 Jan 2003 19:41:31 +0100
Last update: Wed, 20 Nov 2013 16:22:48 +0100