Constructors given in Sound Library documentation not working

Trying to use AudioSample, but I get an error on the constructor from the example given in the documentation.

	
import processing.sound.*;
AudioSample sample;

void setup() {
  size(640, 360);
  background(255);

  // Create a new audiosample
  sample = new AudioSample(this, 100000, 22050);

  // A freshly initiated audiosample contains nothing but zeros, so let's
  // write some data to it.
  for (int i = 0; i < sample.frames(); i++) {
    // Random numbers  will make it sound like white noise
    sample.write(i, random(-100, 100));
  }
  sample.play();
}      

void draw() {
}

Error message “The constructor “AudioSample(sketch_190423b, int, int)” does not exist”

All the possible constructors are given like this:

AudioSample(parent, frames)
AudioSample(parent, frames, stereo)
AudioSample(parent, frames, stereo, frameRate)
AudioSample(parent, data)
AudioSample(parent, data, stereo)
AudioSample(parent, data, frameRate)
AudioSample(parent, data, stereo, frameRate)

However, at least a few that I’ve checked don’t work and some do. Does anyone know what the problem is?

1 Like

-a- pls details from what reference / example / turtorial / video your
code originates from.

that would be a good source:
https://processing.org/reference/libraries/sound/AudioSample.html

-b- you use

this, 100000, 22050

what should each of that numbers mean? do?

the reference example
allows like

AudioSample(parent, frames)
AudioSample(parent, frames,stereo,frameRate)

so a running version of your code could be

  
import processing.sound.*;
AudioSample sample;

void setup() {
  size(640, 360);
  background(255);
//  sample = new AudioSample(this, 100000, 22050);
  sample = new AudioSample(this, 22050);
  for (int i = 0; i < sample.frames(); i++) 
    sample.write(i, random(-100, 100));

//  sample.play();
  sample.loop();
}      

void draw() { }

The example code here is the one that I posted above.

yes, looks like many of that examples
cue, duration, jump, resize, read, write, pan, samplerate …

have that wrong

sample = new AudioSample(this, 100000, 22050);

example code ( must be from some old version ??)

looks like it would work with
sample = new AudioSample(this, 100000, false, 22050);
pls try

thanks for finding & reporting.
i linked this/you from github issues
https://github.com/processing/processing-docs/issues/750 :

2 Likes

That does work, but what’s the logic behind that? Also I tried using these constructor forms with stereo, but they also didn’t work.

AudioSample(parent, data, stereo, frameRate)
AudioSample(parent, frames, stereo)
AudioSample(parent, frames, stereo, frameRate)

stereo boolean: whether to treat the audiosample as 2-channel (stereo) or not (default: false)

2 Likes

Ah, got it. Works now. Thanks

If all else fails, we can always peruse the source code directly in order to see all the available overloaded signatures for the AudioSample’s constructors: :see_no_evil: