AudioQueueStart report with unsupported format

I am trying to get the audio queue to work with the iphone application, and whenever AudioQueueStart is called, it gives "fmt?". (kAudioFormatUnsupportedDataFormatError). In the code below, I install the kAudioFormatLinearPCM format, which is certainly 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);

the data is of type audioData, which is as follows:

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

} audioData;

thanks

+3
source share
2 answers

Turns out I need to set some flags. he works with

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

edit: in fact, do not use kLinearPCMFormatFlagIsBigEndian, it seems that it should be few in this format.

0

, , AudioQueueNewOutput, AudioQueueStart.. . ,

+1

Source: https://habr.com/ru/post/1718276/


All Articles