Fixes to allow changing stream format
Hey @plietar thanks for the PR :)
Can you explain a little more the reasoning behind changing the Scope of the audio unit property request from Output to Input? Is this a bug fix? How exactly does the behaviour change?
Sure, disclaimer though, I've got very little experience with CoreAudio. My understanding is that each unit has an input and an output format. For a sink only the input format matters.
Before this patch, setting the format worked (set_stream_format changes the input), but setting a render callback would not, since it was checking against the output (https://github.com/RustAudio/coreaudio-rs/blob/master/src/audio_unit/render_callback.rs#L387-L394)
This PR makes stream_format and set_stream_format consistent. If this library ever supports audio sources, then this should be revisited (ie make these two methods take a scope, or make two more methods)
I've recently been working on using this crate for audio input and encountered the scope problem, which is actually a bit bigger than just this change. It took a lot of searching but Figure 1-3 in https://developer.apple.com/library/archive/documentation/MusicAudio/Conceptual/AudioUnitHostingGuide_iOS/AudioUnitHostingFundamentals/AudioUnitHostingFundamentals.html makes it clear.
For rendering audio, your application should use the input scope and element 0 (aka element::Output). For taking audio from the microphone you need to use the output scope and element 1 (aka element::Input).