AUDIO
Source snapshot · 11 November 2026

API reference / ravet_audio_file

Crate ravet_audio_file 

Expand description

Bounded WAV/AIFF stream I/O on control/worker threads and prepared audio handoff. No file methods belong in an audio callback. Ring push/pop and prepared transport use storage without allocation, deallocation, blocking or I/O. Memory playback renders a prepared clip without file I/O or implicit rate conversion.

Structs§

AiffFormat
AIFF metadata; 1..64 channels and integer sample rates 1..768000 Hz.
AiffReadAhead
Worker-owned AIFF read-ahead with retained suffixes under ring backpressure. Requires matching channels and 1..65,536 scratch frames within reader capacity. Pump/seek perform file I/O outside callbacks; only prepared consumer pop or BufferedPlayback rendering belongs in audio. No rate conversion is implicit. Wrap in ReadAheadWorker for explicit automatic worker/transport ownership.
AiffReader
Prepared interleaved f32 reader over a seekable uncompressed AIFF stream. Unknown chunks are skipped within FORM (at most 4096 chunks). COMM/SSND must be unique and consistent; zero frames may omit SSND. Its offset is honored but nonzero blockSize rejects. Trailing bytes outside FORM are ignored. No metadata/loop markers are exposed.
AiffRecorder
AIFF PCM16/24/32 recorder draining a prepared input ring on a worker. Preparation writes a header to a caller-selected empty seekable sink. Capture callbacks only push frames. A dequeued write failure poisons the recorder; accepted/output prefixes cannot be rolled back. Drop never finalizes or drains. No physical device, path, worker thread, rate conversion or clock is selected.
AiffWriter
Bounded uncompressed AIFF writer. Destination must initially be empty. Call finish explicitly to patch counts/sizes; Drop performs no I/O. Partial I/O failures poison the writer; discard the partial file.
AudioConsumer
Unique consumer. Only one thread may pop; teardown follows callback stop.
AudioProducer
Unique producer. Only one thread may push; teardown follows callback stop.
BufferedPlayback
Prepared consumer transport. Render/play/pause perform no heap, lock or I/O. Queue-source position advances only for consumed frames; underruns stall it. Paused renders do not consume the ring. Output always fills with audio plus silence. The endpoint itself provides no device clock, rate conversion, crossfade, looping or live seek. A worker can explicitly convert into its queue rate. Serialize commands with this exclusive endpoint on its owning audio thread; destruction follows callback shutdown. Worker status snapshots may change concurrently. A stopped seek belongs to the control owner with this endpoint reclaimed after callback stop, never inside render.
BufferedPlaybackProgress
Bounded source consumption; zero output suffixes do not advance the cursor.
CompressedReadAhead
Owned compressed worker pump. Prepare 1..65536 scratch frames and matching channel ring. No thread/clock/device is created. Decode/seek and destruction may allocate and must stay outside audio; only consumer pop is callback-safe. Pending decoded scratch retains unqueued suffixes under backpressure.
CompressedReader
Lazy decoded single-default-track FLAC/MP3/Vorbis reader. Requires compressed. Encoded input is copied once (1..64 MiB); decoded frames are capped by caller 1..16,777,216 and total interleaved samples <=16,777,216. Decoded packet capacity <=65536 frames, channels 1..64/rate 1..768000. Backend allocations remain its own contract. No file/network I/O, resampling, speaker remapping or callback use. Gapless trims apply; EOF checks declared duration/decoder integrity. Changing configurations/chained resets reject. The default constructor uses replay seeks. new_indexed_flac instead verifies the whole native FLAC stream once and retains a bounded compressed-packet index; both modes swap seek candidates only on success.
ConvertedReadAhead
Explicit converted output queue plus a caller-selected fresh-reader factory. Original input coordinates are exposed separately. Exact stopped seek replays a fresh candidate in output coordinates and adopts only after success. No callback waits, whole PCM clip, device clock or cross-thread mailbox is added. Source/backend version stability is the factory caller’s responsibility; fixed metadata does not authenticate content. Retained Sinc output count is floor((N+taps-2)*output_rate/input_rate)+1, including its fractional delay.
ConvertedReadAheadCounts
Original file and converted queue coordinates are deliberately distinct.
ConvertedReadAheadFailure
Failure-owned preparation: reader, fresh-reader factory and producer survive. Preparation performs no reader read/seek or factory call.
ConvertedReadAheadOptions
Explicit worker profile, validated before source reads or factory calls. Copy/floating Sinc duration is capped at 16,777,216 original frames. Explicit IntegerSinc permits caller usize source bounds with checked retained duration at most u64::MAX-65536, leaving largest automatic callback terminal headroom. Reader/container limits remain separate; source/conversion batches are 1..4096. Source/converter/output arrays are capped at 32MiB. Encoded readers and the separately prepared queue retain their own limits. Copy requires equal rates; Sinc retains causal (taps-1)/2 source-sample delay and finite tail, with even 16..256 taps and ratio 1/16..16.
ConvertedReadAheadProgress
DecodedClip
Complete finite interleaved f32 clip at its encoded rate/channel order. No implicit resampling, channel mapping or amplitude normalization is applied.
FilePlaybackFailure
Original reader/error with exact committed progress and incomplete output. Reader logical/underlying byte position may have advanced; no seek rollback or complete playable clip is promised by this failure-owned prefix.
FilePlaybackInfo
Immutable complete preparation metadata. Player cursors/loops use output frames. Nominal duration and retained filter delay/tail are distinct.
FilePlaybackOptions
Caller-selected budgets and target. No defaults select hidden conversion.
FilePlaybackProgress
Counts committed before success/failure. Reads can advance before an error; submissions and prepared output can lag those committed reader frames.
FlacFormat
Explicit FLAC channel order/encoded rate. This wrapper supports channels 1..8 and integer sample rates 1..96000. It adds no speaker-position metadata.
FlacRecorder
Worker-owned incremental FLAC capture sink fed by a prepared f32 audio ring. Audio callbacks only publish; pump quantizes/encodes/writes on its caller. Any failure after dequeue poisons because accepted ring frames cannot roll back. Producer full-ring drops remain producer policy. Drop does not finalize. No hidden worker, path/device/clock choice or physical recording claim.
FlacWriter
Optional incremental PCM16/24 FLAC writer for an empty seekable destination. Accepts at most 65536 whole interleaved frames per write and retains only one 4096-frame pending block, one backend frame buffer and one serialized frame. Backend working allocations remain its contract; all methods are worker-only. Invalid input preserves prior state/output. Encoding/I/O/capacity failure after acceptance poisons the writer; output may contain an irreversible prefix. Finish emits the sole short final block, rewrites STREAMINFO count/MD5/frame sizes and flushes before returning ownership. Drop does not finalize; partial files are not complete recordings. No float quantization, path/thread/device policy, implicit file truncation or physical recording/deadline claim.
ImpulseResponseFileError
Whole-call refusal with the committed source frames observed.
ImpulseResponseFileOptions
Explicit source bounds for prepare_impulse_response_file.
IndexedConvertedReadAhead
Explicit known-duration indexed PCM transport using IntegerSinc only. Each stopped candidate reads at most the taps-sized source window, plus an EOF probe when needed. The factory owns version stability and metadata parsing; skipped content is not authenticated. No compressed reader/deadline is implied. Temporary window scratch is at most 66KiB in addition to existing bounded state.
IndexedReadAheadCounts
Per-generation output work, original cursor movement and priming window work. Skipped prefixes are never labelled decoded or submitted source frames.
IndexedSeekFailure
Original seek/decode error plus the failed fresh reader, when one was created. Its cursor can have advanced; no restoration or hidden retry occurs.
IndexedSeekReceipt
Window work and mathematical priming are distinct from decoded file prefixes.
MemoryPlayback
Owned interleaved f32 clip with a sample-counted transport. Preparation copies 1..=16,777,216 finite samples (at most 64 MiB), validates 1..64 channels, 1..768,000 Hz metadata and 1..65,536 maximum render frames. Empty clips reject. All subsequent operations are bounded, allocation-free, exclusively borrowed and perform no I/O. Drop frees the owned clip off audio.
Mp3Failure
A failed constructor/finalization still owns its partial sink and first error. Counts distinguish accepted source frames, final file-region bytes and actual sink writes, including the rewritten first frame. No automatic restore/retry/finalization.
Mp3Format
Caller-selected supported CBR, highest quality, MPEG1 file profile. Mono/stereo at exactly 32 kHz, 44.1 kHz or 48 kHz; no hidden resampling/channel remap/ID3/VBR.
Mp3RecordingExit
Explicit complete or incomplete worker outcome, with reclaimed sink/source. An Ok controller result alone does not prove a complete recording: inspect completion(). Irreversible output prefixes are retained on faults.
Mp3RecordingWorker
Prepared-ring automatic MP3 owner. The encoder is constructed, pumped, explicitly finalized and dropped on one named worker. Capture keeps its unique prepared producer; callback push adds no heap, lock, I/O or implicit backpressure. Pause acknowledges quiescence after the active batch and I/O. Control operations, join and Drop may block indefinitely on caller sink I/O. Drop requests abort and joins; it never drains, rewrites metadata or flushes. Sink destructors retain their own contract. Worker panic loses unwound owners. An outer Ok proves recovery only; inspect Mp3RecordingExit::completion before treating the destination as complete. Writer format, source, metadata, physical-write budgets and independent LGPL requirements remain applicable. No physical device, perceptual, resampling or callback deadline claim.
Mp3Writer
Worker-only seekable MP3 writer. New validates a fresh region at current EOF; callers own truncation/concurrent access. All sample-call preflight precedes codec mutation. Explicit finish flushes codec, validates Info/LAME gapless counts, replaces reserved first frame, restores end and flushes destination. Completed files have exact source-frame metadata; gapless-aware file decoders honor it, whereas arbitrary stream players may retain padding. Drop/abort do not write/seek/flush. Sink destructor is caller policy. Backend working memory remains backend-owned, no total-memory or real-time deadline claim.
PlaybackProgress
Progress counts source frames; paused/end silence does not advance position.
PreparedFilePlayback
Owned complete output-rate clip plus explicit source/delay/tail metadata. No reader/converter remains in the callback player. Existing pause/seek/loop operates in prepared output frames; boundaries can click. No live buffered conversion, drift correction or physical-device validation is implied.
ReadAheadExit
Reclaimed stopped source and any original worker pump error.
ReadAheadProgress
Progress from one bounded read-ahead pump. EOF means the reader is exhausted; pending and queued audio may still need playback after EOF becomes true. One bounded pump in queue-source coordinates at ReadAheadPump::sample_rate. Native readers count original frames; explicit converted sources count generated output frames and expose original input progress separately.
ReadAheadWorker
Control-owned automatic worker. Explicit start starts a named thread; a full ring parks the worker with a 2 ms timeout before retrying, without callback-side wake calls. Pump working allocations/I/O remain source-specific. Control stop/seek/ shutdown/Drop can block while joining and must never run in audio callbacks. Stop is cooperative between bounded pump calls; it does not cancel active file I/O and cannot guarantee a join deadline. Worker panic reports Failed, loses the unwound source and causes control reclamation to return Poisoned. The transfer mutex is used only during startup/exit/control operations; pumping and callback rendering never take it. Thread creation failure retains the pump. Callback positions require the source’s sample rate; no clock is created.
RecordingExit
Reclaimed recorder and original worker error; both belong outside callbacks.
RecordingWorker
Control-owned bounded automatic recording pump. new validates the matching prepared producer and retains the recorder; start creates a named worker. Capture callbacks keep their unique AudioProducer and only call prepared push. Full-ring overload remains explicit accepted-prefix/caller-drop policy; no hidden allocation, blocking backpressure, device/path/clock choice occurs. Pump allocations, encoding and I/O belong to the worker. Stop/join/finish/Drop belong to control after capture shutdown; cooperative stop does not cancel active I/O or guarantee a join deadline. Dropping the owner joins but never drains/finalizes. A panicked worker loses its unwound recorder and reports Failed/Poisoned, never successful finalization.
VorbisFormat
Explicit mono (8000..96000 Hz) or stereo (16000..96000 Hz) Vorbis I channel order, perceptual quality and Ogg logical-stream serial. Quality is finite -0.2..=1; no random serial is chosen.
VorbisRecordingExit
Explicit complete or incomplete worker outcome, with reclaimed sink/source. An Ok controller result alone does not prove a complete recording: inspect completion(). Irreversible output prefixes are retained on faults.
VorbisRecordingWorker
Prepared-ring automatic owner for the genuinely !Send Vorbis codec. Only transferable preparation/results cross threads; initialize/pump/EOS/abort/ codec Drop stay on one named worker. Capture retains its unique prepared producer; callback push adds no heap, lock, I/O or implicit backpressure. Pause waits for the active worker batch/I/O, then acknowledges no more queue consumption until resume/finalize. Control operations, join and Drop can block indefinitely on caller sink I/O; they have no cancellation/deadline guarantee. Drop requests gated abort and joins, never EOS/flush. Sink destructors retain their own contract. Worker panic loses unwound sink/source and reports Failed. No physical device, perceptual, clock/resampling or callback deadline claim.
VorbisWriter
Incremental lossy Ogg Vorbis writer. Construct/use/finish/drop on one worker; the safe backend is not Send/Sync. All codec/sink methods can allocate/block and belong outside callbacks. Interleaved finite [-1,1] input is explicitly rejected on overload; no clipping, rate conversion, device/clock/path policy. Wrapper retains prepared 4096-frame planar scratch and one physical Ogg page (at most 65307 bytes). Backend working storage remains its contract. Each write accepts at most 65536 complete frames. Headers and the priming packet must terminate within a physical page; continued headers, mixed header/audio pages and spanning priming packets reject rather than guessing timestamps. Whole-call preflight failures preserve state; encoding/I/O/output-capacity failure after acceptance poisons and may leave an irreversible encoded prefix. Sink receives no framework writes/flushes from Drop, including after failure. Caller-provided sink Drop remains its own contract. Only explicit nonempty finish writes EOS, flushes and returns the sink; a failed finish consumes it. No exact PCM/perceptual-quality/deadline claim. Automatic prepared capture uses crate::VorbisRecordingWorker, which creates this codec locally.
WaveFormat
WaveReadAhead
Worker-owned WAV read-ahead with retained unqueued samples under backpressure. Prepare 1..=65,536 scratch frames no greater than the reader’s own capacity. Calls perform seek/read I/O and must never run on an audio callback.
WaveReader
Prepared bounded interleaved f32 decoder over a seekable WAV stream. File operations block. Unknown chunks are skipped within declared RIFF size; duplicate fmt/data chunks, truncation and inconsistent byte rates reject.
WaveRecorder
Worker-owned recording sink for an input ring, with explicit finalization. Device callbacks only publish to the producer; pump performs file I/O here. No thread, physical device, file path or recording permission is chosen.
WaveWriter
Bounded interleaved WAV recorder on a control/worker thread. Output must initially be empty. Call finish explicitly to patch sizes; Drop never performs file I/O. An I/O failure poisons further writing/finalization.

