xtc/docs/AUDIO_EDITOR.md
2026-11-06 15:20:20 +01:00

153 lines
6.7 KiB
Markdown

# Audio Source Editor Workflows
The editor uses the existing bounded mono WAV reader. Stereo input is downmixed;
these are offline control-thread tools, not stereo restoration or time
stretching. The project format remains 16. No new dependencies are required.
---
## Source Inspection
Select an audio clip and use View / Sample editor or double-click it. The modal
editor loads an independent snapshot of the complete source, up to 4,194,304
frames (about 87 seconds at 48 kHz). Drag or enter half-open native frame
bounds; zoom 1..64 and View start control the visible region. Statistics show
raw mono min/max, RMS and mean/DC before clip gain, fades or mixer processing.
Display clamps to ±1; sample statistics retain finite over-range values. Editing
project MIDI still opens the piano roll. This editor does not audition or stream
long files.
---
## Trim Clip to Selection
Trim clip to selection applies source-frame endpoints within the current audible
clip. Start rounds up and end rounds down to musical ticks; empty sub-tick
ranges reject. Leading removal moves the timeline start by the same amount,
preserving alignment. Source content, reference and clip gain/fade settings
remain intact; project Undo restores the prior trim.
---
## Export and Relink
Export selected frames writes a new mono float32 WAV of the half-open selection
at native rate. Save full copy and relink writes the complete source and relinks
only the selected clip after successful preparation. The original source is
never overwritten. Full-copy adoption requires matching source frame count/rate.
Project undo restores the reference but retains the new file, which may be
referenced by redo/history or other projects. Failed adoption removes its owned
new file. Export/copy runs synchronously outside audio callbacks.
---
## Reverse Selection
Reverse selection changes only the chosen source frames in a new local snapshot.
Undo / redo toggles the most recent processing step; selection and view are
unchanged. Processing does not affect playback until Save full copy and relink.
Close discards unsaved local processing. Sources are bounded to 16 MiB of float
samples; preparing a new edit can temporarily retain three snapshots (48 MiB),
then two (32 MiB).
---
## Invert Polarity
Invert polarity negates selected float samples; it is not time reversal.
Over-range finite samples remain over-range; no implicit limiting is performed.
Outside-selection frames are bit-preserved in the copied snapshot.
---
## Remove DC Offset
Remove DC offset subtracts the mean of the selected range from only that range.
This is a constant offset correction, not a high-pass filter. Selection
boundaries may acquire discontinuities; use fades or zero-crossing tools where
appropriate. Finite over-range results are retained; float overflow rejects the
edit.
---
## Sample Fades
Sample fades offers four offline curves: linear in/out and equal-power in/out
(sinusoidal amplitude). The entire selection is the fade duration; both
endpoints are included in the curve. Fewer than two frames reject. These curves
change copied sample data and stack with existing playback clip fades after
adoption; they do not form a linked clip crossfade.
---
## Gain and Normalize
Gain / normalize processes only selected samples. Mode 0 accepts linear gain
0..16; mode 1 accepts a linear peak target above 0 and at most 1, rejecting
silent selections or required gain above 16. Finite values above unity are not
clipped; float overflow rejects atomically. This changes sample data in the
local snapshot, unlike the existing clip-gain normalization command; it provides
neither true-peak nor LUFS processing.
---
## Select Audible Bounds
Select audible bounds finds the first and last sample strictly above the chosen
dBFS threshold and pads within the existing selection. It only changes
selection; use Trim clip to selection to apply a nondestructive timeline trim,
or export the selection. Entirely silent/below-threshold ranges leave selection
unchanged. This is boundary detection, not automatic removal of internal gaps or
a noise gate.
---
## Snap to Zero Crossings
Snap to zero crossings searches each selected boundary within a source-frame
radius up to 65,536. It uses the mono source, chooses earlier positions on equal
distance and changes both endpoints only if both searches yield a nonempty
range. Source edges qualify only when their adjacent sample is zero. This can
reduce boundary discontinuities but does not guarantee click-free output;
musical-tick trimming/slicing can move a boundary away from the exact crossing.
---
## Detect Attacks
Detect attacks uses absolute sample amplitude, an initial armed state, rearming
below one quarter of the threshold and a minimum frame gap between retained
attacks. It marks up to 128 source positions in orange; hovering the statistics
shows exact frame indices. This is a threshold detector, not spectral onset
detection, beat detection or tempo estimation. Selection/processing changes
invalidate the markers. Slice clip at attacks splits the current clip reference
at those positions in one project undo step and closes the editor. Edits in the
local buffer must be saved/relinked first if the slices should use processed
audio. Source positions round to nearest musical ticks; out-of-trim, edge and
coalesced cuts are skipped. No usable cuts rejects. Left ID, source references
and outside fades remain; inner explicit fades clear. Long explicit fades and
existing automatic region fades can sound different after splitting.
Timeline/source rounding may differ by one sample, so this is not
sample-accurate timeline slicing. The no-explicit-fade aligned regression
fixture remains bit-identical across slicing. No media files are written by
slicing.
---
## Validation and Timing Limits
Focused model and GUI checks pass for each operation. The integrated checks add
allocation failure/cleanup, oversized sources, overflow, clip ID rollback, exact
selected samples, persistence, no-fade render comparison, plugin fixtures,
software JACK, Clang analysis, ASan/UBSan and install layouts. The actual source
editor and attack markers are shown in the
[screenshot gallery](../screenshots/README.md).
Trim placement preserves alignment in musical ticks; independent source/timeline
conversion can differ by one sample. No sample-accurate timeline cuts or
click-free transitions are promised. Clip source data outside a local processing
selection remains intact; exported selections contain only their chosen frames.
Closing the editor discards unsaved local processing. Successful project Undo
keeps generated files for redo/history; only failed adoption removes its owned
new output. Rejecting sources above the editor's frame limit may temporarily use
the existing WAV reader's larger decode bound before rejecting them.