Portable sine instrument¶
SineInstrument<N> connects voice ownership, chosen-side negotiation and linear
ADSR to a no-input mono/stereo f32 processor. The additive SineInstrument64<N>
facade uses the same render kernel with actual f64 output, without an intermediate
f32 sample buffer; existing SineInstrument::new inference and scalar behavior
remain unchanged. Both expose CONTROL Level schema/setter and last-program request
observation. Prepare a finite positive sample rate with ADSR counts fitting u32, at most 65,536
frames and 1,024 events, with no auxiliary/output-event buses. Complete block
validation precedes every event/state change; faults silence active outputs.
Zero-frame events apply without advancing phase/envelopes. New or stolen notes
reset phase/envelope; live pitch bend retunes while retaining phase. Sustain
holds the envelope; released voices finish after their 50 ms release and return
the slot. The fixed envelope uses 5 ms attack, 10 ms decay and 0.8 sustain.
Mix level has stable ID INSTRUMENT_LEVEL_ID (1), defaults to 0.2 and clamps to
0..1. Mix is scaled by level/N; stereo duplicates mono. Normalized portable note
velocities quantize to seven bits (positive values produce at least one); MIDI
messages preserve raw velocity. Master/member bend adds before frequency
conversion, clamped to 49% of sample rate. Pressure/timbre snapshots do not
modulate the sine. Unknown parameters and transport are ignored. Held/sustained
notes can sound indefinitely, so declared tail is infinite. Reset/reprepare
clear voices/history while retaining requested level and negotiated zone/ranges.
Processing/reset use no heap, blocking or I/O. Drop/deactivate/prepare require stopped callback ownership. This is a portable reference; no editor, complete state codec, plug-in instrument adapter, device deadline, click-free stealing or bandlimited waveform bank is claimed. The separate native/AAX MidiSine reference composes the portable instrument explicitly. The executable example renders a synthetic timed note and release into memory without opening a device:
CARGO_BUILD_JOBS=2 cargo run -p ravet-instrument --example synthesis --locked
Tests compare attack samples against an independent sine/ramp formula, prove identical split-block output, complete release/sustain/stealing, rejected-block state preservation, stereo tails and 10,000 heap-free synthesis workloads. See decision 0039.