3

I'm trying to get audio queue working on an iphone app, and whenever AudioQueueStart is called it gives the "fmt?" result code (kAudioFormatUnsupportedDataFormatError). In the code below i'm setting the format to kAudioFormatLinearPCM, which surely is supported. What am i doing wrong?

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

data is of type audioData which is like this:

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

} audioData;

thanks

usrgnxc
  • 794
  • 2
  • 9
  • 34
  • Hi! I have the same problem. Change different flags are not useful for me. May be iPad simulator do not support recording??? –  Jan 30 '11 at 14:29

2 Answers2

1

The cause of your error is actually AudioQueueNewOutput rather than AudioQueueStart.. See this related question audio streaming services failing to recognize file type

Community
  • 1
  • 1
abbood
  • 23,101
  • 16
  • 132
  • 246
0

it turns out i needed to set some flags. it works with

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

edit: actually, dont use kLinearPCMFormatFlagIsBigEndian, it seems that with this format it should be little endian.

usrgnxc
  • 794
  • 2
  • 9
  • 34