processing / processing-sound-archive

Archived Sound Library for Processing
125 stars 62 forks source link

loop() is throwing error when sound loops #31

Open REAS opened 9 years ago

REAS commented 9 years ago

We're getting this error message: ERROR: /node/set: Synth 1 not found

When a sound file is looping. For example:

import processing.sound.*;

SoundFile soundfile1;

void setup() {
  size(640, 360);
  background(255);
  soundfile1 = new SoundFile(this, "rumble.aiff");
  soundfile1.loop();
}      

void draw() {
  background(255);
  line(random(width), random(height), width/2, height/2);
}

We haven't been able to re-create the issue with the vibraphone.aiff file that comes with the examples. We've tried converting our files to AIFF, MP3, and WAV and the issue persists. Will send the files to you over email.

wirsing commented 9 years ago

This is just happening for Stereo files. Working on a fix.

kasperkamperman commented 9 years ago

Probably this bug still isn't fixed. Same problem occurs with oscilators:

import processing.sound.*;

SinOsc soundGenerator;
float [] simonTones = { 391.995, 329.628, 261.626, 195.998 };

boolean isSoundPlaying = false;

void setup() {
  size(200,200); 
  soundGenerator = new SinOsc(this);
}

void draw() {

  background(0);

  int soundNumber = -1;

  if (keyPressed == true) soundNumber = 2;

  if(soundNumber >= 0) {
    // only startPlaying when no sound is playing
    if(isSoundPlaying == false) {
      soundGenerator.freq(simonTones[soundNumber]);
      soundGenerator.play();
      isSoundPlaying = true; 
    }
  }
  else { 
    if(isSoundPlaying == true) {
      soundGenerator.stop();
      isSoundPlaying = false;
    }
  }

  text(soundNumber, width/2,height/2); 
}
wirsing commented 9 years ago

Hi Kasper! The original post here is a bug but what you are encountering is a coding mistake :] Your synth is not existing at the time you want to set the frequency for it. That why it says synth not found. You need to swap the order how you do things. You need to first start the synth and then set the frequencies. You can also set the frequencies with the play method by the way. like .play(freq).

  soundGenerator.freq(simonTones[soundNumber]);
  soundGenerator.play();

needs to be changed to:

  soundGenerator.play();
  soundGenerator.freq(simonTones[soundNumber]);

It was working in your script because the synth started with the previous freq value but still throwing that error because it couldn't set the current synth.

Furthermore all of this does not need to be in a draw loop since you're triggering things event based. Please use the keyPressed() function for that and refer to the keyboard example. You might also consider using Envelopes to avoid clicking.

kasperkamperman commented 9 years ago

Hi Wilm,

Thanks you for the answer. Although I'm not really agree. I think that when you provide a library and access to certain methods I should be able to use them without knowing the exact inner workings of the library. A library should be a black box, that can by use by calling functions in every way.

So if things need to be run in a certain order you should take care of that in the library itself when the function is called. Or at least throw a certain error message to the console that warns me.

I use Processing in teaching and I love it because of the friendliness. However I keep going back to Minim because the Sound library simply gives to much trouble. Your comment works for me, but for students just starting to learn to program this can be a major issue of demotivation (it never works!). That's a pity because it's an official library part of Processing (which I see as a certain quality standard).

I know this is a voluntary project and I hope I don't sound to rude. My criticism is meant to make the project better.

wirsing commented 9 years ago

Kasper,

i'm not expressing an opinion, unfortunately is has to be like this because it is a technical issue. We can hopefully fix this by making the documentation more explicit. you can also set the frequencies in the .play() method.

kasperkamperman commented 9 years ago

Thanks. Indeed good to improve it in the documentation. And if it is possible to throw an error message that is more descriptive.

kasperkamperman commented 9 years ago

By setting the frequencies in the .play method as you mentioned seems to be undocumented: https://processing.org/reference/libraries/sound/SqrOsc_play_.html

korakinos commented 8 years ago

I believe I ran into @REAS 's original bug (with loop, not oscillators) today with some MP3 files. Apart from the error message, loop() also fails to loop: The file is not (audibly) repeated.

Processing 3.2.2, Sound library 1.3.2 on Manjaro Linux without Pulseaudio or Jack, just ALSA.

SoerenNorge commented 8 years ago

@korakinos I'm also having trouble with getting stereo files to loop. Have anyone found a fix for it?

2door commented 7 years ago

Hi I'm also encountering the same issue. This is my code:

SoundFile stringSound = new SoundFile(this, "home/pi/Downloads/string.wav");

while(true) {
    if(GPIO.digitalRead(3) == GPIO.LOW && !pressed) {
        pressed = true;
        stringSound.loop();
    } else if(GPIO.digitalRead(3) == GPIO.HIGH && pressed) {
        pressed = false;
        stringSound.stop();
    }
}

It is supposed to loop while a button is pressed. If I let go of the button before the sample is fully traversed, it stops, as expected. If I hold the button down, the sample plays all the way, but only once. If I let go after the full sample has been played I get the following errors: ERROR: /node/free: Node x not found ERROR: /node/free: Node x+1 not found (if i only use the button once, x is 1, if i use it twice it is 3 etc.)

Are there any other ways to loop SoundFiles?

hkiel commented 6 years ago

I also ran into this problem with a stereo WAV. Any hope that this is going to be fixed soon, or a work-around is given? Maybe some callback that is called when play() is over?