<< Chapter < Page | Chapter >> Page > |
Once we have determined which drum has been hit, we play the appropriate sound and display the corresponding image. The drum sounds and images are preloaded in separate .mat files at the beginning of the program using the load command to expedite execution.
load drumsounds
load drumpics
drumpics.mat
was created by importing drum samples in the wav format using
wavread()
and
wavadd()
.
wavread(‘wavfile’)
is a Matlab function that stores wav files as an Nx2 matrix.
wavadd(sound1,sound2)
is a function that we created to allow the simultaneous play of two different sounds. For example, if both the snare and the crash cymbal were hit at the same time, we zero pad the shorter matrix and combine them as one sound matrix. In the main program, the Matlab function
soundsc(sound, fs)
plays the corresponding sound file, where‘fs’is the sampling rate. Our wav files were sampled at 22 kHz to allow for smaller sound variables without affecting the sound quality too much. All of our drum samples were obtained free online from a Yamaha 9000 drum kit.
drumsounds.mat
was created by importing jpeg files using the
imread()
Matlab command to store the images as variables. The images were created from Google SketchUp, a free 3D modeling program available online. Different views were created to simulate the feel of animation.
Notification Switch
Would you like to follow the 'Tap that: a virtual drum kit' conversation and receive update notifications?