Cannot create multiple AudioIn instances

Hi all,
I’m trying to use two audio inputs (2 microphones) in my p5 js project.
It should be noted that I am using the p5 web editor for this.
This simple program results in an error, and I was going to file an issue in the repository, but I thought it would be wise to first run it through a few people to see if it is just me.

Any thoughts would be much appreciated!
Thanks!

Chrome: 120.0.6099.71 (Official Build) (arm64)
OS: MacOSX Sonoma 14.0

function setup() {
  createCanvas(400, 400);
  let mic1 = new p5.AudioIn();
  let mic2 = new p5.AudioIn(1); // Seems to fail regardless of this number
  mic1.start(); // Fails here
}

Results in the error (in the console):

Uncaught TypeError: Cannot read properties of undefined (reading '0')
    at RingBuffer.push (11ef0dc2-268f-48d7-84d9-f0c49ecd0d14:81:76)
    at AmplitudeProcessor.process (11ef0dc2-268f-48d7-84d9-f0c49ecd0d14:193:28)

Hi @Irigami,

Did you study the reference?

Especially

And

Cheers
— mnse

Hi @mnse

I’m not sure I quite understand how to use these in this context. There’s no mention of anything I can see that is useful for multiple AudioIn instances. I’ve tried all of the examples in the references, and none of them seem to work when you add a second input (all fail at the first call to start()).

Thanks for your time.

Hi @Irigami,

In principle do s.th. like this …

  • Create an AudioIn Object
  • Call the getSources() from it to see if and how many sources are available.
  • If there are sources available
  • Create an AudioIn and setSource(0) for the first, and create another AudioIn and setSource(1) if it is available.
  • Start both by start().
  • Check on each step for errors…

Check the references I’d posted earlier for possible restrictions or prerequisites…

Cheers
— mnse