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

[coreaudio] Implement Endpoint and Format Enumeration #196

Merged
merged 2 commits into from
Feb 4, 2018

Conversation

mitchmindtree
Copy link
Member

Based on #195.

Also implements proper handling of the given Endpoint in the
macos implementation of the build_voice method.

Updates to the latest coreaudio-sys and coreaudio-rs which include the
additional necessary frameworks.

Also adds a line that prints the name of the default device in the
enumeration.rs example.

Updates the CHANGELOG for this PR.

Closes #194.
Related to #180.

Related external issues:

@mitchmindtree mitchmindtree force-pushed the device_enumeration branch 2 times, most recently from b6212dc to 9d4e357 Compare January 27, 2018 13:55
@mitchmindtree mitchmindtree changed the title [macos] Implement Endpoint and Format Enumeration [coreaudio] Implement Endpoint and Format Enumeration Jan 28, 2018
Based on RustAudio#195.

Also implements proper handling of the given `Endpoint` in the
macos implementation of the `build_voice` method.

Updates to the latest coreaudio-sys and coreaudio-rs which include the
additional necessary frameworks.

Also adds a line that prints the name of the default device in the
`enumeration.rs` example.

Updates the CHANGELOG for this PR.

Closes RustAudio#194.
Related to RustAudio#180.

Related external issues:

- RustAudio/coreaudio-sys#4
- RustAudio/coreaudio-rs#57
@mitchmindtree
Copy link
Member Author

Any chance another macos user could test this on their setup? cc @HybridEidolon @jansol @SirVer

@HybridEidolon
Copy link
Contributor

I will take a look this evening.

@HybridEidolon
Copy link
Contributor

I lied, I wanted to check real quick at work.

Compilation fails on High Sierra on building coreaudio-sys because CoreMIDI headers are missing on my system. Not sure if this is because of a deprecation or something else.

@SirVer
Copy link

SirVer commented Feb 2, 2018

Here is my test log:

Full success on a MacBook Pro, 15 inch, 2017 and Sierra (10.12.6):

$ git clone https://github.com/tomaka/cpal.git && cd cpal 
$ git branch --track mitchmindtree/device_enumeration mitchmindtree/device_enumeration
$ git fetch mitchmindtree
$ git branch --track mitchmindtree/device_enumeration mitchmindtree/device_enumeration
$ git checkout mitchmindtree/device_enumeration
$ cargo build --examples
... lotsa output
$ target/debug/examples/beep
I hear a beep
$ target/debug/examples/enumerate
Default Endpoint:
  Some("Built-in Output")
Endpoints:
1. Endpoint "Built-in Output" Audio formats:
1.1. SupportedFormat { channels: [FrontLeft, FrontRight], min_samples_rate: SamplesRate(44100), max_samples_rate: SamplesRate(44100), data_type: F32 }
1.2. SupportedFormat { channels: [FrontLeft, FrontRight], min_samples_rate: SamplesRate(48000), max_samples_rate: SamplesRate(48000), data_type: F32 }
1.3. SupportedFormat { channels: [FrontLeft, FrontRight], min_samples_rate: SamplesRate(96000), max_samples_rate: SamplesRate(96000), data_type: F32 }

Errors on a MacBook Pro, 15 inch, early 2013 and High Sierra (10.13.3):

$ git clone https://github.com/tomaka/cpal.git && cd cpal 
$ git branch --track mitchmindtree/device_enumeration mitchmindtree/device_enumeration
$ git fetch mitchmindtree
$ git branch --track mitchmindtree/device_enumeration mitchmindtree/device_enumeration
$ git checkout mitchmindtree/device_enumeration
$ cargo build --examples
...
   Compiling coreaudio-sys v0.2.0
error: unexpected close delimiter: `]`
    --> /private/tmp/cpal/target/debug/build/coreaudio-sys-40e6324cdf4d6678/out/coreaudio.rs:2188:33
     |
2188 | #[derive(Copy, Clone)]; 16usize ] , }#[test]
     |                                 ^

error: Could not compile `coreaudio-sys`.

Manually deleting this tests leads to more similar errors in that file, once all are fixed compilation fails because of errors in this generated file. I gave up here.

@mitchmindtree
Copy link
Member Author

Thank you both for testing!

@HybridEidolon interesting! In the documentation I've been able to find Apple mentions that CoreMIDI is not available on iOS but seems to imply that it should be generally be available on macOS. That said, those docs were quite old. I'll do some digging and see if I can find anything about a change for CoreMIDI between Sierra and High Sierra.

