Processing on Multiple Sound Files

Is there a way to apply multiple processes from the p5 sound library onto multiple sound files without calling to connect each sound file to the specific function? i.e. any way to combine all outputs of sound files so I can reverb everything or pan everything?

I think they all have to be connected to something to play sound, and that’s how it works with Web Audio API (on which p5.Sound is built); otherwise, the program has no clue if you want to connect the sound to a reverb filter, to the output or to an FFT analyzer, for example (and you can create many of those audio nodes). If you have many sound files, perhaps you should use an array or a map to iterate.

Gotcha! So how would I do that with my code where I have one sound file linked to one sound process? Would I set up the songs in an array and then loop through to connect and process? Would that break my code for any reason? I noticed when I tried to set up two reverbs, for example, it broke my code haha

let video;
let poseNet;
let poses = [];
let skeletons = [];
let nose, rightWrist, leftWrist, rightKnee, leftKnee;
let nScore, rwScore, lwScore, rkScore, lkScore;
let song, song2;
let dholButton, algozeButton;
let delay, rev;
let filRes, filFreq;

function preload() {
  soundFormats('mp3', 'ogg', 'wav');
  song = loadSound('dhol_main_loop.mp3');
  song2 = loadSound('algoze_silence.wav');
  //song3 = loadSound('sarangi_main_loop.wav');

}

function modelLoaded() {
  console.log("Model Loaded");
}

//setup code
function setup() {
  cnv = createCanvas(640, 480);
  video = createCapture(VIDEO);
  video.size(width, height);

  dholButton = document.getElementById("dholButton");
  dholButton.addEventListener("click", handleDholButtonClick);

  /*
  algozeButton = document.getElementById("algozeButton");
  algozeButton.addEventListener("click", handleAlgozeButtonClick);
*/

  poseNet = ml5.poseNet(video, modelLoaded);
  poseNet.on('pose', getPoses);
  video.hide();

  delay = new p5.Delay();
  song2.connect();
  delay.process(song2, 0.12, 0.5, 2300);
  delay.setType('pingPong');
  delay.delayTime(0.0);
  delay.amp(0.0);

  rev = new p5.Reverb();
  song.connect();
  rev.process(song, 3, 2);
}

function draw() {
  //mirrors image 
  translate(video.width, 0);
  scale(-1, 1);
  image(video, 0, 0, video.width, video.height);

  //draws dots on nose, wrists, and knees
  drawPoints();

  //delays algoze with LW y-position
  //reverbs dhol with LW x-position
  if (leftWrist) {
    delayAudio();
    reverbAudio();
  } else {
    return;
  }

  //pans dhol with nose x-position 
  panning();
}

//identifies body parts using posenet
function getPoses(poses) {
  if(poses.length > 0) {
    let pose = poses[0].pose;

    nose = pose.keypoints[0].position;
    nScore = pose.keypoints[0].score;

    leftWrist = pose.keypoints[9].position;
    lwScore = pose.keypoints[9].score;

    /*
    rightWrist = pose.keypoints[10].position;
    rwScore = pose.keypoints[10].score;

    leftKnee = pose.keypoints[13].position;
    lkScore = pose.keypoints[13].score;

    rightKnee = pose.keypoints[14].position;
    rkScore = pose.keypoints[14].score;
    */
  }
}

//draws points on nose, wrists, knees 
function drawPoints() {
  if(nose && nScore > 0.6) {
    stroke(255, 0, 0);
    strokeWeight(15);
    point(nose.x, nose.y);
  }

  if(rightWrist && rwScore > 0.05) {
    stroke(0, 255, 0);
    strokeWeight(15);
    point(rightWrist.x, rightWrist.y); 
  }

  if(leftWrist && lwScore > 0.05) {
    stroke(0, 0, 255);
    strokeWeight(15);
    point(leftWrist.x, leftWrist.y);
  }

  if((rightKnee && leftKnee) && (rkScore && lkScore > 0.6)) {
    stroke(255, 0, 0);
    strokeWeight(15);
    point(rightKnee.x, rightKnee.y);
    stroke(255, 0, 0);
    strokeWeight(15);
    point(leftKnee.x, leftKnee.y);
  }
}

//button handlers
function handleDholButtonClick() {
  if(song.isLooping()) {
    dholButton.innerText = "Start Dhol";
    song.stop();
  } else {
    dholButton.innerText = "Stop Dhol";
    song.loop();
  }
}

/*
function handleAlgozeButtonClick() {
  if(song2.isLooping()) {
    algozeButton.innerText = "Start Algoze";
    song2.stop();
  } else {
    algozeButton.innerText = "Stop Algoze";
    song2.loop();
  }
}
*/

//uses nose to pan dhol 
function panning() {
  if(song.isLooping() && nose) {
    let panning = map(nose.x, 0, width, 1.0, -1.0); //pan right on 1 and left on -1
    song.pan(panning);
  } 
  if(song2.isPlaying() && nose) {
    let panning2 = map(nose.x, 0, width, 1.0, -1.0);
    song2.pan(panning2);
  }
}

//uses left wrist's vertical pos to delay algoze
function delayAudio() {
  if(leftWrist && lwScore > 0.05) {     
      let delTime = map(leftWrist.y, 0, width, 1.0, 0.05);
      delay.delayTime(delTime);
      //console.log("Delay Time: " + delTime);

      delay.amp(1.0);
  } 
  else {
    delay.delayTime(0.0);
    return;
  }
  song2.playMode('untilDone');

}

//uses right wrist's horizontal pos to alter dry/wet of dhol
function reverbAudio() {
  if(leftWrist && lwScore > 0.05 && song.isLooping()) {
    let dryWet = constrain(map(leftWrist.x, width, 0, 0, 1), 0, 1); 
    rev.drywet(dryWet);
  } else {
    rev.drywet(0);
    return;
  }
}

function keyPressed() {
  if(keyCode === LEFT_ARROW) {
    song2.play();
  }
}