-
Notifications
You must be signed in to change notification settings - Fork 442
Description
Hi! I'm having an issue as soon as I try specifying a buffer size for my output stream.
The following code runs:
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use cpal::{BufferSize, StreamConfig};
fn main() {
let host = cpal::default_host();
let device = host.default_output_device().unwrap();
let mut supported_configs_range = device.supported_output_configs().unwrap();
let config = supported_configs_range
.next()
.unwrap()
.with_max_sample_rate();
dbg!(&config);
let mut c: StreamConfig = config.into();
// c.buffer_size = BufferSize::Fixed(64);
let stream = device
.build_output_stream(
&c,
move |_: &mut [f32], _: &cpal::OutputCallbackInfo| {},
move |_| {},
)
.unwrap();
stream.play().unwrap();
}
Furthermore, the SupportedStreamConfig
I get is as follows:
[src/main.rs:15] &config = SupportedStreamConfig {
channels: 1,
sample_rate: SampleRate(
384000,
),
buffer_size: Range {
min: 3,
max: 4194304,
},
sample_format: I16,
}
The above leads me to believe that I can specify any buffer_size
between 3 and 4194304. Is this correct? Unfortunately, selecting any Fixed
buffer size leads to failure. For example, if I uncomment the line c.buffer_size = BufferSize::Fixed(64)
, I get:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BackendSpecific { err: BackendSpecificError { description: "ALSA function 'snd_pcm_hw_params_set_buffer_size' failed with error 'EINVAL: Invalid argument'" } }', src/main.rs:25:10
Am I doing something wrong or is this a bug? I cant seem to specify any buffer size other than Default
.
I tried using other values, such as the minimum 3, and the maximum 4194304, with the same results. I also adapted the code to test it with the master
version of cpal
, and I got the same error.
I'm very new to the audio processing world so apologies if I omitted anything. Any guidance would be appreciated. Thanks!