Updating UI from DSP in AUv3

I'm building an AUv3 and have the basics running. One thing I can't figure out tho, is how to query the DSP from the main thread via the kernelAdapter. There's a getParameter method in the kernelAdapter, but how can I call that from the main thread? Can it be called thru the ParameterTree? I need to poll the DSP at regular interval and update UI based on the values.


Thanks in advance!

Replies

In the simple case of a VU-Meter you can

1) Add a parameter for your VU-Meter
Code Block
 AUParameter *vuParam = [AUParameterTree createParameterWithIdentifier:@"vu-meter"
                                                                    name:@"vu-meter"
                                                                address:vuParamAddress
                                                                     min:0.f
                                                                     max:1.f
                          unit:kAudioUnitParameterUnit_LinearGain
                                                             unitName:nil                                  flags:kAudioUnitParameterFlag_IsReadable | kAudioUnitParameterFlag_MeterReadOnly
                                                        valueStrings:nil
dependentParameters:nil];

NOTE:- 'kAudioUnitParameterFlag_MeterReadOnly' marks the parameter appropriately to avoid caching.

2) Implement getting the parameter value in the DSPKernel
Code Block
AUValue getParameter(AUParameterAddress address) {
        switch (address) {
            ......
            case vuParamAddress:
                return vuFloatValue;
            default: return 0.f;
        }
}


3) In the view controller, get a reference to the parameter from the parameter tree.

self.meter = [self.audioUnit.parameterTree parameterWithAddress:vuParamAddress];

NOTE:- You will need to update this reference in the case the parameterTree is rebuilt for any reason.

4) Create a timer as suggested and poll the parameter(s) value at an appropriate frequency.
Code Block        
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1
                                                 target:self
                                            selector:@selector(vuMeterCallback)
                                               userInfo:nil
                                                repeats:YES];


5) Update your widgets value in the timer callback to trigger a re-draw.
Code Block
-(void)meterUpdate {
const AUValue vuMeterValue = self.meter.value;
self.vuMeterWidget.progress = vuMeterValue;
}


Thank you for this answer! It seems that after creating that AUParameter, the only way getParameter is called in the DSPKernel is after setParameter is called on the AUParameter (UI side). So I have to first do a setParameter (with an arbitrary value since its not being sent to the read only value on the DSP side) and then immediately after retrieve the value with your Step 5 example.