I'm trying to play a sine wave.
I have a SourceDataLine, but when I try to write to it, the write method return 0, meaning that it coulen't write anything to the mixer's output stream, right? I also don't get to hear a thing, by the way.
Here's the code I'm using:
Code:
byte [] sample = new byte[4];
int written = 0;
while (true) {
int valor = (int) ((2 << 15 -1) * wave.height());
//System.out.println(valor);
sample[0] = sample[2] = (byte) (valor & 0xff);
sample[1] = sample[3] = (byte) (valor >> 8);
written = line.write(sample, 0, 4);
if (written != 4) {
System.err.println("Couldn't write all the bytes!");
System.exit(1);
}
line.drain();
wave.tic();
}
wave.height() returns the height of the wave (-1 to 1) for that moment in time.
The Audio Format is PCM_SIGNED, at 44.1 KHtz, 16 bits per sample, Stereo, little endian.
Any ideas?