miketeachman / micropython-esp32-i2s-examples

Usage and examples for I2S support on the ESP32 microcontroller
MIT License
152 stars 29 forks source link

Increasing sample rate #4

Closed asturkoglu closed 4 years ago

asturkoglu commented 5 years ago

I want to increase sample rate to 44k, or 24k, 32k. I tried to play with BITS_PER_SAMPLE, BYTES_PER_SAMPLE (/# side), SAMPLES_PER_SECOND, but I couldn't find the correct ratio. Something above 20k is ok for me. I adjusted these values to 8-8-32k, 16-4-32k, 16-8-32k, 16-16-32k, 24-8-24k, 24-8-32k. 16-8-32k and 16-4-32k skip bytes I guess, because record time is correct but recording is weird. 16-16-32k records in 2x speed. How should I adjust these numbers? Previously, I was recording with these code, but its different platform: const int headerSize = 44; const int waveDataSize = record_time * 88000; const int numCommunicationData = 8000; const int numPartWavData = numCommunicationData/4; byte header[headerSize]; char communicationData[numCommunicationData]; char partWavData[numPartWavData]; Additionaly, this code records with 16bits precision, but I2S sends 24bits. Whats happening to these 8 bits and why we re not recording with 24bits precision. I know 16bits is a good quality, but I just want to learn.

miketeachman commented 5 years ago

Hi. Thanks for trying out this pull request!

Here are some ideas on your questions.

To increase the sample rate try modifying only one parameter: SAMPLES_PER_SECOND

In the first example, (record with 16 bit resolution) every audio sample is reduced from 18-bit resolution to 16bit resolution - this reduces amount of data written to a SDCard, which reduces the risk of the DMA buffer overrunning (losing audio samples).

There is a MicroPython example that records in 32bit resolution. That should work for a 24bit microphone. record 32 bits

I recommend experimenting with the record 32 bits example to see what sample rate can be supported before DMA overrun happens.

I'm interested in feedback on these suggestions ...

miketeachman commented 4 years ago

No response from submitter. I am assuming that they used the posted answer to implement a higher sampling rate.