public class DataUtil
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static void |
bytesToFile(byte[] data,
java.lang.String filename)
Saves the given bytes to the given binary file.
|
static short |
bytesToShort(byte[] byteArray,
int offset)
Convert the two bytes starting at the given offset to a short.
|
static double[] |
bytesToValues(byte[] byteArray,
int offset,
int length,
int bytesPerValue,
boolean signedData)
Converts a big-endian byte array into an array of doubles.
|
static short[] |
byteToShortArray(byte[] byteArray,
int offset,
int length)
Converts a byte array into a short array.
|
static java.lang.String |
doubleArrayToString(double[] data)
Returns the given double array as a string.
|
static FloatData |
DoubleData2FloatData(DoubleData data)
Converts FloatData object to DoubleData.
|
static java.lang.String |
floatArrayToString(float[] data)
Returns the given float array as a string.
|
static DoubleData |
FloatData2DoubleData(FloatData data)
Converts DoubleData object to FloatDatas.
|
static java.lang.String |
formatDouble(double number,
int integerDigits,
int fractionDigits)
Returns a formatted string of the given number, with the given numbers of digit space for the integer and
fraction parts.
|
static javax.sound.sampled.AudioFormat |
getNativeAudioFormat(javax.sound.sampled.AudioFormat format)
Returns a native audio format that has the same encoding, endianness and sample size as the given format, and a
sample rate that is larger than the given sample rate.
|
static javax.sound.sampled.AudioFormat |
getNativeAudioFormat(javax.sound.sampled.AudioFormat format,
javax.sound.sampled.Mixer mixer)
Returns a native audio format that has the same encoding, endianness and sample size as the given format, and a
sample rate that is greater than or equal to the given sample rate.
|
static int |
getSamplesPerShift(int sampleRate,
float windowShiftInMs)
Returns the number of samples in a window shift given the sample rate (in Hertz) and the window shift (in
milliseconds).
|
static int |
getSamplesPerWindow(int sampleRate,
float windowSizeInMs)
Returns the number of samples per window given the sample rate (in Hertz) and window size (in milliseconds).
|
static double[] |
littleEndianBytesToValues(byte[] data,
int offset,
int length,
int bytesPerValue,
boolean signedData)
Converts a little-endian byte array into an array of doubles.
|
static java.lang.String |
shortArrayToString(short[] data)
Returns the string representation of the given short array.
|
public static short[] byteToShortArray(byte[] byteArray,
int offset,
int length)
throws java.lang.ArrayIndexOutOfBoundsException
(byteArray.length - 1)/2, i.e., the last byte is discarded.byteArray - a byte arrayoffset - which byte to start fromlength - how many bytes to convertnull if byteArray is of zero lengthjava.lang.ArrayIndexOutOfBoundsException - if index goes out of boundspublic static double[] bytesToValues(byte[] byteArray,
int offset,
int length,
int bytesPerValue,
boolean signedData)
throws java.lang.ArrayIndexOutOfBoundsException
byteArray - a byte arrayoffset - which byte to start fromlength - how many bytes to convertbytesPerValue - the number of bytes per valuesignedData - whether the data is signednull if byteArray is of zero lengthjava.lang.ArrayIndexOutOfBoundsException - if index goes out of boundspublic static double[] littleEndianBytesToValues(byte[] data,
int offset,
int length,
int bytesPerValue,
boolean signedData)
throws java.lang.ArrayIndexOutOfBoundsException
data - a byte arrayoffset - which byte to start fromlength - how many bytes to convertbytesPerValue - the number of bytes per valuesignedData - whether the data is signednull if byteArray is of zero lengthjava.lang.ArrayIndexOutOfBoundsException - if index goes out of boundspublic static short bytesToShort(byte[] byteArray,
int offset)
throws java.lang.ArrayIndexOutOfBoundsException
byteArray - the byte arrayoffset - where to startjava.lang.ArrayIndexOutOfBoundsException - if index goes out of boundspublic static java.lang.String shortArrayToString(short[] data)
data.length data[0] data[1] ... data[data.length-1]
data - the short array to convertpublic static java.lang.String doubleArrayToString(double[] data)
data.length data[0] data[1] ... data[data.length-1]where
data[i].
The doubles can be written as decimal, hexadecimal, or scientific notation. In decimal notation, it is formatted
by the method Util.formatDouble(data[i], 10, 5). Use the System property
"frontend.util.dumpformat" to control the dump format (permitted values are "decimal",
"hexadecimal", and "scientific".
data - the double array to dumppublic static java.lang.String floatArrayToString(float[] data)
data.length data[0] data[1] ... data[data.length-1]
The floats can be written as decimal, hexadecimal, or scientific notation. In decimal notation, it is formatted
by the method Util.formatDouble(data[i], 10, 5). Use the System property
"frontend.util.dumpformat" to control the dump format (permitted values are "decimal",
"hexadecimal", and "scientific".
data - the float array to dumppublic static java.lang.String formatDouble(double number,
int integerDigits,
int fractionDigits)
integerDigits digits, spaces will be prepended to
it. If the fraction part has less than fractionDigits, spaces will be appended to it. Therefore,
formatDouble(12345.6789, 6, 6) will give
the string " 12345.6789 "(one space before 1, two spaces after 9).
number - the number to formatintegerDigits - the length of the integer partfractionDigits - the length of the fraction partpublic static int getSamplesPerWindow(int sampleRate,
float windowSizeInMs)
sampleRate - the sample rate in Hertz (i.e., frequency per seconds)windowSizeInMs - the window size in millisecondspublic static int getSamplesPerShift(int sampleRate,
float windowShiftInMs)
sampleRate - the sample rate in Hertz (i.e., frequency per seconds)windowShiftInMs - the window shift in millisecondspublic static void bytesToFile(byte[] data,
java.lang.String filename)
throws java.io.IOException
data - the bytes to savefilename - the binary file namejava.io.IOException - if an I/O error occurspublic static javax.sound.sampled.AudioFormat getNativeAudioFormat(javax.sound.sampled.AudioFormat format)
format - format for the datapublic static javax.sound.sampled.AudioFormat getNativeAudioFormat(javax.sound.sampled.AudioFormat format,
javax.sound.sampled.Mixer mixer)
format - the desired formatmixer - if non-null, use this Mixer; otherwise use AudioSystempublic static DoubleData FloatData2DoubleData(FloatData data)
data - data to convertpublic static FloatData DoubleData2FloatData(DoubleData data)
data - data to convert