/** * Construct an LPC datagram from unquantized data. * * @param setDuration * the duration, in samples, of the data represented by this datagram * @param coeffs * the (unquantized) LPC coefficients * @param residual * the (unquantized) residual * @param lpcMin * lpcMin * @param lpcRange * lpcRange */ public LPCDatagram(long setDuration, float[] coeffs, short[] residual, float lpcMin, float lpcRange) { super(setDuration); this.quantizedCoeffs = General.quantize(coeffs, lpcMin, lpcRange); this.quantizedResidual = General.shortToUlaw(residual); }
/** * Get the LPC coefficients, unquantized using the given lpc min and range values. * * @param lpcMin * the lpc minimum * @param lpcRange * the lpc range * @return an array of floats, length lpcOrder() * @see #lpcOrder() * @see #getQuantizedCoeffs() */ public float[] getCoeffs(float lpcMin, float lpcRange) { return General.unQuantize(quantizedCoeffs, lpcMin, lpcRange); }
/** * Get the unquantized residual * * @return an array of shorts */ public short[] getResidual() { return General.ulawToShort(quantizedResidual); }
short[] quantizedFrame = General.quantize(lpcFile.getFrame(f), lpcMin, lpcRange); float[] unQuantizedFrame = General.unQuantize(quantizedFrame, lpcMin, lpcRange); residual[k] = General.shortToUlaw((short) r);
/** * Convert an array from short to ulaw. * * @param samples * an array in linear representation * @return an array in ulaw representation. * @see #shortToUlaw(short) */ public static byte[] shortToUlaw(short[] samples) { if (samples == null) return null; byte[] ulaw = new byte[samples.length]; for (int i = 0; i < samples.length; i++) { ulaw[i] = shortToUlaw(samples[i]); } return ulaw; }
/** * Quantize an array of floats over the 16bits signed short range * * @param f * the array of floats to quantize * @param fMin * the minimum possible value for variable f * @param fRange * the possible range for variable f * * @return an array of 16bits signed codewords, returned as signed shorts * * */ public static short[] quantize(float[] f, float fMin, float fRange) { int len = f.length; short[] ret = new short[len]; for (int i = 0; i < len; i++) ret[i] = quantize(f[i], fMin, fRange); return (ret); }
/** * Reads the next float from the given DataInputStream, where the data is in little endian. * * @param dataStream * the DataInputStream to read from * @throws IOException * IOException * @return a float */ public static float readLittleEndianFloat(DataInputStream dataStream) throws IOException { return Float.intBitsToFloat(readLittleEndianInt(dataStream)); }
/** * Reads a given number of chars from the stream * * @param dis * the stream to read * @param num * the number of chars to read * @return a character array containing the next <code>num</code> in the stream * * @throws IOException * if an error occurs */ public static char[] readChars(DataInputStream dis, int num) throws IOException { char[] carray = new char[num]; for (int i = 0; i < num; i++) { carray[i] = readChar(dis); } return carray; }
/** * load the data section of the file as ascii text * * @param dis * DataInputStream to read from * * @throws IOException * on ill-formatted input */ private void loadTextData(DataInputStream dis) throws IOException { for (int f = 0; f < numFrames; f++) { times[f] = Float.parseFloat(General.readWord(dis)); General.readWord(dis); // can be only 1 for (int c = 0; c < numChannels; c++) { frames[f][c] = Float.parseFloat(General.readWord(dis)); } } }
/** * load the data section of the file as ascii text * * @param dis * DataInputStream to read from * * @throws IOException * on ill-formatted input */ private void loadBinaryData(DataInputStream dis) throws IOException { for (int f = 0; f < numFrames; f++) { times[f] = General.readFloat(dis, isBigEndian); // Ignore the 'breaks' field General.readFloat(dis, isBigEndian); for (int c = 0; c < numChannels; c++) { frames[f][c] = General.readFloat(dis, isBigEndian); } } }
/** * Read a short from the input stream, byte-swapping as necessary * * @param dis * the inputstream * @param isBigEndian * whether or not the data being read in is in big endian format. * * @return an integer value * * @throws IOException * on error */ public static short readShort(DataInputStream dis, boolean isBigEndian) throws IOException { if (!isBigEndian) { return readLittleEndianShort(dis); } else { return dis.readShort(); } }
/** * Read a float from the input stream, byte-swapping as necessary * * @param dis * the inputstream * @param isBigEndian * whether or not the data being read in is in big endian format. * * @return a floating pint value * * @throws IOException * on error */ public static float readFloat(DataInputStream dis, boolean isBigEndian) throws IOException { float val; if (!isBigEndian) { val = readLittleEndianFloat(dis); } else { val = dis.readFloat(); } return val; }
/** * Convert an array from short to ulaw. * * @param samples * an array in linear representation * @return an array in ulaw representation. * @see #shortToUlaw(short) */ public static byte[] shortToUlaw(short[] samples) { if (samples == null) return null; byte[] ulaw = new byte[samples.length]; for (int i = 0; i < samples.length; i++) { ulaw[i] = shortToUlaw(samples[i]); } return ulaw; }
/** * Quantize an array of floats over the 16bits signed short range * * @param f * the array of floats to quantize * @param fMin * the minimum possible value for variable f * @param fRange * the possible range for variable f * * @return an array of 16bits signed codewords, returned as signed shorts * * */ public static short[] quantize(float[] f, float fMin, float fRange) { int len = f.length; short[] ret = new short[len]; for (int i = 0; i < len; i++) ret[i] = quantize(f[i], fMin, fRange); return (ret); }
/** * Reads the next float from the given DataInputStream, where the data is in little endian. * * @param dataStream * the DataInputStream to read from * @throws IOException * IOException * @return a float */ public static float readLittleEndianFloat(DataInputStream dataStream) throws IOException { return Float.intBitsToFloat(readLittleEndianInt(dataStream)); }
/** * Reads a given number of chars from the stream * * @param dis * the stream to read * @param num * the number of chars to read * @return a character array containing the next <code>num</code> in the stream * * @throws IOException * if an error occurs */ public static char[] readChars(DataInputStream dis, int num) throws IOException { char[] carray = new char[num]; for (int i = 0; i < num; i++) { carray[i] = readChar(dis); } return carray; }
/** * load the data section of the file as ascii text * * @param dis * DataInputStream to read from * * @throws IOException * on ill-formatted input */ private void loadTextData(DataInputStream dis) throws IOException { for (int f = 0; f < numFrames; f++) { times[f] = Float.parseFloat(General.readWord(dis)); General.readWord(dis); // can be only 1 for (int c = 0; c < numChannels; c++) { frames[f][c] = Float.parseFloat(General.readWord(dis)); } } }
/** * load the data section of the file as ascii text * * @param dis * DataInputStream to read from * * @throws IOException * on ill-formatted input */ private void loadBinaryData(DataInputStream dis) throws IOException { for (int f = 0; f < numFrames; f++) { times[f] = General.readFloat(dis, isBigEndian); // Ignore the 'breaks' field General.readFloat(dis, isBigEndian); for (int c = 0; c < numChannels; c++) { frames[f][c] = General.readFloat(dis, isBigEndian); } } }
/** * Read a short from the input stream, byte-swapping as necessary * * @param dis * the inputstream * @param isBigEndian * whether or not the data being read in is in big endian format. * * @return an integer value * * @throws IOException * on error */ public static short readShort(DataInputStream dis, boolean isBigEndian) throws IOException { if (!isBigEndian) { return readLittleEndianShort(dis); } else { return dis.readShort(); } }
/** * Read a float from the input stream, byte-swapping as necessary * * @param dis * the inputstream * @param isBigEndian * whether or not the data being read in is in big endian format. * * @return a floating pint value * * @throws IOException * on error */ public static float readFloat(DataInputStream dis, boolean isBigEndian) throws IOException { float val; if (!isBigEndian) { val = readLittleEndianFloat(dis); } else { val = dis.readFloat(); } return val; }