Here’s something I whipped up late one night. It’s a simple drum machine in Python. The script reads formatted text that describes drum patterns then invokes CSound to create the track. Check out the script.
Below is the score to the first few measures of a Zigzags song called Icecream Sandwich. (Full score is here.) The first section defines the patterns named p0, p1, p2, and p3. The second section puts the patterns together to form the song. The numbers in the pattern tell the program to play a drum at a particular volume (1 softest to 0 loudest). A period tells the program to sustain the note for a specific length of time (otherwise the note will sustain until the sample is finished). The vertical ‘|’ character is ignored and can be used as a visual aid to separate ticks into measures. The character string “b222 t4″ tells the program that the succeeding section is 222 beats per minute, with 4 ticks (i.e. dashes) per beat.
p0
stick 8---|6---|4---|2---
p1
kick 9---|--8-|--7-|----
snare ----|6---|----|6---
chh ----|7---|7---|7---
crash 7---|----|----|----
p2
kick 9---|--8-|--7-|----
snare ----|6---|----|6-4-
chh 7---|7---|7---|7---
crash ----|----|----|----
p3
kick --8-|--8-|--8-|--8-
snare 6---|6---|6---|6---
ohh 6...|6...|6...|6...
end
#####################
b222 t4
p0
p1 p2 p1 p2
p1 p2 p1 p3
Here’s a very lo-fi recording of Icecream Sandwich (minus the bass guitar) which uses a drum track created with this program:
(Don’t know why my computer mic squeals like that but my punk rock side doesn’t care.)
Since writing the drum machine code I’ve enhanced the sound code in VROOM and realized I could easily extend the drum machine code to use the Pygame mixer module instead of CSound. One advantage to using CSound, though, is that it’s pretty straight forward to do additional processing. For example, check out the file foo.orc, the CSound orchestra file that I used.
; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1
; Instrument #1.
instr 1
kamp = 200*p5
; If you don't know the frequency of your audio file,
; set both the kcps and ibas parameters equal to 1.
kcps = 1
; ifn = 1
ifn = p4
ibas = 1
a1 loscil kamp, kcps, ifn, ibas
a2 lowres a1, 5*p5^1.5, 0.2
out a2
endin
It applies a low pass filter to the sampled waveforms, with a volume-dependent cutoff frequency. This results in a more realistic sound since drums have more high-end when struck harder. Of course, nothing can replace real drums. I wrote this code mostly for tempo practice and sketch recordings.