Skip to content

Commit b0f37eb

Browse files
authored
Merge pull request #97 from BillyDM/rtaudio
add RtAudio backend
2 parents e5bb264 + 7ba8977 commit b0f37eb

File tree

14 files changed

+932
-183
lines changed

14 files changed

+932
-183
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
uses: dtolnay/rust-toolchain@stable
2626

2727
- name: Install dependencies
28-
run: sudo apt-get update; sudo apt-get install -y --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev
28+
run: sudo apt-get update; sudo apt-get install -y --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev cmake libpulse-dev
2929

3030
- name: Populate target directory from cache
3131
uses: Leafwing-Studios/cargo-cache@v2
@@ -70,7 +70,7 @@ jobs:
7070
uses: dtolnay/rust-toolchain@stable
7171

7272
- name: Install dependencies
73-
run: sudo apt-get update; sudo apt-get install -y --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev
73+
run: sudo apt-get update; sudo apt-get install -y --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev cmake libpulse-dev
7474

7575
- name: Populate target directory from cache
7676
uses: Leafwing-Studios/cargo-cache@v2

Cargo.toml

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ exclude = ["assets/"]
2424
repository = "https://github.com/BillyDM/firewheel"
2525

2626
[features]
27-
default = ["std", "cpal", "symphonium", "symphonium_resample", "sampler_node", "tracing"]
27+
default = [
28+
"std",
29+
"cpal",
30+
"symphonium",
31+
"symphonium_resample",
32+
"sampler_node",
33+
"tracing",
34+
]
2835
std = [
2936
"firewheel-core/std",
3037
"firewheel-graph/std",
@@ -34,9 +41,14 @@ std = [
3441
# Enable this if "std" is disabled.
3542
libm = ["firewheel-core/libm", "firewheel-nodes/libm"]
3643
# Use the `tracing` crate for logging. Currently requires `std`.
37-
tracing = ["firewheel-graph/tracing", "firewheel-cpal?/tracing", "std"]
44+
tracing = [
45+
"firewheel-graph/tracing",
46+
"firewheel-cpal?/tracing",
47+
"firewheel-rtaudio?/tracing",
48+
"std",
49+
]
3850
# Use the `log` crate for logging
39-
log = ["firewheel-graph/log", "firewheel-cpal?/log"]
51+
log = ["firewheel-graph/log", "firewheel-cpal?/log", "firewheel-rtaudio?/log"]
4052
# Enables scheduling events for nodes
4153
scheduled_events = [
4254
"firewheel-core/scheduled_events",
@@ -54,6 +66,12 @@ musical_transport = [
5466
cpal = ["std", "dep:firewheel-cpal"]
5567
# Enables resampling input streams in the cpal backend
5668
cpal_resample_inputs = ["firewheel-cpal?/resample_inputs"]
69+
# Enables the alternative RtAudio backend
70+
# This backend has better support for "full duplex" audio devices than
71+
# the default CPAL backend, which allows for less latency between input
72+
# and output streams. The drawback is that this backend only supports
73+
# Windows, MacOS, and Linux desktop platforms.
74+
rtaudio = ["std", "firewheel-rtaudio"]
5775
# Enables using Symphonium for loading audio files.
5876
# Requires the standard library.
5977
symphonium = ["dep:firewheel-symphonium"]
@@ -155,11 +173,13 @@ members = [
155173
"crates/firewheel-nodes",
156174
"crates/firewheel-macros",
157175
"crates/firewheel-pool",
176+
"crates/firewheel-rtaudio",
158177
"crates/firewheel-symphonium",
159178
"examples/beep_test",
160179
"examples/cpal_input",
161180
"examples/custom_nodes",
162181
"examples/play_sample",
182+
"examples/rtaudio_beep_test",
163183
"examples/sampler_pool",
164184
"examples/sampler_test",
165185
"examples/spatial_basic",
@@ -197,8 +217,8 @@ eframe = { version = "0.33.3", default-features = false, features = [
197217
"default_fonts",
198218
"wayland",
199219
"x11",
200-
"glow"
201-
]}
220+
"glow",
221+
] }
202222

203223
[dependencies]
204224
firewheel-core = { path = "crates/firewheel-core", version = "0.10.0", default-features = false }
@@ -207,6 +227,7 @@ firewheel-cpal = { path = "crates/firewheel-cpal", version = "0.10.0", default-f
207227
firewheel-nodes = { path = "crates/firewheel-nodes", version = "0.10.0", default-features = false }
208228
firewheel-pool = { path = "crates/firewheel-pool", version = "0.10.0", default-features = false, optional = true }
209229
firewheel-symphonium = { path = "crates/firewheel-symphonium", version = "0.10.0", default-features = false, optional = true }
230+
firewheel-rtaudio = { path = "crates/firewheel-rtaudio", version = "0.10.0", default-features = false, optional = true }
210231
thunderdome = { workspace = true, optional = true }
211232
smallvec = { workspace = true, optional = true }
212233
thiserror.workspace = true

crates/firewheel-core/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,34 @@ extern crate self as firewheel_core;
2525
/// Information about a running audio stream.
2626
#[derive(Debug, Clone, PartialEq)]
2727
pub struct StreamInfo {
28+
/// The sample rate of the audio stream.
2829
pub sample_rate: NonZeroU32,
2930
/// The reciprocal of the sample rate.
31+
///
32+
/// This is provided for convenience since dividing by the sample rate is such a
33+
/// common operation.
34+
///
35+
/// Note to users implementing a custom `AudioBackend`: The context will overwrite
36+
/// this value, so just set this to the default value.
3037
pub sample_rate_recip: f64,
3138
/// The sample rate of the previous stream. (If this is the first stream, then this
3239
/// will just be a copy of [`StreamInfo::sample_rate`]).
40+
///
41+
/// Note to users implementing a custom `AudioBackend`: The context will overwrite
42+
/// this value, so just set this to the default value.
3343
pub prev_sample_rate: NonZeroU32,
44+
/// The maximum number of frames that can appear in a single process cyle.
3445
pub max_block_frames: NonZeroU32,
46+
/// The number of input audio channels in the stream.
3547
pub num_stream_in_channels: u32,
48+
/// The number of output audio channels in the stream.
3649
pub num_stream_out_channels: u32,
3750
/// The latency of the input to output stream in seconds.
3851
pub input_to_output_latency_seconds: f64,
52+
/// The number of frames used in the shared declicker DSP.
53+
///
54+
/// Note to users implementing a custom `AudioBackend`: The context will overwrite
55+
/// this value, so just set this to the default value.
3956
pub declick_frames: NonZeroU32,
4057
/// The identifier of the output audio device (converted to a string).
4158
pub output_device_id: String,

0 commit comments

Comments
 (0)