1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/*
Copyright (C) 1995, Steve Isard, Alistair Conkie
You may distribute under the terms of the GNU General Public
Licence as specified in the README file.
*/
#include "t2s.h"
#ifdef FREEPHONE_OBSOLETE
static void transmogrify(CONFIG *config, char *s, SPN *ps)
{
char *phon;
char *durword;
float durfloat;
char *targ_spec;
int freq,perc;
phon = strtok(s," \t");
strcpy(ps->phons[ps->p_sz],phon);
durword = strtok(NULL," \t");
sscanf(durword,"%f",&durfloat);
if(((durfloat < 20) || ( durfloat > 400)) && strcmp(phon,"#")) {
fprintf(stderr,"Unusual duration %dmS for phoneme %s\n",(int)durfloat,phon);
}
ps->duration[ps->p_sz] = (int)((config->sr/1000)*durfloat); /* durations are stored as samples */
while((targ_spec = strtok(NULL," \t"))!=NULL) {
sscanf(targ_spec," %*c%d%*c%d%*c",&perc,&freq);
ps->pc_targs[ps->t_sz] = perc;
ps->targ_freq[ps->t_sz] = freq;
ps->targ_phon[ps->t_sz] = ps->p_sz;
ps->t_sz++;
}
ps->p_sz++; /* must come after copying of freq. info */
if(!ps->t_sz)
fprintf(stderr,"No frequency specified, using default\n");
}
#endif
export void put_mbrola_data(CONFIG *config, SPN *ps)
{
int i;
int dur;
int j = 0; /* pointer to where in targets */
char *converted_phon;
PKEY *ptmp;
for(i=0;i<ps->p_sz;i++) {
dur = ps->duration[i]/10.0;
if((ptmp=pbinary(ps->phons[i],edin2sampa0,config->edin2sampa0_num))!=NULL) {
converted_phon = ptmp->keyvalue;
} else {
converted_phon = "_";
fprintf(stderr,"Unrecognized phoneme: %s\n",ps->phons[i]);
}
fprintf(config->ofd,"%s\t%d",converted_phon,dur);
while(i == ps->targ_phon[j]) {
fprintf(config->ofd,"\t%d %d",ps->pc_targs[j],ps->targ_freq[j]);
j++;
}
fprintf(config->ofd,"\n");
}
fprintf(config->ofd,"#\n");
fflush(config->ofd);
}
#ifdef FREEPHONE_OBSOLETE
export void put_spn_data(CONFIG *config, SPN *ps)
{
int i;
int dur;
int j = 0; /* pointer to where in targets */
for(i=0;i<ps->p_sz;i++) {
dur = ps->duration[i]/10.0;
fprintf(config->ofd,"%s\t%d",ps->phons[i],dur);
while(i == ps->targ_phon[j]) {
fprintf(config->ofd,"\t(%d,%d)",ps->pc_targs[j],ps->targ_freq[j]);
j++;
}
fprintf(config->ofd,"\n");
}
}
export void get_spn_data(CONFIG *config, SPN *ps)
{
char s[100];
int lineno=1;
ps->p_sz = 0; /* actually set in the mallocing too */
ps->t_sz = 0;
while(fgets(s,100,config->ifd)) {
s[99] = '\0';
if(!strcmp(s,"\n")) {
return;
}
if(strlen(s) == 99) {
fprintf(stderr,"Possibly malformed .spn input file, line %d\n",lineno);
}
transmogrify(config,s,ps);
if(ps->p_sz>=ps->p_max) {
ps_realloc(ps->p_max*2,ps->t_max,ps);
}
if(ps->t_sz>=ps->t_max) {
ps_realloc(ps->p_max,ps->t_max*2,ps);
}
lineno++;
}
/* perhaps we should close the file ?? */
}
#endif
|