Package com.sun.speech.freetts.diphone

# Class Diphone

java.lang.Object
com.sun.speech.freetts.diphone.Diphone

Direct Known Subclasses:
  `AliasDiphone`

public class Diphone extends Object
Represents two adjacent phones. A diphone is defined by its name, the set of audio data, and information used to help stitch diphones together. This class is immutable.

## Field Summary

Fields
Modifier and Type
Field
Description
`protected static final int`
`ALIAS_MAGIC`
`protected static final int`
`MAGIC`
`protected static final int`
`NAME_LENGTH`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`Diphone(String name)`
Constructor to be used only by subclasses who do not use the variables except for the name
``
`Diphone(String name, Sample[] samples, int midPoint)`
Creates a diphone with the given name, samples and midpoint.

## Method Summary

Modifier and Type
Method
Description
`void`
`dump()`
dumps out this Diphone.
`void`
`dumpBinary(DataOutputStream os)`
Dumps the diphone to the given channel.
`void`
`dumpBinary(ByteBuffer bb)`
Dumps the diphone to the given channel.
`int`
`getMidPoint()`
Returns the midpoint index. the midpoint index is the sample that divides the diphone into the first and second parts.
`String`
`getName()`
Gets the name of the diphone.
`int`
`getPbPositionMillis()`
Returns the midpoint index. the midpoint index is the sample that divides the diphone into the first and second parts.
`Sample[]`
`getSamples()`
Returns the samples associated with this diphone.
`Sample`
`getSamples(int which)`
Returns a particular sample.
`int`
`getUnitSize(int unitPart)`
Returns the total number of residuals in the given part for this diphone.
`static Diphone`
`loadBinary(DataInputStream dis)`
Loads a new diphone from the given DataInputStream.
`static Diphone`
`loadBinary(ByteBuffer bb)`
Loads a new diphone from the given buffer.
`Sample`
`nearestSample(float uIndex, int unitPart)`
Returns the sample that is closest to uIndex.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### MAGIC

protected static final int MAGIC

See Also:
  - Constant Field Values

### ALIAS_MAGIC

protected static final int ALIAS_MAGIC

See Also:
  - Constant Field Values

### NAME_LENGTH

protected static final int NAME_LENGTH

See Also:
  - Constant Field Values

## Constructor Details

### Diphone

public Diphone(String name, Sample[] samples, int midPoint)
Creates a diphone with the given name, samples and midpoint.

Parameters:
  `name` - the name of the diphone
  `samples` - the set of samples for the diphone
  `midPoint` - the index of the sample midpoint

### Diphone

protected Diphone(String name)
Constructor to be used only by subclasses who do not use the variables except for the name

Parameters:
  `name` - the name of the diphone

## Method Details

### getSamples

public Sample[] getSamples()
Returns the samples associated with this diphone.

Returns:
  the samples associated with this diphone

### getSamples

public Sample getSamples(int which)
Returns a particular sample.

Parameters:
  `which` - which sample to return
Returns:
  the desired sample

### getName

public String getName()
Gets the name of the diphone.

Returns:
  the name of the diphone

### getMidPoint

public int getMidPoint()
Returns the midpoint index. the midpoint index is the sample that divides the diphone into the first and second parts.

Returns:
  the midpoint index.

### getPbPositionMillis

public int getPbPositionMillis()
Returns the midpoint index. the midpoint index is the sample that divides the diphone into the first and second parts.

Returns:
  the midpoint index.

### nearestSample

public Sample nearestSample(float uIndex, int unitPart)
Returns the sample that is closest to uIndex.

Parameters:
  `uIndex` - the desired index
  `unitPart` - do we want the first have (1) or the second half (2)
Returns:
  the sample nearest to the given index in the given part

### getUnitSize

public int getUnitSize(int unitPart)
Returns the total number of residuals in the given part for this diphone.

Parameters:
  `unitPart` - indicates which part is of interest (1 or 2)
Returns:
  the number of residuals in the specified part

### dump

public void dump()
dumps out this Diphone.

### dumpBinary

public void dumpBinary(ByteBuffer bb) throws IOException
Dumps the diphone to the given channel.

Parameters:
  `bb` - the ByteBuffer to write to
Throws:
  `IOException` - if IO error occurs

### dumpBinary

public void dumpBinary(DataOutputStream os) throws IOException
Dumps the diphone to the given channel.

Parameters:
  `os` - the DataOutputStream to write to
Throws:
  `IOException` - if IO error occurs

### loadBinary

public static Diphone loadBinary(ByteBuffer bb) throws IOException
Loads a new diphone from the given buffer.

Parameters:
  `bb` - the byte buffer to load the diphone from
Returns:
  the new diphone
Throws:
  `IOException` - if IO error occurs

### loadBinary

public static Diphone loadBinary(DataInputStream dis) throws IOException
Loads a new diphone from the given DataInputStream.

Parameters:
  `dis` - the datainput stream to load the diphone from
Returns:
  the new diphone
Throws:
  `IOException` - if IO error occurs