AmbeEncoder

Struct AmbeEncoder 

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

Top-level D-STAR AMBE 3600×2400 encoder.

Owns one instance of every per-stream state object. Not thread-safe; construct one per concurrent voice stream.

§Usage

use mbelib_rs::AmbeEncoder;

let mut encoder = AmbeEncoder::new();
// Feed 160-sample (20 ms at 8 kHz) frames of f32 PCM in [-1.0, 1.0).
let pcm: [f32; 160] = [0.0; 160];
let ambe_frame: [u8; 9] = encoder.encode_frame(&pcm);

Implementations§

Source§

impl AmbeEncoder

Source

pub fn new() -> Self

Construct a fresh encoder using OP25’s single-frame (look-back + sub-multiples) pitch tracker. Zero added latency; each encode_frame call commits pitch for the just-received frame.

This is the backwards-compatible default. Real-voice inputs work well here because sub-multiples analysis resolves the common octave ambiguities; pure-sine synthetic tests can lose the 2P-vs-P disambiguation on settled tones. For the full OP25 pitch pipeline (2-frame look-ahead DP), see Self::new_with_lookahead — it costs 40 ms of latency and an extra 2-frame warmup but matches OP25’s pitch decisions on pure sines as well as voice.

Source

pub fn new_with_lookahead() -> Self

Construct a fresh encoder WITH the 2-frame look-ahead DP enabled. The first two encode_frame calls return AMBE_SILENCE while the pipeline fills; frame N-2’s pitch is committed on the third call (frame N). Adds ≈40 ms end-to-end latency; matches OP25’s pitch-tracking behaviour across pure sines and pitch transitions.

Source

pub fn encode_frame(&mut self, pcm: &[f32]) -> [u8; 9]

Encode one 20 ms PCM frame into a 9-byte AMBE wire frame.

  • pcm must contain at least 160 f32 samples in [-1.0, 1.0). Convert from i16 by dividing by 32768.0.
§Output

Returns a 9-byte D-STAR AMBE frame. Silent or near-silent input (pitch tracker confidence below SILENCE_CONFIDENCE) short-circuits to the canonical AMBE_SILENCE pattern that MMDVMHost and DVSI chips use for zero-audio frames, so silent stretches stay wire-compatible with conformant receivers.

§Panics

Never panics under normal use. The look-ahead pipeline’s internal invariant — self.pending is Some iff the encoder was built with Self::new_with_lookahead — is enforced at construction and never mutated afterwards; the unreachable expect is kept as a defensive check rather than removed entirely.

Source

pub fn encode_frame_i16(&mut self, pcm: &[i16]) -> [u8; 9]

Convenience: encode from i16 PCM. Divides by 32768.0 first.

Trait Implementations§

Source§

impl Debug for AmbeEncoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AmbeEncoder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.