Drum Machine by John Richter
The actual score file that generates the short
demonstration of the DrumKit synthesizer is here.
The audio file
generated from this score file is here.
To create a Synthesized drum all that needed to be done was to create a sine wave with a very low
frequency and then apply an amplitude envelope to the wave. To do this I used the CAR and ToneInstrument
classes to create the wave and change its amplitude. I used the supplied Notes.h to convert a Unicode text
value to a frequency for the ToneInstrument then used its output as input to the AR for envelope generation.
I was then able to define different types of drums such as the Bass Drum (implemented as 'SBD', 'LongBD', 'ShortBD',
and 'iLongBD') that could be used in the Score to play a specific note.
You can define any number of notes in the
score file to be played at the same time from the DrumKit
synthesizer. Each note results in either a WaveInstrument(from file) or a
DrumInstument(synthesized) object being generated from a factory and each
of these objects generates sound which is added to the total sound output,
so playing multiple notes at one time is no problem. Each note is added to
the sound that is output. Adding multiple notes together increases the amplitude,
so it would probably be a good idea to decrease the amplitude on each note if many
notes are going to be played together at once.
Envelope generation eliminates any popping sounds
created by the DrumKit synthesizer generating audio. Envelope generation
uses an attack duration, a release duration, and an actual note's duration
in order to eliminate popping. If the note has been playing for less than
the attack duration, then the the amplitude gradually and smoothly increases
from zero to the note's actual amplitude. If the note has been playing for
more than the attack duration but less than the actual duration minus the
release duration, then the amplitude is just the note's actual amplitude
with no modification. If the note has been playing for more than the actual
duration minus the release duration, then the amplitude gradually and
smoothly decreases from the note's actual amplitude to zero.
The DrumKit synthesizer lowers pitch by slowing
down the playback of the .wav files that are loaded and raises pitch by
speeding up playback of the .wav files that are loaded. The rate at which to
slow down or speed up playback is determined by the startNote, midNote, and endNote specified.
For example, if the startNote C4, midNote is D4 and endNote is E4, then the DrumKit
synthesizer would speed up the playback of the .wav file by (1.05946^2 =
1.12246) times to move up two half-steps or semitones. To get to the midnote and step the same amount
to get to the final note of E4.
20 Distinct Drum Sounds:
I have used 4 synthesized Bass Drums and other .wav files loaded from disk.
- ./waves/Cymbols/UNIVOXCH.WAV - HH
- ./waves/Cymbols/CHH01.WAV - HH
- ./waves/Cymbols/UNIVOXOH.WAV - HH
- ./waves/Cymbols/hihatopen.wav - HH
- ./waves/Cymbols/RockOpenHH.wav - HH
- ./waves/Cymbols/CRSHCYM1.WAV - CR
- ./waves/Cymbols/SPLSHCYM.WAV - CR
- Bass Drums:
- ./waves/Toms/drumu hi tom.wav - TH
- ./waves/Toms/drumu mid tom.wav - TM
- ./waves/Toms/drumu lo tom.wav - TL
Score file format:
The format for the DrumKit synthesizer is as follows:
<note HH="./waves/Cymbols/hihat.wav" measure="1" beat="1"/>
<note CR="./waves/Cymbols/crash.wav" measure="1" beat="1"/>
<note SN="./waves/Cymbols/snare.wav" measure="1" beat="1"/>
<note TH="./waves/Cymbols/tomhigh.wav" measure="1" beat="1"/>
<note TM="./waves/Cymbols/tommid.wav" measure="1" beat="1"/>
<note TL="./waves/Cymbols/tomlow.wav" measure="1" beat="1"/>
<note BD="./waves/Cymbols/bassdrum.wav" measure="1" beat="1" startNote="C0" midNote="D#2" endNote="F2" duration="1"/>
<note SBD="" measure="1" beat="1"/>
<note ShortBD="" measure="1" beat="1"/>
<note LongBD="" measure="1" beat="1"/>
<note iLongBD="" measure="1" beat="1"/>
<note ACC="./waves/Effects/effect.wav" measure="1" beat="1"/>
All information for a DrumKit instrument is contained
in the instrument node with the instrument attribute equal to
'DrumKit'. The instrument node contains zero or more note nodes.
The note nodes represent either a .wav audio file that is loaded to be played
by the WaveInstrument synthesizer or by the DrumInstrument synthesizer to actively synthesize a drum sound.
The notes corrosponding to a .wav file are loaded into a WaveInstrumentFactory via the path within the
attribute corrosponding to the specific instrument (e.g. 'HH' for hihat) and played back at the 'measure'
and 'beat'. If the instrument attribute value is blank it means that the instrument will be synthesized.
Each .wav instrument can be pitch altered by specifiying the starting note, the middle note, and ending note.
This will change the .wav to change pitch over the range specified durning its original duration.
These act as frequencies to alter the rate of playback in order to achieve the specified frequency. The midNote
attribute allows for skewing of the pitch changes and how long it takes to reach the midNote from the start
and from the midNote to the end. This allows for many cool effects.
DrumKit instrument nodes and attributes:
- instrument - The name of the instrument must be 'DrumKit'
- HH - The HiHat.
- CR - The Crash, Splash, or any other cymbol used.
- SN - The Snare Drum.
- TH - The High Tom.
- TM - The Mid Tom.
- TL - The Low Tom.
- BD - The Bass Drum.
- SBD - The Synthesized Bass Drum.
- LongBD - A long synthesized bass drum that cresendos over 2 beats.
- iLongBD - A long synthesized bass drum that decresendos over 2 beats.
- iLongBD - A short synthesized bass drum that cresendos over 1 beats.
- ACC - An accessory item such as cowbell, agogo, or tamborine.
- measure - The measure
where the note starts. This value should be greater than or equal to 1.
- beat - The beat in the
measure where the note starts. This value should be greater than or equal to
one and less than or equal to the beatspermeasure value.
- startNote - Optional for all non-synthesized components to be the rate of playback at the beginning of the file.
- midNote - Optional for all non-synthesized components to be the rate of playback at the middle of the file.
- endNote - Optional for all non-synthesized components to be the rate of playback at the end of the file.