You do not need a third-party library to open archive files. With a little help from the AudioToolbox/AudioToolbox.h framework, you can open and read the data of a .caf file, which is a very good choice (better than mp3 or ogg) in terms of performance (minimal CPU impact during decompression). Thus, when the data falls into OpenAL, already PCM , it is ready to fill the buffers. Here is a sample code of how you can do this:
-(void) prepareFiles:(NSString *) filePath{ // get the full path of the file NSString* fileName = [[NSBundle mainBundle] pathForResource:filePath ofType:@"caf"]; // open the file using the custom created methods (see below) AudioFileID fileID = [self openAudioFile:fileName]; preparedAudioFileSize = [self audioFileSize:fileID]; if (preparedAudioFile){ free(preparedAudioFile); preparedAudioFile = nil; } else{ ; } preparedAudioFile = malloc(preparedAudioFileSize); //read the data from the file into soundOutData var AudioFileReadBytes(fileID, false, 0, &preparedAudioFileSize, preparedAudioFile); //close the file AudioFileClose(fileID); } -(AudioFileID)openAudioFile:(NSString*)filePath { AudioFileID fileID; NSURL * url = [NSURL fileURLWithPath:filePath]; OSStatus result = AudioFileOpenURL((CFURLRef)url, kAudioFileReadPermission, 0, &fileID); if (result != noErr) { NSLog(@"fail to open: %@",filePath); } else { ; } return fileID; } -(UInt32)audioFileSize:(AudioFileID)fileDescriptor { UInt64 outDataSize = 0; UInt32 thePropSize = sizeof(UInt64); OSStatus result = AudioFileGetProperty(fileDescriptor, kAudioFilePropertyAudioDataByteCount, &thePropSize, &outDataSize); if(result != 0) NSLog(@"cannot find file size"); return (UInt32)outDataSize; }
source share