Struct Mp3Writer
pub struct Mp3Writer<W: Write + Seek> { /* private fields */ }Expand description
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.
use ravet_audio_file::{Mp3Bitrate, Mp3Format, Mp3Writer};
use std::io::Cursor;
let format = Mp3Format {channels: 2, sample_rate: 48000,
bit_rate: Mp3Bitrate::Kbps256};
let mut writer = Mp3Writer::new(Cursor::new(Vec::new()), format, 17, 65536).unwrap();
writer.write_samples(&[0.25_f32; 34]).unwrap();
let complete = writer.finish().unwrap().into_inner();
assert!(!complete.is_empty());Implementations§
§impl<W: Write + Seek> Mp3Writer<W>
impl<W: Write + Seek> Mp3Writer<W>
pub fn new( destination: W, format: Mp3Format, maximum_frames: u64, maximum_written_bytes: u64, ) -> Result<Self, Mp3Failure<W>>
pub fn format(&self) -> Mp3Format
pub fn accepted_frames(&self) -> u64
pub fn file_bytes(&self) -> u64
pub fn written_bytes(&self) -> u64
pub fn failure(&self) -> Option<&Error>
pub fn write_samples( &mut self, samples: &[f32], ) -> Result<usize, Mp3WriteError<'_>>
pub fn finish(self) -> Result<W, Mp3Failure<W>>
pub fn finish(self) -> Result<W, Mp3Failure<W>>
Explicitly finalize or return partial sink with retained original error.
pub fn abort(self) -> W
pub fn abort(self) -> W
Recover incomplete destination without codec finalization or sink I/O. This convenience abort discards stored error/counts; inspect getters first or finish a poisoned writer to recover original diagnostics without I/O.