Import with #import "std/audio_mp3".

Mp3Decoder :: struct { handle: *void; info: Mp3Info; position: s64; owned: Vec(u8); }

Single-owner native state over borrowed bytes (or bytes it read itself with Mp3DecoderOpenFile). Do not copy a live decoder or call it concurrently; keep borrowed input alive and unchanged until close.

Mp3DecoderClose :: (decoder: *Mp3Decoder)
Mp3DecoderOpen :: (decoder: *Mp3Decoder, input: []u8, max_frames: s64) -> s32

Inspects INPUT, then opens dr_mp3 over its frames with a seek table of about one point per second. MAX_FRAMES bounds the declared duration.

Mp3DecoderOpenFile :: (decoder: *Mp3Decoder, path: string, max_frames: s64) -> s32

Reads the whole file (at most MaxBytes) into the decoder, which then owns it until Mp3DecoderClose.

Mp3DecoderRead :: (decoder: *Mp3Decoder, output: []float32, frames: *s64) -> s32

Fills interleaved float frames. OK with zero frames is the logical end. An error may leave a filled prefix: discard it, then rewind or close.

Mp3DecoderReadS16 :: (decoder: *Mp3Decoder, output: []s16, frames: *s64) -> s32

The same stream as interleaved PCM16: the float samples converted with Pcm16, so they equal the WAV output of the same decode.

Mp3DecoderSeek :: (decoder: *Mp3Decoder, frame: s64) -> s32

Moves to exact PCM frame FRAME (0..frames): the next read returns the same samples a read from the start would. Seeks begin at the nearest seek point and decode forward, so the bit reservoir and overlap are primed.

Mp3DecoderRewind :: (decoder: *Mp3Decoder) -> s32
Mp3Decode :: (input: []u8, max_frames: s64, output: *PCM) -> s32

Whole-file float decode at the stream's own rate, bounded by MaxFrames. OUTPUT is unchanged on an error.

Mp3DecodeS16 :: (input: []u8, max_frames: s64, output: *Vec(s16), info: *Mp3Info) -> s32

Whole-file interleaved s16 decode; INFO describes the samples. Both outputs are unchanged on an error.

Source ↗ · All modules