Sound Open Firmware
Loading...
Searching...
No Matches
Audio Processing Components & Module Interface

Unified interface contracts, lifecycle callbacks, and streaming endpoints for built-in audio components and dynamic LLEXT processing modules (Volume, Mixer, EQ, DRC, SRC, etc.). More...

Files

file  audio_stream.h
 Circular audio buffer calculation and wrap utilities for processing modules.
 
file  format.h
 Audio sample format conversion and size calculation helpers for modules.
 
file  sink_api.h
 Sink audio endpoint API for module output buffers.
 
file  source_api.h
 Source audio endpoint API for module input buffers.
 
file  base.h
 Base definitions and structures for loadable audio modules.
 
file  interface.h
 Dynamic module interface, lifecycle callbacks, and buffer contracts.
 
file  llext.h
 LLEXT manifest macros and declarations for loadable ELF extensions.
 
file  system_service.h
 System services provided by the base firmware to loadable modules.
 
file  sink_api.h
 Audio sink API helpers and stream configuration.
 
file  source_api.h
 Audio source API helpers and stream configuration.
 

Data Structures

struct  sof_audio_stream_params
 set of parameters describing audio stream this structure is shared between audio_stream.h and sink/source interface TODO: compressed formats More...
 
struct  cir_buf_source
 Read-only view of source data in a circular buffer. More...
 
struct  cir_buf_sink
 Writable view of sink data in a circular buffer. More...
 
struct  sof_uuid
 UUID (Universally Unique IDentifier) structure. More...
 
struct  sof_uuid_entry
 Connects UUID with component description. More...
 

Macros

#define UUID_SIZE   16
 UUID is 16 bytes long.
 
#define UUID_NAME_MAX_LEN   32
 UUID name string max length in bytes, including null termination.
 
#define _UUID_INIT(va, vb, vc, d0, d1, d2, d3, d4, d5, d6, d7)    { va, vb, vc, { d0, d1, d2, d3, d4, d5, d6, d7 } }
 
#define _UUID(uuid_name)   (&_##uuid_name)
 
#define _RT_UUID(uuid_name)   (&uuid_name)
 
#define _DEF_UUID(entity_name, uuid_name, initializer)
 
#define SOF_DEFINE_UUID(entity_name, uuid_name, va, vb, vc, vd0, vd1, vd2, vd3, vd4, vd5, vd6, vd7)
 Declares runtime UUID (aaaaaaaa-bbbb-cccc-d0d1-d2d3d4d5d6d7) and name.
 
#define SOF_REG_UUID(name)   _UUIDREG_##name
 Get UUID value sourced from the fixed SOF registry.
 
#define SOF_DEFINE_REG_UUID(name)   _DEF_UUID(#name, name##_uuid, SOF_REG_UUID(name))
 Defines UUID sourced from the fixed SOF registry.
 
#define SOF_UUID(uuid_name)   _UUID(uuid_name)
 Creates local unique 32-bit representation of UUID structure.
 
#define SOF_RT_UUID(uuid_name)   _RT_UUID(uuid_name)
 Dereference unique 32-bit representation of UUID structure in runtime.
 

Enumerations

enum  sof_audio_buffer_state { AUDIOBUF_STATE_INITIAL , AUDIOBUF_STATE_READY , AUDIOBUF_STATE_END_OF_STREAM , AUDIOBUF_STATE_END_OF_STREAM_FLUSH }
 Define states of an audio stream buffer connecting two components. More...
 

Functions

static size_t circ_buf_frames_without_wrap (const void *began, const void *end, size_t sample_bytes, size_t channels)
 Number of whole frames available before a circular buffer wraps.
 
static size_t cir_buf_samples_to_wrap_s16 (const int16_t *ptr, const int16_t *buf_start, size_t buf_samples)
 Calculates numbers of s16 samples to buffer wrap.
 
static size_t cir_buf_samples_to_wrap_s32 (const int32_t *ptr, const int32_t *buf_start, size_t buf_samples)
 Calculates numbers of s32 samples to buffer wrap.
 
