-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TW#22516] Looped noise on A2DP sink example upon disconnection #1945
Comments
This is caused by the fact that the driver continues to run through the same samples, because it does not clear the DMA buffers after it is done with them. I advise you to have a static buffer of X samples that are zero, which you can push to I2S after the last packet you send. the number of consecutive pushes that you need is equal to the number of DMA buffers selected when instantiating the I2S hardware. There is also a zero_dma_buffers function but I am not 100% positive how good of idea it is to be used (since it might clear some samples that you are currently playing). @igrr I have a driver that I am working on for Arduino that does not have this problem. Maybe we can find a middle ground and implement the "fix" in IDF instead. |
I tried to push an empty buffer after receiving "Disconnect" event but that didn't improve much the situation... Where can I find the zero_dma_buffers() function ? I don't mind clearing samples that are currently being played since the I2S DAC shouldn't be outputing sound once the A2DP source is disconnected. |
Thank's. I tried this patch : diff --git a/examples/bluetooth/a2dp_sink/main/bt_app_av.c b/examples/bluetooth/a2dp_sink/main/bt_app_av.c
index b1c432c5..a515cab5 100644
--- a/examples/bluetooth/a2dp_sink/main/bt_app_av.c
+++ b/examples/bluetooth/a2dp_sink/main/bt_app_av.c
@@ -105,6 +105,11 @@ static void bt_av_hdl_a2d_evt(uint16_t event, void *p_param)
m_audio_state = a2d->audio_stat.state;
if (ESP_A2D_AUDIO_STATE_STARTED == a2d->audio_stat.state) {
m_pkt_cnt = 0;
+ } else {
+ ESP_LOGI(BT_AV_TAG, "Flushing I2S buffer");
+ if (i2s_zero_dma_buffer(I2S_NUM_0) != ESP_OK) {
+ ESP_LOGE(BT_AV_TAG, "Flushing I2S buffer failed");
+ }
}
break;
} But it did not solve my issue, event though I see "Flushing I2S buffer" just after disconnecting from the ESP32. Maybe I'm not calling i2s_zero_dma_buffer() at the right time ? For the moment being I'm sticking with #1789 solution. |
Closes: espressif/esp-idf#1945 (cherry picked from commit 1751607)
Hi !
I noticed that the vanilla A2DP example has an annoying bug when used with an I2S DAC (I use a PCM5102). After disconnecting the A2DP source, the ESP32 continues to push data to the DAC (which leads to unbearable noise). I guess that's because the I2S DMA buffer isn't flushed after being disconnected from the A2DP source.
How to reproduce :
Issue #1789 has a fix that works for me.
The text was updated successfully, but these errors were encountered: