Skip to main content

OpusEncoder

Struct OpusEncoder 

Source
pub struct OpusEncoder {
    pub bitrate_bps: i32,
    pub complexity: i32,
    pub use_cbr: bool,
    pub use_inband_fec: bool,
    pub use_dtx: bool,
    pub packet_loss_perc: i32,
    pub force_bandwidth: Option<Bandwidth>,
    pub signal_type: Option<SignalType>,
    pub max_bandwidth: Bandwidth,
    pub lsb_depth: i32,
    pub mode_dwell: u32,
    /* private fields */
}
Expand description

An Opus encoder for one mono or stereo stream.

Create it with OpusEncoder::new, adjust the public fields (bitrate, complexity, CBR, FEC, DTX, …) as needed, then call OpusEncoder::encode once per frame. After the first few frames, encoding performs no heap allocation.

Fields§

§bitrate_bps: i32

Target bitrate in bits per second (default 64 000).

§complexity: i32

Computational complexity, 0 (fastest) to 10 (best quality).

§use_cbr: bool

Constant bitrate when true; variable bitrate (the default) when false.

§use_inband_fec: bool

Embed in-band forward error correction (SILK LBRR) so the next packet can recover a lost one; most useful with packet_loss_perc > 0.

§use_dtx: bool

Discontinuous transmission: after enough consecutive inactive frames, emit a 1-byte (TOC-only) packet so the decoder runs comfort-noise/PLC.

§packet_loss_perc: i32

Expected packet-loss percentage (0-100); raises robustness at some cost in quality.

§force_bandwidth: Option<Bandwidth>

Overrides automatic bandwidth selection when set (OPUS_SET_BANDWIDTH).

§signal_type: Option<SignalType>

OPUS_SET_SIGNAL: force the voice/music bias (None = auto from analysis).

§max_bandwidth: Bandwidth

OPUS_SET_MAX_BANDWIDTH: cap the automatically-selected bandwidth.

§lsb_depth: i32

Input bit depth assumed by the analysis noise floors. The float API default is 24; set 16 for s16-sourced content (opus_demo parity).

§mode_dwell: u32

Mode-dwell hysteresis: a proposed mode change must persist this many consecutive frames before it is committed. 1 = OFF and byte-identical; set via RUSTY_OPUS_MODE_DWELL.

Measured ineffective for the startup-mode defect it was built for and left default-off — see the refutation at its use site in encode.

Implementations§

Source§

impl OpusEncoder

Source

pub fn new( sampling_rate: i32, channels: usize, application: Application, ) -> Result<Self, Error>

§Errors

Error::BadArg if sampling_rate is not 8000, 12000, 16000, 24000 or 48000 Hz or channels is not 1 or 2; Error::Internal if the SILK encoder fails to initialise.

Source

pub fn enable_hybrid_mode(&mut self) -> Result<(), Error>

§Errors

Error::BadArg unless the encoder runs at 24 or 48 kHz, the only rates where hybrid (SILK + CELT) coding exists.

Source

pub fn final_range(&self) -> u32

Final range-coder state of the last encoded packet (libopus OPUS_GET_FINAL_RANGE). Stored in opus_demo .bit framing so the reference decoder can verify encoder/decoder range-coder agreement per packet.

Source

pub fn encode( &mut self, input: &[f32], frame_size: usize, output: &mut [u8], ) -> Result<usize, Error>

§Errors

Error::BadArg if frame_size is not a valid Opus frame duration (2.5–120 ms) at this sampling rate or for the selected mode; Error::BufferTooSmall if output cannot hold the packet; Error::Internal if a codec stage fails.

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.