Skip to content

Commit

Permalink
samples: broadcast_config_tool: Stream LC3 files
Browse files Browse the repository at this point in the history
Implement the LC3 streamer in the sample application to allow
users to select files stored on the SD card and stream them
to configured streams.

OCT-3109

Signed-off-by: Andreas Vibeto <andreas.vibeto@nordicsemi.no>
  • Loading branch information
andvib authored and rlubos committed Sep 23, 2024
1 parent f0cd539 commit 132c5e5
Show file tree
Hide file tree
Showing 10 changed files with 440 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ struct bt_cap_initiator_broadcast_create_param create_param[CONFIG_BT_ISO_MAX_BI
/* Make sure we have statically allocated streams for all potential BISes */
static struct bt_cap_stream cap_streams[CONFIG_BT_ISO_MAX_BIG]
[CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT]
[CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT /
CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT];
[CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT];

static struct bt_bap_lc3_preset lc3_preset = BT_BAP_LC3_BROADCAST_PRESET_NRF5340_AUDIO;

Expand Down
6 changes: 3 additions & 3 deletions applications/nrf5340_audio/src/modules/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ config SD_CARD_PLAYBACK_RING_BUF_SIZE
int "Size of the ring buffer for the SD card playback module"
default 960

config SD_CARD_PLAYBACK_THREAD_PRIORITY
config SD_CARD_PLAYBACK_THREAD_PRIO
int "Priority for the SD card playback thread"
default 7

Expand All @@ -211,9 +211,9 @@ config SD_CARD_LC3_STREAMER_STACK_SIZE
int "Stack size for the SD card LC3 streamer thread"
default 1500

config SD_CARD_LC3_STREAMER_THREAD_PRIORITY
config SD_CARD_LC3_STREAMER_THREAD_PRIO
int "Priority for the SD card LC3 streamer thread"
default 7
default 4

config SD_CARD_LC3_STREAMER_MAX_NUM_STREAMS
int "Maximum number of concurrent LC3 streams"
Expand Down
2 changes: 1 addition & 1 deletion applications/nrf5340_audio/src/modules/lc3_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int lc3_file_frame_get(struct lc3_file_ctx *file, uint8_t *buffer, size_t buffer
}

if ((frame_header_size == 0) || (frame_header == 0)) {
LOG_ERR("No more frames to read");
LOG_DBG("No more frames to read");
return -ENODATA;
}

Expand Down
13 changes: 10 additions & 3 deletions applications/nrf5340_audio/src/modules/lc3_streamer.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ static int put_next_frame_to_fifo(struct lc3_stream *stream)
ret = lc3_file_frame_get(&stream->file, data_ptr,
CONFIG_SD_CARD_LC3_STREAMER_MAX_FRAME_SIZE);
if (ret) {
LOG_ERR("Failed to get frame from file %d", ret);
if (ret != -ENODATA) {
LOG_ERR("Failed to get frame from file %d", ret);
}

data_fifo_block_free(&stream->fifo, (void *)data_ptr);
return ret;
}
Expand Down Expand Up @@ -245,7 +248,11 @@ int lc3_streamer_next_frame_get(const uint8_t streamer_idx, const uint8_t **cons
ret = data_fifo_pointer_last_filled_get(&stream->fifo, (void **)&data_ptr, &data_len,
K_NO_WAIT);
if (ret) {
LOG_ERR("Failed to get last filled block %d", ret);
if (ret == -ENOMSG) {
LOG_DBG("Next block is not ready %d", ret);
} else {
LOG_ERR("Failed to get last filled block %d", ret);
}
return ret;
}

Expand Down Expand Up @@ -465,7 +472,7 @@ int lc3_streamer_init(void)
k_work_queue_init(&lc3_streamer_work_q);
k_work_queue_start(&lc3_streamer_work_q, lc3_streamer_work_q_stack_area,
K_THREAD_STACK_SIZEOF(lc3_streamer_work_q_stack_area),
CONFIG_SD_CARD_LC3_STREAMER_THREAD_PRIORITY, NULL);
CONFIG_SD_CARD_LC3_STREAMER_THREAD_PRIO, NULL);
k_thread_name_set(&lc3_streamer_work_q.thread, "lc3_streamer_work_q");

initialized = true;
Expand Down
2 changes: 1 addition & 1 deletion applications/nrf5340_audio/src/modules/sd_card_playback.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ int sd_card_playback_init(void)
sd_card_playback_thread_id = k_thread_create(
&sd_card_playback_thread_data, sd_card_playback_thread_stack,
CONFIG_SD_CARD_PLAYBACK_STACK_SIZE, (k_thread_entry_t)sd_card_playback_thread, NULL,
NULL, NULL, K_PRIO_PREEMPT(CONFIG_SD_CARD_PLAYBACK_THREAD_PRIORITY), 0, K_NO_WAIT);
NULL, NULL, K_PRIO_PREEMPT(CONFIG_SD_CARD_PLAYBACK_THREAD_PRIO), 0, K_NO_WAIT);
ret = k_thread_name_set(sd_card_playback_thread_id, "sd_card_playback");
if (ret) {
return ret;
Expand Down
6 changes: 4 additions & 2 deletions samples/bluetooth/broadcast_config_tool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ zephyr_library_include_directories(app PRIVATE

add_subdirectory(${ZEPHYR_NRF_MODULE_DIR}/applications/nrf5340_audio/src/bluetooth bluetooth_build)

target_sources_ifdef(CONFIG_NRF5340_AUDIO_SD_CARD_MODULE app PRIVATE ${ZEPHYR_NRF_MODULE_DIR}/applications/nrf5340_audio/src/modules/sd_card.c)

target_sources(app PRIVATE ${ZEPHYR_NRF_MODULE_DIR}/applications/nrf5340_audio/src/modules/audio_sync_timer.c)
target_sources(app PRIVATE ${ZEPHYR_NRF_MODULE_DIR}/applications/nrf5340_audio/src/modules/led.c)

target_sources_ifdef(CONFIG_NRF5340_AUDIO_SD_CARD_MODULE app PRIVATE ${ZEPHYR_NRF_MODULE_DIR}/applications/nrf5340_audio/src/modules/sd_card.c)
target_sources_ifdef(CONFIG_NRF5340_AUDIO_SD_CARD_LC3_FILE app PRIVATE ${ZEPHYR_NRF_MODULE_DIR}/applications/nrf5340_audio/src/modules/lc3_file.c)
target_sources_ifdef(CONFIG_NRF5340_AUDIO_SD_CARD_LC3_STREAMER app PRIVATE ${ZEPHYR_NRF_MODULE_DIR}/applications/nrf5340_audio/src/modules/lc3_streamer.c)

FILE(GLOB app_sources src/*.c)

Expand Down
51 changes: 51 additions & 0 deletions samples/bluetooth/broadcast_config_tool/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,57 @@ Example output:
Location:
BIS 0: Mono Audio
----

file list
=========

Lists the files and directories in the given directory on the SD card.
If no directory is given, contents of the root directory is listed.

Usage:

.. code-block:: console
bct file list [directory]
Example output:

.. code-block:: console
bct file list
[DIR ] 16000hz
[DIR ] 24000hz
[DIR ] 32000hz
[FILE] left-channel-announcement.wav
[FILE] right-channel-announcement.wav
----

file select
===========

Selects a file from the SD card to be used as the audio source for the given stream.
The file must be in the LC3 format, and one file may be used for multiple streams at the same time.

Usage:

.. code-block:: console
bct file select <file> <BIG index> <subgroup index> <BIS index>
Example:

.. code-block:: console
bct file select 16000hz/24_kbps/left-channel-announcement_16kHz_left_24kbps.lc3 1 2 0
This command command selects the file :file:`16000hz/24_kbps/left-channel-announcement_16kHz_left_24kbps.lc3` for the BIS 0 in the subgroup 2 in the BIG 1.

----

packing
=======

Expand Down
10 changes: 10 additions & 0 deletions samples/bluetooth/broadcast_config_tool/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CONFIG_LOG=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_LOG_TAG_MAX_LEN=2
CONFIG_LOG_TAG_DEFAULT="--"
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_BUFFER_SIZE=4096

Expand Down Expand Up @@ -142,4 +143,13 @@ CONFIG_TRANSPORT_BIS=y
CONFIG_BT_AUDIO_BROADCAST_CONFIGURABLE=y
CONFIG_BT_AUDIO_BROADCAST_ZBUS_EVT_STREAM_SENT=y

CONFIG_LE_AUDIO_MSG_SUB_THREAD_PRIO=3

CONFIG_SW_CODEC_LC3=n

CONFIG_NRF5340_AUDIO_SD_CARD_MODULE=y
CONFIG_NRF5340_AUDIO_SD_CARD_LC3_FILE=y
CONFIG_NRF5340_AUDIO_SD_CARD_LC3_STREAMER=y
CONFIG_SD_CARD_LC3_STREAMER_STACK_SIZE=3000

CONFIG_MODULE_SD_CARD_LOG_LEVEL_WRN=y
Loading

0 comments on commit 132c5e5

Please sign in to comment.