Zephyr Project API  3.3.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
21#include <zephyr/types.h>
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, \
261 ((_freq) & 0xFFU), \
262 (((_freq) >> 8) & 0xFFU)), \
263 BT_CODEC_DATA(BT_CODEC_LC3_DURATION, _duration), \
264 BT_CODEC_DATA(BT_CODEC_LC3_CHAN_COUNT, _chan_count), \
265 BT_CODEC_DATA(BT_CODEC_LC3_FRAME_LEN, \
266 ((_len_min) & 0xFFU), \
267 (((_len_min) >> 8) & 0xFFU), \
268 ((_len_max) & 0xFFU), \
269 (((_len_max) >> 8) & 0xFFU)) \
270 COND_CODE_1(_max_frames_per_sdu, (), \
271 (, BT_CODEC_DATA(BT_CODEC_LC3_FRAME_COUNT, \
272 _max_frames_per_sdu))) \
273}
274
278#define BT_CODEC_LC3_META(_prefer_context) \
279{ \
280 BT_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PREF_CONTEXT, \
281 ((_prefer_context) & 0xFFU), \
282 (((_prefer_context) >> 8) & 0xFFU)) \
283}
284
288#define BT_CODEC_LC3(_freq, _duration, _chan_count, _len_min, _len_max, \
289 _max_frames_per_sdu, _prefer_context) \
290 BT_CODEC(BT_CODEC_LC3_ID, 0x0000, 0x0000, \
291 BT_CODEC_LC3_DATA(_freq, _duration, _chan_count, _len_min, \
292 _len_max, _max_frames_per_sdu), \
293 BT_CODEC_LC3_META(_prefer_context))
294
300/* COND_CODE_1 is used to omit an LTV entry in case the _frame_blocks_per_sdu is 1.
301 * COND_CODE_1 will evaluate to second argument if the flag parameter(first argument) is 1
302 * - removing one layer of parentheses.
303 * If the flags argument is != 1 it will evaluate to the third argument which inserts a LTV
304 * entry for the _frame_blocks_per_sdu value.
305 */
306#define BT_CODEC_LC3_CONFIG_DATA(_freq, _duration, _loc, _len, _frame_blocks_per_sdu) \
307{ \
308 BT_CODEC_DATA(BT_CODEC_CONFIG_LC3_FREQ, _freq), \
309 BT_CODEC_DATA(BT_CODEC_CONFIG_LC3_DURATION, _duration), \
310 BT_CODEC_DATA(BT_CODEC_CONFIG_LC3_CHAN_ALLOC, \
311 ((_loc) & 0xFFU), \
312 (((_loc) >> 8) & 0xFFU), \
313 (((_loc) >> 16) & 0xFFU), \
314 (((_loc) >> 24) & 0xFFU)), \
315 BT_CODEC_DATA(BT_CODEC_CONFIG_LC3_FRAME_LEN, \
316 ((_len) & 0xFFU), \
317 (((_len) >> 8) & 0xFFU)) \
318 COND_CODE_1(_frame_blocks_per_sdu, (), \
319 (, BT_CODEC_DATA(BT_CODEC_CONFIG_LC3_FRAME_BLKS_PER_SDU, \
320 _frame_blocks_per_sdu))) \
321}
322
326#define BT_CODEC_LC3_CONFIG_META(_stream_context) \
327{ \
328 BT_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT, \
329 ((_stream_context) & 0xFFU), \
330 (((_stream_context) >> 8) & 0xFFU)) \
331}
332
343#define BT_CODEC_LC3_CONFIG(_freq, _duration, _loc, _len, _frames_per_sdu, \
344 _stream_context) \
345 BT_CODEC(BT_CODEC_LC3_ID, 0x0000, 0x0000, \
346 BT_CODEC_LC3_CONFIG_DATA(_freq, _duration, _loc, _len, _frames_per_sdu), \
347 BT_CODEC_LC3_CONFIG_META(_stream_context))
348
355#define BT_CODEC_LC3_CONFIG_8_1(_loc, _stream_context) \
356 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_8KHZ, \
357 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 26u, \
358 1, _stream_context)
365#define BT_CODEC_LC3_CONFIG_8_2(_loc, _stream_context) \
366 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_8KHZ, \
367 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 30u, \
368 1, _stream_context)
375#define BT_CODEC_LC3_CONFIG_16_1(_loc, _stream_context) \
376 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_16KHZ, \
377 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 30u, \
378 1, _stream_context)
385#define BT_CODEC_LC3_CONFIG_16_2(_loc, _stream_context) \
386 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_16KHZ, \
387 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 40u, \
388 1, _stream_context)
389
396#define BT_CODEC_LC3_CONFIG_24_1(_loc, _stream_context) \
397 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_24KHZ, \
398 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 45u, \
399 1, _stream_context)
406#define BT_CODEC_LC3_CONFIG_24_2(_loc, _stream_context) \
407 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_24KHZ, \
408 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 60u, \
409 1, _stream_context)
416#define BT_CODEC_LC3_CONFIG_32_1(_loc, _stream_context) \
417 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_32KHZ, \
418 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 60u, \
419 1, _stream_context)
426#define BT_CODEC_LC3_CONFIG_32_2(_loc, _stream_context) \
427 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_32KHZ, \
428 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 80u, \
429 1, _stream_context)
436#define BT_CODEC_LC3_CONFIG_441_1(_loc, _stream_context) \
437 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_44KHZ, \
438 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 98u, \
439 1, _stream_context)
446#define BT_CODEC_LC3_CONFIG_441_2(_loc, _stream_context) \
447 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_44KHZ, \
448 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 130u, \
449 1, _stream_context)
456#define BT_CODEC_LC3_CONFIG_48_1(_loc, _stream_context) \
457 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_48KHZ, \
458 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 75u, \
459 1, _stream_context)
466#define BT_CODEC_LC3_CONFIG_48_2(_loc, _stream_context) \
467 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_48KHZ, \
468 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 100u, \
469 1, _stream_context)
476#define BT_CODEC_LC3_CONFIG_48_3(_loc, _stream_context) \
477 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_48KHZ, \
478 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 90u, \
479 1, _stream_context)
486#define BT_CODEC_LC3_CONFIG_48_4(_loc, _stream_context) \
487 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_48KHZ, \
488 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 120u, \
489 1, _stream_context)
496#define BT_CODEC_LC3_CONFIG_48_5(_loc, _stream_context) \
497 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_48KHZ, \
498 BT_CODEC_CONFIG_LC3_DURATION_7_5, _loc, 117u, \
499 1, _stream_context)
506#define BT_CODEC_LC3_CONFIG_48_6(_loc, _stream_context) \
507 BT_CODEC_LC3_CONFIG(BT_CODEC_CONFIG_LC3_FREQ_48KHZ, \
508 BT_CODEC_CONFIG_LC3_DURATION_10, _loc, 155u, \
509 1, _stream_context)
513#define BT_CODEC_LC3_QOS_7_5(_framing, _sdu, _rtn, _latency, _pd) \
514 BT_CODEC_QOS(7500u, _framing, BT_CODEC_QOS_2M, _sdu, _rtn, \
515 _latency, _pd)
519#define BT_CODEC_LC3_QOS_7_5_UNFRAMED(_sdu, _rtn, _latency, _pd) \
520 BT_CODEC_QOS_UNFRAMED(7500u, _sdu, _rtn, _latency, _pd)
524#define BT_CODEC_LC3_QOS_10(_framing, _sdu, _rtn, _latency, _pd) \
525 BT_CODEC_QOS(10000u, _framing, BT_CODEC_QOS_2M, _sdu, _rtn, \
526 _latency, _pd)
530#define BT_CODEC_LC3_QOS_10_UNFRAMED(_sdu, _rtn, _latency, _pd) \
531 BT_CODEC_QOS_UNFRAMED(10000u, _sdu, _rtn, _latency, _pd)
532
533#ifdef __cplusplus
534}
535#endif
536
541#endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_LC3_H_ */
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.