Whenever I run the following code, it crashes on AudioConverterNew( ). But if I change to a PCM file in the pathForResource line (e.g. Test02.aif), it works well and was able to playback the file. Could somebody suggest something for me to try?
NSString *filePath = [[NSBundle mainBundle] pathForResource: @"Test01" ofType:@"m4a"];
CFURLRef audioURL = (__bridge CFURLRef) [NSURL fileURLWithPath:filePath];
// open the input audio file
AudioFileOpenURL(audioURL, kAudioFileReadPermission, 0, &gSourceAudioFileID);
AudioConverterRef myConverter;
// get file's asbd
UInt32 size;
AudioStreamBasicDescription fileASBD = {0};
size = sizeof(AudioStreamBasicDescription);
AudioFileGetProperty(gSourceAudioFileID,
kAudioFilePropertyDataFormat,
&size,
&fileASBD);
if (fileASBD.mFormatID == kAudioFormatMPEGLayer3) NSLog(@"its mp3");
NSLog(@"fileASDB formatId: %d", (unsigned int)fileASBD.mBytesPerFrame);
//NSLog(@"file formatId: %d", (unsigned int)fileASBD.mFormatID);
OSStatus error= AudioConverterNew(&fileASBD,
&thruFormat ,
&(myConverter));
NSLog(@"error: %d", (int)error);