Re: Selecting audio output devices
Re: Selecting audio output devices
- Subject: Re: Selecting audio output devices
- From: Thomas Hass <email@hidden>
- Date: Sun, 22 Jul 2012 08:47:44 -0400
I recently had to figure this out myself. You'll want to become very familiar with everything in AudioHardware.h in the CoreAudio framework. Those are all the functions and properties that you will use to get information about each device.
These are the steps I took:
1) Build a list of audio device objects where each object contains a device's AudioDeviceID, number of input channels, number of output channels, available sample rates, and a human readable name that you can present to the user. You will use AudioHardware.h for this. You start by getting an array of AudioDeviceIDs from the system like so:
AudioObjectPropertyAddress devicesProperty = {
kAudioHardwarePropertyDevices,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
}
UInt32 dataSize = 0;
AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &devicesProperty, 0 , NULL, &dataSize);
UInt32 numDevices = dataSize/sizeof(AudioDeviceID);
AudioDeviceID allDeviceIDs[numDevices];
AudioObjectGetPropertyData(kAudioObjectSystemObject, &devicesProperty, 0, NULL, &dataSize, allDeviceIDs);
// Each AudioDeviceID in this array now represents an audio device on your system. You can now use this id
// to get attributes about each device via the properties in AudioHardware.h.
2) Present the human-readabable names to the user.
3) Once the user has picked one. Setup an AUHAL output unit and set its current device property to the AudioDeviceID that corresponds to the user-selected device. Also note that you can use the kAudioDevicePropertyStreamConfiguration property to know what the buffer list in the IOProc will look like for a device.
Unfortunately, CAPlayThrough was the only example code I could find when I was learning this stuff as well. This definitely requires a lot more code than on iOS. My advice would be to do your best, and then ask specific questions as you get stuck.
-Thomas Hass
On Sun, Jul 22, 2012 at 5:01 AM, Andy Robinson
<email@hidden> wrote:
Yes, thanks. The only thing is, it says "Runtime Requirements: Mac OS X v10.7 or later".
However I will take a look at it, to see if the parts I want might run on 10.6.
I've also been recommended to look at
https://github.com/liscio/CAPlayThrough
Regards,
Andy Robinson
On 21/07/12 22:19, Jason Perkins wrote:
Try the CAPlay example:
http://developer.apple.com/library/mac/#samplecode/CAPlayThrough/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004443
On Jul 20, 2012, at 6:22 AM, Andy Robinson wrote:
Hello, is there any sample code showing how to select and use different audio output devices?
For OS 10.6 and later.
______________________________
_________________
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
_______________________________________________
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