# Constructors given in Sound Library documentation not working

**URL:** <https://discourse.processing.org/t/constructors-given-in-sound-library-documentation-not-working/10563>\
**Category:** Libraries\
**Created:** [April 23, 2019, 12:20pm UTC](https://discourse.processing.org/t/constructors-given-in-sound-library-documentation-not-working/10563 "2019-04-23T12:20:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aeggy](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Aeggy](https://discourse.processing.org/u/Aeggy)\
**Post date:** [April 23, 2019, 12:20pm UTC](https://discourse.processing.org/t/constructors-given-in-sound-library-documentation-not-working/10563/1 "2019-04-23T12:20:45Z")

</div>

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

```auto
	
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?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [April 23, 2019, 12:57pm UTC](https://discourse.processing.org/t/constructors-given-in-sound-library-documentation-not-working/10563/2 "2019-04-23T12:57:33Z")

</div>

-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](https://processing.org/reference/libraries/sound/AudioSample.html)

-b- you use

```auto
this, 100000, 22050

```

what should each of that numbers mean? do?

the reference example  
allows like

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

```

so a running version of your code could be

```auto
  
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() { }

```

---

<div class="post-metadata">

**Author:** ![Aeggy](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Aeggy](https://discourse.processing.org/u/Aeggy)\
**Post date:** [April 23, 2019, 1:14pm UTC](https://discourse.processing.org/t/constructors-given-in-sound-library-documentation-not-working/10563/3 "2019-04-23T13:14:02Z")

</div>

The example code [here](https://processing.org/reference/libraries/sound/AudioSample_write_.html) is the one that I posted above.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [April 23, 2019, 1:28pm UTC](https://discourse.processing.org/t/constructors-given-in-sound-library-documentation-not-working/10563/4 "2019-04-23T13:28:34Z")

</div>

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

have that wrong

```auto
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](https://github.com/processing/processing-docs/issues/750) :

---

<div class="post-metadata">

**Author:** ![Aeggy](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Aeggy](https://discourse.processing.org/u/Aeggy)\
**Post date:** [April 23, 2019, 1:35pm UTC](https://discourse.processing.org/t/constructors-given-in-sound-library-documentation-not-working/10563/5 "2019-04-23T13:35:45Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [April 23, 2019, 1:37pm UTC](https://discourse.processing.org/t/constructors-given-in-sound-library-documentation-not-working/10563/6 "2019-04-23T13:37:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aeggy](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Aeggy](https://discourse.processing.org/u/Aeggy)\
**Post date:** [April 23, 2019, 1:40pm UTC](https://discourse.processing.org/t/constructors-given-in-sound-library-documentation-not-working/10563/7 "2019-04-23T13:40:16Z")

</div>

Ah, got it. Works now. Thanks

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 23, 2019, 2:21pm UTC](https://discourse.processing.org/t/constructors-given-in-sound-library-documentation-not-working/10563/8 "2019-04-23T14:21:46Z")

</div>

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: 🙈

> <https://github.com/processing/processing-sound/blob/master/src/processing/sound/AudioSample.java>
