stream protocol for I2SIn#11064
Conversation
|
The streaming protocol depends on The memento (esp32s3) also had it disabled so I turned off |
dhalbert
left a comment
There was a problem hiding this comment.
This looks good -- I did not go over the buffering code in full detail, but it is working well.
| mp_obj_base_t base; | ||
| // MUST be first so I2SIn can be used directly as an audiosample source. | ||
| audiosample_base_t base; | ||
| uint32_t sample_rate; |
There was a problem hiding this comment.
This could be replaced by self->base.sample_rate.
There was a problem hiding this comment.
In the raspberrypi port the values for self->base.sample_rate and self->sample_rate end up being slightly different due to the pio clock frequency. The adjusted one is set here: https://github.com/FoamyGuy/circuitpython/blob/78d44093eae7f3b3d459bd4d836ee7140d560f41/ports/raspberrypi/common-hal/audioi2sin/I2SIn.c#L268
and comment here tries to explain the rational: https://github.com/FoamyGuy/circuitpython/blob/78d44093eae7f3b3d459bd4d836ee7140d560f41/ports/raspberrypi/common-hal/audioi2sin/I2SIn.c#L288-L293
Without this fix in place there was some sort of audible artifact in the captured sound.
I hadn't actually finished my review yet and was still going through the buffer code and other port implementations. I figured I'd just put it here now since y'all merged it. I'm fine with that, and I'm working on revisiting the PDMIn implementation to follow along these changes. I might roll in some cleanup along the way. |
This allows
audioi2sin.I2SInto be used in effects chains with various audio modules, and to be piped to an output source like AudioOut or USBMicrophone. Prior to this change I2SIn has only a simplerecord()API.I tested with this basic code that passes audio from the I2S mic to USB as a microphone to the host computer, turning the MCU into a functional USB microphone.
I also successfully tested a version with a handful of effects between the input and output so the device acts as a voice changer. I verified the original record API .wav file example works as expected as well.