From 33a8cde0568cc149bc5d637641de6d04f538a83b Mon Sep 17 00:00:00 2001 From: egnehots Date: Tue, 10 Oct 2017 18:24:53 +0200 Subject: [PATCH 1/2] Minimal ios support --- Cargo.toml | 4 ++-- src/coreaudio/mod.rs | 6 +++++- src/lib.rs | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7c13539..5d4eb5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,5 +21,5 @@ kernel32-sys = "0.2" [target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))'.dependencies] alsa-sys = { version = "0.1", path = "alsa-sys" } -[target.'cfg(target_os = "macos")'.dependencies] -coreaudio-rs = "0.6" +[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] +coreaudio-rs = "0.7.0" diff --git a/src/coreaudio/mod.rs b/src/coreaudio/mod.rs index 6f4cba9..eac12d2 100644 --- a/src/coreaudio/mod.rs +++ b/src/coreaudio/mod.rs @@ -157,7 +157,11 @@ impl Voice { } } - let au_type = coreaudio::audio_unit::IOType::DefaultOutput; + let au_type = if cfg!(target_os = "ios") { + coreaudio::audio_unit::IOType::RemoteIO + } else { + coreaudio::audio_unit::IOType::DefaultOutput + }; let mut audio_unit = try!(AudioUnit::new(au_type).map_err(convert_error)); // TODO: iOS uses integer and fixed-point data diff --git a/src/lib.rs b/src/lib.rs index b18e746..fa1281d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,7 +76,7 @@ extern crate libc; pub use samples_formats::{SampleFormat, Sample}; -#[cfg(all(not(windows), not(target_os = "linux"), not(target_os = "freebsd"), not(target_os = "macos")))] +#[cfg(all(not(windows), not(target_os = "linux"), not(target_os = "freebsd"), not(target_os = "macos"), not(target_os = "ios")))] use null as cpal_impl; use std::fmt; @@ -97,7 +97,7 @@ mod cpal_impl; #[path="wasapi/mod.rs"] mod cpal_impl; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] #[path="coreaudio/mod.rs"] mod cpal_impl; From bd88d9d6ffba1a4e8965b3aafb9a4c3b6012cfe4 Mon Sep 17 00:00:00 2001 From: egnehots Date: Tue, 10 Oct 2017 20:43:37 +0200 Subject: [PATCH 2/2] Document RemoteIO as ios unit fallback iOS provides three I/O (input/output) units. The vast majority of audio-unit applications use the Remote I/O unit, which connects to input and output audio hardware and provides low-latency access to individual incoming and outgoing audio sample values. For VoIP apps, the Voice-Processing I/O unit extends the Remote I/O unit by adding acoustic echo cancelation and other features. To send audio back to your application rather than to output audio hardware, use the Generic Output unit. See https://developer.apple.com/library/content/documentation/MusicAudio/Conceptual/AudioUnitHostingGuide_iOS/UsingSpecificAudioUnits/UsingSpecificAudioUnits.html --- src/coreaudio/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/coreaudio/mod.rs b/src/coreaudio/mod.rs index eac12d2..9f3b662 100644 --- a/src/coreaudio/mod.rs +++ b/src/coreaudio/mod.rs @@ -158,6 +158,9 @@ impl Voice { } let au_type = if cfg!(target_os = "ios") { + // The DefaultOutput unit isn't available in iOS unfortunately. RemoteIO is a sensible replacement. + // See + // https://developer.apple.com/library/content/documentation/MusicAudio/Conceptual/AudioUnitHostingGuide_iOS/UsingSpecificAudioUnits/UsingSpecificAudioUnits.html coreaudio::audio_unit::IOType::RemoteIO } else { coreaudio::audio_unit::IOType::DefaultOutput