aspose file tools*
The moose likes Game Development and the fly likes Getting minor sound distortion? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Getting minor sound distortion?" Watch "Getting minor sound distortion?" New topic
Author

Getting minor sound distortion?

Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164
Hi there, im developing a space shooter and have just recently learned how to include sounds, it works fine except when firing the same soundclip over and over again very fast.

Here is the code I use for the sound:


This code above is within the class that "owns" that sound, it superclass has a method to generate the sound:

For some reason there is less distortion when I reassign sound to JApplet.newAudioClip(url).

now the main class can call that method to play the sound. My thread calls this method every 60ms while I hold down right mouse button generating a machinegun firing sound.
This works great except the game stops responding every once in awhile for about 5ms or something, not that serious but noteworthy.
How can I accomplish this task without that distortion? That is replay the same sound clip every 60ms.
By the way the soundclip is in .wav format, lowest quality.
Ashish Parekh
Greenhorn

Joined: Nov 11, 2005
Posts: 7
hi..

just use soundobj.prefatch() method.... it will solve ur problem..


A. G. Parekh
Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164
Thanks for your reply, but im afraid im unfamiliar with this method, could you show me a simple example how you use it. Thanks
J. Insi
Ranch Hand

Joined: Aug 11, 2010
Posts: 84
does it the applet code work while we try in jframe playing wav sound ?
Phil Freihofner
Ranch Hand

Joined: Sep 01, 2010
Posts: 115
    
    1
Hi -
I have only used the javax.sound.sampled libraries for playing sounds, but maybe some of what happens there also applies to your case.
A sound should probably be played on its own thread, as it can block (prevent other things from executing while it is playing).
Also, there might be problems if you try to play a sound again before it's finished playing.
Last, if you preload sounds (in the javax.sound.sampled libraries, this is done with a Clip object), they can be played quickly. So, if there is a way to preload your sound, maybe pre-make an array of as many as will ever sound at the same time (including overlapping) and launch them from their own threads.
This could be terrible advice, since I haven't become acquainted with the Applet's Sound support.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting minor sound distortion?
 
Similar Threads
Analog guitar distortion
font distortion