Пример #1
0
/*
 * Return the next item in the queue for the item with the given item-id.
 *
 * @param queue   The queue
 * @param item_id The id of the item in the queue
 * @param shuffle If 0 return the next item in the play-queue, if 1 the next item in the shuffle-queue
 * @param r_mode  Repeat mode
 * @param reshuffle If 1 and repeat mode is "repeat all" reshuffles the queue on wrap around
 * @return The next item
 */
struct queue_item *
queue_next(struct queue *queue, unsigned int item_id, char shuffle, enum repeat_mode r_mode, int reshuffle)
{
  struct queue_item *item;

  item = queueitem_get_byitemid(queue, item_id);

  if (!item)
    // Item not found, start playing from the start of the queue
    item = queue->head;

  if (r_mode == REPEAT_SONG && item != queue->head)
    return item;

  item = item_next(item, shuffle);

  if (item == queue->head && r_mode == REPEAT_ALL)
    {
      // Repeat all and end of queue reached, return first item in the queue
      if (reshuffle)
	queue_shuffle(queue, 0);
      item = item_next(queue->head, shuffle);
    }

  if (item == queue->head)
    return NULL;

  return item;
}
Пример #2
0
cst_item *item_last_daughter(const cst_item *i)
{
    cst_item *p;

    for (p=item_daughter(i); item_next(p); p=item_next(p));
    return p;
}
Пример #3
0
int main(int argc, char **argv)
{
    cst_utterance *u;
    cst_relation *r;
    cst_item *item=0;
    int i;

    cmu_lex_init();

    u = new_utterance();
    r = utt_relation_create(u,"Word");

    bbb_relation_load(r,"ttt.txt");

    WordSylSeg(u);

    for (i=0,item=item_next(relation_head(utt_relation(u,"Segment"))); 
	 item; item=item_next(item),i++)
    {
	printf("Segment %s %s %s %s\n",
	       ffeature_string(item,"name"),
	       ffeature_string(item,"n.name"),
	       ffeature_string(item,"p.name"),
	       ffeature_string(item,"R:SylStructure.parent.name")
/*	       ffeature_string(item,"R:SylStructure.parent.R:Word.n.name"), */
/*	       item_feat_float(item,"duration")); */
	       );
    }

    delete_utterance(u);

    return 0;
}
Пример #4
0
cst_utterance *cst_spamf0(cst_utterance *utt)
{
    cst_track *spamf0_track = NULL;
    cst_track *param_track = NULL;
    cst_item *s;
    cst_cg_db *cg_db;
    const cst_cart *acc_tree, *phrase_tree;
    float end, f0val, syldur;
    int num_frames, f, i;
    cg_db = val_cg_db(utt_feat_val(utt, "cg_db"));

    spamf0_track = new_track();
    cst_track_resize(spamf0_track,
                     (utt_feat_int(utt, "param_track_num_frames")), 1);
    acc_tree = cg_db->spamf0_accent_tree;
    phrase_tree = cg_db->spamf0_phrase_tree;
    end = 0.0;
    num_frames = 0;
    for (s = utt_rel_head(utt, "Segment"); s; s = item_next(s))
    {
        end = ffeature_float(s, "end");
        if (cst_streq("pau", ffeature_string(s, "name")))
        {
            f0val = 0;
        }
        else
        {
            f0val = val_float(cart_interpret(s, phrase_tree));
        }

        for (;
             ((num_frames * cg_db->frame_advance) <= end)
             && (num_frames < utt_feat_int(utt, "param_track_num_frames"));
             num_frames++)
        {
            spamf0_track->frames[num_frames][0] = f0val;
        }
    }

    for (s = utt_rel_head(utt, "Syllable"); s; s = item_next(s))
    {
        f = val_int(cart_interpret(s, acc_tree));
        syldur = ffeature_float(s, "R:SylStructure.daughtern.R:Segment.end")
            - ffeature_float(s, "R:SylStructure.daughter1.R:Segment.p.end");
        cst_synthtilt(cg_db,
                      ffeature_float(s,
                                     "R:SylStructure.daughter1.R:Segment.p.end"),
                      cg_db->spamf0_accent_vectors[f][0],
                      cg_db->spamf0_accent_vectors[f][2], syldur,
                      cg_db->spamf0_accent_vectors[f][6], spamf0_track);
    }
    param_track = val_track(utt_feat_val(utt, "param_track"));
    for (i = 0; i < utt_feat_int(utt, "param_track_num_frames"); i++)
    {
        param_track->frames[i][0] = spamf0_track->frames[i][0];
    }
    delete_track(spamf0_track);
    return utt;
}
Пример #5
0
cst_utterance *f0_targets_to_pm(cst_utterance *utt)
{
    cst_item *t;
    float pos,lpos,f0,lf0,m;
    double time;
    int pm;
    cst_sts_list *sts_list;
    cst_lpcres *target_lpcres;

    sts_list = val_sts_list(utt_feat_val(utt,"sts_list"));
    lpos = 0;
    lf0 = 120; /* hmm */
    pm = 0;
    time = 0;
    /* First pass to count how many pms will be required */
    for (t=relation_head(utt_relation(utt,"Target"));
	 t;
	 t=item_next(t), lf0 = f0, lpos = pos) /* changed by dhopkins */
    {
	pos = item_feat_float(t,"pos");
	f0 = item_feat_float(t,"f0");
	if (time == pos) continue;
	m = (f0-lf0)/(pos-lpos);
	for ( ; time < pos; pm++)
	{
	    time += 1/(lf0 + ((time-lpos)*m));
	}
    }
    target_lpcres = new_lpcres();
    lpcres_resize_frames(target_lpcres,pm);

    lpos = 0;
    lf0 = 120;
    pm = 0;
    time = 0;
    /* Second pass puts the values in */
    for (t=relation_head(utt_relation(utt,"Target"));
	 t;
	 t=item_next(t), lf0 = f0, lpos = pos) /* changed by dhopkins */
    {
	pos = item_feat_float(t,"pos");
	f0 = item_feat_float(t,"f0");
	if (time == pos) continue;
	m = (f0-lf0)/(pos-lpos);
	for ( ; time < pos; pm++)
	{
	    time += 1/(lf0 + ((time-lpos)*m));
	    target_lpcres->times[pm] = sts_list->sample_rate * time;
	}
    }
    utt_set_feat(utt,"target_lpcres",lpcres_val(target_lpcres));
    return utt;
}
Пример #6
0
/* Flite_HTS_Engine_synthesize: synthesize speech */
HTS_Boolean Flite_HTS_Engine_synthesize(Flite_HTS_Engine * f, const char *txt, const char *wav)
{
   int i;
   FILE *fp;
   cst_voice *v = NULL;
   cst_utterance *u = NULL;
   cst_item *s = NULL;
   char **label_data = NULL;
   int label_size = 0;

   if (txt == NULL)
      return FALSE;

   /* text analysis part */
   v = REGISTER_VOX(NULL);
   if (v == NULL)
      return FALSE;
   u = flite_synth_text(txt, v);
   if (u == NULL) {
      UNREGISTER_VOX(v);
      return FALSE;
   }
   for (s = relation_head(utt_relation(u, "Segment")); s; s = item_next(s))
      label_size++;
   if (label_size <= 0) {
      delete_utterance(u);
      UNREGISTER_VOX(v);
      return FALSE;
   }
   label_data = (char **) calloc(label_size, sizeof(char *));
   for (i = 0, s = relation_head(utt_relation(u, "Segment")); s; s = item_next(s), i++) {
      label_data[i] = (char *) calloc(MAXBUFLEN, sizeof(char));
      Flite_HTS_Engine_create_label(f, s, label_data[i]);
   }

   /* speech synthesis part */
   HTS_Engine_synthesize_from_strings(&f->engine, label_data, label_size);
   if (wav != NULL) {
      fp = fopen(wav, "wb");
      HTS_Engine_save_riff(&f->engine, fp);
      fclose(fp);
   }
   HTS_Engine_refresh(&f->engine);

   for (i = 0; i < label_size; i++)
      free(label_data[i]);
   free(label_data);

   delete_utterance(u);
   UNREGISTER_VOX(v);

   return TRUE;
}
Пример #7
0
static const cst_val *seg_onsetcoda(const cst_item *seg)
{
    const cst_item *s;
    const cst_phoneset *ps = item_phoneset(seg);
    
    for (s=item_next(item_as(seg,"SylStructure"));
	 s;
	 s=item_next(s))
    {
	if (cst_streq("+",phone_feature_string(ps,item_feat_string(s,"name"),
					       "vc")))
	    return (cst_val *)&val_string_onset;
    }
    return (cst_val *)&val_string_coda;
}
Пример #8
0
cst_utterance *cart_intonation(cst_utterance *u)
{
    cst_cart *accents, *tones;
    cst_item *s;
    const cst_val *v;

    if (feat_present(u->features,"no_intonation_accent_model"))
        return u;  /* not all languages have intonation models */

    accents = val_cart(feat_val(u->features,"int_cart_accents"));
    tones = val_cart(feat_val(u->features,"int_cart_tones"));
    
    for (s=relation_head(utt_relation(u,"Syllable")); s; s=item_next(s))
    {
	v = cart_interpret(s,accents);
	if (!cst_streq("NONE",val_string(v)))
	    item_set_string(s,"accent",val_string(v));
	v = cart_interpret(s,tones);
	if (!cst_streq("NONE",val_string(v)))
	    item_set_string(s,"endtone",val_string(v));
	DPRINTF(0,("word %s gpos %s stress %s ssyl_in %s ssyl_out %s accent %s endtone %s\n",
		   ffeature_string(s,"R:SylStructure.parent.name"),
		   ffeature_string(s,"R:SylStructure.parent.gpos"),
		   ffeature_string(s,"stress"),
		   ffeature_string(s,"ssyl_in"),
		   ffeature_string(s,"ssyl_out"),
		   ffeature_string(s,"accent"),
		   ffeature_string(s,"endtone")));
    }

    return u;
}
Пример #9
0
cst_utterance *default_phrasing(cst_utterance *u)
{
    cst_relation *r;
    cst_item *w, *p;
    const cst_val *v;
    cst_cart *phrasing_cart;

    r = utt_relation_create(u,"Phrase");
    phrasing_cart = val_cart(feat_val(u->features,"phrasing_cart"));

    for (p=NULL,w=relation_head(utt_relation(u,"Word")); w; w=item_next(w))
    {
	if (p == NULL)
	{
	    p = relation_append(r,NULL);
	    item_set_string(p,"name","BB");
	}
	item_add_daughter(p,w);
	v = cart_interpret(w,phrasing_cart);
	if (cst_streq(val_string(v),"BB"))
	    p = NULL;
    }
    
    return u;
}
Пример #10
0
void test_hrg(void)
{
    cst_utterance *u;
    cst_relation *r;
    cst_item *item = 0;
    int i;

    u = new_utterance();
    r = utt_relation_create(u, "Segment");

    for (i = 0; i < 10; i++)
    {
        char buff[20];
        sprintf(buff, "seg_%03d", i);
        if (i == 0)
            item = relation_append(r, NULL);
        else
            item = item_append(item, NULL);
        item_set_string(item, "name", buff);
        item_set_float(item, "duration", i * 0.20);
    }

    for (i = 0, item = relation_head(utt_relation(u, "Segment"));
         item; item = item_next(item), i++)
    {
        TEST_CHECK(item_feat_float(item, "duration") == correct_list[i]);
    }

    delete_utterance(u);
}
Пример #11
0
int main(int argc, char **argv)
{
    cst_utterance *u;
    cst_relation *r;
    cst_item *item=0;
    int i;

    u = new_utterance();
    r = utt_relation_create(u,"Segment");

    for (i=0; i<10; i++)
    {
	char buff[20];
	sprintf(buff,"seg_%03d",i);
	if (i==0)
	    item = relation_append(r,NULL);
	else
	    item = item_append(item,NULL);
	item_set_string(item,"name",buff);
	item_set_float(item,"duration",i*0.20);
    }

    for (i=0,item=relation_head(utt_relation(u,"Segment")); 
	 item; item=item_next(item),i++)
    {
	printf("Segment %d %s %f\n",
	       i,
	       item_feat_string(item,"name"),
	       item_feat_float(item,"duration"));
    }

    delete_utterance(u);

    return 0;
}
Пример #12
0
cst_utterance *default_pause_insertion(cst_utterance *u)
{
    /* Add initial silences and silence at each phrase break */
    const char *silence;
    const cst_item *w;
    cst_item *p, *s;

    silence = val_string(feat_val(u->features,"silence"));

    /* Insert initial silence */
    s = relation_head(utt_relation(u,"Segment"));
    if (s == NULL)
	s = relation_append(utt_relation(u,"Segment"),NULL);
    else
	s = item_prepend(s,NULL);
    item_set_string(s,"name",silence);

    for (p=relation_head(utt_relation(u,"Phrase")); p; p=item_next(p))
    {
	for (w = item_last_daughter(p); w; w=item_prev(w))
	{
	    s = path_to_item(w,"R:SylStructure.daughtern.daughtern.R:Segment");
	    if (s)
	    {
		s = item_append(s,NULL);
		item_set_string(s,"name",silence);
		break;
	    }
	}
    }

    return u;
}
Пример #13
0
static int WordSylSeg(cst_utterance *u)
{
    cst_item *word;
    cst_relation *sylstructure,*seg,*syl;
    cst_val *phones;
    const cst_val *p;
    cst_item *ssword,*segitem;
    
    syl = utt_relation_create(u,"Syllable");
    sylstructure = utt_relation_create(u,"SylStructure");
    seg = utt_relation_create(u,"Segment");
    
    for (word=relation_head(utt_relation(u,"Word")); 
	 word; word=item_next(word))
    {
	printf("word: %s\n",item_feat_string(word,"name"));
	ssword = relation_append(sylstructure,word);
	phones = lex_lookup((cst_lexicon *)&cmu_lex,item_feat_string(word,"name"),0);
	for (p=phones; p; p=val_cdr(p))
	{
	    segitem = relation_append(seg,NULL);
	    item_set(segitem,"name",val_car(p));
	    printf("seg: %s\n",item_feat_string(segitem,"name"));
	    item_add_daughter(ssword,segitem);
	}
	delete_val_list(phones);
    }

    return TRUE;

}
Пример #14
0
static cst_utterance *cg_make_hmmstates(cst_utterance *utt)
{
    /* Build HMM state structure below the segment structure */
    cst_cg_db *cg_db;
    cst_relation *hmmstate, *segstate;
    cst_item *seg, *s, *ss;
    const char *segname;
    int sp,p;

    cg_db = val_cg_db(utt_feat_val(utt,"cg_db"));
    hmmstate = utt_relation_create(utt,"HMMstate");
    segstate = utt_relation_create(utt,"segstate");

    for (seg = utt_rel_head(utt,"Segment"); seg; seg=item_next(seg))
    {
        ss = relation_append(segstate,seg);
        segname = item_feat_string(seg,"name");
        for (p=0; cg_db->phone_states[p]; p++)
            if (cst_streq(segname,cg_db->phone_states[p][0]))
                break;
        if (cg_db->phone_states[p] == NULL)
            p = 0;  /* unknown phoneme */
        for (sp=1; cg_db->phone_states[p][sp]; sp++)
        {
            s = relation_append(hmmstate,NULL);
            item_add_daughter(ss,s);
            item_set_string(s,"name",cg_db->phone_states[p][sp]);
            item_set_int(s,"statepos",sp);
        }
    }

    return utt;
}
Пример #15
0
int relation_save(cst_relation *r, const char *filename)
{
    cst_file fd;
    cst_item *item;

    if (cst_streq(filename, "-"))
        fd = stdout;
    else

    if ((fd = cst_fopen(filename, CST_OPEN_WRITE)) == 0)
    {
        cst_errmsg("relation_save: can't open file \"%s\" for writing\n",
                   filename);
        return CST_ERROR_FORMAT;
    }

    for (item = relation_head(r); item; item = item_next(item))
    {
        if (item_feat_present(item, "end"))
            cst_fprintf(fd, "%f ", item_feat_float(item, "end"));
        else
            cst_fprintf(fd, "%f ", 0.00);
        if (item_feat_present(item, "name"))
            cst_fprintf(fd, "%s ", item_feat_string(item, "name"));
        else
            cst_fprintf(fd, "%s ", "_");
        cst_fprintf(fd, "\n");
    }
    if (fd != stdout)
        cst_fclose(fd);

    return CST_OK_FORMAT;
}
Пример #16
0
cst_utterance *default_phrasing(cst_utterance *u)
{
    cst_relation *r;
    cst_item *w, *p, *lp=NULL;
    const cst_val *v;
    cst_cart *phrasing_cart;

    r = utt_relation_create(u,"Phrase");
    phrasing_cart = val_cart(feat_val(u->features,"phrasing_cart"));

    for (p=NULL,w=relation_head(utt_relation(u,"Word")); w; w=item_next(w))
    {
	if (p == NULL)
	{
	    p = relation_append(r,NULL);
            lp = p;
#ifdef FLITE_PLUS_HTS_ENGINE
            item_set_string(p,"name","BB");
#else
            item_set_string(p,"name","B");
#endif /* FLITE_PLUS_HTS_ENGINE */
	}
	item_add_daughter(p,w);
	v = cart_interpret(w,phrasing_cart);
	if (cst_streq(val_string(v),"BB"))
	    p = NULL;
    }

    if (lp && item_prev(lp)) /* follow festival */
        item_set_string(lp,"name","BB");
    
    return u;
}
Пример #17
0
cst_utterance *russian_postlex_function(cst_utterance *u)
{
  const cst_item *word,*seg;
  const char *answer,*name,*pair;
  for(word=relation_head(utt_relation(u,"Transcription"));word;word=item_next(word))
    {
      if(item_feat_present(word,"no_pl")||item_feat_present(word,"no_vr"))
        continue;
      for(seg=item_daughter(word);seg;seg=item_next(seg))
        {
          name=item_feat_string(seg,"name");
          if(cst_member_string(name,unstressed_vowels))
            {
              answer=val_string(cart_interpret(item_as(seg,"Segment"),&ru_vowel_reduction_cart));
              if(!cst_streq(answer,"N"))
                item_set_string(seg,"name",answer);
            }
          else
            {
              if(cst_streq(name,"ii")&&
                 cst_streq(ffeature_string(seg,"R:Segment.p.ph_csoft"),"-")&&
                 !(cst_streq(item_feat_string(word,"name"),"и")&&
                   cst_streq(ffeature_string(word,"gpos"),"content")))
                {
                  item_set_string(seg,"name","yy");
                }
            }
        }
    }
  for(word=relation_tail(utt_relation(u,"Transcription"));word;word=item_prev(word))
    {
      if(item_feat_present(word,"no_pl"))
        continue;
      for(seg=item_last_daughter(word);seg;seg=item_prev(seg))
        {
          name=item_feat_string(seg,"name");
          pair=russian_vpair(name);
          if(pair!=NULL)
            {
              answer=val_string(cart_interpret(item_as(seg,"Segment"),&ru_vpair_cart));
              if(cst_streq(answer,"Y"))
                item_set_string(seg,"name",pair);
            }
        }
    }
  return u;
}
Пример #18
0
/* Flite_Text_Analyzer_analysis: text analysis */
void Flite_Text_Analyzer_analysis(Flite_Text_Analyzer * analyzer, const char *text)
{
   int i;
   cst_item *s;
   Flite_Utterance *fu;

   if (analyzer == NULL || text == NULL)
      return;

   if (analyzer->pointer != NULL)
      Flite_Text_Analyzer_clear(analyzer);

   /* allocate */
   fu = (Flite_Utterance *) malloc(sizeof(Flite_Utterance));

   /* create voice */
   fu->v = REGISTER_VOX(NULL);
   if (fu->v == NULL) {
      free(fu);
      return;
   }

   /* create utterance */
   fu->u = flite_synth_text(text, fu->v);
   if (fu->u == NULL) {
      UNREGISTER_VOX(fu->v);
      free(fu);
      return;
   }

   /* count number of phonemes */
   for (fu->nitem = 0, s = relation_head(utt_relation(fu->u, "Segment")); s; s = item_next(s), fu->nitem++);
   if (fu->nitem == 0) {
      delete_utterance(fu->u);
      UNREGISTER_VOX(fu->v);
      free(fu);
      return;
   }

   /* save informations */
   fu->items = (cst_item **) malloc(sizeof(cst_item *) * fu->nitem);
   for (i = 0, s = relation_head(utt_relation(fu->u, "Segment")); s; s = item_next(s), i++)
      fu->items[i] = s;

   analyzer->pointer = (void *) fu;
}
Пример #19
0
cst_item *item_nth_daughter(const cst_item *i,int n)
{
    int d;
    cst_item *p;

    for (d=0,p=item_daughter(i); p && (d < n); p=item_next(p),d++);
    return p;
}
Пример #20
0
static const cst_val *syl_final(const cst_item *seg)
{   /* last segment in a syllable */
    const cst_item *s = item_as(seg,"SylStructure");

    if (!s || (item_next(s) == NULL))
	return VAL_STRING_1;
    else
	return VAL_STRING_0;
}
Пример #21
0
static void fix_ah(cst_utterance *u)
{
    /* This should really be done in the index itself */
    const cst_item *s;

    for (s=relation_head(utt_relation(u,"Segment")); s; s=item_next(s))
	if (cst_streq(item_feat_string(s,"name"),"ah"))
	    item_set_string(s,"name","aa");
}
/* Flite_HTS_Engine_synthesis: speech synthesis */
void Flite_HTS_Engine_synthesis(Flite_HTS_Engine * f, char *txt, FILE * wavfp)
{
    int i;
    cst_voice *v = NULL;
    cst_utterance *u = NULL;
    cst_item *s = NULL;
    char **label_data = NULL;
    int label_size = 0;

    /* text analysis part */
    v = REGISTER_VOX(NULL);
    if (v == NULL)
        return;
    u = flite_synth_text(txt, v);
    if (u == NULL)
        return;
    for (s = relation_head(utt_relation(u, "Segment")); s; s = item_next(s))
        label_size++;
    if (label_size <= 0)
        return;
    label_data = (char **) calloc(label_size, sizeof(char *));
    for (i = 0, s = relation_head(utt_relation(u, "Segment")); s;
            s = item_next(s), i++) {
        label_data[i] = (char *) calloc(MAXBUFLEN, sizeof(char));
        Flite_HTS_Engine_create_label(f, s, label_data[i]);
    }

    /* speech synthesis part */
    HTS_Engine_load_label_from_string_list(&f->engine, label_data, label_size);
    HTS_Engine_create_sstream(&f->engine);
    HTS_Engine_create_pstream(&f->engine);
    HTS_Engine_create_gstream(&f->engine);
    if (wavfp != NULL)
        HTS_Engine_save_riff(&f->engine, wavfp);

    HTS_Engine_refresh(&f->engine);

    for (i = 0; i < label_size; i++)
        free(label_data[i]);
    free(label_data);

    delete_utterance(u);
    UNREGISTER_VOX(v);
}
Пример #23
0
static cst_utterance *cg_make_params(cst_utterance *utt)
{
    /* puts in the frame items */
    /* historically called "mcep" but can actually be any random vectors */
    cst_cg_db *cg_db;
    cst_relation *mcep, *mcep_link;
    cst_item *s, *mcep_parent, *mcep_frame;
    int num_frames;
    float start, end;
    float dur_stretch, tok_stretch;

    cg_db = val_cg_db(utt_feat_val(utt,"cg_db"));
    mcep = utt_relation_create(utt,"mcep");
    mcep_link = utt_relation_create(utt,"mcep_link");
    end = 0.0;
    num_frames = 0;
    dur_stretch = get_param_float(utt->features,"duration_stretch", 1.0);

    for (s = utt_rel_head(utt,"HMMstate"); s; s=item_next(s))
    {
        start = end;
        tok_stretch = ffeature_float(s,"R:segstate.parent.R:SylStructure.parent.parent.R:Token.parent.local_duration_stretch");
        if (tok_stretch == 0)
            tok_stretch = 1.0;
        end = start + (tok_stretch*dur_stretch*cg_state_duration(s,cg_db));
        item_set_float(s,"end",end);
        mcep_parent = relation_append(mcep_link, s);
        for ( ; (num_frames * cg_db->frame_advance) <= end; num_frames++ )
        {
            mcep_frame = relation_append(mcep,NULL);
            item_add_daughter(mcep_parent,mcep_frame);
            item_set_int(mcep_frame,"frame_number",num_frames);
            item_set(mcep_frame,"name",item_feat(mcep_parent,"name"));
        }
    }

    /* Copy duration up onto Segment relation */
    for (s = utt_rel_head(utt,"Segment"); s; s=item_next(s))
        item_set(s,"end",ffeature(s,"R:segstate.daughtern.end"));

    utt_set_feat_int(utt,"param_track_num_frames",num_frames);

    return utt;
}
Пример #24
0
cst_utterance *asis_to_pm(cst_utterance *utt)
{
    /* Copy the PM structure from the units unchanged */
    cst_item *u;
    cst_lpcres *target_lpcres;
    int  unit_start, unit_end;
    int utt_pms, utt_size, i;
    cst_sts_list *sts_list;

    sts_list = val_sts_list(utt_feat_val(utt,"sts_list"));
    target_lpcres = new_lpcres();

    /* Pass one to find the size */
    utt_pms = utt_size = 0;
    for (u=relation_head(utt_relation(utt,"Unit"));
	 u; 
	 u=item_next(u))
    {
	unit_start = item_feat_int(u,"unit_start");
	unit_end = item_feat_int(u,"unit_end");
	utt_size += get_unit_size(sts_list,unit_start,unit_end);
	utt_pms += unit_end - unit_start;
	item_set_int(u,"target_end",utt_size);
    }
    lpcres_resize_frames(target_lpcres,utt_pms);

    /* Pass two to fill in the values */
    utt_pms = utt_size = 0;
    for (u=relation_head(utt_relation(utt,"Unit"));
	 u; 
	 u=item_next(u))
    {
	unit_start = item_feat_int(u,"unit_start");
	unit_end = item_feat_int(u,"unit_end");
	for (i=unit_start; i<unit_end; i++,utt_pms++)
	{
	    utt_size += get_frame_size(sts_list, i);
	    target_lpcres->times[utt_pms] = utt_size;
	}
    }
    utt_set_feat(utt,"target_lpcres",lpcres_val(target_lpcres));
    return utt;
}
Пример #25
0
static const cst_val *word_numsyls(const cst_item *word)
{
    cst_item *d;
    int c;
    
    for (c=0,d=item_daughter(item_as(word,"SylStructure"));
	 d;
	 d=item_next(d),c++);

    return val_int_n(c);
}
Пример #26
0
static void cg_smooth_F0(cst_utterance *utt,cst_cg_db *cg_db,
                         cst_track *param_track)
{
    /* Smooth F0 and mark unnoived frames as 0.0 */
    cst_item *mcep;
    int i, c;
    float l, s;
    float mean, stddev;

    l = 0.0;
    for (i=0; i<param_track->num_frames-1; i++)
    {
        c = 0; s = 0;
        if (l > 0.0)
        {
            c++; s+=l;
        }
        if (param_track->frames[i+1][0] > 0.0)
        {
            c++; s+=param_track->frames[i+1][0];
        }
        l = param_track->frames[i][0];
        if (param_track->frames[i][0] > 0.0)
        {
            c++; s+=param_track->frames[i][0];
            param_track->frames[i][0] = s/c;
        }
    }

    mean = get_param_float(utt->features,"int_f0_target_mean", cg_db->f0_mean);
    mean *= get_param_float(utt->features,"f0_shift", 1.0);
    stddev = 
        get_param_float(utt->features,"int_f0_target_stddev", cg_db->f0_stddev);
    
    for (i=0,mcep=utt_rel_head(utt,"mcep"); mcep; i++,mcep=item_next(mcep))
    {
        if (voiced_frame(mcep))
        {
            /* scale the F0 -- which normally wont change it at all */
            param_track->frames[i][0] = 
                (((param_track->frames[i][0]-cg_db->f0_mean)/cg_db->f0_stddev) 
                 *stddev)+mean;
            /* Some safety checks */
            if (param_track->frames[i][0] < 50)
                param_track->frames[i][0] = 50;
            if (param_track->frames[i][0] > 700)
                param_track->frames[i][0] = 700;
        }
        else /* Unvoice it */
            param_track->frames[i][0] = 0.0;
    }

    return;
}
Пример #27
0
static void apostrophe_s(cst_utterance *u)
{
    cst_item *s;
    cst_item *schwa;
    const cst_phoneset *ps = u->vox->phoneset;
    const char *pname, *word;

    for (s=item_next(UTT_REL_HEAD(u,SEGMENT));
	 s;
         s=item_next(s))
    {
	word = val_string(ffeature(s, "R:"SYLSTRUCTURE".P.P.name"));
	if (cst_streq("'s", word))
	{
	    pname = item_feat_string(item_prev(s),"name");
	    if ((strchr("fa",*phone_feature_string(ps,pname,"ctype")) != NULL)
		&& (strchr("dbg",
			   *phone_feature_string(ps,pname,"cplace")) == NULL))
		/* needs a schwa */
	    {
		schwa = item_prepend(s,NULL);
		item_set_string(schwa,"name","ax");
		item_prepend(item_as(s,SYLSTRUCTURE),schwa);
	    }
	    else if (cst_streq("-",phone_feature_string(ps,pname,"cvox")))
		item_set_string(s,"name","s");
	}
	else if (cst_streq("'ve", word)
		 || cst_streq("'ll", word)
		 || cst_streq("'d", word))
	{
	    if (cst_streq("-",ffeature_string(s,"p."PH_VC)))
	    {
		schwa = item_prepend(s,NULL);
		item_set_string(schwa,"name","ax");
		item_prepend(item_as(s,SYLSTRUCTURE),schwa);
	    }
	}
    }

}
Пример #28
0
static int vowel_seg_between(const cst_item *f,const cst_item *l)
{
  const cst_item *s;
  for(s=f;s;s=item_next(s))
    {
      if(is_vowel(item_feat_string(s,"name")))
        return TRUE;
      if(item_equal(s,l))
        break;
    }
  return FALSE;
}
Пример #29
0
/*
 * Creates a new queue with a copy of the items of the given queue.
 *
 * The given number of items (count) are copied from the play-queue (shuffle = 0) or shuffle-queue (shuffle = 1)
 * starting with the item at the given index (0-based).
 *
 * If count == 0, all items from the given index up to the end of the queue will be returned.
 *
 * @param queue   The queue
 * @param index   Index of the first item in the queue
 * @param count   Maximum number of items to copy (if 0 all remaining items after index)
 * @param shuffle If 0 the play-queue, if 1 the shuffle queue
 * @return A new queue with the specified items
 */
