Skip to content

Commit 1d72ae7

Browse files
Merge pull request #485 from MichaelHills/mike-ios
Refactor coreaudio host and add iOS support + ios-feedback example
2 parents 36ae2f0 + f9f6990 commit 1d72ae7

File tree

24 files changed

+2241
-876
lines changed

24 files changed

+2241
-876
lines changed

.github/workflows/cpal.yml

+22-2
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ jobs:
135135
with:
136136
command: check
137137
use-cross: true
138-
args: --target armv7-unknown-linux-gnueabihf --workspace --all-features --verbose
138+
args: --target armv7-unknown-linux-gnueabihf --workspace --all-features --verbose
139139

140140
- name: Test all features for armv7
141141
uses: actions-rs/cargo@v1
142142
with:
143143
command: test
144144
use-cross: true
145-
args: --target armv7-unknown-linux-gnueabihf --workspace --all-features --verbose
145+
args: --target armv7-unknown-linux-gnueabihf --workspace --all-features --verbose
146146

147147
asmjs-wasm32-test:
148148
strategy:
@@ -287,3 +287,23 @@ jobs:
287287
run: cargo install cargo-apk
288288
- name: Build APK
289289
run: cargo apk build --example android
290+
291+
ios-build:
292+
runs-on: macOS-latest
293+
steps:
294+
- uses: actions/checkout@v2
295+
- name: Install llvm and clang
296+
run: brew install llvm
297+
- name: Install stable
298+
uses: actions-rs/toolchain@v1
299+
with:
300+
profile: minimal
301+
toolchain: stable
302+
override: true
303+
- name: Add iOS targets
304+
run: rustup target add aarch64-apple-ios x86_64-apple-ios
305+
- name: Install cargo lipo
306+
run: cargo install cargo-lipo
307+
- name: Build iphonesimulator feedback example
308+
run: cd examples/ios-feedback && xcodebuild -scheme cpal-ios-example -configuration Debug -derivedDataPath build -sdk iphonesimulator
309+

Cargo.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,15 @@ parking_lot = "0.11"
3535
jack = { version = "0.6.5", optional = true }
3636

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

41+
[target.'cfg(target_os = "macos")'.dependencies]
42+
coreaudio-rs = { version = "0.10.0", default-features = false, features = ["audio_unit", "core_audio"] }
43+
44+
[target.'cfg(target_os = "ios")'.dependencies]
45+
coreaudio-rs = { version = "0.10.0", default-features = false, features = ["audio_unit", "core_audio", "audio_toolbox"] }
46+
4247
[target.'cfg(target_os = "emscripten")'.dependencies]
4348
stdweb = { version = "0.1.3", default-features = false }
4449

examples/ios-feedback/Cargo.toml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "cpal-ios-example"
3+
version = "0.1.0"
4+
authors = ["Michael Hills <mhills@gmail.com>"]
5+
edition = "2018"
6+
7+
[lib]
8+
name = "cpal_ios_example"
9+
crate-type = ["staticlib"]
10+
11+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
12+
13+
[dependencies]
14+
cpal = { path = "../.." }
15+
anyhow = "1.0.12"
16+
ringbuf = "0.1.6"
17+

examples/ios-feedback/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# iOS Feedback Example
2+
3+
This example is an Xcode project that exercises both input and output
4+
audio streams. Audio samples are read in from your micrphone and then
5+
routed to your audio output device with a small but noticeable delay
6+
so you can verify it is working correctly.
7+
8+
To build the example you will need to still `cargo-lipo`. While not
9+
necessary for building iOS binaries, it is used to build a universal
10+
binary (x86 for simulator and aarch64 for device.)
11+
12+
```
13+
cargo install cargo-lipo
14+
```
15+
16+
Then open the XCode project and click run. A hook in the iOS application
17+
lifecycle calls into the Rust code to start the input/output feedback
18+
loop and immediately returns back control.
19+
20+
Before calling into Rust, the AVAudioSession category is configured.
21+
This is important for controlling how audio is shared with the rest
22+
of the system when your app is in the foreground. One example is
23+
controlling whether other apps can play music in the background.
24+
More information [here](https://developer.apple.com/library/archive/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategoriesandModes/AudioSessionCategoriesandModes.html#//apple_ref/doc/uid/TP40007875-CH10).
25+
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
PATH=$PATH:$HOME/.cargo/bin
6+
7+
# If you want your build to run faster, add a "--targets x86_64-apple-ios" for just using the ios simulator.
8+
if [ -n ${IOS_TARGETS} ]; then
9+
cargo lipo --targets ${IOS_TARGETS}
10+
else
11+
cargo lipo
12+
fi

0 commit comments

Comments
 (0)