i2s internal dac throughput / overflow somewhere ?

chris33
Posts: 9
Joined: Wed Dec 22, 2021 10:35 am

i2s internal dac throughput / overflow somewhere ?

Postby chris33 » Mon Jan 10, 2022 5:46 pm

Hi all !

I'm coding a small app that generate a real time audio signal on internal dac.

Then in a nutshell, the busy loop is something like that :
  1.   while (true) {
  2.         xSemaphoreTake(mutex, portMAX_DELAY);        
  3.         for (int i = 0; i < AUDIO_BUFFER_SIZE; i++) {
  4.             // compute_stuff
  5.         }
  6.         xSemaphoreGive(mutex);
  7.         samples_proceeded += AUDIO_BUFFER_SIZE;
  8.         size_t i2s_bytes_write = 0;
  9.         ret = i2s_write(I2S_NUM, &samples_buffer, AUDIO_BUFFER_SIZE * 2, &i2s_bytes_write, 100); // size is in bytes - 16bits = 2 x bytes
  10.         if (ret != ESP_OK)
  11.             printf("!"); //Never happened, even once
  12.         not_written += (AUDIO_BUFFER_SIZE * 2) - i2s_bytes_write;
  13.  
  14.         bool done = false;
  15.         while (!done) {
  16.             if (xQueueReceive(i2s_queue, &i2s_event, 100) != pdFALSE) {
  17.                 if (i2s_event.type == I2S_EVENT_TX_Q_OVF)
  18.                     printf("*"); // Never happened, even once
  19.                 done = (i2s_event.type == I2S_EVENT_TX_DONE);
  20.             } else
  21.                 printf("#"); // Never happened, even once
  22.         }
  23.     }
- AUDIO_BUFFER_SIZE is 64 and the i2s driver is configured to use 4 buffers of 64 samples
- "Compute stuff" duration is around 780 micro seconds
- Sample rate is 44100

Each second I display the samples_proceeded variable, and I'm always around 202000 samples per second proceeded - far far over from 44100. How is it possible ???

For what I understand, if there's no free DMA buffer available, the loop would block on i2s_write() or xQueueReceive() would not return I2S_EVENT_TX_DONE and I would never be allowed to produce more data than consumed by the driver.

I might add that the not_written variable is always zero.


What am I missing ?

Note : the code runs on a CORE 1 task (priority 1) with watchdog disabled on CORE 1 and no other task running on the same core except IDLE1

chris33
Posts: 9
Joined: Wed Dec 22, 2021 10:35 am

Re: i2s internal dac throughput / overflow somewhere ?

Postby chris33 » Sat Jan 15, 2022 5:19 pm

I switched to an external DAC, and with the exact same code (minus configuration needed by the DAC) I now have correct statistics...

Never mind, using an external DAC is the way to go in any cases !

Who is online

Users browsing this forum: MicroController and 125 guests