Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (575)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2 3
  ignore  |  Print  
  Improving EasyOgg  (Read 21138 times)
0 Members and 1 Guest are viewing this topic.
Offline zammbi

JGO Coder


Medals: 4



« Posted 2008-06-08 05:00:56 »

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.

Current project - Rename and Sort
Offline gouessej
« Reply #1 - Posted 2008-06-08 10:05:38 »

Hi!

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

Offline zammbi

JGO Coder


Medals: 4



« Reply #2 - Posted 2008-06-08 10:35:20 »

Thanks
I got the source from http://www.cokeandcode.com/node/625
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.

Current project - Rename and Sort
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2008-06-08 11:43:09 »

Look at my source code(under GPL licence), the class "main.SoundSystem.java" succeeds in stopping a sound.

Offline zammbi

JGO Coder


Medals: 4



« Reply #4 - Posted 2008-06-08 12:56:09 »

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?

Current project - Rename and Sort
Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2008-06-08 16:01:19 »

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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
   /**
    * 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.

Kev

Offline zammbi

JGO Coder


Medals: 4



« Reply #6 - Posted 2008-06-09 01:00:03 »

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

Current project - Rename and Sort
Offline zammbi

JGO Coder


Medals: 4



« Reply #7 - Posted 2008-06-09 02:14:54 »

Your stopped method isn't working so great.
I solved it by so:
1  
2  
3  
4  
   
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.

Current project - Rename and Sort
Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #8 - Posted 2008-06-09 07:16:32 »

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.

Kev


Offline zammbi

JGO Coder


Medals: 4



« Reply #9 - Posted 2008-06-09 07:43:04 »

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:
1  
2  
3  
4  
5  
6  
try {
   music = new OggClip("Music Clip");
} catch (final IOException e) {
   System.out.println("Sound failed to load");
}
music.play();


Then in my rendering method has.
1  
2  
3  
4  
5  
6  
7  
8  
9  
   
if(music.stopped()){
try {
   music = new OggClip("Music Clip");
} catch (final IOException e) {
   System.out.println("Sound failed to load");
}
music.loop();
}


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


Current project - Rename and Sort
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #10 - Posted 2008-06-09 18:18:32 »

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.

http://www.cokeandcode.com/downloads/EasyOgg-0.3.zip

Kev

Offline zammbi

JGO Coder


Medals: 4



« Reply #11 - Posted 2008-06-10 04:02:47 »

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.

Current project - Rename and Sort
Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #12 - Posted 2008-06-10 06:09:11 »

Ok, updated: http://www.cokeandcode.com/downloads/EasyOgg-0.4.zip

0.17 caused me some issues in another project so I haven't updated locally yet. Smiley

Kev

Offline zammbi

JGO Coder


Medals: 4



« Reply #13 - Posted 2008-06-10 07:42:27 »

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
1  
2  
3  
4  
5  
6  
7  
         
if(!ogg.isPaused() && ogg.stopped()){
   ogg.play();
}
else if(ogg.isPaused()){
   ogg.resume();
}


Then I have this at the end of my walk cycle:
1  
ogg.pause();


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

Edit:
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:
1  
2  
3  
if(!ogg.stopped()){
   ogg.pause();
}

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.

Current project - Rename and Sort
Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #14 - Posted 2008-06-10 09:14:20 »

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 Smiley

Kev

Offline zammbi

JGO Coder


Medals: 4



« Reply #15 - Posted 2008-06-10 09:41:25 »

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.
1  
2  
3  
4  
5  
if(gain == -1){
   control.setValue(0);
}else{
   control.setValue(min+range*gain);
}

Current project - Rename and Sort
Offline zammbi

JGO Coder


Medals: 4



« Reply #16 - Posted 2008-06-10 15:11:41 »

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  Sad
Hope you can fix that.

Current project - Rename and Sort
Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #17 - Posted 2008-06-10 19:42:01 »

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

http://www.cokeandcode.com/downloads/EasyOgg-0.5.zip

Kev

Offline zammbi

JGO Coder


Medals: 4



« Reply #18 - Posted 2008-06-11 07:32:06 »

Sorry but still more problems  Cry
Might want to change your setGain to let it accept the -1  Wink
1  
2  
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  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.

Current project - Rename and Sort
Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #19 - Posted 2008-06-11 08:07:33 »

Doh, shows how much I don't use EasyOGG for my stuff doesn't it? Smiley

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.

Kev

Offline zammbi

JGO Coder


Medals: 4



« Reply #20 - Posted 2008-06-11 08:24:40 »

Well ogg is used in a lot of things so I'm sure someone must no how to fix the clicking problem.
Though fading would be good if you could add that. Though not sure if it would solve my problem unless the fade time was short or able to set the fade time.
Would make my music a lot nicer when stopping since its just a instant stop.

Current project - Rename and Sort
Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #21 - Posted 2008-06-11 09:18:45 »

Heh, I use OGG, just not EasyOGG Smiley I'm mostly pushing the OGGs to OpenAL rather than to Java sound.

Kev

Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #22 - Posted 2008-06-11 17:57:22 »

Think I got what you were talking about.

http://www.cokeandcode.com/downloads/EasyOgg-0.6.zip

Kev

Offline zammbi

JGO Coder


Medals: 4



« Reply #23 - Posted 2008-06-11 21:40:32 »

Ok cool.
Hopefully someone can help with the 2 horrible clicking problems, I been playing around trying to stop it with no luck.

Current project - Rename and Sort
Offline gouessej
« Reply #24 - Posted 2008-10-18 07:34:29 »

I thank you for your source code. I think I'm going to study it because I have to rewrite the sound system of my game because of problems with too often full garbage collections.

Offline gouessej
« Reply #25 - Posted 2008-10-25 20:02:14 »

There is something wrong with EasyOgg. It is impossible to play 2 sounds simultaneously. I tried to use 2 OggClip instances at the same time and I heard only the first one. Do you know how to solve this problem? I think that each clip uses the same SourceDataLine instance  Huh

Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #26 - Posted 2008-10-25 22:03:22 »

It was originally implemented just so someone could play ogg music through JavaSound, so no mixer was required. It'd need mixer support to get multiple sound fx working I think. Assuming your oggs have the same rate/channels the same line might get picked by AudioSystem currently I guess (?), though here it works with multiple clips it seems.

Kev

Offline gouessej
« Reply #27 - Posted 2008-10-26 08:47:41 »

though here it works with multiple clips it seems.
Why does it work with multiple clips in your case? Do they have different rates?

Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #28 - Posted 2008-10-26 11:28:14 »

My clips do have different rates, but I'm not sure thats the reason it works. It could be the JavaSound implementation also. I'm on Windows here.

Kev

Offline gouessej
« Reply #29 - Posted 2008-10-26 16:02:35 »

My clips do have different rates, but I'm not sure thats the reason it works. It could be the JavaSound implementation also. I'm on Windows here.

Kev
Lol, my problem is reproducible under Linux and Windows XP  Wink I think that the default mixer selected by the audio system supports only a very few lines on some machines. I'm going to select the mixer by myself.

Some controls are not supported by the default mixer. Instead of using a lot of try/catch clause, I prefer using the method Mixer.isControlSupported(Type control).

Pages: [1] 2 3
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (35 views)
2014-10-17 03:59:02

Norakomi (26 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (26 views)
2014-10-15 16:18:58

TehJavaDev (50 views)
2014-10-14 00:39:48

TehJavaDev (50 views)
2014-10-14 00:35:47

TehJavaDev (40 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (75 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!