views:

126

answers:

1

Hello. I am using javasound and have an AudioInputStream of format PCM_SIGNED 8000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian

Using AudioSystem.getAudioInputStream(target_format, original_stream) produces an 'IllegalArgumentException: Unsupported Conversion' when the target_format is PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian

Is it possible to convert this stream manually after every read() call? And if yes, how?
In general, how can you compare two formats and tell if a conversion is possible?

A: 

Is it possible to convert this stream manually after every read() call? And if yes, how?

I'm not sure what you want to do, but this seems unnecessary. It makes more sense to buffer your data and to do the format conversion once you actually create the audio input stream.

It appears to me like you are switching from stereo to mono to try and save data transfer sizes. You can achieve the same with proper encoding (to GSM, mu-law or A-law). Note that you might need a plugin to achieve this conversion. More information here: Java Sound Resources

It is possible to convert the stream after each read() call, but if your stream can't convert, it can't convert.

In general, how can you compare two formats and tell if a conversion is possible? You define your two formats and use AudioSystem to check if the conversion is possible.

boolean bConversionSupported = AudioSystem.isConversionSupported(targetFormat, sourceFormat);
Garg Unzola