Files

42 lines
1.0 KiB
C++
Raw Permalink Normal View History

2026-07-24 01:12:37 -07:00
#ifndef PIPEMINI_H
#define PIPEMINI_H
#include <pipewire/pipewire.h>
#include <spa/param/audio/format-utils.h>
#include <stdint.h>
#include <functional>
// Simple PipeWire audio output interface.
// Calls a user-provided callback once per sample at the configured sample rate.
// The callback writes one 16-bit stereo sample (left, right).
class PipeMini {
public:
using Callback = std::function<void(int16_t* left, int16_t* right)>;
PipeMini();
~PipeMini();
// Start the stream with the given callback.
// sample_rate is typically 48000.
bool start(const Callback& cb, int sample_rate = 48000);
void stop();
public:
static void on_process(void* userdata);
void teardown();
private:
pw_main_loop* loop_ = nullptr;
pw_stream* stream_ = nullptr;
pw_core* core_ = nullptr;
pw_context* context_ = nullptr;
spa_hook stream_listener_ = {};
Callback callback_;
int sample_rate_ = 48000;
bool running_ = false;
struct PipeMiniData* data_ = nullptr;
};
#endif // PIPEMINI_H