pub(crate) struct Recording {
samples: Mutex<Vec<f32>>,
peak_bits: AtomicU32,
stop: AtomicBool,
truncated: AtomicBool,
}Expand description
What the recording thread and the handle share.
Fields§
§samples: Mutex<Vec<f32>>§peak_bits: AtomicU32Loudest absolute sample since the last read, as f32 bits.
Atomic so a caller drawing a level meter never blocks the
pusher.
stop: AtomicBool§truncated: AtomicBoolSet when the take stopped itself at the cap rather than because it was asked to.
Implementations§
Source§impl Recording
impl Recording
Sourcepub(crate) fn new(capacity: usize) -> Self
pub(crate) fn new(capacity: usize) -> Self
capacity is the cap in samples. Reserved up front so the buffer
never reallocates as a take grows.
Sourcepub(crate) fn push(&self, block: &[f32], limit: usize)
pub(crate) fn push(&self, block: &[f32], limit: usize)
Fold one block of audio in, keeping the running peak since the last read.
Mono at the model rate: a device’s channels are downmixed and resampled before they reach this buffer. MUST NOT ALLOCATE: the samples extend the preallocated buffer rather than an intermediate.
Sourcefn observe_peak(&self, block: &[f32])
fn observe_peak(&self, block: &[f32])
Fold the loudest absolute sample of block into the meter’s
accumulator. Peak over the RAW block, not any downmix: a meter
should show a channel clipping even when the mean of the
channels does not.
Sourcepub(crate) fn peak_dbfs(&self) -> f32
pub(crate) fn peak_dbfs(&self) -> f32
Loudest input since the last read, in dBFS. Take-and-reset: the read clears the accumulator, so a poller gets one window per ask.
pub(crate) fn stop(&self)
Sourcepub(crate) fn cap_reached(&self)
pub(crate) fn cap_reached(&self)
The take’s cap was reached by WALL CLOCK rather than by samples.
The sample cap fires only while audio is arriving, and a take fed by frames has no callback loop to notice it either: a stream that stops mid-take would hold the seat until teardown, so its host counts the clock and flags it here.
Sourcepub(crate) fn stopped(&self) -> bool
pub(crate) fn stopped(&self) -> bool
Whether the recording has been asked to stop - the cap reached itself, or the host ended the take. What a feeder polls before appending: a stream take’s frame sink, which has no thread to poll it for it.
Sourcepub(crate) fn sample_len(&self) -> usize
pub(crate) fn sample_len(&self) -> usize
Samples currently held. The append-only buffer keeps written ranges stable, so a segmenter can cut by offset while the callback keeps appending past them.
Sourcepub(crate) fn copy_region(&self, from: usize, to: usize) -> Vec<f32>
pub(crate) fn copy_region(&self, from: usize, to: usize) -> Vec<f32>
Copy [from..to) out without draining. The recording keeps the
whole take so finish can hand diagnostics the full capture, and
so an offset that raced a stop is a short copy, not a panic.
The lock is held for the memcpy only - long enough to be felt in
a callback budget if it happened every block, which it does not:
this runs once per window boundary, every 30 to 60 seconds.