I want to decode audio from a buffer or audio file and write it to a buffer for playback (I don't want to route it directly to the hardware) on macOS and iOS. I want to be able to convert it to another format too if supported. What classes/services should I use from AVFoundation/CoreAudio API to do that?
AVFoundation
has classes that can do all these things.
AVAudioFile
for decoding audio from a file to PCM (AVAudioPCMBuffer
).AVAudioConverter
for converting between formatsAVAudioEngine
with an AVAudioPlayerNode
that can play back AVAudioPCMBuffer
sYou might insetad use CoreAudio
and AudioToolbox
if you need more control over latency, devices or if you run into bugs in AVFoundation
.