RustAudio / coreaudio-rs

A friendly rust interface to Apple's Core Audio API.
Apache License 2.0
218 stars 44 forks source link

Input Device is not starting in Feedback Examples #99

Closed sainteckes closed 1 year ago

sainteckes commented 1 year ago

In both feedback examples the input device callback is not getting called, although in the same terminal other audio applications get audio input (so it should have microphone access rights).

MacBook Pro 14-inch, 2021 MacOS Ventura 13.2.1

Can anyone reproduce this?

sainteckes commented 1 year ago

Okay it is because the sample rate needs to be the same that is selected in audio midi settings, otherwise the device won't start. Can I force the sample rate to the rate I want to use?

sainteckes commented 1 year ago

I found the functions in cpal. Just for the record: You have to call set_sample_rate(audio_device_id, sample_rate) before starting the stream to be sure the input device is opening. The frame size can be changed with audio_unit.set_property(kAudioDevicePropertyBufferFrameSize, scope, element, Some(&buffer_size)) and the supported range of fram sizes can be obtained with audio_unit.get_property(kAudioDevicePropertyBufferFrameSizeRange, Scope::Global, Element::Output);

For Output Streams: scope = Input and element = Output For Input Streams: scope = Output and element = Input

Actually integrating those functions in the feedback example would be amazing, so users can have a simpler start :)