Use I2S in I2S_MODE_DAC_BUILT_IN Mode
Posted: Fri Jan 20, 2017 2:21 pm
I found the sample code in i2s.h, and noticed that we can use the built-in DAC to render I2S audio.
However I can't seem to get it working.
This is my init function:
My normal I2S pipeline works fine, but when I use the DAC, I get DMA and buffer underruns.
I feed it samples like this:
Any idea whats wrong?
However I can't seem to get it working.
This is my init function:
Code: Select all
static void init_i2s_dac()
{
i2s_config_t i2s_config = {
.mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN, // Only TX
.sample_rate = 44100,
.bits_per_sample = 8, // Only 8-bit DAC support
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, // 2-channels
.communication_format = I2S_COMM_FORMAT_I2S_MSB,
.dma_buf_count = 14, // number of buffers, 128 max.
.dma_buf_len = 32*2, // size of each buffer
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1 // Interrupt level 1
};
i2s_pin_config_t pin_config = {
.bck_io_num = 26,
.ws_io_num = 25,
.data_out_num = 22,
.data_in_num = I2S_PIN_NO_CHANGE // Not used
};
i2s_driver_install(I2S_NUM, &i2s_config, 0, NULL);
i2s_set_pin(I2S_NUM, &pin_config);
}
I feed it samples like this:
Code: Select all
static int convert_sample(short s) {
// convert 16bit to 8bit and duplicate mono sample to both channels
char eightBit = s >> 8;
short samp = eightBit;
samp = (samp) & 0xff;
samp = (samp << 8) | samp;
return samp;
}