I2S internal DAC

Monsterhero
Posts: 4
Joined: Fri Jun 08, 2018 8:13 pm

I2S internal DAC

Postby Monsterhero » Fri Jun 08, 2018 8:39 pm

Hello all,

so i'm trying to use the built-in DAC with i2s.
It's outputing audio which i'm streaming over a2dp from a android device.

My problem is, i only get a squarewave output, instead of a "analog" signal.
As a result the audio is horrible.

Image

I tried it with the following code in my a2d data-callback:

Code: Select all

void a2dDataCallback(const uint8_t *buf, uint32_t len) {
	const char* data = (char*)buf;	
	i2s_write_bytes(I2S_NUM_0, data, len, portMAX_DELAY);	
}
And this is my i2s init:

Code: Select all

	i2s_config_t i2sconfig;
	i2sconfig.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN);
	i2sconfig.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT;
	i2sconfig.sample_rate = 44100;
	i2sconfig.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT;
	i2sconfig.communication_format = I2S_COMM_FORMAT_I2S_MSB;
	i2sconfig.dma_buf_count = 8;
	i2sconfig.dma_buf_len = 64;
	i2sconfig.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1;
	i2s_driver_install(I2S_NUM_0, &i2sconfig, 0, NULL);
	
	i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN);
	i2s_set_pin(I2S_NUM_0, NULL);
Am i doing something wrong, or is it supposed to be like that?

Thanks for your help.

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: I2S internal DAC

Postby ESP_Sprite » Sat Jun 09, 2018 4:40 am

Are you sure you aren't doing anything wrong wrt signed/unsigned and the values you input? The dac, from memory, takes the top 8 bits from the 16-bit values the I2S peripheral feeds it as unsigned bytes.

Monsterhero
Posts: 4
Joined: Fri Jun 08, 2018 8:13 pm

Re: I2S internal DAC

Postby Monsterhero » Sat Jun 09, 2018 10:56 am

I tried to use the original a2dp_sink example aswell, which gives me the same result.

Theres the code i tried:
https://github.com/espressif/esp-idf/tr ... /a2dp_sink

Monsterhero
Posts: 4
Joined: Fri Jun 08, 2018 8:13 pm

Re: I2S internal DAC

Postby Monsterhero » Fri Jun 15, 2018 6:48 pm

I found the error/bug:

I used the following for I2S init:

Code: Select all

.mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN,
I2S_MODE_DAC_BUILT_IN has a value of 32

instead of I2S_MODE_DAC_BUILT_IN i'm using I2S_MODE_PDM now, which has a value of 64

so this is the following i'm using for init now:

Code: Select all

.mode = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_PDM,
It looks like DAC_BUILD_IN and PDM are swaped, cause I2S_MODE_PDM outputs a 8bit dac where I2S_MODE_DAC_BUILT_IN outputs a 1bit dac.

Can someone confirm this, too?

Monsterhero
Posts: 4
Joined: Fri Jun 08, 2018 8:13 pm

Re: I2S internal DAC

Postby Monsterhero » Fri Jun 15, 2018 7:36 pm

Correction: I2S_MODE_DAC_BUILT_IN is 16 not 32

moefear85
Posts: 44
Joined: Sun Sep 05, 2021 4:55 pm

Re: I2S internal DAC

Postby moefear85 » Sun Jan 23, 2022 9:22 pm

This problem still exists.

Elijahh
Posts: 1
Joined: Fri Mar 03, 2023 6:12 pm

Re: I2S internal DAC

Postby Elijahh » Fri Mar 03, 2023 6:14 pm

Problem still exists, even in ESP-IDF v5.0

Who is online

Users browsing this forum: No registered users and 92 guests