iosavfoundationcore-audio

iOS: How to get Audio Sample Rate from AVAsset or AVAssetTrack


After loading an AVAsset like this:

AVAsset *asset = [AVAsset assetWithURL:url];

I want to know what the Sampling Rate is of the Audio track. Currently, I am getting the Audio Track like this:

AVAssetTrack *audioTrack = [[asset tracksWithMediaCharacteristic:AVMediaCharacteristicAudible] objectAtIndex:0];

Which works. But I can't seem to find any kind of property, not even after using Google ;-) , that gives me the sampling rate. How does this work normally ? Is it even possible ? (I start doubting more and more, because Googling is not giving me a lot of information ...)


Solution

  • Found it. I was using the MTAudioProcessingTap, so in the prepare() function I could just use:

    void prepare(MTAudioProcessingTapRef tap, CMItemCount maxFrames, const AudioStreamBasicDescription *processingFormat)
    {
        sampleRate = processingFormat->mSampleRate;
        NSLog(@"Preparing the Audio Tap Processor");
    }