尝试使用AudioUnit的AudioConverterNew()时崩溃

时间:2013-11-22 10:58:03

标签: ios mp3 core-audio aiff

每当我运行以下代码时,它就会在AudioConverterNew()上崩溃。但是,如果我更改为pathForResource行中的PCM文件(例如Test02.aif),它运行良好,并能够播放该文件。有人可以建议我尝试一下吗?

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);

0 个答案:

没有答案