-
Notifications
You must be signed in to change notification settings - Fork 365
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
Conversation
@@ -0,0 +1,109 @@ | |||
//! Feeds back the input stream directly into the output stream. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more or less a straight copy of the feedback example, I changed latency to 1000ms as I found it easier to test
7121667
to
ce7a2a0
Compare
This should be mostly good to go except for new release in coreaudio-sys (and land + release in coreaudio-rs) |
Oh maybe I need to add some kind of CI check for iOS? |
246568f
to
d2f72f4
Compare
Exciting stuff @MichaelHills! Just to clarify, the next step we're waiting on is RustAudio/coreaudio-rs#72 right?
Yes that would be great, especially if it also included a build step for the iOS example to ensure that all the build-time linking etc continues to work too. After these two steps and getting confirmation from another iOS user that they can get this working I'd be happy to see this land. Then we should open issues for the implementations that are still incomplete, namely the device and supported config enumeration. |
I am still testing all the changes end-to-end across the stack (coreaudio-rs ios example, cpal ios example, bevy ios example) and getting a couple of others to help. On newer devices which default to 48KHz sample rate there was an issue. I think I have resolved it, but I also have an iPhone 11 now so I should be able to test this myself directly when I get a chance. Once all issues have been ironed out, will push a new release on coreaudio-sys, merge the coreaudio-rs, then this PR will be ready to go.
Yep I can add that. I think there's an example of doing an Xcode build from CLI in the bevy ios example I can follow.
Sounds good. :)
Yeah this stuff needs AVAudioSession, just adding I'm also a bit unclear on actually the setting of sample rate for iOS. In the coreaudio-rs and cpal ios samples I can't seem to change the sample rate and have the feedback sample work properly. It underruns, the 1s latency evaporates and the feedback is staticy. It was my understanding that the RemoteIO device automatically employs sample rate converters when setting the ASBD, I need to go read the docs again. In any case, sticking to default (44.1 on old devices, 48 on new) seems to work fine. |
a2b2b5f
to
e250279
Compare
I've rebased onto master, had some merge conflicts so I re-applied the differences manually. I compared my diff against the original diff (using vimdiff, diff of diffs!) and verified that I re-applied it correctly. I added iOS to CI as well. All that remains is to publish coreaudio-rs, then get help to re-test one last time and merge. :) |
a7800b4
to
fef7937
Compare
I had to change the iOS CI to only build for |
fef7937
to
3b2ed60
Compare
Note that the CI does do |
206b37a
to
841ea2b
Compare
Okay this is ready for final review/testing. @naithar are you able to help me test the For the cpal example you should be able to speak into the mic and hear your own voice play back with 1s delay. Would be good to check macos still works as well:
Oh I think examples are broken in cpal atm so you'll need this to run them
I'll re-do a full sweep of testing across macOS (Catalina), iPhone 6, 11, and an iPad soon as I can. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll test this example out on my Macbook and iPhone but from looking at the xcode setup, this looks good.
It might be obvious to the people working on cpal what to expect with a feedback
example but users of cpal might be less aware. Maybe we could add a small README
in the ios-feedback
directory just saying what to expect (also maybe to install cargo-lipo
as a dependency).
Great work @MichaelHills!
src/host/coreaudio/mod.rs
Outdated
#[cfg(target_os = "macos")] | ||
pub use self::macos::enumerate::{Devices, SupportedInputConfigs, SupportedOutputConfigs}; | ||
#[cfg(target_os = "macos")] | ||
pub use self::macos::{Device, Host, Stream}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what cargo fmt
says but I think it would be more readable to have
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "ios")]
mod ios;
#[cfg(target_os = "macos")]
pub use self::macos::{
enumerate::{Devices, SupportedInputConfigs, SupportedOutputConfigs},
Device, Host, Stream
};
// Same thing for the iOS pub use stuff below.
Double check the exact stuff here. From my experience with conditional compilation, fewer cfg(target_os =
will make things easier for the next person.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes much better, thanks. cargo fmt
seems to prefer to put ios first.
Shameless ping Is it good enough to merge? |
3379c5c
to
986dc12
Compare
@enfipy see the PR description, I just finished re-testing everything and put up the results. As far as I can tell we're good to go. @simlay I addressed your comments, added README + cleaned up the imports. @mitchmindtree originally requested confirmation from one other iOS user. I think it'd be good if someone else can independently verify that macOS still works fine and the iOS example works on a device. One device should be fine, I've done testing across the devices that I have with iPhone earphones (cord / 3.5mm plug) and some SoundPEATS TrueAir2 wireless earphones. I'm not sure how cpal or users of cpal should be handling changes in devices. For example, turning off bluetooth on my iPhone 11 and switching back to inbuilt speaker seems to lead to underflow in the output and it becomes stuttery. Nothing that should block landing initial iOS support of course. |
It works pretty well from my side. Tested on iPhone 5s, iPhone 12, and macOS 11.1 simulator. |
Thanks for testing. Also macOS beep + feedback + record_wav all still fine for me. Sounds like we're good to merge then. 👍 I don't have permissions to merge so now up to the powers that be. |
Awesome stuff @MichaelHills, thanks for all your work on this! |
Excellent. :) Can we publish a new version? Then can finally use it in Bevy which was my original motivation all those months ago haha |
Fixes #224
Creating as a draft to get some early feedback while I clean it up / wait for dependency PRs to land. As per the linked issue, macOS + iOS coreaudio are different in many ways and the APIs for configuration are not the same. iOS uses
AVAudioSession
which doesn't exist on macOS.Here's what I did to get iOS to work:
coreaudio
host tocoreaudio/macos
andcoreaudio/ios
with some shared code and re-export incoreaudio/mod.rs
RemoteIO
audio unit and you're pretty much expected to use "default" configuration.ios-feedback
example to show input + output working (tested on sim + iPhone 6)Dependencies
Testing
Following table for the feedback examples.
I also tested that output works on Bevy on inbuilt speaker + bluetooth earphones on iPhone 11.