-3
我正在編寫一個程序,我希望它能夠播放一個頻率。但我不知道在我的代碼中,我必須改變什麼。如何更改java中的音頻頻率?
try
{
byte[] buf = new byte[ 1 ];;
AudioFormat af = new AudioFormat((float)44100, 8, 1, true, false);
SourceDataLine sdl = AudioSystem.getSourceDataLine(af);
sdl = AudioSystem.getSourceDataLine(af);
sdl.open(af);
sdl.start();
for(int i = 0; i < 1000 * (float)44100/1000; i++) {
double angle = i/((float)44100/440) * 2.0 * Math.PI;
buf[ 0 ] = (byte)(Math.sin(angle) * 100);
sdl.write(buf, 0, 1);
}
sdl.drain();
sdl.stop();
sdl.close();
}
catch (Exception x1)
{
}
}