samer@0: /* samer@0: * AudioSink.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@0: package samer.audio; samer@0: import samer.tools.*; samer@0: samer@0: /** samer@0: General interface for objects that accept a stream of samer@0: samples. samer@0: */ samer@0: samer@0: public interface AudioSink samer@0: { samer@0: boolean isOpen(); samer@0: void open() throws Exception; samer@0: void close(); samer@0: void dispose(); samer@0: samer@0: /** Return a task which takes samples from the given buffer samer@0: * The idea is that the audio sink can choose the right samer@0: * kind of writer depending on the format of the audio stream, samer@0: * and then handle any conversions automatically. samer@0: */ samer@0: Task writer(double buf[], int off, int len); samer@0: Task writer(float buf[], int off, int len); samer@0: samer@0: public static class Util { samer@0: public static void doubleToShort(double[] src, byte [] dst, int off, int n, double k) { samer@0: k*=32768; samer@0: for (int i=0, j=off; j>8); samer@0: } samer@0: } samer@0: samer@0: public static void doubletoByte(double [] src, byte[] dst, int off, int n, double k) { samer@0: k*=128; samer@0: for (int i=0, j=off; j>8); samer@0: } samer@0: } samer@0: samer@0: public static void floatToByte(float [] src, byte [] dst, int off, int n, float k) { samer@0: k*=128; samer@0: for (int i=0, j=off; j