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

cpal uses macOS specific APIs not supported on iOS #224

Closed
Moxinilian opened this issue May 9, 2018 · 9 comments · Fixed by #485
Closed

cpal uses macOS specific APIs not supported on iOS #224

Moxinilian opened this issue May 9, 2018 · 9 comments · Fixed by #485

Comments

@Moxinilian
Copy link

Moxinilian commented May 9, 2018

While the README argues iOS is supported, it currently is not as a large part of the CoreAudio logic depends on macOS-specific APIs.

Here is a list of the missing bindings:

error[E0432]: unresolved import `self::coreaudio::sys::AudioDeviceID`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:31:5
   |
31 |     AudioDeviceID,
   |     ^^^^^^^^^^^^^ no `AudioDeviceID` in `sys`

error[E0432]: unresolved import `self::coreaudio::sys::AudioObjectAddPropertyListener`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:32:5
   |
32 |     AudioObjectAddPropertyListener,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `AudioObjectAddPropertyListener` in `sys`. Did you mean to use `AudioUnitAddPropertyListener`?

error[E0432]: unresolved import `self::coreaudio::sys::AudioObjectGetPropertyData`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:33:5
   |
33 |     AudioObjectGetPropertyData,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ no `AudioObjectGetPropertyData` in `sys`

error[E0432]: unresolved import `self::coreaudio::sys::AudioObjectGetPropertyDataSize`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:34:5
   |
34 |     AudioObjectGetPropertyDataSize,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `AudioObjectGetPropertyDataSize` in `sys`

error[E0432]: unresolved import `self::coreaudio::sys::AudioObjectID`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:35:5
   |
35 |     AudioObjectID,
   |     ^^^^^^^^^^^^^ no `AudioObjectID` in `sys`

error[E0432]: unresolved import `self::coreaudio::sys::AudioObjectPropertyAddress`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:36:5
   |
36 |     AudioObjectPropertyAddress,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ no `AudioObjectPropertyAddress` in `sys`

error[E0432]: unresolved import `self::coreaudio::sys::AudioObjectPropertyScope`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:37:5
   |
37 |     AudioObjectPropertyScope,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^ no `AudioObjectPropertyScope` in `sys`

error[E0432]: unresolved import `self::coreaudio::sys::AudioObjectRemovePropertyListener`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:38:5
   |
38 |     AudioObjectRemovePropertyListener,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `AudioObjectRemovePropertyListener` in `sys`. Did you mean to use `AudioUnitRemovePropertyListenerProc`?

error[E0432]: unresolved import `self::coreaudio::sys::AudioObjectSetPropertyData`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:39:5
   |
39 |     AudioObjectSetPropertyData,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ no `AudioObjectSetPropertyData` in `sys`

error[E0432]: unresolved import `self::coreaudio::sys::kAudioDevicePropertyAvailableNominalSampleRates`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:42:5
   |
42 |     kAudioDevicePropertyAvailableNominalSampleRates,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioDevicePropertyAvailableNominalSampleRates` in `sys`

error[E0432]: unresolved import `self::coreaudio::sys::kAudioDevicePropertyDeviceNameCFString`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:43:5
   |
43 |     kAudioDevicePropertyDeviceNameCFString,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioDevicePropertyDeviceNameCFString` in `sys`

error[E0432]: unresolved import `self::coreaudio::sys::kAudioDevicePropertyNominalSampleRate`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:44:5
   |
44 |     kAudioDevicePropertyNominalSampleRate,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioDevicePropertyNominalSampleRate` in `sys`. Did you mean to use `kAudioUnitProperty_SampleRate`?

error[E0432]: unresolved import `self::coreaudio::sys::kAudioObjectPropertyScopeInput`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:45:5
   |
45 |     kAudioObjectPropertyScopeInput,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioObjectPropertyScopeInput` in `sys`

error[E0432]: unresolved import `self::coreaudio::sys::kAudioObjectPropertyScopeGlobal`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:46:5
   |
