Results 1 to 2 of 2
Thread: Making Sounds
- 09-04-2012, 10:52 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 88
- Rep Power
- 0
Making Sounds
Hello. I want to write a program that will generate two audio tones - one high-pitched and one low-pitched - and randomly chose between them and play them repeatedly with a random delay between sounds.
Here is a quickie code I modified that plays one tone with a random delay, using class Toolkit().beep. But what if I want two different tones? I know the java API has a class Synthesizer() and class SamplePlayer(), tho' I don't think I need all the functionality of a synthesizer or a sample-player.
Can anyone suggest other ways to get this done? Thanks.
Java Code:import java.awt.*; import java.io.*; public class timer_beep { public static void main(String[] args) throws IOException { try { System.out.println("Countdown has started!"); Thread.sleep(2000); for (int x=10; x>=0; x-- ) { System.out.println(x); Toolkit.getDefaultToolkit().beep(); Thread.sleep((long) (Math.random() * 3000)); } Thread.sleep(2000); Toolkit.getDefaultToolkit().beep(); System.out.println("Beep beep testing"); } catch(InterruptedException e){ } } }
- 09-05-2012, 12:20 AM #2
Re: Making Sounds
It's no great effort to use Synthesizer, but be aware that the soundbank.gm file distributed with the JDK isn't included with a JRE, so if you need to run your program on a computer which doesn't have a JDK installed you'll need to copy the .../java/jdkXXX/jre/lib/audio folder to .../java/jreN/lib (folders may be different on Linux/MacOS).
An alternative is to obtain a SourceDataLine and write an appropriate byte array to produce the desired tone and duration. Never done that, but I do know it's doable, just a lot more work than simply using a Synthesizer.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Playing sounds on other computers
By jeffpaulwilson in forum AWT / SwingReplies: 0Last Post: 09-14-2011, 09:25 PM -
Sounds?
By Alerhau in forum New To JavaReplies: 3Last Post: 08-29-2011, 07:30 PM -
How can I loop sounds in JPanel?
By rajkobie in forum New To JavaReplies: 4Last Post: 04-24-2011, 03:49 PM -
Wave Sounds
By Doctor Cactus in forum New To JavaReplies: 2Last Post: 10-22-2008, 01:44 PM -
Turn off sounds in Eclipse
By gio.fou in forum EclipseReplies: 2Last Post: 09-06-2008, 08:31 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks