# P5.sound: Connecting an Oscillator to a Gain

**URL:** <https://discourse.processing.org/t/p5-sound-connecting-an-oscillator-to-a-gain/9097>\
**Category:** Libraries\
**Created:** [March 7, 2019, 9:55pm UTC](https://discourse.processing.org/t/p5-sound-connecting-an-oscillator-to-a-gain/9097 "2019-03-07T21:55:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wvnl](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/wvnl/32/4057_2.png) [@wvnl](https://discourse.processing.org/u/wvnl)\
**Post date:** [March 7, 2019, 9:55pm UTC](https://discourse.processing.org/t/p5-sound-connecting-an-oscillator-to-a-gain/9097/1 "2019-03-07T21:55:56Z")

</div>

I’m unsure how the p5 gain node works with an oscillator connecting to it, I’m not having any luck using either connect() or setInput().

The following just ignores the gain node:

```auto
var osc;
var gain;

function setup() {
  createCanvas(400, 400);
	gain = new p5.Gain();
	gain.connect();
	osc = new p5.Oscillator('sawtooth');
	osc.connect(gain);
	osc.amp(0);
	osc.start();
}

function draw() {
  background(220);
	osc.freq(60 + mouseX * 2);
	gain.amp(map(mouseY,0,height,0,1), 0.1);
}

function mousePressed() {
	osc.amp(1, 0.1);
}

function mouseReleased() {
	osc.amp(0, 0.1);
}

```

Any help appreciated!
