Multiple track restarts with music queue and crossfade = 0

Music queue with streamed tracks and crossfade in and out set to 0 causes the second track to restart several times. Also it causes strong fps drops until the track stops restarting and resumes playing normally.



Tested with tracks in steam mode from the file system.

I think this is the same issue as : http://www.jmonkeyengine.com/jmeforum/index.php?topic=6396

Well, I was thinking along the lines that setting crossfade time of 0 should disable crossfade and skip crossfade logic all together.

yeah, would've helped it skip that bug… although the logic is a couple if statements.

Here's another option:



When you want a crossfade of X seconds, make sure that your decoder reads ahead at least X seconds each time you enter a new section of X seconds, so you are guaranteed to always have X amount of decoded data. Then when you realize that you're at the end of the stream, you can open the next stream and start cross-fading in, and you have enough data left to make sure it works out.



I e, if you want a 5 second crossfade, you would always have two buffers of 5 seconds read. One that is currently playing, and one that is pending. When you start playing the pending buffer, the currently read buffer is filled from the stream. If that fails by only having 0.2 seconds left, then you know that you should start crossfading 0.2 seconds into the currently playing buffer.



If you want to make the logic even easier, read ahead by 3 buffers, each the crossfade time, and you won't even have to start playing a buffer before you know whether that buffer will crossfade or not.

Was this ever fixed? Still seems like an issue when streaming.

I'll elaborate on what I'm seeing. First track plays fine. With crossfade set to 0 I still seem to be getting some crossfade between tracks 1 and 2. Track 2 plays. When track 3 starts it cuts out after a few seconds, then track 4 starts. Track 5 starts along with a bit of some other track which cuts out after a couple of seconds. In other words, things are pretty screwy with the MusicQueue. I'm just using TestMusicQueue to see these issues.



Also getting the following errors:


Feb 13, 2008 7:05:48 AM com.jmex.audio.openal.OpenALStreamedAudioPlayer playInNewThread
SEVERE: Audio Error!
org.lwjgl.openal.OpenALException: OpenAL error: Invalid Operation (40964)
   at org.lwjgl.openal.Util.checkALError(Util.java:56)
   at org.lwjgl.openal.AL10.alSourceQueueBuffers(AL10.java:1156)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.playStream(OpenALStreamedAudioPlayer.java:196)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.playInNewThread(OpenALStreamedAudioPlayer.java:214)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.play(OpenALStreamedAudioPlayer.java:166)
   at com.jmex.audio.AudioTrack.play(AudioTrack.java:113)
   at com.jmex.audio.MusicTrackQueue.play(MusicTrackQueue.java:144)
   at com.jmex.audio.MusicTrackQueue.setCurrentTrack(MusicTrackQueue.java:212)
   at com.jmex.audio.MusicTrackQueue.update(MusicTrackQueue.java:240)
   at com.jmex.audio.openal.OpenALSystem.update(OpenALSystem.java:124)
   at imp.Imperious.simpleUpdate(Imperious.java:32)
   at com.jme.app.SimpleGame.update(SimpleGame.java:72)
   at com.jme.app.BaseGame.start(BaseGame.java:79)
   at imp.Imperious.main(Imperious.java:22)
Feb 13, 2008 7:05:49 AM com.jmex.audio.openal.OpenALStreamedAudioPlayer playInNewThread
SEVERE: Audio Error!
org.lwjgl.openal.OpenALException: OpenAL error: Invalid Value (40963)
   at org.lwjgl.openal.Util.checkALError(Util.java:56)
   at org.lwjgl.openal.AL10.alBufferData(AL10.java:1044)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.stream(OpenALStreamedAudioPlayer.java:319)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.playStream(OpenALStreamedAudioPlayer.java:190)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.playInNewThread(OpenALStreamedAudioPlayer.java:214)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.play(OpenALStreamedAudioPlayer.java:166)
   at com.jmex.audio.AudioTrack.play(AudioTrack.java:113)
   at com.jmex.audio.MusicTrackQueue.play(MusicTrackQueue.java:144)
   at com.jmex.audio.MusicTrackQueue.update(MusicTrackQueue.java:257)
   at com.jmex.audio.openal.OpenALSystem.update(OpenALSystem.java:124)
   at imp.Imperious.simpleUpdate(Imperious.java:32)
   at com.jme.app.SimpleGame.update(SimpleGame.java:72)
   at com.jme.app.BaseGame.start(BaseGame.java:79)
   at imp.Imperious.main(Imperious.java:22)
