Skip to content

Commit

Permalink
Applications: nrf5340_audio: Add audio struct
Browse files Browse the repository at this point in the history
Add framework for transferring audio.
OCT-2690

Signed-off-by: Kristoffer Rist Skøien <kristoffer.skoien@nordicsemi.no>
  • Loading branch information
koffes authored and rlubos committed Aug 21, 2023
1 parent 05dde21 commit 8e5bc40
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions include/audio_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#ifndef _AUDIO_DEFINES_H_
#define _AUDIO_DEFINES_H_

#include <zephyr/types.h>
#include <stdbool.h>

/**
* @brief Audio channel assignment values
*/
Expand All @@ -20,4 +23,81 @@ enum audio_channel {
AUDIO_CH_NUM,
};

/**
* @brief Audio data coding.
*/
enum coding {
/* Raw PCM audio data */
PCM = 1,

/* LC3-coded audio data */
LC3
};

struct audio_metadata {
/* Indicates the data type/encoding. */
enum coding data_coding;

/* Playback length in microseconds. */
uint32_t data_len_us;

/* The audio sample rate.
* This may typically be 16000, 24000, 44100 or 48000 Hz.
*/
uint32_t sample_rate_hz;

/* Number of valid bits for a sample (bit depth). Typically 16 or 24. */
uint8_t bits_per_sample;

/* Number of bits used to carry a sample of size bits_per_sample.
* For example, say we have a 24 bit sample stored in a 32 bit
* word (int32_t), then:
* bits_per_sample = 24
* carrier_size = 32
*/
uint8_t carried_bits_pr_sample;

/* A 32 bit mask indicating which channel(s)/locations are active within
* the data. A bit set indicates the location is active and
* a count of these will give the number of locations within the
* audio stream.
* Note: This will follow the ANSI/CTA-861-G’s Table 34 codes
* for speaker placement (as used by Bluetooth Low Energy Audio).
*/
uint32_t locations;

/* Reference time stamp (e.g. ISO timestamp reference from BLE controller). */
uint32_t reference_ts_us;

/* The timestamp for when the data was received. */
uint32_t data_rx_ts_us;

/* A Boolean flag to indicate this data has errors
* (true = bad, false = good).
* Note: Timestamps are still valid even though this flag is set.
*/
bool bad_data;
};

/**
* @brief A unit of audio.
*
* This unit can be used anywhere, so it may be an audio block, a frame or something else.
* It may contain encoded or raw data, as well as a single or multiple channels.
*/
struct audio_data {
/* A pointer to the raw or coded data (e.g., PCM, LC3, etc.) buffer. */
void *data;

/* The size in bytes of the data buffer.
* To get the size of each channel, this value must be divided by the number of
* used channels. Metadata is not included in this figure.
*/
size_t data_size;

/* Additional information describing the audio data.
*/
struct audio_metadata meta;
};

#endif /* _AUDIO_DEFINES_H_ */

0 comments on commit 8e5bc40

Please sign in to comment.