2

My code is based on this example and a stop function is already implemented, there are functions to uninitialize and stop the audio unit:

    AudioOutputUnitStop(toneUnit);
    AudioUnitUninitialize(toneUnit);
    AudioComponentInstanceDispose(toneUnit);
    toneUnit = nil;

In the example I linked to a pause function is not necessary since there's only one frequency being played so there's no difference between pause and stop. In my implementation however, I'm playing a range of different frequencies and I want to be able to pause playback.

Any ideas how this is done?

justin
  • 104,054
  • 14
  • 179
  • 226

2 Answers2

2
  • fade out (~10ms) the AUs' output, feed the output silence after the fade
  • remember the position you stopped reading your input signal
  • reset the AUs before you resume
  • resume from the position you recorded above (here, a fade in of the input signal to the AUs would be also be good)
justin
  • 104,054
  • 14
  • 179
  • 226
0

You can try writing 0 to the buffer when you playback. It is effectively a pause. Here's some code that you can use within the playback callback.

   NSLog(@"Playing silence!");

   for (int i = 0 ; i < ioData->mNumberBuffers; i++){
    //get the buffer to be filled
    AudioBuffer buffer = ioData->mBuffers[i];
    UInt32 *frameBuffer = buffer.mData;

    //loop through the buffer and fill the frames
       for (int j = 0; j < inNumberFrames; j++){
           frameBuffer[j] = 0;
       }
   }
lppier
  • 1,927
  • 3
  • 24
  • 62