Skip to content

Commit 5cbf00c

Browse files
committed
fix(coreaudio): propagate API changes
1 parent 8fde179 commit 5cbf00c

2 files changed

Lines changed: 40 additions & 27 deletions

File tree

src/backends/coreaudio.rs

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ use coreaudio::sys::{
1818
use thiserror::Error;
1919

2020
use crate::audio_buffer::{AudioBuffer, Sample};
21-
use crate::channel_map::Bitset;
21+
use crate::channel_map::{Bitset, ChannelMap32};
2222
use crate::device::{AudioDevice, AudioInputDevice, AudioOutputDevice, Channel, DeviceType};
2323
use crate::driver::AudioDriver;
24-
use crate::prelude::ChannelMap32;
2524
use crate::stream::{
26-
AudioCallbackContext, AudioInputCallback, AudioOutputCallback, AudioStreamHandle, StreamConfig,
25+
AudioCallbackContext, AudioInput, AudioInputCallback, AudioOutput, AudioOutputCallback,
26+
AudioStreamHandle, StreamConfig,
2727
};
2828
use crate::timestamp::Timestamp;
29-
use crate::{AudioInput, AudioOutput, SendEverywhereButOnWeb};
29+
use crate::SendEverywhereButOnWeb;
3030

3131
/// Type of errors from the CoreAudio backend
3232
#[derive(Debug, Error)]
@@ -122,28 +122,6 @@ impl AudioDevice for CoreAudioDevice {
122122
self.device_type
123123
}
124124

125-
fn channel_map(&self) -> impl IntoIterator<Item = Channel> {
126-
let is_input = matches!(self.device_type, DeviceType::Input);
127-
let channels = match audio_unit_from_device_id(self.device_id, is_input) {
128-
Err(err) => {
129-
eprintln!("CoreAudio error getting audio unit: {err}");
130-
0
131-
}
132-
Ok(audio_unit) => {
133-
let stream_format = if is_input {
134-
audio_unit.input_stream_format().unwrap()
135-
} else {
136-
audio_unit.output_stream_format().unwrap()
137-
};
138-
stream_format.channels as usize
139-
}
140-
};
141-
(0..channels).map(|ch| Channel {
142-
index: ch,
143-
name: Cow::Owned(format!("Channel {}", ch)),
144-
})
145-
}
146-
147125
fn is_config_supported(&self, _config: &StreamConfig) -> bool {
148126
true
149127
}
@@ -189,6 +167,23 @@ fn input_stream_format(sample_rate: f64) -> StreamFormat {
189167
impl AudioInputDevice for CoreAudioDevice {
190168
type StreamHandle<Callback: AudioInputCallback> = CoreAudioStream<Callback>;
191169

170+
fn input_channel_map(&self) -> impl Iterator<Item = Channel> {
171+
let channels = match audio_unit_from_device_id(self.device_id, true) {
172+
Err(err) => {
173+
eprintln!("CoreAudio error getting audio unit: {err}");
174+
0
175+
}
176+
Ok(audio_unit) => {
177+
let stream_format = audio_unit.input_stream_format().unwrap();
178+
stream_format.channels as usize
179+
}
180+
};
181+
(0..channels).map(|ch| Channel {
182+
index: ch,
183+
name: Cow::Owned(format!("Channel {}", ch)),
184+
})
185+
}
186+
192187
fn default_input_config(&self) -> Result<StreamConfig, Self::Error> {
193188
let audio_unit = audio_unit_from_device_id(self.device_id, true)?;
194189
let samplerate = audio_unit.get_property::<f64>(
@@ -223,6 +218,23 @@ fn output_stream_format(sample_rate: f64, channels: ChannelMap32) -> StreamForma
223218
}
224219

225220
impl AudioOutputDevice for CoreAudioDevice {
221+
fn output_channel_map(&self) -> impl Iterator<Item = Channel> {
222+
let channels = match audio_unit_from_device_id(self.device_id, false) {
223+
Err(err) => {
224+
eprintln!("CoreAudio error getting audio unit: {err}");
225+
0
226+
}
227+
Ok(audio_unit) => {
228+
let stream_format = audio_unit.output_stream_format().unwrap();
229+
stream_format.channels as usize
230+
}
231+
};
232+
(0..channels).map(|ch| Channel {
233+
index: ch,
234+
name: Cow::Owned(format!("Channel {}", ch)),
235+
})
236+
}
237+
226238
type StreamHandle<Callback: AudioOutputCallback> = CoreAudioStream<Callback>;
227239

228240
fn default_output_config(&self) -> Result<StreamConfig, Self::Error> {

src/backends/wasapi/stream.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use crate::audio_buffer::{AudioMut, AudioRef};
33
use crate::backends::wasapi::util::WasapiMMDevice;
44
use crate::channel_map::Bitset;
55
use crate::stream::{
6-
AudioCallbackContext, AudioInput, AudioInputCallback, AudioOutput, AudioOutputCallback, AudioStreamHandle, StreamConfig
6+
AudioCallbackContext, AudioInput, AudioInputCallback, AudioOutput, AudioOutputCallback,
7+
AudioStreamHandle, StreamConfig,
78
};
89
use crate::timestamp::Timestamp;
910
use duplicate::duplicate_item;

0 commit comments

Comments
 (0)