Two microphone inputs

I wanna know how to get two mic inputs in my p5js code. actually my sound card has two input channels and I wanna process each channel’s signal separated from the other in my code.

1 Like

Check out the example on the getSources() reference page. Not sure if it’s exactly what you’re looking for but hope it’s somewhere to start.

2 Likes

yeah but it discovers 3 input devices which all of them are the same! do you have any solution to define difference between them?

You might have to do some trial and error to see which one is which. I think the extra one is your desktop audio. So that one would have sound on it if you played a video even if your computer is muted. It seems weird that the console log doesn’t have more information. But what’s behind it is the MediaDevices.getUserMedia(). So you can do something like:

  audioGrab.getSources(function(deviceList) {
    console.log(deviceList);
    
    for (let i = 0; i < deviceList.length; i++) {
      console.log(deviceList[i].deviceId);
    }
    
    let micIndex = 0;
    let searchId = "ZiMU0uX4io0elNNAEpeif2qJd226nMu/fUsF2RZ8vbc=";
    for (let i = 0; i < deviceList.length; i++) {
      if (deviceList[i].deviceId === searchId) {
        console.log("Found Mic");
        micIndex = i;
      }
    }
    
    audioGrab.setSource(micIndex);
  });

Unfortunately I think you’d have to change the searchId depending on which computer it’s running on. Also I’d be interested to know if there’s a set order to devices. That way you could just select the microphones based on their order in the list once you find it out but I don’t know if that’s predictable or not.