As shown in the title, I wanted to get an AUGenericView of my own v3 AudioUnit.
I could not get the view from an AUAudioUnit object because AUGenericView's initializer requires the instance of type 'AudioUnit'.
As far as I know, there was no way to get an AudioUnit instance from an AUAudioUnit object.
While, I could get an AudioUnit instance from AVAudioUnit object, which was supplied by AVFoundation framework.
So I tried to make a host app and made the AUGenericView of my own AU.
The code is following:
As a result:- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {AudioComponentDescription desc;desc.componentType = 'aufx';desc.componentSubType = 'vbrt';desc.componentManufacturer = 'Symi';[AVAudioUnit instantiateWithComponentDescription:descoptions:0completionHandler:^(__kindof AVAudioUnit * _Nullable audioUnit, NSError * _Nullable error) {self.unit = audioUnit;AudioUnit unit = [audioUnit audioUnit];AUGenericView *view = [[AUGenericView alloc] initWithAudioUnit:unit];view.frame = self.window.contentView.frame;[self.window.contentView addSubview:view];}];}
Altough I could get the view, no parameters were displayed.
By comparing my AU with FilterDemo, I found that it was needed to give kAudioUnitParameterFlag_IsReadable and kAudioUnitParameterFlag_IsWritableAUParameter flags when creating AUParameter for my AU as follows:
I again ran the host app, thenAUParameter *freqParameter = [AUParameterTree createParameterWithIdentifier:VibratoParameterIdentifierFrequencyname:VibratoParameterNameFrequencyaddress:VibratoParameterAddressFrequencymin:0max:.01unit:kAudioUnitParameterUnit_HertzunitName:nilflags:kAudioUnitParameterFlag_IsReadable | kAudioUnitParameterFlag_IsWritablevalueStrings:nildependentParameters:nil];
YES! I could finally get a view like Apple's AUs!
By the way, when I set only a writable flag to Depth and only a readable flag to Frequency,
the generic view were:
Depth was adjustable, but Frequency was not.Hmm...
Summary:
- When you want to get an AUGenericView for v3 AU in your host app, you can get an 'AudioUnit' instance from an AVAudioUnit object.
- As for your own AU, you need to set kAudioUnitParameterFlag_IsReadable | kAudioUnitParameterFlag_IsWritable flags when creating AUParameter.
That's all for today.