title: save the audio file in the background
body: <p>I have an app that changes the pitch of the audio when the pitch button is selected, now i am using <code>installTapOnBus</code> to save the file but this method gets invocated after i press the pitch button therefore only part of the audio is saved, i want to save the whole audio no matter when the pitch button is selected, is there any way</p>
  
  <p>This method is used to play the audio</p>
  
  <pre><code>-(void)playAudio
  {
      NSError *err = nil;
  
      audioEngine = [[AVAudioEngine alloc] init];
      AudioFileplayer = [[AVAudioPlayerNode alloc] init];
      pitch = [[AVAudioUnitTimePitch alloc] init];
      reverb = [[AVAudioUnitReverb alloc] init];
      [audioEngine stop];
      [AudioFileplayer stop];
      [audioEngine reset];
  
      file = [[AVAudioFile alloc] initForReading:[NSURL URLWithString:[self filePath]] error:&amp;err];
  
  
      [audioEngine attachNode:AudioFileplayer];
  
      [audioEngine attachNode:pitch];
      [audioEngine attachNode:reverb];
  
      [audioEngine connect:AudioFileplayer to:reverb format:nil];
      [audioEngine connect:reverb to:pitch format:nil];
      [audioEngine connect:pitch to:audioEngine.outputNode format:nil];
      [reverb loadFactoryPreset:AVAudioUnitReverbPresetLargeRoom2];
  
   [AudioFileplayer scheduleFile:file atTime:nil completionHandler:^{
          AudioFileplayer = nil;
      }];
  
      [audioEngine prepare];
      [audioEngine startAndReturnError:&amp;err];
  
      if (err != nil) {
          NSLog(@"An error occured");
      }
  
      [AudioFileplayer play];
  
  
  
  }
  </code></pre>
  
  <p>and this method to save the pitch effected audio</p>
  
  <pre><code>-(void)saveEffectedAudioToFolder
  {
  NSError *error;
  if (audioEngine) {
  
  
       pitchEffect.pitch = 1000;
  
      AVAudioFormat  * commonFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32 sampleRate:44100 channels:2 interleaved:NO];
  
      //
      AVAudioFile *outputFile = [[AVAudioFile alloc] initForWriting:[NSURL URLWithString:[self filePath1]] settings:commonFormat.settings error:&amp;error];
      //
  
  
      if (error) {
          NSLog(@"Error is 1 %@",[error localizedDescription]);
  
  
      }
      [pitchEffect  installTapOnBus:0 bufferSize:4096 format:commonFormat block:^(AVAudioPCMBuffer *buffer, AVAudioTime *when)
       {
  
           if (outputFile.length &lt; file.length)
           {//Let us know when to stop saving the file, otherwise saving infinitely
               NSError *error;
  
               NSAssert([outputFile writeFromBuffer:buffer error:&amp;error], @"error writing buffer data to file, %@", [error localizedDescription]);
  
           }else{
               audioEngine = nil;
               [pitchEffect removeTapOnBus:0];//if we dont remove it, will keep on tapping infinitely
  
           }
  
       }
  
  
       ];
  }
  
  }
  </code></pre>
  
  <p>any workaround would be helful</p>