Skip to main content

Encoder

Struct Encoder 

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

A safe wrapper around the glint MP3 encoder.

Implementations§

Source§

impl Encoder

Source

pub fn new( sample_rate: u32, channels: u32, bitrate: u32, ) -> Result<Self, &'static str>

Create a new MP3 encoder.

Returns an error if the configuration is invalid (e.g. unsupported sample rate or bitrate).

Source

pub fn with_options( sample_rate: u32, channels: u32, bitrate: u32, mode: u32, quality: u32, path: u32, vbr_quality: Option<u32>, ) -> Result<Self, &'static str>

Create an MP3 encoder with explicit knobs. mode: 0 mono, 1 dual, 2 joint, 3 stereo. quality: 0 speed / 1 normal / 2 best. path: 0 default, 1 double, 2 fixed. vbr_quality Some(0..9) selects VBR.

Source

pub fn samples_per_frame(&self) -> usize

Number of samples per channel expected by each call to encode.

Source

pub fn channels(&self) -> usize

Number of channels this encoder was configured with.

Source

pub fn encode(&mut self, pcm: &[i16]) -> Vec<u8> ⓘ

Encode one frame of interleaved 16-bit PCM audio.

pcm should contain samples_per_frame * channels samples in interleaved order. If fewer samples are provided, the remainder is zero-padded.

Source

pub fn encode_float(&mut self, pcm: &[f32]) -> Vec<u8> ⓘ

Encode one frame of interleaved 32-bit float PCM audio.

Samples should be in the range [-1.0, 1.0]. Layout is the same as encode.

Source

pub fn flush(&mut self) -> Vec<u8> ⓘ

Flush the encoder, returning any remaining MP3 data.

Trait Implementations§

Source§

impl Drop for Encoder

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

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

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Encoder

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.