oveRTOS C API
Embedded RTOS framework — build system, configuration, and portable C API
Loading...
Searching...
No Matches
audio_node.h
1/* SPDX-License-Identifier: GPL-3.0-or-later */
2
19#ifndef OVE_AUDIO_NODE_H
20#define OVE_AUDIO_NODE_H
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#include <stdint.h>
27
29#define OVE_AUDIO_MAX_CHANNELS 8
30
31/* ── Sample format ──────────────────────────────────────────────── */
32
43
50static inline unsigned int ove_audio_sample_size(enum ove_audio_sample_fmt fmt)
51{
52 switch (fmt) {
53 case OVE_AUDIO_FMT_S16: return sizeof(int16_t);
54 case OVE_AUDIO_FMT_S32: return sizeof(int32_t);
55 case OVE_AUDIO_FMT_F32: return sizeof(float);
56 default: return 0;
57 }
58}
59
60/* ── Audio format descriptor ────────────────────────────────────── */
61
69 unsigned int sample_rate;
70 unsigned int channels;
72};
73
81static inline int ove_audio_fmt_equal(const struct ove_audio_fmt *a,
82 const struct ove_audio_fmt *b)
83{
84 return a->sample_rate == b->sample_rate &&
85 a->channels == b->channels &&
86 a->sample_fmt == b->sample_fmt;
87}
88
89/* ── Audio buffer ───────────────────────────────────────────────── */
90
98 void *data;
99 unsigned int frames;
100 const struct ove_audio_fmt *fmt;
101};
102
103/* ── Node vtable ────────────────────────────────────────────────── */
104
128 int (*configure)(void *ctx, const struct ove_audio_fmt *in_fmt,
129 struct ove_audio_fmt *out_fmt);
130
137 int (*start)(void *ctx);
138
145 int (*stop)(void *ctx);
146
160 int (*process)(void *ctx, const struct ove_audio_buf *in,
161 struct ove_audio_buf *out);
162
170 void (*destroy)(void *ctx);
171};
172
173/* ── Node types ─────────────────────────────────────────────────── */
174
183
191 const char *name;
193 const struct ove_audio_node_ops *ops;
194 void *ctx;
196};
197
198/* ── Built-in node factories ────────────────────────────────────── */
199
200struct ove_audio_graph; /* forward declaration */
201
217 enum ove_audio_sample_fmt target_fmt,
218 const char *name);
219
232
249 const struct ove_audio_channel_map *map,
250 const char *name);
251
267 float gain_db, const char *name);
268
275typedef void (*ove_audio_tap_fn)(const struct ove_audio_buf *buf,
276 void *user_data);
277
295 ove_audio_tap_fn fn, void *user_data,
296 const char *name);
297
298#ifdef __cplusplus
299}
300#endif
301
/* end of ove_audio_node group */
303
304#endif /* OVE_AUDIO_NODE_H */
ove_audio_sample_fmt
PCM sample format tag.
Definition audio_node.h:38
int ove_audio_node_tap(struct ove_audio_graph *g, ove_audio_tap_fn fn, void *user_data, const char *name)
Add a tap (observer) sink node to the graph.
#define OVE_AUDIO_MAX_CHANNELS
Maximum number of audio channels supported by the channel-map node.
Definition audio_node.h:29
int ove_audio_node_converter(struct ove_audio_graph *g, enum ove_audio_sample_fmt target_fmt, const char *name)
Add a sample-format converter processor node to the graph.
ove_audio_node_type
Role of a node within the audio graph.
Definition audio_node.h:178
int ove_audio_node_channel_map(struct ove_audio_graph *g, const struct ove_audio_channel_map *map, const char *name)
Add a channel-mapping processor node to the graph.
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:275
int ove_audio_node_gain(struct ove_audio_graph *g, float gain_db, const char *name)
Add a gain processor node to the graph.
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:81
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:50
@ OVE_AUDIO_FMT_S16
Signed 16-bit integer (int16_t).
Definition audio_node.h:39
@ OVE_AUDIO_FMT_S32
Signed 32-bit integer (int32_t).
Definition audio_node.h:40
@ OVE_AUDIO_FMT_F32
32-bit IEEE 754 float.
Definition audio_node.h:41
@ OVE_AUDIO_NODE_PROCESSOR
Transforms audio; has one upstream connection.
Definition audio_node.h:180
@ OVE_AUDIO_NODE_SINK
Consumes audio; has no downstream connection.
Definition audio_node.h:181
@ OVE_AUDIO_NODE_SOURCE
Produces audio; has no upstream connection.
Definition audio_node.h:179
Audio buffer passed between nodes during graph processing.
Definition audio_node.h:97
unsigned int frames
Number of frames in data.
Definition audio_node.h:99
void * data
Pointer to interleaved sample data.
Definition audio_node.h:98
const struct ove_audio_fmt * fmt
Format descriptor for this buffer.
Definition audio_node.h:100
Channel routing table used by ove_audio_node_channel_map().
Definition audio_node.h:228
unsigned int out_channels
Number of output channels produced.
Definition audio_node.h:229
int map[OVE_AUDIO_MAX_CHANNELS]
map[out_ch] = in_ch index, or -1 for silence.
Definition audio_node.h:230
Complete audio stream format descriptor.
Definition audio_node.h:68
unsigned int sample_rate
Sample rate in Hz.
Definition audio_node.h:69
enum ove_audio_sample_fmt sample_fmt
PCM sample format.
Definition audio_node.h:71
unsigned int channels
Number of interleaved channels.
Definition audio_node.h:70
Audio processing graph instance.
Definition audio.h:93
Virtual function table (vtable) for an audio processing node.
Definition audio_node.h:112
void(* destroy)(void *ctx)
Release all resources owned by the node context.
Definition audio_node.h:170
int(* start)(void *ctx)
Start the node (called on graph start). NULL = no-op.
Definition audio_node.h:137
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:128
int(* process)(void *ctx, const struct ove_audio_buf *in, struct ove_audio_buf *out)
Process one buffer period.
Definition audio_node.h:160
int(* stop)(void *ctx)
Stop the node (called on graph stop). NULL = no-op.
Definition audio_node.h:145
Descriptor for a single node in the audio graph.
Definition audio_node.h:190
const struct ove_audio_node_ops * ops
Vtable for this node.
Definition audio_node.h:193
const char * name
Human-readable node name.
Definition audio_node.h:191
enum ove_audio_node_type type
Source, processor, or sink.
Definition audio_node.h:192
struct ove_audio_fmt out_fmt
Output format resolved during graph build.
Definition audio_node.h:195
void * ctx
Opaque context forwarded to every vtable call.
Definition audio_node.h:194