Currently I am struggling with opening an audio file. In a previous version of my software I used an iostream, timers, fread and my own file opening function for parsing the wav file header, getting the data etc. This was fine as I was only opening a fixed set of files.
Now that I want to open multiple file types I am trying to switch to AudioFile.h functions.
Looking at the documentation, AudioFileOpenWithCallbacks seems to be what I need, AudioFileOpenWithCallbacks providing for async file load so I don't block everything waiting for a large file to open.
Currently this is what I am doing below. AudioFile_ReadProc only gets called once, I thought the purpose of OpenWithCallbacks is that it keeps being called until you have read the entire file? There is nothing really on this process anywhere so some advice/explanation would help.
// AudioFile_ReadProc callback OSStatus MyAudioFile_ReadProc (void *inClientData, SInt64 inPosition, UInt32 requestCount, void *buffer,UInt32 *actualCount){
AudioFileReader *audioFileReader = (AudioFileReader *) inClientData;
OSErr err = AudioFileReadBytes(audioFileReader.afid, false,audioFileReader.numAudioDataBytesRead, &requestCount, audioFileReader.audioData); if(err == noErr) { printf("AudioFileReadBytes Ok!"); audioFileReader.numAudioDataBytesRead+=requestCount; *actualCount = requestCount; }
}
-(void)testFileOpen(){
...
AudioFileOpenURL(inFileURL, kAudioFileReadPermission, 0, &afid);
...
AudioFileOpenWithCallbacks(self, MyAudioFile_ReadProc, MyAudioFile_WriteProc, MyAudioFile_GetSizeProc, MyAudioFile_SetSizeProc, nil, &afid ); } |