Advertisement

Game audio for Mac using Audio Queue Services

Started by March 30, 2016 03:13 AM
0 comments, last by DanB91 8 years, 9 months ago

Hi everyone.

I am currently working on a game on Mac using Audio Queue Services. I am running into an issue where the audio plays for a second and then stops completely. I am getting information from this example from Apple: https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/AQPlayback/PlayingAudio.html#//apple_ref/doc/uid/TP40005343-CH3-SW1

Currently, I am not reading audio from a file, but from another buffer in memory. The tutorial supplied by Apple only shows the case of reading in a file I am currently generating a sine wave into this self-made buffer. From what I understand of this file example of Audio Queue Services from, I am supposed to:

1) Define an audio callback.

2) Allocate the queue and buffer(s). I chose the recommended 3 buffers for where each buffer holds .5 seconds each.

3) “Prime” the Audio Queue buffer(s). This looks like from the Apple example that I have to completely fill up each buffer and then queue each buffer into the Audio Queue.

4) Call AudioQueueStart() to start playback.

The issue is that I only know the sound samples to play on a frame-by-frame basis. I won’t know the sound samples in future frames, so it seems I can’t fill up the buffers fast enough for the sound card. To try to get around this, I tried to “prime” by completely filling the buffers with silence (1.5 seconds worth), hoping that it would keep the stream going. But, again, the desired audio only plays for a second (after the initial 1.5 second silence) and then cuts out.

It seems because I cannot fill the buffer up fast enough, the audio callback gets called when there is no sound samples yet to play in the frame.

I feel I am not understanding some concept that will allow me to fill up the buffer enough to keep the stream going. Any suggestions?

Thanks very much!

Turns out this was happening because I was calculating the wrong size for AudioQueueBufferRef->mAudioDataBytes :/

Now I have a constant stream of audio, but there is a long delay. Gotta figure out how to shorten this delay without starving the buffer...

This topic is closed to new replies.

Advertisement