1 /*************************************************************************/
2 /*                                                                       */
3 /*                Centre for Speech Technology Research                  */
4 /*                     University of Edinburgh, UK                       */
5 /*                       Copyright (c) 1996,1997                         */
6 /*                        All Rights Reserved.                           */
7 /*                                                                       */
8 /*  Permission is hereby granted, free of charge, to use and distribute  */
9 /*  this software and its documentation without restriction, including   */
10 /*  without limitation the rights to use, copy, modify, merge, publish,  */
11 /*  distribute, sublicense, and/or sell copies of this work, and to      */
12 /*  permit persons to whom this work is furnished to do so, subject to   */
13 /*  the following conditions:                                            */
14 /*   1. The code must retain the above copyright notice, this list of    */
15 /*      conditions and the following disclaimer.                         */
16 /*   2. Any modifications must be clearly marked as such.                */
17 /*   3. Original authors' names are not deleted.                         */
18 /*   4. The authors' names are not used to endorse or promote products   */
19 /*      derived from this software without specific prior written        */
20 /*      permission.                                                      */
21 /*                                                                       */
22 /*  THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        */
23 /*  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      */
24 /*  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   */
25 /*  SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     */
26 /*  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    */
27 /*  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   */
28 /*  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          */
29 /*  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       */
30 /*  THIS SOFTWARE.                                                       */
31 /*                                                                       */
32 /*************************************************************************/
33 /*             Author :  Alan W Black (and Paul Taylor)                  */
34 /*             Date   :  April 199[4|6]                                  */
35 /*-----------------------------------------------------------------------*/
36 /*                                                                       */
37 /* Simple intonation prediction: a hat shape on each content word        */
38 /*                                                                       */
39 /*=======================================================================*/
40 #include <cstdio>
41 #include "festival.h"
42 #include "intonation.h"
43 
44 static void add_targets(EST_Utterance *u,EST_Item *syl,
45 			float baseline,float peak);
46 
FT_Intonation_Simple_Utt(LISP utt)47 LISP FT_Intonation_Simple_Utt(LISP utt)
48 {
49     // Predict some accents
50     EST_Utterance *u = get_c_utt(utt);
51     EST_Item *s;
52     LISP accent_tree;
53     EST_Val paccent;
54 
55     *cdebug << "Simple intonation module" << endl;
56 
57     accent_tree = siod_get_lval("int_accent_cart_tree","no accent tree");
58 
59     u->create_relation("IntEvent");
60     u->create_relation("Intonation");
61 
62     for (s=u->relation("Syllable")->first(); s != 0; s = s->next())
63     {
64 	paccent = wagon_predict(s,accent_tree);
65 	if (paccent != "NONE")
66 	    add_IntEvent(u,s,paccent.string());
67     }
68 
69     return utt;
70 }
71 
FT_Int_Targets_Simple_Utt(LISP utt)72 LISP FT_Int_Targets_Simple_Utt(LISP utt)
73 {
74     // Predict F0 targets
75     EST_Utterance *u = get_c_utt(utt);
76     EST_Item *s, *p, start_word, end_word;
77     float start,end,duration;
78     float baseline, decline;
79     EST_Item *start_syl, *end_syl;
80     LISP simple_params;
81     float f0_mean, f0_std;
82 
83     *cdebug << "Simple int targets module" << endl;
84 
85     // Create some down step accents
86     simple_params = siod_get_lval("int_simple_params","no simple params");
87     f0_mean = get_param_int("f0_mean",simple_params,110);
88     f0_std = get_param_int("f0_std",simple_params,25);
89 
90     u->create_relation("Target");
91 
92     for (p=u->relation("Phrase")->first(); p != 0 ; p=p->next())
93     {
94 	baseline = f0_mean + (f0_std * 0.6);
95 	start = ffeature(p,"R:Phrase.daughter1.word_start");
96 	end = ffeature(p,"R:Phrase.daughtern.word_end");
97 	duration = end - start;
98 	decline = f0_std / duration;
99 	start_syl = daughter1(daughter1(p),"SylStructure");
100 	end_syl = daughtern(daughtern(p),"SylStructure");
101 
102 	if (start_syl)
103 	    add_target(u,daughter1(start_syl,"SylStructure"),
104 	       ffeature(start_syl,"R:SylStructure.daughter1.segment_start"),
105 		       baseline);
106 	for (s=start_syl->as_relation("Syllable"); s != end_syl->next();
107 	     s = s->next())
108 	{
109 	    if (ffeature(s,"accented") == 1)
110 		add_targets(u,s,baseline,f0_std);
111 	    baseline -= decline*(ffeature(s,"syllable_duration").Float());
112 	}
113 
114 	if (end_syl)
115 	    add_target(u,daughtern(end_syl,"SylStructure"),
116 		   ffeature(end_syl,"R:SylStructure.daughtern.segment_end"),
117 		   f0_mean-f0_std);
118     }
119 
120     return utt;
121 }
122 
add_targets(EST_Utterance * u,EST_Item * syl,float baseline,float peak)123 static void add_targets(EST_Utterance *u,EST_Item *syl,
124 			float baseline,float peak)
125 {
126     // Add a down stepped accent at this point
127     EST_Item *first_seg = daughter1(syl,"SylStructure");
128     EST_Item *end_seg = daughter1(syl,"SylStructure");
129     EST_Item *t=0,*vowel_seg;
130 
131     add_target(u,first_seg,ffeature(first_seg,"segment_start"),baseline);
132 
133     vowel_seg = end_seg; // by default
134     for (t = first_seg; t != 0; t = t->next())
135 	if (ph_is_vowel(t->name()))
136 	{
137 	    vowel_seg = t;
138 	    break;
139 	}
140     add_target(u,vowel_seg,ffeature(vowel_seg,"segment_mid"),baseline+peak);
141     add_target(u,end_seg,ffeature(end_seg,"segment_end"),baseline);
142 }
143 
144 
145