How can I get PCM sample data from an audio clip in iOS?

I need to extract PCM audio samples from a WAV file (or any other format) in iOS. I would also like to get the same data from a live recording using a microphone.

Can this be done using AVFoundation, or do I need to use a lower level CoreAudio APIs? An example in Swift would be greatly appreciated. I'm just looking for a basic Floats array that matches the individual audio samples that will be used to process the signals.

+4
source share
1 answer

AVFoundationincludes a class called AVAssetReaderthat can be used to get audio data from a sound file. https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVAssetReader_Class/index.html#//apple_ref/occ/instm/AVAssetReader/addOutput :

However, the easiest way is to use advanced audio file services and functions ExtAudioFileRead: https://developer.apple.com/library/prerelease/ios/documentation/MusicAudio/Reference/ExtendedAudioFileServicesReference/index.html#//apple_ref/c/func/ExtAudioFileRead

Advanced Audio File Services is an API C, so you have to deal with a call from Swift.

+3
source

All Articles