Added tons of documentation headers to functions in source files.

This commit is contained in:
Johannes Findeisen 2026-10-27 01:58:27 +01:00
commit 4eb2080933
43 changed files with 3953 additions and 43 deletions

View file

@ -18,6 +18,11 @@ struct xtc_plan {
xtc_native **native;
};
/**
* @brief Releases a compiled plan and all resources it owns.
*
* @param plan Plan to destroy; NULL is accepted.
*/
void xtc_plan_destroy(xtc_plan *plan)
{
if (plan == NULL)
@ -39,6 +44,15 @@ void xtc_plan_destroy(xtc_plan *plan)
free(plan);
}
/**
* @brief Allocates an independent execution plan with preallocated processing buffers.
*
* @param graph Graph model; borrowed for this call.
* @param sample_rate Sample rate in hertz.
* @param max_frames Maximum frames per processing block.
* @param out_plan Receives the newly allocated plan; caller owns it on success.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_compile(const xtc_graph *graph, double sample_rate, size_t max_frames, xtc_plan **out_plan)
{
xtc_plan *plan;
@ -118,6 +132,12 @@ xtc_result xtc_graph_compile(const xtc_graph *graph, double sample_rate, size_t
return XTC_OK;
}
/**
* @brief Resets oscillator phases, meters, and native processor state without allocating.
*
* @param plan Compiled graph plan and its single-owner runtime state.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_plan_reset(xtc_plan *plan)
{
if (plan == NULL)
@ -133,6 +153,14 @@ xtc_result xtc_plan_reset(xtc_plan *plan)
return XTC_OK;
}
/**
* @brief Copies the last block's absolute peak for a meter node.
*
* @param plan Compiled graph plan and its single-owner runtime state.
* @param node_id Stable node identifier.
* @param out_peak Receives the peak.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_plan_meter_peak(const xtc_plan *plan, size_t node_id, float *out_peak)
{
if (plan == NULL || out_peak == NULL)
@ -150,6 +178,20 @@ xtc_result xtc_plan_meter_peak(const xtc_plan *plan, size_t node_id, float *out_
return XTC_OK;
}
/**
* @brief Processes a block with separate stereo timeline and instrument sources.
*
* @param plan Compiled graph plan and its single-owner runtime state.
* @param input Borrowed input sample buffer.
* @param timeline Borrowed timeline source buffer; NULL means silence.
* @param timeline_right Borrowed right timeline source buffer; NULL means silence.
* @param instrument Borrowed instrument source buffer; NULL means silence.
* @param instrument_right Borrowed right instrument source buffer; NULL means silence.
* @param output Destination buffer with room for the requested frames.
* @param right Destination right-channel buffer; NULL selects mono rendering.
* @param frame_count Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_plan_process_stereo(xtc_plan *plan, const float *input, const float *timeline,
const float *timeline_right, const float *instrument, const float *instrument_right,
float *output, float *right, size_t frame_count)
@ -231,6 +273,16 @@ xtc_result xtc_plan_process_stereo(xtc_plan *plan, const float *input, const flo
return XTC_OK;
}
/**
* @brief Compiles at 48000 Hz, applies input gain, renders once, and releases temporary state.
*
* @param graph Graph model; borrowed for this call.
* @param input Borrowed input sample buffer.
* @param output Destination buffer with room for the requested frames.
* @param frame_count Number of audio frames.
* @param input_gain Finite linear gain applied to external input before processing.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_graph_process_offline(xtc_graph *graph, const float *input, float *output, size_t frame_count,
float input_gain)
{
@ -247,17 +299,47 @@ xtc_result xtc_graph_process_offline(xtc_graph *graph, const float *input, float
return result;
}
/**
* @brief Processes a mono block with external input and no timeline or instrument sources.
*
* @param plan Compiled graph plan and its single-owner runtime state.
* @param input Borrowed input sample buffer.
* @param output Destination buffer with room for the requested frames.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_plan_process(xtc_plan *plan, const float *input, float *output, size_t frames)
{
return xtc_plan_process_audio(plan, input, NULL, output, frames);
}
/**
* @brief Processes a mono block with timeline audio and no instrument source.
*
* @param plan Compiled graph plan and its single-owner runtime state.
* @param input Borrowed input sample buffer.
* @param timeline Borrowed timeline source buffer; NULL means silence.
* @param output Destination buffer with room for the requested frames.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_plan_process_audio(xtc_plan *plan, const float *input, const float *timeline, float *output,
size_t frames)
{
return xtc_plan_process_sources(plan, input, timeline, NULL, output, frames);
}
/**
* @brief Processes a mono block with separate timeline and instrument sources.
*
* @param p Compiled graph plan and its single-owner runtime state.
* @param in Borrowed mono input buffer; NULL means silence.
* @param audio Borrowed timeline source buffer; NULL means silence.
* @param midi Borrowed instrument source buffer; NULL means silence.
* @param out Destination sample buffer with room for the requested frames.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_plan_process_sources(xtc_plan *p, const float *in, const float *audio, const float *midi, float *out,
size_t frames)
{

View file

@ -14,6 +14,21 @@ struct xtc_realtime {
unsigned int submitted_revision, pending_revision, active_revision;
};
/**
* @brief Creates a realtime engine for single-producer, single-consumer use.
*
* The engine starts without an active plan, so processing produces silence
* until a graph is submitted. The caller owns the new engine and must release
* it with xtc_realtime_destroy() after stopping the audio consumer.
*
* @param sample_rate Sample rate in Hz; must be finite and positive.
* @param max_frames Maximum frames per process call, from 1 to 65536.
* @param out_engine Receives the new engine on success and NULL on failure;
* must not be NULL.
* @return XTC_OK on success, XTC_ERR_INVALID_ARGUMENT for invalid limits,
* XTC_ERR_UNSUPPORTED if required atomics are not lock-free, or
* XTC_ERR_OUT_OF_MEMORY if allocation fails.
*/
xtc_result xtc_realtime_create(double sample_rate, size_t max_frames, xtc_realtime **out_engine)
{
xtc_realtime *engine;
@ -33,6 +48,11 @@ xtc_result xtc_realtime_create(double sample_rate, size_t max_frames, xtc_realti
return XTC_OK;
}
/**
* @brief Frees acknowledged retired plans on the control thread.
*
* @param engine Realtime engine handle.
*/
void xtc_realtime_collect(xtc_realtime *engine)
{
xtc_plan *retired;
@ -42,6 +62,11 @@ void xtc_realtime_collect(xtc_realtime *engine)
xtc_plan_destroy(retired);
}
/**
* @brief Releases the engine after the audio consumer has stopped; accepts NULL.
*
* @param engine Realtime engine handle.
*/
void xtc_realtime_destroy(xtc_realtime *engine)
{
if (engine == NULL)
@ -53,6 +78,13 @@ void xtc_realtime_destroy(xtc_realtime *engine)
free(engine);
}
/**
* @brief Compiles and publishes a graph to the single pending-plan slot.
*
* @param engine Realtime engine handle.
* @param graph Graph model; borrowed for this call.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_realtime_submit(xtc_realtime *engine, const xtc_graph *graph)
{
xtc_plan *plan = NULL;
@ -74,6 +106,13 @@ xtc_result xtc_realtime_submit(xtc_realtime *engine, const xtc_graph *graph)
return XTC_OK;
}
/**
* @brief Copies processing counters, plan revisions, and the last processing result.
*
* @param engine Realtime engine handle.
* @param out_status Receives the status.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_realtime_get_status(const xtc_realtime *engine, xtc_realtime_status *out_status)
{
if (engine == NULL || out_status == NULL)
@ -85,6 +124,20 @@ xtc_result xtc_realtime_get_status(const xtc_realtime *engine, xtc_realtime_stat
return XTC_OK;
}
/**
* @brief Adopts a pending plan and processes stereo sources without allocation or locking.
*
* @param engine Realtime engine handle.
* @param input Borrowed input sample buffer.
* @param timeline Borrowed timeline source buffer; NULL means silence.
* @param timeline_right Borrowed right timeline source buffer; NULL means silence.
* @param instrument Borrowed instrument source buffer; NULL means silence.
* @param instrument_right Borrowed right instrument source buffer; NULL means silence.
* @param output Destination buffer with room for the requested frames.
* @param right Destination right-channel buffer; NULL selects mono rendering.
* @param frame_count Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_realtime_process_stereo(xtc_realtime *engine, const float *input, const float *timeline,
const float *timeline_right, const float *instrument,
const float *instrument_right, float *output, float *right, size_t frame_count)
@ -132,17 +185,47 @@ xtc_result xtc_realtime_process_stereo(xtc_realtime *engine, const float *input,
return result;
}
/**
* @brief Processes a mono block with external input only.
*
* @param engine Realtime engine handle.
* @param input Borrowed input sample buffer.
* @param output Destination buffer with room for the requested frames.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_realtime_process(xtc_realtime *engine, const float *input, float *output, size_t frames)
{
return xtc_realtime_process_audio(engine, input, NULL, output, frames);
}
/**
* @brief Processes a mono block with timeline audio and no instrument source.
*
* @param engine Realtime engine handle.
* @param input Borrowed input sample buffer.
* @param timeline Borrowed timeline source buffer; NULL means silence.
* @param output Destination buffer with room for the requested frames.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_realtime_process_audio(xtc_realtime *engine, const float *input, const float *timeline, float *output,
size_t frames)
{
return xtc_realtime_process_sources(engine, input, timeline, NULL, output, frames);
}
/**
* @brief Processes mono timeline and instrument sources through the realtime engine.
*
* @param p Realtime engine handle.
* @param in Borrowed mono input buffer; NULL means silence.
* @param audio Borrowed timeline source buffer; NULL means silence.
* @param midi Borrowed instrument source buffer; NULL means silence.
* @param out Destination sample buffer with room for the requested frames.
* @param frames Number of audio frames.
* @return XTC_OK on success, or an error code describing the failure.
*/
xtc_result xtc_realtime_process_sources(xtc_realtime *p, const float *in, const float *audio, const float *midi,
float *out, size_t frames)
{