Skip to content

Instantly share code, notes, and snippets.

@sneakyness
Created September 26, 2012 21:47
Show Gist options
  • Save sneakyness/3790826 to your computer and use it in GitHub Desktop.
Save sneakyness/3790826 to your computer and use it in GitHub Desktop.
// get sample rate of the default input device
OSStatus MyGetDefaultInputDeviceSampleRate(Float64 *outSampleRate)
{
OSStatus error;
AudioDeviceID deviceID = 0;
// get the default input device
AudioObjectPropertyAddress propertyAddress;
UInt32 propertySize;
propertyAddress.mSelector = kAudioHardwarePropertyDefaultInputDevice;
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
propertyAddress.mElement = 0;
propertySize = sizeof(AudioDeviceID);
error = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &propertySize, &deviceID);
if (error) return error;
// get its sample rate
propertyAddress.mSelector = kAudioDevicePropertyNominalSampleRate;
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
propertyAddress.mElement = 0;
propertySize = sizeof(Float64);
error = AudioHardwareServiceGetPropertyData(deviceID, &propertyAddress, 0, NULL, &propertySize, outSampleRate);
return error;
}
@ryanmcgrath
Copy link

Well doesn't this look like fun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment