1 /*************************************************************************/ 2 /* */ 3 /* Centre for Speech Technology Research */ 4 /* (University of Edinburgh, UK) and */ 5 /* Korin Richmond */ 6 /* Copyright (c) 2002 */ 7 /* All Rights Reserved. */ 8 /* */ 9 /* Permission is hereby granted, free of charge, to use and distribute */ 10 /* this software and its documentation without restriction, including */ 11 /* without limitation the rights to use, copy, modify, merge, publish, */ 12 /* distribute, sublicense, and/or sell copies of this work, and to */ 13 /* permit persons to whom this work is furnished to do so, subject to */ 14 /* the following conditions: */ 15 /* */ 16 /* 1. The code must retain the above copyright notice, this list of */ 17 /* conditions and the following disclaimer. */ 18 /* 2. Any modifications must be clearly marked as such. */ 19 /* 3. Original authors' names are not deleted. */ 20 /* 4. The authors' names are not used to endorse or promote products */ 21 /* derived from this software without specific prior written */ 22 /* permission. */ 23 /* */ 24 /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */ 25 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */ 26 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT */ 27 /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */ 28 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */ 29 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */ 30 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */ 31 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */ 32 /* THIS SOFTWARE. */ 33 /* */ 34 /*************************************************************************/ 35 /* */ 36 /* Author: Korin Richmond */ 37 /* Date: October 2002 */ 38 /* --------------------------------------------------------------------- */ 39 /* Interface for family of target cost function objects which */ 40 /* calculate a target score for given candidate */ 41 /* */ 42 /* */ 43 /* */ 44 /* */ 45 /*************************************************************************/ 46 47 48 #ifndef __EST_TARGETCOST_H__ 49 #define __EST_TARGETCOST_H__ 50 51 #include "siod.h" // for gc_protect( obj**) 52 class EST_Item; 53 54 /**@name Interface for Target Cost function object 55 */ 56 57 //@{ 58 59 /** Object oriented approach for better or for worse... 60 */ 61 62 /* Positional enum */ 63 64 enum tcpos_t { 65 TCPOS_INITIAL, 66 TCPOS_MEDIAL, 67 TCPOS_FINAL, 68 TCPOS_INTER, 69 TCPOS_POSITIONS 70 }; 71 72 73 /* 74 * BASE CLASS: EST_TargetCost 75 */ 76 class EST_TargetCost { 77 public: 78 EST_TargetCost()79 EST_TargetCost() : defScore(0.0){}; ~EST_TargetCost()80 virtual ~EST_TargetCost() {}; 81 82 // Base class operator() doesn't do much, but it will work. operator()83 virtual float operator()( const EST_Item* targp, const EST_Item* candp ) const 84 { return defScore; } 85 86 // Allow flatpacking is_flatpack()87 virtual const bool is_flatpack() const {return false;} 88 89 protected: 90 float defScore; 91 // Temp variables for use while calculating cost (here for speed) 92 mutable float score; 93 mutable float weight_sum; 94 mutable const EST_Item *cand; 95 mutable const EST_Item *targ; 96 set_cand(const EST_Item * seg)97 inline void set_cand(const EST_Item* seg) const 98 { cand = seg; } 99 set_targ(const EST_Item * seg)100 inline void set_targ(const EST_Item* seg) const 101 { targ = seg; } 102 set_targ_and_cand(const EST_Item * tseg,const EST_Item * cseg)103 inline void set_targ_and_cand(const EST_Item* tseg, const EST_Item* cseg) const 104 { set_targ(tseg); set_cand(cseg); } 105 add_weight(float w)106 inline float add_weight(float w) const 107 { weight_sum += w ; return w; } 108 109 // General cost functions that derived classes may want to use. 110 float apml_accent_cost() const; 111 float stress_cost() const; 112 float position_in_syllable_cost() const; 113 float position_in_word_cost() const; 114 float position_in_phrase_cost() const; 115 float partofspeech_cost() const; 116 float punctuation_cost() const; 117 float left_context_cost() const; 118 float right_context_cost() const; 119 float bad_duration_cost() const; 120 float out_of_lex_cost() const; 121 float bad_f0_cost() const; 122 }; 123 124 125 /* 126 * DERIVED CLASS: EST_DefaultTargetCost 127 */ 128 class EST_DefaultTargetCost : public EST_TargetCost { 129 130 public: 131 float operator()(const EST_Item* targ, const EST_Item* cand) const; 132 133 }; 134 135 /* 136 * DERIVED CLASS: EST_APMLTargetCost 137 */ 138 class EST_APMLTargetCost : public EST_TargetCost { 139 140 public: 141 float operator()(const EST_Item* targ, const EST_Item* cand) const; 142 143 }; 144 145 /* 146 * DERIVED CLASS: EST_SingingTargetCost 147 */ 148 class EST_SingingTargetCost : public EST_TargetCost { 149 150 public: 151 float operator()(const EST_Item* targ, const EST_Item* cand) const; 152 153 protected: 154 float pitch_cost() const; 155 float duration_cost() const; 156 157 }; 158 159 160 161 162 163 /* 164 * DERIVED CLASS: EST_SchemeTargetCost 165 */ 166 class EST_SchemeTargetCost : public EST_TargetCost { 167 168 private: 169 LISP tc; 170 171 public: EST_SchemeTargetCost(LISP scheme_targetcost)172 EST_SchemeTargetCost( LISP scheme_targetcost ) 173 : EST_TargetCost(), tc(scheme_targetcost) 174 { gc_protect( &tc ); } 175 ~EST_SchemeTargetCost()176 ~EST_SchemeTargetCost() 177 { gc_unprotect( &tc ); } 178 179 float operator()(const EST_Item* targ, const EST_Item* cand) const; 180 }; 181 182 183 #endif // __EST_TARGETCOST_H__ 184 185 186 187 188 189