on IOS you can use [[AVAudioSession sharedInstance] sampleRate];
to retrieve the current sample rate used by the audio driver. AVAudioSession does not exist on OSX, so I am wondering how to achieve the same thing on OSX, as I could not find much on the topic.
Thanks
Okay,
after some more in depth research Audio Hardware Services seems to do the trick on OSX. Here is some example code:
//get the default output device
AudioObjectPropertyAddress addr;
UInt32 size;
AudioDeviceID deviceID = 0;
addr.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
addr.mScope = kAudioObjectPropertyScopeGlobal;
addr.mElement = 0;
size = sizeof(AudioDeviceID);
err = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject, &addr, 0, NULL, &size, &deviceID);
//get its sample rate
addr.mSelector = kAudioDevicePropertyNominalSampleRate;
addr.mScope = kAudioObjectPropertyScopeGlobal;
addr.mElement = 0;
size = sizeof(Float64);
Float64 outSampleRate;
err = AudioHardwareServiceGetPropertyData(deviceID, &addr, 0, NULL, &size, &outSampleRate);
//if there is no error, outSampleRate contains the sample rate
Unfortunately, not as easy as the IOS version, but does the job! This will give you the sample rate settings you can change in the OSX Audio-MIDI-Setup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With