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

feat(apple): add visionOS support #119

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions .github/workflows/coreaudio-rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ jobs:
os: [macOS-latest]
steps:
- uses: actions/checkout@v4

- name: Install LLVM and Clang
uses: KyleMayes/[email protected]
with:
version: "15.0"

- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: cargo test
run: cargo test --verbose


# TODO: don't run on CI, it loops. Works fine locally.
# - name: Run sine example
# run: cargo run --example sine

# TODO: These don't work as of 2020-12-06, but they should.
# - name: cargo test - no features
# run: cargo test --no-default-features --verbose
Expand All @@ -44,11 +52,24 @@ jobs:
with:
toolchain: stable
- name: Add iOS targets
run: rustup target add aarch64-apple-ios x86_64-apple-ios
- name: Install cargo lipo
run: cargo install cargo-lipo
run: rustup target add aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios
- name: Build iphonesimulator feedback example
run: cd examples/ios && xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=x86_64 -scheme coreaudio-ios-example -configuration Debug -derivedDataPath build -sdk iphonesimulator
run: cd examples/ios && xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=arm64 -scheme coreaudio-ios-example -configuration Debug -derivedDataPath build -sdk iphonesimulator

visionos-build:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: nightly
components: rust-src
# select Xcode with visionOS support that has xrsimulator SDK installed
- name: Install Xcode Command Line Tools
run: sudo xcode-select --switch /Applications/Xcode_15.4.app/Contents/Developer
- name: Build xrsimulator feedback example
run: cd examples/ios && xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=arm64 -scheme coreaudio-ios-example -configuration Debug -derivedDataPath build -sdk xrsimulator

# Build the docs with all features to make sure docs.rs will work.
macos-docs:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ target/
.cargo/
.DS_Store
llvm/
build
26 changes: 22 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "coreaudio-rs"
version = "0.12.0"
authors = ["mitchmindtree <[email protected]>", "yupferris <[email protected]>"]
description = "A friendly rust interface for Apple's CoreAudio API."
keywords = ["core", "audio", "unit", "osx", "ios"]
keywords = ["core", "audio", "unit", "osx", "ios", "visionos"]
readme = "README.md"
license = "MIT/Apache-2.0"
edition = '2018'
Expand All @@ -22,11 +22,29 @@ open_al = ["coreaudio-sys/open_al"]
core_midi = ["coreaudio-sys/core_midi"]

[dependencies]
bitflags = "1.0"
bitflags = "2.5.0"
coreaudio-sys = { version = "0.2", default-features = false }
core-foundation-sys = "0.8.3"
avfaudio = "0.0.2"

[package.metadata.docs.rs]
all-features = true
default-target = "x86_64-apple-darwin"
targets = ["x86_64-apple-darwin", "x86_64-apple-ios"]
default-target = "aarch64-apple-darwin"
targets = ["x86_64-apple-darwin", "x86_64-apple-ios", "aarch64-apple-darwin", "aarch64-apple-ios", "aarch64-apple-visionos"]

[[example]]
name = "feedback_interleaved"

[[example]]
name = "feedback"

[[example]]
name = "sine_advanced"

[[example]]
name = "sine"

# TODO: remove this fix, once https://github.com/RustAudio/coreaudio-sys/pull/102 has been merged.
[patch.crates-io]
coreaudio-sys = { git = "https://github.com/eugenehp/coreaudio-sys.git", branch = "visionos" }
# coreaudio-sys = { path = "../coreaudio-sys" }
5 changes: 5 additions & 0 deletions examples/feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern crate coreaudio;
use std::collections::VecDeque;
use std::sync::{Arc, Mutex};

use avfaudio::session::{AVAudioSession, Category};
use coreaudio::audio_unit::audio_format::LinearPcmFlags;
use coreaudio::audio_unit::macos_helpers::{audio_unit_from_device_id, get_default_device_id};
use coreaudio::audio_unit::render_callback::{self, data};
Expand All @@ -20,6 +21,10 @@ const SAMPLE_FORMAT: SampleFormat = SampleFormat::F32;
// type S = i8; const SAMPLE_FORMAT: SampleFormat = SampleFormat::I8;

fn main() -> Result<(), coreaudio::Error> {

let session = AVAudioSession::shared_instance();
session.set_category(Category::play_and_record());

let mut input_audio_unit =
audio_unit_from_device_id(get_default_device_id(true).unwrap(), true)?;
let mut output_audio_unit =
Expand Down
Loading