Stutter and lag when playing multiple samples repeatedly
When using SoundFile class and triggering samples repeatedly it will start to stutter eventually. This is not happening in another audio library - Beads. Also reported here: https://discourse.processing.org/t/sound-library-bugs-lagging-noise-choppy/4718 Example code below:
import processing.sound.*;
int timer;
SoundFile[] file = new SoundFile[5];
void setup() {
size(640, 480);
background(0);
for (int i=0; i<file.length; i++) {
file[i] = new SoundFile(this, "http://soundbible.com/grab.php?id=1705&type=wav" );
}
timer = millis();
frameRate(30);
}
int numplays = 0;
void draw() {
//around 800-1100 plays it will start to stutter
if (numplays<1000) {
if (millis() > timer + 20 ) {
int i = (int)random(0, file.length);
file[i].play();
numplays++;
println(numplays);
timer = millis();
}
}
}