static size_t cir_buf_samples_without_wrap_s16 (const void *ptr, const void *buf_end)
 Calculates numbers of s16 samples to buffer wrap when reading a circular buffer forward from current pointer towards the buffer end.
 
static size_t cir_buf_samples_without_wrap_s32 (const void *ptr, const void *buf_end)
 Calculates numbers of s32 samples to buffer wrap when reading a circular buffer forward from current pointer towards the buffer end.
 
static size_t cir_buf_bytes_without_wrap (const void *ptr, const void *buf_end)
 Calculates number of bytes to buffer wrap when reading a circular buffer forward from current pointer towards the buffer end.
 
static void * cir_buf_wrap (const void *ptr, const void *buf_addr, const void *buf_end)
 Verifies the pointer and performs rollover when reaching the end of the circular buffer.
 
static const void * source_cir_buf_wrap (const void *ptr, const void *buf_addr, const void *buf_end)
 Verifies a read pointer and performs rollover when reaching the end of the circular buffer.
 
static size_t cir_buf_bytes_without_wrap_rewind (const void *ptr, const void *buf_start)
 Calculates number of bytes to buffer wrap when reading a circular buffer backwards from current pointer towards the buffer start.
 
static const void * source_cir_buf_rewind_wrap (const void *ptr, const void *buf_start, const void *buf_end)
 Verifies the pointer and performs rollover when reading a read-only circular buffer backwards past its start address.
 
void sink_init (struct sof_sink *sink, const struct sink_ops *ops, struct sof_audio_stream_params *audio_stream_params)
 Initialize sink API structure before any operation.
 
size_t sink_get_num_of_processed_bytes (struct sof_sink *sink)
 Get total number of bytes processed by the sink (committed by sink_commit_buffer()).
 
void sink_reset_num_of_processed_bytes (struct sof_sink *sink)
 Reset counter of total processed bytes to zero.
 
bool sink_get_overrun (struct sof_sink *sink)
 Check if buffer overrun is permitted on sink stream.
 
void sink_set_min_free_space (struct sof_sink *sink, size_t min_free_space)
 Set minimum free space required in sink buffer.
 
void source_init (struct sof_source *source, const struct source_ops *ops, struct sof_audio_stream_params *audio_stream_params)
 Initialize source API structure before any operation.
 
size_t source_get_num_of_processed_bytes (struct sof_source *source)
 Get total number of bytes processed by the source (freed by source_release_data()).
 
void source_reset_num_of_processed_bytes (struct sof_source *source)
 Reset counter of total processed bytes to zero.
 
bool source_get_underrun (struct sof_source *source)
 Check if buffer underrun is permitted on source stream.
 
uint32_t source_get_id (struct sof_source *source)
 Get unique stream identifier for source.
 
int source_set_frm_fmt (struct sof_source *source, enum sof_ipc_frame frm_fmt)
 Set audio frame format for source.
 
int source_set_valid_fmt (struct sof_source *source, enum sof_ipc_frame valid_sample_fmt)
 Set valid sample format for source.
 
int source_set_rate (struct sof_source *source, unsigned int rate)
 Set sample rate for source.
 
int source_set_channels (struct sof_source *source, unsigned int channels)
 Set channel count for source.
 
int source_set_underrun (struct sof_source *source, bool underrun_permitted)
 Configure whether underrun is permitted on source.
 
int source_set_buffer_fmt (struct sof_source *source, uint32_t buffer_fmt)
 Set buffer format for source.
 
void source_set_min_available (struct sof_source *source, size_t min_available)
 Set minimum available data requirement in bytes.
 
int source_set_params (struct sof_source *source, struct sof_ipc_stream_params *params, bool force_update)
 Configure initial set of audio parameters.
 
int source_set_alignment_constants (struct sof_source *source, const uint32_t byte_align, const uint32_t frame_align_req)
 Set byte and frame alignment constants for source stream.
 

Detailed Description

Unified interface contracts, lifecycle callbacks, and streaming endpoints for built-in audio components and dynamic LLEXT processing modules (Volume, Mixer, EQ, DRC, SRC, etc.).

