oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
audio.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
14#pragma once
15
16#include <ove/audio.h>
17#include <ove/audio_device.h>
18#include <ove/types.hpp>
19
20#ifdef CONFIG_OVE_AUDIO
21
22namespace ove {
23namespace audio {
24
30class Graph {
31public:
32 Graph() : initialized_(false) {}
33
34 ~Graph() {
35 if (initialized_)
36 ove_audio_graph_deinit(&g_);
37 }
38
40 [[nodiscard]] int init(unsigned int frames_per_period) {
41 int ret = ove_audio_graph_init(&g_, frames_per_period);
42 if (ret == OVE_OK)
43 initialized_ = true;
44 return ret;
45 }
46
48 [[nodiscard]] int add_node(const struct ove_audio_node_ops *ops,
49 void *ctx, const char *name,
50 enum ove_audio_node_type type) {
51 return ove_audio_graph_add_node(&g_, ops, ctx, name, type);
52 }
53
55 [[nodiscard]] int connect(unsigned int from, unsigned int to) {
56 return ove_audio_graph_connect(&g_, from, to);
57 }
58
60 [[nodiscard]] int build() {
61 return ove_audio_graph_build(&g_);
62 }
63
65 [[nodiscard]] int start() {
66 return ove_audio_graph_start(&g_);
67 }
68
70 [[nodiscard]] int stop() {
71 return ove_audio_graph_stop(&g_);
72 }
73
75 [[nodiscard]] int process() {
76 return ove_audio_graph_process(&g_);
77 }
78
80 [[nodiscard]] int get_stats(struct ove_audio_graph_stats *stats) const {
81 return ove_audio_graph_get_stats(&g_, stats);
82 }
83
85 [[nodiscard]] int device_source(const struct ove_audio_device_cfg *cfg,
86 const char *name) {
87 return ove_audio_device_source(&g_, cfg, name);
88 }
89
91 [[nodiscard]] int device_sink(const struct ove_audio_device_cfg *cfg,
92 const char *name) {
93 return ove_audio_device_sink(&g_, cfg, name);
94 }
95
97 struct ove_audio_graph *raw() { return &g_; }
98
103 template<typename T>
104 [[nodiscard]] int add_processor(T &node, const char *name) {
105 static const struct ove_audio_node_ops ops = {
106 /* configure */
107 [](void *, const struct ove_audio_fmt *in_f,
108 struct ove_audio_fmt *out_f) -> int {
109 if (in_f && out_f) *out_f = *in_f;
110 return OVE_OK;
111 },
112 /* start */ nullptr,
113 /* stop */ nullptr,
114 /* process */
115 [](void *ctx, const struct ove_audio_buf *in,
116 struct ove_audio_buf *out) -> int {
117 return static_cast<T*>(ctx)->process(in, out);
118 },
119 /* destroy */ nullptr,
120 };
121 return ove_audio_graph_add_node(&g_, &ops, &node, name,
122 OVE_AUDIO_NODE_PROCESSOR);
123 }
124
125private:
126 struct ove_audio_graph g_;
127 bool initialized_;
128};
129
130} /* namespace audio */
131} /* namespace ove */
132
133#endif /* CONFIG_OVE_AUDIO */
C++ wrapper around ove_audio_graph.
Definition audio.hpp:30
int connect(unsigned int from, unsigned int to)
Connect two nodes (output of from to input of to).
Definition audio.hpp:55
int init(unsigned int frames_per_period)
Initialise the audio graph with the given period size.
Definition audio.hpp:40
int get_stats(struct ove_audio_graph_stats *stats) const
Query runtime statistics.
Definition audio.hpp:80
int build()
Finalize the graph topology.
Definition audio.hpp:60
struct ove_audio_graph * raw()
Access the underlying C graph struct.
Definition audio.hpp:97
int device_source(const struct ove_audio_device_cfg *cfg, const char *name)
Add an audio input device as a source node.
Definition audio.hpp:85
int device_sink(const struct ove_audio_device_cfg *cfg, const char *name)
Add an audio output device as a sink node.
Definition audio.hpp:91
int process()
Run one processing period through the graph.
Definition audio.hpp:75
int start()
Start audio processing.
Definition audio.hpp:65
int stop()
Stop audio processing.
Definition audio.hpp:70
int add_node(const struct ove_audio_node_ops *ops, void *ctx, const char *name, enum ove_audio_node_type type)
Add a processing node to the graph.
Definition audio.hpp:48
int add_processor(T &node, const char *name)
Definition audio.hpp:104
Top-level namespace for all oveRTOS C++ abstractions.
Definition app.hpp:19
Common type definitions and concepts for the C++ wrapper layer.