2

I've prepared an AVPlayer and AVAssetExportSession which both use the same MTAudioProcessingTap yet I cannot get either to call the process callback. I'd appreciate some help with identifying why the callback is not being called while others are.

I am simply trying to process audio with a tap so that it increases the levels by a scale to increase the volume. I am able to add the audioMix which includes the audioTapProcessor but when I run the app it only calls the init and finalize callbacks.

What is missing which is preventing the process callback from being run?

    var callbacks = MTAudioProcessingTapCallbacks(
        version: kMTAudioProcessingTapCallbacksVersion_0,
        clientInfo: UnsafeMutableRawPointer(Unmanaged<AnyObject>.passUnretained(self as AnyObject).toOpaque()),
        init: tapInit,
        finalize: tapFinalize,
        prepare: tapPrepare,
        unprepare: tapUnprepare,
        process: tapProcess)

    var tap: Unmanaged<MTAudioProcessingTap>?
    let status = MTAudioProcessingTapCreate(kCFAllocatorDefault, &callbacks, kMTAudioProcessingTapCreationFlag_PostEffects, &tap)
    if status != noErr {
        debugPrint("Failed to create audio processing tap.")
        throw BoosterExporterError.failure
    }

I've published code on GitHub with the full project. Linked below.

https://github.com/brennanMKE/Boosted/blob/master/BoosterKit/BoosterPlayer.swift#L153

Brennan
  • 11,546
  • 16
  • 64
  • 86

1 Answers1

1

Your need to find out the audio trackID and set it to AVMutableAudioMixInputParameters to make it work.

AVMutableAudioMixInputParameters *audioMixInputParameters = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:self.audioAssetTrack];

See Apple's example here https://developer.apple.com/library/content/samplecode/AudioTapProcessor/Listings/AudioTapProcessor_MYAudioTapProcessor_m.html#//apple_ref/doc/uid/DTS40012324-AudioTapProcessor_MYAudioTapProcessor_m-DontLinkElementID_6

Allan Zero
  • 11
  • 2