How does I2S work? #3912
-
I'm trying to add audio support for the T-Deck. I've been able to get this QA example to work but I don't really understand it so I can't extend it.
Thank you. I'm documenting all of my lessons to publish new docs. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
At the moment the I2S driver can only be used with DMA. See #2574 Volume can be controlled by adjusting the data. You should be able to just multiply/divide the bytes by some value to adjust the volume. There could also be a hardware volume rocker which can also control/influence the volume but I don't see these often. I'm not too sure how to answer the continuous streaming question. You've seen the example so you know how the streaming I2S APIs work. All I can say is "Do what you want" I guess. If you clarify what kinda of answer you're looking for, I might be able to give a better answer. The frequency can be adjusted here . When I adjusted that I noticed the difference in pitch. |
Beta Was this translation helpful? Give feedback.
-
I’ve made some progress, but I’m still having some trouble. I have successfully been able to stream bytes out of WAV file from an SD card, and then parse the WAV header, but I’m doing something wrong with the circular DMA. It works fine for the first couple of seconds, and then the audio stops and see errors that say the transfer is late. Does that mean I need smaller chunks? Or that I need to do the file loading work in a different order? Here’s the code. The DMA transfer is on lines 278 - 305. https://github.com/joshmarinacci/rust-tdeck-experiments/blob/main/src/bin/streaming_wave.rs |
Beta Was this translation helpful? Give feedback.
I was able to get it to work. Measuring the SD card read speed I was able to get 176kb/sec which is more than enough for a 44.1kb/sec wav stream. The trick was switching to an async circular buffer and only reading in as many bytes as necessary for each DMA. I put some example code here.
The relevant part: