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.

Books

Comprehensive coverage of Ruby 1.8 and 1.9

"The New Most Important Ruby Book"
Peter Cooper,
rubyinside.com

Completely updated for Ajax and Web 2.0

"A must-have reference"
Brendan Eich,
creator of JavaScript

The classic Java quick-reference

Advertising

Pages

Hosted By

Powered by Movable Type 4.21-en