when i receive stereo audio signal on the nrf5340 audio DK, it has many limitations

In my last ticket, I consulted on how to use nrf5340 audio dk to achieve stereo audio transmission (from gateway to one headset), and I received the answer.

(+) How can i receive stereo audio signal on the nrf5340 audio DK configured for headset - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)

However, during my debugging process on the CIS code, what ever the answer code or my own code. I found that implementing this feature would have significant limitations, such as the gateway being able to only connect to one headset at same time. I have changed the BT_MAX_CONN to 2, also the BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT and BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT, but it still some err logged out. Then i remembered that the sdu size is doubled, so i enable the CONFIG_BT_BAP_UNICAST_24_2_1 to reduce the sdu size,  and the gateway finally can connected two headset.

But the audio sampling rate will decrease to 24KHz as a result, which cannot meet my requirements. 

What I need is that in CIS mode, the Gateway can connect two Headsets with an audio sampling rate of at least 48KHz, and not only can it receive external input audio data from the Gateway, but it can also input audio data from one Headset and transmit it to another Headset through the Gateway(realy function). If it woke as mono mode(gateway only send mono audio data to corresponding Headset), I have already implemented it on a standard sample, But it too hard for me when i want to send the stereo audio data to every Headset.

So i want to ask for help, what is the true problem and how can i resolv it.

  • Hello,Maria

    Sorry for the late reply. you can check the code from github.com/.../cis_stereo_headset_v240 , the cis_stereo_headset_v240 branch. I already enable the CONFIG_BT_BAP_UNICAST_24_2_1 and CONFIG_AUDIO_SOURCE_I2S, you can change it by yourself to test it, thank you very much.


    If my gateway only connects to one headset, it can transmit stereo signals with 48K sampling rate. I think the problem is that when I try to connect to the second headset, the code will automatically allocate relevant resources, and the required resources will be doubled. But according to my needs, the second headset does not need to receive audio signals from the gateway, but instead transmits the audio signals it receives to the gateway and gateway can relay them to the first headset. Therefore, I am trying to find and modify this part of the code to see if it can save resources and use a 48K sampling rate.If you have any suggestions, please also provide them. Thank you.

  • Hello,

    Sorry about the delay. I will test this as soon as I can.

    BR,

    Maria

  • Hello, Maria

    Thank you very much for your help!

    I will waiting for you.

  • Hello and happy new year!

    I have not found a solution for NCS v2.4.0, but I found that using the main branch of NCS is possible. Very often the recommendation is to always move to the newest release of NCS when you are working with LE Audio.

    If you don't have the option to upgrade, I can search for another solution for you.

    Note that I do not have a stereo codec, so you will have to find out if the below solution works in practice.

    I added these lines to prj.conf:

    CONFIG_AUDIO_SOURCE_I2S=y
    
    CONFIG_BT_MAX_CONN=2
    
    CONFIG_BT_BAP_UNICAST_CONFIGURABLE=y
    CONFIG_BT_AUDIO_BITRATE_UNICAST_SINK=80000
    CONFIG_BT_AUDIO_BITRATE_UNICAST_SRC=80000
    CONFIG_BT_AUDIO_RETRANSMITS=5
    CONFIG_AUDIO_SAMPLE_RATE_48000_HZ=y
    
    CONFIG_STEREO_CIS_HEADSET=y

    The structure of the nRF5340 application has changed since v2.4.0 so these changes are needed as well:

    src/bluetooth/bt_stream/unicast/unicast_client.c:

    static struct bt_bap_lc3_preset lc3_preset_source = BT_BAP_LC3_UNICAST_PRESET_NRF5340_AUDIO_SOURCE;
    
    +++
    static struct bt_audio_codec_qos lc3_preset_sink_stereo_qos = BT_AUDIO_CODEC_LC3_QOS_10_UNFRAMED(
    	LE_AUDIO_SDU_SIZE_OCTETS(CONFIG_BT_AUDIO_BITRATE_UNICAST_SINK) * 2, 
    	CONFIG_BT_AUDIO_RETRANSMITS, CONFIG_BT_AUDIO_MAX_TRANSPORT_LATENCY_MS,
    	CONFIG_BT_AUDIO_PRESENTATION_DELAY_US);
    +++
    
    static bool playing_state = true;

    int unicast_client_send(struct le_audio_encoded_audio enc_audio)
    { 
    	int ret;
    	size_t data_size_pr_stream;
    	struct bt_iso_tx_info tx_info = {0};
    	struct sdu_ref_msg msg;
    	
    +++ if (IS_ENABLED(CONFIG_STEREO_CIS_HEADSET)) {
    +++	    data_size_pr_stream = enc_audio.size;
    +++	} else {
    		if ((enc_audio.num_ch == 1) || (enc_audio.num_ch == ARRAY_SIZE(headsets))) {
    			data_size_pr_stream = enc_audio.size / enc_audio.num_ch;
    		} else {
    			LOG_ERR("Num encoded channels must be 1 or equal to num headsets");
    			return -EINVAL;
    		}
    
    		if (data_size_pr_stream != LE_AUDIO_SDU_SIZE_OCTETS(CONFIG_BT_AUDIO_BITRATE_UNICAST_SINK)) {
    			LOG_ERR("The encoded data size does not match the SDU size");
    			return -EINVAL;
    		}
    +++	}
        /* rest of function unchanged */
    }	

    int unicast_client_enable(le_audio_receive_cb recv_cb)
    { /* unchanged until stream alternation loop */
        
    	for (int i = 0; i < ARRAY_SIZE(group_stream_params); i++) {
    		/* Every other stream should be sink or source */
    		if ((i % 2) == 0) {
    +++			if (IS_ENABLED(CONFIG_STEREO_CIS_HEADSET)) {
    +++				group_stream_params[i].qos = &lc3_preset_sink_stereo_qos;
    +++			} else {
    				group_stream_params[i].qos = &lc3_preset_sink.qos;
    +++		    }
                group_stream_params[i].stream = &headsets[headset_iterator].sink_stream;
    		} else {
    			group_stream_params[i].qos = &lc3_preset_source.qos;
    			group_stream_params[i].stream = &headsets[headset_iterator].source_stream;
    			headset_iterator++;
    		}
    	}
        /* unchanged to end of function */	
    }

    src/bluetooth/bt_stream/unicast/unicast_server.c:

    static struct bt_audio_codec_cap lc3_codec = BT_AUDIO_CODEC_CAP_LC3(
    	BT_AUDIO_CODEC_CAPABILIY_FREQ,
    	(BT_AUDIO_CODEC_LC3_DURATION_10 | BT_AUDIO_CODEC_LC3_DURATION_PREFER_10),
    +++
    #if CONFIG_STEREO_CIS_HEADSET
    	BT_AUDIO_CODEC_LC3_CHAN_COUNT_SUPPORT(2),
    #else
    	BT_AUDIO_CODEC_LC3_CHAN_COUNT_SUPPORT(1), 
    #endif /* CONFIG_STEREO_CIS_HEADSET */
    +++
    	LE_AUDIO_SDU_SIZE_OCTETS(CONFIG_LC3_BITRATE_MIN),
    	LE_AUDIO_SDU_SIZE_OCTETS(CONFIG_LC3_BITRATE_MAX), 1u, BT_AUDIO_CONTEXT_TYPE_MEDIA);

    src/audio/Kconfig:

    config MONO_TO_ALL_RECEIVERS
    	bool "Send mono (first/left channel) to all receivers"
    	default y if BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT = 1
    	default y if BT_BAP_BROADCAST_SRC_STREAM_COUNT = 1
    	default n
    	help
    	  With this flag set, the gateway will encode and send the same (first/left)
    	  channel on all ISO channels.
    
    +++
    config STEREO_CIS_HEADSET
    	bool "Stereo CIS headset demo"
    	default n
    +++
    
    endmenu # Stream

    src/audio/audio_system.c:

    static void audio_headset_configure(void)
    { /* unchanged until after birirectional chunck */
        #endif /* (CONFIG_STREAM_BIDIRECTIONAL) */
    +++	if (IS_ENABLED(CONFIG_STEREO_CIS_HEADSET)) {
    +++		sw_codec_cfg.decoder.num_ch = 2;
    +++		sw_codec_cfg.decoder.channel_mode = SW_CODEC_STEREO;
    +++	} else {
    +++		sw_codec_cfg.decoder.num_ch = 1;
    +++		sw_codec_cfg.decoder.channel_mode = SW_CODEC_MONO;
    +++	}
    	if (IS_ENABLED(CONFIG_SD_CARD_PLAYBACK)) {
    	/* unchanged to end of function */
    }

    After making the changes above you can build the application for with --ctlr="SDC". The full build command I used was (from the nrf5340_audio directory):

    python .\tools\buildprog\buildprog.py -c both -d headset -b debug -p -f

    Good luck and best regards,

    Maria

Related