






Hotspots: Admin Pages | Turn-in Site |
Current Links: Case Final Project Summer 2007
AudioExplorer Modification
What you need:
- audioexplorer.st - the original AudioExplorer
- Missing File (/cs2340/uploads/soundplayingar.1.cs) - change set that adds sound playing functionality
To install the program, just download the two files then file them in. Starting up the program is pretty easy too – just go into class comments for AudioExplorer, select the last line and do it.
What you get is something that looks like this:

Actually, thats what it should look like after you've recorded some audio (did I mention you need a microphone?). To record sound you simply press the Record button at the bottom left; to stop hit pause.
Go ahead and hit the "Math On" button at the bottom left. You'll see something like this:

Now click on the "Sound On" button. Now when you hit any key on that little keyboard, it'll actually play that note.
So what did I do?
Well, I added the sound playing capabilities. Originally I was planning on just throwing the capability in there, but I spoke with the Author, Je77, and he expressed a desire to have the feature as an option... Thus the "Sound On"/"Sound Off" button was born.
And how did you do it?
Squeak actually had most of stuff already there, it was just a matter of hooking it up. My other considerations were to preserve the look and feel of the program, and to keep the code clean.
Adding the button
I didn't want the button to always be visible. Rather, I'd prefer it only appear when it acutally served a purpose, i.e. when the keyboard is visible. So, if you take a look at the "toggleMath" method you'll see where the button is added and removed.
Some other methods that were written with regards to the button were addSoundButton, and toggleSound both of which I think are pretty self explanatory.
Playing those sweet sounds
Here's the source for the playing the sound:
keyPressed: aKey
| frequency |
"The numbers on the side are reference points"
self selected: (scale indexOf: aKey).
"1" frequency := 440 (2 raisedTo: selected - 34 / 12).
owner signalFrequencyPosition: frequency.
"2" owner playSound ifTrue:[
"3" ((AbstractSound soundNamed: 'default') soundForPitch:
frequency dur:0.5 loudness:1) play.
].
OK, obviously this code is called when a key is pressed. Je77 had already written the code to calculate the tone's frequency (see line 1).
Line 2 has a little method I wrote called playSound. It returns a boolean saying whether or not to play the sound. Actual implementation is a little hack-ish since what it does is check the color of the "Sound" button. If its red, return true, else return false. Oh well, guess you're stuck with green and red.
Line 3 is the real heart of the code. AbstractSound is an object that can generate audio. The parameter that soundNamed takes in is a string representation of what instrument you want to have played. An AbstractSound object is returned. I told that object to play a sound at the frequency Je77 calculated for half a second and at full volume (YEAH!)
Things I might like to change
- I'm not too crazy about creating a new AbstractSound object every time a key is pressed. It adds a bit of a delay before the sound is actually produced. Maybe a global AbstractSound variable would have been better.
- The duration is fixed. It doesn't matter how long you hold the key down, it only plays for a half second. Also, if you run your mouse over the keys you can get notes to overlap (you can make some really aweful noises by combining adjacent notes). I'd really rather have the audio mirror the user's actions on the keyboard.
- The instrument is fixed. Not too sure how difficult it would be to allow users to switch instruments. One of those "Play with me" projects has this feature already. Maybe it could be pasted in real easily.
Nice job! But a GLOBAL AbstractSound?!? EEKS! Probably better to figure out what's taking so long in making an AbstractSound. At worst, maybe you can attach one to the AudioExplorer somewhere. Mark Guzdial
Link to this Page
- Case last edited on 29 July 2009 at 11:50 pm by c-76-97-208-233.hsd1.ga.comcast.net