i2s_write losing data due to fail to return update pointer
Posted: Thu Oct 17, 2019 9:59 pm
Hi all,
I am searching for the explanation/suggestions to debug this problem.
I am using I2S DMA to send out the wave file to the built-in DAC. There is a bug of loosing sound data and I trace back till I saw there data was lost because the same tx buffer got overwritten because the tx->curr_ptr didn't get update.
My I2S DMA running as a task, which will play the exactly the same sound wave
And I have 3 different LEDs toggling with different high resolution timers.
Here is my set up for i2s configuration
When the DMA data got copy correctly I will see the two current pointers got updated correctly from the call of the i2s_write
I (67066) SPKER: Total Wave File Size:24257
I (67066) I2S: PLL_D2: Req RATE: 16000, real rate: 1004.000, BITS: 16, CLKM: 83, BCK: 60, MCLK: 83.333, SCLK: 32128.000000, diva: 64, divb: 21
I (67066) SPKER: Play len:2048
I (67076) I2S: CURR_PTR: 1073622200
I (67076) I2S: size: 4096, rw_pos: 0, buf_size: 2048, curr_ptr: 1073622200
I (67136) I2S: CURR_PTR: 1073620148
I (67146) I2S: size: 2048, rw_pos: 0, buf_size: 2048, curr_ptr: 1073620148
I (67146) SPKER: offset:2048
However when the sound wave data lost I will see this
I (74566) SPKER: Total Wave File Size:24257
I (74566) I2S: PLL_D2: Req RATE: 16000, real rate: 1004.000, BITS: 16, CLKM: 83, BCK: 60, MCLK: 83.333, SCLK: 32128.000000, diva: 64, divb: 21
I (74566) SPKER: Play len:2048
0I (74576) I2S: CURR_PTR: 1073620148
I (74576) I2S: size: 4096, rw_pos: 0, buf_size: 2048, curr_ptr: 1073620148
I (74636) I2S: CURR_PTR: 1073620148
I (74646) I2S: size: 2048, rw_pos: 0, buf_size: 2048, curr_ptr: 1073620148
Please help or suggest where should I do more investigation are very appreciated.
Thank you so much.
I am searching for the explanation/suggestions to debug this problem.
I am using I2S DMA to send out the wave file to the built-in DAC. There is a bug of loosing sound data and I trace back till I saw there data was lost because the same tx buffer got overwritten because the tx->curr_ptr didn't get update.
My I2S DMA running as a task, which will play the exactly the same sound wave
Code: Select all
xTaskCreate(SPEAKER_Run, "example_i2s_adc_dac", 1024 * 2, c, 5, &c->pSpeakerHandle);
Here is my set up for i2s configuration
Code: Select all
static void SPEAKER_I2S_Init(void)
{
int i2s_num = I2S_NUM;
i2s_config_t i2s_config = {
.mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN,
.sample_rate = 16000,
.bits_per_sample = 16,
.communication_format = I2S_COMM_FORMAT_I2S_MSB,
.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT,
.intr_alloc_flags = 0,
.dma_buf_count = 2,
.dma_buf_len = 1024,
.use_apll = 1,
};
//install and start i2s driver
i2s_driver_install(i2s_num, &i2s_config, 0, NULL);
//init DAC pad
i2s_set_dac_mode(I2S_DAC_CHANNEL_RIGHT_EN); // maps to GPIO25 DAC Channel 1
}
I (67066) SPKER: Total Wave File Size:24257
I (67066) I2S: PLL_D2: Req RATE: 16000, real rate: 1004.000, BITS: 16, CLKM: 83, BCK: 60, MCLK: 83.333, SCLK: 32128.000000, diva: 64, divb: 21
I (67066) SPKER: Play len:2048
I (67076) I2S: CURR_PTR: 1073622200
I (67076) I2S: size: 4096, rw_pos: 0, buf_size: 2048, curr_ptr: 1073622200
I (67136) I2S: CURR_PTR: 1073620148
I (67146) I2S: size: 2048, rw_pos: 0, buf_size: 2048, curr_ptr: 1073620148
I (67146) SPKER: offset:2048
However when the sound wave data lost I will see this
I (74566) SPKER: Total Wave File Size:24257
I (74566) I2S: PLL_D2: Req RATE: 16000, real rate: 1004.000, BITS: 16, CLKM: 83, BCK: 60, MCLK: 83.333, SCLK: 32128.000000, diva: 64, divb: 21
I (74566) SPKER: Play len:2048
0I (74576) I2S: CURR_PTR: 1073620148
I (74576) I2S: size: 4096, rw_pos: 0, buf_size: 2048, curr_ptr: 1073620148
I (74636) I2S: CURR_PTR: 1073620148
I (74646) I2S: size: 2048, rw_pos: 0, buf_size: 2048, curr_ptr: 1073620148
Please help or suggest where should I do more investigation are very appreciated.
Thank you so much.