使用AudioQueueGetProperty检索记录格式的常规参数错误 [英] General param error retrieving record format with AudioQueueGetProperty

查看:168
本文介绍了使用AudioQueueGetProperty检索记录格式的常规参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从AudioQueueGetProperty的调用中收到-50(一般参数错误)。自从我接触XCode和任何iPhone作品已经有几个月了,请帮助我。对我来说,这可能是一件简单的事,但我无法解决。我的代码指向-50:

I am getting a -50 (general param error) from a call to AudioQueueGetProperty. Please help me as it has been several months since I've touched XCode and any iPhone work. This is likely a simple goof on my behalf but I cannot resolve it. My code leading to the -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,它们都导致相同的错误。队列定义如下:

I have verified that I have a valid queue just as I make the call to AudioQueueGetProperty. I've tried both ways of passing the queue "self->queue", and "self.queue" and they both result in the same error. The queue is defined as follows:

@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."];

解决以下错误检查功能:

Which resolves to the following error checking 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,避免类实例级别iVar并仍然出现相同的错误:

I've also tried calling AudioFormatGetProperty on a queue created with a local variable, avoiding the class instance level iVar and still get the same error:

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

**更新**
我有以下代码可在模拟器上运行,而不是在设备上。 (我没有将它与我先前发布的内容交叉引用,但我相信它是相似或完全相同的。)

** Update ** I have the following code which works on the simulator and not on the device. (I have not cross referenced it with what I posted earlier but I believe it's either similar or the exact.)

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。

Running it on device I get a crash in the same spot with error -50 general param error. My device is an iPhone 4S running iOS6 I'm working with XCode 4.5.

推荐答案

您正在遵循学习核心音频这本书对吗?第4章关于实现记录器?我注意到您的代码和本书的代码有所不同,在本书中,他们只是初始化Queue并按原样使用它:

You are following the code from the learning core audio book right? Chapter 4 about implementing a recorder? I noticed a difference between your code and the book's code, in the book they simply initialize the Queue and use it as is:

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

我不确定你为什么要丢 。但这绝对是导致您的错误的原因。如果全部失败,只需在此处下载该章的完整代码,然后查看您可以在其中识别错误。

I'm not sure why you're throwing self in the mix. But that's definitely what's causing your bug. If all fails simply download the complete code for that chapter here and see where you can identify your mistake.

这篇关于使用AudioQueueGetProperty检索记录格式的常规参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