oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
audio_node.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-3.0-or-later */
2
20#ifndef OVE_AUDIO_NODE_H
21#define OVE_AUDIO_NODE_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#include <stdint.h>
28
29#include "ove/storage.h"
30
32#define OVE_AUDIO_MAX_CHANNELS 8
33
34/* ── Sample format ──────────────────────────────────────────────── */
35
46
53static inline unsigned int ove_audio_sample_size(enum ove_audio_sample_fmt fmt)
54{
55 switch (fmt) {
57 return sizeof(int16_t);
59 return sizeof(int32_t);
61 return sizeof(float);
62 default:
63 return 0;
64 }
65}
66
67/* ── Audio format descriptor ────────────────────────────────────── */
68
76 unsigned int sample_rate;
77 unsigned int channels;
79};
80
88static inline int ove_audio_fmt_equal(const struct ove_audio_fmt *a, const struct ove_audio_fmt *b)
89{
90 return a->sample_rate == b->sample_rate && a->channels == b->channels &&
91 a->sample_fmt == b->sample_fmt;
92}
93
94/* ── Audio buffer ───────────────────────────────────────────────── */
95
103 void *data;
104 unsigned int frames;
105 const struct ove_audio_fmt *fmt;
106};
107
108/* ── Node vtable ────────────────────────────────────────────────── */
109
134 int (*configure)(void *ctx, const struct ove_audio_fmt *in_fmt,
135 struct ove_audio_fmt *out_fmt);
136
143 int (*start)(void *ctx);
144
151 int (*stop)(void *ctx);
152
166 int (*process)(void *ctx, const struct ove_audio_buf *in, struct ove_audio_buf *out);
167
175 void (*destroy)(void *ctx);
176};
177
178/* ── Node types ─────────────────────────────────────────────────── */
179
188
196 const char *name;
198 const struct ove_audio_node_ops *ops;
199 void *ctx;
201};
202
203/* ── Built-in node factories ────────────────────────────────────── */
204
205struct ove_audio_graph; /* forward declaration */
206
219
226typedef void (*ove_audio_tap_fn)(const struct ove_audio_buf *buf, void *user_data);
227
228/* The built-in factory functions below internally allocate a per-node
229 * context with OVE_BACKEND_MALLOC. Under CONFIG_OVE_ZERO_HEAP the gate
230 * OVE_HEAP_AUDIO hides them: link fails rather than silently trapping,
231 * nudging the application toward its own static-context processor nodes. */
232#ifdef OVE_HEAP_AUDIO
233
248int ove_audio_node_converter(struct ove_audio_graph *g, enum ove_audio_sample_fmt target_fmt,
249 const char *name);
250
266int ove_audio_node_channel_map(struct ove_audio_graph *g, const struct ove_audio_channel_map *map,
267 const char *name);
268
283int ove_audio_node_gain(struct ove_audio_graph *g, float gain_db, const char *name);
284
301int ove_audio_node_tap(struct ove_audio_graph *g, ove_audio_tap_fn fn, void *user_data,
302 const char *name);
303
304#endif /* OVE_HEAP_AUDIO */
305
306#ifdef __cplusplus
307}
308#endif
309
/* end of ove_audio_node group */
311
312#endif /* OVE_AUDIO_NODE_H */
ove_audio_sample_fmt
PCM sample format tag.
Definition audio_node.h:41
#define OVE_AUDIO_MAX_CHANNELS
Maximum number of audio channels supported by the channel-map node.
Definition audio_node.h:32
ove_audio_node_type
Role of a node within the audio graph.
Definition audio_node.h:183
void(* ove_audio_tap_fn)(const struct ove_audio_buf *buf, void *user_data)
Callback invoked by the tap node for every processed buffer.
Definition audio_node.h:226
static int ove_audio_fmt_equal(const struct ove_audio_fmt *a, const struct ove_audio_fmt *b)
Test two format descriptors for equality.
Definition audio_node.h:88
static unsigned int ove_audio_sample_size(enum ove_audio_sample_fmt fmt)
Return the size in bytes of one sample for a given format.
Definition audio_node.h:53
@ OVE_AUDIO_FMT_S16
Signed 16-bit integer (int16_t).
Definition audio_node.h:42
@ OVE_AUDIO_FMT_S32
Signed 32-bit integer (int32_t).
Definition audio_node.h:43
@ OVE_AUDIO_FMT_F32
32-bit IEEE 754 float.
Definition audio_node.h:44
@ OVE_AUDIO_NODE_PROCESSOR
Transforms audio; has one upstream connection.
Definition audio_node.h:185
@ OVE_AUDIO_NODE_SINK
Consumes audio; has no downstream connection.
Definition audio_node.h:186
@ OVE_AUDIO_NODE_SOURCE
Produces audio; has no upstream connection.
Definition audio_node.h:184
Audio buffer passed between nodes during graph processing.
Definition audio_node.h:102
unsigned int frames
Number of frames in data.
Definition audio_node.h:104
void * data
Pointer to interleaved sample data.
Definition audio_node.h:103
const struct ove_audio_fmt * fmt
Format descriptor for this buffer.
Definition audio_node.h:105
Channel routing table used by ove_audio_node_channel_map().
Definition audio_node.h:215
unsigned int out_channels
Number of output channels produced.
Definition audio_node.h:216
int map[OVE_AUDIO_MAX_CHANNELS]
map[out_ch] = in_ch index, or -1 for silence.
Definition audio_node.h:217
Complete audio stream format descriptor.
Definition audio_node.h:75
unsigned int sample_rate
Sample rate in Hz.
Definition audio_node.h:76
enum ove_audio_sample_fmt sample_fmt
PCM sample format.
Definition audio_node.h:78
unsigned int channels
Number of interleaved channels.
Definition audio_node.h:77
Audio processing graph instance.
Definition audio.h:96
Virtual function table (vtable) for an audio processing node.
Definition audio_node.h:118
void(* destroy)(void *ctx)
Release all resources owned by the node context.
Definition audio_node.h:175
int(* start)(void *ctx)
Start the node (called on graph start). NULL = no-op.
Definition audio_node.h:143
int(* configure)(void *ctx, const struct ove_audio_fmt *in_fmt, struct ove_audio_fmt *out_fmt)
Negotiate format during graph build (topological order).
Definition audio_node.h:134
int(* process)(void *ctx, const struct ove_audio_buf *in, struct ove_audio_buf *out)
Process one buffer period.
Definition audio_node.h:166
int(* stop)(void *ctx)
Stop the node (called on graph stop). NULL = no-op.
Definition audio_node.h:151
Descriptor for a single node in the audio graph.
Definition audio_node.h:195
const struct ove_audio_node_ops * ops
Vtable for this node.
Definition audio_node.h:198
const char * name
Human-readable node name.
Definition audio_node.h:196
enum ove_audio_node_type type
Source, processor, or sink.
Definition audio_node.h:197
struct ove_audio_fmt out_fmt
Output format resolved during graph build.
Definition audio_node.h:200
void * ctx
Opaque context forwarded to every vtable call.
Definition audio_node.h:199