AVAudioEngine for recording microphone and sound files and preventing feedback

I am trying to use AVAudioEngine to record microphone sound and sound files (which play when the user clicks a button). I connected the inputNode microphone to mainMixer, as well as a couple of AVAudioPlayerNodes to play audio files. I installed tap on mainMixer to capture the sound and write it to a file. Sound is also sent to the speaker.

This is the main layout of my sound graph:

------------- mic --> | | | mainMixer | --> speaker file --> | | ------------- | tap (writes to file) 

By default, sound is played through the receiver / ear speaker, not the speaker at the bottom of the iPhone.

Unfortunately, this means that the sound output through the speaker is too low and not heard - I want the user to be able to hear sound files as they play and record. Therefore, I would like the sound effects to be reproduced through the lower speaker.

If I change the audio session to use the lower speaker for playback, I get a feedback loop since the microphone input and the sounds played by the lower speaker are raised by the microphone again. (Curiously, this works on the iPad, where no feedback loop is created. The iPad does not have a headphone jack, of course, so the sound is always heard through the main speaker on this device.)

I have two questions:

  • Can I route only audio files to the bottom speaker? I do not want to output microphone sound through any of the speakers. However, sound from the microphone and sound files must be recorded.

  • Why am I getting a feedback loop on the iPhone, but not on the iPad? Is it possible to output all the sound through the lower speaker without receiving feedback?

+5
source share

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


All Articles