Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (578)
games submitted by our members
Games in WIP (499)
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  
  javax.sound.sampled 1.4.1 problem  (Read 4673 times)
0 Members and 1 Guest are viewing this topic.
Offline lamster

Senior Newbie





« Posted 2003-02-09 21:34:08 »

When playing sampled sounds using the Windows java 1.4.1 virtual machine, sounds play back incorrectly and the sound thread blocks all other goings-on, causing the main game thread to slow down and chop madly.  After some testing I've concluded that this problem does not exist under the Windows 1.4.0_* runtimes and all other previous runtimes that implement javax.sound.sampled.

Am I doing something wrong?  Or is the new runtime just horribly flawed?

I've posted an example jar (source included) that demonstrates the problem at
http://www.zianet.com/emeasure/SoundTest.jar

To run:
java -jar SoundTest.jar
p to play sound
arrow keys to move oval (demonstrates choppiness)

Relevant code:
--------------------------------------

private Clip clip;

private final void initializeClip()
{
     try
     {
           AudioInputStream stream =
           AudioSystem.getAudioInputStream( getClass().getResource( "test.wav" ) );
           
           AudioFormat format = stream.getFormat();
           
           DataLine.Info info = new DataLine.Info(
           Clip.class, stream.getFormat(), ( (int) stream.getFrameLength() * format.getFrameSize() ) );
           clip = (Clip) AudioSystem.getLine( info );
           
           // Wait until audio file completely loaded
           clip.open( stream );
     } catch( Exception e )
     {
           e.printStackTrace();
     }
}

private final void playClip()
{
     clip.setFramePosition( 0 );
     clip.loop( 0 );
}


--------------------------------------
Thanks in advance for any insights you can provide,
lamster
Offline erikd

JGO Ninja


Medals: 15
Projects: 4
Exp: 14 years


Maximumisness


« Reply #1 - Posted 2003-02-10 07:20:48 »

Tried your test and I got the same problem.
In fact I have very bad experiences with javax.sound since java 1.3 myself. Sound always lags behind and you will give your program a huge slow down. I also tried to use continuous sound streams using javax.sound.sampled in an emulator. No way to get that to behave like expected.
If I were you I'd give open-al a try.

[rant]
I think Sun should stop adding features for a while and start making their java platform stable, reliable and well performing.
[/rant]

Offline Pops

Senior Newbie




I love YaBB 1G - SP1!


« Reply #2 - Posted 2003-02-12 14:25:02 »

lamster - haven't tried yours but I can confirm it with my own game.  Ran smooth as silk under 1.4.0 - under 1.4.1 whenever I hit a clip.start() - I get a small pause (thought it was the GC but then debugged it down to that line).  If I comment out that line (effectively disabling the playing of my clips) - then everything runs smooth again...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lamster

Senior Newbie





« Reply #3 - Posted 2003-02-12 14:49:31 »

Thanks for the confirmation guys,

I've submitted the bug to the java parade, let's
hope it's dealt with in 1.4.2.
Offline coramoor

Senior Newbie




Java games rock!


« Reply #4 - Posted 2003-02-14 12:06:59 »

I'm having this problem in my game too.. Every time a sound is played, the game stutters horribly  Cry

What Bug ID did you get? I couldn't find it in the bug parade (or is it too soon?). I read another bug report (Bug ID 4190660) about the sound device not being released after the clips stopped, and that it had been fixed by remodeling the internal behaviour of applet.AudioClip. Maybe this new bug is related to the previous bugfix?
Offline lamster

Senior Newbie





« Reply #5 - Posted 2003-02-14 21:28:30 »

Quote

What Bug ID did you get? I couldn't find it in the bug parade (or is it too soon?).

It's too soon yet; I'll post the pertinent infos to this thread as soon as the bug team sends me a response.  Sun claims typical processing time of about 3 weeks for new bug reports, so expect to wait until at least March 2nd for the update.

