Problems with Threaded Audio Loader

I’m having some difficulties setting up my own audio environment. I can play sounds just fine, but once I start trying to play music, I run into problems.

Currently music is processed like this:

  • Pre-loaded AudioKeys are stored in a Hashmap
  • A threaded MusicLoader gets a song from the Hashmap, loads the song. (only loads, does not play the nodes!)
  • If Music should be played, a SoundManager gets the Song stored in the MusicLoader, places it into the “AudioNode music;” variable in the Application, then invokes Application.getAudioRenderer().play( music )

Additional Info:

  • the state of the current song (if it is loaded or yet has to be loaded…) is checked in the SoundManager which is kept update in Application.simpleUpdate()
  • Interface Sounds are not streamed, while music is.

Now the problem I have is, this indeed plays the song (which is ~2:30 mins), but after the song finished, I get the following error trying to play an interface sound afterwards:

[java]
Exception in thread “jME3 Audio Thread” java.lang.ArrayIndexOutOfBoundsException: 0
at de.jarnbjo.ogg.LogicalOggStreamImpl.getNextOggPacket(LogicalOggStreamImpl.java:119)
at de.jarnbjo.vorbis.VorbisStream.getNextAudioPacket(VorbisStream.java:166)
at de.jarnbjo.vorbis.VorbisStream.readPcm(VorbisStream.java:140)
at com.jme3.audio.plugins.OGGLoader$JOggInputStream.read(OGGLoader.java:95)
at com.jme3.audio.AudioStream.readSamples(AudioStream.java:94)
at com.jme3.audio.lwjgl.LwjglAudioRenderer.fillBuffer(LwjglAudioRenderer.java:627)
at com.jme3.audio.lwjgl.LwjglAudioRenderer.fillStreamingSource(LwjglAudioRenderer.java:665)
at com.jme3.audio.lwjgl.LwjglAudioRenderer.updateInThread(LwjglAudioRenderer.java:770)
at com.jme3.audio.lwjgl.LwjglAudioRenderer.run(LwjglAudioRenderer.java:114)
at java.lang.Thread.run(Thread.java:722)
Sep 03, 2013 1:40:11 PM com.jme3.app.Application handleError
Schwerwiegend: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.IllegalStateException: Audio thread is terminated
at com.jme3.audio.lwjgl.LwjglAudioRenderer.checkDead(LwjglAudioRenderer.java:93)
at com.jme3.audio.lwjgl.LwjglAudioRenderer.playSourceInstance(LwjglAudioRenderer.java:834)
at core.app.SoundManager.playUISound(SoundManager.java:79)
at core.app.Shell.playSound(Shell.java:324)
at core.app.gui.event.InterfaceEvent.consume(InterfaceEvent.java:81)
at core.app.gui.container.SimplePanel.onSelected(SimplePanel.java:115)
at core.app.gui.container.Tab.onSelected(Tab.java:155)
at core.app.gui.manager.ModuleSelectionManager.onSelected(ModuleSelectionManager.java:166)
at core.app.ShellManager.triggerAction(ShellManager.java:77)
at core.app.Shell.onAction(Shell.java:375)
at com.jme3.input.InputManager.invokeActions(InputManager.java:169)
at com.jme3.input.InputManager.onKeyEventQueued(InputManager.java:455)
at com.jme3.input.InputManager.processQueue(InputManager.java:833)
at com.jme3.input.InputManager.update(InputManager.java:885)
at com.jme3.app.Application.update(Application.java:606)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:230)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:722)
[/java]

I assumed this was caused by the AudioThread to be terminated, so I have tried to reinitialize it. But that doesn’t seem to be working either. Does the MusicLoader somehow cause the audio thread to be terminated, or is there a problem with streamed/non-streamed audio? Any tips or ideas would be appreciated…

Can you explain the issue you were having with sound that got you going in this direction?

The problem I have is that the application crashes if I attempt to play a non-streamed sound, after the streamed audio music has finished playing.

EDIT:
I did not run into any issues playing sound per-se; I want to create a sound managing system that could be used everywhere in the project and is more than just “play sound x”.

1 Like
<cite>@b5cully said:</cite> The problem I have is that the application crashes if I attempt to play a non-streamed sound, after the streamed audio music has finished playing.

I take it the non-streamed audio is pre-loaded?

And ooooo… you’re getting the same error with your implementation as well.

What audio format are you using?
What hardware have you tested this on?
Is your streamed audio stereo?
Are you using positional sound at all? or is this just Music and UI sounds? (this is what it looks to be from the stack trace)
Are you using a common audio format for all sounds?

<cite>@b5cully said:</cite> The problem I have is that the application crashes if I attempt to play a non-streamed sound, after the streamed audio music has finished playing.

