一般参数错误与AudioQueueGetProperty检索logging格式

我得到一个-50(一般参数错误)从一个调用AudioQueueGetProperty。 请帮助我,因为我已经触摸了XCode和任何iPhone工作了几个月。 这可能是一个简单的代表,但我无法解决它。 我的代码通往-50:

//Setup format AudioStreamBasicDescription recordFormat; memset(&recordFormat, 0, sizeof(recordFormat)); recordFormat.mFormatID = kAudioFormatMPEG4AAC; recordFormat.mChannelsPerFrame = 2; CCGetDefaultInputDeviceSampleRate(&recordFormat.mSampleRate); UInt32 propSize = sizeof(recordFormat); AQ(AudioFormatGetProperty(kAudioFormatProperty_FormatInfo, 0, NULL, &propSize, &recordFormat), "AudioFormatGetProperty throws unexpected errors."); //Setup Queue //listing 4.8-4.9 AudioQueueRef theQueue = {0}; self->queue = theQueue; AQ(AudioQueueNewInput(&recordFormat, CCAudioRecordingCallback, self, NULL, NULL, 0, &self->queue), "AudioQueueNewInput throws unexpected errors."); UInt32 size = sizeof(recordFormat); AQ(AudioQueueGetProperty(self->queue, kAudioConverterCurrentOutputStreamDescription, &recordFormat, &size), "Getting audio property kAudioConverterCurrentOutputStreamDescription throws unexpected errors."); 

我已经validation,我有一个有效的队列,就像我调用AudioQueueGetProperty。 我已经尝试了通过队列“self> queue”和“self.queue”两种方式,它们都导致相同的错误。 队列定义如下:

 @interface CCAudioRecorder() //... @property (nonatomic, assign) AudioQueueRef queue; //... @end @implementation CCAudioRecorder @synthesize queue; 

AQ是#def:

 #define AQ(expr, msg) if(nil!=CheckError((expr), msg)) [NSException raise:@"AudioException" format:@"Unexpected exception occured."]; 

这解决了以下错误检查function:

 static NSString* CheckError(OSStatus error, const char* operation) { if (noErr == error) return nil; NSString *errorMessage = nil; char errorString[20]; //See if it appears to be a 4-char code *(UInt32 *)(errorString+1) = CFSwapInt32HostToBig(error); if ( isprint(errorString[1]) && isprint(errorString[2]) && isprint(errorString[3]) && isprint(errorString[4]) ) { errorString[0] = errorString[5] = '\''; errorString[6] = '\0'; } else { sprintf(errorString, "%d", (int)error); } errorMessage = [NSString stringWithFormat: @"Audio Error: %@ (%@)\n", [NSString stringWithUTF8String:operation], [NSString stringWithUTF8String:errorString]]; NSLog(@"%@", errorMessage); return errorMessage; } 

我也尝试调用AudioFormatGetProperty创build一个局部variables的队列,避免类实例级别iVar,仍然得到相同的错误:

 AudioQueueRef theQueue = {0}; AQ(AudioQueueNewInput(&recordFormat, CCAudioRecordingCallback, self, NULL, NULL, 0, &theQueue), "AudioQueueNewInput throws unexpected errors."); UInt32 size = sizeof(recordFormat); AQ(AudioQueueGetProperty(theQueue, kAudioConverterCurrentOutputStreamDescription, &recordFormat, &size), "Getting audio property kAudioConverterCurrentOutputStreamDescription throws unexpected errors."); 

**更新**我有以下代码在模拟器上,而不是在设备上。 (我没有交叉引用它与我之前发布的,但我相信它是相似或确切的。)

 AudioQueueRef theQueue = {0}; self->queue = theQueue; AQ(AudioQueueNewInput(&recordFormat, CCAudioRecordingCallback, self, NULL, NULL, 0, &self->queue), "AudioQueueNewInput throws unexpected errors."); UInt32 size = sizeof(recordFormat); AQ(AudioQueueGetProperty(self->queue, kAudioConverterCurrentOutputStreamDescription, &recordFormat, &size), "Getting audio property kAudioConverterCurrentOutputStreamDescription throws unexpected errors."); 

在设备上运行我在同一个地方出现了一个错误-50一般参数错误。 我的设备是运行iOS6的iPhone 4S我正在使用XCode 4.5。

你正在学习核心audio书的代码吧? 关于实现录音机的第4章 我注意到了你的代码和本书的代码之间的区别,他们只是简单地初始化Queue并按照原样使用它:

 AudioQueueRef queue = {0}; UInt32 size = sizeof(recordFormat); CheckError(AudioQueueGetProperty(queue, kAudioConverterCurrentOutputStreamDescription, &recordFormat, &size), "couldn't get queue's format"); 

我不确定你为什么要把自己扔在一起。 但是,这绝对是什么导致你的错误。 如果全部失败,只需在这里下载该章节的完整代码,并查看哪里可以识别您的错误。