Esc

Audio_Stream

moduleextensionexperimentalSource
  • macOS: Everything works on macOS
  • Linux: Everything works on Linux
  • Windows: Everything works on Windows
  • Wasm: Everything works on Wasm
·since 0.36.1

#import "Extensions/Audio_Stream";

Bounded, seekable decoding of WAV PCM/IMA ADPCM and Ogg Vorbis files. A reader owns its file and scratch block; it never loads the whole recording.

Procedures#

openexperimentalsince 0.36.1Source
(r: *Reader, path: string) -> bool

Opens a file and copies Vorbis ARTIST/ALBUM/TITLE comments. Returns false on unsupported or malformed headers, including Vorbis on WebAssembly, which has no native decoder. PCM 8/16/24/32-bit and IMA ADPCM, one or two channels, are accepted on every target.

r: Reader;
if open(*r, "song.ogg") {
    defer close(*r);
    assert(r.rate > 0);
}
↗
closeexperimentalsince 0.36.1Source
(r: *Reader)

Releases file handles, comments and block buffers. Safe after a failed open or repeated close.

seekexperimentalsince 0.36.1Source
(r: *Reader, frame: s64) -> bool

Moves to an exact source frame; out-of-range requests clamp to the recording's ends.

readexperimentalsince 0.36.1Source
(r: *Reader, output: [] s16) -> s64

Reads interleaved signed 16-bit samples into caller storage. Returns frames decoded, zero at EOF, or -1 on a file/codec failure. Storage must fit a whole number of frames.

Types#

Readerstructexperimentalsince 0.36.1Source

An open decoder. Keep it on one thread, close it before reuse, and do not copy it. position and frames count frames, not individual interleaved channel samples.

Reader :: struct {
    file: File;
    opened: bool;
    vorbis: *V.stb_vorbis;
    channels: s32;
    rate: s32;
    frames: s64;
    position: s64;
    artist: string;
    album: string;
    title: string;
    format: W.Waveformatex;
    extra: W.Wave_Extra_Info;
    offset: s64;
    block: [] u8;
    decoded: [] s16;
    cached_block: s64 = -1;
}