EDIT:
I did not run into any issues playing sound per-se; I want to create a sound managing system that could be used everywhere in the project and is more than just “play sound x”.

/nod attempting to do something similar atm as well.

<cite>@t0neg0d said:</cite> I take it the non-streamed audio is pre-loaded?

And ooooo… you’re getting the same error with your implementation as well.

What audio format are you using?
What hardware have you tested this on?
Is your streamed audio stereo?
Are you using positional sound at all? or is this just Music and UI sounds? (this is what it looks to be from the stack trace)
Are you using a common audio format for all sounds?

yes, the non-streamed audio is pre-loaded and stored in an array of audio nodes in the application,

The audio formats I am using is .ogg for music and .wav for sound.

Hardware is an AMD High Definition Audio Device (at least that’s what my system tells me), and the audio is indeed stereo. I am not using any positional nodes.

I did program another music loader and player a while ago and that one worked fine, but it was not pre-loading any sounds or music and created a new AudioNode each time a sound or song was played. So there must be a way to do this without causing errors… I’ll try to merge this old player with the new one I made and report back if I found a solution… Still any comments on this would be appreciated

<cite>@b5cully said:</cite> yes, the non-streamed audio is pre-loaded and stored in an array of audio nodes in the application,

The audio formats I am using is .ogg for music and .wav for sound.

Hardware is an AMD High Definition Audio Device (at least that’s what my system tells me), and the audio is indeed stereo. I am not using any positional nodes.

I did program another music loader and player a while ago and that one worked fine, but it was not pre-loading any sounds or music and created a new AudioNode each time a sound or song was played. So there must be a way to do this without causing errors… I’ll try to merge this old player with the new one I made and report back if I found a solution… Still any comments on this would be appreciated

Just a quick thought… have you tried converting your streamed audio to .wav format?

EDIT: The wave loader is an internal class to JME… the ogg loader is not.

1 Like
<cite>@t0neg0d said:</cite> Just a quick thought... have you tried converting your streamed audio to .wav format?

EDIT: The wave loader is an internal class to JME… the ogg loader is not.

I loaded the music as .wav files, and that indeed worked… Thanks for the tip! (Now if only .wav wasn’t so space-y in terms of required disk space)

But this is very interesting… it seems like concurrency/threading breaks the playback for .ogg’s somehow.

<cite>@b5cully said:</cite> I loaded the music as .wav files, and that indeed worked... Thanks for the tip! (Now if only .wav wasn't so space-y in terms of required disk space)

But this is very interesting… it seems like concurrency/threading breaks the playback for .ogg’s somehow.

What audio app are you using for conversion? You should be able to reduce the wav to 8bit 22k mono (as long as your music isn’t using any stereo panning… stereo if so) and still get good playback quality depending on the app you’re using for conversion. SoundForge is a great tool, if you have access to it.

@t0neg0d said: /nod attempting to do something similar atm as well.

Aren’t we all? ^^

<cite>@normen said:</cite> Aren't we all? ^^
Lol
<cite>@t0neg0d said:</cite> What audio app are you using for conversion? You should be able to reduce the wav to 8bit 22k mono (as long as your music isn't using any stereo panning... stereo if so) and still get good playback quality depending on the app you're using for conversion. SoundForge is a great tool, if you have access to it.
"Free Audio Converter" is what I am using: http://www.dvdvideosoft.com/products/dvd/Free-Audio-Converter.htm#.UiX8ekBRA7I it seemingly lets me adjust the bitrate, but file size remains the same (1411kbit/sec, typical for .wav). I used it to convert sound from wav to ogg.

SoundForge seems like a good idea, but yeah, access is an issues here :smiley:

I didn’t read too much into the details but are you trying to reuse AudioNodes? That won’t work for streamed files for the same reason they can’t be looped.

<cite>@pspeed said:</cite> I didn't read too much into the details but are you trying to reuse AudioNodes? That won't work for streamed files for the same reason they can't be looped.
No, I did not. Each time the music loader was called, the current audio node that plays would be replaced by a new audio node object. Hmm. Still could be a possible error source, though.
<cite>@b5cully said:</cite> "Free Audio Converter" is what I am using: http://www.dvdvideosoft.com/products/dvd/Free-Audio-Converter.htm#.UiX8ekBRA7I it seemingly lets me adjust the bitrate, but file size remains the same (1411kbit/sec, typical for .wav). I used it to convert sound from wav to ogg.

SoundForge seems like a good idea, but yeah, access is an issues here :smiley:

Let me see what I can track down for audio converters… something that allows you to use DX effects/VST plugins chaining is never a bad thing to have as well.

Looks like it would do the trick

I don’t see any mention of DX effects… however, VST is supported. Usually audio plugins will ship in both formats