sound : Java Glossary

home page S words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all) ©1996-2010 2008-01-21 Roedy Green, Canadian Mind Products
sound
The official Java sound interface is called JMF. It can play many audio and video file formats including MP3. The catch is, the user has to download and hook up the JMF jar files to make it work. So you might want something simpler.
Introduction Sound Files Used On This Site
Playing A Sound with javax.sound.sampled Canned Sound Sources
Applet Sound with java.applet.AudioClip Learning More
Synthesizing Sound Mathematically Links
Common Sound File Types

Introduction

I have posted some source code to create sounds mathematically, i.e. create AU files in RAM and play them with sun.audio.AudioPlayer.start. If you feed it a Math.sin wave for example you will hear an smooth continuous tone of the same frequency as the sine wave. You can create any theoretically possible sound. All you need is a way of mathematically describing it, or providing a list of amplitudes. sun.audio is not an official class. It is accessible in Applets in Java version 1.1, not in JDK 1.2, but is now back again in JDK 1.4.

The Java Sound engine can render 8 or 16-bit audio data, in mono or stereo, with sample rates from 8KHz to 48KHz, that might be found in streaming audio or any of the supported file formats. You can also play *.au, *.wav, *.midi (SMP 0, SMF 1 and RMP) and *.aiff files with java.applet. AudioClip. play. For *.au files use G.711 µ-law format did not originally support PCM. Originally, you could use only 8-bit, 8000 Hz, single-channel (mono) NEXT/Sun *.au files with G.711 µ-law compression. However JDK 1.6.0_10+ does play PCM_SIGNED 8000.0 Hz, 8-bit, 64 kpbs, mono. Java supports only 8 KHz to 48 KHz.

In my Vercheck app, I used Sun PCM_SIGNED 8000.0 Hz, 8-bit, 64 kpbs, mono.

If your files are in other formats such as *.mp3, you can use a utility like Goldwave to convert them. Unfortunately, not all *.wav files or all *.midi files will play. You just have to test them.

Using AudioClip, I have managed to get *.wav and *.au files to work on Vista, but not *.midi or *.mp3.

RealPlayer is required for *.ra files. AudioClip has been around since JDK 1.0.

You can use javax.sound.midi to play MIDI files. It has been around since JDK 1.3.

You can use javax.sound.sampled.SourceDataLine can be used to merge sampled datastreams and play a variety of sound files. It has been around since JDK 1.3.

Playing A Sound with javax.sound.sampled

This technique works both in Applets and applications. It is suitable also for very large sound files. This code will let you play sound in the background while your program continues computing and responding to GUI events.
Possible formats include AudioFormat.Encoding. PCM_SIGNED, PCM_UNSIGNED, ULAW and ALAW. PCM Pulse Code Modulation is the most widely supported. It is simple linear sampling without any sort of compression. CDs use 16-bit PCM. Possible file types include: AudioFileFormat. Type. AIFC, AIFF, AU, SND and WAVE. Third parties can add support for other types, e.g. MP3. I have a horrible feeling that what is supported depends entirely on the capabilities of the native sound driver on any particular platform. This is not at all WORA. You can find out a bit of what your current platform support with code like this:

Applet Sound with java.applet.AudioClip

Applets can play *.au files, (and *.wav files in Windows) this way:
AudioClip.play

is not very bright. If you call it while a sound is playing, it will not wait for that first sound to complete. It plays the two sounds on top of each other.

Here is a technique to introduce time delays to avoid overlap.

In a similar way, you can use javax.sound.midi to play midi files.

Synthesizing Sound Mathematically

Common Sound File Types

Audio Format MIME Type And Extensions Associated With Them
Extension MIME Type Alternate MIME Types Notes
3gppaudio/3gp audio only, also 3gp
aacaudio/aacaudio/MP4-LATM, audio/x-aac, audio/x-mp4Apple QuickTime compressed audio used in iPods
aifaudio/x-aiff MacIntosh sound
aifcaudio/x-aiff MacIntosh sound
aiffaudio/x-aiff MacIntosh uncompressed sound
asfvideo/x-ms-asf Microsoft media audio and/or video
auaudio/basicaudio/x-pn-austandard Unix/Internet/Java uncompressed wave sound
avivideo/avivideo/x-msvideoearlier Microsoft video format. avi movie, works with Winamp (best), MS Media Player (often audio only), or QuickTime (in theory)
chtaudio/x-dspeech  
dusaudio/x-dspeech  
esaudio/echospeech  
gsdaudio/gsm  
gsmaudio/gsm  
karaudio/midi  
m3uaudio/x-mpegurl  
m4aaudio/mp4 M4A Audio
midaudio/x-midiaudio/midiMIDI sound
midiaudio/x-midiaudio/midiMIDI sound
mp2audio/mpegaudio/x-mpeg 
mp3audio/mp3audio/mpeg, audio/x-mp3, audio/x-mpgmp3/mpeg compressed audio. Popular format for portable music players.
mp4video/mp4  
mpegvideo/mpeg mpeg movie player
mpgaaudio/mpeg  
ogaaudio/ogg Ogg audio
oggaudio/x-oggvorbisapplication/oggencapsulation for Vorbis I non-proprietary audio or video.
ogxapplication/ogg muliplex ogg stream
raaudio/x-pn-realaudio Real Audio
ramaudio/x-pn-realaudio Real Audio
rmaudio/x-pn-realaudioapplication/vnd.rn-realmediaReal Audio
rmfaudio/rmfaudio/x-rmf 
rmmaudio/x-pn-realaudio  
rmsaudio/x-realaudio-secure  
rpmaudio/x-pn-realaudio-plugin Real Audio
sndaudio/basic standard Internet/Java wave sound
streamaudio/x-qt-stream  
tsiaudio/tsplayer  
voxaudio/voxware  
vqeaudio/x-twinvq-plugin  
vqfaudio/x-twinvq  
vqlaudio/x-twinvq  
wavaudio/wavaudio/x-pn-windows-pcm, audio/x-wavMicrosoft wave uncompressed sound files
waxaudio/x-ms-wax Microsoft compressed audio
wmaaudio/x-ms-wma Microsoft compressed audio
wmvvideo/x-ms-wmv Microsoft compressed video. Play with Windows media Player or Winamp. Winamp lets you slide forward and back.
wtxaudio/wtx  
xamlapplication/xaml+xml Silverlight

