Page 1 of 1

I2S: why no 8 bits per sample?

Posted: Fri Sep 27, 2019 3:14 pm
by blippy
I'm curious as to why i2s_config_t doesn't allow a bits_per_sample of 8. Given that the DAC pins are only 8 bits, surely it would make sense?

It means that we have to either pad our samples or store/transmit twice as much data as we need.

Re: I2S: why no 8 bits per sample?

Posted: Fri Sep 27, 2019 9:07 pm
by blippy
OK, I thought I solved things just now, but apparently not. I've got

Code: Select all

        static const int i2s_num = 0; // i2s port number
   
#define RATE 8000

        static const i2s_config_t i2s_config = {
                .mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN,
                .sample_rate = RATE,
                .bits_per_sample = I2S_BITS_PER_SAMPLE_8BIT,
                .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
                .communication_format = I2S_COMM_FORMAT_I2S,
                .intr_alloc_flags = 0, // default interrupt priority
                .dma_buf_count = 8,
                .dma_buf_len = 64,
                .use_apll = false
        };

        ret = i2s_driver_install(i2s_num, &i2s_config, 0, NULL);
        assert(ret == ESP_OK);

But I get an assertion error, with the message

Code: Select all

E (7650) I2S: Invalid bits per sample
How do I fix this?

Also, I'm confused as to how I should set .dma_buf_count and .dma_buf_len. I assume it's got something to do with how you can buffer input, but the documentation doesn't decribe how to set or use them. They're just kinda magic numbers as far as I'm concerned.

Re: I2S: why no 8 bits per sample?

Posted: Fri Sep 27, 2019 10:22 pm
by blippy
Just a follow-up. Here is sets the bits per sample to be 8:
https://esp-idf-zh.readthedocs.io/zh_CN ... s/i2s.html

I still couldn't get my code to work properly, though.