nRF Connect SDK API 3.3.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
16#ifndef _LE_AUDIO_H_
17#define _LE_AUDIO_H_
18
19#include <zephyr/bluetooth/audio/bap.h>
20#include <zephyr/bluetooth/audio/cap.h>
21#include <zephyr/net_buf.h>
22#include <audio_defines.h>
23
24#define LE_AUDIO_ZBUS_EVENT_WAIT_TIME K_MSEC(5)
25#define LE_AUDIO_SDU_SIZE_OCTETS(bitrate, dur_us) (bitrate / (USEC_PER_SEC / dur_us) / 8)
26
27#if CONFIG_SAMPLE_RATE_CONVERTER && CONFIG_AUDIO_SAMPLE_RATE_48000_HZ
28#define BT_AUDIO_CODEC_CAPABILIY_FREQ \
29 BT_AUDIO_CODEC_CAP_FREQ_48KHZ | BT_AUDIO_CODEC_CAP_FREQ_24KHZ | \
30 BT_AUDIO_CODEC_CAP_FREQ_16KHZ
31
32#elif CONFIG_AUDIO_SAMPLE_RATE_16000_HZ
33#define BT_AUDIO_CODEC_CAPABILIY_FREQ BT_AUDIO_CODEC_CAP_FREQ_16KHZ
34
35#elif CONFIG_AUDIO_SAMPLE_RATE_24000_HZ
36#define BT_AUDIO_CODEC_CAPABILIY_FREQ BT_AUDIO_CODEC_CAP_FREQ_24KHZ
37
38#elif CONFIG_AUDIO_SAMPLE_RATE_48000_HZ
39#define BT_AUDIO_CODEC_CAPABILIY_FREQ BT_AUDIO_CODEC_CAP_FREQ_48KHZ
40
41#else
42#error No sample rate supported
43#endif /* CONFIG_SAMPLE_RATE_CONVERTER */
44
48#define BT_BAP_LC3_PRESET_CONFIGURABLE(_loc, _stream_context, _bitrate) \
49 BT_BAP_LC3_PRESET(BT_AUDIO_CODEC_LC3_CONFIG(CONFIG_BT_AUDIO_PREF_SINK_SAMPLE_RATE_VALUE, \
50 BT_AUDIO_CODEC_CFG_DURATION_10, _loc, \
51 LE_AUDIO_SDU_SIZE_OCTETS(_bitrate, 10000), 1, \
52 _stream_context), \
53 BT_BAP_QOS_CFG_UNFRAMED(10000u, \
54 LE_AUDIO_SDU_SIZE_OCTETS(_bitrate, 10000), \
55 CONFIG_BT_AUDIO_RETRANSMITS, \
56 CONFIG_BT_AUDIO_MAX_TRANSPORT_LATENCY_MS, \
57 CONFIG_BT_AUDIO_PRESENTATION_DELAY_US))
58
66typedef void (*le_audio_receive_cb)(struct net_buf *audio_frame, struct audio_metadata *meta,
67 uint8_t location_index);
68
77 uint8_t lvl1;
79 uint8_t lvl2;
81 uint8_t lvl3;
82};
83
96int le_audio_concurrent_sync_num_get(uint8_t *num_streams, enum bt_audio_location *locations);
97
108int le_audio_metadata_populate(struct audio_metadata *meta, const struct bt_bap_stream *stream,
109 const struct bt_iso_recv_info *info,
110 const struct net_buf *audio_frame);
111
120int le_audio_ep_state_get(struct bt_bap_ep const *const ep, uint8_t *state);
121
133bool le_audio_ep_state_check(struct bt_bap_ep const *const ep, enum bt_bap_ep_state state);
134
144bool le_audio_ep_qos_configured(struct bt_bap_ep const *const ep);
145
154int le_audio_freq_hz_get(const struct bt_audio_codec_cfg *codec, int *freq_hz);
155
164int le_audio_duration_us_get(const struct bt_audio_codec_cfg *codec, int *frame_dur_us);
165
174int le_audio_octets_per_frame_get(const struct bt_audio_codec_cfg *codec, uint32_t *octets_per_sdu);
175
184int le_audio_frame_blocks_per_sdu_get(const struct bt_audio_codec_cfg *codec,
185 uint32_t *frame_blks_per_sdu);
186
196int le_audio_bitrate_get(const struct bt_audio_codec_cfg *const codec, uint32_t *bitrate);
197
208int le_audio_stream_dir_get(struct bt_bap_stream const *const stream);
209
218bool le_audio_bitrate_check(const struct bt_audio_codec_cfg *codec);
219
228bool le_audio_freq_check(const struct bt_audio_codec_cfg *codec);
229
236void le_audio_print_codec(const struct bt_audio_codec_cfg *codec, enum bt_audio_dir dir);
237
245int le_audio_print_qos_from_stream(struct bt_bap_stream const *const stream);
246
254int le_audio_print_unicast_group(struct bt_cap_unicast_group const *const unicast_group);
255
260#endif /* _LE_AUDIO_H_ */
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_print_unicast_group(struct bt_cap_unicast_group const *const unicast_group)
Print the unicast group information.
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.
void(* le_audio_receive_cb)(struct net_buf *audio_frame, struct audio_metadata *meta, uint8_t location_index)
Callback for receiving Bluetooth LE Audio data.
Definition le_audio.h:66
int le_audio_metadata_populate(struct audio_metadata *meta, const struct bt_bap_stream *stream, const struct bt_iso_recv_info *info, const struct net_buf *audio_frame)
Function to populate the audio metadata.
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_concurrent_sync_num_get(uint8_t *num_streams, enum bt_audio_location *locations)
Get the number of active streams.
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_ep_state_check(struct bt_bap_ep const *const 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,...
bool le_audio_freq_check(const struct bt_audio_codec_cfg *codec)
Check that the sample rate is supported.
void le_audio_print_codec(const struct bt_audio_codec_cfg *codec, enum bt_audio_dir dir)
Print the codec configuration.
int le_audio_print_qos_from_stream(struct bt_bap_stream const *const stream)
Print the QoS configuration for a stream.
int le_audio_ep_state_get(struct bt_bap_ep const *const ep, uint8_t *state)
Get the current state of an endpoint.
Definition audio_defines.h:42
uint8_t lvl3
Definition le_audio.h:81
uint8_t lvl2
Definition le_audio.h:79
uint8_t lvl1
Definition le_audio.h:77
Stream index structure for identifying audio streams.
Definition le_audio.h:75