Phase 22: add non-destructive audio splitting, clip gain and fades, and cached waveforms

This commit is contained in:
Johannes Findeisen 2026-10-27 15:46:41 +01:00
commit 01d8c1d661
23 changed files with 650 additions and 18 deletions

View file

@ -10,6 +10,26 @@ extern "C" {
typedef struct xtc_audio_plan xtc_audio_plan;
typedef struct xtc_recorder xtc_recorder;
/* Control-thread metadata edits; audio/silent clips only. No source-file writes.
* Gain 0..4, fade durations 0..source_length_tick, measured at current tempo.
* Fades follow audible trimmed boundaries; 0 disables the explicit fade. */
xtc_result xtc_project_set_clip_audio(xtc_project *project, uint64_t clip, float gain,
uint64_t fade_in_tick, uint64_t fade_out_tick);
/* Split strictly inside the timeline range. Left keeps ID; right receives a
* fresh ID and adjusted source offset. Gain/source/name retained. Inner explicit
* fades cleared; outer fades retained. Transactional; output unchanged on error. */
xtc_result xtc_project_split_audio(xtc_project *project, uint64_t clip, uint64_t tick, uint64_t *out_right);
/* Immutable waveform summary, created/destroyed on control thread only. Uses
* the same bounded WAV reader/downmix as playback; no media writes. Up to 1024
* equal frame bins, fewer for short media. Peaks are raw source, before gain or
* fades. Accessors read cached memory only. Load errors are explicit. */
typedef struct xtc_waveform xtc_waveform;
xtc_result xtc_waveform_create(const char *path, xtc_waveform **out);
void xtc_waveform_destroy(xtc_waveform *waveform);
xtc_result xtc_waveform_info(const xtc_waveform *waveform, unsigned int *rate, size_t *frames, size_t *bins);
xtc_result xtc_waveform_peak(const xtc_waveform *waveform, size_t bin, float *minimum, float *maximum);
/* 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.
@ -67,11 +87,11 @@ xtc_result xtc_audio_plan_set_fade_frames(xtc_audio_plan *plan, size_t frames);
* @return Number of unique asset issues; zero for a NULL 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.
/* Single consumer; output replaced with overlap-summed mono, clip/track gain and fades.
* Linear rate conversion, no time stretching. Output must have frames floats. */
/* Stereo outputs must be distinct; NULL right selects mono gain-only rendering. */
/**
* @brief Replaces output with the overlap-summed timeline mix, applying track gain and pan.
* @brief Replaces output with the overlap-summed timeline mix, applying clip gain/fades and track gain/pan.
*
* @param plan Preloaded arrangement plan.
* @param position Absolute sample position at the start of the block.

View file

@ -7,7 +7,7 @@
extern "C" {
#endif
#define XTC_PROJECT_FORMAT_VERSION 7U
#define XTC_PROJECT_FORMAT_VERSION 8U
#define XTC_PROJECT_MAX_TRACKS 64U
#define XTC_PROJECT_MAX_CLIPS 1024U
#define XTC_PROJECT_NAME_BYTES 64U
@ -35,6 +35,8 @@ typedef struct {
uint64_t id, track_id, start_tick, length_tick, offset_tick, source_length_tick;
char name[XTC_PROJECT_NAME_BYTES];
char asset_path[XTC_ASSET_PATH_BYTES];
float gain; /* Audio-only, linear 0..4; default 1. */
uint64_t fade_in_tick, fade_out_tick; /* Audio-only linear boundary fades. */
int midi; /* 0 silent/audio region, 1 MIDI clip; no asset path in MIDI. */
} xtc_clip_info;
@ -209,7 +211,7 @@ xtc_result xtc_project_sample_to_tick(const xtc_project *project, uint64_t sampl
uint64_t *out_tick);
/* Control-thread I/O. Versioned, bounded format; see docs/PROJECT_FORMAT.md.
* Load is transactional. Save fsyncs a same-directory temporary and renames it;
* failures before rename preserve the previous destination. No asset I/O. v7 saves local media paths relative to the project folder; load
* failures before rename preserve the previous destination. No asset I/O. v7+ saves local media paths relative to the project folder; load
* resolves them to absolute references. Post-rename directory-sync failure can
* report IO with the complete new document already published. */
/**