marytts.util.data
Class BaseDoubleDataSource

java.lang.Object
  extended by marytts.util.data.BaseDoubleDataSource
All Implemented Interfaces:
DoubleDataSource
Direct Known Subclasses:
AudioDoubleDataSource, BufferedDoubleDataSource, MixerDoubleDataSource, NoiseDoubleDataSource, SequenceDoubleDataSource, SilenceDoubleDataSource, TextReaderDoubleDataSource

public class BaseDoubleDataSource
extends java.lang.Object
implements DoubleDataSource

Author:
Marc Schröder

Field Summary
protected  long dataLength
           
protected  DoubleDataSource inputSource
           
 
Fields inherited from interface marytts.util.data.DoubleDataSource
NOT_SPECIFIED
 
Constructor Summary
BaseDoubleDataSource()
           
BaseDoubleDataSource(DoubleDataSource inputSource)
           
 
Method Summary
 int available()
          The number of doubles that can currently be read from this double data source without blocking.
 double[] getAllData()
          Get all the data that can be read from this data source, in a single double array.
 int getData(double[] target)
          Try to get as many double data from this DoubleDataSource as target can hold.
 int getData(double[] target, int targetPos, int length)
          Try to get length doubles from this DoubleDataSource, and copy them into target, starting from targetPos.
 double[] getData(int amount)
          Request to get the specified amount of data in a new double array.
 long getDataLength()
          Get the total length of the data in this data source, if available.
 boolean hasMoreData()
          Whether or not any more data can be read from this data source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputSource

protected DoubleDataSource inputSource

dataLength

protected long dataLength
Constructor Detail

BaseDoubleDataSource

public BaseDoubleDataSource()

BaseDoubleDataSource

public BaseDoubleDataSource(DoubleDataSource inputSource)
Method Detail

getData

public double[] getData(int amount)
Request to get the specified amount of data in a new double array.

Specified by:
getData in interface DoubleDataSource
Parameters:
amount - the number of doubles requested
Returns:
a new double array; its length may be smaller than amount if not enough data could be obtained. If no data could be read, null is returned.

getData

public int getData(double[] target)
Try to get as many double data from this DoubleDataSource as target can hold.

Specified by:
getData in interface DoubleDataSource
Parameters:
target - the double array in which to write the data
Returns:
the number of data items written into target. If the returned value is less than target.length, only that many data items have been copied into target; further calls will return 0 and not copy anything.

getData

public int getData(double[] target,
                   int targetPos,
                   int length)
Try to get length doubles from this DoubleDataSource, and copy them into target, starting from targetPos. This is the core method getting the data. Subclasses may want to override this method.

Specified by:
getData in interface DoubleDataSource
Parameters:
target - the double array to write into
targetPos - position in target where to start writing
length - the amount of data requested
Returns:
the amount of data actually delivered. If the returned value is less than length, only that many data items have been copied into target; further calls will return 0 and not copy anything.
Throws:
java.lang.IllegalArgumentException - if there is not enough space in target after targetPos to hold length values.

hasMoreData

public boolean hasMoreData()
Whether or not any more data can be read from this data source.

Specified by:
hasMoreData in interface DoubleDataSource
Returns:
true if another call to getData() will return data, false otherwise.

available

public int available()
The number of doubles that can currently be read from this double data source without blocking. This number can change over time.

Specified by:
available in interface DoubleDataSource
Returns:
the number of doubles that can currently be read without blocking

getAllData

public double[] getAllData()
Get all the data that can be read from this data source, in a single double array.

Specified by:
getAllData in interface DoubleDataSource
Returns:
a double array of exactly the length required to contain all the data that can be read from this source. Returns an array of length 0 if no data can be read from this source.
Throws:
java.lang.OutOfMemoryError - if a sufficiently large double array cannot be created.

getDataLength

public long getDataLength()
Get the total length of the data in this data source, if available. For a BufferedDoubleDataSource created from a double[], the data length is available.

Specified by:
getDataLength in interface DoubleDataSource
Returns:
the number of doubles that can be read from this data source, or DoubleDataSource.NOT_SPECIFIED if unknown.