Processing Sound library, multiple plays, some annoying playing, noises, bad quality

Hello, i try to make some shooter game, and when i was clicking the mouse, the sound gets lags and some noisy, can you help me ? Try it yourself, why it is doing that ? I try to stop afrer if(!audio.isPlaying()) … end its the same… its doesnt matter… why ?


import processing.sound.*;
SoundFile someSoundEffect;

void setup() {
  size(800, 800);

  someSoundEffect = new SoundFile(this, "http://soundbible.com/mp3/40_smith_wesson_single-mike-koenig.mp3");

  // Lets play this sound effect multiple times, doesnt matter if its on the one time or with delays etc.
  for (int i = 0; i < 350; i++) {
    someSoundEffect.play();
    delay(50);
  }
}

void draw() {
  // Wait some time
  delay(1000);
  // play again, and you can hear, the audio going very bad...
  someSoundEffect.play();
}

1 Like

with some reasonable settings and a very short sound file
it works here ( win 10 64b // processing 3.5.3 ) fine
( also using updated sound lib )

import processing.sound.*;
SoundFile snd;

void setup() {
  size(800, 800);
  snd = new SoundFile(this, "data/blip.mp3");
  for (int i = 0; i < 20; i++) {
    snd.play();
    delay(500);
  }
  println("setup end");
}

void draw() {
  delay(1000);
  snd.play();
}

anything shorter ( your 50msec are 20 songs per second )
would need OS to run multiple player instances ( like same time ) as with

  • start program
  • file load
  • play file ( even if short one )
  • and close file
  • shutdown player

computer (OS) needs longer as 50 msec ( for one blip )

and ( for windows ) it can’t do it without a hicks.

this timing problem MUST happen if you try to run “faster”
( more often ) as a

snd.loop();

( in setup with an empty draw ) works. did you test that ?


summary: don’t do it!