0

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);
Smit
  • 4,685
  • 1
  • 24
  • 28
Brad
  • 13
  • 4

1 Answers1

0

I didn't find a solution to make the clip buffer accessible after the clip is opened, but I simulated a clip using a SourceDataLine and a feed buffer. It's surely more CPU intensive, but at least it can be tested in a local applet.

Brad
  • 13
  • 4