Will Powers
Will Powers

Reputation: 155

Using AUGraphs for Mic input

I am trying to create a streamlined audio application that takes the volume of the mic input from the iPhone and uses that to set the volume of a sound played from another audio unit source.

I would prefer to do all of this using graphs. I don't need any information from the mic other than the volume level, and as mentioned previously, I would like this to be a streamlined solution that has good performance and a minimum of code.

I am investigating a solution that would use an "output" audio type with remoteIO as a subtype, which the documentation says can be used for input or output or both.

I can't seem to find any way to accomplish this using graphs only. I've previously implemented it with AVAudioRecorder, but I'm not happy with that approach. I've looked at the aurioTouch and aurioTouch2 examples, but neither implements the graph approach. Apple's audio documentation states that this is the way to go.

Upvotes: 4

Views: 978

Answers (1)

admsyn
admsyn

Reputation: 1461

Novocaine will probably be the easiest solution for you, as it'll give you data from the mic right away. You'll probably want to take the buffer it gives you and calculate its RMS. This'll give you a rough "how loud is the mic volume right now" answer.

To answer your question from an AUGraph perspective, the trick is that it's difficult to use the RemoteIO as an input to an AUGraph. Technically, a RemoteIO is an output unit, which confuses the AUGraph somewhat. Typically you would use a ring buffer to buffer audio from the RemoteIO's mic input, then feed that into an AUGraph later (i.e. when the head of the AUGraph issues a render callback to your app). Of course, if you get to this point you don't need an AUGraph at all and can just check the audio level at what would be the ring buffer stage.

That said, let's say you have samples coming into your AUGraph. How do you tell how loud they are at a given point? You can use the AUMultiChannelMixer audio unit, which has a metering feature. Just enable the kAudioUnitProperty_MeteringMode property on the input scope, then just check the kMultiChannelMixerParam_PreAveragePower param to see the volume of the audio passing through the mixer at that point (values will be floats from -120 to 0 representing -120dB to 0dB).

Upvotes: 4

Related Questions