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

PCM5102A Lots of different types of noise (clicking, high frequency, low frequency) #556

Closed Tuxorials closed 1 month ago

Tuxorials commented 1 month ago

Problem Description

As soon as the esp+PCM5102A breakout (the aliexpress cheapo variant) are connected to the amp, a plethora of noise is made depending on if the device is connected or not. Check the attached video (Everything is recorded at 20cm distance on an AT2020 Microphone)

https://github.com/pschatzmann/ESP32-A2DP/assets/61655859/62e22b42-851a-4adb-8c74-cad123084615

Device Description

ESP32 Wroom (just the normal version you see everywhere (im yet to find the actual name for the board)) PCM5102A (this one)

Sketch

#include "AudioTools.h"
#include "BluetoothA2DPSink.h"

I2SStream i2s;
BluetoothA2DPSink a2dp_sink(i2s);

void setup() {
  Serial.begin(115200);
  pinMode(27,INPUT);
  pinMode(21,OUTPUT);
  auto cfg = i2s.defaultConfig();
  cfg.pin_bck = 4;
  cfg.pin_ws = 15;
  cfg.pin_data = 2;
  i2s.begin(cfg);

  static const i2s_config_t i2s_config = {
        .mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_TX),
        .sample_rate = 44100,
        .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
        .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
        .communication_format = (i2s_comm_format_t) (I2S_COMM_FORMAT_I2S_MSB | I2S_COMM_FORMAT_I2S_LSB),
        .intr_alloc_flags = 0, // default interrupt priority
        .dma_buf_count = 48,
        .dma_buf_len = 256,
        .use_apll = false,
        .tx_desc_auto_clear = true // avoiding noise in case of data unavailability
  };
  a2dp_sink.set_i2s_config(i2s_config);

  a2dp_sink.set_channels (I2S_CHANNEL_STEREO);
  a2dp_sink.set_auto_reconnect(true, 1000);

  a2dp_sink.start("Big Speakers");
}

void loop() {
 delay(50); //Simplified, normally theres battery voltage measurement going on here
}

Other Steps to Reproduce

I tried both a Pixel 8 and a Galaxy A23 5G as bluetooth devices. the amps arent high quality by any means (3,80€ on aliexpress) but they dont cause any noise when the input is bridged as can be seen in the video

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

2.0.13

I have checked existing issues, discussions and online documentation

pschatzmann commented 1 month ago

Your code does not make any sense at all! Please stick to the documented functionality that you can find in the Readme!

If you absolutly want to use the legacy functionality, you can find the documentation in the Wiki

Tuxorials commented 1 month ago

The documentation isnt great as its somehow mixed between the legacy api and the new one. can you help me out in telling me which part is the legacy part

pschatzmann commented 1 month ago

No, it is not mixed: The Readme contains the actual API! The Legacy API is documented in a separate Wiki Finally, there is a Wiki for the different DACs

Tuxorials commented 1 month ago

Alright.. so i copied the code from the Readme.

#include "AudioTools.h"
#include "BluetoothA2DPSink.h"

I2SStream i2s;
BluetoothA2DPSink a2dp_sink(i2s);

void setup() {
    auto cfg = i2s.defaultConfig();
    cfg.pin_bck = 4;
    cfg.pin_ws = 15;
    cfg.pin_data = 2;
    i2s.begin(cfg);

    a2dp_sink.start("MyMusic");
}

void loop() {
}

Exactly the same issues. So as i suspected its not a problem of the code

pschatzmann commented 1 month ago

Did you read the Wiki for your DAC?

Tuxorials commented 1 month ago

I did. everything is as suggested, except for the pin layout

pschatzmann commented 1 month ago

Did you check the solder bridges ?

Tuxorials commented 1 month ago

Yes, although i will check them again since i have heated up the board recently (although the issues also happened before that)

pschatzmann commented 1 month ago

I suggest to do the tests with a simpler sketch and test your I2S functionality first.

I bet the issue is either the connection or your module is damaged. I suggest you also try another GND pin. I noticed that on my ESP32 not all GND pins are working as expected.

Tuxorials commented 1 month ago

All resoldered :white_check_mark: Same issue. I'm pretty sure this has to be a software issue as e.g the high pitched noise is only audible for like 5 seconds after connecting, after unlocking, and obviously during and after playback. I will try what you just suggested, but again, it doesnt make sense why this would happen after stuff thats going on via bluetooth. Anyways, ill try and let you know

Tuxorials commented 1 month ago

Is that cracking sound intended? can i buffer the sound somehow so its not so choppy but a clean sine wave

pschatzmann commented 1 month ago

If the sine wave sketch does not give a clean sound, set the log level to Warning. So, no there should not be any crackling sound!

I would not recognize your recorded sound from above. Do you get the same when you test with earphones ?

Tuxorials commented 1 month ago

I do get the same sound with headphones and on the speaker. the blue indicator led is flashing as well though so im still unsure its a hardware problem

pschatzmann commented 1 month ago

Do you get at least a clean sine signal ? What is your power supply ?

Tuxorials commented 1 month ago

i have both a stepdown converter running off a lipo (the lipo powers the amps as well) as well as a usb line to the esp obviously. the cracking occurs on any combination of them (only usb, only battery, both). the signal is not clean at all

https://github.com/pschatzmann/ESP32-A2DP/assets/61655859/2c66b538-b5eb-4162-83e9-18fdb53fc5aa

pschatzmann commented 1 month ago

Is this with log level Warning ?

AudioLogger::instance().begin(Serial, AudioLogger::Warning);

This is definitively not how it should sound like and this noise is not normal. What are the settings of your Solder Bridges ?

Tuxorials commented 1 month ago

Oh, now that ive set it to warning, it sounds normal. I have purchased new ESP32s, but on the bluetooth code, it still has all the aforementioned issues

Tuxorials commented 1 month ago

It was BOTH OF MY SUPPLIES.... its fixed, by using a cleaner power source.. sorry for bothering you