[OT] Sound in Java

Oct 04, 2011 13 Replies

Rather than putting together $10 worth of pieces from my junkbox to make an exercise timer for my wife, I'm thinking of writing a Java app to do it.



There seems to be a lot of flexibility in how to generate sound from Java, and flexibility = confusion. Does anyone know a good, reliable way to make one damn little beep with perhaps +/- 1/4 of a second of timing accuracy?



Thanks.


www.wescottdesign.com

way

On what platform? PC or Phones, etc.?

Sorry -- PC.

www.wescottdesign.com

ble

wave or mp3 files? It's overkill, but players are free anyway.

Do not use Java. Do the sound by direct WinAPI calls from C. Java sound system is a mess. You are at the mercy of particular JVM. If it seems to work here and now, there is absolutely no warranty that it works anywhere else. Been there, done that, got burned.

Vladimir Vassilevsky DSP and Mixed Signal Design Consultant

formatting link

Dang. I wanted to prototype it on my Linux machine and then give it to my wife for her Windows machine -- hence the idea to use Java.

Oh well -- maybe it'll be some 555s, CD4040s and CD4017s after all...

www.wescottdesign.com

There are /lots/ of ways to write cross-platform code other than java. I do most of my cross-platform stuff with Python (though I must admit I've never tried sound). You can also use cross-platform toolkits, such as wxWidgets (for C++, Python, and many other languages), GTK, QT, etc.

For Python, you might try

formatting link
- it's a toolkit specifically designed to make it easy to write simple cross-platform games in Python. It's bound to easy to make noises with it, and to make a nice bright and cheerful user interface.

Simplest way is the AWT toolkit.

import java.awt.*; public class BeepExample { public static void main(String[] args) { Toolkit.getDefaultToolkit().beep(); } }

George

Except that doesn't seem to work in Ubuntu. Running from the console, System.out.print('\007') works -- we'll see how it likes Windows 7.

www.wescottdesign.com

This should work on Linux and Windows:

formatting link

Use a static main method as usual for a standalone application, which you can start with javaw instead of an applet.

My "beep" research :-)

formatting link

Frank Buss, http://www.frank-buss.de piano and more: http://www.youtube.com/user/frankbuss

So much for portability 8-/

Works on Suse, Windows XP and 7, though.

George

In Windows printing CTRL-G works from the command line but doesn't work in the GUI. AWT.Toolkit.Beep() works in both.

George

I don't know why that guy advised against it. Many games have been written with Java. Why not go with your original idea and have some fun. Take a break from your normal work.

This works great on my machine (Ubuntu 64 bit) and over 5 years old Audigy sound card:

formatting link

// This is my opinion.

Op Tue, 04 Oct 2011 19:00:46 +0200 schreef Tim Wescott :

Years ago I created a toy two-channel tone generator application in Java with sliders for frequency, volume and phase shift. The phase shift was fun because it could cause an unsettling feeling to innocent passers-by. ;)

Anyway, here you can find a stripped-down version that generates a short single-channel 600Hz tone:

formatting link

Gemaakt met Opera's revolutionaire e-mailprogramma: http://www.opera.com/mail/ (Remove the obvious prefix to reply.)

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required