xtc/include/xtc/xtc_audio.h

46 lines
2.6 KiB
C

#ifndef XTC_AUDIO_H
#define XTC_AUDIO_H
#include "xtc_project.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct xtc_audio_plan xtc_audio_plan;
typedef struct xtc_recorder xtc_recorder;
/* Control-thread WAV import: PCM16/24/32 or float32, mono/stereo downmixed to
* mono, 1..768000 Hz. Absolute canonical references, <=511 bytes.
* Adds a timeline source -> output route if no timeline source exists.
* Transactional; track must exist. Duration rounds up to a musical tick. */
xtc_result xtc_project_import_audio(xtc_project *project, uint64_t track,
const char *path, uint64_t start_tick, uint64_t *out_clip);
/* Empty path makes a region silent; nonempty path must be absolute. Does not
* open the file. Missing references survive save/load for later relinking. */
xtc_result xtc_project_set_clip_asset(xtc_project *project, uint64_t clip, const char *path);
/* Immutable/preloaded plan. At most 64 distinct assets, 16M mono frames/asset,
* 64M total frames, 256 MiB file and 4096 chunk input limits. Missing/invalid assets become silence with explicit issues.
* OOM/capacity fails creation. No file access during render. */
xtc_result xtc_audio_plan_create(const xtc_project *project, unsigned int rate,
xtc_audio_plan **out_plan);
void xtc_audio_plan_destroy(xtc_audio_plan *plan);
size_t xtc_audio_plan_issues(const xtc_audio_plan *plan, const char **out_first_path);
/* Single consumer; output replaced with overlap-summed mono at unity gain.
* Linear rate conversion, no time stretching. Output must have frames floats. */
xtc_result xtc_audio_plan_render(const xtc_audio_plan *plan, uint64_t position,
float *output, size_t frames);
/* Control-thread creation opens a same-directory temporary float32 WAV.
* Ring capacity 1..2097152 frames. One callback producer, one control consumer.
* push accepts whole blocks; overflow is sticky and all later input is dropped.
* drain performs file I/O; call regularly. finish requires producer quiescence,
* drains, finalizes and atomically renames even on overflow (partial recovery).
* No source/recorder is freed until destroy, which also removes unfinished temp.
* Counts and sticky error can be observed while producing. */
xtc_result xtc_recorder_create(const char *path, unsigned int rate, size_t capacity,
xtc_recorder **out_recorder);
void xtc_recorder_push(xtc_recorder *recorder, const float *input, size_t frames);
xtc_result xtc_recorder_drain(xtc_recorder *recorder);
xtc_result xtc_recorder_finish(xtc_recorder *recorder);
xtc_result xtc_recorder_status(const xtc_recorder *recorder, uint64_t *out_frames);
void xtc_recorder_destroy(xtc_recorder *recorder);
#ifdef __cplusplus
}
#endif
#endif