17#include <ove/audio_device.h>
21#ifdef CONFIG_OVE_AUDIO
53inline struct ove_audio_device_cfg
device_cfg_i2s(uint32_t sample_rate, uint32_t channels,
54 uint32_t input_device)
56 struct ove_audio_device_cfg cfg {
58 cfg.transport = OVE_AUDIO_TRANSPORT_I2S;
59 cfg.fmt.sample_rate = sample_rate;
60 cfg.fmt.channels = channels;
61 cfg.fmt.sample_fmt = OVE_AUDIO_FMT_S16;
62 cfg.i2s.input_device = input_device;
74 Graph() : g_{}, initialized_(
false)
81 ove_audio_graph_deinit(&g_);
87 const int rc = ove_audio_graph_init(&g_, frames_per_period);
102 template <
unsigned Nodes,
unsigned Frames,
unsigned Channels = 1,
unsigned SampleBytes = 2>
105 int rc = ove_audio_graph_init(&g_, Frames);
109#ifdef CONFIG_OVE_ZERO_HEAP
110 alignas(4)
static unsigned char storage[OVE_AUDIO_GRAPH_STORAGE_BYTES(
111 Nodes, Frames, Channels, SampleBytes)];
112 rc = ove_audio_graph_set_buf_storage(&g_, storage,
sizeof(storage));
121 const char *name,
enum ove_audio_node_type type)
noexcept
123 const int rc = ove_audio_graph_add_node(&g_, ops, ctx, name, type);
126 return std::unexpected{
static_cast<Error>(rc)};
132 return from_rc(ove_audio_graph_connect(&g_, from, to));
138 return from_rc(ove_audio_graph_build(&g_));
144 return from_rc(ove_audio_graph_start(&g_));
150 return from_rc(ove_audio_graph_stop(&g_));
156 return from_rc(ove_audio_graph_process(&g_));
163 struct ove_audio_graph_stats stats {
165 const int rc = ove_audio_graph_get_stats(&g_, &stats);
172 const char *name)
noexcept
174 const int rc = ove_audio_device_source(&g_, cfg, name);
177 return std::unexpected{
static_cast<Error>(rc)};
183 const char *name)
noexcept
185 const int rc = ove_audio_device_sink(&g_, cfg, name);
188 return std::unexpected{
static_cast<Error>(rc)};
192 struct ove_audio_graph *
raw()
205 static const struct ove_audio_node_ops ops = {
207 [](
void *,
const struct ove_audio_fmt *in_f,
208 struct ove_audio_fmt *out_f) ->
int {
216 [](
void *ctx,
const struct ove_audio_buf *in,
struct ove_audio_buf *out)
217 ->
int {
return static_cast<T *
>(ctx)->
process(in, out); },
221 ove_audio_graph_add_node(&g_, &ops, &node, name, OVE_AUDIO_NODE_PROCESSOR);
224 return std::unexpected{
static_cast<Error>(rc)};
228 struct ove_audio_graph g_;
C++ wrapper around ove_audio_graph.
Definition audio.hpp:72
Result< void > init(unsigned int frames_per_period) noexcept
Initialise the audio graph with the given period size.
Definition audio.hpp:85
Result< void > create() noexcept
Definition audio.hpp:103
Result< void > build() noexcept
Finalize the graph topology.
Definition audio.hpp:136
Result< struct ove_audio_graph_stats > get_stats() const noexcept
Definition audio.hpp:161
struct ove_audio_graph * raw()
Access the underlying C graph struct.
Definition audio.hpp:192
Result< void > connect(unsigned int from, unsigned int to) noexcept
Connect two nodes (output of from to input of to).
Definition audio.hpp:130
Result< int > device_sink(const struct ove_audio_device_cfg *cfg, const char *name) noexcept
Definition audio.hpp:182
Result< void > process() noexcept
Run one processing period through the graph.
Definition audio.hpp:154
Result< int > add_node(const struct ove_audio_node_ops *ops, void *ctx, const char *name, enum ove_audio_node_type type) noexcept
Definition audio.hpp:120
Result< int > add_processor(T &node, const char *name)
Definition audio.hpp:203
Result< void > start() noexcept
Start audio processing.
Definition audio.hpp:142
Result< int > device_source(const struct ove_audio_device_cfg *cfg, const char *name) noexcept
Definition audio.hpp:171
Result< void > stop() noexcept
Stop audio processing.
Definition audio.hpp:148
Strong ove::Error type, Result<T> alias, and std::error_code interop for the oveRTOS C++ binding.
Audio graph engine — typed node factories, device configuration helpers, and graph lifecycle (init/bu...
Definition audio.hpp:24
struct ove_audio_device_cfg device_cfg_i2s(uint32_t sample_rate, uint32_t channels, uint32_t input_device)
Build an audio device config for the I2S transport.
Definition audio.hpp:53
Result< void > from_rc(int rc) noexcept
Lifts a substrate rc-code into a Result<void>.
Definition error.hpp:254
Error
Strong-typed mirror of substrate OVE_ERR_* codes.
Definition error.hpp:64
std::expected< T, Error > Result
std::expected-based result alias.
Definition error.hpp:139
Common type definitions and concepts for the C++ wrapper layer.