diff --git a/.github/workflows/coreaudio-rs.yml b/.github/workflows/coreaudio-rs.yml index d1e32fbca..13d869cb2 100644 --- a/.github/workflows/coreaudio-rs.yml +++ b/.github/workflows/coreaudio-rs.yml @@ -9,15 +9,23 @@ jobs: os: [macOS-latest] steps: - uses: actions/checkout@v4 + - name: Install LLVM and Clang uses: KyleMayes/install-llvm-action@v2.0.3 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 @@ -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: diff --git a/.gitignore b/.gitignore index 2cc3e6778..85f2fecca 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ target/ .cargo/ .DS_Store llvm/ +build diff --git a/Cargo.toml b/Cargo.toml index 8ce822e7a..0970aa56e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "coreaudio-rs" version = "0.12.0" authors = ["mitchmindtree ", "yupferris "] 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' @@ -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" } diff --git a/examples/feedback.rs b/examples/feedback.rs index f40b80944..e214ba87b 100644 --- a/examples/feedback.rs +++ b/examples/feedback.rs @@ -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}; @@ -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 = diff --git a/examples/ios/Cargo.lock b/examples/ios/Cargo.lock new file mode 100644 index 000000000..dd761fd3e --- /dev/null +++ b/examples/ios/Cargo.lock @@ -0,0 +1,435 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "avfaudio" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00f488019b88734f701d257e8665d382d2c9d86b1142d38b4f8977d059b23231" +dependencies = [ + "avfaudio2-sys", + "block", +] + +[[package]] +name = "avfaudio2-sys" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69ad67b63444645964f7e7e07d8d6519eda6c468c8f0f2f6c5c4f97c4f4c34b9" +dependencies = [ + "bindgen", + "block", + "objc", +] + +[[package]] +name = "bindgen" +version = "0.69.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools", + "lazy_static", + "lazycell", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", + "which", +] + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "coreaudio-ios-example" +version = "0.1.0" +dependencies = [ + "coreaudio-rs", +] + +[[package]] +name = "coreaudio-rs" +version = "0.12.0" +dependencies = [ + "avfaudio", + "bitflags", + "core-foundation-sys", + "coreaudio-sys", +] + +[[package]] +name = "coreaudio-sys" +version = "0.2.15" +source = "git+https://github.com/eugenehp/coreaudio-sys.git?branch=visionos#17eaa7c2fb9b5cf81e3c09984c1c443c4b724635" +dependencies = [ + "bindgen", +] + +[[package]] +name = "either" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "libloading" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" +dependencies = [ + "cfg-if", + "windows-targets", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "prettyplease" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" diff --git a/examples/ios/Cargo.toml b/examples/ios/Cargo.toml index c04bf362d..ff8bd7603 100644 --- a/examples/ios/Cargo.toml +++ b/examples/ios/Cargo.toml @@ -13,3 +13,7 @@ crate-type = ["staticlib"] [dependencies] coreaudio-rs = { path = "../.." } +# 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" } \ No newline at end of file diff --git a/examples/ios/build_rust_deps.sh b/examples/ios/build_rust_deps.sh index 024a42b28..4c1c55c84 100755 --- a/examples/ios/build_rust_deps.sh +++ b/examples/ios/build_rust_deps.sh @@ -1,9 +1,92 @@ -#!/bin/sh +#!/bin/bash set -e PATH=$PATH:$HOME/.cargo/bin +POSITIONAL_ARGS=() + +# cargo clean +# rm -rf build + +# ./build_rust_deps.sh --platform ${PLATFORM_DISPLAY_NAME:?} --sdk-root ${SDKROOT:?} --framework-search-paths "${FRAMEWORK_SEARCH_PATHS:?}" --header-search-paths "${HEADER_SEARCH_PATHS:?}" --gcc-preprocessor-definitions "${GCC_PREPROCESSOR_DEFINITIONS:-}" --configuration ${CONFIGURATION:?} ${FORCE_COLOR} ${ARCHS:?} + +# TODO: x86_64 crashes +# xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=x86_64 -scheme coreaudio-ios-example -configuration Debug -derivedDataPath build -sdk iphonesimulator + +# WORKS +# xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=arm64 -scheme coreaudio-ios-example -configuration Debug -derivedDataPath build -sdk iphoneos + +while [[ $# -gt 0 ]]; do + case $1 in + -p|--platform) + PLATFORM="$2" + shift # past argument + shift # past value + ;; + --root) + SRCROOT="$2" + shift # past argument + shift # past value + ;; + -s|--sdk-root) + SDKROOT="$2" + shift # past argument + shift # past value + ;; + --framework-search-paths) + FRAMEWORK_SEARCH_PATHS="$2" + shift # past argument + shift # past value + ;; + --header-search-paths) + HEADER_SEARCH_PATHS="$2" + shift # past argument + shift # past value + ;; + --gcc-preprocessor-definitions) + GCC_PREPROCESSOR_DEFINITIONS="$2" + shift # past argument + shift # past value + ;; + --configuration) + CONFIGURATION="$2" + shift # past argument + shift # past value + ;; + -*|--*) + echo "Unknown option $1" + exit 1 + ;; + *) + POSITIONAL_ARGS+=("$1") # save positional arg + shift # past argument + ;; + esac +done + +ARCH=$POSITIONAL_ARGS + +echo "SRCROOT $SRCROOT" +echo "PLATFORM $PLATFORM" +echo "SDKROOT $SDKROOT" +echo "FRAMEWORK_SEARCH_PATHS $FRAMEWORK_SEARCH_PATHS" +echo "HEADER_SEARCH_PATHS $HEADER_SEARCH_PATHS" +echo "GCC_PREPROCESSOR_DEFINITIONS $GCC_PREPROCESSOR_DEFINITIONS" +echo "CONFIGURATION $CONFIGURATION" +echo "ARCH $ARCH" +echo "POSITIONAL_ARGS $POSITIONAL_ARGS" + +PREFIX="aarch64" +SUFFIX=$([ "$ARCH" = "Simulator" ] && echo "-sim" || echo "") +PREFIX=$([ "$ARCH" = "arm64" ] && echo "aarch64" || echo $PREFIX) + +platform=$(tr '[:upper:]' '[:lower:]' <<<"$PLATFORM") +target="${PREFIX}-apple-${platform}${SUFFIX}" + +echo "TRIPLE $target" +COMMAND=$([ "$PLATFORM" = "visionOS" ] && echo "cargo +nightly build -Zbuild-std" || echo "cargo build") + if [[ -n "${DEVELOPER_SDK_DIR:-}" ]]; then # Assume we're in Xcode, which means we're probably cross-compiling. # In this case, we need to add an extra library search path for build scripts and proc-macros, @@ -12,9 +95,4 @@ if [[ -n "${DEVELOPER_SDK_DIR:-}" ]]; then export LIBRARY_PATH="${DEVELOPER_SDK_DIR}/MacOSX.sdk/usr/lib:${LIBRARY_PATH:-}" fi -# 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 +$COMMAND --target $target \ No newline at end of file diff --git a/examples/ios/coreaudio-ios-example.xcodeproj/project.pbxproj b/examples/ios/coreaudio-ios-example.xcodeproj/project.pbxproj index a706f377e..e5645b913 100644 --- a/examples/ios/coreaudio-ios-example.xcodeproj/project.pbxproj +++ b/examples/ios/coreaudio-ios-example.xcodeproj/project.pbxproj @@ -15,16 +15,6 @@ 57AB5B0B252769700040DE8C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 57AB5B04252769700040DE8C /* AppDelegate.m */; }; /* End PBXBuildFile section */ -/* Begin PBXContainerItemProxy section */ - 57AB5AEE252766820040DE8C /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 57AB5AC2252762C00040DE8C /* Project object */; - proxyType = 1; - remoteGlobalIDString = 57AB5AE9252766240040DE8C; - remoteInfo = cargo_ios; - }; -/* End PBXContainerItemProxy section */ - /* Begin PBXFileReference section */ 57AB5ACA252762C10040DE8C /* coreaudio-ios-example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "coreaudio-ios-example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 57AB5AF2252767460040DE8C /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; @@ -92,28 +82,12 @@ }; /* End PBXGroup section */ -/* Begin PBXLegacyTarget section */ - 57AB5AE9252766240040DE8C /* cargo_ios */ = { - isa = PBXLegacyTarget; - buildArgumentsString = build_rust_deps.sh; - buildConfigurationList = 57AB5AEA252766240040DE8C /* Build configuration list for PBXLegacyTarget "cargo_ios" */; - buildPhases = ( - ); - buildToolPath = /bin/sh; - buildWorkingDirectory = .; - dependencies = ( - ); - name = cargo_ios; - passBuildSettingsInEnvironment = 1; - productName = cargo_ios; - }; -/* End PBXLegacyTarget section */ - /* Begin PBXNativeTarget section */ 57AB5AC9252762C10040DE8C /* coreaudio-ios-example */ = { isa = PBXNativeTarget; buildConfigurationList = 57AB5AE3252762C30040DE8C /* Build configuration list for PBXNativeTarget "coreaudio-ios-example" */; buildPhases = ( + 44275A242C1510DC003B0C1C /* Build Rust Code */, 57AB5AC6252762C10040DE8C /* Sources */, 57AB5AC7252762C10040DE8C /* Frameworks */, 57AB5AC8252762C10040DE8C /* Resources */, @@ -121,7 +95,6 @@ buildRules = ( ); dependencies = ( - 57AB5AEF252766820040DE8C /* PBXTargetDependency */, ); name = "coreaudio-ios-example"; productName = "coreaudio-ios-example"; @@ -139,9 +112,6 @@ 57AB5AC9252762C10040DE8C = { CreatedOnToolsVersion = 12.0.1; }; - 57AB5AE9252766240040DE8C = { - CreatedOnToolsVersion = 12.0.1; - }; }; }; buildConfigurationList = 57AB5AC5252762C00040DE8C /* Build configuration list for PBXProject "coreaudio-ios-example" */; @@ -158,7 +128,6 @@ projectRoot = ""; targets = ( 57AB5AC9252762C10040DE8C /* coreaudio-ios-example */, - 57AB5AE9252766240040DE8C /* cargo_ios */, ); }; /* End PBXProject section */ @@ -175,6 +144,31 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 44275A242C1510DC003B0C1C /* Build Rust Code */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Build Rust Code"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(SRCROOT)/target/aarch64-apple-ios/${CONFIGURATION}/coreaudio_ios_example.a", + "$(SRCROOT)/target/aarch64-apple-ios-sim/${CONFIGURATION}/coreaudio_ios_example.a", + "$(SRCROOT)/target/aarch64-apple-visionos/${CONFIGURATION}/coreaudio_ios_example.a", + "$(SRCROOT)/target/aarch64-apple-visionos-sim/${CONFIGURATION}/coreaudio_ios_example.a", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "./build_rust_deps.sh --root ${SRCROOT:?} --platform ${PLATFORM_DISPLAY_NAME:?} --sdk-root ${SDKROOT:?} --framework-search-paths \"${FRAMEWORK_SEARCH_PATHS:?}\" --header-search-paths \"${HEADER_SEARCH_PATHS:?}\" --gcc-preprocessor-definitions \"${GCC_PREPROCESSOR_DEFINITIONS:-}\" --configuration ${CONFIGURATION:?} ${ARCHS:?}\n"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 57AB5AC6252762C10040DE8C /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -188,14 +182,6 @@ }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXTargetDependency section */ - 57AB5AEF252766820040DE8C /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 57AB5AE9252766240040DE8C /* cargo_ios */; - targetProxy = 57AB5AEE252766820040DE8C /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - /* Begin PBXVariantGroup section */ 57AB5AFF252769700040DE8C /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; @@ -333,18 +319,27 @@ buildSettings = { ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "ios-src/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - LIBRARY_SEARCH_PATHS = target/universal/debug; + LIBRARY_SEARCH_PATHS = ( + "target/aarch64-apple-ios/debug", + "target/aarch64-apple-ios-sim/debug", + "target/aarch64-apple-visionos/debug", + "target/aarch64-apple-visionos-sim/debug", + ); OTHER_LDFLAGS = "-lcoreaudio_ios_example"; OTHER_LIBTOOLFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = "coreaudio-rs.coreaudio-ios-example"; PRODUCT_NAME = "$(TARGET_NAME)"; - TARGETED_DEVICE_FAMILY = "1,2"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; + TARGETED_DEVICE_FAMILY = "1,2,7"; }; name = Debug; }; @@ -353,43 +348,22 @@ buildSettings = { ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "ios-src/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - LIBRARY_SEARCH_PATHS = target/universal/release; + LIBRARY_SEARCH_PATHS = "target/aarch64-apple-ios/release"; OTHER_LDFLAGS = "-lcoreaudio_ios_example"; OTHER_LIBTOOLFLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = "coreaudio-rs.coreaudio-ios-example"; PRODUCT_NAME = "$(TARGET_NAME)"; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; - 57AB5AEB252766240040DE8C /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - DEBUGGING_SYMBOLS = YES; - DEBUG_INFORMATION_FORMAT = dwarf; - GCC_GENERATE_DEBUGGING_SYMBOLS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - OTHER_CFLAGS = ""; - OTHER_LDFLAGS = ""; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 57AB5AEC252766240040DE8C /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - OTHER_CFLAGS = ""; - OTHER_LDFLAGS = ""; - PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; + TARGETED_DEVICE_FAMILY = "1,2,7"; }; name = Release; }; @@ -414,15 +388,6 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 57AB5AEA252766240040DE8C /* Build configuration list for PBXLegacyTarget "cargo_ios" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 57AB5AEB252766240040DE8C /* Debug */, - 57AB5AEC252766240040DE8C /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; /* End XCConfigurationList section */ }; rootObject = 57AB5AC2252762C00040DE8C /* Project object */; diff --git a/examples/ios/coreaudio-ios-example.xcodeproj/project.xcworkspace/xcuserdata/eugene.xcuserdatad/UserInterfaceState.xcuserstate b/examples/ios/coreaudio-ios-example.xcodeproj/project.xcworkspace/xcuserdata/eugene.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 000000000..9adfc70e2 Binary files /dev/null and b/examples/ios/coreaudio-ios-example.xcodeproj/project.xcworkspace/xcuserdata/eugene.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/examples/ios/coreaudio-ios-example.xcodeproj/xcuserdata/eugene.xcuserdatad/xcschemes/xcschememanagement.plist b/examples/ios/coreaudio-ios-example.xcodeproj/xcuserdata/eugene.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 000000000..3f852af2d --- /dev/null +++ b/examples/ios/coreaudio-ios-example.xcodeproj/xcuserdata/eugene.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,19 @@ + + + + + SchemeUserState + + cargo_ios.xcscheme_^#shared#^_ + + orderHint + 0 + + coreaudio-ios-example.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/examples/sine_advanced.rs b/examples/sine_advanced.rs index 8e2685538..fa2df89e5 100644 --- a/examples/sine_advanced.rs +++ b/examples/sine_advanced.rs @@ -21,6 +21,7 @@ const SAMPLE_FORMAT: SampleFormat = SampleFormat::F32; // type S = i8; const SAMPLE_FORMAT: SampleFormat = SampleFormat::I8; const SAMPLE_RATE: f64 = 44100.0; +// const SAMPLE_RATE: f64 = 48000.0; const INTERLEAVED: bool = true; diff --git a/src/audio_unit/audio_format.rs b/src/audio_unit/audio_format.rs index 952d706bd..97b454a84 100644 --- a/src/audio_unit/audio_format.rs +++ b/src/audio_unit/audio_format.rs @@ -282,6 +282,8 @@ bitflags! { /// the **AudioFormat** type. /// /// Original documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/AudioStreamBasicDescription_Flags). + #[derive(Copy, Clone, Debug)] + #[allow(non_camel_case_types)] pub struct StandardFlags: u32 { /// Set for floating point, clear for integer. /// @@ -335,7 +337,10 @@ bitflags! { /// have chosen to separate these for greater type safety and clearer compatibility with /// the **AudioFormat** type. /// - /// Original documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/AudioStreamBasicDescription_Flags). + /// Original documentation [here](https://developer.apple.com/documentation/coreaudiotypes/1572097-audio_stream_basic_description_f). + /// + #[derive(Copy, Clone, Debug)] + #[allow(non_camel_case_types)] pub struct LinearPcmFlags: u32 { /// Synonmyn for the **IS_FLOAT** **StandardFlags**. /// @@ -399,6 +404,8 @@ bitflags! { /// the **AudioFormat** type. /// /// Original documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/AudioStreamBasicDescription_Flags). + #[derive(Copy, Clone, Debug)] + #[allow(non_camel_case_types)] pub struct AppleLosslessFlags: u32 { /// Sourced from 16 bit native endian signed integer data. const BIT_16_SOURCE_DATA = 1; @@ -473,6 +480,8 @@ bitflags! { /// **Available** in OS X v10.0 and later. /// /// Original Documentation [here](https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/#//apple_ref/doc/constant_group/Audio_Time_Stamp_Flags). + #[derive(Copy, Clone, Debug)] + #[allow(non_camel_case_types)] pub struct AudioTimeStampFlags: u32 { /// The sample frame time is valid. const SAMPLE_TIME_VALID = 1; diff --git a/src/audio_unit/mod.rs b/src/audio_unit/mod.rs index 05695f052..b493a4dd8 100644 --- a/src/audio_unit/mod.rs +++ b/src/audio_unit/mod.rs @@ -419,13 +419,15 @@ pub fn get_property( /// ---------- /// /// - **id**: The identifier of the property. -#[cfg(target_os = "ios")] +#[cfg(any(target_os = "ios", target_os = "visionos"))] pub fn audio_session_get_property(id: u32) -> Result { let mut size = ::std::mem::size_of::() as u32; unsafe { let mut data_uninit = ::std::mem::MaybeUninit::::uninit(); let data_ptr = data_uninit.as_mut_ptr() as *mut _ as *mut c_void; let size_ptr = &mut size as *mut _; + // https://developer.apple.com/documentation/audiotoolbox/1618433-audiosessiongetproperty + // deprecated try_os_status!(sys::AudioSessionGetProperty(id, size_ptr, data_ptr)); let data: T = data_uninit.assume_init(); Ok(data) diff --git a/src/audio_unit/render_callback.rs b/src/audio_unit/render_callback.rs index 57c2628bf..7bdeeeb97 100644 --- a/src/audio_unit/render_callback.rs +++ b/src/audio_unit/render_callback.rs @@ -553,13 +553,13 @@ impl AudioUnit { // Pre-allocate a buffer list for input stream. // // First, get the current buffer size for pre-allocating the `AudioBuffer`s. - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos"))] let mut buffer_frame_size: u32 = { let id = sys::kAudioDevicePropertyBufferFrameSize; let buffer_frame_size: u32 = self.get_property(id, Scope::Global, Element::Output)?; buffer_frame_size }; - #[cfg(target_os = "ios")] + #[cfg(any(target_os = "ios", target_os = "visionos"))] let mut buffer_frame_size: u32 = { let id = sys::kAudioSessionProperty_CurrentHardwareIOBufferDuration; let seconds: f32 = super::audio_session_get_property(id)?;