• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Enumerating and switching audio devices (NEWBIE)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Enumerating and switching audio devices (NEWBIE) (From: Lorenzo Thurman <email@hidden>)
 >Re: Enumerating and switching audio devices (NEWBIE) (From: Michael Thornburgh <email@hidden>)

  • Prev by Date: Re: Enumerating and switching audio devices (NEWBIE)
  • Next by Date: Re: MyVolumeUnit example.. does not 'pan'
  • Previous by thread: Re: Enumerating and switching audio devices (NEWBIE)
  • Next by thread: Re: Re: Enumerating and switching audio devices (NEWBIE)
  • Index(es):
    • Date
    • Thread