Skip to content

Commit

Permalink
add 320hz 16khz, 800hz 24khz and 2000hz 48khz source builds.
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Sørensen <[email protected]>
  • Loading branch information
smaerup committed Nov 19, 2024
1 parent 4aef439 commit 974e293
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 5 deletions.
14 changes: 14 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ config BASE_CONFIG_1_48FL
help
Using the BASE_CONFIG_1_48FL configuration.

config BASE_CONFIG_1_16M
bool "1 subgroups with 16 KHz Mono"
help
Using the BASE_CONFIG_1_16M configuration.

config BASE_CONFIG_1_24M
bool "1 subgroups with 24 KHz Mono"
help
Using the BASE_CONFIG_1_24M configuration.

config BASE_CONFIG_1_48M
bool "1 subgroups with 48 KHz Mono"
help
Using the BASE_CONFIG_1_48M configuration.
endchoice

config BROADCAST_CODE
Expand Down
4 changes: 4 additions & 0 deletions app/base_1_16m.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Config overlay for 1 x 16 Mono BIS
CONFIG_BASE_CONFIG_1_16M=y
CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT=1
CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT=1
4 changes: 4 additions & 0 deletions app/base_1_24m.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Config overlay for 1 x 24 Mono BIS
CONFIG_BASE_CONFIG_1_24M=y
CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT=1
CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT=1
4 changes: 4 additions & 0 deletions app/base_1_48m.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Config overlay for 1 x 48 Mono BIS
CONFIG_BASE_CONFIG_1_48M=y
CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT=1
CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT=1
132 changes: 127 additions & 5 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <zephyr/bluetooth/audio/bap.h>
#include <zephyr/bluetooth/audio/bap_lc3_preset.h>

BUILD_ASSERT(strlen(CONFIG_BROADCAST_CODE) <= BT_AUDIO_BROADCAST_CODE_SIZE,
BUILD_ASSERT(strlen(CONFIG_BROADCAST_CODE) <= BT_ISO_BROADCAST_CODE_SIZE,
"Invalid broadcast code");

/* Zephyr Controller works best while Extended Advertising interval to be a multiple
Expand Down Expand Up @@ -49,10 +49,22 @@ static struct bt_bap_lc3_preset preset_16_stereo = BT_BAP_LC3_BROADCAST_PRESET_1
BT_AUDIO_LOCATION_FRONT_LEFT | BT_AUDIO_LOCATION_FRONT_RIGHT,
BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);

static struct bt_bap_lc3_preset preset_24_mono = BT_BAP_LC3_BROADCAST_PRESET_24_2_1(
BT_AUDIO_LOCATION_MONO_AUDIO,
BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);

static struct bt_bap_lc3_preset preset_24_front_left = BT_BAP_LC3_BROADCAST_PRESET_24_2_1(
BT_AUDIO_LOCATION_FRONT_LEFT,
BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);

static struct bt_bap_lc3_preset preset_24_stereo = BT_BAP_LC3_BROADCAST_PRESET_24_2_1(
BT_AUDIO_LOCATION_FRONT_LEFT | BT_AUDIO_LOCATION_FRONT_RIGHT,
BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);

static struct bt_bap_lc3_preset preset_48_mono = BT_BAP_LC3_BROADCAST_PRESET_48_2_1(
BT_AUDIO_LOCATION_MONO_AUDIO,
BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);

static struct bt_bap_lc3_preset preset_48_stereo = BT_BAP_LC3_BROADCAST_PRESET_48_2_1(
BT_AUDIO_LOCATION_FRONT_LEFT | BT_AUDIO_LOCATION_FRONT_RIGHT,
BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED);
Expand Down Expand Up @@ -547,6 +559,116 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source)

return 0;
}
#elif defined(CONFIG_BASE_CONFIG_1_16M) || defined(CONFIG_BASE_CONFIG_1_24M) || defined(CONFIG_BASE_CONFIG_1_48M)
#if defined(CONFIG_BASE_CONFIG_1_16M)
#define BT_AUDIO_BROADCAST_NAME "Mono 320hz 16khz"
#elif defined(CONFIG_BASE_CONFIG_1_24M)
#define BT_AUDIO_BROADCAST_NAME "Mono 800hz 24khz"
#elif defined(CONFIG_BASE_CONFIG_1_48M)
#define BT_AUDIO_BROADCAST_NAME "Mono 2000hz 48khz"
#endif

struct bt_audio_codec_cfg subgroup_codec_cfg[CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT];

static int setup_broadcast_source(struct bt_bap_broadcast_source **source)
{
int frame_us;
int srate_hz;
int nchannels;
int nsamples;
int sdu;
int ret;
int samples_per_frame;

struct bt_bap_broadcast_source_stream_param
stream_params[CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT];
struct bt_bap_broadcast_source_subgroup_param
subgroup_param[CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT];
struct bt_bap_broadcast_source_param create_param = {0};
int err;

for (size_t i = 0U; i < ARRAY_SIZE(subgroup_param); i++) {

#if defined(CONFIG_BASE_CONFIG_1_16M)
memcpy(&subgroup_codec_cfg[i], &preset_16_mono.codec_cfg,
sizeof(struct bt_audio_codec_cfg));
#elif defined(CONFIG_BASE_CONFIG_1_24M)
memcpy(&subgroup_codec_cfg[i], &preset_24_mono.codec_cfg,
sizeof(struct bt_audio_codec_cfg));
#elif defined(CONFIG_BASE_CONFIG_1_48M)
memcpy(&subgroup_codec_cfg[i], &preset_48_mono.codec_cfg,
sizeof(struct bt_audio_codec_cfg));
#endif

/* MONO is implicit if omitted */
bt_audio_codec_cfg_unset_val(&subgroup_codec_cfg[i], BT_AUDIO_CODEC_CFG_CHAN_ALLOC);

subgroup_param[i].params_count = 1;
subgroup_param[i].params = &stream_params[i];
subgroup_param[i].codec_cfg = &subgroup_codec_cfg[i];
}

