7
\$\begingroup\$

I've heard that the ESP32's ADC isn't "good" enough for audio purposes. It's a 12 bit SAR ADC with a sampling rate of 200 ksps which is much higher than most consumer products use (44.1 kHz). Does 200 ksps not correlate to a 200 kHz sampling rate. I couldn't find much in the datasheet when it came to calculation times. What am I missing?

\$\endgroup\$
7
  • 6
    \$\begingroup\$ The resolution could be an issue, most consumer audio is 16bits or higher \$\endgroup\$
    – chamod
    Nov 6 '20 at 6:58
  • 6
    \$\begingroup\$ What audio 'purposes' do you need it for? \$\endgroup\$ Nov 6 '20 at 7:17
  • 2
    \$\begingroup\$ A warm welcome to the site. It's a Q&A site, not a discussion forum, and this is far too vague a question. It's based around a couple of words of nondescript hearsay from completely unreferenced sources. Please edit your question and greatly improve it, explaining specifically and exactly what are you are trying to do and why. The better the quality of your question, the better the quality of the answers you will attract. Again, welcome. \$\endgroup\$
    – TonyM
    Nov 6 '20 at 7:27
  • 9
    \$\begingroup\$ Define "good enough" ... 12 bit correctly implemented should be in the ballpark of a cassette tape ... not great but some of us survived the 1970s... \$\endgroup\$ Nov 6 '20 at 12:40
  • 2
    \$\begingroup\$ I've tried to use ESP8266 ADC for audio. It worked, until I enabled wifi - the radio transmissions make very loud noise in the ADC samples. \$\endgroup\$
    – jpa
    Nov 8 '20 at 12:10
13
\$\begingroup\$

I agree with Justme's answer that the DNL/INL is quite high, and also call your attention to this sentence:

By default, there are ±6% differences in measured results between chips.

This matters less for audio applications where the DC level can be normalised later, but for other applications it will definitely require calibration.

There is also a general concern for any ADC on the same chip as digital circuitry: power supply rejection ratio (PSRR). This is the ability to avoid conducting noise from the power supply into the analog results. Since no mention is made of using an external reference voltage, or separate analog power/ground, or a PSRR number, I suspect this is very bad.

What that is likely to mean that every power burst from the radio side gets conducted straight into the audio.

Ultimately the easiest thing to do is try it; if it's not up to your percieved quality standards, you'll want an external ADC with its own little linear regulator and separate area of the PCB. But the built-in ADC is probably adequate for phone-quality speech or music played through tinny cheap speakers.

\$\endgroup\$
10
\$\begingroup\$

Audio is about more than just sampling rate and bits. Other parameters are significant as well, such as linearity, monotonicity, noise, distortion, etc.

The ESP32 ADC has DNL of +/- 7 counts. It means that for any voltage measured, the result can be wrong by that amount. This already means the ADC may have missing codes and may not be monotonic.

The ADC measurements are also performed while there is a 100nF capacitor filtering a DC signal that is measured.

So while it could be used to sample audio, it would require a lot of analog signal conditioning to filter and buffer the signal into ESP32 with low enough impedance, and perhaps using oversampling and signal processing to get acceptable quality audio that cannot even reach 12 bits.

So it would be far simpler to just connect a simple audio ADC chip to the I2S bus and it would easily exceed CD quality in terms of bits, linearity, SNR and sampling rate.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ What\ does DNL mean? \$\endgroup\$
    – Jacob Lara
    Nov 7 '20 at 7:40
  • 2
    \$\begingroup\$ If you already have not found it by now, it means differential non-linearity. For more info see Atmel appnote "Understanding ADC Parameters" or Wikipedia page on "Analog-to-digital converter". \$\endgroup\$
    – Justme
    Nov 7 '20 at 10:27
9
\$\begingroup\$

Dynamic Range expressed as Effective Number of Bits (ENOB) is another way of expressing Signal to Noise Ratio (SNR):

ENOB: SNR = 6.02*N + 1.76 [dB]

So with resolution
N=24 SNR=146dB
N=20 SNR=122dB
N=16 SNR=98dB
N=14 SNR=86dB
N=12 SNR=74dB
N=8 SNR=50dB

We often use this in characterizing the noise floor of an ADC system, where N is the actual number of bits, and ENOB is the "effective" number of bits. A 16-bit system with 92dB SNR from various noise sources, is effectively comparable to a 15-bit system with noise only from quantization error. There are other noise sources besides quantization error, we just use ENOB to express effective number of bits because quantization error is the one noise source that we can never get rid of.

