• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting minor sound distortion?

 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi..

just use soundobj.prefatch() method.... it will solve ur problem..
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply, but im afraid im unfamiliar with this method, could you show me a simple example how you use it. Thanks
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does it the applet code work while we try in jframe playing wav sound ?
 
Ranch Hand
Posts: 140
4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic