我这里有这个代码,我从如何创建一个可听正弦波的教程有:Java错误生成声音正弦波
import java.nio.ByteBuffer;
import javax.sound.sampled.*;
public class FixedFreqSine {
//This is just an example - you would want to handle LineUnavailable properly...
public static void main(String[] args) throws InterruptedException, LineUnavailableException
{
final int SAMPLING_RATE = 44100; // Audio sampling rate
final int SAMPLE_SIZE = 2; // Audio sample size in bytes
SourceDataLine line;
double fFreq = 440; // Frequency of sine wave in hz
//Position through the sine wave as a percentage (i.e. 0 to 1 is 0 to 2*PI)
double fCyclePosition = 0;
//Open up audio output, using 44100hz sampling rate, 16 bit samples, mono, and big
// endian byte ordering
AudioFormat format = new AudioFormat(SAMPLING_RATE, 16, 1, true, true);