Jump to content
  • Advertisement
Sign in to follow this  

Game audio for Mac using Audio Queue Services

This topic is 989 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!




Share this post

Link to post
Share on other sites

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...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!