Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Sound API  RSS feed

George Krueger
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!