AUDIO
Source snapshot · 11 November 2026

API reference / ravet_audio_file::VorbisWriter

Struct VorbisWriter 

pub struct VorbisWriter<W: Write> { /* private fields */ }
Expand description

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.

use ravet_audio_file::{VorbisFormat, VorbisWriter};
let writer = VorbisWriter::new(Vec::new(), VorbisFormat {
    channels: 1, sample_rate: 48000, quality: 0.5, stream_serial: 1,
}, 4096, 65536).unwrap();
std::thread::spawn(move || drop(writer));

Implementations§

§

impl<W: Write> VorbisWriter<W>

pub fn new( destination: W, format: VorbisFormat, maximum_frames: u64, maximum_bytes: u64, ) -> Result<Self, Error>

Validate mono 8000..96000/stereo 16000..96000 Hz, finite quality -0.2..1, total frames 1..16777216 and output bytes 1..67108864 before preparation/header output. Writes start at the caller’s current sink position; no seek/truncate occurs. Header I/O/capacity errors may leave a partial prefix and consume the sink. Caller serial identifies one logical stream; chaining/multiplexing requires distinct caller-selected serials and is outside this writer’s contract.

pub fn format(&self) -> VorbisFormat

pub fn accepted_frames(&self) -> u64

Submitted frames, including a failing accepted codec batch. Not finalized.

pub fn written_bytes(&self) -> u64

Bytes actually accepted by the sink, including any failed partial write.

pub fn is_poisoned(&self) -> bool

pub fn write_frames(&mut self, samples: &[f32]) -> Result<(), Error>

Validate shape/finite [-1,1]/per-call and total bounds before acceptance. Empty input is a no-op; it does not signal encoder EOS. Backend batches stay at most 4096 frames regardless of call size.

pub fn finish(self) -> Result<W, Error>

Explicit nonempty EOS and sink flush. Failure consumes the destination, with no complete-file/retry/rollback guarantee. Drop never finishes it.

Trait Implementations§

§

impl<W: Write> Drop for VorbisWriter<W>

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

fn pin_drop(self: Pin<&mut Self>)

Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<W> !RefUnwindSafe for VorbisWriter<W>

§

impl<W> !Send for VorbisWriter<W>

§

impl<W> !Sync for VorbisWriter<W>

§

impl<W> !UnwindSafe for VorbisWriter<W>

§

impl<W> Freeze for VorbisWriter<W>

§

impl<W> Unpin for VorbisWriter<W>

§

impl<W> UnsafeUnpin for VorbisWriter<W>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.