struct queue *
queue_new_byindex(struct queue *queue, unsigned int index, unsigned int count, char shuffle)
{
  struct queue *qi;
  struct queue_item *qii;
  struct queue_item *item;
  int i;
  unsigned int qlength;
  int qii_size;

  qi = queue_new();

  qlength = queue_count(queue);

  qii_size = qlength - index;
  if (count > 0 && count < qii_size)
    qii_size = count;

  if (qii_size <= 0)
    {
      return qi;
    }

  item = queueitem_get_byindex(queue, index, shuffle);

  if (!item)
    return NULL;

  i = 0;
  for (; item != queue->head && i < qii_size; item = item_next(item, shuffle))
    {
      qii = malloc(sizeof(struct queue_item));
      qii->id = item->id;
      qii->item_id = item->item_id;
      qii->len_ms = item->len_ms;
      qii->data_kind = item->data_kind;
      qii->media_kind = item->media_kind;
      qii->next = qii;
      qii->prev = qii;
      qii->shuffle_next = qii;
      qii->shuffle_prev = qii;

      queue_add(qi, qii);

      // queue_add(...) changes the queue item-id, reset the item-id to the original value
      qii->item_id = item->item_id;

      i++;
    }

  return qi;
}
Пример #30
0
static const cst_val *ssyl_out(const cst_item *syl)
{
    /* Number of stressed syllables until last major break */
    const cst_item *ss,*p,*fs;
    int c;

    ss = item_as(syl,"Syllable");

    fs = path_to_item(syl,"R:SylStructure.parent.R:Phrase.parent.daughtern.R:SylStructure.daughtern");

    for (c=0, p=item_next(ss); 
	 p && (c < CST_CONST_INT_MAX); 
	 p=item_next(p))
    {
	if (cst_streq("1",item_feat_string(p,"stress")))
	    c++;
	if (item_equal(p,fs))
	    break;
    }
    
    return val_string_n(c);  /* its used randomly as int and float */
}