In the meantime you can always test your stuff with 1.4.0_03 (http://java.sun.com/j2se/1.4/download.html), but it'll be painful to have to try to distribute an obsolete java as a prerequisite for a release game :(
Offline caraiz

Senior Newbie




Java games rock!


« Reply #6 - Posted 2003-02-20 09:51:06 »

I have the same problem, also i have tried with jmf 2.1.1 but the result is like jdk, so for now i use the "hidden" class <sun.applet.AppletAudioClip>.
I know its not the best solution but it work fine for me,
i hope it works fine for you.  Smiley

Offline Pops

Senior Newbie




I love YaBB 1G - SP1!


« Reply #7 - Posted 2003-02-28 19:18:32 »

FYI - still broken in 1.4.1_02
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #8 - Posted 2003-05-13 18:10:47 »

Quote

In the meantime you can always test your stuff with 1.4.0_03 (http://java.sun.com/j2se/1.4/download.html), but it'll be painful to have to try to distribute an obsolete java as a prerequisite for a release game :(


You really do not want to get people to use 1.4.0. It's utterly utterly rubbish; it's full of really major bugs (NIO is f*cked on windows; Swing's paint routines are partially f*cked on windows - I have example apps that paint funky animations on 1.4.1, and on 1.4.0 you get a black screen.). Look at the bugfixes list for 1.4.1, and you should be able to spot some howlers :).

malloc will be first against the wall when the revolution comes...
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #9 - Posted 2003-05-13 18:14:32 »

Quote
I have the same problem, also i have tried with jmf 2.1.1 but the result is like jdk, so for now i use the "hidden" class <sun.applet.AppletAudioClip>.
I know its not the best solution but it work fine for me,
i hope it works fine for you.  Smiley


Have you tried the NON hidden Applet .newAudioClip(...) method(s)? The ones that are officially sanctioned by Sun? I've not started using the JMF audio (I've heard too many horror stories Wink), so forgive my ignorance if there's some reason they'd be uselss for you. However, I find they work perfectly for playing up to about 5 sounds simultaneously...

1  
2  
3  
      java.net.URL url = getClass().getResource( "clockticks.wav" );
      clockTick = Applet.newAudioClip( url );
      clockTick.play(); // clockTick.loop() or whatever...

malloc will be first against the wall when the revolution comes...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline caraiz

Senior Newbie




Java games rock!


« Reply #10 - Posted 2003-05-16 08:39:44 »

Quote


Have you tried the NON hidden Applet .newAudioClip(...) method(s)? The ones that are officially sanctioned by Sun? I've not started using the JMF audio (I've heard too many horror stories Wink), so forgive my ignorance if there's some reason they'd be uselss for you. However, I find they work perfectly for playing up to about 5 sounds simultaneously...


The reason i dont use newAudioClip is because i want create many AudioClips sharing the same data, so i have the data file in memory and use the constructor sun.applet.AppletAudioClip(byte[]).

All methods i found in jdk need an URL, anybody know a better form to do this?

I think jmf is really bad for play sound, although with video it work fine.

bye!

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #11 - Posted 2003-05-16 09:54:37 »

Quote


The reason i dont use newAudioClip is because i want create many AudioClips sharing the same data, so i have the data file in memory and use the constructor sun.applet.AppletAudioClip(byte[]).


I don't understand - what's the point? How is this different from using the standard library newAudioClip (except that it is non-standard)?

If you create one clip normally, the data file will probably be "in memory" (thanks to disk caching). Once the clips are created,  have you saved any memory? Isn't each clip object still going to need it's own copy of the clip data?

malloc will be first against the wall when the revolution comes...
Offline caraiz

Senior Newbie




Java games rock!


« Reply #12 - Posted 2003-05-19 08:35:57 »

Quote


I don't understand - what's the point? How is this different from using the standard library newAudioClip (except that it is non-standard)?

If you create one clip normally, the data file will probably be "in memory" (thanks to disk caching). Once the clips are created,  have you saved any memory? Isn't each clip object still going to need it's own copy of the clip data?


First i have in memory the clip data in a byte array, and then i create all the audioclips using that array.
How u say, "the data file file will probably be in memory", but i can not be sure of it, also if im in a low internet connection and the data is not in memory, probably the audio will sucks.

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #13 - Posted 2003-05-19 14:41:01 »

Quote


First i have in memory the clip data in a byte array, and then i create all the audioclips using that array.
How u say, "the data file file will probably be in memory", but i can not be sure of it, also if im in a low internet connection and the data is not in memory, probably the audio will sucks.


I see now; I suggest you log a bug with Sun. The API docs ought to tell you whether you needed to do this at all, but they don't...yet another lazy Sun developer wrote:

"newAudioClip

public static final AudioClip newAudioClip(URL url)

   Get an audio clip from the given URL.

   Parameters:
       url - points to the audio clip
   Returns:
       the audio clip at the specified URL.
   Since:
       1.2"

This is NOT documentation, this is a piece of crap. The non-static AudioClip methods were written by someone marginally less lazy, and confess that they are not loaded until you attempt to play them. If the same is true of the static version, then you've obviously got a big problem with the static methods.

Sadly, AudioClip isn't cloneable, and it's unclear whether we should assume (from the lack of documentation) that AudioClips to the same URL do or don't share their loaded data...

malloc will be first against the wall when the revolution comes...
Offline caraiz

Senior Newbie




Java games rock!


« Reply #14 - Posted 2003-05-19 15:46:20 »

Quote


I see now; I suggest you log a bug with Sun. The API docs ought to tell you whether you needed to do this at all, but they don't...yet another lazy Sun developer wrote:

"newAudioClip

public static final AudioClip newAudioClip(URL url)

   Get an audio clip from the given URL.

   Parameters:
       url - points to the audio clip
   Returns:
       the audio clip at the specified URL.
   Since:
       1.2"

This is NOT documentation, this is a piece of crap. The non-static AudioClip methods were written by someone marginally less lazy, and confess that they are not loaded until you attempt to play them. If the same is true of the static version, then you've obviously got a big problem with the static methods.

Sadly, AudioClip isn't cloneable, and it's unclear whether we should assume (from the lack of documentation) that AudioClips to the same URL do or don't share their loaded data...


If u see source of that method, the code is
1  
2  
3  
4  
public static final AudioClip newAudioClip(URL url)
{
return new sun.applet.AppletAudioClip(url);
}
, so it use the same class but with other constructor. And that class create a inputstream for each url, so i dont think the data is shared.
Maybe with javax.sound there are some manner to do that, but i dont know how....

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.

xsi3rr4x (27 views)
2014-04-15 18:08:23

BurntPizza (23 views)
2014-04-15 03:46:01

UprightPath (38 views)
2014-04-14 17:39:50

UprightPath (20 views)
2014-04-14 17:35:47

Porlus (36 views)
2014-04-14 15:48:38

tom_mai78101 (61 views)
2014-04-10 04:04:31

BurntPizza (119 views)
2014-04-08 23:06:04

tom_mai78101 (219 views)
2014-04-05 13:34:39

trollwarrior1 (186 views)
2014-04-04 12:06:45

CJLetsGame (193 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!