While dB is a general-purpose ratio unit, for audio applications it is related to the Sound Pressure Level or loudness of a sound. At 16-bit resolution, the ratio between the loudest expressible signal sound and the "noise level" of the inherent quantization noise, would be 98dB -- painfully loud. So 16-bits is enough resolution to capture good quality audio, at least in terms of dynamic range.

However, a 12-bit resolution ADC system has at best a signal-to-noise ratio of only 74dB, so while it would be able to capture sound at some level, the background hiss will be noticeable. For telephone it might be acceptable, but for music the background hiss would be objectionable.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ When you are oversampling a signal by a factor of 4 (200 ksa/s instead of 44.1), you can increase your ENOB by 2 additional bits. Surely that’s what OP alludes to when bringin up ”200 ksps which is much higher than most consumer products use”? Granted, even 14 bits isn’t great. \$\endgroup\$
    – jms
    Nov 6 '20 at 8:14
  • 3
    \$\begingroup\$ @jms You can improve SNR by 1 bit for 4x oversampling, making some reasonable assumptions about the noise. However, it may not improve the spurious or distortion at all. \$\endgroup\$
    – Neil_UK
    Nov 6 '20 at 8:43
8
\$\begingroup\$

Many calculations here already, so I won't go there and try for a different answer.

Whether the ESP32's ADC is good enough or not depends on what quality audio you want, and the quality of your playback chain.

I experimented a bit and sampled some music with the ADC peripheral on a SAMD21G, not using the full 12-bit and 350ksps but 12 bit, 32khz sampled down to 8 bit.

To my ear, cheap computer speakers playing back the 8-bit, 32kHz PCM sound about the same as when fed with CD-quality music, while the same 8-bit, 32kHz PCM won't do at all when played on the equipment I normally listen to.

If the ESP32's ADC is good enough for audio depends on what quality you want and the quality of the rest of the audio chain. The only way to find out is to try it.

If you have quantifiable expectations though, like "CD-quality", you can do the math (and then try it).

\$\endgroup\$
3
\$\begingroup\$

There might be another issue with the ESP32 as a systemic one:

aside from your ADC supplying samples, your CPU must be able to do something with these samples, before the next sample happens.

Often, that's no big issue, at least at audio-typical sampling rates: simply have a DMA controller copy the samples from ADC to a RAM buffer, and then regularly process whatever has amassed in that buffer with the CPU.

Now, what could happen in your use case is that there's Wifi-handling firmware that occasionally needs to grab the CPU core, and needs to do a couple calculations, so that the time window to process the buffer before it's full passes.

I don't know whether that's the case in the ESP32 architecture – other Wifi-integrating MCUs do in fact do a couple of things in CPU software that preempts whatever executes on the CPU occasionally.

\$\endgroup\$
5
  • \$\begingroup\$ The ESP32 has two cores, the ESP8266 has one (and I think the latter uses the ADC for WiFi signal strength measurements as well). \$\endgroup\$
    – ocrdu
    Nov 6 '20 at 15:33
  • \$\begingroup\$ @ocrdu if the core where the ADC is connected to on the ESP32 is never occupied by any time-critical Wifi stuff (e.g. cryptographic challenges etc), then this is no problem \$\endgroup\$ Nov 6 '20 at 15:40
  • \$\begingroup\$ If I recall correctly, the ESP32 has two ADCs. However, if you have any BLE/WiFi operations, ADC2 is completely turned off. This limits the pins you can connect your input to just ADC1. \$\endgroup\$
    – Gliderman
    Nov 6 '20 at 20:13
  • \$\begingroup\$ @Gliderman aha! But that would imply that in fact, if both ADCs are attached to the same CPU core, then that CPU core might occasionally be busy with dealing with BLE/WiFi; if ADC2 is shared among the CPU core and the embedded BLE/wifi core, then nto. \$\endgroup\$ Nov 6 '20 at 20:51
  • \$\begingroup\$ I thought I remembered reading somewhere that BLE/WiFi physically used the ADC2 hardware in its operation, not that it was specifically tied to a core, but I can't seem to find it again with a quick search. Since I last needed ADC and BLE on an ESP32, it appears there's been updates to a GitHub issue on this, which may contain a fix for those interested: github.com/espressif/arduino-esp32/issues/102 \$\endgroup\$
    – Gliderman
    Nov 6 '20 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.