1 /***************************************************************************
2  *   Copyright (C) 2005 to 2010 by Jonathan Duddington                     *
3  *   email: jonsd@users.sourceforge.net                                    *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 3 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, see:                                 *
17  *               <http://www.gnu.org/licenses/>.                           *
18  ***************************************************************************/
19 
20 
21 
22 // phoneme types
23 #define phPAUSE   0
24 #define phSTRESS  1
25 #define phVOWEL   2
26 #define phLIQUID  3
27 #define phSTOP    4
28 #define phVSTOP   5
29 #define phFRICATIVE 6
30 #define phVFRICATIVE 7
31 #define phNASAL   8
32 #define phVIRTUAL 9
33 #define phDELETED 14
34 #define phINVALID 15
35 
36 
37 // phoneme properties
38 //   bits 16-19 give place of articulation
39 #define phARTICULATION 0xf0000
40 #define phWAVE     0x01
41 #define phUNSTRESSED 0x02
42 #define phFORTIS   0x08
43 #define phVOICED   0x10
44 #define phSIBILANT 0x20
45 #define phNOLINK   0x40
46 #define phTRILL    0x80
47 #define phVOWEL2   0x100   // liquid that is considered a vowel
48 #define phPALATAL  0x200
49 #define phSINGLE_INSTN  0x1000    // this phoneme has a single instruction program, with an implicit Return
50 #define phBRKAFTER 0x4000  // [*] add a post-pause
51 
52 #define phNONSYLLABIC  0x100000   // don't count this vowel as a syllable when finding the stress position
53 #define phLONG         0x200000
54 #define phLENGTHENSTOP 0x400000  // make the pre-pause slightly longer
55 #define phRHOTIC       0x800000  // bit 23
56 #define phNOPAUSE     0x1000000
57 #define phPREVOICE    0x2000000  // for voiced stops
58 
59 #define phFLAG1      0x10000000
60 #define phFLAG2      0x20000000
61 #define phFLAG3      0x40000000
62 #define phLOCAL      0x80000000  // used during compilation
63 
64 // fixed phoneme code numbers, these can be used from the program code
65 #define phonCONTROL     1
66 #define phonSTRESS_U    2
67 #define phonSTRESS_D    3
68 #define phonSTRESS_2    4
69 #define phonSTRESS_3    5
70 #define phonSTRESS_P    6
71 #define phonSTRESS_P2   7    // priority stress within a word
72 #define phonSTRESS_PREV 8
73 #define phonPAUSE       9
74 #define phonPAUSE_SHORT 10
75 #define phonPAUSE_NOLINK 11
76 #define phonLENGTHEN    12
77 #define phonSCHWA       13
78 #define phonSCHWA_SHORT 14
79 #define phonEND_WORD    15
80 #define phonDEFAULTTONE 17
81 #define phonCAPITAL     18
82 #define phonGLOTTALSTOP 19
83 #define phonSYLLABIC    20
84 #define phonSWITCH      21
85 #define phonX1          22      // a language specific action
86 #define phonPAUSE_VSHORT 23
87 #define phonPAUSE_LONG  24
88 #define phonT_REDUCED   25
89 #define phonSTRESS_TONIC 26
90 #define phonPAUSE_CLAUSE 27
91 #define phonVOWELTYPES   28  // 28 to 33
92 
93 extern const unsigned char pause_phonemes[8];  // 0, vshort, short, pause, long, glottalstop
94 
95 // place of articulation
96 #define phPLACE        0xf0000
97 #define phPLACE_blb    0x10000
98 #define phPLACE_pla    0x60000
99 
100 #define N_PHONEME_TABS     100     // number of phoneme tables
101 #define N_PHONEME_TAB      256     // max phonemes in a phoneme table
102 #define N_PHONEME_TAB_NAME  32     // must be multiple of 4
103 
104 // main table of phonemes, index by phoneme number (1-254)
105 
106 typedef struct {
107 	unsigned int  mnemonic;      // Up to 4 characters.  The first char is in the l.s.byte
108 	unsigned int  phflags;       // bits 16-19 place of articulation
109 	unsigned short program;      // index into phondata file
110 	unsigned char  code;         // the phoneme number
111 	unsigned char  type;         // phVOWEL, phPAUSE, phSTOP etc
112 	unsigned char  start_type;
113 	unsigned char  end_type;
114 	unsigned char  std_length;   // for vowels, in mS/2;  for phSTRESS phonemes, this is the stress/tone type
115 	unsigned char  length_mod;   // a length_mod group number, used to access length_mod_tab
116 
117 } PHONEME_TAB;
118 
119 
120 
121 // Several phoneme tables may be loaded into memory. phoneme_tab points to
122 // one for the current voice
123 extern int n_phoneme_tab;
124 extern int current_phoneme_table;
125 extern PHONEME_TAB *phoneme_tab[N_PHONEME_TAB];
126 extern unsigned char phoneme_tab_flags[N_PHONEME_TAB];  // bit 0: not inherited
127 
128 typedef struct {
129 	char name[N_PHONEME_TAB_NAME];
130 	PHONEME_TAB *phoneme_tab_ptr;
131 	int n_phonemes;
132 	int includes;            // also include the phonemes from this other phoneme table
133 	int equivalence_tables;   // lists of equivalent phonemes to match other languages, byte index into phondata
134 } PHONEME_TAB_LIST;
135 
136 
137 
138 // table of phonemes to be replaced with different phonemes, for the current voice
139 #define N_REPLACE_PHONEMES   60
140 typedef struct {
141 	unsigned char old_ph;
142 	unsigned char new_ph;
143 	char type;   // 0=always replace, 1=only at end of word
144 } REPLACE_PHONEMES;
145 
146 extern int n_replace_phonemes;
147 extern REPLACE_PHONEMES replace_phonemes[N_REPLACE_PHONEMES];
148 
149 
150 // Table of phoneme programs and lengths.  Used by MakeVowelLists
151 typedef struct {
152 	unsigned int addr;
153 	unsigned int length;
154 } PHONEME_PROG_LOG;
155 
156 
157 
158 #define PH(c1,c2)  (c2<<8)+c1          // combine two characters into an integer for phoneme name
159 #define PH3(c1,c2,c3) (c3<<16)+(c2<<8)+c1
160 #define PhonemeCode2(c1,c2)  PhonemeCode((c2<<8)+c1)
161 int LookupPhonemeString(const char *string);
162 int PhonemeCode(unsigned int mnem);
163 
164 const char *EncodePhonemes(const char *p, char *outptr, int *bad_phoneme);
165 void DecodePhonemes(const char *inptr, char *outptr);
166 
167 extern const char *WordToString(unsigned int word);
168 
169 extern PHONEME_TAB_LIST phoneme_tab_list[N_PHONEME_TABS];
170 extern int phoneme_tab_number;
171