Zephyr Project API  3.4.0
A Scalable Open Source RTOS
lc3.h
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2020 Intel Corporation
7 * Copyright (c) 2022 Nordic Semiconductor ASA
8 *
9 * SPDX-License-Identifier: Apache-2.0
10 */
11#ifndef ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_LC3_H_
12#define ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_LC3_H_
13
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
31#define BT_CODEC_LC3_ID 0x06
32
42
47
52
57
62
67};
68
72#define BT_CODEC_LC3_FREQ_8KHZ BIT(0)
76#define BT_CODEC_LC3_FREQ_11KHZ BIT(1)
80#define BT_CODEC_LC3_FREQ_16KHZ BIT(2)
84#define BT_CODEC_LC3_FREQ_22KHZ BIT(3)
88#define BT_CODEC_LC3_FREQ_24KHZ BIT(4)
92#define BT_CODEC_LC3_FREQ_32KHZ BIT(5)
96#define BT_CODEC_LC3_FREQ_44KHZ BIT(6)
100#define BT_CODEC_LC3_FREQ_48KHZ BIT(7)
104#define BT_CODEC_LC3_FREQ_ANY (BT_CODEC_LC3_FREQ_8KHZ | \
105 BT_CODEC_LC3_FREQ_16KHZ | \
106 BT_CODEC_LC3_FREQ_24KHZ | \
107 BT_CODEC_LC3_FREQ_32KHZ | \
108 BT_CODEC_LC3_FREQ_44KHZ | \
109 BT_CODEC_LC3_FREQ_48KHZ)
110
114#define BT_CODEC_LC3_DURATION_7_5 BIT(0)
118#define BT_CODEC_LC3_DURATION_10 BIT(1)
122#define BT_CODEC_LC3_DURATION_ANY (BT_CODEC_LC3_DURATION_7_5 | \
123 BT_CODEC_LC3_DURATION_10)
127#define BT_CODEC_LC3_DURATION_PREFER_7_5 BIT(4)
131#define BT_CODEC_LC3_DURATION_PREFER_10 BIT(5)
132
136#define BT_CODEC_LC3_CHAN_COUNT_MIN 1
140#define BT_CODEC_LC3_CHAN_COUNT_MAX 8
151#define BT_CODEC_LC3_CHAN_COUNT_SUPPORT(...) ((uint8_t)((FOR_EACH(BIT, (|), __VA_ARGS__)) >> 1))
152
156};
157
167
170
173
176
179
182};
183
187#define BT_CODEC_CONFIG_LC3_FREQ_8KHZ 0x01
191#define BT_CODEC_CONFIG_LC3_FREQ_11KHZ 0x02
195#define BT_CODEC_CONFIG_LC3_FREQ_16KHZ 0x03
199#define BT_CODEC_CONFIG_LC3_FREQ_22KHZ 0x04
203#define BT_CODEC_CONFIG_LC3_FREQ_24KHZ 0x05
207#define BT_CODEC_CONFIG_LC3_FREQ_32KHZ 0x06
211#define BT_CODEC_CONFIG_LC3_FREQ_44KHZ 0x07
215#define BT_CODEC_CONFIG_LC3_FREQ_48KHZ 0x08
219#define BT_CODEC_CONFIG_LC3_FREQ_88KHZ 0x09
223#define BT_CODEC_CONFIG_LC3_FREQ_96KHZ 0x0a
227#define BT_CODEC_CONFIG_LC3_FREQ_176KHZ 0x0b
231#define BT_CODEC_CONFIG_LC3_FREQ_192KHZ 0x0c
235#define BT_CODEC_CONFIG_LC3_FREQ_384KHZ 0x0d
236
240#define BT_CODEC_CONFIG_LC3_DURATION_7_5 0x00
244#define BT_CODEC_CONFIG_LC3_DURATION_10 0x01
245
246
252/* COND_CODE_1 is used to omit an LTV entry in case the _frames_per_sdu is 1.
253 * COND_CODE_1 will evaluate to second argument if the flag parameter(first argument) is 1
254 * - removing one layer of paranteses.
255 * If the flags argument is != 1 it will evaluate to the third argument which inserts a LTV
256 * entry for the max_frames_per_sdu value.
257 */
258#define BT_CODEC_LC3_DATA(_freq, _duration, _chan_count, _len_min, _len_max, _max_frames_per_sdu) \
259{ \
260 BT_CODEC_DATA(BT_CODEC_LC3_FREQ, BT_BYTES_LIST_LE16(_freq)), \
261 BT_CODEC_DATA(BT_CODEC_LC3_DURATION, _duration), \
262 BT_CODEC_DATA(BT_CODEC_LC3_CHAN_COUNT, _chan_count), \
263 BT_CODEC_DATA(BT_CODEC_LC3_FRAME_LEN, \
264 BT_BYTES_LIST_LE16(_len_min), \
265 BT_BYTES_LIST_LE16(_len_max)) \
266 COND_CODE_1(_max_frames_per_sdu, (), \
267 (, BT_CODEC_DATA(BT_CODEC_LC3_FRAME_COUNT, \
268 _max_frames_per_sdu))) \
269}
270
274#define BT_CODEC_LC3_META(_prefer_context) \
275{ \
276 BT_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PREF_CONTEXT, BT_BYTES_LIST_LE16(_prefer_context)) \
277}
278
282#define BT_CODEC_LC3(_freq, _duration, _chan_count, _len_min, _len_max, \
283 _max_frames_per_sdu, _prefer_context) \
284 BT_CODEC(BT_CODEC_LC3_ID, 0x0000, 0x0000, \
285 BT_CODEC_LC3_DATA(_freq, _duration, _chan_count, _len_min, \
286 _len_max, _max_frames_per_sdu), \
287 BT_CODEC_LC3_META(_prefer_context))
288
294/* COND_CODE_1 is used to omit an LTV entry in case the _frame_blocks_per_sdu is 1.
295 * COND_CODE_1 will evaluate to second argument if the flag parameter(first argument) is 1
296 * - removing one layer of parentheses.
297 * If the flags argument is != 1 it will evaluate to the third argument which inserts a LTV
298 * entry for the _frame_blocks_per_sdu value.
299 */
300#define BT_CODEC_LC3_CONFIG_DATA(_freq, _duration, _loc, _len, _frame_blocks_per_sdu) \
301{ \
302 BT_CODEC_DATA(BT_CODEC_CONFIG_LC3_FREQ, _freq), \
303 BT_CODEC_DATA(BT_CODEC_CONFIG_LC3_DURATION, _duration), \
304 BT_CODEC_DATA(BT_CODEC_CONFIG_LC3_CHAN_ALLOC, BT_BYTES_LIST_LE32(_loc)), \
305 BT_CODEC_DATA(BT_CODEC_CONFIG_LC3_FRAME_LEN, BT_BYTES_LIST_LE16(_len)), \
306 COND_CODE_1(_frame_blocks_per_sdu, (), \
307 (, BT_CODEC_DATA(BT_CODEC_CONFIG_LC3_FRAME_BLKS_PER_SDU, \
308 _frame_blocks_per_sdu))) \
309}
310
314#define BT_CODEC_LC3_CONFIG_META(_stream_context) \
315{ \
316 BT_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT, BT_BYTES_LIST_LE16(_stream_context)) \
317}
318
329#define BT_CODEC_LC3_CONFIG(_freq, _duration, _loc, _len, _frames_per_sdu, \
330 _stream_context) \
331 BT_CODEC(BT_CODEC_LC3_ID, 0x0000, 0x0000, \
332 BT_CODEC_LC3_CONFIG_DATA(_freq, _duration, _loc, _len, _frames_per_sdu), \
333 BT_CODEC_LC3_CONFIG_META(_stream_context))
334
341#define BT_CODEC_LC3_CONFIG_8_1(_loc, _stream_context) \
342 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_8KHZ, \
343 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 26u, \
344 1, _stream_context)
351#define BT_CODEC_LC3_CONFIG_8_2(_loc, _stream_context) \
352 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_8KHZ, \
353 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 30u, \
354 1, _stream_context)
361#define BT_CODEC_LC3_CONFIG_16_1(_loc, _stream_context) \
362 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_16KHZ, \
363 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 30u, \
364 1, _stream_context)
371#define BT_CODEC_LC3_CONFIG_16_2(_loc, _stream_context) \
372 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_16KHZ, \
373 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 40u, \
374 1, _stream_context)
375
382#define BT_CODEC_LC3_CONFIG_24_1(_loc, _stream_context) \
383 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_24KHZ, \
384 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 45u, \
385 1, _stream_context)
392#define BT_CODEC_LC3_CONFIG_24_2(_loc, _stream_context) \
393 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_24KHZ, \
394 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 60u, \
395 1, _stream_context)
402#define BT_CODEC_LC3_CONFIG_32_1(_loc, _stream_context) \
403 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_32KHZ, \
404 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 60u, \
405 1, _stream_context)
412#define BT_CODEC_LC3_CONFIG_32_2(_loc, _stream_context) \
413 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_32KHZ, \
414 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 80u, \
415 1, _stream_context)
422#define BT_CODEC_LC3_CONFIG_441_1(_loc, _stream_context) \
423 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_44KHZ, \
424 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 98u, \
425 1, _stream_context)
432#define BT_CODEC_LC3_CONFIG_441_2(_loc, _stream_context) \
433 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_44KHZ, \
434 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 130u, \
435 1, _stream_context)
442#define BT_CODEC_LC3_CONFIG_48_1(_loc, _stream_context) \
443 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_48KHZ, \
444 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 75u, \
445 1, _stream_context)
452#define BT_CODEC_LC3_CONFIG_48_2(_loc, _stream_context) \
453 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_48KHZ, \
454 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 100u, \
455 1, _stream_context)
462#define BT_CODEC_LC3_CONFIG_48_3(_loc, _stream_context) \
463 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_48KHZ, \
464 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 90u, \
465 1, _stream_context)
472#define BT_CODEC_LC3_CONFIG_48_4(_loc, _stream_context) \
473 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_48KHZ, \
474 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 120u, \
475 1, _stream_context)
482#define BT_CODEC_LC3_CONFIG_48_5(_loc, _stream_context) \
483 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_48KHZ, \
484 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 117u, \
485 1, _stream_context)
492#define BT_CODEC_LC3_CONFIG_48_6(_loc, _stream_context) \
493 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_48KHZ, \
494 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 155u, \
495 1, _stream_context)
499#define BT_CODEC_LC3_QOS_7_5(_framing, _sdu, _rtn, _latency, _pd) \
500 BT_CODEC_QOS(7500u, _framing, BT_CODEC_QOS_2M, _sdu, _rtn, \
501 _latency, _pd)
505#define BT_CODEC_LC3_QOS_7_5_UNFRAMED(_sdu, _rtn, _latency, _pd) \
506 BT_CODEC_QOS_UNFRAMED(7500u, _sdu, _rtn, _latency, _pd)
510#define BT_CODEC_LC3_QOS_10(_framing, _sdu, _rtn, _latency, _pd) \
511 BT_CODEC_QOS(10000u, _framing, BT_CODEC_QOS_2M, _sdu, _rtn, \
512 _latency, _pd)
516#define BT_CODEC_LC3_QOS_10_UNFRAMED(_sdu, _rtn, _latency, _pd) \
517 BT_CODEC_QOS_UNFRAMED(10000u, _sdu, _rtn, _latency, _pd)
518
519#ifdef __cplusplus
520}
521#endif
522
527#endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_LC3_H_ */
Bluetooth byteorder API.
bt_codec_capability_type
Codec capability type id's.
Definition: lc3.h:41
bt_codec_config_type
Codec configuration type IDs.
Definition: lc3.h:166
@ BT_CODEC_LC3_FRAME_COUNT
Max codec frame count per SDU capability type.
Definition: lc3.h:66
@ BT_CODEC_LC3_FRAME_LEN
LC3 frame length capability type.
Definition: lc3.h:61
@ BT_CODEC_LC3_CHAN_COUNT
LC3 channel count capability type.
Definition: lc3.h:56
@ BT_CODEC_LC3_DURATION
LC3 frame duration capability type.
Definition: lc3.h:51
@ BT_CODEC_LC3_FREQ
LC3 sample frequency capability type.
Definition: lc3.h:46
@ BT_CODEC_CONFIG_LC3_FREQ
LC3 Sample Frequency configuration type.
Definition: lc3.h:169
@ BT_CODEC_CONFIG_LC3_CHAN_ALLOC
LC3 channel Allocation configuration type.
Definition: lc3.h:175
@ BT_CODEC_CONFIG_LC3_FRAME_LEN
LC3 Frame Length configuration type.
Definition: lc3.h:178
@ BT_CODEC_CONFIG_LC3_DURATION
LC3 Frame Duration configuration type.
Definition: lc3.h:172
@ BT_CODEC_CONFIG_LC3_FRAME_BLKS_PER_SDU
Codec frame blocks, per SDU configuration type.
Definition: lc3.h:181
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Definition: lc3.h:153
uint16_t max
Definition: lc3.h:155
uint16_t min
Definition: lc3.h:154
Macro utilities.