Open aCaB opened 4 years ago
For what it's worth, it's possible to work around the problem in different ways.
One way is simply to discard the initial values read (up to the size of the dma buffer). This however introduces some latency.
Another way is to manually reset the state of the internal dma pointer. This is tricky as there seems to be no way to quickly set dma->curr_ptr to NULL via the api. Nonetheless it's possible to force a full dma buffer reallocation by changing bits_per_sample to a different value and back. E.g. assuming your desired bits_per_sample value is 16, you can add the following in between i2s_adc_disable and i2s_adc_enable:
i2s_set_clk(I2S_NUM_0, EXAMPLE_I2S_SAMPLE_RATE, 24, 1);
i2s_set_clk(I2S_NUM_0, EXAMPLE_I2S_SAMPLE_RATE, 16, 1);
Again this is far from ideal as it triggers full reallocation of the dma buffers.
It seems to me the reset should happen automatically upon i2s_adc_disable
Thanks for reporting, we will look into.
Hi, @aCaB
There is no APIs to set DMA->curr_ptr to NULL or reallocate the DMA buffer directly,
you can use i2s_set_clk
to clear the old value in the DMA buffer as you said.
Environment
git describe --tags
to find it): // v4.3-dev-472-gcf056a7d0xtensa-esp32-elf-gcc --version
to find it): // xtensa-esp32-elf-gcc (crosstool-NG esp-2020r2) 8.2.0Problem Description
The internal dma buffer pointer is not properly reset across i2s_adc_enable/i2s_adc_disable which causes the unconsumed tail of the previous read to be returned in place of the fresh data.
Expected Behavior
I expect that:
Actual Behavior
After calling i2s_adc_enable, i2s_read returns cached (old) data.
Steps to reproduce
Code to reproduce this issue