# Two amplitude objects listening to two separate loaded sounds

**URL:** https://discourse.processing.org/t/two-amplitude-objects-listening-to-two-separate-loaded-sounds/29361
**Category:** Libraries
**Created:** [April 14, 2021, 4:31pm UTC](https://discourse.processing.org/t/two-amplitude-objects-listening-to-two-separate-loaded-sounds/29361 "2021-04-14T16:31:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![fbrie002](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fbrie002/32/11663_2.png) [@fbrie002](https://discourse.processing.org/u/fbrie002)
#### Post date: [April 14, 2021, 4:31pm UTC](https://discourse.processing.org/t/two-amplitude-objects-listening-to-two-separate-loaded-sounds/29361/1 "2021-04-14T16:31:34Z")

</div>

Hi!  
I’m trying to figure out a way to have two separate sound files loaded and playing at the same time connect to two separate amplitude objects. At the moment all the sounds just go straight to the first amplitude object declared and the p5.Sound connect function that should be able to link them separately doesn’t have enough documentation or examples.  
Do any of you have experience figuring this stuff out?

Here is a simplified version of my code:

```auto

let sound1;
let sound2;

var sound1_Amp;
var sound2_Amp;

var sound1_Vol;
var sound2_Vol;

function preload(){
    sound1 = loadSound ('assets/sound-1.mp3');
    sound2 = loadSound('assets/sound-2.mp3');
}

function setup() {

    sound1_Amp = new p5.Amplitude();
    sound1.connect(sound1_Amp);

    sound2_Amp = new p5.Amplitude();
    sound2.connect(sound2_Amp);
    
    createCanvas(windowWidth, windowHeight);
}

function draw() {
    background(0);

    sound1_Vol = sound1_Amp.getLevel();
    sound2_Vol = sound2_Amp.getLevel();
    
    fill(255, 0, 0);
    ellipse(100, 100, 50 + sound1_Vol*500);

    fill(0, 255,0);
    ellipse(400, 100, 50 + sound2_Vol*500);
}

```

Thanks for reading, any help would be greatly appreciated!

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [April 14, 2021, 4:56pm UTC](https://discourse.processing.org/t/two-amplitude-objects-listening-to-two-separate-loaded-sounds/29361/2 "2021-04-14T16:56:04Z")

</div>

you need to use `setInput`  
[https://editor.p5js.org/micuat/sketches/SEmDwkB4PQ](https://editor.p5js.org/micuat/sketches/SEmDwkB4PQ)  
(by the way it works on chrome but doesn’t seem to work on firefox)

described here  
[https://p5js.org/reference/#/p5.Amplitude](https://p5js.org/reference/#/p5.Amplitude)

(I personally found p5.sound a bit confusing because they take care of “everything” so unconnected nodes are automatically connected to the master out or amplitude this case, which is sometimes problematic. You can also use tone.js, for example, as an alternative)

---

<div class="post-metadata">

### Author: ![fbrie002](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/fbrie002/32/11663_2.png) [@fbrie002](https://discourse.processing.org/u/fbrie002)
#### Post date: [April 14, 2021, 5:00pm UTC](https://discourse.processing.org/t/two-amplitude-objects-listening-to-two-separate-loaded-sounds/29361/3 "2021-04-14T17:00:58Z")

</div>

oh my gosh thank you so much for the super quick response! 🐥

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [April 14, 2021, 5:03pm UTC](https://discourse.processing.org/t/two-amplitude-objects-listening-to-two-separate-loaded-sounds/29361/4 "2021-04-14T17:03:27Z")

</div>

no problem, also I found the firefox bug is reported here but not solved yet

> <https://github.com/processing/p5.js-sound/issues/499>
>
> As mentioned in the Processing forum, Firefox is returning a strange error while using latest 0.3.12 of p5.sound (Safari + Chrome...

by the way I recommend posting a link to web editor if you have questions (also when you open an issue on github) so others don’t have to create their own sketch!
