decode_to_mp3

Function decode_to_mp3 

Source
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

  1. Creates an mbelib_rs::AmbeDecoder (one per call — stateful across frames within the same stream).
  2. Feeds each 9-byte AMBE frame through the decoder, collecting the resulting 160-sample PCM chunks into a contiguous Vec<i16>.
  3. Configures a LAME MP3 encoder for mono 8000 Hz CBR at bitrate kbps.
  4. 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 LAME Bitrate enum values (8, 16, 24, 32, 40, 48, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320).

§Errors