pub struct AudioEncoder { /* private fields */ }Expand description
Stateful deterministic PCM-S16 audio encoder.
Input is interleaved FP32. Complete configured packets are emitted by
encode; flush emits a final partial
packet. close deliberately discards an unflushed partial
packet, matching the donor lifecycle contract. Dropping the encoder only
releases host state and never flushes implicitly.
Implementations§
Source§impl AudioEncoder
impl AudioEncoder
Sourcepub fn new(profile: AudioEncodeProfile) -> Result<Self>
pub fn new(profile: AudioEncodeProfile) -> Result<Self>
Create one open encoder with a checked profile.
§Errors
Returns an error unless the profile has a nonzero sample rate, one to eight channels, a nonzero packet size, and an addressable packet shape.
Sourcepub fn encode(&mut self, interleaved: &[f32]) -> Result<Vec<EncodedAudioPacket>>
pub fn encode(&mut self, interleaved: &[f32]) -> Result<Vec<EncodedAudioPacket>>
Append complete interleaved frames and emit every full packet now ready.
§Errors
Returns an error when the encoder is closed, the input is empty or does not contain complete frames, buffered allocation fails, or timing exceeds the signed frame domain.
Sourcepub fn flush(&mut self) -> Result<Vec<EncodedAudioPacket>>
pub fn flush(&mut self) -> Result<Vec<EncodedAudioPacket>>
Emit the final partial packet, if any.
Calling flush on a closed encoder is idempotent and returns no packets.
§Errors
Returns an error when packet allocation fails or timing exceeds the signed frame domain.
Sourcepub fn profile(&self) -> Option<&AudioEncodeProfile>
pub fn profile(&self) -> Option<&AudioEncodeProfile>
Return the active profile, or None after close.
Sourcepub const fn codec_config(&self) -> &[u8] ⓘ
pub const fn codec_config(&self) -> &[u8] ⓘ
Return codec initialization bytes.
PCM-S16 has no codec configuration record.
Sourcepub const fn priming_frames(&self) -> u32
pub const fn priming_frames(&self) -> u32
Return encoder-delay frames.
PCM-S16 introduces no priming delay.