If I continue to write the same data the signal is fine, but after sending a burst of silence and restarting the tone, the same distortion appears. It can last for a few cycles, or the entire duration of the sound. I see similar issues when playing converted WAV files, such that the sound varies from one play to the next.
Here is my code writing the data - any ideas on what is the problem? I am going to try the internal I2S DAC and see if it suffers from the same problem. I have tried different bit rates, dma buffer sizes and counts, all with no change.
Code: Select all
for (;;) {
int64_t start = esp_timer_get_time();
int64_t end = esp_timer_get_time();
while ((end - start)/1000 < SAMPLE_DURATION * 1) {
ESP_ERROR_CHECK(i2s_write(I2S_NUM_0, samples_data, sizeof(samples_data), &i2s_bytes_write, portMAX_DELAY));
end = esp_timer_get_time();
}
int32_t msElapsed = (int32_t)(end - start) / 1000;
//ESP_LOGI(TAG, "i2s_write wrote %d bytes, took %d mS", i2s_bytes_write, msElapsed);
cnt++;
while ((end - start)/1000 < SAMPLE_DURATION * 2) {
ESP_ERROR_CHECK(i2s_write(I2S_NUM_0, silence, sizeof(silence), &i2s_bytes_write, portMAX_DELAY));
end = esp_timer_get_time();
}
}