samer@0: /* samer@0: * StreamSink.java samer@0: * samer@0: * Copyright (c) 2000, Samer Abdallah, King's College London. samer@0: * All rights reserved. samer@0: * samer@0: * This software is provided AS iS and WITHOUT ANY WARRANTY; samer@0: * without even the implied warranty of MERCHANTABILITY or samer@0: * FITNESS FOR A PARTICULAR PURPOSE. samer@0: */ samer@0: samer@46: package ishara.audio; samer@0: samer@0: import javax.sound.sampled.*; samer@0: import java.io.*; samer@0: samer@0: import org.tritonus.share.sampled.AudioSystemShadow; samer@0: import org.tritonus.share.sampled.file.AudioOutputStream; samer@0: samer@0: /** samer@0: An AudioSink that writes to an OutputStream samer@0: */ samer@0: samer@0: public class StreamSink extends AudioSink samer@0: { samer@0: AudioOutputStream out; samer@0: samer@0: public StreamSink(AudioOutputStream stream) { super(stream.getFormat()); out=stream; } samer@0: samer@0: public void dispose() { samer@0: try { out.close(); } samer@0: catch (IOException ex) { print("*** Error closing: "+ex); } samer@0: } samer@0: samer@0: public void stop() {} samer@0: public void start() {} samer@0: public int bwrite(byte []buf, int off, int n) throws Exception { return out.write(buf, off, n); } samer@0: samer@0: public String toString() { return "StreamSink: "+getFormat(); } samer@0: samer@0: public static AudioOutputStream wavOutputStream(OutputStream stream, AudioFormat fmt) throws Exception { samer@0: // could alse have raw output stream samer@0: return AudioSystemShadow.getAudioOutputStream( samer@0: AudioFileFormat.Type.WAVE,fmt,AudioSystem.NOT_SPECIFIED,stream); samer@0: } samer@0: }