ESP32 A2DP src SBC codec setup

64-core CPU
Posts: 1
Joined: Thu Oct 15, 2020 9:15 am

ESP32 A2DP src SBC codec setup

Postby 64-core CPU » Thu Oct 15, 2020 10:51 am

(Sorry for my english)


I have esp32 and vs1053(audio codec). I trying create bluetooth audio player. I set up the esp32 as bluetooth sound source. vs1053 decodes audio and returns it over the i2s bus. vs1053 support i2s output format is 16bit per sample and 48/96/192KHz. I set it to output at 48KHz, but SBC codec in the esp32 hardcoded to 44100Hz. I tried to reproduce the sound as it is - it plays, but expectedly of poor quality due to distortion and clicks.
Then I started looking for information on the Internet and came across this:
I made some fixes to the sources as indicated in this post ... -374894493
This gave the result - the sound plays without distortion, but freezes after about 2 seconds. Moreover, the vs1053 continues to reproduce sound without problems - i can hear it on wired headphones that are connected to it, but silence on bluetooth. There are no errors in the " monitor" command output when the sound hangs.

In my feeling, something hangs at a2dp_input_data_callback(), because when at the end of the test the system tries to disconnect bluetooth, it hangs on the call to the esp_a2d_source_disconnect() function.

Code: Select all

int a2dp_input_data_callback( unsigned char* data, int dataLength ){
	if (dataLength < 0 || data == NULL) return 0;
	size_t bytes_read = 0;
	printf("a %i\n", dataLength );
	if( i2s_read( I2S_NUM_0, data, dataLength, &bytes_read, portMAX_DELAY ) )return 0;
	//if( i2s_read( I2S_NUM_0, data, dataLength, &bytes_read, 200 / portTICK_PERIOD_MS ) ) return 0;
	return bytes_read;
The first few seconds, while the sound in the bluetooth headphones is playing, the console is outputting "a 512". As soon as the bluetooth sound freezes, the output in the console also stops. The sound in wired headphones that are connected directly to the vs1053 continues to play normally.

Could it be that I misconfigured i2s? My config is:

Code: Select all

static int i2s0_init(){
	int err = 0;
	i2s_config_t i2s_conf = {
		.mode = I2S_MODE_SLAVE | I2S_MODE_RX,
		.sample_rate = 48000,
		.bits_per_sample = 16,
		.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
		.communication_format = I2S_COMM_FORMAT_STAND_I2S,
		.intr_alloc_flags = 0,
		.dma_buf_count = 64,
		.dma_buf_len = 64,
		.use_apll = false,
		.tx_desc_auto_clear = false,
		.fixed_mclk = 0
	err = i2s_driver_install( I2S_NUM_0, &i2s_conf, 1, NULL );
	if( err )return err;
	i2s_pin_config_t pin_conf = {
		.bck_io_num = def_i2s0_bck,
		.ws_io_num = def_i2s0_ws,
		.data_out_num = I2S_PIN_NO_CHANGE,
		.data_in_num = def_i2s0_data_in
	return i2s_set_pin( I2S_NUM_0, &pin_conf );
With this config the sound plays without freezes if I do not touch the source bta_av_co.c and bta_av_co.c.

Can you help me with this?
Thanks in advance!

Who is online

Users browsing this forum: No registered users and 20 guests