2 * Copyright (C) 2005 DFKI GmbH. All rights reserved.
\r
4 package com.sun.speech.freetts.diphone;
\r
6 import java.io.DataOutputStream;
\r
7 import java.io.IOException;
\r
8 import java.nio.ByteBuffer;
\r
10 import com.sun.speech.freetts.relp.Sample;
\r
13 * Represent an alias diphone which is just another name for an
\r
14 * already-existing original diphone. This can be used just like a
\r
16 * @author Marc Schröder
\r
19 public class AliasDiphone extends Diphone
\r
21 private String originalName;
\r
22 private Diphone original;
\r
24 * @param name The alias name to use for the existing diphone
\r
25 * @param originalName the original name of the diphone.
\r
27 public AliasDiphone(String name, String originalName)
\r
30 this.originalName = originalName;
\r
34 * Get the name of the original name that this alias points to.
\r
36 public String getOriginalName()
\r
38 return originalName;
\r
42 * Associate the actual diphone object of the original with this alias.
\r
43 * @param original a diphone object whose getName() must return the same
\r
44 * as our getOriginalName().
\r
45 * @throws IllegalArgumentException if the diphone to be registered as the
\r
46 * original has a name which is different from this AliasDiphone's original name
\r
47 * as returned by getOriginalName().
\r
49 public void setOriginalDiphone(Diphone original)
\r
51 if (!originalName.equals(original.getName())) {
\r
52 throw new IllegalArgumentException("The diphone to register ("+original.getName()
\r
53 +") does not match the original name ("+originalName+")");
\r
55 this.original = original;
\r
59 * Returns the samples associated with this diphone.
\r
61 * @return the samples associated with this diphone
\r
63 public Sample[] getSamples() {
\r
64 return original.getSamples();
\r
68 * Returns a particular sample.
\r
70 * @param which which sample to return
\r
72 * @return the desired sample
\r
74 public Sample getSamples(int which) {
\r
75 return original.getSamples(which);
\r
79 * Returns the midpoint index. the midpoint index is the sample
\r
80 * that divides the diphone into the first and second parts.
\r
82 * @return the midpoint index.
\r
84 public int getMidPoint() {
\r
85 return original.getMidPoint();
\r
89 * Returns the midpoint index. the midpoint index is the sample
\r
90 * that divides the diphone into the first and second parts.
\r
92 * @return the midpoint index.
\r
94 public int getPbPositionMillis() {
\r
95 return original.getPbPositionMillis();
\r
99 * Returns the sample that is closest to uIndex.
\r
101 * @param uIndex the desired index
\r
102 * @param unitPart do we want the first have (1) or the second
\r
105 * @return the sample nearest to the given index in the given
\r
108 public Sample nearestSample(float uIndex, int unitPart) {
\r
109 return original.nearestSample(uIndex, unitPart);
\r
113 * Returns the total number of residuals in the given part for this
\r
116 * @param unitPart indicates which part is of interest (1 or 2)
\r
118 * @return the number of residuals in the specified part
\r
120 public int getUnitSize(int unitPart) {
\r
121 return original.getUnitSize(unitPart);
\r
125 * dumps out this Diphone.
\r
127 public void dump() {
\r
128 System.out.println("AliasDiphone: " + getName() + " aliased to " + original.getName());
\r
132 * Dumps the diphone to the given channel.
\r
134 * @param bb the ByteBuffer to write to
\r
136 * @throws IOException if IO error occurs
\r
138 public void dumpBinary(ByteBuffer bb) throws IOException {
\r
139 char[] nameArray = (getName() + " ").toCharArray();
\r
140 char[] origNameArray = (original.getName() + " ").toCharArray();
\r
142 bb.putInt(ALIAS_MAGIC);
\r
143 for (int i = 0; i < NAME_LENGTH; i++) {
\r
144 bb.putChar(nameArray[i]);
\r
146 for (int i = 0; i < NAME_LENGTH; i++) {
\r
147 bb.putChar(origNameArray[i]);
\r
152 * Dumps the diphone to the given channel.
\r
154 * @param os the DataOutputStream to write to
\r
156 * @throws IOException if IO error occurs
\r
158 public void dumpBinary(DataOutputStream os) throws IOException {
\r
159 char[] nameArray = (getName() + " ").toCharArray();
\r
160 char[] origNameArray = (original.getName() + " ").toCharArray();
\r
162 os.writeInt(ALIAS_MAGIC);
\r
163 for (int i = 0; i < NAME_LENGTH; i++) {
\r
164 os.writeChar(nameArray[i]);
\r
166 for (int i = 0; i < NAME_LENGTH; i++) {
\r
167 os.writeChar(origNameArray[i]);
\r
172 * Determines if the two diphones are equivalent. This is for
\r
173 * testing databases. This is not the same as "equals".
\r
174 * For aliased diphones, this will return true if the compare() method
\r
175 * of the original diphone returns true, even if the name used in this alias
\r
178 * @param other the diphone to compare this one to
\r
180 * @return <code>true</code> if the diphones match; otherwise
\r
181 * <code>false</code>
\r
183 boolean compare(Diphone other) {
\r
184 return original.compare(other);
\r