view audio/java/StreamSink.java @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents 63cefb01cbab
children
line wrap: on
line source
/*
 *	StreamSink.java
 *
 *	Copyright (c) 2000, Samer Abdallah, King's College London.
 *	All rights reserved.
 *
 *	This software is provided AS iS and WITHOUT ANY WARRANTY;
 *	without even the implied warranty of MERCHANTABILITY or
 *	FITNESS FOR A PARTICULAR PURPOSE.
 */

package ishara.audio;

import  javax.sound.sampled.*;
import  java.io.*;

import  org.tritonus.share.sampled.AudioSystemShadow;
import  org.tritonus.share.sampled.file.AudioOutputStream;

/**
	An AudioSink that writes to an OutputStream
*/

public class StreamSink extends AudioSink 
{
	AudioOutputStream	out;

	public StreamSink(AudioOutputStream stream) { super(stream.getFormat()); out=stream; }

	public void dispose() {
		try { out.close(); }
		catch (IOException ex) { print("*** Error closing: "+ex); }
	}

	public void stop() {}
	public void start() {}
	public int  bwrite(byte []buf, int off, int n) throws Exception { return out.write(buf, off, n); }

	public String toString() { return "StreamSink: "+getFormat(); }

	public static AudioOutputStream wavOutputStream(OutputStream stream, AudioFormat fmt) throws Exception {
		// could alse have raw output stream
		return AudioSystemShadow.getAudioOutputStream(
					AudioFileFormat.Type.WAVE,fmt,AudioSystem.NOT_SPECIFIED,stream);
	}
}