Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stutter and lag when playing multiple samples repeatedly #74

Closed
trackme518 opened this issue Oct 23, 2022 · 4 comments
Closed

Stutter and lag when playing multiple samples repeatedly #74

trackme518 opened this issue Oct 23, 2022 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@trackme518
Copy link

trackme518 commented Oct 23, 2022

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();
    }
  }
}
@kevinstadler
Copy link
Collaborator

Thanks for reporting! Presumably this is an issue with how extra JSyn data players are allocated ad hoc when a sound file that is already playing is cued to start another playback... This will require a bit of debugging around here to figure out whether the issue is with the JSyn engine being overloaded, or if it's a general garbage collection issue (in which case this TODO finally needs implementing...):

// helper function: when called on a soundfile already running, the original
// library triggered a second (concurrent) playback. with JSyn, every data
// reader can only do one playback at a time, so if the present player
// is busy we need to create a new one with the exact same settings and
// trigger it instead (see JSyn's VoiceAllocator class)
protected AudioSample getUnusedPlayer() {
// TODO could implement a more intelligent player allocation pool method here to
// limit the total number of playback voices
if (this.isPlaying()) {
// use private constructor which copies the sample as well as all playback
// settings over
return new AudioSample(this);
} else {
return this;
}
}

@kevinstadler kevinstadler added the bug Something isn't working label Oct 24, 2022
@trackme518
Copy link
Author

Hi,
is it maybe possible to get number of used audio players at given time? So at least I could monitor it and restrict the max number....

@kevinstadler
Copy link
Collaborator

I had another look and it might not be just about the number of active audio players, but an issue of previously used but now inactive players staying connected to the synthesis engine forever. Could you do me a favour and try out the following test build and let me know if it improves the situation for you? sound.zip Just extract it into your Processing's libraries/ folder, replacing the sound directory that is already there.

I tried to test it with the sketch you posted above but I'm finding it difficult to hear past the clipping that's happening with too many simultaneous players, you probably have a better idea of what it should sound like...

(note that audiosample.loop() is probably not working in this build, all one-shot methods like .play(), .jump() etc should work as expected though)

@trackme518
Copy link
Author

trackme518 commented Nov 28, 2022 via email

@kevinstadler kevinstadler added this to the 2.4 milestone Jan 22, 2023
kevinstadler added a commit that referenced this issue Sep 21, 2023
This allows them to be properly removed from the JSyn synth network, and
consequently garbage collected. Closes #17, #74.

Insert COPIOUS expletives here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants