Aeggy
April 23, 2019, 12:20pm
1
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
kll
April 23, 2019, 12:57pm
2
-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() { }
Aeggy
April 23, 2019, 1:14pm
3
The example code here is the one that I posted above.
kll
April 23, 2019, 1:28pm
4
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
Aeggy
April 23, 2019, 1:35pm
5
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)
Aeggy
April 23, 2019, 1:40pm
7
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:
package processing.sound;
import com.jsyn.data.FloatSample;
import com.jsyn.unitgen.VariableRateDataReader;
import com.jsyn.unitgen.VariableRateMonoReader;
import com.jsyn.unitgen.VariableRateStereoReader;
import processing.core.PApplet;
/**
* This class allows you low-level access to an audio buffer to create, access,
* manipulate and play back sound samples.
*
* If you want to pre-load your audio sample with an audio file from disk you
* can do so using the SoundFile subclass.
*
* @see SoundFile
* @webref sound
*/
public class AudioSample extends SoundObject {
This file has been truncated. show original