Friday, March 31, 2006

Win some, lose some

Last night I decided to bring up a minor feature I had been contemplating for a long time: the addition of audio feedback to Swat. This is nothing more than little beeps and boops that sound in response to your button clicks. I've long felt that these sounds are crucial to a good user interface, so I set to work. But gad, what a battle I faced! First there were problems getting a microphone to work with my old Mac, then recording the sounds, then storing them in a file format that my sound editor would recognize, then editing them, then getting them into a file format that Java would recognize (and, along the way, a great deal of time wasted trying to find beeps and boops on the Internet in a usable format.) After getting all my sound effects together, I added code to Swat that would play the sounds, and I was set.

Or so I thought. It turns out that the sound player I used was synchronous: it plays the sound and nothing else happens while it is playing the sound. This flabbergasted me. The old Mac 9 operating system supported asynchronous sounds (you start the sound playing, then proceed to other computations so that the sound plays while the interface is drawing the screen or waiting for input.) But Java, a threaded language that supports multiple threads, doesn't seem to be aware of asynchronous sounds. Oh, I'm sure that there are asynchronous sounds somewhere in the libraries. I'm just using the wrong sound library. "Oh!" some expert will say, "you're using the javax.sound.blech library. If you want to use asynchronous sounds, you have to use the javazzz.adgwed.yorch library. Didn't you know that?" Yeah, right.

So I reverted my code to what I had running Thursday and left it at that. To hell with sound, for now. We'll put it in when we can find somebody willing to wade knee-deep through the sewers of the Java libraries.


Anonymous Kris Schnee said...

Try for GPL-licensed sound effects.

1:39 AM  
Blogger Chris Crawford said...

Thanks for the tip. It looks useful -- if I ever get around to getting the Java library working for me.

7:59 AM  
Anonymous Sean Givan said...

Try putting the sound-playing code in a seperate Thread object, and launch that thread (with different params) whenever you need to play a sound.

9:02 AM  
Blogger Chris Crawford said...

Thanks, Sean. I tried it and it worked. Threads are a vital part of Java that I had successfully evaded until now. After about an hour's reading, it all made sense and I wrote up the code and it worked the first time. The only tricky part was figuring out to pass the parameters through the constructor.

2:00 PM  

Post a Comment

<< Home