From 62499865fa152d1c9e98e607990e72963767cced Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Thu, 30 May 2024 15:51:02 +1000 Subject: [PATCH] frontend-common: prefer jack on linux --- Cargo.lock | 1 + frontend-common/Cargo.toml | 2 +- frontend-common/src/audio.rs | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6df1d70..0d9709c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1122,6 +1122,7 @@ dependencies = [ "core-foundation-sys 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)", "coreaudio-rs", "dasp_sample", + "jack", "jni", "js-sys", "libc", diff --git a/frontend-common/Cargo.toml b/frontend-common/Cargo.toml index 3c1b408..6f68c45 100644 --- a/frontend-common/Cargo.toml +++ b/frontend-common/Cargo.toml @@ -15,7 +15,7 @@ wgpu = ["gb-emu-lib/wgpu-renderer"] [dependencies] gb-emu-lib = { workspace = true } gilrs = "0.10" -cpal = "0.15" +cpal = { version = "0.15", features = ["jack"] } futures = "0.3" nokhwa = { version = "0.10", features = [ "input-avfoundation", diff --git a/frontend-common/src/audio.rs b/frontend-common/src/audio.rs index 10ab89c..4324942 100644 --- a/frontend-common/src/audio.rs +++ b/frontend-common/src/audio.rs @@ -10,7 +10,11 @@ use crate::access_config; const DOWNSAMPLE_TYPE: DownsampleType = DownsampleType::ZeroOrderHold; pub fn create_output(muted: bool) -> (AudioOutput, Stream) { - let host = cpal::default_host(); + let host = if cfg!(target_os = "linux") { + cpal::host_from_id(cpal::HostId::Jack).unwrap_or_else(|_| cpal::default_host()) + } else { + cpal::default_host() + }; let device = host .default_output_device()