Re: Enumerating and switching audio devices (NEWBIE)
Re: Enumerating and switching audio devices (NEWBIE)
- Subject: Re: Enumerating and switching audio devices (NEWBIE)
- From: Ethan Funk <email@hidden>
- Date: Mon, 7 Mar 2005 14:15:29 -0700
Here is a good old fashioned C code snippet from a command line application I wrote that returns a list of device names, UIDs, input and output count out a tcp connection. I hope this helps! In this example cs is an opened TCP socket, buf is a char buffer for holding the result to be sent out the TCP socket and size is the length of the buffer. my_send actually send the buffer out the socket.
Ethan...
void ReturnDeviceList(int cs, char *buf, UInt32 size)
{
CFStringRef devUID;
AudioBufferList *bufferlistPtr;
AudioDeviceID* theDeviceList;
UInt32 nChan, theSize, theNumberDevices, i, j;
char str[1024], name[1024];
int tx_length;
OSStatus OSerr;
OSerr = AudioHardwareGetPropertyInfo (
kAudioHardwarePropertyDevices,
&theSize, NULL );
if (OSerr)
return;
theNumberDevices = theSize / sizeof(AudioDeviceID);
theDeviceList = (AudioDeviceID*) malloc(theNumberDevices * sizeof(AudioDeviceID));
theSize = theNumberDevices * sizeof(AudioDeviceID);
OSerr = AudioHardwareGetProperty (
kAudioHardwarePropertyDevices,
&theSize, theDeviceList );
if (OSerr)
return;
0; i<theNumberDevices; i++){ // loop through the list
theSize = sizeof name;
OSerr = AudioDeviceGetProperty(
theDeviceList[i], 0, false,
kAudioDevicePropertyDeviceName,
&theSize, name);
if (OSerr)
return;
theSize = sizeof(CFStringRef);
OSerr = AudioDeviceGetProperty(
theDeviceList[i], 0, false,
kAudioDevicePropertyDeviceUID,
&theSize, &devUID);
CFStringGetCString(devUID, str, sizeof str, CFStringGetSystemEncoding());
tx_length = snprintf(buf, size, "%lu\t%s\t%s\t", theDeviceList[i], name, str);
my_send( cs, buf, tx_length);
CFRelease(devUID);
if (OSerr)
return;
// count outputs
AudioDeviceGetPropertyInfo(
theDeviceList[i], 0, false,
kAudioDevicePropertyStreamConfiguration,
&theSize, NULL);
bufferlistPtr = (AudioBufferList*)malloc(theSize);
nChan = 0;
OSerr = AudioDeviceGetProperty(
theDeviceList[i], 0, false,
kAudioDevicePropertyStreamConfiguration,
&theSize, bufferlistPtr);
if (!OSerr){
for (j=0; j < bufferlistPtr->mNumberBuffers; j++)
nChan = nChan + bufferlistPtr->mBuffers[j].mNumberChannels;
}
free(bufferlistPtr);
tx_length = snprintf(buf, size, "%lu\t", nChan);
my_send( cs, buf, tx_length);
// count inputs
AudioDeviceGetPropertyInfo(
theDeviceList[i], 0, true,
kAudioDevicePropertyStreamConfiguration,
&theSize, NULL);
bufferlistPtr = (AudioBufferList*)malloc(theSize);
nChan = 0;
OSerr = AudioDeviceGetProperty(
theDeviceList[i], 0, true,
kAudioDevicePropertyStreamConfiguration,
&theSize, bufferlistPtr);
if (!OSerr){
for (j=0; j < bufferlistPtr->mNumberBuffers; j++)
nChan = nChan + bufferlistPtr->mBuffers[j].mNumberChannels;
}
free(bufferlistPtr);
tx_length = snprintf(buf, size, "%lu\n", nChan);
my_send( cs, buf, tx_length);
}
if (theDeviceList) free(theDeviceList);
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden