ios10audiounitremoteio

RemoteIO configuration at runtime


I have a RemoteIO unit setup that gets input from microphone and plays it. The playback can be enabled or disabled anytime with a tap of a button. My question is does the call to enable or disable playback requires audio unit to stop, uninitialize and then configure or stopping & uninitializing is not required at all? This is the sample code I use to enable or disable playback at runtime when RIO is running.

/* Are these two lines required or not???*/
[self stopIOUnit];
AudioUnitUninitialize(mAudioUnit);


 int flag = enable? 1 : 0;
// play on io on the output bus
OSStatus   status = AudioUnitSetProperty(mAudioUnit,
                              kAudioOutputUnitProperty_EnableIO,
                              kAudioUnitScope_Output,
                              0, /*output*/
                              &flag,
                              sizeof(flag));

Solution

  • To enabled and disable the audio unit, it is sufficient to call AudioOutputUnitStop() and AudioOutputUnitStart(). You only need AudioUnitUninitialize() and AudioUnitInitialize() if you wish to change the unit's state as well (and enabled/disabled doesn't appear to be considered "state").

    From the AudioUnitUninitialize() documentation:

    Usually, the state of an audio unit (such as its I/O formats and memory allocations) cannot be changed while an audio unit is initialized.