ESP8266Audio icon indicating copy to clipboard operation
ESP8266Audio copied to clipboard

Telling when the audio actually gets out ?

Open Maigre opened this issue 2 years ago • 1 comments

Hi, I am a regular user of your library, thanks for the good work!

I am trying to achieve a specific use case where i trigger a GPIO when playing a sound. I need a sub 1ms accuracy. I use an external PCM5102 over I2S and read WAV file from an SD card.

Right now i do

while(true) { if (!wav->isRunning() || !wav->loop()) break; digitalWrite(21, HIGH); } digitalWrite(21, LOW);

But i have ~24ms delta between gpio trigger and actual audio out. I guess it's due to dma_buffer + maybe some PCM buffering + maybe some initial SD read latency ?

What i am looking for is a way to now when data are actually sent to the PCM chip over I2S, and even better if you know some way to tell when audio actually get out of the chip..

Could you hint me where in the code i could hook such informations ? i am trying to warp my head around the I2S flow path but i am a bit lost rigth now..

Maybe i could calculate it from dma_buf_count / dma_buf_len / buffersize / sample_rate ? But then how to account for the initial variable time to fill the buffer from SD card ?

I'll continue to look on my own and report back if i find interesting ways to trigger something accurately when audio is actually playing out.

Thanks ! Best Regards,

Thomas

Maigre avatar Mar 18 '23 09:03 Maigre

Did you ever find a solution for this? I would start by looking around https://github.com/earlephilhower/ESP8266Audio/blob/master/src/AudioOutputI2S.cpp#L326 and i2s_write

ChuckMash avatar Dec 19 '23 18:12 ChuckMash