import javax.sound.sampled.*;
public class game0705{
static int SAMPLE_RATE = 44100; // 44.1KHz
static AudioFormat audio_format;
static DataLine.Info info;
static SourceDataLine line;
public static void main(String[] args)
throws LineUnavailableException {
audio_format = new AudioFormat(SAMPLE_RATE, 8, 1, true, true);
info = new DataLine.Info(
SourceDataLine.class, audio_format);
line = (SourceDataLine)AudioSystem.getLine(info);
line.open();
line.start();
writeNote(523.25); // C
writeNote(587.33); // D
writeNote(659.26); // E
}
public static void writeNote(double frequency) {
byte[] b = new byte[SAMPLE_RATE];
for (int i = 0; i < b.length; i++) {
double r = i / (SAMPLE_RATE / frequency);
b[i] = (byte)((Math.round(r) % 2 == 0) ? 100 : -100);
}
line.write(b, 0, b.length);
line.drain();
}
}
最終更新:2011年02月27日 09:05