Sound Files Used On This Site

Audio Links Legend
streaming or downloadable
Click corresponding icon to download player.
Real Audio click to listen
compressed mp3 click to listen
super compressed mp4 click to listen
Microsoft Media Player click to listen
MIDI music files click to listen
uncompressed au click to listen
Microsoft uncompressed wav click to listen
unknown click to listen
lyrics click to listen
transcript click to listen

Canned Sound Sources

Windows stores its *.wav files in C:\WINNT\media or C:\Windows\Media These are the sound effects you hear on error, on incoming mail etc. I find them easier to configure if you listen to them, then copy them with a name meaningful to you. Ones I find useful for configuring for non-system purposes include:
Euphonious Windows Sounds
Sound Name Comments
MUSICA~1.WAV Sounds a bit like the opening to a jazz song, with bass strings.
MUSICAOP.WAV quick short rising scale. Like someone sitting down to a piano and just doing a quick warmup.
MUSICAWI.WAV Like the short musical signature TV networks use.
MUSICACL.WAV Like a strum on an out of tune autoharp.
Utopia Restore Up.WAV sounds like a camera click.
Utopia Critical Stop.WAV Like a cork popping.
Utopia Asterisk.WAV Ding Dong
MUSICA~2.WAV resonant thunk
MUSICAME.WAV Like a drum from India
Hardware Insert.wav 2-note synthesiser-like sound. Vista only.
Hardware Remove.wav 2-note synthesiser-like sound. Vista only.
Of course you can scan the net for WAV files to replace the Microsoft sounds, e.g. HAL saying human error.

Here are some places where you can find canned sounds: Microsoft extra sound schemes, SoundAmerica, FreeAudioClips.com, Sound collection links. Vista no longer comes with a rich set of sounds, so you have to find them on the web.

Learning More

Sun’s Javadoc on javax.sound.midi package : available:
Sun’s Javadoc on javax.sound.sampled package : available:
Sun’s Javadoc on java.applet.AudioClip class : available:
Sun’s Javadoc on getAudioClip class : available:
Sun’s Javadoc on AudioFormat class : available:
Sun’s Javadoc on AudioInputStream class : available:
Sun’s Javadoc on AudioSystem class : available:
Sun’s Javadoc on DataLine class : available:
Sun’s Javadoc on SourceDataLine class : available:
Sun’s Javadoc on Mixer.getSourceLineInfo : available:
Sun’s Javadoc on Line.Info : available:
AboutSound: to find out what sound formats your machine supports
AU
AudioSparx.com: sound effect clips
beep
ClipStream
Crescendo
Freedom Audio
FreeSound: free to use sounds in any way want if you give attribution
Goldwave
Honk: a windows utility to generate sounds from the Windows command line
IMF
Into to javax.media.sound API
javax.media.sound demo
javax.media.sound FAQ
JavaZoom JGui: plays WAV, AU, AIFF, MP3, OGG VORBIS, FLAC, MONKEY’s AUDIO and SPEEX audio formats
JavaZoom MP3 player
JavaZoom vorbis OGG player
JFugue: Java music API
JMF: Java Media Framework
JSAPI
MIDI
MIME
MP-3
Philharmonia orchestra sound samples
Real Audio
Rhythm Tutor Student Project
sound-on-the-fly
Soundbite
SoundEffect.com: sound effect clips
Speaker: make tones on the built-in PC Speaker from Java
Sun Java Sound home
Tritonus: Java sound API alternative implementation
Tritonus: open source Java sound
wav

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/sound.html J:\mindprod\jgloss\sound.html
CMP logofeedback Please email your feedback for publication, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.191.85]
You are visitor number 36,729.