46 |     kAudioObjectPropertyScopeGlobal,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioObjectPropertyScopeGlobal` in `sys`

error[E0432]: unresolved import `self::coreaudio::sys::kAudioDevicePropertyScopeOutput`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:47:5
   |
47 |     kAudioDevicePropertyScopeOutput,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioDevicePropertyScopeOutput` in `sys`

error[E0432]: unresolved import `self::coreaudio::sys::kAudioDevicePropertyStreamConfiguration`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:48:5
   |
48 |     kAudioDevicePropertyStreamConfiguration,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioDevicePropertyStreamConfiguration` in `sys`

error[E0432]: unresolved import `self::coreaudio::sys::kAudioDevicePropertyStreamFormat`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:49:5
   |
49 |     kAudioDevicePropertyStreamFormat,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioDevicePropertyStreamFormat` in `sys`. Did you mean to use `kAudioUnitProperty_StreamFormat`?

error[E0432]: unresolved import `self::coreaudio::sys::kAudioHardwareNoError`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:53:5
   |
53 |     kAudioHardwareNoError,
   |     ^^^^^^^^^^^^^^^^^^^^^ no `kAudioHardwareNoError` in `sys`

error[E0432]: unresolved import `self::coreaudio::sys::kAudioObjectPropertyElementMaster`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:54:5
   |
54 |     kAudioObjectPropertyElementMaster,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioObjectPropertyElementMaster` in `sys`. Did you mean to use `kAudioUnitProperty_ElementName`?

error[E0432]: unresolved import `self::coreaudio::sys::kAudioObjectPropertyScopeOutput`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/mod.rs:55:5
   |
55 |     kAudioObjectPropertyScopeOutput,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioObjectPropertyScopeOutput` in `sys`

error[E0432]: unresolved import `super::coreaudio::sys::AudioDeviceID`
 --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/enumerate.rs:6:5
  |
6 |     AudioDeviceID,
  |     ^^^^^^^^^^^^^ no `AudioDeviceID` in `sys`

error[E0432]: unresolved import `super::coreaudio::sys::AudioObjectPropertyAddress`
 --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/enumerate.rs:7:5
  |
7 |     AudioObjectPropertyAddress,
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ no `AudioObjectPropertyAddress` in `sys`

error[E0432]: unresolved import `super::coreaudio::sys::AudioObjectGetPropertyData`
 --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/enumerate.rs:8:5
  |
8 |     AudioObjectGetPropertyData,
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ no `AudioObjectGetPropertyData` in `sys`

error[E0432]: unresolved import `super::coreaudio::sys::AudioObjectGetPropertyDataSize`
 --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/enumerate.rs:9:5
  |
9 |     AudioObjectGetPropertyDataSize,
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `AudioObjectGetPropertyDataSize` in `sys`

error[E0432]: unresolved import `super::coreaudio::sys::kAudioHardwareNoError`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/enumerate.rs:10:5
   |
10 |     kAudioHardwareNoError,
   |     ^^^^^^^^^^^^^^^^^^^^^ no `kAudioHardwareNoError` in `sys`

error[E0432]: unresolved import `super::coreaudio::sys::kAudioHardwarePropertyDefaultInputDevice`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/enumerate.rs:11:5
   |
11 |     kAudioHardwarePropertyDefaultInputDevice,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioHardwarePropertyDefaultInputDevice` in `sys`

error[E0432]: unresolved import `super::coreaudio::sys::kAudioHardwarePropertyDefaultOutputDevice`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/enumerate.rs:12:5
   |
12 |     kAudioHardwarePropertyDefaultOutputDevice,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioHardwarePropertyDefaultOutputDevice` in `sys`

error[E0432]: unresolved import `super::coreaudio::sys::kAudioHardwarePropertyDevices`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/enumerate.rs:13:5
   |
