zammbi
|
 |
«
Posted
2008-06-08 07: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.
|
|
|
|
gouessej
|
 |
«
Reply #1 - Posted
2008-06-08 12:05:38 » |
|
Hi!
I will look at your code. I'm using JOGG and JORBIS, I didn't know EasyOgg.
|
|
|
|
zammbi
|
 |
«
Reply #2 - Posted
2008-06-08 12:35:20 » |
|
Thanks I got the source from http://www.cokeandcode.com/node/625It 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.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
gouessej
|
 |
«
Reply #3 - Posted
2008-06-08 13:43:09 » |
|
Look at my source code(under GPL licence), the class "main.SoundSystem.java" succeeds in stopping a sound.
|
|
|
|
zammbi
|
 |
«
Reply #4 - Posted
2008-06-08 14: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?
|
|
|
|
kevglass
|
 |
«
Reply #5 - Posted
2008-06-08 18: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
| public void setGain(float gain);
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
|
|
|
|
zammbi
|
 |
«
Reply #6 - Posted
2008-06-09 03:00:03 » |
|
Wow thanks. Well then next time I might have to bother the author  I just thought I would get faster action here since its a small basic package. *Off to work with the changes* Thanks again.
|
|
|
|
zammbi
|
 |
«
Reply #7 - Posted
2008-06-09 04: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.
|
|
|
|
kevglass
|
 |
«
Reply #8 - Posted
2008-06-09 09: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
|
|
|
|
zammbi
|
 |
«
Reply #9 - Posted
2008-06-09 09: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.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
kevglass
|
 |
«
Reply #10 - Posted
2008-06-09 20: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.zipKev
|
|
|
|
zammbi
|
 |
«
Reply #11 - Posted
2008-06-10 06: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.
|
|
|
|
|
|
zammbi
|
 |
«
Reply #13 - Posted
2008-06-10 09: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: 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.
|
|
|
|
kevglass
|
 |
«
Reply #14 - Posted
2008-06-10 11: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  Kev
|
|
|
|
zammbi
|
 |
«
Reply #15 - Posted
2008-06-10 11: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); } |
|
|
|
|
zammbi
|
 |
«
Reply #16 - Posted
2008-06-10 17: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  Hope you can fix that.
|
|
|
|
|
|
zammbi
|
 |
«
Reply #18 - Posted
2008-06-11 09:32:06 » |
|
Sorry but still more problems  Might want to change your setGain to let it accept the -1  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  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.
|
|
|
|
kevglass
|
 |
«
Reply #19 - Posted
2008-06-11 10:07:33 » |
|
Doh, shows how much I don't use EasyOGG for my stuff doesn't it? 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
|
|
|
|
zammbi
|
 |
«
Reply #20 - Posted
2008-06-11 10: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.
|
|
|
|
kevglass
|
 |
«
Reply #21 - Posted
2008-06-11 11:18:45 » |
|
Heh, I use OGG, just not EasyOGG  I'm mostly pushing the OGGs to OpenAL rather than to Java sound. Kev
|
|
|
|
kevglass
|
 |
«
Reply #22 - Posted
2008-06-11 19:57:22 » |
|
|
|
|
|
zammbi
|
 |
«
Reply #23 - Posted
2008-06-11 23: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.
|
|
|
|
gouessej
|
 |
«
Reply #24 - Posted
2008-10-18 09: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.
|
|
|
|
gouessej
|
 |
«
Reply #25 - Posted
2008-10-25 22: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 
|
|
|
|
kevglass
|
 |
«
Reply #26 - Posted
2008-10-26 00: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
|
|
|
|
gouessej
|
 |
«
Reply #27 - Posted
2008-10-26 09: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?
|
|
|
|
kevglass
|
 |
«
Reply #28 - Posted
2008-10-26 12: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
|
|
|
|
gouessej
|
 |
«
Reply #29 - Posted
2008-10-26 17: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  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).
|
|
|
|
|