feat: detect and slice audio attacks atomically and qualify sample editor workflows

This commit is contained in:
Johannes Findeisen 2026-11-06 01:16:39 +01:00
commit 9e380d4dd0
20 changed files with 257 additions and 22 deletions

View file

@ -5,7 +5,8 @@
extern "C" {
#endif
/* Control-thread sample editor snapshots. Same WAV mono downmix as playback.
* <=4194304 source frames. No file writes or realtime use. Ranges are half-open,
* <=4194304 source frames. Only explicit save writes files; never use in realtime.
* Ranges are half-open,
* nonempty native source frames; failures preserve outputs. */
#define XTC_SAMPLE_MAX_FRAMES 4194304U
typedef struct xtc_sample xtc_sample;
@ -18,7 +19,8 @@ xtc_result xtc_sample_analyze(const xtc_sample *sample,size_t begin,size_t end,x
typedef enum { XTC_SAMPLE_REVERSE, XTC_SAMPLE_INVERT, XTC_SAMPLE_REMOVE_DC, XTC_SAMPLE_FADE_IN, XTC_SAMPLE_FADE_OUT, XTC_SAMPLE_FADE_IN_POWER, XTC_SAMPLE_FADE_OUT_POWER, XTC_SAMPLE_GAIN, XTC_SAMPLE_NORMALIZE } xtc_sample_operation;
/* Independent full-source result; only [begin,end) changes. Never mutates input.
* amount: GAIN 0..16, NORMALIZE target 0<peak<=1 (required gain <=16).
* Other operations ignore amount. No implicit clipping; nonfinite results reject.
* All amounts must be finite; other operations ignore the value. No implicit
* clipping; nonfinite results reject.
* One-frame fades reject; fade endpoints are exactly 0 and 1. Failure preserves *out. */
xtc_result xtc_sample_process(const xtc_sample *sample,size_t begin,size_t end,
xtc_sample_operation operation,double amount,xtc_sample **out);
@ -30,8 +32,21 @@ xtc_result xtc_sample_audible_bounds(const xtc_sample *sample,size_t begin,size_
* center 0..frames, radius <=65536 frames. Edge boundaries qualify only when
* the adjacent sample is zero. NOT_FOUND preserves output. */
xtc_result xtc_sample_zero_crossing(const xtc_sample *sample,size_t center,size_t radius,size_t *out);
#define XTC_SAMPLE_MAX_TRANSIENTS 128U
/* Absolute-amplitude attacks: armed initially, rearm <=threshold/4, trigger
* >threshold, minimum gap since last retained attack. threshold >0..1,
* gap 1..MAX_FRAMES; includes a loud range start. No spectral/beat inference.
* All outputs unchanged on NOT_FOUND/capacity/errors. positions capacity 1..128. */
xtc_result xtc_sample_transients(const xtc_sample *sample,size_t begin,size_t end,
double threshold,size_t gap,size_t *positions,size_t capacity,size_t *count);
/* Sorted unique native source positions round to nearest timeline tick. Skip
* boundaries/out-of-trim and coalesced ticks. Split entire clip atomically,
* retaining left ID and outer explicit fades; no render auto-fades synthesized.
* Source/routing/mix unchanged, count unchanged on failure/no usable cuts. */
xtc_result xtc_project_slice_source_frames(xtc_project *project,uint64_t clip,unsigned int rate,
const size_t *positions,size_t count,size_t *out_slices);
/* Control-thread bounded mono float32 WAV save. Absolute path <512 bytes,
* NEW destination only. Failure/cancel publishes nothing and removes temporary. */
* NEW destination only. Failure publishes nothing and removes temporary. */
xtc_result xtc_sample_write(const xtc_sample *sample,size_t begin,size_t end,const char *path);
/* Select native source frame bounds inside the clip's current audible trim.
* Start rounds up to a tick; end rounds down. Sub-tick empty ranges reject.