I've been generating dynamic audio by looping a clip and updating it's buffer on the fly.
With the java update 7 25 (June 18, 2013) the clip no longer plays changes made to its buffer, but merely loops its original content. In the clip below, white noise is played if test==0, but not if test==1. It used to play noise both ways, and it still does when run as a console app instead of a local applet.
I really need to update that buffer after the clip has opened: Several pieces of software are suddenly silent. Is there another (or correct) way to do it? Thanks in advance.
AudioFormat.Encoding enc = new AudioFormat.Encoding("PCM_SIGNED");
AudioFormat frmt = new AudioFormat(enc, 22050, 16, 2, 4, 22050, false);
DataLine.Info info = new DataLine.Info(Clip.class, frmt);
Clip loop_clip;
int size = 8192;
byte[] sound_buf = new byte[size];
for (int i = 0; i < size; i++)
sound_buf[i] = 0;
int test = 1;
if (test == 0)
for (int i = 0; i < size; i++)
sound_buf[i] = (byte) (Math.random() * 256);
try {
loop_clip = (Clip) AudioSystem.getLine(info);
loop_clip.open(frmt, sound_buf, 0, size);
} catch (LineUnavailableException e) {
e.printStackTrace();
return;
}
if (test == 1)
for (int i = 0; i < size; i++)
sound_buf[i] = (byte) (Math.random() * 256);
loop_clip.setLoopPoints(0, -1);
loop_clip.loop(999);