dcsimg
Java audio system cannot play all sampled file formats
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nathan_Meyers
Posted On:   Monday, July 30, 2001 11:00 AM

I'm trying to play arbitrary wavfiles through the Java audio system. My code opens the audio file, obtains the format, sets the format on the SourceDataLine, then copies bits from the file to the SourceDataLine: AudioInputStream ais = AudioSystem.getAudioInputStream(new File(filename)); AudioFormat format = ais.getFormat(); SourceDataLine line; . . (obtain line) . line.open(format); . . (copy from AudioInputStream to line) . It works if my file format happens to be PCM stereo 16-bit 44100Khz, but generates bad sound for all other formats. I'm confused, SourceDataLine.open() doesn't complain about other formats (for example, mono 8-bit 8Khz) - it just fai   More>>

I'm trying to play arbitrary wavfiles through the Java audio system. My code opens the audio file, obtains the format, sets the format on the SourceDataLine, then copies bits from the file to the SourceDataLine:


			
AudioInputStream ais = AudioSystem.getAudioInputStream(new File(filename));
AudioFormat format = ais.getFormat();
SourceDataLine line;
.
. (obtain line)
.
line.open(format);
.
. (copy from AudioInputStream to line)
.

It works if my file format happens to be PCM stereo 16-bit 44100Khz, but generates bad sound for all other formats.


I'm confused, SourceDataLine.open() doesn't complain about other formats (for example, mono 8-bit 8Khz) - it just fails to render the sound properly. Even PCM mono 16-bit 44100Khz sounds fail to render properly: it's very picky!


I also find that I cannot convert file formats. If I try to convert to a format that will work, I get a complaint about illegal conversion:


			
AudioFormat targetFormat = new AudioFormat(44100.0f, 16, 2, true, false);
ais = AudioSystem.getAudioInputStream(targetFormat, ais);

I've seen these problems with both Windows and Linux J2SDK1.3.1. It appears to be a huge piece of missing functionality, but I've found no reference to such limitations anywhere - including the page listing supported formats (http://java.sun.com/products/java-media/jmf/2.1.1/formats.html).

   <<Less

Re: Java audio system cannot play all sampled file formats

Posted By:   Nathan_Meyers  
Posted On:   Monday, July 30, 2001 05:58 PM

OK... the cockpit error has been discovered. Information on the audio format is needed when the SourceDataLine is obtained, not just when it is opened. The code obtained a line supporting only a default audio format.
About | Sitemap | Contact