nRF Connect SDK API 3.3.99
Loading...
Searching...
No Matches
audio_defines.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
13#ifndef _AUDIO_DEFINES_H_
14#define _AUDIO_DEFINES_H_
15
16#include <zephyr/toolchain.h>
17#include <zephyr/types.h>
18#include <stddef.h>
19#include <stdbool.h>
20#include <stdint.h>
21
30
34enum coding {
35 /* Raw PCM audio data */
36 PCM = 1,
37
38 /* LC3-coded audio data */
39 LC3
40};
41
43 /* Indicates the data type/encoding. */
45
46 /* Playback length in microseconds. */
47 uint32_t data_len_us;
48
49 /* The audio sample rate.
50 * This may typically be 16000, 24000, 44100 or 48000 Hz.
51 */
53
54 /* Number of valid bits for a sample (bit depth). Typically 16 or 24. */
56
57 /* Number of bytes per active location in the bitstream */
59
60 /* Number of bits used to carry a sample of size bits_per_sample.
61 * For example, say we have a 24 bit sample stored in a 32 bit
62 * word (int32_t), then:
63 * bits_per_sample = 24
64 * carrier_size = 32
65 */
67
68 /* The bit-rate for the data stream.
69 * For example, say we have a 16 bit sample stored in a 32 bit
70 * word (int_32), 100 samples in each of 2 locations and a sample rate of 48000 Hz then:
71 * bitrate_bps = 32 * 48000 * 2
72 * = 3.072 Mbps
73 *
74 * For encoded data the bit-rate will be determined by the encoding process.
75 */
76 uint32_t bitrate_bps;
77
78 /* A flag to specify if the data is interleaved or de-interleaved
79 * (true = interleaved, false = de-interleaved).
80 *
81 * @note This flag is only valid for data types that support interleaving (e.g. PCM
82 * channel interleaving, where interleaved is LRLRLRLRL..... and de-interleaved is
83 * LLLLLRRRRRLL...
84 */
86
87 /* A 32 bit mask indicating which channel(s)/locations are active within
88 * the data. A bit set indicates the location is active and
89 * a count of these will give the number of locations within the
90 * audio stream.
91 * Note: This will follow the ANSI/CTA-861-G’s Table 34 codes
92 * for speaker placement (as used by Bluetooth Low Energy Audio).
93 *
94 * @note For Bluetooth Low Energy Audio a value of 0 indicates mono.
95 */
96 uint32_t locations;
97
98 /* Reference time stamp (e.g. ISO timestamp reference from BLE controller). */
99 uint32_t ref_ts_us;
100
101 /* The timestamp for when the data was received. */
103
104 /* A bit field to indicate if any channel has errors (1 = bad, 0 = good).
105 *
106 * Note: Timestamps are still valid when this is set.
107 */
108 uint32_t bad_data;
109};
110
121static inline uint8_t audio_metadata_num_loc_get(struct audio_metadata const *const meta)
122{
123 if (meta == NULL) {
124 return 0;
125 }
126
127 if (meta->locations == 0) {
128 return 1;
129 }
130
131 return POPCOUNT(meta->locations);
132}
133
134#endif /* _AUDIO_DEFINES_H_ */
static uint8_t audio_metadata_num_loc_get(struct audio_metadata const *const meta)
Get the number of locations in the meta data.
Definition audio_defines.h:121
audio_channel
Audio channel assignment values.
Definition audio_defines.h:25
@ AUDIO_CH_L
Definition audio_defines.h:26
@ AUDIO_CH_R
Definition audio_defines.h:27
@ AUDIO_CH_NUM
Definition audio_defines.h:28
coding
Audio data coding.
Definition audio_defines.h:34
@ PCM
Definition audio_defines.h:36
@ LC3
Definition audio_defines.h:39
uint32_t bitrate_bps
Definition audio_defines.h:76
uint32_t ref_ts_us
Definition audio_defines.h:99
uint8_t carried_bits_per_sample
Definition audio_defines.h:66
uint32_t data_rx_ts_us
Definition audio_defines.h:102
uint32_t bad_data
Definition audio_defines.h:108
uint32_t data_len_us
Definition audio_defines.h:47
enum coding data_coding
Definition audio_defines.h:44
bool interleaved
Definition audio_defines.h:85
uint8_t bits_per_sample
Definition audio_defines.h:55
uint32_t bytes_per_location
Definition audio_defines.h:58
uint32_t sample_rate_hz
Definition audio_defines.h:52
uint32_t locations
Definition audio_defines.h:96
Definition audio_defines.h:42