Questions about I2S in I2S_MODE_DAC_BUILT_IN mode and 8-bit 44100Hz mono WAV

ssacp148
Posts: 9
Joined: Sun Aug 25, 2019 9:21 pm

Questions about I2S in I2S_MODE_DAC_BUILT_IN mode and 8-bit 44100Hz mono WAV

Postby ssacp148 » Wed Sep 04, 2019 7:50 pm

Hey all,

I have 8 bit unsigned, 44100 Hz. 1 Channel (mono) WAV files that I want to play through the built in DAC using I2S.
Initialization is done as follows:

Code: Select all

    i2s_port_t i2s_num      = I2S_NUM_0;
    i2s_config_t i2s_config = 
    {
        .mode                   = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN),
        .sample_rate            = 44100,
        .bits_per_sample        = I2S_BITS_PER_SAMPLE_16BIT, /* the DAC module will only take the 8bits from MSB */
        .channel_format         = I2S_CHANNEL_FMT_ONLY_RIGHT,
        .communication_format   = I2S_COMM_FORMAT_I2S_MSB,
        .intr_alloc_flags       = 0,
        .dma_buf_count          = 2,
        .dma_buf_len            = 512,
        .use_apll               = false,
    };

    i2s_driver_install(i2s_num, &i2s_config, 0, NULL);
    i2s_set_dac_mode(I2S_DAC_CHANNEL_RIGHT_EN /** GPIO25 */);
I am aware of the fact that the sample data should always 16-bits and the 8-bit WAV sample data should be in the upper 8 bits.
However I am unsure of the value to use for channel_format and how it affects the way I should write samples using i2s_write.
What does I2S_CHANNEL_FMT_ONLY_RIGHT mean exactly? Does it mean the I2S driver will only use the Right sample and skips the Left sample? If so, Am I supposed to write an empty Left sample using i2s_write?
Should I be using I2S_CHANNEL_FMT_ALL_RIGHT instead or even I2S_CHANNEL_FMT_RIGHT_LEFT?

ssacp148
Posts: 9
Joined: Sun Aug 25, 2019 9:21 pm

Re: Questions about I2S in I2S_MODE_DAC_BUILT_IN mode and 8-bit 44100Hz mono WAV

Postby ssacp148 » Thu Sep 05, 2019 3:19 pm

I got it to work using the code in my previous post and calling, however when playing 44100Hz WAV files there's a clicking/popping noise audible at the start of the WAV file. I thought I was messing up the DMA buffers but I'm filling those up entirely with either WAV samples or 0x80. So I decided to try a 22050Hz WAV and there's no clicking noise anymore?

How come the 22050Hz one plays fine and the 44100 always produces a clicking noise close to the start of the audio (it's always at the same time)? There's no other tasks on the ESP32 running, it's basically twiddling its thumbs in between i2s_write calls.

ssacp148
Posts: 9
Joined: Sun Aug 25, 2019 9:21 pm

Re: Questions about I2S in I2S_MODE_DAC_BUILT_IN mode and 8-bit 44100Hz mono WAV

Postby ssacp148 » Thu Sep 05, 2019 9:00 pm

It seems that calling i2s_set_sample_rates introduces a tiny pop, but not always?
Leaving it out removes any unwanted noises but I set the initial sample rate through i2s_driver_install once and then call i2s_driver_install if i need to switch from 44100 to another sampling frequency. How can I ensure no such noises occur while calling i2s_set_sample_rates?

Who is online

Users browsing this forum: VinayDand and 441 guests