Enums§

AiffEncoding
Supported signed, big-endian PCM widths. AIFF-C is not supported.
AudioFileError
FlacCapturePolicy
Explicit normalized f32 capture policy before signed PCM16/24 quantization. Finite samples round to nearest integer, ties away from zero, without dither. -1 maps to the signed minimum and +1 to the signed maximum. Nonfinite input always rejects. This policy applies to a complete dequeued worker batch.
FlacPcmEncoding
Lossless signed integer precision; no implicit float quantization.
ImpulseResponseFileErrorKind
Why file preparation stopped. Reads may have advanced the reader.
Mp3Bitrate
Explicit supported constant bit rate. The pinned backend 192 kbps preset applies a 0.97 input scale; 256/320 presets use 1.0. RAVET adds no compensation.
Mp3RecordingCompletion
Mutually exclusive completion evidence carried by a worker-constructed exit. Failed retains the first original startup/pump/drain/metadata rewrite/flush error.
Mp3RecordingStatus
Diagnostic lifecycle; only a finalized exit proves metadata rewrite and successful flush.
Mp3WriteError
Call preflight rejects without codec mutation; operational failure poisons and borrows the retained original error, recoverable with the sink at finish.
PlaybackConversion
Explicit same-rate copy or causal sinc filtering; no implicit bypass.
PlaybackError
Invalid preparation, position, loop or render shape; rejection preserves transport state. Render rejection silences the complete supplied buffer.
ReadAheadStatus
Snapshot of worker progress. EOF denotes all pending frames published; audible EOF additionally requires the callback ring to drain.
RecordingStatus
Worker running/drain ownership is distinct from finalized-file success.
RingError
VorbisRecordingCompletion
Mutually exclusive completion evidence carried by a worker-constructed exit. Failed retains the first original startup/pump/drain/EOS/flush error.
VorbisRecordingStatus
Diagnostic lifecycle; only a finalized exit proves EOS and successful flush.
WaveEncoding
Supported little-endian RIFF encodings; extensible/RF64/W64 are not supported.

