pub struct SimpleVorbisEncoder { /* private fields */ }Expand description
A simple Vorbis encoder that accepts interleaved f32 PCM and emits raw Ogg Vorbis payload bytes.
The first call to SimpleVorbisEncoder::encode_pcm prepends the three
mandatory Vorbis header packets so the output is a self-contained stream.
§Example
ⓘ
use oximedia_codec::vorbis::{SimpleVorbisEncoder, VorbisEncConfig};
let cfg = VorbisEncConfig {
sample_rate: 44100,
channels: 2,
quality: 0.5,
};
let mut enc = SimpleVorbisEncoder::new(cfg)?;
let pcm = vec![0.0f32; 4096]; // 2048 stereo frames
let payload = enc.encode_pcm(&pcm)?;
assert!(!payload.is_empty());Implementations§
Source§impl SimpleVorbisEncoder
impl SimpleVorbisEncoder
Sourcepub fn new(config: VorbisEncConfig) -> CodecResult<Self>
pub fn new(config: VorbisEncConfig) -> CodecResult<Self>
Create a new encoder.
§Errors
Returns CodecError::InvalidParameter if sample_rate or channels
are out of the valid range (see VorbisEncoder).
Sourcepub fn encode_pcm(&mut self, samples: &[f32]) -> CodecResult<Vec<u8>>
pub fn encode_pcm(&mut self, samples: &[f32]) -> CodecResult<Vec<u8>>
Encode interleaved f32 PCM samples (range [−1, +1]).
On the first call the three Vorbis header packets are prepended so the returned bytes form a complete, decodable stream. Subsequent calls return only audio packets.
§Errors
Returns CodecError::InvalidParameter if samples.len() is not a
multiple of the channel count.
Auto Trait Implementations§
impl Freeze for SimpleVorbisEncoder
impl RefUnwindSafe for SimpleVorbisEncoder
impl Send for SimpleVorbisEncoder
impl Sync for SimpleVorbisEncoder
impl Unpin for SimpleVorbisEncoder
impl UnsafeUnpin for SimpleVorbisEncoder
impl UnwindSafe for SimpleVorbisEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more