From 4a5ca8f93b0abc9780a4ed72c6cb812489e2c50f Mon Sep 17 00:00:00 2001 From: Michele Imbriani Date: Tue, 31 Oct 2023 14:10:47 +0100 Subject: [PATCH] bluetooth: audio: added support for 24kHz frequency to broadcast source Added option to support 24kHz frequency for broadcast_sample_source Signed-off-by: Michele Imbriani --- .../bluetooth/broadcast_audio_source/Kconfig | 22 +++++++++++++++ .../broadcast_audio_source/src/main.c | 28 +++++++++++++------ 2 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 samples/bluetooth/broadcast_audio_source/Kconfig diff --git a/samples/bluetooth/broadcast_audio_source/Kconfig b/samples/bluetooth/broadcast_audio_source/Kconfig new file mode 100644 index 000000000000000..91cca49cc074435 --- /dev/null +++ b/samples/bluetooth/broadcast_audio_source/Kconfig @@ -0,0 +1,22 @@ +# Copyright (c) 2023 Demant A/S +# SPDX-License-Identifier: Apache-2.0 + +mainmenu "Bluetooth: Broadcast Audio Source" + +choice BAP_LC3_PRESET + prompt "The BAP LC3 Preset to be used" + default BAP_BROADCAST_16_2_1 + +config BAP_BROADCAST_16_2_1 + bool "BAP_LC3_BROADCAST_PRESET_16_2_1 preset" + help + Using the BAP_LC3_BROADCAST_PRESET_16_2_1 preset. + +config BAP_BROADCAST_24_2_1 + bool "BAP_LC3_BROADCAST_PRESET_24_2_1 preset" + help + Using the BAP_LC3_BROADCAST_PRESET_24_2_1 preset. + +endchoice + +source "Kconfig.zephyr" diff --git a/samples/bluetooth/broadcast_audio_source/src/main.c b/samples/bluetooth/broadcast_audio_source/src/main.c index 6dc853f2d6dd637..369c7b0d0ec644f 100644 --- a/samples/bluetooth/broadcast_audio_source/src/main.c +++ b/samples/bluetooth/broadcast_audio_source/src/main.c @@ -29,11 +29,21 @@ #define TOTAL_BUF_NEEDED (BROADCAST_ENQUEUE_COUNT * CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT) BUILD_ASSERT(CONFIG_BT_ISO_TX_BUF_COUNT >= TOTAL_BUF_NEEDED, - "CONFIG_BT_ISO_TX_BUF_COUNT should be at least " - "BROADCAST_ENQUEUE_COUNT * CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT"); + "CONFIG_BT_ISO_TX_BUF_COUNT should be at least " + "BROADCAST_ENQUEUE_COUNT * CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT"); -static struct bt_bap_lc3_preset preset_16_2_1 = BT_BAP_LC3_BROADCAST_PRESET_16_2_1( +#if defined(CONFIG_BAP_BROADCAST_16_2_1) + +static struct bt_bap_lc3_preset preset_active = BT_BAP_LC3_BROADCAST_PRESET_16_2_1( + BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); + +#elif defined(CONFIG_BAP_BROADCAST_24_2_1) + +static struct bt_bap_lc3_preset preset_active = BT_BAP_LC3_BROADCAST_PRESET_24_2_1( BT_AUDIO_LOCATION_FRONT_LEFT, BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED); + +#endif + static struct broadcast_source_stream { struct bt_bap_stream stream; uint16_t seq_num; @@ -70,7 +80,7 @@ static int octets_per_frame; static void init_lc3(void) { - const struct bt_audio_codec_cfg *codec_cfg = &preset_16_2_1.codec_cfg; + const struct bt_audio_codec_cfg *codec_cfg = &preset_active.codec_cfg; int ret; ret = bt_audio_codec_cfg_get_freq(codec_cfg); @@ -152,7 +162,7 @@ static void stream_sent_cb(struct bt_bap_stream *stream) net_buf_reserve(buf, BT_ISO_CHAN_SEND_RESERVE); #if defined(CONFIG_LIBLC3) int lc3_ret; - uint8_t lc3_encoder_buffer[preset_16_2_1.qos.sdu]; + uint8_t lc3_encoder_buffer[preset_active.qos.sdu]; if (lc3_encoder == NULL) { printk("LC3 encoder not setup, cannot encode data.\n"); @@ -167,9 +177,9 @@ static void stream_sent_cb(struct bt_bap_stream *stream) return; } - net_buf_add_mem(buf, lc3_encoder_buffer, preset_16_2_1.qos.sdu); + net_buf_add_mem(buf, lc3_encoder_buffer, preset_active.qos.sdu); #else - net_buf_add_mem(buf, mock_data, preset_16_2_1.qos.sdu); + net_buf_add_mem(buf, mock_data, preset_active.qos.sdu); #endif /* defined(CONFIG_LIBLC3) */ ret = bt_bap_stream_send(stream, buf, source_stream->seq_num++, BT_ISO_TIMESTAMP_NONE); @@ -207,7 +217,7 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source) for (size_t i = 0U; i < ARRAY_SIZE(subgroup_param); i++) { subgroup_param[i].params_count = streams_per_subgroup; subgroup_param[i].params = stream_params + i * streams_per_subgroup; - subgroup_param[i].codec_cfg = &preset_16_2_1.codec_cfg; + subgroup_param[i].codec_cfg = &preset_active.codec_cfg; } for (size_t j = 0U; j < ARRAY_SIZE(stream_params); j++) { @@ -219,7 +229,7 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source) create_param.params_count = ARRAY_SIZE(subgroup_param); create_param.params = subgroup_param; - create_param.qos = &preset_16_2_1.qos; + create_param.qos = &preset_active.qos; create_param.encryption = false; create_param.packing = BT_ISO_PACKING_SEQUENTIAL;