Skip to main content

Encoder

Struct Encoder 

Source
pub struct Encoder { /* private fields */ }
Expand description

A one-shot FLAC encoder, byte-identical to libFLAC 1.4.3 at the same settings.

Each encode* method takes the entire interleaved signal (channel-major within a sample — L R L R … for stereo, each value a sign-extended i32) and returns the encoded bytes.

use libflac_rs::{Encoder, EncoderConfig};

let enc = Encoder::new(EncoderConfig::new(2, 16, 44_100));
let pcm = vec![0i32; 4096 * 2]; // one block of stereo silence, interleaved
let flac = enc.encode(&pcm);    // a complete .flac file
assert_eq!(&flac[..4], b"fLaC");

Implementations§

Source§

impl Encoder

Source

pub fn new(config: EncoderConfig) -> Self

Create an encoder from config.

Source

pub fn config(&self) -> &EncoderConfig

The configuration this encoder was built with.

Source

pub fn encode_frames(&self, interleaved: &[i32]) -> Vec<u8>

Encode to raw FLAC frames — no fLaC marker or metadata — the byte stream MAME/CHD embeds. (The md5 setting has no effect here: MD5 lives in STREAMINFO, which raw frames omit.)

Source

pub fn encode(&self, interleaved: &[i32]) -> Vec<u8>

Encode to a complete .flac file (the fLaC marker, STREAMINFO, libFLAC’s default VORBIS_COMMENT, then the frames) — byte-identical to libFLAC’s default output. Use Encoder::encode_with_metadata to control the metadata.

Source

pub fn encode_with_metadata( &self, interleaved: &[i32], blocks: &[MetadataBlock<'_>], ) -> Vec<u8>

Encode to a complete .flac file with the given metadata blocks, written after STREAMINFO in order (the last automatically carries the end-of-metadata flag). To match libFLAC’s output, put a MetadataBlock::VorbisComment with LIBFLAC_VENDOR_STRING first. A MetadataBlock::Seektable is filled in during encoding.

Source

pub fn encode_ogg(&self, interleaved: &[i32], serial: i32) -> Vec<u8>

Encode to a complete Ogg FLAC stream with the given Ogg logical-bitstream serial number. libFLAC’s default VORBIS_COMMENT is included; any SEEKTABLE is dropped (as libFLAC does for Ogg).

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.