We don't need a DAC - ESP32 PDM Audio
HTML-код
- Опубликовано: 30 сен 2024
- The ESP32-S3 doesn't have a DAC - that's no problem for us! Thanks to PCBWay www.PCBWay.com... for sponsoring the channel.
I've been using I2S to output PCM data to an amplifier - but recently I've been using a board that only has a buzzer. Can we get audio to come out of it? Of course we can!
Sample code is here: github.com/ato...
---
If you'd like to help support the channel and help me buy more nonsense - I have a Patreon page: / atomic14
We've also got a shop now! shop.atomic14.com
And if you're shopping on AliExpress or Amazon then if you click on these links I will get a little bit of affiliate money:
Aliexpress - s.click.aliexp...
Amazon - www.amazon.com...
You can also join us on Discord here: / discord
There's also the Atomic14 newsletter here: atomic14.subst...
And don't forget about the MakerNews newsletter - makernews.subs...
If you'd like to help support the channel and help me buy more nonsense - I have a Patreon page: www.patreon.com/atomic14
We've also got a shop now! shop.atomic14.com
And if you're shopping on AliExpress or Amazon then if you click on these links I will get a little bit of affiliate money:
Aliexpress - s.click.aliexpress.com/e/_Ac05mF
Amazon - www.amazon.com/?tag=atomic14-20
You can also join us on Discord here: discord.gg/h2DDnDdjD2
There's also the Atomic14 newsletter here: atomic14.substack.com/
And don't forget about the MakerNews newsletter - makernews.substack.com/
Wow... another stunning video. I had known about PWM but PDM is news to me. Looks like I've got some light reading to do before bed tonight. Thanks for this - continued Success!
Thanks! Hopefully the code on GitHub is understandable. It was knocked together pretty quickly.
Class D amplifiers do something very similar to this :D I've used this technique too with an LCD screen and an Arduino Uno to adjust the contrast. It's very handy :D
Yeah, it's very similar to what Class D amplifiers do which is why you can just drive a speaker directly from a PDM signal (with the right driver of course!)
I have a question on this, If I use a class D amplifier on a pwm signal will it be able to drive a speaker?
Uxed to use this in the 80's in small audio warning devices, if I remember correctly there was a chip that took the one bit serial stream and produced an audio output. You could get a longer message in the small capacity eproms available at the time, no micro controllers about then.
Reminded me of the old 8 bit comouter crappy speakers. The things people managed to get out of them was quite impressive.
there was a program on the PET that played polyphonic music on one gpio pin. was very impressive for the time. one day i'll look through all my disc's and see if i've still got it.
@@TheEmbeddedHobbyist I still remember being amazed by the Manic Miner intro screen on the ZX Spectrum. Compared to what I could do with the BEEP command it was incredible.
Are you talking about a CVSD Modulator chip?
@@any123-og delta sigma rings a bell. it's been a long time. but i still have a board somewhere, if i find it i'll see what the chip was.
That's awesome! Yay for not needing a DAC !!!!!
It still is a DAC, in final result u have analog signal reconstructed from digital code. There is whole branch of audio equipment which use 1bit sampling, it is commonly known as DSD. Sony and Philips used it for Super Audio CD, sample rates are around 2,5 to 6 MHz. There are even digital audio mixing consoles that use DSD, but this technology is pretty niche, as its having superior quality to PCM is mostly a marketing mambojambo.
Seems both were connected to same wall outlet, so the shared ground made it function seeminlgy
Thank you, I didn't know that about PDM. I tried to play PDM on one channel, format only left, and got the same sound as on two from your example. I still don't understand what the difference is, if the sound is the same?
The above code is not working for the Seeed Studio ESP32 S3. Please can you give me the updated code for that.
What is theoretical maximum frequency/sample rate for s3's pdm?
I think 48KHz - according to this GitHub issue - github.com/espressif/esp-idf/issues/10420
Great intro to PDM, thanks. What's happened to your microphone signal though? Distorted for most of it, and lots of compression artefacts (warbling) in the closing comments. I thought you were going to reveal it had all gone through the PDM, but I guess it wasn't that?
Had all sorts of issues with the recording, lots of variable audio levels that needed fixing. Turned into a complete nightmare. Realised that I'd forgotten to connect my mic a few times.
Out of the blue a mention of "Delta-Sigma Modulation". What's that. What's that got to do with anything? How does that tie to the video?
Sorry - that should have been more clear. It's how PDM signals can be generated - en.wikipedia.org/wiki/Pulse-density_modulation
Thanks for posting that! Confirms something I saw on greatscott channel. So basically. a DAC is essentially a fancy overhyped RC filter?
The rumour is that the DAC took up a lot of die space and there wasn’t enough room which might explain why the S3 is the fastest ESP32 chip available granted it doesn't have the radios the C6 and H series have.
For most use cases PWM or PDM is sufficient. For more complex cases you are probably looking for some very specific performance characteristics and an external IC probably makes more sense.
This video just points out that you don't need a DAC on the S3 for an audio use case and can use a discreet RC. You can do the same with the Pi Pico which doesn't have a DAC either.
Worth noting that since ESP-IDF 5.0 and its new I2S driver you don't have to waste a pin on clock signal if you don't use it, and you can also output stereo PDM channels separately (see the `line_mode` parameter).
Great !!!
I used pdm with esp32 few years back in my game project.I had some trouble making it sound nice. Also tried the 8bit DA and was not happy. Finally made things easy for me and used some 2 euro 1 watt i2s amplifier boards from aliexpress.
Thank you for sharing this awesome feature.
Is it possible to make a video in which you discuss the code implementation? because I find it hard to understand
Please break out all esp32 pins, even if in use, so others can extend your good work
Why not just add a separate DAC integrated circuit chip to the design? They are very cheap to buy and take up very little area on a circuit board.
It sounds very good, thanks.
Thanks - it’s not bad at all. With a better filter than a simple RC you can get even better results.
Esp32 users have bitbanged 3d animated video signals with audio direct to a uhf tv.
Theres also a great basic interpreter for it
Hi,
You mention @8:40 that GPIO 45 and 46 can't be used for anything but in the datasheet for the ESP32-S3 on page 23 it explains how these pins together with GPIO 0 and 3 are the strapping pins and that "...the pins are freed up to be used as regular IO pins after reset."
They tend to be disconnected on a lot of boards and designs because the danger of interfering with the boot process is so high.
That's quite cool! What project do you use it in?
Awesome video. thanks for sharing.
Thats really cool, considering you could build something thats value far exceeds its worth
Need a doomsday mesh radio network with voice calls for like $2.50 each. Give it a solar panel but no battery. Hella swag.
nice! How do you generate that audio file with audacity? could there be 3 buttons that each play out separate short wav in esp32 ?
I wrote a little python script to simulate PDM and wrote it out as a WAV file - I'll clean it up and put it into the GitHub repo. Playing multiple WAV files should be pretty straight forward. The main limitation is how much you can fit in the SPIFFS filesystem - which will depend on how much flash you have on your module.
I can't listen to this song without thinking of the "Logan you are my hero" cover 🤣
I had to go and search for it didn’t I - and now I can’t get it out of my head!
Why use the S3 for this application?
I would use the I2S on the original ESP32 and use DMA to send the data out.
Very interesting tho...
The DAC on the original ESP32 was pretty noisy. In theory with PDM output you can get good quality output.
@@atomic14 I've never tried it. Thanks for the free knowledge.
Original ESP32 doesn’t have DMA, does it?
@@crosswick I think all the versions have DMA. I've certainly used DMA with I2S on the original ESP32.
Nicely done!
What is the software used at 5:32?
It’s a tool called Audacity - it’s a great free tool for dealing with audio files.
I usually use a PWM for this on AVR MCU's, since it also works through a low pass and needs minimal CPU intervention. Does the ESP32 not offer PWM?
Yes, you can do that - but then you’ll need a timer that fires on every sample to get audio output. With this we can use the I2S peripheral and use DMA to send the data out.
@@atomic14 ahh, I see what you mean. Needing to load new waveform points individually in a timer ISR can be expensive.
Ok nerd