Re: API for switching audio output device or disabling output altogether
Re: API for switching audio output device or disabling output altogether
- Subject: Re: API for switching audio output device or disabling output altogether
- From: Roger Thornhill <email@hidden>
- Date: Fri, 11 Dec 2009 19:04:11 -0500
On Fri, Dec 11, 2009 at 3:53 PM, William Stewart <email@hidden> wrote:
>
> On Dec 10, 2009, at 10:49 PM, tahome izwah wrote:
>
>> Not sure if this helps but you can get the current default system
>> output device via
>>
>> AudioDeviceID currentDevice;
>> UInt32 propsize = sizeof(AudioDeviceID);
>> OSStatus err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
>> &propsize, ¤tDevice);
>>
>> In order to find the built-in device you iterate through all audio
>> devices calling
Sorry if this is a basic question, but how do you get the list of
audio devices in order to iterate through them? I tried searching the
coreaudio documentation, but couldn't find the relevant information.
>>
>> UInt32 transportType;
>> UInt32 propsize=sizeof(AudioDeviceID);
>> OSStatus err = AudioDeviceGetProperty(deviceID, 0, false,
>> kAudioDevicePropertyTransportType, &propsize, &transportType);
>>
>> on each device. The built-in audio hardware has transportType ==
>> kIOAudioDeviceTransportTypeBuiltIn. You can set it system wide via
>> this call when required:
>>
>> OSStatus err = AudioHardwareSetProperty(kAudioHardwarePropertyDefaultOutputDevice,
>> sizeof(AudioDeviceID), &outputDevice);
Does the built in audio hardware remain constant? For example, when
you insert an optical cable into the audio output port on the Mac, a
hardware switch is triggered and the output device now becomes
"Digital Out". Will the default output device now be changed to
"Digital Out", or will it still refer to the internal speakers?
>>
>> So you should be able to switch your device as required. Whether or
>> not this is good practice from a user experience POV I do not know -
>
> It is not. Applications should not be setting the default device as this is something the user controls.
>
> It is also completely irrelevant to the question that was asked.
This is the problem I want to rectify. You mention that the default
device is something the user controls, however, once you insert a
cable into the audio output port, the option for "Internal Speakers"
is removed and replaced by "Digital Out". I'd like to give back this
option to the user, and allow them to select "Internal Speakers",
rather than force them to physically remove the audio cable. I
understand that in most cases, it would be ideal for the system to
automatically switch to the digital or line out when an audio cable is
inserted, but I can't understand why there's no option to forcefully
switch back to the Macs internal speakers if you so desired.
Rogueamoeba makes a free program called SoundSource which allows you
to switch between various audio inputs and outputs, although it still
doesn't allow you to switch to the Internal Speakers once an audio
cable is inserted. I'd like to know if this is even possible to
accomplish. Does the act of plugging in the cable remove the internal
speakers from the list of available output devices, making it
impossible to switch to the internal speakers through software?
>> 2009/12/11 Roger Thornhill <email@hidden>:
>>>
>>> When an optical cable is inserted into the audio output port on an iMac, a
>>> hardware switch is triggered and the sound output device is automatically
>>> changed to "Digital Out". I'd like to know if there's a way to prevent this
>>> from happening by programmatically disabling or enabling the optical output.
>
>
>>> Right now the only way to switch from optical out to internal speakers is
>>> to physically disconnect the cable from the optical output port.
>
> Yes - this is the default behaviour - the gesture is interpreted by the system as a deliberate request by the user to route the audio to what they've just plugged in.
>
> The real question then is why would you NOT want this to switch?
The reason I don't want to switch is when you're using your Mac as a
media centre, which is becoming more and more popular these days. For
example, you've got your Mac hooked up to your TV through HDMI and
connected to your amplifier through an optical audio cable. This
works great for watching movies, but what happens when you just want
to use your Mac as a regular desktop machine? In my case, the
speakers are located next to the TV, in a separate room from the
computer, so it's less than ideal to have the sound permanently routed
to these speakers, versus being able to easily switch back to the
Mac's internal speakers. The remedy for this is to simply unplug the
audio cable from the back of the computer, but this can be a nuisance
when the port is not easily accessible, or you don't want to risk
damaging the port by constantly inserting and removing the audio plug.
So the ideal situation is to leave the optical cable plugged in, but
have the ability to select the output device through software. I'm
actually surprised that Apple doesn't provide a way to do this. I
understand that Apple has implemented this hardware switch to make
things easier and more transparent for the user, which I fully
support, but I don't understand why they would completely disable the
ability to select the internal speakers through some advanced
configuration option.
It seems that the solution most people are using is to get some type
of USB Audio interface, such as a Griffin iMic, and leave the optical
cable permanently plugged into the back of the Mac. This way, you can
switch to the USB Audio Interface when you want to use your computer
as a desktop machine, or switch to the Digital Out when you want to
use it as a media centre. This workaround wouldn't be necessary if
there was some software method to select the internal speakers,
regardless of whether an audio cable is connected or not.
So the real question is whether this is possible to implement via
software. I've read quite a few other posts* regarding end users
requesting this ability, and most of the messages refer to the fact
that this isn't possible since the audio cable triggers a hardware
based switch. I'm not sure if this is accurate though, since the
hardware switch must instruct the OS to actually change the audio
output device, so I figure there must be some way to duplicate this
same behaviour through another application. What remains to be seen
is whether this is available through a public API, or if you need to
use private methods to enable this functionality.
This is hopefully where you guys might be able to provide me with some
insight. I appreciate your responses, thanks for taking the time to
help me out!
Roger
* for those interested, here's some posts regarding users requesting
this software switching ability. In the first link, the user has
actually damaged the audio output port by repeatedly inserting and
removing the plug.
http://discussions.apple.com/thread.jspa?threadID=2247396&tstart=0
http://www.mac-forums.com/forums/apple-desktops/140940-optical-audio-out-software-enable-disable.html
http://forums.macosxhints.com/showthread.php?t=54515
http://forums.macosxhints.com/showthread.php?t=95978
http://www.instructables.com/answers/How-do-you-play-audio-through-both-internal-speake/
http://forums.macrumors.com/showthread.php?t=520071
http://forums.macrumors.com/showthread.php?t=312184
_______________________________________________
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