[OT] Sound in Java

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
Reply to
Tim Wescott
Loading thread data ...

way

On what platform? PC or Phones, etc.?

Reply to
linnix

Sorry -- PC.

--
www.wescottdesign.com
Reply to
Tim Wescott

ble

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

Reply to
linnix

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

Reply to
Vladimir Vassilevsky

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
Reply to
Tim Wescott

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.

Reply to
David Brown

Simplest way is the AWT toolkit.

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

George

Reply to
George Neuner

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
Reply to
Tim Wescott

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
Reply to
Frank Buss

So much for portability 8-/

Works on Suse, Windows XP and 7, though.

George

Reply to
George Neuner

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

George

Reply to
George Neuner

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.
Reply to
jebblue

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.)
Reply to
Boudewijn Dijkstra

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.