Sample audio directly on the onboard ADC #11504
-
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
On other ports (e.g. STM32) we support Unfortunately this is not (yet) supported on ESP32. If you want this to run in the background while the code does other things, your best bet is to use a timer and read from the ADC in the interrupt handler. I recommend pre-allocating the output buffer so that the handler doesn't have to do any allocations. Unfortunately the sample rate will not be terrible high. If you just want to sample as fast as possible, then calling ADC.read in a loop (optionally with time.sleep_us), but there will be quite a lot of jitter in the sampling interval. |
Beta Was this translation helpful? Give feedback.
-
See also #10561 |
Beta Was this translation helpful? Give feedback.
On other ports (e.g. STM32) we support
adc.read_timed
which allows the ADC to be sampled at a fixed rate.Unfortunately this is not (yet) supported on ESP32.
If you want this to run in the background while the code does other things, your best bet is to use a timer and read from the ADC in the interrupt handler. I recommend pre-allocating the output buffer so that the handler doesn't have to do any allocations. Unfortunately the sample rate will not be terrible high.
If you just want to sample as fast as possible, then calling ADC.read in a loop (optionally with time.sleep_us), but there will be quite a lot of jitter in the sampling interval.