Hi, Assuming AIFF format you have got uncompressed lpcm samples there. You can simply determine how much packets in that file by calling AudioFileGetProperty with kAudioFilePropertyAudioDataPacketCount property id. To determine length of audio file you should do the following:
packets_per_second = sample_rate / frames_per_packet; seconds = total_packet / packets_per_second For constant bit rate formats frames_per_packet will be equal to 1. Best regards, Yuri. On Mar 1, 2015, at 5:51, Patrick J. Collins <[email protected]> wrote: >> either you want to use some new-fangled language and don't know how to do >> heap allocation or do you don't understand how to >> get the number of samples in the file? > > That's correct.. I am not sure about a lot of how to properly get > information like that via coreaudio's api... > > This would be my code to read samples to memory: > > AudioFileID file; > CheckError(AudioFileOpenURL((__bridge CFURLRef)self.url, > kAudioFileReadPermission, > 0, > &file), > "AudioFileOpenURL failed"); > > AudioStreamBasicDescription dataFormat; > UInt32 propSize = sizeof(dataFormat); > CheckError(AudioFileGetProperty(file, > kAudioFilePropertyDataFormat, > &propSize, > &dataFormat), > "couldn't get file's data format"); > > > UInt32 numBytes; > UInt32 numPackets; > float durationInSeconds = ???; // how do you determine the length of an > audio file? > > NSUInteger samples = ceil(dataFormat.mSampleRate * durationInSeconds); > float *buffer = (float *) malloc (sizeof (float) * samples); > CheckError(AudioFileReadPacketData(file, > false, > &numBytes, > NULL, > 0, > &numPackets, > buffer), > "AudioFileReadData failed"); > > So how can I determine the durationInSeconds? > > Patrick J. Collins > http://collinatorstudios.com > _______________________________________________ > Do not post admin requests to the list. They will be ignored. > Coreaudio-api mailing list ([email protected]) > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/coreaudio-api/solomidsf%40bk.ru > > This email sent to [email protected]
_______________________________________________ Do not post admin requests to the list. They will be ignored. Coreaudio-api mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com This email sent to [email protected]