What are the results if you build coreaudio-sys with --no-default-features --features "audio_toolbox audio_unit core_audio open_al" (in other words, all the features besides the core_midi one)? Is it just /System/Library/Frameworks/CoreMIDI.framework/Headers that does not exist? Or does the framework itself not exist on your system?

@SirVer it looks like this syntax error is due to an old bug in the way that rustfmt handles unions. What is the result of rustfmt --version on your High Sierra system? Mine is 0.2.16-nightly (the one that the rustup stable target provides) and it seems to work OK. If you update to the rustfmt that rustup manages does the error go away for you?

Do you run into the missing CoreMIDI issue that HybridEidolon mentioned at all?

@mitchmindtree
Copy link
Member Author

I wonder if we should just call .rustfmt_bindings(false) on the bindgen::Builder to reduce the surface area of potential errors anyway? On the other hand, it is quite useful to be able to browse the source of the generated bindings when running cargo doc --open for example, which might be near impossible without rustfmt as I think bindgen puts everything on one line by default.

@HybridEidolon
Copy link
Contributor

The Headers are missing from the system framework. I do have Xcode installed, so it seems odd.

@mitchmindtree
Copy link
Member Author

@HybridEidolon hmm I'm struggling to find why this might be the case. The frameworks reference mentions it should have been around since v10.0. The CoreMIDIServer framework was deprecated in 10.6, but it doesn't mention anything about CoreMIDI itself. The more current looking docs don't seem to say anything about it being deprecated either.

If you search your system for CoreMIDI.h do you find anything? A total shot in the dark, but I wonder if for some reason its in ~/Library/Frameworks/ instead? I don't see why it would be though.

Is MIDI input/output working on your system at all at the moment? I wonder if you could test with this, although you'd probably need some MIDI device to do so.

@mitchmindtree
Copy link
Member Author

For starters, I'll update this PR to remove all unnecessary features that CPAL itself does not currently use. This should leave only the audio_unit and core_audio features - at least this might help us move forward with this PR and allow us to address the CoreMIDI framework issue in coreaudio-sys itself.

@mitchmindtree
Copy link
Member Author

@HybridEidolon I've updated this PR to only link to the necessary AudioUnit and CoreAudio frameworks - I wonder if you'll have more luck now?

@SirVer
Copy link

SirVer commented Feb 3, 2018

Reading through the comments I revisited the Errors on a MacBook Pro, 15 inch, early 2013 and High Sierra (10.13.3):

$ cargo uninstall rustfmt
    Removing /Users/sirver/.cargo/bin/cargo-fmt
    Removing /Users/sirver/.cargo/bin/rustfmt
$ cargo uninstall rustfmt-nightly
    Removing /Users/sirver/.cargo/bin/rustfmt-format-diff
$ rustup component add rustfmt-preview --toolchain=nightly
info: downloading component 'rustfmt-preview'
info: installing component 'rustfmt-preview'
$ git pull
remote: Counting objects: 19, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 19 (delta 10), reused 18 (delta 9), pack-reused 0
Unpacking objects: 100% (19/19), done.
From github.com:mitchmindtree/cpal
   3952c44..d482d64  device_enumeration -> mitchmindtree/device_enumeration
 + d847b03...d2e56e1 channel_position   -> mitchmindtree/channel_position  (forced update)
 + cd44abf...1ce498b rename_types       -> mitchmindtree/rename_types  (forced update)
Updating 3952c44..d482d64
Fast-forward
 Cargo.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
$ cargo build --examples
runs through without errors
$ target/debug/examples/beep
I hear a beep
$ target/debug/examples/enumerate
Default Endpoint:
  Some("Built-in Output")
Endpoints:
1. Endpoint "Built-in Output" Audio formats:
1.1. SupportedFormat { channels: [FrontLeft, FrontRight], min_samples_rate: SamplesRate(44100), max_samples_rate: SamplesRate(44100), data_type: F32 }
1.2. SupportedFormat { channels: [FrontLeft, FrontRight], min_samples_rate: SamplesRate(48000), max_samples_rate: SamplesRate(48000), data_type: F32 }
1.3. SupportedFormat { channels: [FrontLeft, FrontRight], min_samples_rate: SamplesRate(88200), max_samples_rate: SamplesRate(88200), data_type: F32 }
1.4. SupportedFormat { channels: [FrontLeft, FrontRight], min_samples_rate: SamplesRate(96000), max_samples_rate: SamplesRate(96000), data_type: F32 }

So full success on both of my systems now.

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

Successfully merging this pull request may close these issues.

4 participants