Reading raw audio samples from WAV files
The most common .WAV files are just a 44 byte header followed by 16-bit or 2 byte little-endian raw PCM audio samples. If you have one of those types of files, on a little-endian CPU (x86,ARM,etc.), you just need to skip the first 44 bytes, then read and convert short ints to floats.
As you discovered, to do this you need to first get the file’s data format and then create a client data format at the file’s sample rate but with your desired sample size and type. It really boils down to one extra function call which in the world of Core Audio isn’t much.
Read more here: Source link