Converting Mono Stream to Stereo Stream
843802Aug 14 2009 — edited Aug 17 2009hi, i´m new to javax.sound and i have a problem to convert my mono stream in stereo stream. until now i have only work with mono, but now i have an additional soundcard with 3 stereo outputs and i have to change them, so that i have 6 mono outputs.
i decided to solve this by changing the AudioFormat in stereo and then copy the audio data in left channel or right channel.
First problem is to get AudioFormat in stereo:
// mono: private final AudioFormat ulawformat= new AudioFormat(Encoding.ULAW,8000,8,1,1,8000,false);
// mono: protected final AudioFormat pcmFormat = new AudioFormat(Encoding.PCM_SIGNED,8000.0f,8,1,2,8000.0f,false);
changed in:
protected final AudioFormat pcmFormat = new AudioFormat(Encoding.PCM_SIGNED,8000.0f,16,2,4,8000.0f,false);
i can start a call, but my speaking is like mickey mouse, i properly have to change also my ulawformat???
with: private final AudioFormat ulawformat= new AudioFormat(Encoding.ULAW,8000,8,2,1,8000,false); it isn´t better!
public void write(long timestamp, byte[] data, boolean absolute) {
byte outBytes[] = new byte[1024];
Encoding encodingPCM = pcmFormat.getEncoding();
AudioInputStream ulawStream= new AudioInputStream(new ByteArrayInputStream(data),ulawformat,data.length);
AudioInputStream pcmStream = AudioSystem.getAudioInputStream(encodingPCM, ulawStream);
int nbytesRead = pcmStream.read(outBytes, 0, outBytes.length); // outBytes.length);
buffer.putBytes(outBytes,nbytesRead); //ringbuffer
}catch(Exception e){e.printStackTrace();}
can someone help me, please?
thanks, karen