diff --git a/app/Kconfig b/app/Kconfig index 415c80a..6219577 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -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 diff --git a/app/base_1_16m.conf b/app/base_1_16m.conf new file mode 100644 index 0000000..8aadf23 --- /dev/null +++ b/app/base_1_16m.conf @@ -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 diff --git a/app/base_1_24m.conf b/app/base_1_24m.conf new file mode 100644 index 0000000..9c19a76 --- /dev/null +++ b/app/base_1_24m.conf @@ -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 diff --git a/app/base_1_48m.conf b/app/base_1_48m.conf new file mode 100644 index 0000000..ca87081 --- /dev/null +++ b/app/base_1_48m.conf @@ -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 diff --git a/app/src/main.c b/app/src/main.c index 96e0cc1..58ebe43 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -11,7 +11,7 @@ #include #include -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 @@ -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); @@ -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" @@ -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; @@ -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; } diff --git a/compile_app_1_16M.sh b/compile_app_1_16M.sh new file mode 100755 index 0000000..aba1e66 --- /dev/null +++ b/compile_app_1_16M.sh @@ -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" diff --git a/compile_app_1_24M.sh b/compile_app_1_24M.sh new file mode 100755 index 0000000..3a3bf0d --- /dev/null +++ b/compile_app_1_24M.sh @@ -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" diff --git a/compile_app_1_48M.sh b/compile_app_1_48M.sh new file mode 100755 index 0000000..8bf67d2 --- /dev/null +++ b/compile_app_1_48M.sh @@ -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" diff --git a/compile_app.sh b/compile_app_24S_16S.sh similarity index 100% rename from compile_app.sh rename to compile_app_24S_16S.sh