Skip to main content

Crate glint

Crate glint 

Source
Expand description

Safe Rust wrapper for the glint MP3 encoder.

Structs§

AacDecoder
ADTS AAC-LC decoder.
AacEncoder
AAC-LC encoder (ADTS output). Same interleaved-PCM conventions as Encoder; one encode call consumes samples_per_frame() (1024) samples per channel and returns one ADTS frame. flush returns the two tail frames and must be called at end of stream (encoder delay: 2048 samples; the first frame is a silence priming frame).
DecFrameInfo
A decoded frame’s stream parameters.
DecodedAudio
Decoded audio: interleaved f32 PCM plus its stream parameters.
Encoder
A safe wrapper around the glint MP3 encoder.
Mp3Decoder
MPEG-1/2 Layer III decoder (keeps a bit reservoir across frames).
OpusDecoder
Opus decoder (SILK/CELT/hybrid, PLC, SILK in-band FEC), output rates 8/12/16/24/48 kHz, interleaved f32 PCM out.
OpusEncoder
CELT-only Opus encoder: 48 kHz interleaved f32 PCM in, complete Opus packets out. Frame sizes 120/240/480/960 samples per channel.

Enums§

Codec
Output codec for encode_audio.

Functions§

decode_audio
Decode a whole encoded stream (MP3 / AAC-LC / Ogg-Opus / Ogg-Vorbis / FLAC, format auto-detected from the header) to interleaved f32 PCM. Returns None on unrecognized or corrupt input.
decode_audio_i16
Decode a whole stream to interleaved i16 PCM, resampled to out_rate (0 = keep native). Returns (pcm, sample_rate, channels).
decode_audio_rate
Decode a whole stream to interleaved f32 PCM, resampled to out_rate (0 = keep native). Auto-detects MP3/AAC/Opus/Vorbis/FLAC (incl. Opus surround).
decode_flac
Decode a complete in-memory native FLAC stream to interleaved f32 PCM at its native rate. decode_audio also decodes FLAC transparently.
decode_vorbis
Decode a complete in-memory Ogg-Vorbis I stream (identification + comment + setup headers followed by audio packets) to interleaved f32 PCM at its native rate — the shape the .sf3 soundfont sample path needs. Mirrors OpusDecoder; decode_audio also decodes Vorbis transparently. Returns None on a non-Vorbis or corrupt buffer.
encode_audio
One-call encode: interleaved f32 PCM (±1.0) at any rate / 1-2 channels -> a complete MP3 / AAC-LC / Ogg-Opus stream. The input is auto- resampled to a codec-valid rate (Opus->48k, MP3/AAC->nearest supported). bitrate_kbps is the CBR/target rate; vbr_quality Some(0..9) selects VBR. Returns None on error.
encode_opus_file
Encode interleaved 48 kHz f32 PCM (±1.0, frames per channel, 1-2 channels) to a complete Ogg-Opus file (CELT-only, 20 ms frames). vbr selects unconstrained VBR. Input MUST be 48 kHz — resample first with resample. Returns None on error.
encode_pcm
Convenience function: encode an entire buffer of interleaved 16-bit PCM to MP3 in one call.
encode_pcm_aac
Convenience function: encode an entire buffer of interleaved 16-bit PCM to AAC (ADTS) in one call. quality: 0 speed / 1 normal / 2 best.
read_wav
Read a WAV buffer (PCM 8/16/24/32, IEEE float 32/64, A-law, mu-law, EXTENSIBLE) into interleaved f32 PCM. Returns None on malformed or unsupported input.
resample
Resample interleaved f32 PCM (±1.0) from sr_in to sr_out with a Kaiser-windowed sinc kernel (anti-aliased, unity passband). pcm is frames * channels interleaved samples; returns the resampled buffer. Pass-through (a clone) when the rates match.
write_wav
Encode interleaved f32 PCM (±1.0) to a WAV file buffer. bits: 8/16/24/32 integer PCM, or 32/64 with float_fmt for IEEE float (invalid combos fall back to 16-bit). Returns None on error.