AudioQueueGetProperty の呼び出しから -50 (一般的なパラメーター エラー) が発生します。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.");
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."];
これは、次のエラー チェック関数に解決されます。
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 を呼び出してみましたが、クラス インスタンス レベルの 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 general param エラーで同じ場所でクラッシュが発生します。私のデバイスは iOS6 を実行している iPhone 4S で、XCode 4.5 を使用しています。