AudioQueueStart报告不支持的格式

时间:2009-09-22 12:07:00

标签: iphone macos audio queue

我正在尝试在iphone应用程序上运行音频队列,每当调用AudioQueueStart时,它会给出“fmt?”结果代码(kAudioFormatUnsupportedDataFormatError)。在下面的代码中,我将格式设置为kAudioFormatLinearPCM,肯定是支持的。我做错了什么?

data.mDataFormat.mSampleRate = 44100;
data.mDataFormat.mFormatID = kAudioFormatLinearPCM;
data.mDataFormat.mFormatFlags = 0;
data.mDataFormat.mBytesPerPacket = 4;
data.mDataFormat.mFramesPerPacket = 1;
data.mDataFormat.mBytesPerFrame = 4;
data.mDataFormat.mChannelsPerFrame = 2;
data.mDataFormat.mBitsPerChannel = 16;

OSStatus status;

status = AudioQueueNewOutput(&data.mDataFormat, audioCallback, &data, CFRunLoopGetCurrent (), kCFRunLoopCommonModes, 0, &data.mQueue);

for (int i = 0; i < NUMBUFFERS; ++i)
{
    status = AudioQueueAllocateBuffer (data.mQueue, BUFFERSIZE, &data.mBuffers[i] );
    audioCallback (&data, data.mQueue, data.mBuffers[i]);
}

Float32 gain = 1.0;
status = AudioQueueSetParameter (data.mQueue, kAudioQueueParam_Volume, gain);

status = AudioQueueStart(data.mQueue, NULL);

数据类型为audioData,如下所示:

typedef struct _audioData {
AudioQueueRef mQueue;
AudioQueueBufferRef mBuffers[NUMBUFFERS];
AudioStreamBasicDescription mDataFormat;

} audioData;

感谢

2 个答案:

答案 0 :(得分:1)

您的错误原因实际上是AudioQueueNewOutput而非AudioQueueStart ..请参阅此相关问题audio streaming services failing to recognize file type

答案 1 :(得分:0)

事实证明我需要设置一些标志。它适用于

data.mDataFormat.mFormatFlags = kLinearPCMFormatFlagIsBigEndian | kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;

编辑:实际上,不要使用kLinearPCMFormatFlagIsBigEndian,看来用这种格式它应该是小端。