简体   繁体   中英

Using AVAudioEngine to record mic and sound effects

I'm using AVAudioEngine to record input from the microphone as well as various sound effects to a single file. While recording, the sound is played back through the speakers, via the engine's outputNode. However, this causes a weird effect for users recording with headsets, since they can hear their own voice played back through the speakers/headphones. Therefore, I only wish to output the sound of the sound files through the speakers and not the sound coming from the microphone.

I haven't found a way to achieve this using AVAudioEngine, however. My latest attempt involved hooking up the sound file nodes to the main mixer, and have them played back using the mixer's outputNode and then hooking up the microphone to a second mixer. The mainMixer then sends its output (the audio from the sound files) to this mixer, which I installed a tap on, for writing the audio to my file.

However, mixer nodes only have one output, which means that no sound at all was played back through the speakers, since the mainMixer had been altered to route it's output to the second mixer instead of to the outputNode.

Here's my engine layout:

soundfileNode ----> mainMixer ---> outputNode (speaker)
                        |
                        |
                        v
inputNode (mic) --> secondaryMixer ---> tap (write to file)

How can I solve my problem? Any ideas?

Update:

I'm now using AVAudioConnectionPoint to split the output from the mainMixer. However, the sound files played back (and recorded) sound distorted, with lots of crackling and noise. This only occurs when I install a tap on my secondary mixer, for writing to the output file. Has anyone else experienced this?

However, mixer nodes only have one output

Aha, but that's not true. You're looking for AVAudioConnectionPoint. By connecting to an array of connection points, you split the output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM