How do you get the sampling rate of AudioFileID?

On iOS, it is easy 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 seem to be unable to find any information on how to determine the sampling rate of the PCM wave file.

+4
source share
1 answer

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 ; } 
+5
source

All Articles