marytts.unitselection.data
Class Datagram

java.lang.Object
  extended by marytts.unitselection.data.Datagram
Direct Known Subclasses:
FloatArrayDatagram, HnmDatagram, LPCDatagram, MCepDatagram

public class Datagram
extends java.lang.Object


Field Summary
protected  byte[] data
          The datagram's contents, as a generic byte array.
protected  long duration
          The datagram duration, in samples.
static int NUM_HEADER_BYTES
           
 
Constructor Summary
  Datagram(java.nio.ByteBuffer bb)
          Constructor which reads a datagram from a byte buffer.
  Datagram(java.nio.ByteBuffer bb, boolean readData)
          Constructor which reads a datagram from a byte buffer.
protected Datagram(long duration)
          Constructor for subclasses which want to represent data in a different format.
  Datagram(long setDuration, byte[] setData)
          Constructor from external data.
  Datagram(java.io.RandomAccessFile raf)
          Constructor which reads a datagram from a random access file.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Tests if this datagram is equal to another datagram.
 byte[] getData()
          Get the datagram's data field.
 long getDuration()
          Get the datagram duration, in samples.
 int getLength()
          Get the length, in bytes, of the datagram's data field.
 void setDuration(long setDuration)
          Set the new duration.
 void write(java.io.DataOutput raf)
          Write this datagram to a random access file or data output stream.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NUM_HEADER_BYTES

public static final int NUM_HEADER_BYTES
See Also:
Constant Field Values

duration

protected long duration
The datagram duration, in samples.


data

protected byte[] data
The datagram's contents, as a generic byte array.

Constructor Detail

Datagram

protected Datagram(long duration)
Constructor for subclasses which want to represent data in a different format.

Parameters:
setDuration - the datagram duration, in samples. Must be non-negative.
Throws:
java.lang.IllegalArgumentException - if duration is negative

Datagram

public Datagram(long setDuration,
                byte[] setData)
Constructor from external data.

Parameters:
setDuration - the datagram duration, in samples. Must be non-negative.
setBuff - the byte buffer to use as the datagram's data field. Must not be null.
Throws:
java.lang.IllegalArgumentException - if duration is negative
java.lang.NullPointerException - if setData is null.

Datagram

public Datagram(java.io.RandomAccessFile raf)
         throws java.io.IOException
Constructor which reads a datagram from a random access file.

Parameters:
raf - the random access file to read the datagram from.
Throws:
java.io.IOException - if there is a problem initialising the datagram from the file

Datagram

public Datagram(java.nio.ByteBuffer bb)
         throws java.io.IOException
Constructor which reads a datagram from a byte buffer.

Parameters:
bb - the byte buffer to read the datagram from.
Throws:
java.io.IOException - if the datagram has wrong format or if the datagram cannot be fully read

Datagram

public Datagram(java.nio.ByteBuffer bb,
                boolean readData)
         throws java.io.IOException
Constructor which reads a datagram from a byte buffer.

Parameters:
bb - the byte buffer to read the datagram from.
readData - whether to try and read the actual data
Throws:
java.io.IOException - if the datagram has wrong format or if the datagram cannot be fully read
Method Detail

setDuration

public void setDuration(long setDuration)
Set the new duration.

Parameters:
setDuration - the datagram duration, in samples. Must be non-negative.
Throws:
java.lang.IllegalArgumentException - if duration is negative

write

public void write(java.io.DataOutput raf)
           throws java.io.IOException
Write this datagram to a random access file or data output stream. Must only be called if data is not null.

Parameters:
raf - the data output to write to.
Throws:
java.lang.IllegalStateException - if called when data is null.
java.io.IOException - if a write error occurs.

getDuration

public long getDuration()
Get the datagram duration, in samples. Note: the sample rate has to be provided externally.

Returns:
the non-negative duration.

getLength

public int getLength()
Get the length, in bytes, of the datagram's data field. Must only be called if data is not null.

Returns:
a non-negative integer representing the number of bytes in the data field.
Throws:
java.lang.IllegalStateException - if called when data is null.

getData

public byte[] getData()
Get the datagram's data field.

Returns:
the data in this Datagram, or null if there is no such data (should be the case only for subclasses).

equals

public boolean equals(java.lang.Object obj)
Tests if this datagram is equal to another datagram.

Overrides:
equals in class java.lang.Object