Overview of firewheel-graph
mainfirewheel-graph crate provides the core audio graph algorithm and executor for the Firewheel project. It is responsible for managing the structure and execution of audio processing nodes within a graph.repository·main·Indexed 43 days ago
https://github.com/billydm/firewheelA modular, real-time safe audio graph engine written in Rust for games and applications. Version 0.14.0 supports directed acyclic graphs (DAG), multiple platform backends (including cpal and rtaudio), and is designed for extensibility via custom nodes and ECS-friendly parameter APIs. It features precise timing via AudioClock, musical transport management, and no_std compatibility.
firewheel-graph crate provides the core audio graph algorithm and executor for the Firewheel project. It is responsible for managing the structure and execution of audio processing nodes within a graph.Firewheel is an open-source audio graph engine written in Rust, designed for games and other applications. It can be used as a standalone engine or as a foundation for building higher-level audio engines. It is designed to be modular, allowing it to run on any backend that provides an audio stream.
Key characteristics include:
Firewheel is a modular audio engine designed for games, built to run on any backend that provides an audio stream. The architecture is split into several specialized crates:
firewheel-core: Common types, utilities, and the Audio Node API.firewheel-cpal: The default backend using the CPAL library (supports Windows, Mac, Linux, Android, iOS, and WebAssembly).firewheel-graph: The core audio graph engine.firewheel-macros: Macros for parameter diffing and patching.firewheel-nodes: Built-in factory nodes (e.g., volume, panning, sampler).firewheel-pool: Enables node pools for dynamic work assignment.Firewheel provides several core capabilities for audio processing:
Symphonium crate.no_std Compatibility: The engine is compatible with no_std environments (though some features may require the standard library).firewheel-cpal crate provides a backend implementation for the Firewheel audio engine using cpal (Cross-Platform Audio Library). Use this crate when you need cross-platform audio I/O capabilities within the Firewheel ecosystem.Firewheel provides three types of clocks to handle different timing requirements within the audio stream:
Recommended for most general use cases. It tracks total elapsed seconds as an f64. It is highly accurate as it reads from the OS's native audio API and accounts for output underflows.
Usage Pattern:
AudioGraph::clock_now().EventDelay::DelayUntilSeconds(current_time + delay).Tracks the total number of samples processed since the stream started. It is very accurate but does not account for output underflows.
A user-controlled clock (start, pause, resume, stop) that counts musical beats as an f64. Ideal for syncing events to a tempo. It does not account for underflows; users should poll the clock from the context to maintain game sync.
To prevent unnecessary processing in the audio graph, nodes can skip processing if their inputs are silent.
ProcInfo::in_silence_mask to determine which input buffers contain silence. If all input buffers are silent, the node can skip its processing step.ProcessStatus type defined in crates/firewheel-core/src/node.rs.When targeting WebAssembly, the following constraints and behaviors apply to the Firewheel engine:
CPAL) is responsible for spawning the audio thread.creek crate is disabled for WASM targets because it requires threads and file operations which are unsupported.The engine follows a specific lifecycle to ensure real-time safety and synchronization:
update method on the context (typically once per frame). This method:All platforms require CMake to be installed. Depending on your operating system, follow these steps:
Install the necessary system dependencies using apt:
apt install cmake pkg-config libasound2-dev libpulse-devIf you plan to use the jack_linux feature, you must also install the JACK development headers:
apt install libjack-devInstall cmake using one of these methods:
brew install cmakeInstall cmake by downloading it from https://cmake.org/.
The firewheel-rtaudio backend uses RtAudio (via rtaudio-rs) to provide better support for "full duplex" audio devices compared to the default CPAL backend, resulting in lower latency between input and output streams.
Note: This backend only supports Windows, MacOS, and Linux desktop platforms.
A Notify<T> is a lightweight wrapper around a value of type T that guarantees an event will be generated every time the inner value is accessed mutably, even if the value itself does not change.
This is particularly useful for types where periodic updates are meaningful even if the data is identical, such as a play head position.
Key behaviors:
DerefMut, AsMut, or calling .notify() increments an internal NotifyID, signaling a change.Diff::diff, a change is detected if the NotifyID differs, regardless of whether the inner T is equal to the baseline..as_mut_unsync() to get mutable access to the inner value without triggering a new ID/notification.// Diffing two separate instances with the same value will produce an event
let a = Notify::new(1);
let b = Notify::new(1);
// a.diff(&b, ...) -> produces event
// Diffing a clone will NOT produce an event
let c = b.clone();
// b.diff(&c, ...) -> no event