Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor coreaudio host and add iOS support + ios-feedback example #485

Merged
merged 3 commits into from
Jan 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions .github/workflows/cpal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ jobs:
with:
command: check
use-cross: true
args: --target armv7-unknown-linux-gnueabihf --workspace --all-features --verbose
args: --target armv7-unknown-linux-gnueabihf --workspace --all-features --verbose

- name: Test all features for armv7
uses: actions-rs/cargo@v1
with:
command: test
use-cross: true
args: --target armv7-unknown-linux-gnueabihf --workspace --all-features --verbose
args: --target armv7-unknown-linux-gnueabihf --workspace --all-features --verbose

asmjs-wasm32-test:
strategy:
Expand Down Expand Up @@ -287,3 +287,23 @@ jobs:
run: cargo install cargo-apk
- name: Build APK
run: cargo apk build --example android

ios-build:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v2
- name: Install llvm and clang
run: brew install llvm
- name: Install stable
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Add iOS targets
run: rustup target add aarch64-apple-ios x86_64-apple-ios
- name: Install cargo lipo
run: cargo install cargo-lipo
- name: Build iphonesimulator feedback example
run: cd examples/ios-feedback && xcodebuild -scheme cpal-ios-example -configuration Debug -derivedDataPath build -sdk iphonesimulator

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ parking_lot = "0.11"
jack = { version = "0.6.5", optional = true }

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
coreaudio-rs = { version = "0.9.1", default-features = false, features = ["audio_unit", "core_audio"] }
core-foundation-sys = "0.6.2" # For linking to CoreFoundation.framework and handling device name `CFString`s.
mach = "0.3" # For access to mach_timebase type.

[target.'cfg(target_os = "macos")'.dependencies]
coreaudio-rs = { version = "0.10.0", default-features = false, features = ["audio_unit", "core_audio"] }

[target.'cfg(target_os = "ios")'.dependencies]
coreaudio-rs = { version = "0.10.0", default-features = false, features = ["audio_unit", "core_audio", "audio_toolbox"] }

[target.'cfg(target_os = "emscripten")'.dependencies]
stdweb = { version = "0.1.3", default-features = false }

Expand Down
17 changes: 17 additions & 0 deletions examples/ios-feedback/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "cpal-ios-example"
version = "0.1.0"
authors = ["Michael Hills <mhills@gmail.com>"]
edition = "2018"

[lib]
name = "cpal_ios_example"
crate-type = ["staticlib"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cpal = { path = "../.." }
anyhow = "1.0.12"
ringbuf = "0.1.6"

25 changes: 25 additions & 0 deletions examples/ios-feedback/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# iOS Feedback Example

This example is an Xcode project that exercises both input and output
audio streams. Audio samples are read in from your micrphone and then
routed to your audio output device with a small but noticeable delay
so you can verify it is working correctly.

To build the example you will need to still `cargo-lipo`. While not
necessary for building iOS binaries, it is used to build a universal
binary (x86 for simulator and aarch64 for device.)

```
cargo install cargo-lipo
```

Then open the XCode project and click run. A hook in the iOS application
lifecycle calls into the Rust code to start the input/output feedback
loop and immediately returns back control.

Before calling into Rust, the AVAudioSession category is configured.
This is important for controlling how audio is shared with the rest
of the system when your app is in the foreground. One example is
controlling whether other apps can play music in the background.
More information [here](https://developer.apple.com/library/archive/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategoriesandModes/AudioSessionCategoriesandModes.html#//apple_ref/doc/uid/TP40007875-CH10).

12 changes: 12 additions & 0 deletions examples/ios-feedback/build_rust_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

set -e

PATH=$PATH:$HOME/.cargo/bin

# If you want your build to run faster, add a "--targets x86_64-apple-ios" for just using the ios simulator.
if [ -n ${IOS_TARGETS} ]; then
cargo lipo --targets ${IOS_TARGETS}
else
cargo lipo
fi