Re: How to use AudioComponentRegister()?
Re: How to use AudioComponentRegister()?
- Subject: Re: How to use AudioComponentRegister()?
- From: patrick machielse <email@hidden>
- Date: Sat, 08 Mar 2014 01:10:07 +0100
Op 5 mrt. 2014, om 22:57 heeft patrick machielse <email@hidden> het volgende geschreven:
> My application needs to be sandboxed. The application uses 1 bundled AudioUnit.
>
> In accordance with TN 2247 I've added:
>
> <key>sandboxSafe</key>
> <true/>
>
> to my bundled audio unit's Info.plist.
>
> https://developer.apple.com/library/mac/technotes/tn2247
[]
> I think I'm mis-understanding AudioComponentRegister().
To answer my own question, this is the solution that ended up working for me:
****
#import <AudioToolbox/AudioToolbox.h>
// standard type of an AU factory function
typedef AudioComponentPlugInInterface *(*FactoryFunctionPtr)(const AudioComponentDescription *inDesc);
// AudioComponentRegister() callback
static AudioComponentPlugInInterface *HostPitchShiftUnitFactory(const AudioComponentDescription *inDesc)
{
static CFBundleRef bundle = NULL;
static FactoryFunctionPtr factoryFunction = NULL;
if ( !factoryFunction ) {
if ( !bundle ) {
CFURLRef bundleURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("PitchShiftUnit"), CFSTR("component"), NULL);
if ( !bundleURL ) { printf("PitchShiftUnit.component not found\n"); return NULL; }
bundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);
CFRelease(bundleURL);
}
if ( !bundle ) { printf("Could not create component bundle\n"); return NULL; }
CFArrayRef components = CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("AudioComponents"));
if ( components && CFArrayGetCount(components) ) {
CFDictionaryRef componentInfo = CFArrayGetValueAtIndex(components, 0);
CFStringRef factoryFunctionName = CFDictionaryGetValue(componentInfo, CFSTR("factoryFunction"));
if ( !factoryFunctionName ) { printf("Could not locate factrory function name\n"); return NULL; }
factoryFunction = CFBundleGetFunctionPointerForName(bundle, factoryFunctionName);
}
if ( !factoryFunction ) { printf("Could not locate factory function\n"); return NULL; }
}
return factoryFunction(inDesc);
}
/* adapted from TN2247
* https://developer.apple.com/library/mac/technotes/tn2247
*/
void RegisterBundledAudioUnit(NSString *name)
{
// fill out the AudioComponentDescription
AudioComponentDescription description = { 0 };
description.componentType = kAudioUnitType_FormatConverter;
description.componentSubType = 'ptsh';
description.componentManufacturer = 'Miik';
description.componentFlags = kAudioComponentFlag_SandboxSafe;
AudioComponentRegister(&description, CFSTR("Mixed In Key: PitchShift Unit"), 0x00010000, HostPitchShiftUnitFactory);
}
****
In hindsight, it seems that something like 'CFBundleGetFunctionPointerForName' is what's being used by the system frameworks to load and instantiate Audio Units. Ideally, I'd really like to be isolated from that layer.
Other thoughts:
- It's sad that the Audio Component API documentation is stuck in 2011 and doesn't even list AudioComponentRegister():
https://developer.apple.com/library/mac/documentation/AudioUnit/Reference/AudioComponentServicesReference/Reference/reference.html
- It's also a bit sad that I didn't even need to add the 'sandboxSafe' info dictionary key to load may bundled (Audio Component) AU into my sandboxed app (I do have the temporary host exemption). Almost anything seems to do, as long as it isn't Component Manager based?
- I would have expected having to sign my Audio Units in order to make them Sandbox ready. Now that bundled .frameworks have that requirement too.
- AudioComponentRegister() is still a bit of a mystery to me. What use are the 'name' and 'version' parameters, and where are they used?
- AudioComponentRegister() is awkward to use — at least in my application. Here I need to hard code information about the AU both _before_ calling AudioComponentRegister() AND in the callback. RegisterComponentFileRef(), taking a file location and simply gathering the info directly from the AU itself, is so much more pleasant, and results in code that is easier to re-use.
patrick
--
Patrick Machielse
Hieper Software
http://www.hieper.nl
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