RemoteIO Glitch With Sound Recognition Feature

My app is using RemoteIO to record audio. It doesn’t do any playback. RemoteIO seems to be broadly compatible with the new Sound Recognition feature in iOS14, but I’m seeing a glitch when sound recognition is first enabled.

If my app is started and I initialise RemoteIO, and then turn on Sound Recognition (say via control centre), the RemoteIO input callback is not called thereafter, until I tear down the audio unit and set it back up. So something like the following:
  • Launch app

  • RemoteIO is initialised and working, can record

  • Turn on Sound Recognition via Settings or control centre widget

  • Start recording with already-set up RemoteIO

  • Recording callback is never again called

  • Though no input callbacks are seen, kAudioOutputUnitProperty_IsRunning is reported as true, so the audio unit thinks it is active

  • Tear down audio unit

  • Set up audio unit again

  • Recording works

  • Buffer size is changed, reflecting some effect on the audio session of the Sound Recognition feature

I also noticed that when Sound Recognition is enabled, I see several (usually 3) AVAudioSession.routeChangeNotifications in quick succession. When Sound Recognition is disabled while RemoteIO is set up, I don’t see this problem. I’m allocating my own buffers so it’s not a problem with their size.

What could be going on here? Am I not handling a route change properly? There doesn’t seem to be a reliable sequence of events I can catch to know when to reset the audio unit.



The only fix I’ve found here is to hack in a timer that checks for callback activity shortly after starting recording, and resets the audio unit if no callback activity is seen. Better than nothing, but not super reliable.

Accepted Reply

The answer to this, ultimately, was to ditch using RemoteIO and use AVAudioEngine. It has a TON of its own quirks (have fun hunting down crashes when you make even the tiniest mistake with connections and formats or engine lifecycle), but if you respond to the engine reset event it mostly continues working when Sound Recognition is toggle on and off.

Replies

The answer to this, ultimately, was to ditch using RemoteIO and use AVAudioEngine. It has a TON of its own quirks (have fun hunting down crashes when you make even the tiniest mistake with connections and formats or engine lifecycle), but if you respond to the engine reset event it mostly continues working when Sound Recognition is toggle on and off.