For context, the Windows audio device properties allow you to configure the default sample rate and bit depth that should be used when an audio device is running in shared mode:

If you try to create an output stream in cpal using the build_output_stream method and the specified sample rate does not match the sample rate defined in the device properties, the method fails.
Example code:
use cpal::traits::{DeviceTrait, HostTrait};
fn main() {
let host = cpal::default_host();
let device = host.default_output_device().unwrap();
device.build_output_stream(
&cpal::StreamConfig {
channels: cpal::ChannelCount::from(2u16),
sample_rate: cpal::SampleRate(48000), // Audio device default sample rate is set to 192000
buffer_size: cpal::BufferSize::Default,
},
move |_: &mut [f32], _| {},
move |_| {},
).unwrap();
}
Result:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: StreamConfigNotSupported', src\main.rs:16:7
The error can be resolved in one of two ways:
- Change the sample rate in
StreamConfig to 192000 to match the device setting
- Change the device setting to 48000 to match the sample rate in the code
Am I correct in believing that this is a bug, and you should be able to create an output stream using any (supported) sample rate, or is there some limitation that prevents that from being possible?