esp32c3-lyra board: No DAC, no problem! Audio over PDM#10643
esp32c3-lyra board: No DAC, no problem! Audio over PDM#10643dragonx wants to merge 2 commits intoadafruit:mainfrom
Conversation
The I2S data pin is hooked up directly to the amplifier on this board, so while it does generate sound, it sounds terrible since it's not actually handling the data signal. The sample implementation in the esp-adf uses the I2S hardware with PDM encoding to drive the amp. https://github.com/espressif/esp-adf/blob/ad4ac707c5dffb450dbabfdcaa7443165ee4e852/examples/player/pipeline_spiffs_mp3/main/play_spiffs_mp3_example.c#L76 This change hardcodes the PDM implementation for this board.
|
This is my preferred approach. The docs already note that the platform gets to decide the frequency of the PWM pulses so we can make it a little less specific to encompass PDM. |
So have some sort of #ifdef or variable in Also I'm just ramping up on this. I couldn't find an |
Nope, just implement audiopwmio for Espressif using PDM for everyone.
Yup! Add ports/espressif/common-hal/audiopwmio with the implementation and enable it by setting CIRCUITPY_AUDIOPWMIO=1. I'd suggest using starting with another implementation and clearing out the function bodies. You could try an LLM with your existing changes to see if can mash the two together for you. |
|
@tannewt thanks for the input. I'm not likely going to get to this next week, so it'll be a little while. |
Works for me. Thanks! |
This PR is a proof of concept, but need some discussion on how to handle this "properly".
The esp32-c3-lyra board has no DAC, but the i2s data pin is connected directly to an audio amplifier.
Using the
audiobusiolibrary, I was able to play music on this board, but it sounded terrible.Comparing the i2s implementation in CircuitPython vs the working sample in the
esp-adfdev kit, it turns out that the dev kit isn't using true i2s, but the i2s hardware has a PDM output mode. This prototype forces the i2s output pin into this PDM mode.The reason it's implemented in
audiobusio/I2SOut.cright now is because I started looking at the I2S peripheral, and this file is where the I2S peripheral code is. However, it seems to not belong here for a few reasons: a) it's not really running in I2S mode, b) it's using a single pin, so theaudiobusioAPI that uses multiple pins doesn't make sense.Against argument a) above though, there is an
audiobusio.PDMInAPI that takes one pin. It seems like the logical followup would be to have anaudiobusio.PDMOutAPI.Another alternative that comes to mind is the
audiopwmioAPI, which is a "natural" place for beginners to go, since it's used in a bunch of examples. The API would look the same, except that the name is wrong by one letter. Perhaps adding a flag or PWM vs PDM, or anaudiopwmio.PDMAudioOutAPI.