Hi
I'm trying to use the Audio Queue API to play out linear PCM audio received over the net.
I create an audio queue and then try to allocate the first buffer. The allocation call returns OK but the buffer data space isn't allocated.
Can anyone see what I'm doing wrong?
Code:
aQState->bufferSize = 4800;
AudioStreamBasicDescription* desc = &aQState->audioDataFormat;
desc->mSampleRate = 48000;
desc->mFormatID = kAudioFormatLinearPCM;
desc->mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
desc->mBytesPerPacket = 2;
desc->mFramesPerPacket = 1;
desc->mBytesPerFrame = 2;
desc->mChannelsPerFrame = 1;
desc->mBitsPerChannel = 16;
OSStatus result = AudioQueueNewOutput( &aQState->audioDataFormat,
audioPlayCallBack,
&aQState,
NULL,
kCFRunLoopCommonModes,
0,
&aQState->audioQueue );
//result is 0 OK so far
for (int i =0; i < numAudioBuffers; i++) {
result = AudioQueueAllocateBuffer( aQState->audioQueue,
aQState->bufferSize,
&aQState->audioBuffers[i] );
// again result 0 OK
AudioQueueBufferRef thisBuf = aQState->audioBuffers[1];
/* problem is here thisBuf->mAudioData is 0 so no data space
has been allocated*/
}