13 |     kAudioHardwarePropertyDevices,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioHardwarePropertyDevices` in `sys`

error[E0432]: unresolved import `super::coreaudio::sys::kAudioObjectPropertyElementMaster`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/enumerate.rs:14:5
   |
14 |     kAudioObjectPropertyElementMaster,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioObjectPropertyElementMaster` in `sys`. Did you mean to use `kAudioUnitProperty_ElementName`?

error[E0432]: unresolved import `super::coreaudio::sys::kAudioObjectPropertyScopeGlobal`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/enumerate.rs:15:5
   |
15 |     kAudioObjectPropertyScopeGlobal,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioObjectPropertyScopeGlobal` in `sys`

error[E0432]: unresolved import `super::coreaudio::sys::kAudioObjectSystemObject`
  --> /Users/theodegioanni/.cargo/registry/src/github.com-1ecc6299db9ec823/cpal-0.8.1/src/coreaudio/enumerate.rs:16:5
   |
16 |     kAudioObjectSystemObject,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^ no `kAudioObjectSystemObject` in `sys`

This breaks compatibility for iOS and therefore breaks all iOS projects depending on cpal.
I am currently working on iOS support for the Amethyst game engine, so I assume I will have to look into that myself. However, I do not have the necessary experience nor time to fix all those issues to bring back iOS support.

@Moxinilian
Copy link
Author

Moxinilian commented May 9, 2018

I believe audio is too different on iOS compared to macOS, and that it deserves its own parallel implementation. This will also make sure people updating the macOS backend will not overwrite the iOS backend forgetting about the important special cases.
I am currently making a draft of such implementation.

@Moxinilian
Copy link
Author

Moxinilian commented May 13, 2018

I am wondering if cpal could use AVFoundation on iOS. This API is more modern and as far as I can tell offers everything cpal needs, in an easier to use form.

@mtak-
Copy link

mtak- commented Jan 17, 2019

@Moxinilian How far did you get in your implementation?

@tanis2000
Copy link

@Moxinilian you should have a look at how SDL2 is doing this for iOS, it would make your job easier

@Moxinilian
Copy link
Author

Moxinilian commented Jan 17, 2019

@mtak- not far at all, I got busy somewhere else. If this is something you want to tackle please do as my experience with Apple audio APIs is limited. But I will have to do it sooner than later.
@tanis2000 thanks!

@mtak-
Copy link

mtak- commented Jan 18, 2019

@Moxinilian I think I'm going to use OpenAl since that works on android (via openalsoft) and iOS. I'll spend a little time trying to cobble together a cpal backend, but if that fails, I'll roll a custom openal backed sound library.

@Moxinilian
Copy link
Author

Considering cpal does not have an Android backend that could kill two birds with one stone.
What do you think would prevent it to be integrated as a cpal backend?
Does it bring tradeoffs (like some overhead maybe)?

@mtak-
Copy link

mtak- commented Jan 18, 2019

OpenAL soft uses OpenSL ES on the backend on android, so I suspect it'll be pretty fast.

My concerns are that some issues discussed here #92 (comment) might apply. I don't fully understand the context of what they were talking about, but basically OpenAL is poll based instead of being callback based so there could be some timing issues.

I've just started on the implementation and haven't gotten far enough to test anything. @jpernst or @tomaka might be able to expand more on the potential problems.

@mtak-
Copy link

mtak- commented Jan 24, 2019

@Moxinilian I'm giving up, and rolling a custom audio lib on top of alto. Here's a somewhat working version of cpal with openal as a backend: https://github.com/mtak-/cpal/tree/openal There's a fair amount to cleanup, but it's a decent start.

The current design of cpal has intentional latency which, atleast using openal on iphone5s, is tough to lower enough to be satisfying for sound effects IMHO (e.g. this button was pressed, so make a click noise). If I try to push the latency below around 1/15th-1/20th of a second (every 4th/3rd graphical frame), CPU usage gets high, and iphone5s risks dropping audio frames. There might be a way to fix it, but it seems easier to just roll a custom audio lib at this point.

Related: #205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants