Using AUGraphs to Enter Mic

I am trying to create a simplified audio application that takes the volume of the microphone input from the iPhone and uses it to set the volume of the sound played from another source of the audio device.

I would rather do it all using graphs. I do not need any information from the microphone, except for the volume level, and, as mentioned earlier, I would like it to be an optimized solution with good performance and minimal code.

I am studying a solution that will use the β€œoutput” type of sound with remoteIO as a subtype, which, according to the documentation, can be used for input or output, or both.

I cannot find a way to do this using only graphics. I previously implemented it using AVAudioRecorder, but I am not happy with this approach. I looked at aurioTouch and aurioTouch2 examples, but none of them use a graphical approach. Apple audio documentation claims this is the way to go.

+4
source share
1 answer

Novocaine will probably be the easiest solution for you, as it will immediately give you microphone data. You probably want to take the buffer that it will give you and calculate its RMS . This will give you an approximate answer "how loud the microphone sounds now."

To answer your question from an AUGraph point of view, the trick is that it is difficult to use RemoteIO as an entrance to AUGraph. Technically, RemoteIO is an output unit that confuses AUGraph somewhat. Usually you should use a ring buffer to buffer the sound from the RemoteIO microphone input, and then transfer it to the AUGraph later (i.e. when the AUGraph chapter issues a render callback to your application). Of course, if you get to this point, you don’t need AUGraph at all, and you can just check the sound level on what the ring buffer stage will be.

However, let's say you have samples included in your AUGraph. How do you say how loud they are at the moment? You can use the AUMultiChannelMixer audio unit, which has a measurement function. Just turn on the kAudioUnitProperty_MeteringMode property in the input area, and then just check kMultiChannelMixerParam_PreAveragePower to see the volume of sound passing through the mixer at this point (values ​​will have values ​​from -120 to 0, representing -120 dB to 0 dB).

+4
source

Source: https://habr.com/ru/post/1440653/


All Articles