Skip to content
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

Crackling sound with ESP32 board support >= 2.0.10 #27

Closed
harbaum opened this issue Jul 27, 2023 · 6 comments
Closed

Crackling sound with ESP32 board support >= 2.0.10 #27

harbaum opened this issue Jul 27, 2023 · 6 comments

Comments

@harbaum
Copy link
Owner

harbaum commented Jul 27, 2023

While sound was working fine with ESP board support 2.0.6 it only gives a crackling noise in the 2.0.10 and the latest 2.0.11

@harbaum harbaum changed the title Crackling sound Crackling sound with ESP32 board support >= 2.0.10 Jul 27, 2023
@harbaum
Copy link
Owner Author

harbaum commented Jul 27, 2023

Works up to 2.0.9 and is broken since 2.0.10

The following sketch gives a clean rectangular signal up to 2.0.9 and the crackling noise on later versions.

#include "driver/i2s.h"

unsigned short snd_buffer[64];

void setup() {
    static const i2s_config_t i2s_config = {
    .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN),
    .sample_rate = 24000,
    .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,

    .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT,
    .intr_alloc_flags = 0,
    .dma_buf_count = 4,
    .dma_buf_len = 64,   // 64 samples
    .use_apll = true
  };
  i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
  i2s_set_dac_mode(I2S_DAC_CHANNEL_RIGHT_EN);
}

void loop() {
  // generate square wave
  for(int i=0;i<32;i++)  snd_buffer[i] = 0x0000;
  for(int i=32;i<64;i++) snd_buffer[i] = 0x1000;

  size_t bytesOut = 0;
  i2s_write(I2S_NUM_0, snd_buffer, sizeof(snd_buffer), &bytesOut, 0);
  printf("BytesOut: %d\n", bytesOut);
}

@harbaum
Copy link
Owner Author

harbaum commented Jul 27, 2023

See espressif/arduino-esp32#8467

harbaum added a commit that referenced this issue Jul 29, 2023
@harbaum
Copy link
Owner Author

harbaum commented Jul 29, 2023

Please try the latest commit. The donkey kong sounds are the most critical ones and may be affected most by the implemented work around.

Still unclear what's causing the apll to generate the crackling noise.

@KlausMu
Copy link

KlausMu commented Aug 1, 2023

I tried the latest commit with ESP32 board version 2.0.11. The workaround worked in my tests. Thanks a lot.

@bjotos
Copy link

bjotos commented Aug 1, 2023

I started with this project after reading about it in the latest Make and ran in exact the issue with crackling noise from the speakers w/o this fix (cloned repo last week). And this commit solved it.

But I was getting this noise also in game select screen where it should be silent, which makes me wonder if that's because I'm using single-wire SC8002B, while PAM8302A uses differential audio signal, or some other difference with these solutions (different amps, different filters, ...)

P.S.: Thanks for the great work, love it ;)

@harbaum
Copy link
Owner Author

harbaum commented Aug 2, 2023

The crackling sound even happens when there's silence at a signal level != zero. So yes, it was expected to happen in the menu as well.

@harbaum harbaum closed this as completed Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants