|
-
September 26th, 2005, 01:43 PM
#1
Questions about sound in Java
I have been playing around with some things, and wanted to ask you experts out there if there is a way to play sounds in Java that are, for lack of a better term, user interactive...
For example, using just BASIC, I can write a program that will create a beep, and I can add stuff to that program to change the tone of that beep as well as the lenght of that beep...
The idea is that a user can be asked for a lenght (in ms or s) and a tone frequency, and the program will sound out the tone for the correct lenght of time.
I looked into the Toolkit beep, but that is just a system beep and I cant see anyway to vary the tone or lenght of the beep.
Ultimately, I want to build an applet that will allow a user to enter a text string and then output that string as audible morse code, with user selected speed and tone. That way the user can simulate a morse code message in 5wpm through 40wpm speeds in various tone frequencies to make it easier to hear each letter being signaled out.
So I was looking at this two ways... the first way which is more dynamic and more preferable in any case looks something like this in bad pseudocode:
Code:
Open User Input dialog
User enters text string
User selects code speed in Words Per Minute
User selsects tone frequency to change the pitch of the sounds
Parse input string and remove spaces and illegal characters
read each char in the new string
find the morse equivalent for the char
play a beep for that char that lasts the correct lenght at the correct frequency
move to next char and repeat until the end of the string
reopen user dialog with option to exit program
In that case all the sound generation is done by the computer. It simply creates a beep that is of dotBeepLen or dashBeepLen length in milliseconds, and of userFreq frequency, so a lower frequency would yield a lower note and a higher freq would create a higher note.
The next idea would be (borrowing from similar apps available on the web) probably simpler, but involve far more files:
Code:
Open User Dialog
Get text string
Get character speed
parse string
strip out bad chars
find first char in string
find matching sound file
play sound file at appropriate speed
get next char
repeat
Roughly, thats how I would like it to go. The upside of the first one is that it uses only the code I write. But I have no earthly idea where to even begin wiht the sound creation.
The upside of the second one is no sound creation, but the downside is that I need at least 40 premade .au files in addition to the source code.
So, Any ideas, or suggestions, or comments would be appreciated. I have found lots on playing sounds that come in .wav or .mp3 or .au or whatever, and plenty on making a simple system error beep using java.awt.Toolkit, but nothing so far that really helps me figure this out...
Like I said, in something as simple as BASIC I could create the sounds easily (and have done so quite a few times on little programs) but I have no clue how to do this in Java, if it is even possible...
Thanks all!
Jeff
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|