Remap AVplayer playback
What I want to do is take the AVAsset output samples corresponding to the audio file (no video involved) and send them to the sound effect class which takes the sample block, and I want to be able to do this in real time.
I'm currently looking at the AVfoundation reference and programming guide link, but I don't see a way to redirect the output of the player element and send it to the effects class, and from there send the converted samples to the Audio Output (using AVAssetReaderAudioMixOutput?) And hear it from there. I can see that the AVAssetReader class gives me a way to get a block of samples using
[myAVAssetReader addOutput:myAVAssetReaderTrackOutput];
[myAVAssetReaderTrackOutput copyNextSampleBuffer];
but Apple documentation indicates that the AVAssetReader class was not created and should not be used for real-time situations. Does anyone have any suggestion on where to look, or if I have the right approach?
source to share
MTAudioProcessingTap is perfect for this. Using AVPlayer, you can choose not to block the samples yourself with AVAssetReaderOutput, and then render them yourself in an audio queue or with an audio device.
Instead, attach an MTAudioProcessingTap to your AVAsset's audio inputs, and you will be presented with block samples that can easily be thrown into the effects block.
Another benefit of this is that it will work with AVAssets derived from URLs that other Apple APIs (such as Audio File Services) may not always open, such as the iPod custom library. Plus, you get all the functionality, like audio interrupt porting, that AVPlayer provides for free that you would otherwise have to implement manually if you went with the AVAssetReader solution.
To set up a tap, you have to set up some callbacks that the system calls when appropriate during playback. You can find the complete code for this treatment in this manual .
source to share
AVAssetReader
not ideal for real-time use as it handles the decoding for you and copyNextSampleBuffer
can block random periods of time on various occasions .
Speaking of which, AVAssetReader
can be used just fine in a producer thread feeding a circular buffer. It depends on your desired use, but I have successfully used this method to feed the RemoteIO output and handle my effects / signals in the RemoteIO callback.
source to share