dcsimg
How can I get information about a WAV file using an InputStream?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Yoav_Gonen
Posted On:   Tuesday, June 25, 2002 07:00 AM

I'm trying to get information about a WAV file, such as the encoding. Using this code: File f = new File("filename.wav"); AudioFileFormat fmt = AudioSystem.getAudioFileFormat(f); AudioFormat audioFmt = fmt.getFormat(); AudioFormat.Encoding enc = audioFmt.getEncoding(); System.out.println(enc.toString()); I get the desired information (e.g. ALAW). When I try this approach: File f = new File("filename.wav"); FileInputStream fis = new FileInputStream(f); AudioFileFormat fmt = AudioSystem.getAudioFileFormat (new BufferedInputStream(fis)); AudioFormat audioFmt = fmt.getFormat(); AudioFormat.Encoding enc = audio   More>>


I'm trying to get information about a WAV file, such as the encoding. Using this code:

			
File f = new File("filename.wav");
AudioFileFormat fmt = AudioSystem.getAudioFileFormat(f);
AudioFormat audioFmt = fmt.getFormat();
AudioFormat.Encoding enc = audioFmt.getEncoding();
System.out.println(enc.toString());


I get the desired information (e.g. ALAW). When I try this approach:

			
File f = new File("filename.wav");
FileInputStream fis = new FileInputStream(f);
AudioFileFormat fmt = AudioSystem.getAudioFileFormat
(new BufferedInputStream(fis));
AudioFormat audioFmt = fmt.getFormat();
AudioFormat.Encoding enc = audioFmt.getEncoding();
System.out.println(enc.toString());


I get a different result (PCM_SIGNED). Any ideas why?
   <<Less

Re: How can I get information about a WAV file using an InputStream?

Posted By:   Christopher_Koenigsberg  
Posted On:   Tuesday, June 25, 2002 07:53 AM

Disclaimer: Shooting from the hip, closed book test, just guessing:



If you don't start with a file that really specifies a format in its header (have you tried "setFormat" and "setEncoding" first?), but rather if you start with an "empty object" ("new filename.wav") and try to "get" the format/encoding of the empty object, you're just going to get some defaults "inserted" somewhere along the way.



"ALAW" is crappy compressed old telephone quality audio, I think it's limited to 8 bit resolution (but also compressed), and 8KHz sample rate (thus the highest pitched sound it can pass is only 4KHz, like a telephone where you cannot tell the difference between an "f" and an "s" for instance).



"PCM SIGNED" is nice uncompressed linear 16-bit resolution, 44.1KHz (but takes a lot more bytes), e.g. standard CD-quality audio.




All you are determining is what comes through by default, given various kinds of "empty" input. Why don't you set up a real WAV file, with real (well, fixed-point or integer :-) audio content, and real format/encoding, and see what you get for it?

About | Sitemap | Contact