EmbeddedRelated.com
Forums

[OT] Sound in Java

Started by Tim Wescott October 4, 2011
On Wed, 05 Oct 2011 12:59:55 -0500, Tim Wescott <tim@seemywebsite.com>
wrote:

>On Tue, 04 Oct 2011 23:58:14 -0400, George Neuner wrote: > >> On Tue, 04 Oct 2011 12:00:46 -0500, Tim Wescott <tim@seemywebsite.com> >> wrote: >> >>>There seems to be a lot of flexibility in how to generate sound from >>>Java, ... >> >> Simplest way is the AWT toolkit. >> >> import java.awt.*; >> public class BeepExample >> { >> public static void main(String[] args) { >> Toolkit.getDefaultToolkit().beep(); >> } >> } >> > >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.
So much for portability 8-/ Works on Suse, Windows XP and 7, though. George
On Wed, 05 Oct 2011 12:59:55 -0500, Tim Wescott <tim@seemywebsite.com>
wrote:

>Except [Toolkit.Beep()] doesn't seem to work in Ubuntu. Running from >the console, System.out.print('\007') works -- we'll see how it likes Windows 7.
In Windows printing CTRL-G works from the command line but doesn't work in the GUI. AWT.Toolkit.Beep() works in both. George
On Tue, 04 Oct 2011 15:06:54 -0500, Tim Wescott wrote:

> On Tue, 04 Oct 2011 13:17:56 -0500, Vladimir Vassilevsky wrote: > >> Tim Wescott wrote: >> >>> 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? >> >> 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. >> > 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...
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: http://www.oracle.com/technetwork/java/index-139508.html -- // This is my opinion.
Op Tue, 04 Oct 2011 19:00:46 +0200 schreef Tim Wescott
<tim@seemywebsite.com>:
> 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?
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: http://indes.com/~boudewijn/AudioTest.java -- Gemaakt met Opera's revolutionaire e-mailprogramma: http://www.opera.com/mail/ (Remove the obvious prefix to reply.)