Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Are short Clips safe to use now?  (Read 3692 times)
0 Members and 1 Guest are viewing this topic.
Offline Dream Of Sleeping
« Posted 2012-04-16 19:43:58 »

Hello. I was reading through Killer Game Programming In Java and the writer mentions a bug which stops Clips from playing if they are under one second. On both my computers Clips that are under 1 second are playing fine. In fact they play better because as the sound will be played again and again rapidly it messes up when I load a clip longer than one second. Will this be fine on most computers now or am I still best to make all my clips over 1 second long?

Offline sproingie

JGO Kernel


Medals: 202



« Reply #1 - Posted 2012-04-16 20:07:44 »

The "short sound bug" is so fixed, they fixed it at least three times!

Seriously, it's something that's had a lot of regressions, and though it does appear to be behaving itself in 1.6, you never know when or if it's going to bite you again.  JavaSound has lots of issues, and serious apps tend to use third party libraries instead, like OpenAL (jogl and lwjgl have bindings for it), Paul Lamb's sound library, or an FMOD binding of some flavor.
Offline Dream Of Sleeping
« Reply #2 - Posted 2012-04-16 20:14:43 »

Thanks for the reply.

Yes I've come to hate java sound with a passion. I will look into other libraries for my next project. But I want to keep it simple for now. I'm just trying to finish my first applet and put it in the showcase section. As long at works ok for now on most computers, I'm ok with it.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Dream Of Sleeping
« Reply #3 - Posted 2012-04-19 07:50:43 »

I was googling more questions about java sound and this thread came up so I thought I may as well post here again!

I emailed my game to my friend for testing and everything works fine, except one of the sounds is inconsistent. It's a puzzle game and you move tiles. You can move these tiles very rapidly, and it makes a sound, and this is the sound that is inconsistent. It works perfectly on both my computers though so it's hard to tell what I can do to improve.

Would you say using a DataLine will be more reliable? I've not had much look with them before but that was for long sounds. I really want to stick to the standard library for this game. I was also thinking of just loading the sound twice and putting it in two clips and alternating them.


Offline philfrei
« Reply #4 - Posted 2012-04-22 20:33:41 »

In what way "inconsistent"?

How is chaining two Clips different from looping a single Clip?

I have done this (two overlapping Clips and two overlapping SourceDataLines), but the motivation was that I wanted them to slightly overlap. Both methods work but are subject to the real-time precision constraints of Java audio (possible disruptions being things like garbage collection, unpredictable thread switching, bouncing back and forth from byte code interpretation to memory). So whether that would work will depend on the tolerances of the sound that you want to be heard.

For example, if the sound that needs to be continuous can variably overlap at the ends for a reasonable range of intervals (if I remember correctly, something like a 1/3rd or 1/2 of a second would be safe) and still sound acceptable, the alternation of two sounds should be okay.

For more consistent or precise timing, Riven had a very good suggestion, that you keep track of desired frame positions (which correspond to specific milliseconds via a calculation using the sample rate) and insert correct amounts of "silence" in order to add the sound at the exact required frame. This would be done with a continuous DataLine (continuous over the duration that you want to be precise about the timing).

"It's after the end of the world! Don't you know that yet?"
Offline Dream Of Sleeping
« Reply #5 - Posted 2012-04-23 11:51:39 »

By inconsitent he meant that the sounds would play sometimes but not others.

I had the same problem at first until I shortened the wav file so there was no silence at the end, then it worked fine on my computers.  Althought it didn't on my friends. This was the method I was using.  Would it have made a difference if I called stop() before setting the framePosition to 0?

1  
2  
3  
4  
5  
6  
7  
8  
9  
   
 public void playClip(String clipName) {
        Clip clip = soundsMap.get(clipName);
       
        if (clip != null) {
            clip.setFramePosition(0);
            clip.start();
        }
    }


This is the method I use now, just for the clicking sound that is played rapidly.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
  public void click() {
        Clip clip = clicks.get(clickIndex);
        clip.setFramePosition(0);
        clip.start();
        clickIndex++;
       
        if (clickIndex >= clicks.size()) {
            clickIndex = 0;
        }
    }


So I have four clicking sounds in an array. This apparently works fine on his computer. No one who tested my game in the showcase section had any problems either. I don't know why this would work better than the other way.

Offline Dream Of Sleeping
« Reply #6 - Posted 2012-04-28 17:28:31 »

I thought I would just add my solution to the problem in case in future someone else is searching.

I added another sound effect which at times needed to play quickly. And I noticed that if the sound was playing it would not replay despite restarting the frame position.  But this code seems to work. I have to stop the clip and flush() it. Also drain() seems to work too. If I only flushed it if  isActive() returned true, it still  didn't work sometimes, so I have to call flush every time.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
 public void playClip(String clipName) {
        Clip clip = soundsMap.get(clipName);
       
        if (clip != null) {
             clip.stop();
             clip.flush();
             clip.setFramePosition(0);
             clip.start();
        }
    }

Pages: [1]
  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.

PocketCrafter7 (13 views)
2014-11-28 16:25:35

PocketCrafter7 (9 views)
2014-11-28 16:25:09

PocketCrafter7 (10 views)
2014-11-28 16:24:29

toopeicgaming1999 (76 views)
2014-11-26 15:22:04

toopeicgaming1999 (66 views)
2014-11-26 15:20:36

toopeicgaming1999 (15 views)
2014-11-26 15:20:08

SHC (29 views)
2014-11-25 12:00:59

SHC (27 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (28 views)
2014-11-24 19:59:16
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!