Traits§

IndexedPlaybackReader
Explicit indexed original-frame positioning for known-duration PCM readers. Implementations report stable known duration and exact original coordinates. Seek/read work belongs off audio. Successful seek sets exactly the requested logical frame; failure exposes its actual committed position and original error. This does not promise a filesystem deadline or authenticate skipped regions. WAV/AIFF defer physical seeking to their next read. No compressed impl exists.
PlaybackReader
A stable metadata/committed-frame interface for control/worker file preparation. Metadata getters must not read/seek. Successful reads advance position by exactly the returned complete frames; errors expose their actual committed frame position, which can have advanced. No rollback is implied. A zero read means validated EOF; compressed implementations must retain gapless trimming. Implementations own their original I/O/codec errors and source bounds.
ReadAheadPump
Worker-only queue source for an automatic read-ahead owner. All cursors, seek targets and ReadAheadProgress frame counts use this source queue’s sample rate. Native readers publish original-rate frames; explicit converted sources publish output-rate frames and expose original input coordinates separately. Implementations must preserve queued/pending/cursor state on failed stopped seeks, and must publish only complete frames to their unique producer. Pump calls must be bounded; worker backend allocations and I/O remain explicit.
RecordingPump
Worker-only incremental recorder contract for an automatic owner. Each pump must drain at most prepared scratch capacity and perform no work when empty. Any failure after dequeue must poison subsequent source calls. Finalization requires the matching producer stopped and performs a bounded remaining-ring drain followed by explicit file/codec finalization.

