Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've written my own audio mixer. For Linux/Windows, my game uses SDL. On a small handful of Linux machines (including my laptop), SDL has a bug where it allocates a ridiculously large (about 120 milliseconds) audio buffer. While I'm not to the point that I care so much about affected machines, it points out a problem I'd like to solve.

The problem is that when an event occurs that triggers an audio track to be played, I've already written audio for a small portion of "the future." In other words, I can't really play something "now." If I wait until the next audio buffer fill and start playing this track at sample position 0, I will effectively create a small lag period before the track is heard. With the enormous buffer size mentioned above, this is very noticeable.

One approach I've come up with is to estimate how many audio samples the track would play between "now" and the next sample I can give to the audio buffer. However, this would be incorrect if the game were to be paused/resumed or even slowed down, and this introduces some added complexity to the mixing code.

Is there a standard way to solve this problem, and/or do you have any helpful ideas?

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.