Improving EasyOgg

I finally got round to adding sound into my game, and I wanted to use ogg. Took me a while to find what I wanted and then found EasyOgg to be my answer.
I don’t know much about sound but I did improve on the code quality, e.g removed useless variables, code reuse and all the tips from FindBugs. But wondering if someone could help me(and others who want to use this) where I left off and improve it more.
There is no way to set the volume of the left and right channels is someone able to help create a constructor or so that able to do this?
Also stopping isn’t instant and playing multiple times and sound is corrupted.
I have attached my changes below.

Edit: added a method to tell if the clip is still playing.


I will look at your code. I’m using JOGG and JORBIS, I didn’t know EasyOgg.

I got the source from
It just makes using JOrbis a lot easier to use.
But wondering if a few people help out and improve on this while still making it easy to use. I done all I can, but I have no knowledge in this kind of area. Though I did try fixing the stop problem but failed on all the ways I tried.

Look at my source code(under GPL licence), the class “” succeeds in stopping a sound.

Looks like that has the features I need, but hard to follow with no Javadoc. So I don’t know how to fix EasyOgg stopping problem. You able to assist more?

You could always mail the author?

If you provide your changes as a diff I’ll happily apply them (though FindBugs default set is full of misconceptions and over compensations). As to the updates you request, there’s a new version of EasyOGG available. You should find:

	 * Attempt to set the global gain (volume ish) for the play back. If the control is not supported
	 * this method has no effect. 
	 * @param gain The gain value
	public void setGain(float gain);

	 * Attempt to set the balance between the two speakers. -1.0 is full left speaker, 1.0 if full right speaker.
	 * Anywhere in between moves between the two speakers. If the control is not supported
	 * this method has no effect
	 * @param balance The balance value
	public void setBalance(float balance);

Stopping should be pretty instant now - well as instant as Java Sound will let you have. It should also cope with replays alright. If not, try mailing the author.


Wow thanks.
Well then next time I might have to bother the author :stuck_out_tongue:
I just thought I would get faster action here since its a small basic package.
Off to work with the changes
Thanks again.

Your stopped method isn’t working so great.
I solved it by so:

public boolean stopped() {
		return (player == null || !player.isAlive());

The stop is good but will still glitch up badly when you stop and then soon play it again.
I also found that checking if a clip is stopped and then set and play a new clip it doesn’t sound to nice when changing over.

K, will add this tonight. Have you got a sample that gives the not nice change over. On WinXP here everything sounds normal but Java Sound is such an awkward beast cross platform.


Just tested the setGain, works great. Might want to add what values to accept in the JavaDoc. Though I found that on google that -80 is mute.

About that problem. I’m also using XP. Anyway this is what code I use.
This is what happens at the start of a battle:

try {
	music = new OggClip("Music Clip");
} catch (final IOException e) {
	System.out.println("Sound failed to load");

Then in my rendering method has.

try {
	music = new OggClip("Music Clip");
} catch (final IOException e) {
	System.out.println("Sound failed to load");

Oh and another handy method would be the pause/resume.

Uploaded another version. Applied your stopped() method, add pause()/resume().

I think the problem when changing sounds is down to Java 2D, doesn’t happen here so I guess it’s driver specific. Could try reusing the clip.


Sorry should of used different names, they are 2 different clips.
I think they are overlapping slightly. But if its a driver problem then don’t worry about it.
But a way around it is maybe able give a list of songs which it will play through the list.

Anyway I’m finding your updates very helpful.
I couldn’t mute with your new change in the setgain.
I fixed it by uncommenting “control.getMinimum();” then setting the default gain to 1. Not sure if that’s the right way but it got mute working again.

Also you might want to have a ispaused method or change resume to play when there’s nothing to resume.
Also noticed you bundle the old version of Jorbis, the .17 version works well with this.

Thanks again.

Ok, updated:

0.17 caused me some issues in another project so I haven’t updated locally yet. :slight_smile:


Good work.
But did find that the default volume was on mute, I modified your setgain method to accept a value of -1 which resets the volume to normal again. Then set the default gain to -1.

Been trying use the pause but seems its too buggy atm how I use it.

This is the start of my walk cycle

if(!ogg.isPaused() && ogg.stopped()){;
else if(ogg.isPaused()){

Then I have this at the end of my walk cycle:


It ticks loud when it pauses/resumes and after a few steps it just keeps ticking even when standing still.

Ok I did a bit more testing. I think I solved the always ticking problem when I change the end of the walking cycle to this:


But still have the pause/resume ticks, but this only happens when there’s a large pause between pause and the resume.
Meaning if I keep walking I get no ticks. But if I stop-walk-stop-walk I get really bad ticking.

I’ll take a look tonight. Setting the default gain to -1 makes no sense to me. That means you should be getting the minimum value supported by your master gain control. Hopefully it’ll make sense tonight :slight_smile:


Maybe I should of explained a little better.
When -1 is entered it sets it to default volume. Because it was impossible to get that default volume back.

if(gain == -1){

Ah looks like I still get that horrible clicking noise for walking even when I don’t walk.
So I still can’t use the pause/resume :frowning:
Hope you can fix that.

Okie, I’ve done the things above and tried setGain(0) on pause() and setGain(oldGainValue) on resume. Hopefully should get it quiet quicker?


Sorry but still more problems :’(
Might want to change your setGain to let it accept the -1 :wink:

public void setGain(float gain) {
	if ((gain < 0 && gain != -1) || (gain > 1)) {

Having a default gain value of 1 it will distort the sound clips, making my music sound horrible. So you might want to leave the default as default :stuck_out_tongue:
Also still horrible ticking for pause/resume. If you can’t fix this then it doesn’t matter, I could just leave out things that require the pause atm.

Doh, shows how much I don’t use EasyOGG for my stuff doesn’t it? :slight_smile:

I’ll post the update tonight. Shame the pause/resume thing doesn’t want to resolve - suprised setting gain to the minimum value doesn’t give an instant silence - I seem to remember reading something about sound effects that doesn’t fade out give some clicking feeling. Maybe it should try fade out.