public class TimelineReader extends Object
Modifier and Type | Class and Description |
---|---|
static class |
TimelineReader.IdxField
Simple helper class to read the index fields in a timeline.
|
static class |
TimelineReader.Index
Simple helper class to read the index part of a timeline file.
|
static class |
TimelineReader.ProcHeader
Simple helper class to load the processing header.
|
Modifier and Type | Field and Description |
---|---|
protected int |
datagramsBytePos |
protected TimelineReader.Index |
idx |
protected MaryHeader |
maryHdr |
protected long |
numDatagrams |
protected TimelineReader.ProcHeader |
procHdr |
protected int |
sampleRate |
protected int |
timeIdxBytePos |
protected long |
totalDuration
The total duration of the timeline data, in samples.
|
Modifier | Constructor and Description |
---|---|
protected |
TimelineReader()
Only subclasses can instantiate a TimelineReader object that doesn't call
load(String) . |
|
TimelineReader(String fileName)
Construct a timeline from the given file name.
|
|
TimelineReader(String fileName,
boolean tryMemoryMapping)
Construct a timeline from the given file name.
|
Modifier and Type | Method and Description |
---|---|
protected void |
computeTotalDuration()
Compute the total duration of a timeline.
|
protected Pair<ByteBuffer,Long> |
getByteBufferAtTime(long targetTimeInSamples)
This method produces a new byte buffer whose current position represents the requested positionInFile.
|
Datagram |
getDatagram(long targetTimeInSamples)
Get a single datagram from a particular time location, given in the timeline's sampling rate.
|
Datagram |
getDatagram(long targetTimeInSamples,
int reqSampleRate)
Get a single datagram from a particular time location.
|
Datagram[] |
getDatagrams(long targetTimeInSamples,
int number,
int reqSampleRate,
long[] returnOffset)
Get a given number of datagrams from a particular time location, and return the time offset between the time request and
the actual location of the first returned datagram.
|
Datagram[] |
getDatagrams(long targetTimeInSamples,
long timeSpanInSamples)
Get a given number of datagrams from a particular time location.
|
Datagram[] |
getDatagrams(long targetTimeInSamples,
long timeSpanInSamples,
int reqSampleRate)
Get the datagrams spanning a particular time range from a particular time location.
|
Datagram[] |
getDatagrams(long targetTimeInSamples,
long timeSpanInSamples,
int reqSampleRate,
long[] returnOffset)
Get the datagrams spanning a particular time range from a particular time location, and return the time offset between the
time request and the actual location of the first returned datagram.
|
Datagram[] |
getDatagrams(Unit unit,
int reqSampleRate)
Get the datagrams spanning a particular unit.
|
Datagram[] |
getDatagrams(Unit unit,
int reqSampleRate,
long[] returnOffset)
Get the datagrams spanning a particular unit, and return the time offset between the unit request and the actual location
of the first returned datagram.
|
protected long |
getDatagramsBytePos()
Returns the position of the datagram zone in the original file.
|
TimelineReader.Index |
getIndex()
The index object.
|
protected Pair<ByteBuffer,Long> |
getMappedByteBufferAtTime(long targetTimeInSamples) |
protected Datagram |
getNextDatagram(ByteBuffer bb)
Read and return the upcoming datagram from the given byte buffer.
|
long |
getNumDatagrams()
Returns the number of datagrams in the timeline.
|
String |
getProcHeaderContents()
Return the content of the processing header as a String.
|
int |
getSampleRate()
Returns the timeline's sample rate.
|
long |
getTotalDuration()
Return the total duration of all data in this timeline.
|
protected long |
hopToTime(ByteBuffer bb,
long currentTimeInSamples,
long targetTimeInSamples)
Hop the datagrams in the given byte buffer until the one which begins at or contains the desired time (time is in samples;
the sample rate is assumed to be that of the timeline).
|
protected void |
load(String fileName)
Load a timeline from a file.
|
protected void |
load(String fileName,
boolean tryMemoryMapping)
Load a timeline from a file.
|
protected Pair<ByteBuffer,Long> |
loadByteBufferAtTime(long targetTimeInSamples) |
protected long |
scaleTime(int reqSampleRate,
long targetTimeInSamples)
Scales a discrete time to the timeline's sample rate.
|
protected long |
skipNextDatagram(ByteBuffer bb)
Skip the upcoming datagram at the current position of the byte buffer.
|
protected long |
unScaleTime(int reqSampleRate,
long timelineTimeInSamples)
Unscales a discrete time from the timeline's sample rate.
|
protected MaryHeader maryHdr
protected TimelineReader.ProcHeader procHdr
protected TimelineReader.Index idx
protected int sampleRate
protected long numDatagrams
protected long totalDuration
protected int datagramsBytePos
protected int timeIdxBytePos
public TimelineReader(String fileName) throws MaryConfigurationException
fileName
- The file to read the timeline from. Must be non-null and point to a valid timeline file.NullPointerException
- if null argument is givenMaryConfigurationException
- if no timeline reader can be instantiated from fileNamepublic TimelineReader(String fileName, boolean tryMemoryMapping) throws MaryConfigurationException
fileName
- The file to read the timeline from. Must be non-null and point to a valid timeline file.tryMemoryMapping
- if true, will attempt to read audio data via a memory map, and fall back to piecewise reading. If false, will
immediately go for piecewise reading using a RandomAccessFile.NullPointerException
- if null argument is givenMaryConfigurationException
- if no timeline reader can be instantiated from fileNameprotected TimelineReader()
load(String)
. It is their responsibility
then to ensure the fundamental guarantee.protected void load(String fileName) throws IOException, BufferUnderflowException, MaryConfigurationException, NullPointerException
fileName
- The file to read the timeline from. Must be non-null and point to a valid timeline file.IOException
- if a problem occurs during readingBufferUnderflowException
- if a problem occurs during readingMaryConfigurationException
- if fileName does not point to a valid timeline fileNullPointerException
protected void load(String fileName, boolean tryMemoryMapping) throws IOException, BufferUnderflowException, MaryConfigurationException, NullPointerException
fileName
- The file to read the timeline from. Must be non-null and point to a valid timeline file.tryMemoryMapping
- tryMemoryMappingIOException
- if a problem occurs during readingBufferUnderflowException
- if a problem occurs during readingMaryConfigurationException
- if fileName does not point to a valid timeline fileNullPointerException
- NullPointerExceptionpublic String getProcHeaderContents()
public long getNumDatagrams()
protected long getDatagramsBytePos()
public int getSampleRate()
public long getTotalDuration() throws MaryConfigurationException
MaryConfigurationException
- if the duration cannot be obtained.protected void computeTotalDuration() throws MaryConfigurationException
MaryConfigurationException
- if the duration could not be computed.public TimelineReader.Index getIndex()
protected long scaleTime(int reqSampleRate, long targetTimeInSamples)
reqSampleRate
- the externally given sample rate.targetTimeInSamples
- a discrete time, with respect to the externally given sample rate.protected long unScaleTime(int reqSampleRate, long timelineTimeInSamples)
reqSampleRate
- the externally given sample rate.timelineTimeInSamples
- a discrete time, with respect to the timeline sample rate.protected long skipNextDatagram(ByteBuffer bb) throws IOException
bb
- bbIOException
- if we cannot skip another datagram because we have reached the end of the byte bufferprotected Datagram getNextDatagram(ByteBuffer bb)
bb
- the timeline byte buffer to read fromprotected long hopToTime(ByteBuffer bb, long currentTimeInSamples, long targetTimeInSamples) throws IOException, IllegalArgumentException
bb
- the timeline byte buffer to use. Must not be null.currentTimeInSamples
- the time position corresponding to the current position of the byte buffer. Must not be negative.targetTimeInSamples
- the time location to reach. Must not be less than currentTimeInSamplesIOException
- if there is a problem skipping the datagramsIllegalArgumentException
- if targetTimeInSamples is less than currentTimeInSamplesprotected Pair<ByteBuffer,Long> getByteBufferAtTime(long targetTimeInSamples) throws IOException, BufferUnderflowException
targetTimeInSamples
- the time position in the file which should be accessed as a byte buffer, in samples. Must be non-negative and
less than the total duration of the timeline.IOException
- IOExceptionBufferUnderflowException
- , BufferUnderflowException if no byte buffer can be obtained for the requested time.protected Pair<ByteBuffer,Long> getMappedByteBufferAtTime(long targetTimeInSamples) throws IllegalArgumentException, IOException
IllegalArgumentException
IOException
protected Pair<ByteBuffer,Long> loadByteBufferAtTime(long targetTimeInSamples) throws IOException
IOException
public Datagram getDatagram(long targetTimeInSamples) throws IOException
targetTimeInSamples
- the requested position, in samples. Must be non-negative and less than the total duration of the timeline.IOException
- , BufferUnderflowException if no datagram could be created from the data at the given time.public Datagram getDatagram(long targetTimeInSamples, int reqSampleRate) throws IOException
targetTimeInSamples
- the requested position, in samples. Must be non-negative and less than the total duration of the timeline.reqSampleRate
- the sample rate for the requested times.IOException
- if no datagram could be created from the data at the given time.public Datagram[] getDatagrams(long targetTimeInSamples, long timeSpanInSamples, int reqSampleRate, long[] returnOffset) throws IOException
targetTimeInSamples
- the requested position, in samples. Must be non-negative and less than the total duration of the timeline.timeSpanInSamples
- the requested time span, in samples. If positive, then datagrams are selected by the given time span.reqSampleRate
- the sample rate for the requested and returned times. Must be positive.returnOffset
- an optional output field. If it is not null, then after the call it must have length of at least 1, and the
first array field will contain the time difference, in samples, between the time request and the actual
beginning of the first datagram.IllegalArgumentException
- if targetTimeInSamples is negative, or if a returnOffset of length 0 is given.IOException
- , BufferUnderflowException if no data can be read at the given target timepublic Datagram[] getDatagrams(long targetTimeInSamples, long timeSpanInSamples, int reqSampleRate) throws IOException
targetTimeInSamples
- the requested position, in samples. Must be non-negative and less than the total duration of the timeline.timeSpanInSamples
- the requested time span, in samples. If positive, then datagrams are selected by the given time span.reqSampleRate
- the sample rate for the requested and returned times. Must be positive.IllegalArgumentException
- if targetTimeInSamples is negative, or if a returnOffset of length 0 is given.IOException
- if no data can be read at the given target timepublic Datagram[] getDatagrams(long targetTimeInSamples, long timeSpanInSamples) throws IOException
targetTimeInSamples
- the requested position, in samples. Must be non-negative and less than the total duration of the timeline.timeSpanInSamples
- the span in samplesIllegalArgumentException
- if targetTimeInSamples is negative, or if a returnOffset of length 0 is given.IOException
- if no data can be read at the given target timepublic Datagram[] getDatagrams(long targetTimeInSamples, int number, int reqSampleRate, long[] returnOffset) throws IOException
targetTimeInSamples
- the requested position, in samples. Must be non-negative and less than the total duration of the timeline.number
- the number of datagrams to read. Even if this is ≤ 0, at least one datagram is always returned.reqSampleRate
- the sample rate for the requested and returned times. Must be positive.returnOffset
- an optional output field. If it is not null, then after the call it must have length of at least 1, and the
first array field will contain the time difference, in samples, between the time request and the actual
beginning of the first datagram.IllegalArgumentException
- if targetTimeInSamples is negative, or if a returnOffset of length 0 is given.IOException
- if no data can be read at the given target timepublic Datagram[] getDatagrams(Unit unit, int reqSampleRate, long[] returnOffset) throws IOException
unit
- The requested speech unit, containing its own position and duration.reqSampleRate
- the sample rate for the requested and returned times. Must be positive.returnOffset
- an optional output field. If it is not null, then after the call it must have length of at least 1, and the
first array field will contain the time difference, in samples, between the time request and the actual
beginning of the first datagram.IllegalArgumentException
- if targetTimeInSamples is negative, or if a returnOffset of length 0 is given.IOException
- if no data can be read at the given target timepublic Datagram[] getDatagrams(Unit unit, int reqSampleRate) throws IOException
unit
- The requested speech unit, containing its own position and duration.reqSampleRate
- the sample rate for the requested and returned times. Must be positive.IllegalArgumentException
- if targetTimeInSamples is negative, or if a returnOffset of length 0 is given.IOException
- if no data can be read at the given target timeCopyright © 2000–2016 DFKI GmbH. All rights reserved.