1

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));
Tim
  • 4,560
  • 2
  • 40
  • 64
Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131

2 Answers2

2

Stopping the Audio Unit is not absolutely required, although it does reduce the power consumption of the app, and thus should be done if stopping playback for any length of time in order to conserve the users battery life. Not stopping the Audio Unit has the advantage that starting to record again will happen with many milliseconds of lower latency, which can be important in some applications. The alternative to stopping the audio unit is to discard samples in the record callback and to fill the buffer with silence (zeros) in the play callback.

Uninitialization only needs to be done if you later went to reinitialize the audio unit with a different configuration.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
0

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.

Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159