1

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.

My question is, which one should I be using, and why? I tried to figure out the other two, but I can't find a single example. Any help would be appreciated!

MysteryPancake
  • 1,235
  • 1
  • 15
  • 42

1 Answers1

2

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.

marius
  • 1,862
  • 1
  • 15
  • 15