diff --git a/Cargo.toml b/Cargo.toml index 56140d8..130cf2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,8 @@ hound = "3.4" ringbuf = "0.1.6" [target.'cfg(target_os = "windows")'.dependencies] -winapi = { version = "0.3", features = ["audiosessiontypes", "audioclient", "coml2api", "combaseapi", "debug", "devpkey", "handleapi", "ksmedia", "mmdeviceapi", "objbase", "profileapi", "std", "synchapi", "winbase", "winuser"] } +winapi = { path = "../winapi-rs", version = "0.3", features = ["audiosessiontypes", "audioclient", "coml2api", "combaseapi", "debug", "devpkey", "errhandlingapi", "handleapi", "ksmedia", "mmdeviceapi", "objbase", "std", "synchapi", "winbase", "winuser"] } +# winapi = { version = "0.3", features = ["audiosessiontypes", "audioclient", "coml2api", "combaseapi", "debug", "devpkey", "handleapi", "ksmedia", "mmdeviceapi", "objbase", "profileapi", "std", "synchapi", "winbase", "winuser"] } asio-sys = { version = "0.1", path = "asio-sys", optional = true } parking_lot = "0.9" diff --git a/src/host/alsa/mod.rs b/src/host/alsa/mod.rs index 6e59f91..f8b8305 100644 --- a/src/host/alsa/mod.rs +++ b/src/host/alsa/mod.rs @@ -3,9 +3,9 @@ extern crate libc; use self::alsa::poll::Descriptors; use crate::{ - BackendSpecificError, BuildStreamError, ChannelCount, Data, DefaultStreamConfigError, + BackendSpecificError, BufferSize, BuildStreamError, ChannelCount, Data, DefaultStreamConfigError, DeviceNameError, DevicesError, InputCallbackInfo, OutputCallbackInfo, PauseStreamError, - PlayStreamError, SampleFormat, SampleRate, StreamConfig, StreamError, SupportedStreamConfig, + PlayStreamError, SampleFormat, SampleRate, StreamConfig, StreamError, SupportedBufferSizeRange, SupportedStreamConfig, SupportedStreamConfigRange, SupportedStreamConfigsError, }; use std::convert::TryInto; @@ -339,6 +339,15 @@ impl Device { }) .collect::>(); + let min_buffer_size = hw_params.get_buffer_size_min()?; + let max_buffer_size = hw_params.get_buffer_size_max()?; + + let buffer_size_range = SupportedBufferSizeRange { + min: min_buffer_size, + max: max_buffer_size, + requires_power_of_two: false, + }; + let mut output = Vec::with_capacity( supported_formats.len() * supported_channels.len() * sample_rates.len(), ); @@ -349,6 +358,7 @@ impl Device { channels: channels.clone(), min_sample_rate: SampleRate(min_rate as u32), max_sample_rate: SampleRate(max_rate as u32), + buffer_size: buffer_size_range, sample_format: sample_format, }); } diff --git a/src/host/coreaudio/mod.rs b/src/host/coreaudio/mod.rs index 970e155..0a09955 100644 --- a/src/host/coreaudio/mod.rs +++ b/src/host/coreaudio/mod.rs @@ -6,7 +6,7 @@ use self::coreaudio::audio_unit::render_callback::{self, data}; use self::coreaudio::audio_unit::{AudioUnit, Element, Scope}; use self::coreaudio::sys::{ kAudioDevicePropertyAvailableNominalSampleRates, kAudioDevicePropertyDeviceNameCFString, - kAudioDevicePropertyNominalSampleRate, kAudioDevicePropertyScopeOutput, + kAudioDevicePropertyBufferFrameSizeRange,kAudioDevicePropertyNominalSampleRate, kAudioDevicePropertyScopeOutput, kAudioDevicePropertyStreamConfiguration, kAudioDevicePropertyStreamFormat, kAudioFormatFlagIsFloat, kAudioFormatFlagIsPacked, kAudioFormatLinearPCM, kAudioObjectPropertyElementMaster, kAudioObjectPropertyScopeGlobal, @@ -20,10 +20,10 @@ use self::coreaudio::sys::{ }; use crate::traits::{DeviceTrait, HostTrait, StreamTrait}; use crate::{ - BackendSpecificError, BuildStreamError, ChannelCount, Data, DefaultStreamConfigError, + BackendSpecificError, BufferSize, BuildStreamError, ChannelCount, Data, DefaultStreamConfigError, DeviceNameError, DevicesError, InputCallbackInfo, OutputCallbackInfo, PauseStreamError, - PlayStreamError, SampleFormat, SampleRate, StreamConfig, StreamError, SupportedStreamConfig, - SupportedStreamConfigRange, SupportedStreamConfigsError, + PlayStreamError, SampleFormat, SampleRate, StreamConfig, StreamError, SupportedBufferSizeRange, + SupportedStreamConfig, SupportedStreamConfigRange, SupportedStreamConfigsError, }; use std::cell::RefCell; use std::ffi::CStr; @@ -276,6 +276,18 @@ impl Device { let ranges: *mut AudioValueRange = ranges.as_mut_ptr() as *mut _; let ranges: &'static [AudioValueRange] = slice::from_raw_parts(ranges, n_ranges); + let mut audio_unit = audio_unit_from_device(self, true)?; + let buffer_size_range = audio_unit.get_property( + kAudioDevicePropertyBufferFrameSizeRange, + Scope::Global, + Element::Output)?; + + let buffer_size = SupportedBufferSizeRange { + min: buffer_size_range.mMinimum; + max: buffer_size_range.mMaximum; + requires_power_of_two: false, + }; + // Collect the supported formats for the device. let mut fmts = vec![]; for range in ranges { @@ -283,6 +295,7 @@ impl Device { channels: n_channels as ChannelCount, min_sample_rate: SampleRate(range.mMinimum as _), max_sample_rate: SampleRate(range.mMaximum as _), + buffer_size, sample_format: sample_format, }; fmts.push(fmt);