title: Export AVAsset with fading by AVAudioMix
body: <p>The task is to trim audio asset and make fade effect. Here is my code:</p>
  
  <pre><code>+ (void)exportAsset:(AVAsset *)asset trimTimeRange:(CMTimeRange)trimTimeRange fadeDuration:(CMTime)fadeDuration
  {
      NSArray *tracks = [asset tracksWithMediaType:AVMediaTypeAudio];
      AVAssetTrack *track = [tracks objectAtIndex:0];
  
      CMTimeRange fadeInTimeRange = CMTimeRangeMake(trimTimeRange.start, fadeDuration);
  
      AVMutableAudioMixInputParameters *exportAudioMixFadeInInputParameters = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:track];
      [exportAudioMixFadeInInputParameters setVolumeRampFromStartVolume:0.0 toEndVolume:1.0 timeRange:fadeInTimeRange];
  
      CMTime startFadeOutTime = CMTimeMake(trimTimeRange.start.value + trimTimeRange.duration.value - fadeDuration.value, 1000);
      CMTimeRange fadeOutTimeRange = CMTimeRangeMake(startFadeOutTime, fadeDuration);
  
      AVMutableAudioMixInputParameters *exportAudioMixFadeOutInputParameters = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:track];
      [exportAudioMixFadeOutInputParameters setVolumeRampFromStartVolume:1.0 toEndVolume:0.0 timeRange:fadeOutTimeRange];
  
      AVMutableAudioMix *exportAudioMix = [AVMutableAudioMix audioMix];
      exportAudioMix.inputParameters = @[exportAudioMixFadeOutInputParameters, exportAudioMixFadeInInputParameters];
  
      NSString *path = [NSString stringWithFormat:@"%@/%@", [PathHelper applicationDocumentsDirectory], filenameM4A];
  
      AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:asset presetName:AVAssetExportPresetAppleM4A];
      exportSession.audioMix = exportAudioMix;
      exportSession.outputURL = [NSURL fileURLWithPath:path];
      exportSession.outputFileType = AVFileTypeAppleM4A;
      exportSession.timeRange = trimTimeRange;
  
      [exportSession exportAsynchronouslyWithCompletionHandler:nil];
  }
  </code></pre>
  
  <p>It's very strange, but if I pass input parameters for audio mix like this</p>
  
  <pre><code>exportAudioMix.inputParameters = @[exportAudioMixFadeInInputParameters, exportAudioMixFadeOutInputParameters];
  </code></pre>
  
  <p>I get 1st result (take a look at the picture)
  If like this</p>
  
  <pre><code>exportAudioMix.inputParameters = @[exportAudioMixFadeOutInputParameters, exportAudioMixFadeInInputParameters];
  </code></pre>
  
  <p>I get 2nd result.
  Looks like second parameter is ignoring. Can anyone explain this behavior?</p>
  
  <p><img src="https://i.stack.imgur.com/H7Gni.png" alt="enter image description here"></p>