January 25, 2004

Fun with Java Sound

One of the new chapters I added to the 3rd edition of Java Examples in a Nutshell covers the Java Sound API. That chapter was a lot of fun to research and write.

To the right is an applet I played around with before writing the example that actually made it into the chapter: its a MIDI drum machine. Click your mouse in the applet to give it keyboard focus and then strike keys at random to generate percussion effects. Move the mouse to the bottom of the applet for louder sounds and to the top of the applet for softer sounds. Play around with the keys: only keys whose keycode maps to a MIDI key number between 35 and 81 produce any sound.

You'll need the Java 1.4 plugin installed in your browser for this to work, of course. Don't forget to click on the applet. If you don't it may never get the keyboard events it needs.

Please excuse the lame visuals, and take a look at the surprisingly simple source code. | TrackBack

Comments