3

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?

rodskagg
  • 3,827
  • 4
  • 27
  • 46

1 Answers1

2

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • AVAudioConnectionPoint was introduced in iOS9 it seems, and I need to support iOS8 as well... – rodskagg Mar 10 '16 at 22:35
  • 2
    Then you're up a creek. AVAudioConnectionPoint was introduced in iOS 9 _exactly_ to solve this problem. Conversely, therefore, in iOS 8, you _can't_ split the output and you can just forget all about it. – matt Mar 10 '16 at 22:57
  • How does AVAudioConnectionPoint work? The documentation is practically non-existent. – rodskagg Mar 11 '16 at 08:54
  • @andlin Congrats on figuring this out! I have a very similar problem. If I link you to my stackoverflow question can you take a quick look at my small snippet of AVAudioEngine code? – user3344977 Mar 13 '16 at 06:38
  • I'm still having some problems, however. For example, the sound files I play and record to the file sound distorted when I'm using AVAudioConnectionPoint. The problem seems to be the actual tap on the mixer. If I remove the tap, the sound is fine, but that means nothing is written to my output file, of course... – rodskagg Mar 13 '16 at 08:57