How to use AUAudioUnitPreset

I'm trying to figure out how we are supposed to use AUAudioUnitPreset. There's not much documentation about it. Are we supposed to subclass AUAudioUnitPreset and encode/decode the parameter values using NSCoding protocol?


My conclusion is that my AUAudioUnit is supposed return an array of factoryPresets consisting of my preset objects and later on host can change the active preset by calling setCurrentPreset on my AUAudioUnit subclass and passing me back the preset object.


After trying that idea and creating MyPreset subclass of AUAudioUnitPreset I get the following exception:


<NSXPCConnection: 0x7fbaf4900200> connection from pid 19053: Warning: Exception caught during decoding of received reply to message 'valueForProperty:reply:', dropping incoming message and calling failure block.

Exception: Exception while decoding argument 0 (#1 of invocation):

<NSInvocation: 0x7fbaf242ea10>

return value: {v} void

target: {@?} 0x0 (block)

argument 1: {@} 0x0

Exception: decodeObjectForKey: class "MyPreset" not loaded or does not exist


This is with Xcode7-beta3 and I used the host app from the AudioUnit sample code provided by Apple. Also, note that MyPreset is just a shell and it doesn't impliment any methods/properties. I assumed that it would just work.


Any ideas?

Answered by theanalogkid in 30945022

I asked our resident "Core Audio Plumber" to confirm my understanding of this object and here's some information I hope you find helpful.


An AUAudioUnitPreset is just a translation of AUPreset -- a name and number that refer to a "canned" preset.


typedef struct AUPreset {

SInt32 presetNumber;

CFStringRef presetName;

} AUPreset;


NS_CLASS_AVAILABLE(10_11, 9_0)

@interface AUAudioUnitPreset : NSObject <NSSecureCoding>


/! @property number

@brief The preset's unique numeric identifier.

*/

@property (NS_NONATOMIC_IOSONLY) NSInteger number;


/! @property name

@brief The preset's name.

*/

@property (NS_NONATOMIC_IOSONLY, copy) NSString *name;

@end


When you talk about saving and restoring parameters values, that's the fullState dictionary which maps to the V2 kAudioUnitProperty_ClassInfo property. See AUAudioUnit.h & AudioUnitProperties.h


factoryPresets should return an array of AUAudioUnitPreset(s). A host can display these and let a user select a preset though currentPreset which accepts a selected AUAudioUnitPreset. These two are the bridged v2 kAudioUnitProperty_FactoryPresets and kAudioUnitProperty_PresentPreset properties respectively.

Accepted Answer

I asked our resident "Core Audio Plumber" to confirm my understanding of this object and here's some information I hope you find helpful.


An AUAudioUnitPreset is just a translation of AUPreset -- a name and number that refer to a "canned" preset.


typedef struct AUPreset {

SInt32 presetNumber;

CFStringRef presetName;

} AUPreset;


NS_CLASS_AVAILABLE(10_11, 9_0)

@interface AUAudioUnitPreset : NSObject <NSSecureCoding>


/! @property number

@brief The preset's unique numeric identifier.

*/

@property (NS_NONATOMIC_IOSONLY) NSInteger number;


/! @property name

@brief The preset's name.

*/

@property (NS_NONATOMIC_IOSONLY, copy) NSString *name;

@end


When you talk about saving and restoring parameters values, that's the fullState dictionary which maps to the V2 kAudioUnitProperty_ClassInfo property. See AUAudioUnit.h & AudioUnitProperties.h


factoryPresets should return an array of AUAudioUnitPreset(s). A host can display these and let a user select a preset though currentPreset which accepts a selected AUAudioUnitPreset. These two are the bridged v2 kAudioUnitProperty_FactoryPresets and kAudioUnitProperty_PresentPreset properties respectively.

Thanks theanalogkid. After I posted the question I realised that I didn't need to sublcass AUAudioUnitPreset and it was only suppsoed to hold a preset name and number information. So, cheers for confirming it.

How to use AUAudioUnitPreset
 
 
Q