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.

Parents
  • Hello,

    I will discuss this with our LE Audio engineers and get back to you when I know more. Thank you for your patience.

    Best regards,

    Maria

  • Hello, Maria.

    Thank you very much. I will wait for you.

  • Hello,

    I am not completely sure that I have the correct understanding of your wanted topology, so please correct me if I have made any wrong assumptions. If you need further support after my reply: Please share a simple diagram of your wanted system. It will make it a bit easier to visualize what you need.

    From your linked ticket I can see that you are aware of the work you need to do to make stereo audio work, so I will not address this here.

    You can set up the Gateway and Headsets to be bidirectional with CONFIG_STREAM_BIDIRECTIONAL=y. This will allow the device to encode and decode audio. The decoding may not be needed on the Gateway, depending on how you organize the input audio streams on the Gateway. Note that if you need to mix the streams, the relay functionality will be more involved to implement. If you just wish to forward the already encoded stream to the other headset, you only need to implement a reroute on the Gateway for the stream from the first Headset to the second Headset.

    What I need is that in CIS mode, the Gateway can connect two Headsets with an audio sampling rate of at least 48KHz

    Using CONFIG_BT_BAP_UNICAST_CONFIGURABLE=y will allow you to set up other combinations of sampling frequency/bit rates/retransmissions. See the BAP Specification available here, and see the possible combination in table 5.2. An important note is that we only support 10ms frame duration now.

    Best regards,

    Maria

  • Hello,Maria

    Sorry,my description may be a bit confusing. The function I want to implement is to send the stereo audio signal received by one headset (I can try to input an external signal from one headset's codec) through the gateway to another headset. However, once the 48K sampling rate is maintained, the gateway cannot connect two headsets at the same time, even if I use BT_ MAX_ CONN is set to 2, and when connecting to any headset, it will log out “disconnect Reason 13”, I found that the error code that 13 means CONNECTION REJUCTED DUE TO LIMITED  RESOURCES, that why i tried to reduce the audio sample rate to 24K.


    So I don't know what can i do now. I think although I need to connect the gateway to two Headsets, I can temporarily only send audio data to one Headset and the other Headset is only used to receive audio data.But it seems that the current default setting is that once a connection is established, it will occupy resources, and I don't know where to modify these. I hope you can give me some advice, thank you.

  • Hello,

    I would like to reproduce this. Are you able to share the code? I can make the ticket private if needed.

    Best regards,

    Maria

Reply Children
  • 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