The following method "sound" works on my PC and it sounds a beep. I am using java 1.5
and Jdeveopler 10.1.3.4 on Windows XP/SP2.
import javax.sound.sampled.*;
public void handleBeep(ReturnEvent returnEvent)
{
try {
sound(2000,150);
} catch (LineUnavailableException lue) {
System.out.println(lue);
}
}
public static void sound(int hz,int msecs) throws LineUnavailableException {
byte[] buf = new byte[msecs*8];
for (int i=0; i<buf.length; i++) {
double angle = i / (8000.0 / hz) * 2.0 * Math.PI;
buf[i] = (byte)(Math.sin(angle) * 80.0);
}
AudioFormat af = new AudioFormat(8000f,8,1,true,false);
SourceDataLine sdl = AudioSystem.getSourceDataLine(af);
sdl.open(af);
sdl.start();
sdl.write(buf,0,buf.length);
sdl.drain();
sdl.close();
}