Skip to main content

Crate maudio

Crate maudio 

Source
Expand description

maudio is an audio library built on top of miniaudio, providing both a high-level playback-focused API and the foundation for a more flexible low-level interface.

At the high level, audio is driven through an Engine, which offers a simple and ergonomic way to play sounds without requiring manual audio processing or buffer management.

The Engine is designed primarily for playback. It does not currently support recording, loopback, or full duplex operation, and it intentionally hides much of the complexity exposed by the low-level API. A lower-level, more flexible interface is planned and under active development.

Under the hood, the engine consists of:

  • ResourceManager: It is responsible for loading sounds into memory or streaming them. It is also responsible for refence counting them to avoid loading sounds into memory multiple times. It also has a Decoder and can decode audio either before or after it is loaded into memory.
  • NodeGraph: It is a directed graph of audio processing units called Nodes. Nodes can be audio sources (such as sounds or waveforms), processing units (DSP, filters, splitters), or endpoints. Audio data flows through the graph from source nodes, through optional processing nodes, and finally into the endpoint.
  • Device: An abstraction of a physical device. Represents the audio playback device and is responsible for driving the engine. Internally, it runs a callback on a dedicated audio thread, which continuously requests (pulls) audio frames from the engine. The engine, in turn, processes the node graph to produce the requested audio data.

By default, sounds created from an Engine are automatically connected to the graph’s endpoint and played in a push-based manner. Audio generation, mixing, and playback are handled internally by the engine, so users do not need to manually pull or read audio data.

While basic playback can be achieved without interacting directly with the NodeGraph, more advanced setups allow nodes to be explicitly connected, reordered, or routed through custom processing chains.

Most types in maudio are constructed using a builder pattern, enabling additional configuration at creation time while keeping common use cases straightforward.

In addition to the high level Engine API, maudio exposes a low level interface for working directly with the core audio building blocks. While the high level API provides a ready-to-use playback system, the low level API gives you the components needed to build your own. This includes manual control over devices, audio graphs, data sources, decoding, and resource management.

The two APIs are closely related: the high level engine is built using many of the same concepts exposed by the low level API, but organizes them into a simpler, playback-focused workflow.

The low level API includes:

  • Context for initializing the audio backend and enumerating devices.
  • Device for creating playback, capture, loopback, or duplex streams with direct control over the audio callback.
  • Decoder for reading audio from encoded formats.
  • Data sources as a unified interface for producing PCM frames.
  • Audio buffers for working with decoded PCM data in memory.
  • Utility primitives such as ring buffers, fences, and notification systems for real-time and asynchronous coordination.

Use the low level API when you need full control over how audio is generated, processed, or delivered, or when building abstractions on top of maudio.

§Feature flags

This crate builds and links the vendored miniaudio C library and exposes raw FFI bindings.

§Backend Features

These features disable specific miniaudio backends.

FeatureBackend
no_wasapiWindows WASAPI
no_dsoundWindows DirectSound
no_winmmWindows WinMM
no_alsaLinux ALSA
no_pulseaudioLinux PulseAudio
no_jackJACK
no_coreaudiomacOS/iOS CoreAudio
no_sndioOpenBSD sndio
no_audio4NetBSD audio
no_ossOSS
no_aaudioAndroid AAudio
no_openslAndroid OpenSL

By default all backends are enabled unless explicitly disabled.

§vorbis

Enables Ogg/Vorbis decoding by compiling the stb_vorbis implementation into the miniaudio translation unit.

  • Vorbis .ogg files can be decoded via miniaudio’s decoding APIs.

§generate-bindings

Generates bindings at build time using bindgen.

  • Required on MacOS
  • Intended for maintainers when updating the vendored miniaudio version.
  • Regular users should prefer the pre-generated bindings shipped with the crate.
  • Adds a build dependency on clang/libclang via bindgen.

Modules§

audio
Audio-related types and utilities
backend
Audio backends supported by miniaudio.
context
Audio backend context and device discovery.
data_source
Interface for reading from a data source
device
Audio device abstraction and control.
encoder
Audio file encoding.
engine
High level audio engine.
pcm_frames
PCM format abstraction and utilities.
sound
Sound playback primitives.
util

Structs§

MaudioError
Error type returned by the maudio crate.

Enums§

ErrorKinds
Wrapper-level error kinds.

Type Aliases§

MaResult