Sign in to follow this  
Flawe

[java] JavaSound Clip problem

Recommended Posts

How come when I load an ogg file and play it as a clip, it causes my rendering (Jogl) to lag? I tried even playing the clip in a thread of its own and it still does that. The ogg file is just a little above 1MB in size. What am I doing wrong? I don't want to have to play midis in the background :P Thanx [Edited by - Flawe on May 27, 2005 9:01:14 AM]

Share this post


Link to post
Share on other sites
If it isn't too much trouble if you post up your code I/we could have a look at it and see if anything jumps out… Usually if one thread is hogging all the cpu a command like thread.yield() will help drastically.

Share this post


Link to post
Share on other sites
While this is unrealated, it does have to do with the java sound clip, I found it to be a BIG gotcha, so I am going to post it.


One thing to watch out for is when you create a clip, you should do a copy of byte array you give it.

Like so:

ps.clip.open(ls.format,(byte[])ls.data.clone(),0,((int)ls.frameLength*ls.format.getFrameSize()));

Doing this, will cause problems mentioned below:

ps.clip.open(ls.format,ls.data,0,((int)ls.frameLength*ls.format.getFrameSize()));


Under windows if you dont do a copy, everything is cool, but if you are using Mac OS X and java 1.4.1, and you dont make sure you copy the data, the next time you play that sound, it will cause horrid static.

The problem isnt present in 1.4.2 on OS X(think people hate Java for a reason?)[grin]

As you can imagine this took me forever to figure out, and I think it has somthing to do with Mac's underlying implementation of the 1.4.1 and it's ties to the Mac audio subsystem, and that it isnt sharing the memory gracefully. Either way just FYI =D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this