for (size_t j = 0U; j < ARRAY_SIZE(stream_params); j++) {
stream_params[j].data = NULL;
stream_params[j].data_len = 0;
#if defined(CONFIG_BASE_CONFIG_1_16M)
samples_per_frame = 160;
sdu = preset_16_mono.qos.sdu;
streams[j].data_ptr = (uint8_t *)lc3_sine_0320_16;
#elif defined(CONFIG_BASE_CONFIG_1_24M)
samples_per_frame = 240;
sdu = preset_24_mono.qos.sdu;
streams[j].data_ptr = (uint8_t *)lc3_sine_0800_24;
#elif defined(CONFIG_BASE_CONFIG_1_48M)
samples_per_frame = 480;
sdu = preset_48_mono.qos.sdu;
streams[j].data_ptr = (uint8_t *)lc3_sine_2000_48;
#endif

printk("Reading LC3 Music header (%p)\n", streams[j].data_ptr);
printk("======================\n");

ret = lc3bin_read_header(&streams[j].data_ptr, &frame_us, &srate_hz, &nchannels, &nsamples);

printk("Frame size: %dus\n", frame_us);
printk("Sample rate: %dHz\n", srate_hz);
printk("Number of channels: %d\n", nchannels);
printk("Number of samples: %d\n", nsamples);

/* Store position of start and end+1 of frame blocks */
streams[j].start_data_ptr = streams[j].data_ptr;
streams[j].end_data_ptr = streams[j].data_ptr + (nsamples / samples_per_frame) *
(sdu + 2); // TBD

streams[j].sdu = sdu;

stream_params[j].stream = &streams[j].stream;
bt_bap_stream_cb_register(stream_params[j].stream, &stream_ops);
}

create_param.params_count = ARRAY_SIZE(subgroup_param);
create_param.params = subgroup_param;

#if defined(CONFIG_BASE_CONFIG_1_16M)
create_param.qos = &preset_16_mono.qos;
#elif defined(CONFIG_BASE_CONFIG_1_24M)
create_param.qos = &preset_24_mono.qos;
#elif defined(CONFIG_BASE_CONFIG_1_48M)
create_param.qos = &preset_48_mono.qos;
#endif

create_param.encryption = strlen(CONFIG_BROADCAST_CODE) > 0;
create_param.packing = BT_ISO_PACKING_SEQUENTIAL;

err = bt_bap_broadcast_source_create(&create_param, source);
if (err != 0) {
printk("Unable to create broadcast source: %d\n", err);
return err;
}

return 0;
}

#elif defined(CONFIG_BASE_CONFIG_1_16FL)
#define BT_AUDIO_BROADCAST_NAME "Multi 1x 16FL"

Expand All @@ -573,7 +695,7 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source)

for (size_t i = 0U; i < ARRAY_SIZE(subgroup_param); i++) {

memcpy(&subgroup_codec_cfg[i], &preset_48_front_left.codec_cfg,
memcpy(&subgroup_codec_cfg[i], &preset_16_front_left.codec_cfg,
sizeof(struct bt_audio_codec_cfg));

subgroup_param[i].params_count = 1;
Expand Down Expand Up @@ -744,9 +866,9 @@ int main(void)
return 0;
}

err = bt_bap_broadcast_source_get_id(broadcast_source, &broadcast_id);
if (err != 0) {
printk("Unable to get broadcast ID: %d\n", err);
err = bt_rand(&broadcast_id, BT_AUDIO_BROADCAST_ID_SIZE);
if (err) {
printk("Unable to generate broadcast ID: %d\n", err);
return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions compile_app_1_16M.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

west build -b nrf52840dongle app --pristine -- "-DOVERLAY_CONFIG=overlay-bt_ll_sw_split.conf;base_1_16m.conf"
3 changes: 3 additions & 0 deletions compile_app_1_24M.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

west build -b nrf52840dongle app --pristine -- "-DOVERLAY_CONFIG=overlay-bt_ll_sw_split.conf;base_1_24m.conf"
3 changes: 3 additions & 0 deletions compile_app_1_48M.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

west build -b nrf52840dongle app --pristine -- "-DOVERLAY_CONFIG=overlay-bt_ll_sw_split.conf;base_1_48m.conf"
File renamed without changes.

0 comments on commit 974e293

Please sign in to comment.