iDevGames Forums
OpenAL - sound disappearing - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: OpenAL - sound disappearing (/thread-429.html)

OpenAL - sound disappearing - Madrayken - Jan 16, 2010 03:35 PM

Hi folks,

I've written a small OpenAL library for my iPhone game.
I allocate 42 buffers - one for each sound, right at the beginning of the game. I recycle my 8 sources in a nice round-robin style. All good so far. However, after around 20 minutes of game-playing, I find that the sound starts to go a little strange.

At first, some of the sounds play a little bit high-pitched. Not all of the time, but sporadically. Then they settle again. This occurs more and more regularly until all sound, bar the music disappears.

Does this sound familiar to anyone?

Many thanks for any help.

OpenAL - sound disappearing - reubert - Jan 17, 2010 02:34 PM

I've had sounds double in pitch after a period with OpenAL on the iPhone. I wasn't really able to track down the exact cause. In my case I found that in my audio code I was calling alSourceStop and alSourcePlay excessively, and that the pitch doubling always occurred on the alSourcePlay call after a sound had been stopped.

I was unable to track down the cause further than that, but simply replacing nearly all of the stop and play calls with alSourcePause did the trick. I have not had any problems since.

OpenAL - sound disappearing - Madrayken - Jan 18, 2010 06:47 AM

Thanks for the feedback. I'll check my code, but I don't think I'm using alSourceStop much at all. I am, of course, using alSourcePlay for every sound I make, but I don't see why that would cause the slow deterioration of the sound.

OpenAL - sound disappearing - Madrayken - Jan 19, 2010 03:22 AM

Okay, found the problem. I'll document it here in case anyone else comes across it.

The overall effect was brought to light by stopping and restarting a looping sample.

I statically allocate all of my buffers (42 of them) at the start of the game.
I statically allocate 8 sources at the start of the game, and recycle them.

When a call comes in to play a sound my CALSource class is handed a pointer to the CALBuffer to be attached and uses that to get information about whether it is a looping sound or not, amongst other things.

When a request comes into my sound manager to play a sound, I look for:

1) a source with no buffer attached, that is not playing.
2) a source that has a lower priority

In the case of 2) my sources are force-stopped if a higher priority sound wants to come in and play despite all the sources being used.

In real-world use, the only time this latter event really occurs is when I have been playing several looping samples concurrently. I think that, due to alStopSound taking a little while to take effect, you may think you have stopped a sound, but openAL may not.

Also, I had not retained the CALBuffer pointer when giving the CSoundSource ownership of it. When I stopped the sound I was also not releasing the buffer, nor making the buffer pointer nil.

As a result many of my tests later showed that there was, in fact, a looping sample still playing when there was not, which meant that - over the course of 25 minutes - I slowly lost all of my alSources and the game eventually became silent. This didn't show up in early tests because in 90% of cases I was not calling alSourceStop, but reusing an already playing source.

I hope this helps someone in the future, as it's taken me days to figure out.