A9: Scilab Sings
Last activity, we used morphological operations and the IPD kit by Dr. Galda to identify abnormal “cells” in an image, but did you know we can use this kit in a variety of other ways? In this activity, we were made to let scilab read and play sheet music. It wasn’t an easy task, but it was pretty fun to work on.
The sheet music I used for this activity is a piano adaptation of the song ECHO by Crusher-P. The piano piece can be found here, while the original song can be found here. For this activity, I only included the melody following the treble clef up until the 64th measure of the piece.
First of all, we should know that scilab can produce sounds from sinusoid functions.
The frequency f of the wave here determines the pitch of the sound, and the time t defines how long the sound plays.
Now the product of this is called pure tone, a continuous sound that doesn’t quite sound like a note played by a piano. To fix that, we applied an sound envelope or an ADSR (attack, decay, sustain, release) envelope to emulate the sound of an instrument.
Here’s the note function I used, based on the one provided by our professor, Dr. Soriano:
//note function function n = note(f, t)
n = sin (2*%pi*f*t); //defines the envelope env1 = linspace(0, 1, round(0.025*length(t))); //attack env2 = linspace(1, 1, round(0.05*length(t))); //sustain env3 = linspace(1, 0.9, round(0.05*length(t))); //drop before decay env4 = linspace(0.9, 0.45, round(0.85*length(t))); //decay env5 = linspace(0.45, 0, length(t)-length([env1,env2,env3,env4])); //release env = [env1, env2, env3, env4, env5]; //applies the envelope n = n.* env; endfunction;
So with that done I had two main objectives: identifying the kinds of notes (half, quarter, eighth, sixteenth), and their pitch, in addition to recognizing rests and dotted notes.
I stitched together the many lines of music to form one long continuous line from the first to 64th measure. This was my input image.
As I said before, I used Dr. Galda’s IPD kit to analyze the notes here. After reading the image, I realized I had a problem. If I applied morphological operations to isolate the quarter notes, I’d be removing the half notes. And even so, how would I differentiate between quarter, eight, and sixteenth notes?!
I ended up using three segmentation methods for the notes:
one to detect the “filled” note heads that quarter, eight, and sixteenth notes shared,
another to detect the “hollow” half note heads, and
the last to detect the bars and flags of eighth and sixteenth notes
Here’s an example of how the first segmentation process worked.
The other two used different thresholds and morphological operations.
With the notes indexed, I’d get the x and y-coordinates of the centroids of the note heads and used the x-coordinates to control the sequence at which the notes would be played, and the y-coordinates to determine the pitch of the note. Additionally, if the x-coordinate of a note head coincided with those included in a bar or flag, the note was identified as an eighth or sixteenth note.
For the rests and the dotted notes, I had to use two more segmentation processes. Fortunately, all rests are located in the same spots on the musical staff, so if a blob was found to occupy that spot, I could mark it as a corresponding quarter or eighth rest. For the dots, I had a bit of trouble since most of my notes were staccato notes. To remove the staccato marks, I only considered dots that didn’t line up vertically with other notes. After finding the notes closest to these dots, I applied the corresponding modification to their time (dotted notes are played at a total time equal to 1.5 times the time of the usual note). I... ignored the staccato notes for now, as modifying the envelope either produced no noticeable effect, or too much of an effect on the final notes in the wave file.
With all of that done, I have my final output. You can listen to it here. HEADPHONES WARNING!! It can get kinda loud.
That was a really tedious activity, but I can’t deny it was a lot of fun too. I met the requirements of the activity, plus adding in the sound envelope, together with recognizing rests and dotted notes. For that, I think I deserve a 12 out of 10.
Now I get to sing praises to the following as my acknowledgements:
Dr. Maricor Soriano, our professor who provided the note function
Joshua Abuel, for helping me with the process of detecting notes
Physics of Music Notes, for the note frequencies
Luman Magnum, for the info on how to apply a sound envelope
Crusher-P, for creating the beautiful and addictive song ECHO
jazzermazzer99, for transcribing a piano adaptation (and making an easy version) of ECHO












