1 /**
2  * @file
3  * @brief Bluetooth BAP Broadcast Sink LC3 header
4  *
5  * This files handles all the LC3 related functionality for the sample
6  *
7  * Copyright (c) 2025 Nordic Semiconductor ASA
8  *
9  * SPDX-License-Identifier: Apache-2.0
10  */
11 #ifndef SAMPLE_BAP_BROADCAST_SINK_LC3_H
12 #define SAMPLE_BAP_BROADCAST_SINK_LC3_H
13 
14 #include <stdbool.h>
15 #include <stddef.h>
16 #include <stdint.h>
17 #include <string.h>
18 
19 #include <zephyr/autoconf.h>
20 #include <zephyr/bluetooth/audio/audio.h>
21 #include <zephyr/bluetooth/iso.h>
22 #include <zephyr/device.h>
23 #include <zephyr/devicetree.h>
24 #include <zephyr/kernel.h>
25 #include <zephyr/logging/log.h>
26 #include <zephyr/net_buf.h>
27 #include <zephyr/shell/shell.h>
28 #include <zephyr/sys/ring_buffer.h>
29 #include <zephyr/sys/util.h>
30 #include <zephyr/sys/util_macro.h>
31 #include <zephyr/sys_clock.h>
32 #include <zephyr/toolchain.h>
33 #include <zephyr/usb/usb_device.h>
34 #include <zephyr/usb/class/usb_audio.h>
35 
36 #include "stream_rx.h"
37 
38 #define LC3_MAX_SAMPLE_RATE_HZ     48000U
39 #define LC3_MAX_FRAME_DURATION_US  10000U
40 #define LC3_MAX_NUM_SAMPLES_MONO                                                                   \
41 	((LC3_MAX_FRAME_DURATION_US * LC3_MAX_SAMPLE_RATE_HZ) / USEC_PER_SEC)
42 #define LC3_MAX_NUM_SAMPLES_STEREO (LC3_MAX_NUM_SAMPLES_MONO * 2U)
43 
44 /**
45  * @brief Enables LC3 for a stream
46  *
47  * This will initialize the LC3 decoder given the @p stream codec configuration
48  *
49  * @param stream The stream to enable LC3 for
50 
51  * @retval 0 Success
52  * @retval -EINVAL The stream is not LC3 codec configured or the codec configuration is invalid
53  */
54 int lc3_enable(struct stream_rx *stream);
55 
56 /**
57  * @brief Disabled LC3 for a stream
58  *
59  * @param stream The stream to disable LC3 for
60 
61  * @retval 0 Success
62  * @retval -EINVAL The stream is LC3 initialized
63  */
64 int lc3_disable(struct stream_rx *stream);
65 
66 /**
67  * @brief Enqueue an SDU for decoding
68  *
69  * @param stream The stream that received the SDU
70  * @param info Information about the SDU
71  * @param buf The buffer of the SDU
72  */
73 void lc3_enqueue_for_decoding(struct stream_rx *stream, const struct bt_iso_recv_info *info,
74 			      struct net_buf *buf);
75 
76 /**
77  * @brief Initialize the LC3 module
78  *
79  * This will start the thread if not already initialized
80  *
81  * @retval 0 Success
82  * @retval -EALREADY Already initialized
83  */
84 int lc3_init(void);
85 #endif /* SAMPLE_BAP_BROADCAST_SINK_LC3_H */
86