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; |
| } |