OpenAL - sound disappearing
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.
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.
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.
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.
Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
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.
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.
or
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.
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.
or
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.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
OpenAL looping sound problem | Gillissie | 0 | 5,338 |
Sep 16, 2010 12:31 AM Last Post: Gillissie |
|
OpenAL - Varying Pitch (for an engine sound) | SethWillits | 4 | 12,956 |
Aug 17, 2009 06:29 AM Last Post: FrazAli |
|
Disappearing Models Problem | merrill541 | 1 | 2,987 |
Jan 26, 2009 03:55 AM Last Post: DoG |
|
sound file formats in OpenAL | unknown | 7 | 12,638 |
Nov 6, 2005 12:50 AM Last Post: Skorche |