Skip to content

Commit

Permalink
bluetooth: audio: added support for 24kHz frequency to broadcast source
Browse files Browse the repository at this point in the history
Added option to support 24kHz frequency for broadcast_sample_source
Signed-off-by: Michele Imbriani <[email protected]>
  • Loading branch information
MicImbriani committed Nov 1, 2023
1 parent b1c207b commit 4a5ca8f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
22 changes: 22 additions & 0 deletions samples/bluetooth/broadcast_audio_source/Kconfig
Original file line number Diff line number Diff line change
@@ -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"
28 changes: 19 additions & 9 deletions samples/bluetooth/broadcast_audio_source/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down Expand Up @@ -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++) {
Expand All @@ -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;

Expand Down

0 comments on commit 4a5ca8f

Please sign in to comment.