Question

It is easy in iOS to get the number of bytes in a loaded .wav file:

UInt64 dataSize = 0;  // dataSize
UInt32 ps = sizeof(UInt64); // property size
if( AudioFileGetProperty(fileId, kAudioFilePropertyAudioDataByteCount, &ps, &dataSize) )
  puts( "error retriving data chunk size" );
return dataSize ;

But in the documentation I cannot seem to find any information on how to determine the sampling rate of a PCM wave file.

Was it helpful?

Solution

I found the answer using AudioStreamBasicDescription. All you have to do is:

UInt32 getAudioDataSamplingRate( AudioFileID fileId )
{
  AudioStreamBasicDescription bsd;
  UInt32 ps = sizeof(AudioStreamBasicDescription) ;
  if( AudioFileGetProperty(fileId, 
      kAudioFilePropertyDataFormat, &ps, &bsd) )
    puts( "error retriving af basic description" );
  return bsd.mSampleRate ;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top