File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes Java Sound API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Java Sound API" Watch "Java Sound API" New topic

Java Sound API

George Krueger

Joined: Aug 24, 2001
Posts: 1
Has anybody else had trouble with getting certain sound formats to play while using the javax.sound.sampled package.
For example, I can play a sound of the format:
PCM_SIGNED, 11025.0 Hz, 16 bit, mono, little-endian, audio data
But I can't play a sound of the format:
PCM_SIGNED, 44100.0 Hz, 16 bit, stereo, little-endian, audio data
I've checked the Java Sound API website several times, and according to it this sound file should be supported. It says:
"The Java Sound engine can render 8 or 16 bit audio data, in mono or stereo, with sample rates from 8KHz to 48KHz".
I've tried using the isFormatSupported() function to make sure this file format is supported and it returns true. So I really don't know what the problem could be.
Any thoughts?
I've also included my code below.

try {
AudioInputStream stream = (AudioInputStream) currentSound;
AudioFormat format = stream.getFormat();

* we can't yet open the device for ALAW/ULAW playback,
* convert ALAW/ULAW to PCM
if ((format.getEncoding() == AudioFormat.Encoding.ULAW) | |
(format.getEncoding() == AudioFormat.Encoding.ALAW))
AudioFormat tmp = new AudioFormat(
format.getSampleSizeInBits() * 2,
format.getFrameSize() * 2,
stream = AudioSystem.getAudioInputStream(tmp, stream);
format = tmp;
DataLine.Info info = new DataLine.Info(
((int) stream.getFrameLength() *
Clip clip = (Clip) AudioSystem.getLine(info);;
currentSound = clip;
catch (Exception ex) {
System.out.println("Could not obtain dataline");
I agree. Here's the link:
subject: Java Sound API
It's not a secret anymore!