upstream version 1.2.2
[debian/freetts] / com / sun / speech / freetts / clunits / ClusterUnitPitchmarkGenerator.java
1 /**
2  * Portions Copyright 2001 Sun Microsystems, Inc.
3  * Portions Copyright 1999-2001 Language Technologies Institute, 
4  * Carnegie Mellon University.
5  * All Rights Reserved.  Use is subject to license terms.
6  * 
7  * See the file "license.terms" for information on usage and
8  * redistribution of this file, and for a DISCLAIMER OF ALL 
9  * WARRANTIES.
10  */
11 package com.sun.speech.freetts.clunits;
12
13 import com.sun.speech.freetts.Item;
14 import com.sun.speech.freetts.relp.LPCResult;
15 import com.sun.speech.freetts.UtteranceProcessor;
16 import com.sun.speech.freetts.Utterance;
17 import com.sun.speech.freetts.Relation;
18 import com.sun.speech.freetts.ProcessException;
19
20 import com.sun.speech.freetts.relp.SampleSet;
21
22 /**
23  * 
24  * Calculates the pitchmarks. This class is an UtteranceProcessor that
25  * calculates target pitchmarks for the given utterance and adds the
26  * <i>target_lpcres</i> relation to the utterance with the pitchmark
27  * information.
28  *
29  * @see LPCResult
30  */
31 public class ClusterUnitPitchmarkGenerator implements UtteranceProcessor {
32
33     /**
34      * Calculates the pitchmarks for the utterance and adds them as
35      * an LPCResult to the Utterance in a relation named
36      * "target_lpcres".
37      *
38      * @param utterance the utterance to process
39      *
40      * @see LPCResult
41      *
42      * @throws ProcessException if an error occurs while processing
43      *     the utterance
44      */
45     public void processUtterance(Utterance utterance) throws ProcessException {
46         LPCResult lpcResult;
47         int pitchmarks = 0;
48         int uttSize = 0;
49         int unitEntry;
50         int unitStart;
51         int unitEnd;
52
53         SampleSet sts = (SampleSet) utterance.getObject("sts_list");
54         lpcResult = new LPCResult();
55
56         for (Item unit = utterance.getRelation(Relation.UNIT).getHead();
57                 unit != null; unit = unit.getNext()) {
58             unitEntry = unit.getFeatures().getInt("unit_entry");
59             unitStart = unit.getFeatures().getInt("unit_start");
60             unitEnd = unit.getFeatures().getInt("unit_end");
61             uttSize += sts.getUnitSize(unitStart, unitEnd);
62             pitchmarks += unitEnd - unitStart;
63             unit.getFeatures().setInt("target_end", uttSize);
64         }
65
66         lpcResult.resizeFrames(pitchmarks);
67
68         pitchmarks = 0;
69         uttSize = 0;
70
71         int[] targetTimes = lpcResult.getTimes();
72
73         for (Item unit = utterance.getRelation(Relation.UNIT).getHead();
74                 unit != null; unit = unit.getNext()) {
75             unitEntry = unit.getFeatures().getInt("unit_entry");
76             unitStart = unit.getFeatures().getInt("unit_start");
77             unitEnd = unit.getFeatures().getInt("unit_end");
78             for (int i = unitStart; i < unitEnd; i++,pitchmarks++) {
79                 uttSize += sts.getSample(i).getResidualSize();
80                 targetTimes[pitchmarks] = uttSize;
81             }
82         }
83         utterance.setObject("target_lpcres", lpcResult);
84     }
85
86     /**
87      * Retrieves the name of this utteranceProcessor.
88      * 
89      * @return the name of the utteranceProcessor
90      */
91     public String toString() {
92         return "ClusterUnitPitchmarkGenerator";
93     }
94 }