Reputation: 67234
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.
Upvotes: 4
Views: 937
Reputation: 67234
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 ;
}
Upvotes: 6