Re: Trying to get all samples from an audio file on disk into memory
Re: Trying to get all samples from an audio file on disk into memory
- Subject: Re: Trying to get all samples from an audio file on disk into memory
- From: "Patrick J. Collins" <email@hidden>
- Date: Sat, 28 Feb 2015 19:51:43 -0800 (PST)
> 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@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden