AudioNimbus

repository·master·Indexed 42 days ago

https://github.com/maxencemaire/audionimbus

A safe Rust wrapper around Steam Audio providing spatial audio capabilities, including physics-based occlusion, reflections, and HRTF effects. Version 0.16.0 includes a high-level safe API, raw bindings via audionimbus-sys (v4.8.2-rc.3), and integrations for the Bevy engine, FMOD, and Wwise.

Tokens
21.5K
Snippets
58
Records
84
Agent score
52%

What's inside AudioNimbus

  1. Overview of AudioNimbus features

    master

    AudioNimbus provides spatial audio capabilities for games and VR applications by simulating realistic sound propagation. Key features include:

    • Sound propagation: Models distance attenuation and how sound interacts with physical obstacles of varying materials.
    • Reflections & reverb: Simulates sound wave reflections off geometry to create realistic acoustics.
    • Head-Related Transfer Function (HRTF): Simulates how the listener's head and ears shape incoming sound to convey direction and distance.
    • Ambisonics & surround sound: Encodes spatial information across multiple channels to reproduce directional sound fields.

    AudioNimbus is designed to integrate with audio engines like FMOD Studio and Wwise, as well as game engines like Bevy.

  2. Understand the spatial audio simulation architecture

    master

    Spatial audio simulation in audionimbus is compute-intensive (reflections passes can take 50-500ms) and cannot run directly on the real-time audio thread without causing glitches.

    To handle this, the library uses a decoupled architecture, often managed via the wiring module:

    1. Game Loop: Publishes new source positions to simulation threads every frame.
    2. Simulation Threads: Run asynchronously (one dedicated thread per simulation type) to calculate complex effects like reflections.
    3. Audio Thread: Renders audio using the latest available simulation output. This thread never blocks, ensuring smooth playback even if simulation updates are delayed.
  3. Understand audionimbus-sys vs audionimbus

    master

    audionimbus-sys

    audionimbus-sys provides raw, unsafe Rust bindings to the Steam Audio C library. It is intended for low-level access and is inherently unsafe because it interfaces directly with external C code. Most users should not use this crate directly.

    audionimbus

    audionimbus is a safe Rust wrapper built on top of audionimbus-sys. It is the recommended crate for general use as it provides a safe API for interacting with Steam Audio.

  4. How Bevy integration works in audionimbus

    master

    The bevy module provides ECS wrappers around AudioNimbus types.

    Architecture

    • Threading: It uses the wiring module to run simulations on dedicated threads, ensuring that the Bevy world can keep scene and source state up to date without blocking.
    • Output Boundary: The integration provides simulation outputs. It does not automatically apply these outputs to audio buffers; the developer is responsible for applying the simulation results to their chosen playback backend.

    Compatibility

    AudioNimbusBevy
    0.160.19
    0.150.19
    0.140.18
  5. Understand the AudioNimbus crate structure

    master

    AudioNimbus is split into two crates to separate high-level safety from low-level bindings:

    • audionimbus: The primary crate for end-users. It provides a high-level, safe Rust wrapper around Steam Audio. This is the crate you should typically use for your application logic.
    • audionimbus-sys: Contains raw, automatically generated bindings to the Steam Audio C API. This is intended for internal use by the audionimbus crate and is generally not meant for direct interaction by developers.
  6. How Audionimbus integrates with Bevy

    master

    The integration relies on the audionimbus::bevy module to synchronize the spatial audio simulation state with the Bevy ECS world.

    Key architectural characteristics:

    • Asynchronous Simulation: The audio simulation runs on dedicated background threads, separate from the main Bevy application loop.
    • Non-blocking Audio Graph: The audio backend (using Firewheel via bevy_seedling) consumes simulation outputs (direct sound, reflections, and reverb) without blocking the main simulation or the engine.
    • Ownership: Bevy manages the scene and source transforms, while the simulation threads produce spatial audio data in the background.
  7. Install AudioNimbus

    master

    To use AudioNimbus in your Rust project, add the audionimbus crate to your Cargo.toml. It is highly recommended to enable the auto-install feature, which automatically handles the downloading and installation of the underlying Steam Audio dependencies.

    [dependencies]
    audionimbus = { version = "0.16.0", features = ["auto-install"] }
  8. Manual FMOD and Wwise Integration for audionimbus-sys

    master

    To manually integrate FMOD or Wwise, you must link against both the Steam Audio library and the specific integration library provided in the respective Steam Audio zip files.

    FMOD Manual Setup

    1. Download steamaudio_fmod_4.8.1.zip.
    2. Locate both phonon and phonon_fmod libraries for your platform (e.g., libphonon.so and libphonon_fmod.so on Linux).
    3. Set FMODSDK to your FMOD SDK path.
    4. Enable the fmod feature in Cargo.toml.

    Wwise Manual Setup

    1. Download steamaudio_wwise_4.8.1.zip.
    2. Locate the Wwise integration libraries for your platform.
    3. Set WWISESDK to your Wwise SDK path.
    4. Enable the wwise feature in Cargo.toml.
    # FMOD manual dependency
    [dependencies]
    audionimbus-sys = { version = "4.8.2-rc.3", features = ["fmod"] }
    
    # Wwise manual dependency
    [dependencies]
    audionimbus-sys = { version = "4.8.2-rc.3", features = ["wwise"] }
  9. Install audionimbus via automatic installation (Recommended)

    master

    The easiest way to use audionimbus is by enabling the auto-install feature. This automatically downloads and sets up the required Steam Audio libraries for your target platform during the build process.

    Requirements

    • curl or wget
    • Clang 9.0 or later

    Basic Usage

    Add audionimbus to your Cargo.toml with the auto-install feature enabled.

    Feature Combinations

    • With Bevy Integration: Enables ECS integration and the wiring module for running simulations on dedicated threads.
    • With FMOD Studio Integration: Requires setting the FMODSDK environment variable to your local FMOD SDK path.
    • With Wwise Integration: Requires setting the WWISESDK environment variable to your local Wwise SDK path.

    Troubleshooting

    • Large Downloads: The initial download is large (≈180 MB for Steam Audio, plus integration sizes). Cargo may appear stuck while downloading.
    • Silencing Warnings: Set AUDIONIMBUS_AUTO_INSTALL_PROGRESS=0 to silence progress warnings.
    • Forcing Re-download: Delete the $OUT_DIR/steam_audio_cache directory.
    # Basic
    [dependencies]
    audionimbus = { version = "0.16.0", features = ["auto-install"] }
    
    # With Bevy
    [dependencies]
    audionimbus = { version = "0.16.0", features = ["auto-install", "bevy"] }
    
    # With FMOD
    [dependencies]
    audionimbus = { version = "0.16.0", features = ["auto-install", "fmod"] }
    
    # With Wwise
    [dependencies]
    audionimbus = { version = "0.16.0", features = ["auto-install", "wwise"] }