Audio Unit level metering on the iPhone
Audio Unit level metering on the iPhone
- Subject: Audio Unit level metering on the iPhone
- From: email@hidden
- Date: Sat, 18 Apr 2009 23:09:00 -0700 (PDT)
- Importance: Normal
Hello all,
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, but I'm
having a hard time getting things working. 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 obviously doesn't know
about the mixerUnit.
I've been reding through Technical Note TN2104 and trying to grasp the Run
Loop concept. All this Carbon stuff is quite foreign to my OOP mind.
Should I be using an Audio Unit event listener? Can I then use this to
monitor the input level and 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?
The ultimate goal is low latency monitoring of the mic input level.
-Andrew
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden