Two amplitude objects listening to two separate loaded sounds

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:

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();

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

function draw() {

    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!

1 Like

you need to use setInput
(by the way it works on chrome but doesn’t seem to work on firefox)

described here

(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)


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

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

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!