I2S: Stereo input/output

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
mcc
Posts: 14
Joined: Fri Oct 30, 2020 4:41 am

I2S: Stereo input/output

Post by mcc » Tue Dec 01, 2020 4:50 pm

Hi,

I have two INMP441 i2s mems microphones, which each are mono microphones
but can be set to represent either the left or the right channel.
Further I have two MAX98357A I2S amplifiers, again each is a monofonic (monophonic?)
amplifier but can be set two represent either the left or the right channel.

Is it possible to build a circuit with only an ESP32 in the middle and the microphones and the ampllifiers,
which consumes the signal of both microphones (building one stereofonic (stereophonic?) microphone therefore)
signal-process the stream (nothing fancy...may be some filtering) and feed that signal into the amplifiers and
finally make it into a audio signal?

(Currently I am struggling to understand how to combine the two input streams and to split the output stream...)

Or is that a wrong setup right from the beginning?

Cheers!
mcc

User avatar
pythoncoder
Posts: 4914
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: I2S: Stereo input/output

Post by pythoncoder » Tue Dec 01, 2020 6:23 pm

You might like to read this.

tl;dr I2S support on ESP32 is a work-in-progress. There is unofficial working code, but no support yet in the official build.
Peter Hinch

User avatar
Mike Teachman
Posts: 98
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: I2S: Stereo input/output

Post by Mike Teachman » Wed Dec 02, 2020 4:18 am

Cool Project - this is quite doable with one ESP32 which has two I2S channels. First you'll need some I2S capability. You can either apply the I2S PR to a MicroPython build or try out one of the precompiled ESP32 binaries available here: https://github.com/miketeachman/micropy ... s-examples

Two INMP441 mics can be configured for left and right channels. One mic will put samples into the left channel word of the I2S frame, and the other puts samples in the left channel word, creating a stream of stereo I2S frames. Pin 4 "L/R" determines which channel the sample goes. One instance of I2S is needed to read both mics, configured as stereo.

The audio samples are read into bytearrays, and then processed. Here is an example where audio samples are continuously processed in real time -- a dBA meter. The implementation uses uasyncio which I recommend. The dBA meter code is written in C to efficiently implement a 6th order IIR filter.
https://hackaday.io/project/162059-stre ... -real-time

Then, you can configure the DACs in a similar way to the mics. One DAC is configured to response to the right channel word, and the other to the left channel word. Take a look at the SD_MODE pin on the MAX98357A device. Lastly, drive the two DACs with the 2nd I2S instance, again configuring I2S for stereo output.

Hope this is enough to get you started.

What's coming fairly soon: a new PR for I2S that also covers the pyboards v1.1 and D, as well as the ESP32. The API will be the same for pyboards and the ESP32. The pyboard work is pretty much done - an asynchronous buffer oriented implementation with callbacks. I'm currently porting the pyboard work to the ESP32. Maybe end of December to release it? Ultimately the hope is to get this into the mainline. I2S is a quick and easy way to build sound into MicroPython projects.

User avatar
pythoncoder
Posts: 4914
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: I2S: Stereo input/output

Post by pythoncoder » Wed Dec 02, 2020 6:03 am

Good to hear you're still working on this, I'd very much like to see it in official builds for STM and ESP32. The uasyncio integration may depend on @Damien completing his work on select.poll which I believe will be implemented with a scheme to enable uasyncio to prioritise I/O.

A side effect of this hopefully forthcoming release is that I can finally obsolete my uasyncio V2 support with its kludgy workrounds for the bugs in V2. The one current use case for this is the fast_io variant: I believe you are among its users.
Peter Hinch

Post Reply