1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2;;;                                                                     ;;;
3;;;                     Carnegie Mellon University                      ;;;
4;;;                  and Alan W Black and Kevin Lenzo                   ;;;
5;;;                      Copyright (c) 1998-2000                        ;;;
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;;; CARNEGIE MELLON UNIVERSITY 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 CARNEGIE MELLON UNIVERSITY 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;;;
34;;; Using CART models rather than LR models generate target points
35;;; in a way similar to the way that Int_Targets_LR does
36;;;
37;;; To use this train three CART trees that predict start, mid and
38;;; end values F0 (cf. the features syl_startpitch, syl_midpitch and
39;;; syl_endpitch).  Then in your voice definition
40;;;
41;;; (set! F0start_tree f2b_F0start_tree)
42;;; (set! F0mid_tree f2b_F0mid_tree)
43;;; (set! F0end_tree f2b_F0end_tree)
44;;; (set! int_params
45;;; 	'((target_f0_mean 110) (target_f0_std 10)
46;;; 	  (model_f0_mean 170) (model_f0_std 40)))
47;;; (Parameter.set 'Int_Target_Method Int_Targets_Tree)
48
49(define (Int_Targets_Tree utt)
50  "(Int_Targets_Tree utt)
51For each syllable in a phrase add start mid and end F0 targets."
52  (utt.relation.create utt 'Target)
53  (mapcar
54   (lambda (syl)
55     (Tree_Predict_Targets utt syl))
56   (utt.relation.items utt 'Syllable))
57  utt)
58
59(define (Tree_Predict_Targets utt syl)
60  "(Tree_Predict_Targets utt syl)
61Add targets to start (if immediately after a pause) mid vowel
62and end for this syllable."
63  (if (tpt_after_pause syl)
64      (tpt_add_target
65       utt
66       (item.relation.daughter1 syl 'SylStructure)
67       0
68       (wagon_predict syl F0start_tree)))
69  (tpt_add_target utt (tpt_find_syl_vowel syl) 50
70	      (wagon_predict syl F0mid_tree))
71  (tpt_add_target utt (item.relation.daughtern syl 'SylStructure) 100
72	      (wagon_predict syl F0end_tree)))
73
74(define (tpt_after_pause syl)
75  "(tpt_after_pause syl)
76Retursn t if segment immediately before this is a pause (or utterance
77start).  nil otherwise."
78  (let ((pseg (item.relation.prev (item.relation.daughter1 syl 'SylStructure)
79				  'Segment)))
80    (if (or (not pseg)
81	    (member_string
82	     (item.name pseg)
83	     (car (cdr (car (PhoneSet.description '(silences)))))))
84	t
85	nil)))
86
87(define (tpt_find_syl_vowel syl)
88  "(tpt_find_syl_vowel syl)
89Find the item that is the vowel in syl."
90  (let ((v (item.relation.daughtern syl 'SylStructure)))
91    (mapcar
92     (lambda (s)
93       (if (string-equal "+" (item.feat s "ph_vc"))
94	   (set! v s)))
95     (item.relation.daughters syl 'SylStructure))
96    v))
97
98(define (tpt_f0_map_value value)
99  "(tpt_f0_map_value value)
100Map F0 vlaue through means and standard deviations in int_params."
101  (let ((target_f0_mean (get_param 'target_f0_mean int_params 110))
102	(target_f0_stddev (get_param 'target_f0_stddev int_params 15))
103	(model_f0_mean (get_param 'model_f0_mean int_params 110))
104	(model_f0_stddev (get_param 'model_f0_stddev int_params 15)))
105    (+ (* (/ (- value model_f0_mean) model_f0_stddev)
106	  target_f0_stddev) target_f0_mean)))
107
108(define (tpt_add_target utt seg pos value)
109  "(tpt_add_target utt seg pos value)
110Add Target at pos and value related to seg."
111  (let ((tseg (item.relation seg 'Target))
112	(ntarg))
113    (if (null tseg)
114	(set! tseg (utt.relation.append utt 'Target seg)))
115    (set! ntarg (item.append_daughter tseg))
116    (item.set_feat ntarg 'f0 (tpt_f0_map_value value))
117    (item.set_feat ntarg 'pos
118		   (+ (item.feat seg "segment_start")
119		      (* (/ pos 100) (item.feat seg "segment_duration"))))))
120
121(provide 'tree_f0)
122