Re: using non-default output units
Re: using non-default output units
- Subject: Re: using non-default output units
- From: Kurt Bigler <email@hidden>
- Date: Sun, 20 Oct 2002 00:22:49 -0700
With the help of some off-list support from Kurt Revis, and some trial and
error (and yes, the documentation helped), I found answers to my questions.
I was able to modify an app based on the output unit sample code, namely
Developer/Examples/CoreAudio/Services/DefaultOutputUnit/UsingDefaultNoAC.cpp
to allow the app to select the output device instead of using the default
output. It turned out to be _almost_ as easy as adding this code after the
call to AudioUnitInitialize...
AudioDeviceID deviceId = 0x1B/*the device ID that I wanted*/;
verify_noerr(err = AudioUnitSetProperty(
theOutputUnit,
kAudioOutputUnitProperty_CurrentDevice,
kAudioUnitScope_Global,
0,
&deviceId,
sizeof(deviceId)));
...which permitted the output device for the AU to be set to something other
than the current default device. Unfortunately this did not prevent the
default AU from switching away from the app's preferred device whenever the
user switches the default output (e.g. using the system sound preferences
panel).
So it was necessary to use FindNextComponent and OpenAComponent to open the
V1 HALOutput AU instead of the default output unit by replacing the
OpenDefaultAudioOutput(&theOutputUnit) call with:
ComponentDescription searchDesc;
searchDesc.componentType = kAudioUnitComponentType;
searchDesc.componentSubType = kAudioUnitSubType_Output;
searchDesc.componentManufacturer = kAudioUnitID_HALOutput;
searchDesc.componentFlags = 0;
searchDesc.componentFlagsMask = 0;
Component theAUComponent = FindNextComponent (NULL, &searchDesc);
if (theAUComponent != NULL)
err = OpenAComponent (theAUComponent, &theOutputUnit);
Result: the modified sample app can now take charge of switching devices by
using the AudioUnitSetProperty above. The HALOutput AU appears to default
_initially_ to the default output device if you don't set the
kAudioOutputUnitProperty_CurrentDevice property, but does not track
subsequent user changes to the default output.
This glosses over the issue of how to usefully determine the desired
deviceId at run-time. I used the displayhaldeviceinfo sample code to
discover how to get the list of device id's and the name for each id, from
which a menu could be built, for example.
Now there is the question of the choice of V1 rather than the V2 audio unit.
It is curious that OpenDefaultAudioOutput opens the V1 default output unit,
although this is certainly helpful for compatibility, because as it turns
out, the sample code AS IS would not work with the V2 unit, since that code
uses the kAudioUnitProperty_SetInputCallback mechanism to set the callback
routine (MyRenderer) that computes the audio _input_ to the output AU, and
that mechanism has been replaced by a different callback mechanism in V2
units.
The question remains: would it be a good idea to change over to the V2
scheme? Does the V1 approach perform just as well, and can we expect it to
stay around? I did not look into the coding changes that would have been
necessary to switch to V2 but it appeared to be a slightly more complex
callback interface. I believe (correct me if I am wrong) that the standard
format conversions would permit the V2-based renderer to continue to
generated audio in interleaved format (if that were more convenient), but
are there other implications, and does Apple plan to change this sample code
to use the V2 scheme?
Thanks,
Kurt Bigler
on 10/19/02 12:40 AM, Kurt Bigler <email@hidden> wrote:
>
I can't seem to find any information in the documentation or the archives
>
about how to use audio units to output to devices other than the default
>
device. In other words I want the application to be able to choose the
>
output device independent of the current default device.
>
>
I expected to be able to find an apple audio unit component that I could
>
instantiate and some how tell it to associate itself with a particular
>
output device, after which I could hopefully use it just like I would use
>
the default audio unit.
>
>
Thanks in advance for any info.
>
>
-Kurt Bigler
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.