Attention! For Japanese customers, my Japanese blog might help.

Aug 5, 2016

I wanted an AUGenericView for handemade v3 AudioUnit

NOTE: This is the english version of my Japanese article.

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:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    AudioComponentDescription desc;
    desc.componentType = 'aufx';
    desc.componentSubType = 'vbrt';
    desc.componentManufacturer = 'Symi';
    [AVAudioUnit instantiateWithComponentDescription:desc
                                             options:0
                                   completionHandler:^(__kindof AVAudioUnit * _Nullable audioUnit, NSError * _Nullable error) {
                                       self.unit = audioUnit;
                                       AudioUnit unit = [audioUnit audioUnit];
                                       AUGenericView *view = [[AUGenericView allocinitWithAudioUnit:unit];
                                       view.frame = self.window.contentView.frame;
                                       [self.window.contentView addSubview:view];
                                   }];
}
As a result:


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:
AUParameter *freqParameter = [AUParameterTree createParameterWithIdentifier:VibratoParameterIdentifierFrequency
                                                                           name:VibratoParameterNameFrequency
                                                                        address:VibratoParameterAddressFrequency
                                                                            min:0
                                                                            max:.01
                                                                           unit:kAudioUnitParameterUnit_Hertz
                                                                       unitName:nil
                                                                          flags:kAudioUnitParameterFlag_IsReadable | kAudioUnitParameterFlag_IsWritable
                                                                   valueStrings:nil
                                                            dependentParameters:nil];
I again ran the host app, then
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.