# Cannot create multiple AudioIn instances

**URL:** <https://discourse.processing.org/t/cannot-create-multiple-audioin-instances/43411>\
**Category:** Libraries\
**Created:** [December 7, 2023, 10:42am UTC](https://discourse.processing.org/t/cannot-create-multiple-audioin-instances/43411 "2023-12-07T10:42:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Irigami](https://avatars.discourse-cdn.com/v4/letter/i/e5b9ba/32.png) [@Irigami](https://discourse.processing.org/u/Irigami)\
**Post date:** [December 7, 2023, 10:42am UTC](https://discourse.processing.org/t/cannot-create-multiple-audioin-instances/43411/1 "2023-12-07T10:42:34Z")

</div>

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`

```js
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):

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [December 7, 2023, 6:09pm UTC](https://discourse.processing.org/t/cannot-create-multiple-audioin-instances/43411/2 "2023-12-07T18:09:24Z")

</div>

Hi @Irigami,

Did you study the reference?

> **[reference | p5.js](https://p5js.org/reference/#/p5.AudioIn)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

Especially

> **[reference | p5.js](https://p5js.org/reference/#/p5.AudioIn/getSources)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

And

> **[reference | p5.js](https://p5js.org/reference/#/p5.AudioIn/setSource)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![Irigami](https://avatars.discourse-cdn.com/v4/letter/i/e5b9ba/32.png) [@Irigami](https://discourse.processing.org/u/Irigami)\
**Post date:** [December 8, 2023, 6:47am UTC](https://discourse.processing.org/t/cannot-create-multiple-audioin-instances/43411/3 "2023-12-08T06:47:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [December 8, 2023, 4:38pm UTC](https://discourse.processing.org/t/cannot-create-multiple-audioin-instances/43411/4 "2023-12-08T16:38:53Z")

</div>

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
