samer@0: /* samer@0: * AudioSource.java samer@0: * samer@0: * Copyright (c) 2012, Samer Abdallah 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: public class Util samer@0: { samer@0: /* NB. These copying functions allow NEGATIVE offset (off<0). The semantics samer@0: * of this is are that n values are copied from source to destination, writing samer@0: * into the destination starting at the negative offset, but that values before samer@0: * index 0 will never be accessed, hence, they are not actually copied. Only samer@0: * the last n-off values will be available in dst starting from index 0. samer@0: * This is useful as it allows block-wise audio input where the block lenght samer@0: * is smaller than the step length. samer@0: */ samer@0: samer@0: public static void intToDouble(byte [] src, double [] dst, int off, int n) { samer@0: int i, j; samer@0: if (off<0) { i= 4*(-off); j=0; } else { i=0; j=off; } samer@0: while (j>8 & 0xff); samer@0: dst[i++] = (byte)(y>>16 & 0xff); samer@0: dst[i++] = (byte)(y>>24); samer@0: } samer@0: } samer@0: samer@0: public static void doubleToMedium(double[] src, byte [] dst, int off, int n, double k) { samer@0: k*=256.0*32768; samer@0: for (int i=0, j=off; j>8 & 0xff); samer@0: dst[i++] = (byte)(y>>16); samer@0: } samer@0: } samer@0: 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 & 0xff); 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