Page 1 of 1

Best solution handling ADC-DAC for simple audio effects processor

Posted: Mon May 27, 2019 8:10 pm
by tom303
Hi!

I'm trying to add a simple audio effects processor to my project. (mono in - stereo out - chorus effect)

Audio input via the onboard 12bit ADC, output via a stereo 12bit SPI DAC.
Sampling rate needs to be at least 32kHz, so there's about 31µs time for AD-conversion, processing and DA conversion.

Pseudo code:

loop @ 32kHz
{
adc_reading
audio processing
dac_writing
wait until 1/32000s are over
}

HSPI and VSPI are already in use for other things, so I tried to bitbang data to the DAC chip, which works fine and only takes about 6µs for sending out a set of stereo samples. The audio effect algorithm only takes a few µs either. So there's about 15µs left for ADC sampling.

My first approach was using a timer at 32kHz and to read single samples with "adc1_get_raw". However "adc1_get_raw" takes 40µs for one sample, which is too long unfortunately.

I am now looking into I2S and DMA, but I haven't found out how to make it work for my specific application.
I can make it work by accessing the DMA buffer, but since my loop and the i2s sampling rate are not perfectly in sync, I am having terrible jitter noise. I don't know how to sync my loop to the I2S sampling rate. I need some kind of trigger/interrupt for every input sample.

Ideally I'd want to use i2s_read to grab a single sample and let it controll the timing of my loop, but since I cannot set the buffer size to 1 sample, the only way to get samples is in packets of 8 or more.

Clearly I am lacking knowledge here :)

Any kind of help is much appreciated!
Thank you very much

Re: Best solution handling ADC-DAC for simple audio effects processor

Posted: Tue May 28, 2019 7:49 am
by tom303
I have just found out that while adc1_get_raw() takes 40µs, analogRead() only takes 10µs. So my effects processor is now working. :)

But maybe there's overall a better solution for what I'm trying to do.

best

Re: Best solution handling ADC-DAC for simple audio effects processor

Posted: Tue May 28, 2019 8:44 pm
by chibill
https://docs.espressif.com/projects/esp ... s_source_t can be used to attach I2S to the ADC for sampling :) Hope this helps.

Re: Best solution handling ADC-DAC for simple audio effects processor

Posted: Wed May 29, 2019 9:02 am
by tom303
Unfortunately not, but thanks anyway. ;)