Skip to content

Commit b317639

Browse files
committed
fix
1 parent f16ae61 commit b317639

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

crates/audio/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ impl AudioInput {
141141
}
142142
}
143143

144+
#[cfg(target_os = "macos")]
144145
pub fn from_mixed() -> Result<Self, crate::Error> {
145146
let mixed = MixedInput::new().unwrap();
146147

crates/audio/src/mixed/macos.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ impl MixedInput {
7474
&[input_uid.as_type_ref()],
7575
);
7676

77+
let output_sub_device = cf::DictionaryOf::with_keys_values(
78+
&[sub_device_keys::uid()],
79+
&[output_uid.as_type_ref()],
80+
);
81+
7782
let sub_tap = cf::DictionaryOf::with_keys_values(
7883
&[ca::sub_device_keys::uid()],
7984
&[tap.uid().unwrap().as_type_ref()],
@@ -98,7 +103,7 @@ impl MixedInput {
98103
cf::str!(c"mixed-audio-tap"),
99104
&output_uid,
100105
&cf::Uuid::new().to_cf_string(),
101-
&cf::ArrayOf::from_slice(&[input_sub_device.as_ref()]),
106+
&cf::ArrayOf::from_slice(&[input_sub_device.as_ref(), output_sub_device.as_ref()]),
102107
&cf::ArrayOf::from_slice(&[sub_tap.as_ref()]),
103108
&input_uid, // Use input device as clock source for consistency
104109
],

crates/audio/src/mixed/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
#[cfg(target_os = "macos")]
12
mod macos;
3+
4+
#[cfg(target_os = "macos")]
25
pub use macos::*;

plugins/listener/src/actors/source.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ impl Actor for SourceActor {
7373
}
7474
});
7575

76-
let mic_device = AudioInput::get_default_mic_name();
76+
let mic_device = args
77+
.device
78+
.or_else(|| Some(AudioInput::get_default_mic_name()));
7779
let silence_stream_tx = Some(hypr_audio::AudioOutput::silence());
7880

7981
let mut st = SourceState {
80-
mic_device: Some(mic_device),
82+
mic_device,
8183
proc: args.proc,
8284
token: args.token,
8385
mic_muted: Arc::new(AtomicBool::new(false)),
@@ -170,10 +172,14 @@ async fn start_source_loop(
170172
let stream_cancel_token = CancellationToken::new();
171173
st.stream_cancel_token = Some(stream_cancel_token.clone());
172174

175+
#[cfg(target_os = "macos")]
173176
let use_mixed = !AudioInput::is_using_headphone();
174-
tracing::info!(use_mixed = use_mixed);
177+
178+
#[cfg(not(target_os = "macos"))]
179+
let use_mixed = false;
175180

176181
let handle = if use_mixed {
182+
#[cfg(target_os = "macos")]
177183
tokio::spawn(async move {
178184
let mixed_stream = {
179185
let mut mixed_input = AudioInput::from_mixed().unwrap();
@@ -196,7 +202,8 @@ async fn start_source_loop(
196202
}
197203
mixed_next = mixed_stream.next() => {
198204
if let Some(data) = mixed_next {
199-
let output_data = if mic_muted.load(Ordering::Relaxed) || spk_muted.load(Ordering::Relaxed) {
205+
// TODO: should be able to mute each stream
206+
let output_data = if mic_muted.load(Ordering::Relaxed) && spk_muted.load(Ordering::Relaxed) {
200207
vec![0.0; data.len()]
201208
} else {
202209
data

0 commit comments

Comments
 (0)