| 1 |
/*************************************************************************/ |
| 2 |
/* */ |
| 3 |
/* Language Technologies Institute */ |
| 4 |
/* Carnegie Mellon University */ |
| 5 |
/* Copyright (c) 2011 */ |
| 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 |
/* Authors: Gopala Anumanchipalli ([email protected]) */ |
| 34 |
/* Date: November 2011 */ |
| 35 |
/*************************************************************************/ |
| 36 |
|
| 37 |
#include "cst_cg.h" |
| 38 |
#include "cst_hrg.h" |
| 39 |
#include "cst_utt_utils.h" |
| 40 |
#include "cst_spamf0.h" |
| 41 |
#include "cst_math.h" |
| 42 |
|
| 43 |
static void cst_synthtilt(const cst_cg_db *cg_db, |
| 44 |
const float start, const float peak, const float tiltamp, |
| 45 |
const float tiltdur, const float tilttilt, |
| 46 |
cst_track *ftrack); |
| 47 |
|
| 48 |
cst_utterance *cst_spamf0(cst_utterance *utt) |
| 49 |
{ |
| 50 |
cst_track *spamf0_track=NULL; |
| 51 |
cst_track *param_track=NULL; |
| 52 |
cst_item *s; |
| 53 |
cst_cg_db *cg_db; |
| 54 |
const cst_cart *acc_tree, *phrase_tree; |
| 55 |
float end,f0val, syldur; |
| 56 |
int num_frames,f,i; |
| 57 |
cg_db = val_cg_db(utt_feat_val(utt,"cg_db")); |
| 58 |
|
| 59 |
spamf0_track=new_track(); |
| 60 |
cst_track_resize(spamf0_track, |
| 61 |
(utt_feat_int(utt,"param_track_num_frames")), |
| 62 |
1); |
| 63 |
acc_tree = cg_db->spamf0_accent_tree; |
| 64 |
phrase_tree = cg_db->spamf0_phrase_tree; |
| 65 |
end = 0.0; |
| 66 |
num_frames = 0; |
| 67 |
for (s = utt_rel_head(utt,"Segment"); s; s=item_next(s)) |
| 68 |
{ |
| 69 |
end = ffeature_float(s,"end"); |
| 70 |
if(cst_streq("pau",ffeature_string(s,"name"))) |
| 71 |
{ |
| 72 |
f0val=0; |
| 73 |
} |
| 74 |
else |
| 75 |
{ |
| 76 |
f0val=val_float(cart_interpret(s,phrase_tree)); |
| 77 |
} |
| 78 |
|
| 79 |
for ( ; ((num_frames * cg_db->frame_advance) <= end) && (num_frames < utt_feat_int(utt,"param_track_num_frames")); num_frames++) |
| 80 |
{ |
| 81 |
spamf0_track->frames[num_frames][0]=f0val; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
for (s=utt_rel_head(utt,"Syllable"); s; s=item_next(s)) |
| 86 |
{ |
| 87 |
f = val_int(cart_interpret(s,acc_tree)); |
| 88 |
syldur = ffeature_float(s,"R:SylStructure.daughtern.R:Segment.end") |
| 89 |
- ffeature_float(s,"R:SylStructure.daughter1.R:Segment.p.end"); |
| 90 |
cst_synthtilt(cg_db, |
| 91 |
ffeature_float(s,"R:SylStructure.daughter1.R:Segment.p.end"), |
| 92 |
cg_db->spamf0_accent_vectors[f][0], |
| 93 |
cg_db->spamf0_accent_vectors[f][2], |
| 94 |
syldur, |
| 95 |
cg_db->spamf0_accent_vectors[f][6], |
| 96 |
spamf0_track); |
| 97 |
} |
| 98 |
param_track = val_track(utt_feat_val(utt,"param_track")); |
| 99 |
for (i=0;i<utt_feat_int(utt,"param_track_num_frames");i++) |
| 100 |
{ |
| 101 |
param_track->frames[i][0]=spamf0_track->frames[i][0]; |
| 102 |
} |
| 103 |
delete_track(spamf0_track); |
| 104 |
return utt; |
| 105 |
} |
| 106 |
|
| 107 |
void cst_synthtilt(const cst_cg_db *cg_db, |
| 108 |
const float start, const float peak, const float tiltamp, |
| 109 |
const float tiltdur, const float tilttilt, |
| 110 |
cst_track *ftrack) |
| 111 |
{ |
| 112 |
float arise,afall,drise,dfall,i; |
| 113 |
int num_frames; |
| 114 |
arise= tiltamp*(1+tilttilt)/2; |
| 115 |
afall= tiltamp*(1-tilttilt)/2; |
| 116 |
drise= tiltdur*(1+tilttilt)/2; |
| 117 |
dfall= tiltdur*(1-tilttilt)/2; |
| 118 |
num_frames=(int)ceil((double)(start/cg_db->frame_advance)); |
| 119 |
/* Synthesizing the rise event */ |
| 120 |
for (i=cg_db->frame_advance;((num_frames * cg_db->frame_advance)<(start+(drise/2))) ; num_frames++,i+=cg_db->frame_advance) |
| 121 |
{ |
| 122 |
ftrack->frames[num_frames][0]+= peak - arise + (2 * arise * (i/drise) * (i/drise)); |
| 123 |
ftrack->frames[num_frames][0]=exp(ftrack->frames[num_frames][0]); |
| 124 |
} |
| 125 |
for (;((num_frames * cg_db->frame_advance)<(start+drise)) ; num_frames++,i+=cg_db->frame_advance) |
| 126 |
{ |
| 127 |
ftrack->frames[num_frames][0]+= peak - 2 * arise * (1- (i/drise)) * (1- (i/drise)); |
| 128 |
ftrack->frames[num_frames][0]=exp(ftrack->frames[num_frames][0]); |
| 129 |
} |
| 130 |
/* Synthesizing the fall event */ |
| 131 |
for (i=cg_db->frame_advance;((num_frames * cg_db->frame_advance)<(start+drise+(dfall/2))) ; num_frames++,i+=cg_db->frame_advance) |
| 132 |
{ |
| 133 |
ftrack->frames[num_frames][0]+= peak + afall - (2 * afall * (i/dfall) * (i/dfall)) - afall; |
| 134 |
ftrack->frames[num_frames][0]=exp(ftrack->frames[num_frames][0]); |
| 135 |
} |
| 136 |
for (;((num_frames * cg_db->frame_advance)<(start+drise+dfall)) ; num_frames++,i+=cg_db->frame_advance) |
| 137 |
{ |
| 138 |
ftrack->frames[num_frames][0]+= peak + (2 * afall * (1- (i/dfall)) * (1- (i/dfall))) - afall; |
| 139 |
ftrack->frames[num_frames][0]=exp(ftrack->frames[num_frames][0]); |
| 140 |
} |
| 141 |
return ; |
| 142 |
} |