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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
#include <config.h>
/* $Id: phtoelm.c,v 1.13 1994/11/08 13:30:50 a904209 Exp a904209 $
*/
char *phtoelm_id = "$Id: phtoelm.c,v 1.13 1994/11/08 13:30:50 a904209 Exp a904209 $";
#include <stdio.h>
#include <ctype.h>
#if defined (__STDC__)
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include <useconfig.h>
#include "proto.h"
#include "elements.h"
#include "phfeat.h"
#include "darray.h"
#include "trie.h"
#include "phtoelm.h"
#include "hplay.h"
#include "holmes.h"
#include "nsynth.h"
trie_ptr phtoelm = NULL;
static Elm_ptr find_elm PROTO((char *s));
static Elm_ptr
find_elm(s)
char *s;
{
Elm_ptr e = Elements;
while (e < Elements + num_Elements)
{
if (!strcmp(s, e->name))
{
return e;
}
e++;
}
return NULL;
}
#if defined (__STDC__)
static void
enter(char *p,...)
#else
static void
enter(p, va_alist)
char *p;
va_dcl
#endif
{
va_list ap;
char *s;
char buf[20];
char *x = buf + 1;
#if defined(__STDC__)
va_start(ap, p);
#else
va_start(ap);
#endif
while ((s = va_arg(ap, char *)))
{
Elm_ptr e = find_elm(s);
if (e)
*x++ = (e - Elements);
else
{
fprintf(stderr, "Cannot find %s\n", s);
}
}
va_end(ap);
buf[0] = (x - buf) - 1;
x = malloc(buf[0] + 1);
memcpy(x, buf, buf[0] + 1);
trie_insert(&phtoelm, p, x);
}
static void enter_phonemes
PROTO((void))
{
#include "phtoelm.def"
}
int
phone_append(p, ch)
darray_ptr p;
int ch;
{
char *s = (char *) darray_find(p, p->items);
*s = ch;
return ch;
}
#if 0
#define StressDur(e,s) ((e->ud + (e->du - e->ud) * s / 3)*speed)
#else
#define StressDur(e,s) (s,((e->du + e->ud)/2)*speed)
#endif
unsigned
phone_to_elm(phone, n, elm)
char *phone;
int n;
darray_ptr elm;
{
int stress = 0;
char *s = phone;
unsigned t = 0;
char *limit = s + n;
if (!phtoelm)
enter_phonemes();
while (s < limit && *s)
{
char *e = trie_lookup(&phtoelm, &s);
if (e)
{
int n = *e++;
while (n-- > 0)
{
int x = *e++;
Elm_ptr p = &Elements[x];
/* This works because only vowels have ud != du,
and we set stress just before a vowel
*/
phone_append(elm, x);
if (!(p->feat & vwl))
stress = 0;
t += phone_append(elm,StressDur(p,stress));
phone_append(elm, stress);
}
}
else
{
char ch = *s++;
switch (ch)
{
case '\'': /* Primary stress */
stress = 3;
break;
case ',': /* Secondary stress */
stress = 2;
break;
case '+': /* Tertiary stress */
stress = 1;
break;
case '-': /* hyphen in input */
break;
default:
fprintf(stderr, "Ignoring %c in '%.*s'\n", ch, n, phone);
break;
}
}
}
return t;
}
|