comparison audio/java/StreamSink.java @ 0:672052bd81f8

Initial partial import.
author samer
date Wed, 19 Dec 2012 22:38:28 +0000
parents
children 63cefb01cbab
comparison
equal deleted inserted replaced
-1:000000000000 0:672052bd81f8
1 /*
2 * StreamSink.java
3 *
4 * Copyright (c) 2000, Samer Abdallah, King's College London.
5 * All rights reserved.
6 *
7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
8 * without even the implied warranty of MERCHANTABILITY or
9 * FITNESS FOR A PARTICULAR PURPOSE.
10 */
11
12 package samer.audio.alt;
13
14 import javax.sound.sampled.*;
15 import java.io.*;
16
17 import org.tritonus.share.sampled.AudioSystemShadow;
18 import org.tritonus.share.sampled.file.AudioOutputStream;
19
20 /**
21 An AudioSink that writes to an OutputStream
22 */
23
24 public class StreamSink extends AudioSink
25 {
26 AudioOutputStream out;
27
28 public StreamSink(AudioOutputStream stream) { super(stream.getFormat()); out=stream; }
29
30 public void dispose() {
31 try { out.close(); }
32 catch (IOException ex) { print("*** Error closing: "+ex); }
33 }
34
35 public void stop() {}
36 public void start() {}
37 public int bwrite(byte []buf, int off, int n) throws Exception { return out.write(buf, off, n); }
38
39 public String toString() { return "StreamSink: "+getFormat(); }
40
41 public static AudioOutputStream wavOutputStream(OutputStream stream, AudioFormat fmt) throws Exception {
42 // could alse have raw output stream
43 return AudioSystemShadow.getAudioOutputStream(
44 AudioFileFormat.Type.WAVE,fmt,AudioSystem.NOT_SPECIFIED,stream);
45 }
46 }