Skip to content

Commit 744f27b

Browse files
philpaxroderickvd
andauthored
chore: update cpal to latest Git, fix conflict (#803)
* chore: update cpal to latest Git, replace `From<Input> for cpal::Device` with `into_inner` * feat: enable U24 support from cpal * chore: remove oboe backend support * feat: filter actionable stream errors in example --------- Co-authored-by: Roderick van Domburg <[email protected]>
1 parent b6421f2 commit 744f27b

File tree

10 files changed

+208
-56
lines changed

10 files changed

+208
-56
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3737
- `Blue` noise generator uses uniform instead of Gaussian noise for better performance.
3838
- `Gaussian` noise generator has standard deviation of 0.6 for perceptual equivalence.
3939
- `Velvet` noise generator takes density in Hz as `usize` instead of `f32`.
40+
- Upgrade `cpal` to v0.17.
4041

4142
## Version [0.21.1] (2025-07-14)
4243

Cargo.lock

Lines changed: 137 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ noise = ["rand", "rand_distr"]
4646
#
4747
# Enable WebAssembly support for web browsers
4848
wasm-bindgen = ["cpal/wasm-bindgen"]
49-
# Use shared C++ stdlib on Android (reduces APK size, fixes linking issues)
50-
cpal-shared-stdcxx = ["cpal/oboe-shared-stdcxx"]
5149

5250
# To decode an audio source with Rodio, you need to enable the appropriate features for *both* the
5351
# demuxer and the decoder.
@@ -106,7 +104,7 @@ all-features = true
106104
rustdoc-args = ["--cfg", "docsrs"]
107105

108106
[dependencies]
109-
cpal = { version = "0.16", optional = true }
107+
cpal = { version = "0.17.0", optional = true }
110108
dasp_sample = "0.11.0"
111109
claxon = { version = "0.4.2", optional = true }
112110
hound = { version = "3.5", optional = true }

examples/error_callback.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ fn main() -> Result<(), Box<dyn Error>> {
1414

1515
let stream_handle = rodio::OutputStreamBuilder::from_device(default_device)?
1616
.with_error_callback(move |err| {
17-
// Filter for where err is a DeviceNotAvailable error.
18-
if let cpal::StreamError::DeviceNotAvailable = err {
17+
// Filter for where err is an actionable error.
18+
if matches!(
19+
err,
20+
cpal::StreamError::DeviceNotAvailable | cpal::StreamError::StreamInvalidated
21+
) {
1922
if let Err(e) = tx.send(err) {
2023
eprintln!("Error emitting StreamError: {e}");
2124
}
@@ -31,9 +34,10 @@ fn main() -> Result<(), Box<dyn Error>> {
3134
mixer.add(wave);
3235

3336
if let Ok(err) = rx.recv_timeout(Duration::from_secs(30)) {
34-
// Here we print the error that was emitted by the error callback.
35-
// but in a real application we may want to destroy the stream and
36-
// try to reopen it, either with the same device or a different one.
37+
// Here we received an error that requires action from the error callback.
38+
// In a real application you would destroy the stream and try to reopen it,
39+
// either with the same device (for StreamInvalidated) or a different device
40+
// (for DeviceNotAvailable).
3741
eprintln!("Error with stream {err}");
3842
}
3943

examples/microphone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main() -> Result<(), Box<dyn Error>> {
1313
.prompt()?;
1414

1515
let input = MicrophoneBuilder::new()
16-
.device(input)?
16+
.device(input.into_inner())?
1717
.default_config()?
1818
.open_stream()?;
1919

src/microphone.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
//!
9292
//! // Use a specific device (e.g., the second one)
9393
//! let mic = MicrophoneBuilder::new()
94-
//! .device(inputs[1].clone())?
94+
//! .device(inputs[1].clone().into_inner())?
9595
//! .default_config()?
9696
//! .open_stream()?;
9797
//! # Ok(())
@@ -130,23 +130,38 @@ pub struct Input {
130130
inner: cpal::Device,
131131
}
132132

133-
impl From<Input> for cpal::Device {
134-
fn from(val: Input) -> Self {
135-
val.inner
133+
impl Input {
134+
/// Consumes the input and returns the inner device.
135+
pub fn into_inner(self) -> cpal::Device {
136+
self.inner
136137
}
137138
}
138139

139140
impl fmt::Debug for Input {
140141
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
141142
f.debug_struct("Device")
142-
.field("inner", &self.inner.name().unwrap_or("unknown".to_string()))
143+
.field(
144+
"inner",
145+
&self
146+
.inner
147+
.description()
148+
.ok()
149+
.map_or("unknown".to_string(), |d| d.name().to_string()),
150+
)
143151
.finish()
144152
}
145153
}
146154

147155
impl fmt::Display for Input {
148156
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
149-
write!(f, "{}", self.inner.name().unwrap_or("unknown".to_string()))
157+
write!(
158+
f,
159+
"{}",
160+
self.inner
161+
.description()
162+
.ok()
163+
.map_or("unknown".to_string(), |d| d.name().to_string())
164+
)
150165
}
151166
}
152167

@@ -271,8 +286,7 @@ impl Microphone {
271286
I64, i64;
272287
U8, u8;
273288
U16, u16;
274-
// TODO: uncomment when https://github.com/RustAudio/cpal/pull/1011 is merged
275-
// U24, cpal::U24;
289+
U24, cpal::U24;
276290
U32, u32;
277291
U64, u64
278292
)

0 commit comments

Comments
 (0)