pub struct Mp3Encoder { /* private fields */ }Expand description
Stream-level MP3 encoder: accumulates per-channel PCM, emits one MP3 frame per
1152 samples per channel (576 for MPEG-2/2.5). MPEG-1/2/2.5, CBR or VBR,
psychoacoustic noise shaping; mono, stereo, or per-frame mid/side joint
stereo. Configured via Mp3EncoderConfig.
Push PCM with push_pcm_f32 /
push_pcm_s16 (the first push fixes the header
from the sample rate + channel count), drain with
next_packet, and call
finish at end of input (tail padding, reservoir
assembly, Xing/Info header).
Implementations§
Source§impl Mp3Encoder
impl Mp3Encoder
pub fn new(config: Mp3EncoderConfig) -> Mp3Encoder
Sourcepub fn push_pcm_f32(
&mut self,
interleaved: &[f32],
channels: u16,
sample_rate: u32,
) -> Result<()>
pub fn push_pcm_f32( &mut self, interleaved: &[f32], channels: u16, sample_rate: u32, ) -> Result<()>
Push interleaved f32 PCM in [-1, 1]. The first push fixes the frame
header (MPEG version from sample_rate, mono/stereo from channels);
if a later push carries fewer channels than the header, the last input
channel is replicated. interleaved.len() should be a multiple of
channels (a trailing partial sample is ignored).
Sourcepub fn push_pcm_s16(
&mut self,
interleaved: &[i16],
channels: u16,
sample_rate: u32,
) -> Result<()>
pub fn push_pcm_s16( &mut self, interleaved: &[i16], channels: u16, sample_rate: u32, ) -> Result<()>
Push interleaved signed-16-bit PCM. Converts i16 / 32768.0 — the same
convention the decoder uses — then follows
push_pcm_f32.
Sourcepub fn next_packet(&mut self) -> Result<Vec<u8>>
pub fn next_packet(&mut self) -> Result<Vec<u8>>
Pull the next encoded MP3 packet (one frame, or the prepended Xing/Info
frame after finish). Err(Again) = feed more
PCM; Err(Eof) = finished and fully drained.
Sourcepub fn finish(&mut self)
pub fn finish(&mut self)
End of input: pad the PCM tail to a whole frame, assemble the bit
reservoir stream (CBR V1), and prepend the Xing/Info header. After this,
next_packet drains to Err(Eof).