I'm currently using an AVAudioPCMBuffer to play a .wav file in a simple game. However, when checking the documentation for it, I came across two other types of buffers I never saw anywhere else, the ones in the title: AVAudioBuffer and AVAudioCompressedBuffer.
Which buffer should I be using, and why? Any help would be appreciated!
AVAudioBuffer
is the superclass of AVAudioPCMBuffer
and AVAudioCompressedBuffer
.
You shouldn't have to deal with AVAudioBuffer
it in practice, normally you just use its subclasses.
AVAudioPCMBuffer
is to be used for playing uncompressed, PCM encoded data (such as what a .wav file contains)AVAudioCompressedBuffer
supports different compressed formats (see Supported Audio file formats in iPhone)For your specific use case, I'd suggest using a simpler way to play the file: AVAudioFile(forReading: URL)
which you can directly feed into a AVAudioPlayerNode
using scheduleFile(_:, at:)
which would automatically handle the buffering.