pschatzmann / ESP32-A2DP

A Simple ESP32 Bluetooth A2DP Library (to implement a Music Receiver or Sender) that supports Arduino, PlatformIO and Espressif IDF
Apache License 2.0
1.55k stars 261 forks source link

Popping on playback suspend / resume with external DAC #517

Closed rec0de closed 3 months ago

rec0de commented 5 months ago

Problem Description

I'm getting audible clicks / pops when pausing bluetooth playback for a few seconds (and again when resuming). I assume this is from the DAC powering down when the I2S connection is inactive.

Commenting out the referenced line (thus keeping I2S active even when playback is paused) fixes the issue for me. Might be worth exposing this as a config flag or something similar?

https://github.com/pschatzmann/ESP32-A2DP/blob/707d306d515a80e343cfe1a0728c6e3fecd7d155/src/BluetoothA2DPSink.cpp#L725

Device Description

ESP-WROOM32 with UDA1334A DAC breakout

Sketch

#include "BluetoothA2DPSinkQueued.h"

BluetoothA2DPSinkQueued a2dp_sink;

void setup() {
  // you could also do this also with your own i2s config. But this is simpler
  i2s_pin_config_t my_pin_config = {
        .mck_io_num = I2S_PIN_NO_CHANGE,
        .bck_io_num = 26,
        .ws_io_num = 25,
        .data_out_num = 33,
        .data_in_num = I2S_PIN_NO_CHANGE
  };

  static const i2s_config_t i2s_config = {
       .mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_TX),
       .sample_rate = 41000,
       .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT,
       .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
       .communication_format = (i2s_comm_format_t) (I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_LSB),
       .intr_alloc_flags = 0, // default interrupt priority
       .dma_buf_count = 8,
       .dma_buf_len = 64,
       .use_apll = false,
       .tx_desc_auto_clear = true // avoiding noise in case of data unavailability
  };

  a2dp_sink.set_pin_config(my_pin_config);
  a2dp_sink.set_i2s_config(i2s_config);
  a2dp_sink.start("Debug");  
}

void loop() {}

Other Steps to Reproduce

No response

Provide your Version of the EP32 Arduino Core (or the IDF Version)

2.0.11

I have checked existing issues, discussions and online documentation

pschatzmann commented 3 months ago

No, in this case you better use the callback: Here a simple example