Functions§

audio_ring
Prepare an SPSC interleaved f32 ring, channels 1..64 and power-of-two capacity 1..65536 frames. Frame counters wrap safely because capacity is a power of two. Endpoints cannot be cloned; transfers use atomic publication, no locks/I/O. Dropping endpoints can deallocate and belongs after audio callbacks stop.
decode_compressed
Decode the single default audio track from explicitly supplied encoded bytes. Requires the optional compressed feature (pinned Symphonia). Input is copied and limited to 64 MiB; output is limited by caller frames and 16,777,216 samples (64 MiB), channels 1..64 and integer rates 1..768000. At most 1,048,576 packets are processed; decoded packet capacity is limited to 65536 frames. Backend metadata/visual limits are 64 KiB/0; decoder internal allocations remain backend-owned, not a total-memory or deadline guarantee. Gapless trims are enabled. Decode errors, nonfinite samples, changing audio configuration and chained stream resets reject the entire clip. No partial output is returned, no encoder/network/file I/O occurs and no audio callback use is permitted. Metadata and channel speaker positions are not exposed.
encode_flac
Encode a complete nonempty interleaved signed-PCM clip to owned FLAC bytes. Requires optional flac-encode (pinned Apache-2.0 flacenc, default features disabled). 1..4,194,304 input i32 samples (16 MiB), valid whole frames and precision ranges are checked before backend block copying/encoding. Encoded output is limited to 64 MiB through the incremental writer’s per-frame preflight. Fixed 4096-frame single-thread encoding with constant/verbatim fallback for excessive prediction sizes; backend allocations remain its own contract. No float conversion/clipping, implicit threads, file/network I/O or callback use. This is a complete-clip encoder, not a streaming recorder.
encode_mp3
Encode a complete supported finite clip; same worker-only/gapless-file limits.
encode_vorbis
Encode a nonempty complete interleaved finite [-1,1] mono/stereo clip. Input <=4194304 f32 samples and output <=64MiB; lossy worker-only Vorbis encoding. Explicit format/quality/serial, no implicit RNG/thread/path/rate/device policy.
prepare_file_playback
Prepare from frame zero using explicit source/target budgets, off audio. Bounds/configuration/known duration reject before any source reads; unknown duration uses the caller’s maximum source bound for output-capacity preflight. Sinc retains exactly (taps-1)/2 source-sample delay. For N source frames the T-tap causal history has support through source coordinate N+T-2, so retained output length is floor((N+T-2)output/input)+1. Nominal duration remains ceil(Noutput/input). At most T explicit zero frames flush that support, including one numeric boundary guard; actual padding progress is reported. Fixed ratios1/16..16 and the existing 1025-phase Blackman profile apply. No output rate, bypass, gain, delay compensation or decoder trimming is implicit.
prepare_impulse_response_file
Read a complete WAV/AIFF/compressed response through PlaybackReader at its source rate and prepare it with ravet_signal::prepare_impulse_response.