Created
April 21, 2016 05:15
Retrieval audio devices of yours with CoreAudio HAL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $ clang -framework CoreAudio devices.c | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <CoreAudio/CoreAudio.h> | |
int main(int argc, char *argv[]) { | |
AudioObjectPropertyAddress theAddress = { kAudioHardwarePropertyDevices, | |
kAudioObjectPropertyScopeGlobal, | |
kAudioObjectPropertyElementMaster }; | |
UInt32 theDataSize = 0; | |
OSStatus err; | |
err = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &theAddress, 0, NULL, &theDataSize); | |
if (err != noErr) { | |
return -1; | |
} | |
printf("the data size is %d bytes.\n", theDataSize); | |
UInt32 numOfDevices = theDataSize / (UInt32)sizeof(AudioDeviceID); | |
printf("device count is %d.\n", numOfDevices); | |
AudioDeviceID* deviceIDs = malloc(theDataSize); | |
memset(deviceIDs, 0, theDataSize); | |
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &theDataSize, (void *)deviceIDs); | |
if (err != noErr) { | |
printf("could not get devices %d\n", err); | |
return -1; | |
} | |
for(size_t i = 0; i < numOfDevices; i++) { | |
printf("device %ld is %u.\n", i, deviceIDs[i]); | |
} | |
free(deviceIDs); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment