marytts.tools.voiceimport
Class General

java.lang.Object
  extended by marytts.tools.voiceimport.General

public class General
extends java.lang.Object

This class is for general purpose functions such as reading and writing from files, or converting formats of numbers.


Constructor Summary
General()
           
 
Method Summary
static java.lang.String hex(float f)
          Print a float type's internal bit representation in hex
static void launchBatchProc(java.lang.String cmdLine, java.lang.String task, java.lang.String filedir)
          A general process launcher for the various tasks but using an intermediate batch file
static void launchProc(java.lang.String cmdLine, java.lang.String task, java.lang.String baseName)
          A general process launcher for the various tasks
static short[] quantize(float[] f, float fMin, float fRange)
          Quantize an array of floats over the 16bits signed short range
static short quantize(float f, float fMin, float fRange)
          Quantize a float variable over the 16bits signed short range
static char readChar(java.io.DataInputStream dis)
          Reads a single char from the stream
static char[] readChars(java.io.DataInputStream dis, int num)
          Reads a given number of chars from the stream
static float readFloat(java.io.DataInputStream dis, boolean isBigEndian)
          Read a float from the input stream, byte-swapping as necessary
static int readInt(java.io.DataInputStream dis, boolean isBigEndian)
          Read an integer from the input stream, byte-swapping as necessary
static float readLittleEndianFloat(java.io.DataInputStream dataStream)
          Reads the next float from the given DataInputStream, where the data is in little endian.
static int readLittleEndianInt(java.io.DataInputStream dataStream)
          Reads the next little-endian integer from the given DataInputStream.
static short readLittleEndianShort(java.io.DataInputStream dis)
          Reads the next little-endian short from the given DataInputStream.
static short readShort(java.io.DataInputStream dis, boolean isBigEndian)
          Read a short from the input stream, byte-swapping as necessary
static java.lang.String readWord(java.io.DataInputStream dis)
          Reads the next word (text separated by whitespace) from the given stream
static byte shortToUlaw(short sample)
          Convert a short to ulaw format
static byte[] shortToUlaw(short[] samples)
          Convert an array from short to ulaw.
static short ulawToShort(byte ulaw)
          Convert a ulaw format to short
static short[] ulawToShort(byte[] ulaw)
          Convert an array from ulaw to short.
static float[] unQuantize(short[] s, float fMin, float fRange)
          Unquantize an array of 16bits signed shorts over a float range
static float unQuantize(short s, float fMin, float fRange)
          Unquantize a 16bits signed short over a float range
static void writeFloat(java.io.DataOutputStream dos, boolean isBigEndian, float val)
          Write a float from the output stream, byte-swapping as necessary
static void writeInt(java.io.DataOutputStream dis, boolean isBigEndian, int val)
          Writes an integer to the output stream, byte-swapping as necessary
static void writeLittleEndianFloat(java.io.DataOutputStream dataStream, float val)
          Writes a float to the given DataOutputStream, where the data is in little endian.
static void writeLittleEndianInt(java.io.DataOutputStream dataStream, int val)
          Writes a little-endian integer to the given DataOutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

General

public General()
Method Detail

readWord

public static java.lang.String readWord(java.io.DataInputStream dis)
                                 throws java.io.IOException
Reads the next word (text separated by whitespace) from the given stream

Parameters:
dis - the input stream
Returns:
the next word
Throws:
java.io.IOException - on error

readChar

public static char readChar(java.io.DataInputStream dis)
                     throws java.io.IOException
Reads a single char from the stream

Parameters:
dis - the stream to read
Returns:
the next character on the stream
Throws:
java.io.IOException - if an error occurs

readChars

public static char[] readChars(java.io.DataInputStream dis,
                               int num)
                        throws java.io.IOException
Reads a given number of chars from the stream

Parameters:
dis - the stream to read
num - the number of chars to read
Returns:
a character array containing the next num in the stream
Throws:
java.io.IOException - if an error occurs

readFloat

public static float readFloat(java.io.DataInputStream dis,
                              boolean isBigEndian)
                       throws java.io.IOException
Read a float from the input stream, byte-swapping as necessary

Parameters:
dis - the inputstream
isBigEndian - whether or not the data being read in is in big endian format.
Returns:
a floating pint value
Throws:
java.io.IOException - on error

writeFloat

public static void writeFloat(java.io.DataOutputStream dos,
                              boolean isBigEndian,
                              float val)
                       throws java.io.IOException
Write a float from the output stream, byte-swapping as necessary

Parameters:
dos - the outputstream
isBigEndian - whether or not the data being read in is in big endian format.
val - the floating point value to write
Throws:
java.io.IOException - on error

readLittleEndianFloat

public static float readLittleEndianFloat(java.io.DataInputStream dataStream)
                                   throws java.io.IOException
Reads the next float from the given DataInputStream, where the data is in little endian.

Parameters:
dataStream - the DataInputStream to read from
Returns:
a float
Throws:
java.io.IOException

writeLittleEndianFloat

public static void writeLittleEndianFloat(java.io.DataOutputStream dataStream,
                                          float val)
                                   throws java.io.IOException
