nRF Connect SDK API 2.8.99
Loading...
Searching...
No Matches
le_audio.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef _LE_AUDIO_H_
8#define _LE_AUDIO_H_
9
10#include <zephyr/bluetooth/audio/bap.h>
11#include <audio_defines.h>
12
13#define LE_AUDIO_ZBUS_EVENT_WAIT_TIME K_MSEC(5)
14#define LE_AUDIO_SDU_SIZE_OCTETS(bitrate) (bitrate / (1000000 / CONFIG_AUDIO_FRAME_DURATION_US) / 8)
15
16#if CONFIG_SAMPLE_RATE_CONVERTER && CONFIG_AUDIO_SAMPLE_RATE_48000_HZ
17#define BT_AUDIO_CODEC_CAPABILIY_FREQ \
18 BT_AUDIO_CODEC_CAP_FREQ_48KHZ | BT_AUDIO_CODEC_CAP_FREQ_24KHZ | \
19 BT_AUDIO_CODEC_CAP_FREQ_16KHZ
20
21#elif CONFIG_AUDIO_SAMPLE_RATE_16000_HZ
22#define BT_AUDIO_CODEC_CAPABILIY_FREQ BT_AUDIO_CODEC_CAP_FREQ_16KHZ
23
24#elif CONFIG_AUDIO_SAMPLE_RATE_24000_HZ
25#define BT_AUDIO_CODEC_CAPABILIY_FREQ BT_AUDIO_CODEC_CAP_FREQ_24KHZ
26
27#elif CONFIG_AUDIO_SAMPLE_RATE_48000_HZ
28#define BT_AUDIO_CODEC_CAPABILIY_FREQ BT_AUDIO_CODEC_CAP_FREQ_48KHZ
29
30#else
31#error No sample rate supported
32#endif /* CONFIG_SAMPLE_RATE_CONVERTER */
33
34#define BT_BAP_LC3_PRESET_CONFIGURABLE(_loc, _stream_context, _bitrate) \
35 BT_BAP_LC3_PRESET(BT_AUDIO_CODEC_LC3_CONFIG(CONFIG_BT_AUDIO_PREF_SAMPLE_RATE_VALUE, \
36 BT_AUDIO_CODEC_CFG_DURATION_10, _loc, \
37 LE_AUDIO_SDU_SIZE_OCTETS(_bitrate), 1, \
38 _stream_context), \
39 BT_AUDIO_CODEC_QOS_UNFRAMED(10000u, LE_AUDIO_SDU_SIZE_OCTETS(_bitrate), \
40 CONFIG_BT_AUDIO_RETRANSMITS, \
41 CONFIG_BT_AUDIO_MAX_TRANSPORT_LATENCY_MS, \
42 CONFIG_BT_AUDIO_PRESENTATION_DELAY_US))
43
54typedef void (*le_audio_receive_cb)(const uint8_t *const data, size_t size, bool bad_frame,
55 uint32_t sdu_ref, enum audio_channel channel_index,
56 size_t desired_size);
57
64 uint8_t const *const data;
65 size_t size;
66 uint8_t num_ch;
67};
68
70 uint8_t lvl1; /* BIG / CIG */
71 uint8_t lvl2; /* Subgroups (only applicable to Broadcast) */
72 uint8_t lvl3; /* BIS / CIS */
73};
74
83int le_audio_ep_state_get(struct bt_bap_ep *ep, uint8_t *state);
84
96bool le_audio_ep_state_check(struct bt_bap_ep *ep, enum bt_bap_ep_state state);
97
107bool le_audio_ep_qos_configured(struct bt_bap_ep const *const ep);
108
117int le_audio_freq_hz_get(const struct bt_audio_codec_cfg *codec, int *freq_hz);
118
127int le_audio_duration_us_get(const struct bt_audio_codec_cfg *codec, int *frame_dur_us);
128
137int le_audio_octets_per_frame_get(const struct bt_audio_codec_cfg *codec, uint32_t *octets_per_sdu);
138
147int le_audio_frame_blocks_per_sdu_get(const struct bt_audio_codec_cfg *codec,
148 uint32_t *frame_blks_per_sdu);
149
159int le_audio_bitrate_get(const struct bt_audio_codec_cfg *const codec, uint32_t *bitrate);
160
171int le_audio_stream_dir_get(struct bt_bap_stream const *const stream);
172
181bool le_audio_bitrate_check(const struct bt_audio_codec_cfg *codec);
182
191bool le_audio_freq_check(const struct bt_audio_codec_cfg *codec);
192
199void le_audio_print_codec(const struct bt_audio_codec_cfg *codec, enum bt_audio_dir dir);
200
201#endif /* _LE_AUDIO_H_ */
audio_channel
Audio channel assignment values.
Definition audio_defines.h:20
Globally accessible audio related defines.
bool le_audio_ep_qos_configured(struct bt_bap_ep const *const ep)
Check if an endpoint has had the QoS configured. If the endpoint is NULL, it is not in the state,...
int le_audio_bitrate_get(const struct bt_audio_codec_cfg *const codec, uint32_t *bitrate)
Get the bitrate for the codec configuration.
int le_audio_duration_us_get(const struct bt_audio_codec_cfg *codec, int *frame_dur_us)
Decode the audio frame duration in us in the codec configuration.
bool le_audio_ep_state_check(struct bt_bap_ep *ep, enum bt_bap_ep_state state)
Check if an endpoint is in the given state. If the endpoint is NULL, it is not in the given state,...
int le_audio_frame_blocks_per_sdu_get(const struct bt_audio_codec_cfg *codec, uint32_t *frame_blks_per_sdu)
Decode the number of frame blocks per SDU in the codec configuration.
int le_audio_freq_hz_get(const struct bt_audio_codec_cfg *codec, int *freq_hz)
Decode the audio sampling frequency in the codec configuration.
bool le_audio_bitrate_check(const struct bt_audio_codec_cfg *codec)
Check that the bitrate is within the supported range.
int le_audio_stream_dir_get(struct bt_bap_stream const *const stream)
Get the direction of the stream provided.
int le_audio_octets_per_frame_get(const struct bt_audio_codec_cfg *codec, uint32_t *octets_per_sdu)
Decode the number of octets per frame in the codec configuration.
bool le_audio_freq_check(const struct bt_audio_codec_cfg *codec)
Check that the sample rate is supported.
void(* le_audio_receive_cb)(const uint8_t *const data, size_t size, bool bad_frame, uint32_t sdu_ref, enum audio_channel channel_index, size_t desired_size)
Callback for receiving Bluetooth LE Audio data.
Definition le_audio.h:54
void le_audio_print_codec(const struct bt_audio_codec_cfg *codec, enum bt_audio_dir dir)
Print the codec configuration.
int le_audio_ep_state_get(struct bt_bap_ep *ep, uint8_t *state)
Get the current state of an endpoint.
uint8_t const *const data
Definition le_audio.h:64
size_t size
Definition le_audio.h:65
uint8_t num_ch
Definition le_audio.h:66
Encoded audio data and information.
Definition le_audio.h:63
uint8_t lvl3
Definition le_audio.h:72
uint8_t lvl2
Definition le_audio.h:71
uint8_t lvl1
Definition le_audio.h:70
Definition le_audio.h:69
enum state_type state