Game studders when playing sound

When playing a midi file for music and wav’s for sound effects, it’s not really noticeable.

When streaming a wav music file and playing wav sound effects, the game stops for split seconds. The sound effects are even delayed.

I have all wav files sampled to 22 kHz, 16-bit stereo. I was hoping having them all at the same sample rate would help.

Is there a trick to streaming audio for the background music and playing sound effects at the same time?

How are you playing the sound fx? Post some code.

Kev

I figured out the problem.

I’m using the “sound system” via Paul’s code. I was only using the Java Sound Library. I figured that’s all I needed but I added the OpenAL library and that works without studder. Very smooth now.

Sorry to respond so late on this one (I have so many forums I’m a member of that I tend to forget to check a couple of them now and then).

Yes, the problem with playing MIDI while using JavaSound for sound effects, is that JavaSound handles both MIDI synthesis and audio mixing on the same thread (rather poorly), so while it is busy doing stuff with the MidiDevices, the Clips and SourceDataLines get ignored for a millisecond or so - enough to create undesirable “artifacts” (i.e. clicks and stutters). Unfortunately, this is a bug with the JavaSound API itself, so the only way around it would be for me to write my own MIDI synthesizer instead of using the JavaSound one (something I may do in the distant future, if I can get the rest of the library to a “final release” point). In the mean time, you already found the best solution: using OpenAL for the sound effects leaves JavaSound free to focus its full attention on MIDI synthesis.