Writes a float to the given DataOutputStream, where the data is in little endian.

Parameters:
dataStream - the DataOutputStream to write to.
val - The float value to write.
Throws:
java.io.IOException

readInt

public static int readInt(java.io.DataInputStream dis,
                          boolean isBigEndian)
                   throws java.io.IOException
Read an integer from the input stream, byte-swapping as necessary

Parameters:
dis - the inputstream
isBigEndian - whether or not the data being read in is in big endian format.
Returns:
an integer value
Throws:
java.io.IOException - on error

writeInt

public static void writeInt(java.io.DataOutputStream dis,
                            boolean isBigEndian,
                            int val)
                     throws java.io.IOException
Writes an integer to the output stream, byte-swapping as necessary

Parameters:
dis - the outputstream.
isBigEndian - whether or not the data being read in is in big endian format.
val - the integer value to write.
Throws:
java.io.IOException - on error

readLittleEndianInt

public static int readLittleEndianInt(java.io.DataInputStream dataStream)
                               throws java.io.IOException
Reads the next little-endian integer from the given DataInputStream.

Parameters:
dataStream - the DataInputStream to read from
Returns:
an integer
Throws:
java.io.IOException

writeLittleEndianInt

public static void writeLittleEndianInt(java.io.DataOutputStream dataStream,
                                        int val)
                                 throws java.io.IOException
Writes a little-endian integer to the given DataOutputStream.

Parameters:
dataStream - the DataOutputStream to write to
val - the integer value to write
Throws:
java.io.IOException - on error

readShort

public static short readShort(java.io.DataInputStream dis,
                              boolean isBigEndian)
                       throws java.io.IOException
Read a short from the input stream, byte-swapping as necessary

Parameters:
dis - the inputstream
isBigEndian - whether or not the data being read in is in big endian format.
Returns:
an integer value
Throws:
java.io.IOException - on error

readLittleEndianShort

public static short readLittleEndianShort(java.io.DataInputStream dis)
                                   throws java.io.IOException
Reads the next little-endian short from the given DataInputStream.

Parameters:
dataStream - the DataInputStream to read from
Returns:
a short
Throws:
java.io.IOException

shortToUlaw

public static byte shortToUlaw(short sample)
Convert a short to ulaw format

Parameters:
sample - the short to convert
Returns:
a short containing an unsigned 8-bit quantity representing the ulaw

ulawToShort

public static short ulawToShort(byte ulaw)
Convert a ulaw format to short

Parameters:
ulaw - a (signed) byte which, after converting into a short and adding 128, will be an unsigned 8-but quantity representing a ulaw
Returns:
the short equivalent of the ulaw

shortToUlaw

public static byte[] shortToUlaw(short[] samples)
Convert an array from short to ulaw.

Parameters:
samples - an array in linear representation
Returns:
an array in ulaw representation.
See Also:
shortToUlaw(short)

ulawToShort

public static short[] ulawToShort(byte[] ulaw)
Convert an array from ulaw to short.

Parameters:
samples - an array in ulaw representation
Returns:
an array in linear representation.
See Also:
ulawToShort(byte)

hex

public static java.lang.String hex(float f)
Print a float type's internal bit representation in hex

Parameters:
f - the float to print
Returns:
a string containing the hex value of f

quantize

public static short quantize(float f,
                             float fMin,
                             float fRange)
Quantize a float variable over the 16bits signed short range

Parameters:
f - the float to quantize
min - the minimum possible value for variable f
range - the possible range for variable f
Returns:
the 16bits signed codeword, returned as a signed short

quantize

public static short[] quantize(float[] f,
                               float fMin,
                               float fRange)
Quantize an array of floats over the 16bits signed short range

Parameters:
f - the array of floats to quantize
min - the minimum possible value for variable f
range - the possible range for variable f
Returns:
an array of 16bits signed codewords, returned as signed shorts

unQuantize

public static float unQuantize(short s,
                               float fMin,
                               float fRange)
Unquantize a 16bits signed short over a float range

Parameters:
s - the 16bits signed codeword
min - the minimum possible value for variable f
range - the possible range for variable f
Returns:
the corresponding float value

unQuantize

public static float[] unQuantize(short[] s,
                                 float fMin,
                                 float fRange)
Unquantize an array of 16bits signed shorts over a float range

Parameters:
s - the array of 16bits signed codewords
min - the minimum possible value for variable f
range - the possible range for variable f
Returns:
the corresponding array of float values

launchProc

public static void launchProc(java.lang.String cmdLine,
                              java.lang.String task,
                              java.lang.String baseName)
A general process launcher for the various tasks

Parameters:
cmdLine - the command line to be launched.
task - a task tag for error messages, such as "Pitchmarks" or "LPC".
the - basename of the file currently processed, for error messages.

launchBatchProc

public static void launchBatchProc(java.lang.String cmdLine,
                                   java.lang.String task,
                                   java.lang.String filedir)
A general process launcher for the various tasks but using an intermediate batch file

Parameters:
cmdLine - the command line to be launched.
task - a task tag for error messages, such as "Pitchmarks" or "LPC".
the - filedir of the file currently processed, for error messages and for creating a temporal batch file.