Not sure if this is the right place to ask...

I am building a sound project on an ESP 32 via I2S using an example from: https://github.com/nhatuan84/esp32-i2s-sdcard-wav-player [/edit:]I use the example file "esp32_i2s_play_sdcard_wav_.ino" as I suspect "DAC_builtin" refers to if the DAC is built into the external ic/shield. I am using a max98357A which I think does not have a DAC built in...? [/edit]

It works fine with the example wav file t.wav posted in the repository.

But when I try to use a custom wav which I exported from audacity it sounds distorted an/or too slow/fast (it sounds fine when I play it within audacity).

This is an example that is totaly distorted when playing from the esp with I2S: badly sounding wav While it sounds fine when playing from audacity.

I tried different settings in audacity exporting 16 bit, 32 bit. 44100 Hz, 11025.

Any hints or tips what I could try or am doing wrong?



  • You should probably ask this on dsp.stackexchange.com - this is not really within the remit of sound engineers, it's more a coder's issue. – Tetsujin Oct 4 '19 at 17:22
  • yeah, I was in doubt... If I use the same settings as the wav that works and export from audacity it does not work. So I thought maybe it was a wav encoding issue... The software reads the header of the wav and determines the chunckid, chunksize, audioformat nuber of channels, samplerate, byterate, blockl alignment and bits per sample. – Jeroen Oct 4 '19 at 17:59
  • "chunckid, chunksize…" not within the purview of your average sound engineer - we push faders, we don't build software ;) – Tetsujin Oct 4 '19 at 18:01
  • yeah...... some of us.... ;-) – Mark Oct 6 '19 at 6:53

The file T.Wav has the following format:

  • Sample rate: 11025
  • PCM 16 BIT

Try exporting a similar format file.

The file you are currently testing has a sampling rate of 44100. You should try and resample this down to 11025.

Looking at the driver code, If I can assume you are using the "builtin DAC" version, there's an error in line 140. It should read uint32_t as opposed to uint8_t. The prototype for this function in the header is:

bool i2s_write_sample_nb(uint32_t sample);

I think the code looks like it's expecting 16 bit stereo samples at 44100 or 48000 so it might be worth trying with the original file, but 16 bit stereo and change line 140 in the driver to expect a 32 bit sample, or two 16 bit samples.

uint8_t is definitely not right for the driver at least.

Looking at ESP32 there are two 8-bit DAC's. I think the DAC's will read the most significant 8-bits from a 16 bit word. So basically, you need to configure the audio to be 8-bit and pack it into the top 8 bit of the 16-bit word. Stereo will work. I recommend you use dither to make it sound good. 8-bits with lots of dither will sound fine.

  • thx, I did (at least I think I did as I am no expert in audacity). This is the file which I resampled to 11025 link. It plays fine in audacity but too fast (I think twice the speed) on the ESP32 – Jeroen Oct 7 '19 at 10:13
  • hmm. so does T.wav play correctly? – Mark Oct 7 '19 at 11:12
  • OK so check line 140 in the driver code. I don't particularly like the look of that. You're using 16 bit samples and the driver is only reading in a uint8_t structure, which is 8 bits. So basically, only half the sample is being read. This isn't ideal. I suspect this needs to change. Either you configure it for 8 bit pcm or the driver code needs to change. – Mark Oct 7 '19 at 11:19
  • answer updated. – Mark Oct 7 '19 at 11:29
  • T.wav plays correctly. I use the version without dac built in, I editted the original post (should have included that right away, sorry). In "esp32_i2s_play_sdcard_wav_.ino" it does use an uint32_t... – Jeroen Oct 8 '19 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.