pub(crate) fn decode_to_mp3(
frames: &[[u8; 9]],
bitrate: u32,
) -> Result<Vec<u8>, DecodeError>Expand description
Decodes a sequence of 9-byte AMBE voice frames into an MP3 byte buffer.
§Pipeline
- Creates an
mbelib_rs::AmbeDecoder(one per call — stateful across frames within the same stream). - Feeds each 9-byte AMBE frame through the decoder, collecting the
resulting 160-sample PCM chunks into a contiguous
Vec<i16>. - Configures a LAME MP3 encoder for mono 8000 Hz CBR at
bitratekbps. - Encodes the entire PCM buffer in one pass, then flushes to finalize the MP3 stream.
§Arguments
frames— Ordered slice of 9-byte AMBE frames from a single D-STAR voice stream. Must be in receive order (the decoder uses inter-frame delta prediction).bitrate— MP3 constant bitrate in kbps. Must match one of the LAMEBitrateenum values (8, 16, 24, 32, 40, 48, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320).
§Errors
DecodeError::EmptyInputifframesis empty.DecodeError::UnsupportedBitrateifbitrateis not a valid LAME value.DecodeError::EncoderInitif LAME fails to initialize.DecodeError::Encodeif LAME fails during encoding or flushing.