|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.cmu.sphinx.frontend.util.DataUtil
Defines utility methods for manipulating data values.
Method Summary | |
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 java.lang.String |
floatArrayToString(float[] data)
Returns the given float array as a string. |
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. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
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 convert
null
if byteArray is of zero
length
java.lang.ArrayIndexOutOfBoundsException
public static final 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 signed
null
if byteArray is of zero
length
java.lang.ArrayIndexOutOfBoundsException
public static final 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 signed
null
if byteArray is of zero
length
java.lang.ArrayIndexOutOfBoundsException
public static short bytesToShort(byte[] byteArray, int offset) throws java.lang.ArrayIndexOutOfBoundsException
byteArray
- the byte arrayoffset
- where to start
java.lang.ArrayIndexOutOfBoundsException
public static java.lang.String shortArrayToString(short[] data)
data.length data[0] data[1] ... data[data.length-1]
data
- the short array to convert
public 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 dump
public 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 dump
public 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 part
public static int getSamplesPerWindow(int sampleRate, float windowSizeInMs)
sampleRate
- the sample rate in Hertz (i.e., frequency per
seconds)windowSizeInMs
- the window size in milliseconds
public static int getSamplesPerShift(int sampleRate, float windowShiftInMs)
sampleRate
- the sample rate in Hertz (i.e., frequency per
seconds)windowShiftInMs
- the window shift in milliseconds
public static void bytesToFile(byte[] data, java.lang.String filename) throws java.io.IOException
data
- the bytes to savefilename
- the binary file name
java.io.IOException
- if an I/O error occurspublic static javax.sound.sampled.AudioFormat getNativeAudioFormat(javax.sound.sampled.AudioFormat format)
public 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
AudioSystem
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |