AudioQueue does not output sound

I have problems getting sound on my iPhone experiment, and I have no ideas.

Here is my callback to populate the audio queue buffer

void AudioOutputCallback(void *user, AudioQueueRef refQueue, AudioQueueBufferRef inBuffer) { NSLog(@"callback called"); inBuffer->mAudioDataByteSize = 1024; gme_play((Music_Emu*)user, 1024, (short *)inBuffer->mAudioData); AudioQueueEnqueueBuffer(refQueue, inBuffer, 0, NULL); } 

I am tuning the audio queue using the following snippet

  // Create stream description AudioStreamBasicDescription streamDescription; streamDescription.mSampleRate = 44100; streamDescription.mFormatID = kAudioFormatLinearPCM; streamDescription.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked; streamDescription.mBytesPerPacket = 1024; streamDescription.mFramesPerPacket = 1024 / 4; streamDescription.mBytesPerFrame = 2 * sizeof(short); streamDescription.mChannelsPerFrame = 2; streamDescription.mBitsPerChannel = 16; AudioQueueNewOutput(&streamDescription, AudioOutputCallback, theEmu, NULL, NULL, 0, &theAudioQueue); OSStatus errorCode = AudioQueueAllocateBuffer(theAudioQueue, 1024, &someBuffer); if( errorCode ) { NSLog(@"Cannot allocate buffer"); } AudioOutputCallback(theEmu, theAudioQueue, someBuffer); AudioQueueSetParameter(theAudioQueue, kAudioQueueParam_Volume, 1.0); AudioQueueStart(theAudioQueue, NULL); 

The library I use outputs linear PCM 16bit 44hz.

0
source share
2 answers

I usually use 3 buffers. You need at least 2, because as soon as you play, the other is populated with your code. If you have only one, there is not enough time to fill the same buffer and re-enqueue it, and playback will be smooth. So he probably just stops your turn because she has run out of buffers.

0
source

Select two buffers instead.

AudioQueues very subtle.

0
source

All Articles