try {
AudioFormat af = new AudioFormat(SAMPLE_RATE, 8, 1, true, true);
DataLine.Info info = new DataLine.Info(SourceDataLine.class, af);
SourceDataLine source = (SourceDataLine) AudioSystem.getLine(info);
source.open(af);
source.start();
byte[] buf = new byte[(int) (SAMPLE_RATE * seconds)];
for (int i = 0; i < buf.length; i++) {
buf[i] = (byte) (Math.sin(RAD * frequency / SAMPLE_RATE * i) * 64.0 / Math.sqrt(i));
}
source.write(buf, 0, buf.length);