Feb 13, 2008 7:08:10 AM com.jmex.audio.openal.OpenALStreamedAudioPlayer playInNewThread
SEVERE: Audio Error!
org.lwjgl.openal.OpenALException: OpenAL error: Invalid Operation (40964)
   at org.lwjgl.openal.Util.checkALError(Util.java:56)
   at org.lwjgl.openal.AL10.alSourceQueueBuffers(AL10.java:1156)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.playStream(OpenALStreamedAudioPlayer.java:196)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.playInNewThread(OpenALStreamedAudioPlayer.java:214)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.play(OpenALStreamedAudioPlayer.java:166)
   at com.jmex.audio.AudioTrack.play(AudioTrack.java:113)
   at com.jmex.audio.MusicTrackQueue.play(MusicTrackQueue.java:144)
   at com.jmex.audio.MusicTrackQueue.update(MusicTrackQueue.java:257)
   at com.jmex.audio.MusicTrackQueue.update(MusicTrackQueue.java:241)
   at com.jmex.audio.openal.OpenALSystem.update(OpenALSystem.java:124)
   at imp.Imperious.simpleUpdate(Imperious.java:32)
   at com.jme.app.SimpleGame.update(SimpleGame.java:72)
   at com.jme.app.BaseGame.start(BaseGame.java:79)
   at imp.Imperious.main(Imperious.java:22)
Feb 13, 2008 7:08:10 AM com.jmex.audio.openal.OpenALStreamedAudioPlayer playInNewThread
SEVERE: Audio Error!
java.lang.ArrayIndexOutOfBoundsException: -1
   at java.util.ArrayList.remove(Unknown Source)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.playStream(OpenALStreamedAudioPlayer.java:189)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.playInNewThread(OpenALStreamedAudioPlayer.java:214)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.play(OpenALStreamedAudioPlayer.java:166)
   at com.jmex.audio.AudioTrack.play(AudioTrack.java:113)
   at com.jmex.audio.MusicTrackQueue.play(MusicTrackQueue.java:144)
   at com.jmex.audio.MusicTrackQueue.setCurrentTrack(MusicTrackQueue.java:212)
   at com.jmex.audio.MusicTrackQueue.update(MusicTrackQueue.java:240)
   at com.jmex.audio.openal.OpenALSystem.update(OpenALSystem.java:124)
   at imp.Imperious.simpleUpdate(Imperious.java:32)
   at com.jme.app.SimpleGame.update(SimpleGame.java:72)
   at com.jme.app.BaseGame.start(BaseGame.java:79)
   at imp.Imperious.main(Imperious.java:22)
Feb 13, 2008 7:11:12 AM com.jmex.audio.openal.OpenALStreamedAudioPlayer playInNewThread
SEVERE: Audio Error!
org.lwjgl.openal.OpenALException: OpenAL error: Invalid Value (40963)
   at org.lwjgl.openal.Util.checkALError(Util.java:56)
   at org.lwjgl.openal.AL10.alBufferData(AL10.java:1044)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.stream(OpenALStreamedAudioPlayer.java:319)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.playStream(OpenALStreamedAudioPlayer.java:190)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.playInNewThread(OpenALStreamedAudioPlayer.java:214)
   at com.jmex.audio.openal.OpenALStreamedAudioPlayer.play(OpenALStreamedAudioPlayer.java:166)
   at com.jmex.audio.AudioTrack.play(AudioTrack.java:113)
   at com.jmex.audio.MusicTrackQueue.play(MusicTrackQueue.java:144)
   at com.jmex.audio.MusicTrackQueue.setCurrentTrack(MusicTrackQueue.java:212)
   at com.jmex.audio.MusicTrackQueue.update(MusicTrackQueue.java:240)
   at com.jmex.audio.openal.OpenALSystem.update(OpenALSystem.java:124)
   at imp.Imperious.simpleUpdate(Imperious.java:32)
   at com.jme.app.SimpleGame.update(SimpleGame.java:72)
   at com.jme.app.BaseGame.start(BaseGame.java:79)
   at imp.Imperious.main(Imperious.java:22)

what files are you using to test with and do you have the code changes you made handy?  I'll be happy to investigate.

All I'm doing is this:


MusicTrackQueue queue = AudioSystem.getSystem().getMusicQueue();
      queue.setCrossfadeinTime(0);
      queue.setRepeatType(RepeatType.ALL);
      
      File dir = new File("src/resources/music/");
      String[] list = dir.list();
      for(int a=0; a<list.length; a++){
         queue.addTrack(AudioSystem.getSystem().createAudioTrack(
               Music.class.getClassLoader().getResource("resources/music/" + list[a]), true));
      }
      queue.play();



I'm using 2-3 minute (~2-5mb) ogg files, although I also tested it with wavs and had the same result. Reading the files from memory instead of streaming works fine (but eats up a ton of memory), so I don't think the files are at issue.