(Slick2D) not enough sound channels

Apparently, Slick2D’s sound class dynamically allocated sounds to channels. When a channel is not available, the sound is not played. The problem is, in a few cases, when I play one sound and then quickly try to play another sound, the second sound occasionally doesn’t play. I’m guessing that for whatever reason, there wasn’t a channel to allocate the second sound to. Is there any way to guarantee that sounds will play when using the Slick2D library?

How many sound sources is Slick initialized with on your system? It should print in the log. Slick tries to initialize 64 by default (which should be enough – that many sounds simultaneously will probably sound like garbage, anyways).

I wonder if there is a bug in your code or in Slick’s audio classes that is causing them to stop. It’s unlikely that all your sources are playing at the exact same time, unless your system severely limits the max number of sources.

If you really do find that your game/application demands more simultaneous sounds, you pretty much have three options:

  1. Request more sources – you can set the max sources in Slick and re-init. This is likely the worst solution, since most computers max out at 64 or 32 sources, and you can’t really expect your average user’s sound card to do any better than that.

  2. Mix all sources in software – you are limited only by how much data you can mix without latency. This requires a fair amount of knowledge, although maybe TinySound (which is a software mixer) will be a good starting point.

  3. Manage your sources based on priority, distance, and other attributes. For example, a speech dialog will not be interrupted by a subtle bird chirping in the distance (and the user won’t notice if a gunshot interrupts a subtle bird chirp).

A while back (when I was first learning OpenAL) I wrote a simple extension for Slick which does just this. You specify what “layer” a sound would be (for e.g. SPEECH_LAYER, AMBIENT_LAYER, EFFECTS_LAYER) so that less important sounds will never cut off more important sounds. There is also some other controls (e.g. distance from player) that can affect a sound’s priority. It was never really completed, and pretty messy compared to how I would do things these days.
Soundly - Sound Manager for Slick

Personally (if you actually need this feature) I’d recommend rolling your own audio manager – it will teach you a lot about OpenAL and start getting you more comfortable with audio programming. Only, I wouldn’t use Slick or its decoders as a base… :stuck_out_tongue:

Yeah, have exactly zero experience with openal. Anyway, I found where the problem is. I set it up so a particular sound won’t play unless it is not already playing. For instance, I would write:

if(!smashSound.playing())
smashSound.play();

Problem is, whenever ANY sound plays, smashSound.playing() returns true… Go figure… Eh, I guess I can figure out a way to fix this without checking to see if a sound is playing. It’s just a little inconvenient. I’ll just work around it. Thanks a bunch, though!