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

Fix input and output scope and element usage. #104

Merged
merged 1 commit into from
Apr 4, 2024

Conversation

akhudek
Copy link
Contributor

@akhudek akhudek commented Aug 29, 2023

Getting input from a microphone needs to use the Output scope and Input Element, and sending audio to a speaker needs to use the Input Scope and Output Element. See Figure 1-3 in https://developer.apple.com/library/archive/documentation/MusicAudio/Conceptual/AudioUnitHostingGuide_iOS/AudioUnitHostingFundamentals/AudioUnitHostingFundamentals.html

This PR also removes a bit of redundancy in the code by reusing input and output stream functions in the callback code.

…crophone needs to use the Output scope and Input Element, and sending audio to a speaker needs to use the Input Scope and Output Element. See Figure 1-3 in https://developer.apple.com/library/archive/documentation/MusicAudio/Conceptual/AudioUnitHostingGuide_iOS/AudioUnitHostingFundamentals/AudioUnitHostingFundamentals.html
@HEnquist
Copy link
Contributor

HEnquist commented Apr 2, 2024

Getting input from a microphone needs to use the Output scope and Input Element, and sending audio to a speaker needs to use the Input Scope and Output Element.

These changes look reasonable, but I'm a bit confused why things are working without them. I have done both playback and capture and not noticed any problems. What is it that does not work currently?

@akhudek
Copy link
Contributor Author

akhudek commented Apr 2, 2024

I no longer have the test code I was using, but audio capture wasn't working for me without these changes. I was instantiating a device via its id rather than using the default capture device. This is on a 2021 macbook pro with Sonoma.

@HEnquist
Copy link
Contributor

HEnquist commented Apr 3, 2024

I tried modifying the feedback_interleaved example to test this.

I replaced the start of the main to get the device ids by name, like this:

fn main() -> Result<(), coreaudio::Error> {
    let input_device_id = get_device_id_from_name("MacBook Air Microphone").unwrap();
    let output_device_id = get_device_id_from_name("MacBook Air Speakers").unwrap();

This seems to work just fine on my M1 Air with the latest macOS. Do you remember if this is similar to your test code?

@akhudek
Copy link
Contributor Author

akhudek commented Apr 3, 2024

I believe I was using set_stream_format along with input_stream_format. The feedback_interleaved example actually manually sets the scope and element as in this pr which is likely why it works:

https://github.com/RustAudio/coreaudio-rs/blob/master/examples/feedback.rs#L63

These changes make the stream format correct (which is why they can be used in render_callback.rs instead of manually getting the format with the correct scope and element as before).

@HEnquist
Copy link
Contributor

HEnquist commented Apr 3, 2024

Ah yes that makes sense! I set these manually in my code too, so this would explain why I haven't had any trouble.

Can some maintainer please merge this and publish a new version?

@simlay
Copy link
Member

simlay commented Apr 4, 2024

Can some maintainer please merge this and publish a new version?

That's me! Based on the changes here and in #109, these look like small breaking changes so I'll submit a PR bumping from 0.11.3 to 0.12.0.

@simlay simlay merged commit 3233a54 into RustAudio:master Apr 4, 2024
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.

3 participants