Hi Bill,
Thanks for the quick response.
Is it correct that I can use:
kMultiChannelMixerParam_PreAveragePower
for level metering? What range of values will I be reading from it? 0.0 to 1.0?
I followed your advice on checking for an error with this code:
UInt32 meteringMode = 1; setupErr = AudioUnitSetProperty(mixerUnit, kAudioUnitProperty_MeteringMode, kAudioUnitScope_Input, 0, &meteringMode, sizeof(meteringMode) ); [self throwIfErr:setupErr withMessage:@"Couldn't turn on metering"];
and I am indeed getting an error:
exception: Couldn't turn on metering (OSStatus: -10879 [Å’ˇˇ])
Here comes the newbie question - how to I troubleshoot this? On Apr 20, 2009, at 3:24 PM, William Stewart wrote: On Apr 19, 2009, at 10:19 AM, Andrew Nalband wrote: I'm extremely new to programming so forgive me for the simple concepts I am obviously missing here. I'm attempting to monitor the input level of the iPhone's mic and use it to trigger a an OpenGL visual effect and audio event when the mic level is hot.
I've been reading through this code which connects
RemoteIO-->MultliChannelMixer -->RemoteIO: http://pastie.org/445149
I believe I can monitor the level with: kMultiChannelMixerParam_PreAveragePower on the Multichannel mixer. I'm using this code to enable metering:
UInt32 meteringMode = 1; AudioUnitSetProperty(mixerUnit, kAudioUnitProperty_MeteringMode, kAudioUnitScope_Input, 0, &meteringMode, sizeof(meteringMode) );
I'm then attempting to use an NSTimer to regularly fire code that monitors the input level:
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 0.50
target:self selector: @selector (updateAudioLevels)
userInfo: nil repeats:YES]; self.vibrationTimer = timer;
This is the method I'm calling as the selector:
-(void) updateAudioLevels {
OSStatus err;
float amps[1];
err = AudioUnitGetParameter(mixerUnit, kMultiChannelMixerParam_PreAveragePower, kAudioUnitScope_Input, 0, &s[0]);
NSLog("%f", amps[0]);
}
I'm getting some errors here since this method doesn't know about the mixerUnit.
You are pretty right here so far. As long as the mixer unit is in the signal chain and is getting audio You should *always* check the result code - your set property to enable metering just assumes that that works. You don't describe what errors you get back from the GetParameter call
I've been reading through Technical Note TN2104 and wondering if I should be using the AudioUnitEvent api.
wrong path - it isn't going to help you here
Can I call an Objective-C method if kMultiChannelMixerParam_PreAveragePower crosses a certain threshold? Am I way off here? Is there a better way to do this? If I'm clearly missing something - can anyone recommend some documentation to read?
Not sure I understand the question.
The ultimate goal is low latency monitoring of the mic input level.
Bill
|