File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Java Sound API

George Krueger
Greenhorn

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();
System.out.println(format.toString());

/**
* 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(
AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate(),
format.getSampleSizeInBits() * 2,
format.getChannels(),
format.getFrameSize() * 2,
format.getFrameRate(),
true);
stream = AudioSystem.getAudioInputStream(tmp, stream);
format = tmp;
}
DataLine.Info info = new DataLine.Info(
Clip.class,
stream.getFormat(),
((int) stream.getFrameLength() *
format.getFrameSize()));
System.out.println(info.isFormatSupported(format));
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(stream);
currentSound = clip;
}
catch (Exception ex) {
System.out.println("Could not obtain dataline");
ex.printStackTrace();
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Sound API