# "this" argument not working correctly

**URL:** https://discourse.processing.org/t/this-argument-not-working-correctly/21880
**Category:** Libraries
**Created:** [June 15, 2020, 2:20am UTC](https://discourse.processing.org/t/this-argument-not-working-correctly/21880 "2020-06-15T02:20:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Odermonicon](https://avatars.discourse-cdn.com/v4/letter/o/96bed5/32.png) [@Odermonicon](https://discourse.processing.org/u/Odermonicon)
#### Post date: [June 15, 2020, 2:20am UTC](https://discourse.processing.org/t/this-argument-not-working-correctly/21880/1 "2020-06-15T02:20:43Z")

</div>

I’m using the processing.sound library to make a synth,  
but when I use the “this” keyword it gives me an error:  
`The constructor "SinOsc(Timbre)" does not exist`

> **MCVE**
>
> ```auto
> import processing.sound.*;
> class Timbre {
> SinOsc freqF;
> Timbre() {
> freqF = new SinOsc(this);
> }
> }
> Timbre sound;
> void setup() {
> sound = new Timbre();
> }
> 
> ```

> **Code**
>
> ```auto
> class Timbre {
> float harmU;
> float harmD;
> float harmT;
> float harmQ;
> SinOsc freqF;
> SinOsc freqU;
> SinOsc freqD;
> SinOsc freqT;
> SinOsc freqQ;
> Timbre(float U, float D, float T, float Q) {
> harmU = U;
> harmD = D;
> harmT = T;
> harmQ = Q;
> freqF = new SinOsc(this);
> freqU = new SinOsc(this);
> freqD = new SinOsc(this);
> freqT = new SinOsc(this);
> freqQ = new SinOsc(this);
> }
> void playFreq(float freq) {
> freqF.set(freq, 1, 0, 0);
> freqU.set(freq*harmU, 1/harmU, 0, 0);
> freqD.set(freq*harmD, 1/harmD, 0, 0);
> freqT.set(freq*harmT, 1/harmT, 0, 0);
> freqQ.set(freq*harmQ, 1/harmQ, 0, 0);
> freqF.play();
> freqU.play();
> freqD.play();
> freqT.play();
> freqQ.play();
> }
> void stopFreq(float freq) {
> freqF.stop();
> freqU.stop();
> freqD.stop();
> freqT.stop();
> freqQ.stop();
> }
> }
> import processing.sound.*;
> Timbre sound;
> 
> void setup() {
> sound = new Timbre(2,3,4,5,);
> sound.playFreq(440);
> }
> 
> ```

Please send help  
PS: I’ve tried the following code too:

> **Extra**
>
> ```auto
> import processing.sound.*;
> class Timbre {
> SinOsc freqF;
> Timbre(Object sketch) {
> freqF = new SinOsc(sketch);
> }
> }
> Timbre sound;
> void setup() {
> sound = new Timbre(this);
> }
> 
> ```

And this:

> **Extra 2**
>
> ```auto
> import processing.sound.*;
> class Timbre {
> SinOsc freqF;
> Timbre(SinOsc tmp) {
> freqF = tmp;
> }
> }
> SinOsc tmp = new SinOsc(this);
> Timbre sound;
> void setup() {
> sound = new Timbre(tmp);
> }
> 
> ```

Note that the second one doesn’t error, but it doesn’t play any sound.

---

<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: [June 15, 2020, 2:41am UTC](https://discourse.processing.org/t/this-argument-not-working-correctly/21880/2 "2020-06-15T02:41:08Z")

</div>

> [@Odermonicon](#):
>
> ```auto
> import processing.sound.*;
> class Timbre {
> SinOsc freqF;
> Timbre(Object sketch) {
> freqF = new SinOsc(sketch);
> }
> }
> Timbre sound;
> void setup() {
> sound = new Timbre(this);
> }
> 
> ```

```auto
import processing.sound.*;

Timbre sound;

void setup() {
  sound = new Timbre(this);
}

static 
public class Timbre {
  PApplet p;
  SinOsc freqF;

  public Timbre(final PApplet pa) {
    freqF = new SinOsc(p = pa);
  }
}

```

---

<div class="post-metadata">

### Author: ![Odermonicon](https://avatars.discourse-cdn.com/v4/letter/o/96bed5/32.png) [@Odermonicon](https://discourse.processing.org/u/Odermonicon)
#### Post date: [June 15, 2020, 3:11am UTC](https://discourse.processing.org/t/this-argument-not-working-correctly/21880/3 "2020-06-15T03:11:08Z")

</div>

Very close, but doesn’t actually play anything.

---

<div class="post-metadata">

### Author: ![GSA\_IxD](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gsa_ixd/32/7554_2.png) [@GSA\_IxD](https://discourse.processing.org/u/GSA_IxD)
#### Post date: [February 18, 2022, 7:07pm UTC](https://discourse.processing.org/t/this-argument-not-working-correctly/21880/4 "2022-02-18T19:07:08Z")

</div>

For latecomers to this like me – you need a draw() loop for any sound to actually be heard
