This commit is contained in:
Johannes Findeisen 2026-10-26 23:32:04 +01:00
commit 577d80f018
16 changed files with 1100 additions and 41 deletions

63
include/xtc/xtc_backend.h Normal file
View file

@ -0,0 +1,63 @@
#ifndef XTC_BACKEND_H
#define XTC_BACKEND_H
#include "xtc_engine.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct xtc_backend xtc_backend;
typedef enum { XTC_BACKEND_JACK = 1 } xtc_backend_kind;
typedef struct {
xtc_backend_kind kind;
const char *client_name; /* Borrowed for open only; nonempty. */
size_t max_frames; /* 1..65536, at least the server's current block. */
size_t channel_count; /* Currently must be 1. */
} xtc_backend_config;
typedef struct {
unsigned int sample_rate;
unsigned int buffer_frames;
unsigned int xruns; /* Wraps modulo UINT_MAX + 1. */
unsigned int processed_blocks;
int running;
int server_lost;
int sample_rate_changed; /* Sticky: close/reopen and resubmit to recover. */
xtc_result process_result;
} xtc_backend_status;
/* All operations are serialized on one control thread. Public API contains
* no JACK types. JACK is optional at build time (otherwise UNSUPPORTED).
* Opens without starting a server, changing devices, or connecting ports.
* Returns IO if server/client setup fails. On failure *out_backend is NULL,
* except if cleanup itself fails: a non-NULL handle must be closed/retried;
* only close is permitted on that partially initialized handle. */
xtc_result xtc_backend_open(const xtc_backend_config *config, xtc_backend **out_backend);
/* Stop/close establish callback quiescence before state can be destroyed.
* On failure the handle remains owned by caller; retry close. NULL close OK. */
xtc_result xtc_backend_close(xtc_backend *backend);
xtc_result xtc_backend_start(xtc_backend *backend);
xtc_result xtc_backend_stop(xtc_backend *backend);
/* Submit allowed stopped or running. Copies graph; capacity = pending slot busy. */
xtc_result xtc_backend_submit(xtc_backend *backend, const xtc_graph *graph);
void xtc_backend_collect(xtc_backend *backend);
/* Snapshot fields are individually coherent, not a transactional snapshot. */
xtc_result xtc_backend_get_status(const xtc_backend *backend, xtc_backend_status *out_status);
/* Borrowed names valid until close. Direction is the client's own port. */
xtc_result xtc_backend_port_name(const xtc_backend *backend, xtc_port_direction direction,
const char **out_name);
/* Enumerates available mono audio ports (devices and software routes). Visitor
* receives a borrowed name valid only during call; return nonzero to stop.
* Control-thread only. JACK NULL list means no matching ports. */
typedef int (*xtc_backend_port_visitor)(const char *name, void *context);
xtc_result xtc_backend_visit_ports(xtc_backend *backend, xtc_port_direction direction,
xtc_backend_port_visitor visitor, void *context);
/* Connect/disconnect this client's port with a remote opposite-direction port.
* own_direction INPUT receives remote output; OUTPUT sends to remote input.
* Explicit user choice only; no automatic physical routing. */
xtc_result xtc_backend_connect(xtc_backend *backend, xtc_port_direction own_direction,
const char *remote_name);
xtc_result xtc_backend_disconnect(xtc_backend *backend, xtc_port_direction own_direction,
const char *remote_name);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,38 @@
#ifndef XTC_REALTIME_H
#define XTC_REALTIME_H
#include "xtc_engine.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct xtc_realtime xtc_realtime;
typedef struct {
unsigned int processed_blocks; /* Wraps modulo UINT_MAX + 1. */
xtc_result last_result;
} xtc_realtime_status;
/* Control thread only. A single control producer and single audio consumer.
* C99 with GCC/Clang lock-free __atomic builtins is required; unsupported
* targets return XTC_ERR_UNSUPPORTED. No ownership is shared with callers. */
xtc_result xtc_realtime_create(double sample_rate, size_t max_frames,
xtc_realtime **out_engine);
/* Requires the audio consumer to have stopped and joined. */
void xtc_realtime_destroy(xtc_realtime *engine);
/* Compiles/copies a graph. One pending plan allowed; full mailbox returns
* XTC_ERR_CAPACITY without changing the active or pending plan. */
xtc_result xtc_realtime_submit(xtc_realtime *engine, const xtc_graph *graph);
/* Frees acknowledged retired state, never the audio thread's active plan. */
void xtc_realtime_collect(xtc_realtime *engine);
xtc_result xtc_realtime_get_status(const xtc_realtime *engine,
xtc_realtime_status *out_status);
/* Audio consumer only. Adopts at most one plan per block, without allocation,
* freeing, locks or I/O. No plan means silence. On failure writes silence.
* frame_count must be <= configured max_frames and output must hold it.
* Oversized buffers are silenced too; callers must bound their own frame count.
* NULL input means silence. Zero frames is a no-op. */
xtc_result xtc_realtime_process(xtc_realtime *engine, const float *input,
float *output, size_t frame_count);
#ifdef __cplusplus
}
#endif
#endif