/** * Encodes a float array into byteCount bytes, using DCT. * * @return a byte array with the encoded data */ public static byte[] encodeSegmentToBytes?(float[] data, int byteCount){ byte[] compressed = new byte[byteCount]; float[] dctValues = forwardDCT(data); for(int i = 0; i < byteCount; i++){ compressed[i] = (byte) Math.min(Byte.MAX_VALUE, Math.max(Byte.MIN_VALUE, Math.round((i + 1) * 128.0 * dctValues[i]))); if(compressed[i] == Byte.MAX_VALUE){ System.out.println("Warning: max value"); printArray(data); } if(compressed[i] == Byte.MIN_VALUE){ System.out.println("Warning: min value"); printArray(data); } } return compressed; } /** * Decodes a float array from the specified array of bytes. The parameter * arraySize is how many floats should be in the decoded array. * * @param data DCT-encoded bytes * @param arraySize the size of the array * @return the decompressed array of floats */ |
/** * Decodes a float array from the specified array of bytes. The parameter * arraySize is how many floats should be in the decoded array. * * @param useFirstNBytes? how many of the compressed bytes to use when decompressing. * @param data DCT-encoded bytes * @param arraySize the size of the array * @return the decompressed array of floats * */ |
/** * Performs a forward discrete cosine transform on the provided data, and returns the coefficients * * @param data the data to encode * @return DCT-encoded data */ |
/** * Performs an inverse discrete cosine transform on the provided coefficients, * returning an approximation of the original data. * * @param coefficients the DCT coefficients * @return the original data, or as close to it as possible! */ |