user49863: 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
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  and/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?
Thx!
Jeroen 

user84707: I know this is an old question, but I ran into the same issue and spent days trying to figure it out, so I hope this answer can save another poor soul from that:
The Problem
For reference, I have an ESP32 (HUZZAH32 from Adafruit) hooked up to a breakout board that uses a PCM5102a chip as an external DAC. I would set the sample rate to 44.1khz but it seemed my song, which I confirmed had accurate data, would play at double speed. Lowering the sample rate to 22.05khz made it play at the correct speed, but quality seemed reduced.
The Root Cause
The issue was that my .channel_format value was set to I2S_CHANNEL_FMT_RIGHT_LEFT, however my data was mixed to mono in Audacity. This problem may exhibit itself differently depending on how you push bytes via I2S, but for me, this meant double speed. This is because the protocol was reading every 2 samples (which should be separate) as the left/right channels. Effectively, this meant that it was skipping every other sample, which doubled the playback speed.
Code Snippets
My i2s_config_t code:
#define DMA_BUFFER_COUNT 8
#define DMA_BUFFER_LENGTH 1024

i2s_config_t i2s_config = {
    .mode = I2S_MODE_MASTER | I2S_MODE_TX,
    .sample_rate = 44100,
    .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
    .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, // this was causing double speed due to being I2S_CHANNEL_FMT_RIGHT_LEFT 
    .communication_format = (i2s_comm_format_t) (I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
    .tx_desc_auto_clear = true,
    .dma_buf_count = DMA_BUFFER_COUNT,
    .dma_buf_len = DMA_BUFFER_LENGTH,
    .use_apll = false, 
    .intr_alloc_flags = 0
};

My code for sending bytes to the external DAC (which is its own task):
(rx_buffer and readPointer here are part of a ring buffer that I streamed in over wifi on a separate task, please only use as reference and substitute for your own sound data)
int FRAMES_TO_SEND = 1024;
int32_t frames[FRAMES_TO_SEND];

for (int i = 0; i < FRAMES_TO_SEND; i++) {
    // copy into i2s buffer
    int32_t sample = (int32_t)rx_buffer[readPointer]; 
    
    // write bytes to the i2s peripheral
    esp_err_t err = i2s_write(i2s_num, (char *) &sample,
        sizeof(int32_t), &bytesWritten, 100);
            
    if(err != ESP_OK) {
        printf("ESP32 i2s Errorcode %i", err);
    }

    readPointer++;
    if (readPointer == TOTAL_BUFFER_SIZE) {
        readPointer = 0;
    }
}

Hopefully this helps out some of you, or at least get you on track to the solution. Unfortunately, the I2S protocol on the ESP32 is not very well documented so there's a lot of trial and error to be had. Keep at it!

49863: <p>I am building a sound project on an ESP 32 via I2S  using an example from: 
<a href="https://github.com/nhatuan84/esp32-i2s-sdcard-wav-player" rel="nofollow noreferrer">https://github.com/nhatuan84/esp32-i2s-sdcard-wav-player</a></p>

<p>It works fine with the example wav file t.wav posted in the repository.</p>

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

<p>This is an example that is totaly distorted when playing from the esp with I2S:
<a href="http://vandevorst.com/temp/starting.wav" rel="nofollow noreferrer">badly sounding wav</a>
While it sounds fine when playing from audacity.</p>

<p>I tried different settings in audacity exporting 16 bit, 32 bit. 44100 Hz, 11025.</p>

<p>Any hints or tips what I could try or am doing wrong?</p>

<p>Thx!</p>

<p>Jeroen </p>
 84707: <p>I know this is an old question, but I ran into the same issue and spent days trying to figure it out, so I hope this answer can save another poor soul from that:</p>
<h2>The Problem</h2>
<p>For reference, I have an ESP32 (HUZZAH32 from Adafruit) hooked up to a breakout board that uses a PCM5102a chip as an external DAC. I would set the sample rate to 44.1khz but it seemed my song, which I confirmed had accurate data, would play at double speed. Lowering the sample rate to 22.05khz made it play at the correct speed, but quality seemed reduced.</p>
<h2>The Root Cause</h2>
<p>The issue was that my .channel_format value was set to I2S_CHANNEL_FMT_RIGHT_LEFT, however <em>my data was mixed to mono in Audacity.</em> This problem may exhibit itself differently depending on how you push bytes via I2S, but for me, this meant double speed. This is because the protocol was reading every 2 samples (which should be separate) as the left/right channels. Effectively, this meant that it was skipping every other sample, which doubled the playback speed.</p>
<h2>Code Snippets</h2>
<p>My i2s_config_t code:</p>
<pre><code>#define DMA_BUFFER_COUNT 8
#define DMA_BUFFER_LENGTH 1024

i2s_config_t i2s_config = {
    .mode = I2S_MODE_MASTER | I2S_MODE_TX,
    .sample_rate = 44100,
    .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
    .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, // this was causing double speed due to being I2S_CHANNEL_FMT_RIGHT_LEFT 
    .communication_format = (i2s_comm_format_t) (I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
    .tx_desc_auto_clear = true,
    .dma_buf_count = DMA_BUFFER_COUNT,
    .dma_buf_len = DMA_BUFFER_LENGTH,
    .use_apll = false, 
    .intr_alloc_flags = 0
};
</code></pre>
<p>My code for sending bytes to the external DAC (which is its own task):</p>
<p>(rx_buffer and readPointer here are part of a ring buffer that I streamed in over wifi on a separate task, please only use as reference and substitute for your own sound data)</p>
<pre><code>int FRAMES_TO_SEND = 1024;
int32_t frames[FRAMES_TO_SEND];

for (int i = 0; i &lt; FRAMES_TO_SEND; i++) {
    // copy into i2s buffer
    int32_t sample = (int32_t)rx_buffer[readPointer]; 
    
    // write bytes to the i2s peripheral
    esp_err_t err = i2s_write(i2s_num, (char *) &amp;sample,
        sizeof(int32_t), &amp;bytesWritten, 100);
            
    if(err != ESP_OK) {
        printf(&quot;ESP32 i2s Errorcode %i&quot;, err);
    }

    readPointer++;
    if (readPointer == TOTAL_BUFFER_SIZE) {
        readPointer = 0;
    }
}
</code></pre>
<p>Hopefully this helps out some of you, or at least get you on track to the solution. Unfortunately, the I2S protocol on the ESP32 is not very well documented so there's a lot of trial and error to be had. Keep at it!</p>
