0

I am using AVAudioEngine to record a user's voice while applying some real-time effects to the voice.

As I need the user to be able to hear his own voice during the session, I've hooked up my AVAudioEngine graph to look like the following:

inputNode -> audio effect node -> mainMixerNode (tap installed here) -> outputNode

I also installed a node tap at the mainMixerNode to pull the processed voice and save it into a buffer.

All these work fine when I have the headphones plugged in. However, when I unplug the headphones halfway during the recording, I experience a lot of sharp echoes and feedback. I guess this is due to the fact that the voice is being sent to the output for playing which in turn reinforces the user's original input voice.

Is there a good way to minimize the feedback in the event that the headphones are unplugged halfway during the recording session? I've thought of dynamically disconnecting the mainMixerNode so that the voice will not route to the output during unplugging, but I am not sure if there is a better way.

Ideally I would like to have a single audio buffer at the end of each recording session, no matter how many times the user plugs and unplugs the headphones within the session.

Any thoughts? Thanks in advance!

Ken Toh
  • 3,581
  • 1
  • 21
  • 29

1 Answers1

0

use other Node to change volume to 0, then connect to outputNode.

audioEngine.connect(mainMixerNode, to: otherNode, format: yourFormat)
otherNode.volume = 0
audioEngine.connect(otherNode, to: outputNode, format: yourFormat)
Unpxre
  • 1
  • 1