Skip to content

Commit 95cc3bd

Browse files
wasapi: Enable resampling and rate adjustment
This allows non-native sample rates to be resampled by the WASAPI server. This should not have any meaningful performance impact, many pieces of software and middleware like SDL do this already.
1 parent d2bdd53 commit 95cc3bd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/host/wasapi/device.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ const PKEY_AUDIOENDPOINT_JACKSUBTYPE: PROPERTYKEY = PROPERTYKEY {
6161
pid: 8,
6262
};
6363

64+
const DEFAULT_FLAGS: u32 = Audio::AUDCLNT_STREAMFLAGS_EVENTCALLBACK | Audio::AUDCLNT_STREAMFLAGS_RATEADJUST | Audio::AUDCLNT_STREAMFLAGS_SRC_DEFAULT_QUALITY | Audio::AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM;
65+
6466
/// Wrapper because of that stupid decision to remove `Send` and `Sync` from raw pointers.
6567
#[derive(Clone)]
6668
struct IAudioClientWrapper(Audio::IAudioClient);
@@ -696,7 +698,7 @@ impl Device {
696698
// will return `AUDCLNT_E_BUFFER_SIZE_ERROR` if the buffer size is not supported.
697699
let buffer_duration = buffer_size_to_duration(&config.buffer_size, config.sample_rate);
698700

699-
let mut stream_flags = Audio::AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
701+
let mut stream_flags = DEFAULT_FLAGS;
700702

701703
if self.data_flow() == Audio::eRender {
702704
stream_flags |= Audio::AUDCLNT_STREAMFLAGS_LOOPBACK;
@@ -829,7 +831,7 @@ impl Device {
829831
audio_client
830832
.Initialize(
831833
share_mode,
832-
Audio::AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
834+
DEFAULT_FLAGS,
833835
buffer_duration,
834836
0,
835837
&format_attempt.Format,

0 commit comments

Comments
 (0)