UUID API specification.

Macro Definition Documentation

◆ _DEF_UUID

#define _DEF_UUID (   entity_name,
  uuid_name,
  initializer 
)
Value:
const STRUCT_SECTION_ITERABLE(sof_uuid_entry, _##uuid_name) = \
{ .id = initializer, .name = entity_name }; \
extern const struct sof_uuid \
__attribute__((alias("_" #uuid_name))) uuid_name
Connects UUID with component description.
Definition uuid.h:77
UUID (Universally Unique IDentifier) structure.
Definition uuid.h:60

◆ _RT_UUID

#define _RT_UUID (   uuid_name)    (&uuid_name)

◆ _UUID

#define _UUID (   uuid_name)    (&_##uuid_name)

◆ _UUID_INIT

#define _UUID_INIT (   va,
  vb,
  vc,
  d0,
  d1,
  d2,
  d3,
  d4,
  d5,
  d6,
  d7 
)     { va, vb, vc, { d0, d1, d2, d3, d4, d5, d6, d7 } }

◆ SOF_DEFINE_REG_UUID

#define SOF_DEFINE_REG_UUID (   name)    _DEF_UUID(#name, name##_uuid, SOF_REG_UUID(name))

Defines UUID sourced from the fixed SOF registry.

As for SOF_DEFINE_UUID(), but the ID value is sourced by name from the uuid-registry.txt file distributed with the source tree. The string name field will be identical with the name passed (which is passed as a symbol!), runtime symbol (e.g. the "uuid_name" argument to SOF_DEFINE_UUID()) will be the same, postfixed with a "_uuid".

Parameters
nameName of the UUID, must match an entry in uuid-registry.txt

◆ SOF_DEFINE_UUID

#define SOF_DEFINE_UUID (   entity_name,
  uuid_name,
  va,
  vb,
  vc,
  vd0,
  vd1,
  vd2,
  vd3,
  vd4,
  vd5,
  vd6,
  vd7 
)
Value:
_DEF_UUID(entity_name, uuid_name, \
_UUID_INIT(va, vb, vc, vd0, vd1, vd2, vd3, vd4, vd5, vd6, vd7))
#define _UUID_INIT(va, vb, vc, d0, d1, d2, d3, d4, d5, d6, d7)
Definition uuid.h:67
#define _DEF_UUID(entity_name, uuid_name, initializer)
Definition uuid.h:90

Declares runtime UUID (aaaaaaaa-bbbb-cccc-d0d1-d2d3d4d5d6d7) and name.

UUID value from variables declared with this macro are accessible in runtime code - to dereference use SOF_RT_UUID()

Parameters
entity_nameName of the object pinted by the software tools.
uuid_nameUuid symbol name used with SOF_UUID() and SOF_RT_UUID().
vaaaaaaaaa value.
vbbbbb value.
vccccc value.
vd0d0 value (note how d0 and d1 are grouped in formatted uuid)
vd1d1 value.
vd2d2 value.
vd3d3 value.
vd4d4 value.
vd5d5 value.
vd6d6 value.
vd7d7 value.

◆ SOF_REG_UUID

#define SOF_REG_UUID (   name)    _UUIDREG_##name

Get UUID value sourced from the fixed SOF registry.

The ID value is sourced by name from the uuid-registry.txt file distributed with the source tree.

Parameters
nameName of the UUID, must match an entry in uuid-registry.txt

◆ SOF_RT_UUID

#define SOF_RT_UUID (   uuid_name)    _RT_UUID(uuid_name)

Dereference unique 32-bit representation of UUID structure in runtime.

Parameters
uuid_nameUUID symbol name declared with DECLARE_SOF_RT_UUID().

◆ SOF_UUID

#define SOF_UUID (   uuid_name)    _UUID(uuid_name)

Creates local unique 32-bit representation of UUID structure.

In Zephyr builds, this has the same address as the result of SOF_RT_UUID, but has type of "struct sof_uuid *" and not "struct sof_uid_record *"

Parameters
uuid_nameUUID symbol name declared with DECLARE_SOF_UUID() or DECLARE_SOF_RT_UUID().

◆ UUID_NAME_MAX_LEN

#define UUID_NAME_MAX_LEN   32

UUID name string max length in bytes, including null termination.

◆ UUID_SIZE

#define UUID_SIZE   16

UUID is 16 bytes long.

Enumeration Type Documentation

◆ sof_audio_buffer_state

Define states of an audio stream buffer connecting two components.

This enum represents the lifecycle of an audio stream, including its initialization, readiness, and end-of-stream handling. It is used to track and manage the state transitions of the stream during audio processing.

Enumerator
AUDIOBUF_STATE_INITIAL 
AUDIOBUF_STATE_READY 
AUDIOBUF_STATE_END_OF_STREAM 
AUDIOBUF_STATE_END_OF_STREAM_FLUSH 

Function Documentation

◆ cir_buf_bytes_without_wrap()

static size_t cir_buf_bytes_without_wrap ( const void *  ptr,
const void *  buf_end 
)
inlinestatic

Calculates number of bytes to buffer wrap when reading a circular buffer forward from current pointer towards the buffer end.

Parameters
ptrRead or write pointer of circular buffer.
buf_endEnd address of circular buffer.
Returns
Number of bytes between the pointer and the buffer end.

◆ cir_buf_bytes_without_wrap_rewind()

static size_t cir_buf_bytes_without_wrap_rewind ( const void *  ptr,
const void *  buf_start 
)
inlinestatic

Calculates number of bytes to buffer wrap when reading a circular buffer backwards from current pointer towards the buffer start.

Parameters
ptrRead or write pointer of circular buffer.
buf_startStart address of circular buffer.
Returns
Number of bytes between the buffer start and the pointer.

◆ cir_buf_samples_to_wrap_s16()

static size_t cir_buf_samples_to_wrap_s16 ( const int16_t *  ptr,
const int16_t *  buf_start,
size_t  buf_samples 
)
inlinestatic

Calculates numbers of s16 samples to buffer wrap.

Parameters
ptrRead or write pointer of circular buffer.
buf_startStart address of circular buffer.
buf_samplesTotal size of circular buffer in samples.
Returns
Number of samples to buffer wrap.

◆ cir_buf_samples_to_wrap_s32()

static size_t cir_buf_samples_to_wrap_s32 ( const int32_t *  ptr,
const int32_t *  buf_start,
size_t  buf_samples 
)
inlinestatic

Calculates numbers of s32 samples to buffer wrap.

Parameters
ptrRead or write pointer of circular buffer.
buf_startStart address of circular buffer.
buf_samplesTotal size of circular buffer in samples.
Returns
Number of samples to buffer wrap.

◆ cir_buf_samples_without_wrap_s16()

static size_t cir_buf_samples_without_wrap_s16 ( const void *  ptr,
const void *  buf_end 
)
inlinestatic

Calculates numbers of s16 samples to buffer wrap when reading a circular buffer forward from current pointer towards the buffer end.

Parameters
ptrRead or write pointer of circular buffer.
buf_endEnd address of circular buffer.
Returns
Number of s16 samples between the pointer and the buffer end.

◆ cir_buf_samples_without_wrap_s32()

static size_t cir_buf_samples_without_wrap_s32 ( const void *  ptr,
const void *  buf_end 
)
inlinestatic

Calculates numbers of s32 samples to buffer wrap when reading a circular buffer forward from current pointer towards the buffer end.

Parameters
ptrRead or write pointer of circular buffer.
buf_endEnd address of circular buffer.
Returns
Number of s32 samples between the pointer and the buffer end.

◆ cir_buf_wrap()

static void * cir_buf_wrap ( const void *  ptr,
const void *  buf_addr,
const void *  buf_end 
)
inlinestatic

Verifies the pointer and performs rollover when reaching the end of the circular buffer.

Parameters
ptrRead pointer that may have moved past the buffer end.
buf_addrStart address of the circular buffer.
buf_endEnd address of the circular buffer.
Returns
Pointer, adjusted if necessary.

◆ circ_buf_frames_without_wrap()

static size_t circ_buf_frames_without_wrap ( const void *  began,
const void *  end,
size_t  sample_bytes,
size_t  channels 
)
inlinestatic

Number of whole frames available before a circular buffer wraps.

Computes (end - began) / channels expressed in frames. The pointer distance is evaluated in bytes so the helper works for any sample width.

Parameters
begancurrent position in the circular buffer
endone past the last sample of the circular buffer
sample_bytessize of a single sample in bytes (2 for s16, 4 for s32)
channelsnumber of channels, i.e. samples per frame
Returns
number of frames that can be processed without wrapping

◆ sink_get_num_of_processed_bytes()

size_t sink_get_num_of_processed_bytes ( struct sof_sink *  sink)

Get total number of bytes processed by the sink (committed by sink_commit_buffer()).

Parameters
[in]sinkPointer to sink structure.
Returns
Total number of processed bytes.

◆ sink_get_overrun()

bool sink_get_overrun ( struct sof_sink *  sink)

Check if buffer overrun is permitted on sink stream.

Parameters
[in]sinkPointer to sink structure.
Returns
True if overrun is permitted by audio stream params, false otherwise.

◆ sink_init()

void sink_init ( struct sof_sink *  sink,
const struct sink_ops *  ops,
struct sof_audio_stream_params *  audio_stream_params 
)

Initialize sink API structure before any operation.

NOTE: audio_stream_params must be accessible by the caller core, and the implementation must ensure coherent access to the parameters (e.g. for a cross-core shared queue, it must be located in non-cached memory).

Parameters
[in,out]sinkPointer to sink structure.
[in]opsPointer to API operations vtable.
[in]audio_stream_paramsPointer to structure with audio parameters.

◆ sink_reset_num_of_processed_bytes()

void sink_reset_num_of_processed_bytes ( struct sof_sink *  sink)

Reset counter of total processed bytes to zero.

Parameters
[in,out]sinkPointer to sink structure.

◆ sink_set_min_free_space()

void sink_set_min_free_space ( struct sof_sink *  sink,
size_t  min_free_space 
)

Set minimum free space required in sink buffer.

Parameters
[in,out]sinkPointer to sink structure.
[in]min_free_spaceMinimum free space in bytes.

◆ source_cir_buf_rewind_wrap()

static const void * source_cir_buf_rewind_wrap ( const void *  ptr,
const void *  buf_start,
const void *  buf_end 
)
inlinestatic

Verifies the pointer and performs rollover when reading a read-only circular buffer backwards past its start address.

Parameters
ptrPointer that may have moved below the buffer start.
buf_startStart address of the circular buffer.
buf_endEnd address of the circular buffer.
Returns
Pointer, wrapped to the end of the buffer if necessary.

◆ source_cir_buf_wrap()

static const void * source_cir_buf_wrap ( const void *  ptr,
const void *  buf_addr,
const void *  buf_end 
)
inlinestatic

Verifies a read pointer and performs rollover when reaching the end of the circular buffer.

Parameters
ptrRead pointer that may have moved past the buffer end.
buf_addrStart address of the circular buffer.
buf_endEnd address of the circular buffer.
Returns
Pointer, adjusted if necessary.

◆ source_get_id()

uint32_t source_get_id ( struct sof_source *  source)

Get unique stream identifier for source.

Parameters
[in]sourcePointer to source structure.
Returns
Stream identifier.

◆ source_get_num_of_processed_bytes()

size_t source_get_num_of_processed_bytes ( struct sof_source *  source)

Get total number of bytes processed by the source (freed by source_release_data()).

Parameters
[in]sourcePointer to source structure.
Returns
Total number of processed bytes.

◆ source_get_underrun()

bool source_get_underrun ( struct sof_source *  source)

Check if buffer underrun is permitted on source stream.

Parameters
[in]sourcePointer to source structure.
Returns
True if underrun is permitted by audio stream params, false otherwise.

◆ source_init()

void source_init ( struct sof_source *  source,
const struct source_ops *  ops,
struct sof_audio_stream_params *  audio_stream_params 
)

Initialize source API structure before any operation.

NOTE: audio_stream_params must be accessible by the caller core, and the implementation must ensure coherent access to the parameters (e.g. for a cross-core shared queue, it must be located in non-cached memory).

Parameters
[in,out]sourcePointer to source structure.
[in]opsPointer to API operations vtable.
[in]audio_stream_paramsPointer to structure with audio parameters.

◆ source_reset_num_of_processed_bytes()

void source_reset_num_of_processed_bytes ( struct sof_source *  source)

Reset counter of total processed bytes to zero.

Parameters
[in,out]sourcePointer to source structure.

◆ source_set_alignment_constants()

int source_set_alignment_constants ( struct sof_source *  source,
const uint32_t  byte_align,
const uint32_t  frame_align_req 
)

Set byte and frame alignment constants for source stream.

Sets frame_align_shift and frame_align of stream according to byte_align and frame_align_req requirements. Once the channel number and frame size are determined, the frame_align and frame_align_shift are determined too. These features are used by audio_stream_get_avail_frames_aligned() to calculate available frames.

Note
This must be called in component prepare or param functions only once after channel count and frame size are known and before stream copying begins. If omitted or called late, aligned availability can evaluate to zero and no data will be copied.
Parameters
[in,out]sourcePointer to source structure.
[in]byte_alignProcessing byte alignment requirement.
[in]frame_align_reqProcessing frames alignment requirement.
Returns
0 on success, negative error code on failure.

◆ source_set_buffer_fmt()

int source_set_buffer_fmt ( struct sof_source *  source,
uint32_t  buffer_fmt 
)

Set buffer format for source.

Parameters
[in,out]sourcePointer to source structure.
[in]buffer_fmtBuffer format identifier.
Returns
0 on success, negative error code on failure.

◆ source_set_channels()

int source_set_channels ( struct sof_source *  source,
unsigned int  channels 
)

Set channel count for source.

Parameters
[in,out]sourcePointer to source structure.
[in]channelsNumber of audio channels.
Returns
0 on success, negative error code on failure.

◆ source_set_frm_fmt()

int source_set_frm_fmt ( struct sof_source *  source,
enum sof_ipc_frame  frm_fmt 
)

Set audio frame format for source.

Parameters
[in,out]sourcePointer to source structure.
[in]frm_fmtAudio frame format.
Returns
0 on success, negative error code on failure.

◆ source_set_min_available()

void source_set_min_available ( struct sof_source *  source,
size_t  min_available 
)

Set minimum available data requirement in bytes.

Parameters
[in,out]sourcePointer to source structure.
[in]min_availableMinimum available bytes.

◆ source_set_params()

int source_set_params ( struct sof_source *  source,
struct sof_ipc_stream_params *  params,
bool  force_update 
)

Configure initial set of audio parameters.

Parameters
[in,out]sourcePointer to source structure.
[in]paramsAudio stream parameters.
[in]force_updateTrue to force parameters override.
Returns
0 on success, negative error code on failure.

◆ source_set_rate()

int source_set_rate ( struct sof_source *  source,
unsigned int  rate 
)

Set sample rate for source.

Parameters
[in,out]sourcePointer to source structure.
[in]rateSample rate in Hz.
Returns
0 on success, negative error code on failure.

◆ source_set_underrun()

int source_set_underrun ( struct sof_source *  source,
bool  underrun_permitted 
)

Configure whether underrun is permitted on source.

Parameters
[in,out]sourcePointer to source structure.
[in]underrun_permittedTrue if underrun is permitted, false otherwise.
Returns
0 on success, negative error code on failure.

◆ source_set_valid_fmt()

int source_set_valid_fmt ( struct sof_source *  source,
enum sof_ipc_frame  valid_sample_fmt 
)

Set valid sample format for source.

Parameters
[in,out]sourcePointer to source structure.
[in]valid_sample_fmtValid sample format.
Returns
0 on success, negative error code on failure.