Skip to content

Commit e06fe04

Browse files
committed
feat: default wasapi-virtual-default-devices -> windows-legacy
1 parent ad2f408 commit e06fe04

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

Cargo.toml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2021"
1010
rust-version = "1.77"
1111

1212
[features]
13-
default = ["wasapi-virtual-default-devices"]
13+
default = []
1414

1515
# ASIO backend for Windows
1616
# Provides low-latency audio I/O by bypassing the Windows audio stack
@@ -21,14 +21,18 @@ asio = [
2121
"dep:num-traits",
2222
]
2323

24-
25-
# Enable virtual default devices for WASAPI. When enabled:
26-
# - Audio automatically reroutes when the default device changes
27-
# - Streams survive device changes (e.g., plugging in headphones)
28-
# - Requires Windows 8 or later
24+
# Legacy Windows audio device activation mode. When enabled:
25+
# - Uses IMMDevice::Activate instead of ActivateAudioInterfaceAsync
26+
# - Audio does NOT automatically reroute when the default device changes
27+
# - Streams will break when the default device changes (e.g., plugging in headphones)
28+
#
29+
# By default (without this feature), CPAL uses virtual default devices that:
30+
# - Automatically reroute audio when the default device changes
31+
# - Allow streams to survive device changes
32+
# - Require Windows 8 or later
2933
#
30-
# Disable this feature if supporting Windows 7 or earlier.
31-
wasapi-virtual-default-devices = []
34+
# Enable this feature only if supporting Windows 7 or earlier.
35+
windows-legacy = []
3236

3337
# JACK Audio Connection Kit backend
3438
# Provides low-latency connections between applications and audio hardware

src/host/wasapi/device.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ unsafe fn format_from_waveformatex_ptr(
305305
Some(format)
306306
}
307307

308-
#[cfg(feature = "wasapi-virtual-default-devices")]
308+
#[cfg(not(feature = "windows-legacy"))]
309309
unsafe fn activate_audio_interface_sync(
310310
deviceinterfacepath: windows::core::PWSTR,
311311
) -> windows::core::Result<Audio::IAudioClient> {
@@ -587,13 +587,14 @@ impl Device {
587587
return Ok(lock);
588588
}
589589

590-
// When using virtual default devices, we use `ActivateAudioInterfaceAsync` to get
591-
// an `IAudioClient` for the default output or input device. When retrieved this way,
592-
// streams will be automatically rerouted if the default device is changed.
590+
// By default, we use `ActivateAudioInterfaceAsync` to get an `IAudioClient` for
591+
// virtual default devices. When retrieved this way, streams will be automatically
592+
// rerouted if the default device is changed.
593593
//
594-
// Otherwise, we use `Activate` to get an `IAudioClient` for the current device.
594+
// When the `windows-legacy` feature is enabled, we use `Activate` to get an
595+
// `IAudioClient` for the current device, which does not support automatic rerouting.
595596

596-
#[cfg(feature = "wasapi-virtual-default-devices")]
597+
#[cfg(not(feature = "windows-legacy"))]
597598
let audio_client: Audio::IAudioClient = unsafe {
598599
match &self.device {
599600
DeviceHandle::DefaultOutput => {
@@ -614,7 +615,7 @@ impl Device {
614615
}
615616
};
616617

617-
#[cfg(not(feature = "wasapi-virtual-default-devices"))]
618+
#[cfg(feature = "windows-legacy")]
618619
let audio_client = unsafe {
619620
self.immdevice()
620621
.ok_or(windows::core::Error::new(

0 commit comments

Comments
 (0)