de.dfki.lt.mary.unitselection.voiceimport
Class TimelineIO

java.lang.Object
  extended by de.dfki.lt.mary.unitselection.voiceimport.TimelineIO
Direct Known Subclasses:
TimelineReader, TimelineWriter

public class TimelineIO
extends java.lang.Object

Base class for the TimelineReader and TimelineWriter classes.

Author:
sacha

Nested Class Summary
static class TimelineIO.IdxField
          Simple helper class to read the index fields in a timeline.
 class TimelineIO.Index
          Simple helper class to read the index part of a timeline file
 class TimelineIO.ProcHeader
          Simple helper class to load the processing header.
 
Field Summary
protected  long datagramsBytePos
           
static int DEFAULT_INCREMENT
           
protected  TimelineIO.Index idx
           
protected  MaryHeader maryHdr
           
protected  long numDatagrams
           
protected  TimelineIO.ProcHeader procHdr
           
protected  java.io.RandomAccessFile raf
           
protected  int sampleRate
           
protected  long timeIdxBytePos
           
protected  long timePtr
           
 
Constructor Summary
TimelineIO()
           
 
Method Summary
 long getBytePointer()
          Get the current byte position in the file
 long getDatagramsBytePos()
          Returns the position of the datagram zone
 long getNumDatagrams()
          Returns the current number of datagrams in the timeline.
 java.lang.String getProcHeaderContents()
          Return the content of the processing header as a String
 int getSampleRate()
          Returns the timeline's sample rate.
 long getTimePointer()
          Get the current time position in the file
protected  long loadHeaderAndIndex(java.lang.String fileName)
          Load the headers and the info, the position the file pointer to the beginning of the datagram zone and the time pointer to 0.
 void printIdx()
          Prints the index to System.out.
protected  long scaleTime(int reqSampleRate, long targetTimeInSamples)
          Scales a discrete time to the timeline's sample rate.
protected  void setBytePointer(long bytePos)
          Set the current byte position in the file
protected  void setTimePointer(long timePosition)
          Set the current time position in the file
protected  long unScaleTime(int reqSampleRate, long timelineTimeInSamples)
          Unscales a discrete time from the timeline's sample rate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_INCREMENT

public static final int DEFAULT_INCREMENT
See Also:
Constant Field Values

raf

protected java.io.RandomAccessFile raf

maryHdr

protected MaryHeader maryHdr

procHdr

protected TimelineIO.ProcHeader procHdr

idx

protected TimelineIO.Index idx

sampleRate

protected int sampleRate

numDatagrams

protected long numDatagrams

datagramsBytePos

protected long datagramsBytePos

timeIdxBytePos

protected long timeIdxBytePos

timePtr

protected long timePtr
Constructor Detail

TimelineIO

public TimelineIO()
Method Detail

getProcHeaderContents

public java.lang.String getProcHeaderContents()
Return the content of the processing header as a String


getBytePointer

public long getBytePointer()
                    throws java.io.IOException
Get the current byte position in the file

Throws:
java.io.IOException

getTimePointer

public long getTimePointer()
Get the current time position in the file


setBytePointer

protected void setBytePointer(long bytePos)
                       throws java.io.IOException
Set the current byte position in the file

Throws:
java.io.IOException

setTimePointer

protected void setTimePointer(long timePosition)
Set the current time position in the file


getNumDatagrams

public long getNumDatagrams()
Returns the current number of datagrams in the timeline.

Returns:
the number of datagrams, as a long. Warning: you may have to cast this value into an int if you want to use it to create an array.

getDatagramsBytePos

public long getDatagramsBytePos()
Returns the position of the datagram zone


getSampleRate

public int getSampleRate()
Returns the timeline's sample rate.


printIdx

public void printIdx()
Prints the index to System.out. (For testing purposes.))


scaleTime

protected long scaleTime(int reqSampleRate,
                         long targetTimeInSamples)
Scales a discrete time to the timeline's sample rate.

Parameters:
reqSampleRate - the externally given sample rate.
targetTimeInSamples - a discrete time, with respect to the externally given sample rate.
Returns:
a discrete time, in samples with respect to the timeline's sample rate.

unScaleTime

protected long unScaleTime(int reqSampleRate,
                           long timelineTimeInSamples)
Unscales a discrete time from the timeline's sample rate.

Parameters:
reqSampleRate - the externally given sample rate.
timelineTimeInSamples - a discrete time, with respect to the timeline sample rate.
Returns:
a discrete time, in samples with respect to the externally given sample rate.

loadHeaderAndIndex

protected long loadHeaderAndIndex(java.lang.String fileName)
                           throws java.io.IOException
Load the headers and the info, the position the file pointer to the beginning of the datagram zone and the time pointer to 0.

Throws:
java.io.IOException