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
impl Encoder
Sourcepub fn new(config: EncoderConfig) -> Self
pub fn new(config: EncoderConfig) -> Self
Create an encoder from config.
Sourcepub fn config(&self) -> &EncoderConfig
pub fn config(&self) -> &EncoderConfig
The configuration this encoder was built with.
Sourcepub fn encode_frames(&self, interleaved: &[i32]) -> Vec<u8> ⓘ
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.)
Sourcepub fn encode(&self, interleaved: &[i32]) -> Vec<u8> ⓘ
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.
Sourcepub fn encode_with_metadata(
&self,
interleaved: &[i32],
blocks: &[MetadataBlock<'_>],
) -> Vec<u8> ⓘ
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.