<p>I'm looking for Java code that can be used to generate sound at runtime - NOT playback of existing sound files.</p>

<p>For example, what's the best code for generating a sawtooth waveform at 440 Hz for a duration of 2 milliseconds? <b>Source code appreciated!</b></p>

<p>I remember my Commodore 128 had a simple Sound command that took as parameters voice, frequency, waveform, and duration to define a sound.  That worked great in a lot of simple cases (quick and dirty games, experiments with sound, etc).</p>

<p>I am looking specifically for sound-effect like sounds, not music or MIDI (which the <a href="http://www.jfugue.org" rel="noreferrer">JFugue</a> library covers quite well).</p>

What you want is probably not a sound API but some kind of synthesizer code, I'm pretty sure you need more low-level sound driver control than Java would allow (it being a interpreted language normally running in a "sandbox").
But the good news is that a quick search for "
java sound synthesizing
" on google revealed a plugin called
JSyn
wich uses native C methods (wich I guessed was one way of doing it) to generate sound. It seems to be free for non-commercial use and available in commercial licenses as well. :)