• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /**
17  * @file picodata.h
18  *
19  * Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland
20  * All rights reserved.
21  *
22  * History:
23  * - 2009-04-20 -- initial version
24  *
25  */
26 #ifndef PICODATA_H_
27 #define PICODATA_H_
28 
29 #include "picodefs.h"
30 #include "picoos.h"
31 #include "picotrns.h"
32 #include "picokfst.h"
33 #include "picorsrc.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 #if 0
39 }
40 #endif
41 
42 
43 /* ***************************************************************
44  *                   Constants                                   *
45  *****************************************************************/
46 
47 #define PICODATA_MAX_ITEMS_PER_PHRASE 30
48 
49 /**
50  * @addtogroup picodata
51  * <b> Pico Data : Item Format </b>\n
52  *
53   The item header is identical for all item types and PUs. Item types
54  that are not handled by a PU are copied.
55 
56  Item Header structure\n
57  ---------------------
58    - Byte     Content
59    - 0x00     item type
60    - 0x01     item info 1
61    - 0x02     item info 2
62    - 0x03     item length in bytes (not including the header)
63 
64  depending on the item type/info, a specific subheader may follow
65  (included in length)
66 */
67 
68 /* item header fields (tmp.: use item functions below to acces header fields */
69 #define PICODATA_ITEMIND_TYPE  0
70 #define PICODATA_ITEMIND_INFO1 1
71 #define PICODATA_ITEMIND_INFO2 2
72 #define PICODATA_ITEMIND_LEN   3
73 
74 /* ***************************************************************
75  *                   CharBuffer                                  *
76  *****************************************************************/
77 typedef struct picodata_char_buffer * picodata_CharBuffer;
78 
79 picodata_CharBuffer picodata_newCharBuffer(picoos_MemoryManager mm,
80         picoos_Common common, picoos_objsize_t size);
81 
82 void picodata_disposeCharBuffer(picoos_MemoryManager mm,
83                                 picodata_CharBuffer * this);
84 
85 /* should not be used for PUs but only for feeding the initial cb */
86 pico_status_t picodata_cbPutCh(register picodata_CharBuffer this, picoos_char ch);
87 
88 /* should not be used for PUs other than first PU in the chain (picotok) */
89 picoos_int16 picodata_cbGetCh(register picodata_CharBuffer this);
90 
91 /* reset cb (as if after newCharBuffer) */
92 pico_status_t picodata_cbReset (register picodata_CharBuffer this);
93 
94 /* ** CharBuffer item functions, cf. below in items section ****/
95 
96 /* ***************************************************************
97  *                   items                                       *
98  *****************************************************************/
99 
100 /* item header size */
101 #define PICODATA_ITEM_HEADSIZE 4
102 
103 typedef struct picodata_itemhead
104 {
105     picoos_uint8 type;
106     picoos_uint8 info1;
107     picoos_uint8 info2;
108     picoos_uint8 len;
109 } picodata_itemhead_t;
110 
111 
112 /* -------------- System wide defines referred to by items -------- */
113 /* ---- These maybe better stored in a knowledge module/resoruce*/
114 #define PICODATA_ACC0  '\x30' /*  48  '0' */
115 #define PICODATA_ACC1  '\x31' /*  49  '1' */
116 #define PICODATA_ACC2  '\x32' /*  50  '2' */
117 #define PICODATA_ACC3  '\x33' /*  51  '3' */
118 #define PICODATA_ACC4  '\x34' /*  52  '4' */
119 
120 /* reserved for future use:
121  * user-imposed Part-Of-Speech ids for user lexica and phoneme tags
122  * These values should be applied BEFORE POS-disambiguation. The POS lingware either assigns the same
123  * ids to corresponding internal unique or composed POS or else the POS-D will consider these values
124  * "default" */
125 #define PICODATA_POS_XNPR 20
126 #define PICODATA_POS_XN   21
127 #define PICODATA_POS_XV   22
128 #define PICODATA_POS_XA   23
129 #define PICODATA_POS_XADV 24
130 #define PICODATA_POS_XX   25
131 
132 /* ------------------------- item types ---------------------------- */
133 /* new item types, info1, info2 to be defined during PU development  */
134 /* make sure this stays in sync with "is_valid_itemtype" function    */
135 #define PICODATA_ITEM_WSEQ_GRAPH '\x73'  /* 115, 's' */
136 #define PICODATA_ITEM_TOKEN      '\x74'  /* 116  't' */
137 #define PICODATA_ITEM_WORDGRAPH  '\x67'  /* 103  'g' */
138 #define PICODATA_ITEM_WORDINDEX  '\x69'  /* 105  'i' */
139 #define PICODATA_ITEM_WORDPHON   '\x77'  /* 119  'w' */
140 #define PICODATA_ITEM_SYLLPHON   '\x79'  /* 121  'y' */
141 #define PICODATA_ITEM_BOUND      '\x62'  /*  98  'b' */
142 /* #define PICODATA_ITEM_BOUND_DUR  '\x64' */ /* 100  'd' */ /* duration-constrained bound */
143 #define PICODATA_ITEM_PUNC       '\x70'  /* 112  'p' */
144 #define PICODATA_ITEM_CMD        '\x63'  /*  99  'c' */
145 #define PICODATA_ITEM_PHONE      '\x68'  /* 104  'h' */ /*reserved for PAM*/
146 #define PICODATA_ITEM_FRAME_PAR  '\x6b'  /* 107  'k' */ /*reserved for CEP*/
147 #define PICODATA_ITEM_FRAME      '\x66'  /* 102  'f' */ /*reserved for SIG*/
148 #define PICODATA_ITEM_OTHER      '\x6f'  /* 111  'o' */
149 #define PICODATA_ITEM_ERR        '\x00'  /*   0 '^@' */
150 
151 /* generic iteminfo1 */
152 #define PICODATA_ITEMINFO1_ERR   '\x00'  /*   0 '^@' */  /* error state */
153 #define PICODATA_ITEMINFO1_NA    '\x01'  /*   1 '^A' */  /* not applicable */
154 
155 /* generic iteminfo2 */
156 #define PICODATA_ITEMINFO2_ERR   '\x00'  /*   0 '^@' */ /* error state */
157 #define PICODATA_ITEMINFO2_NA    '\x01'  /*   1 '^A' */ /* not applicable */
158 
159 /* ------------------------- PUNC item type ---------------------------- */
160 /* iteminfo1 */
161 #define PICODATA_ITEMINFO1_PUNC_SENTEND       '\x73'  /* 115  's' */
162 #define PICODATA_ITEMINFO1_PUNC_PHRASEEND     '\x70'  /* 112  'p' */
163 #define PICODATA_ITEMINFO1_PUNC_FLUSH         '\x66'  /* 102  'f' */
164 /* iteminfo2 */
165 #define PICODATA_ITEMINFO2_PUNC_SENT_T        '\x74'  /* 116  't' */
166 #define PICODATA_ITEMINFO2_PUNC_SENT_Q        '\x71'  /* 113  'q' */
167 #define PICODATA_ITEMINFO2_PUNC_SENT_E        '\x65'  /* 101  'e' */
168 #define PICODATA_ITEMINFO2_PUNC_PHRASE        '\x70'  /* 112  'p' */
169 #define PICODATA_ITEMINFO2_PUNC_PHRASE_FORCED '\x66'  /* 102  'f' */
170 /* len for PUNC item is ALWAYS = 0 */
171 /* ------------------------- BOUND item type ---------------------------- */
172 /* iteminfo1 : phrase strength*/
173 #define PICODATA_ITEMINFO1_BOUND_SBEG  '\x62'  /*  98 'b', at sentence begin */
174 #define PICODATA_ITEMINFO1_BOUND_SEND  '\x73'  /* 115 's', at sentence end */
175 #define PICODATA_ITEMINFO1_BOUND_TERM  '\x74'  /* 116 't', replaces a flush */
176 #define PICODATA_ITEMINFO1_BOUND_PHR0  '\x30'  /*  48 '0', no break, no item */
177 #define PICODATA_ITEMINFO1_BOUND_PHR1  '\x31'  /*  49 '1', pri. phrase bound. */
178 #define PICODATA_ITEMINFO1_BOUND_PHR2  '\x32'  /*  50 '2', short break */
179 #define PICODATA_ITEMINFO1_BOUND_PHR3  '\x33'  /*  51 '3', sec. phr. bound., no break*/
180 /* iteminfo2 : phrase type*/
181 #define PICODATA_ITEMINFO2_BOUNDTYPE_P '\x50'  /*  80 'P' */
182 #define PICODATA_ITEMINFO2_BOUNDTYPE_T '\x54'  /*  84 'T' */
183 #define PICODATA_ITEMINFO2_BOUNDTYPE_Q '\x51'  /*  81 'Q' */
184 #define PICODATA_ITEMINFO2_BOUNDTYPE_E '\x45'  /*  69 'E' */
185 /* len for BOUND item is ALWAYS = 0 */
186 /* ------------------------- CMD item type ---------------------------- */
187 /* iteminfo1 */
188 #define PICODATA_ITEMINFO1_CMD_FLUSH          'f' /* 102 flush command (all PUs)*/
189 #define PICODATA_ITEMINFO1_CMD_PLAY           'p' /* 112 play command : PU in info 2 will read items from file-->Filename in item content.*/
190 #define PICODATA_ITEMINFO1_CMD_SAVE           's' /* 115 save command : PU in info 2 will save items to file-->Filename in item content.*/
191 #define PICODATA_ITEMINFO1_CMD_UNSAVE         'u' /* 117 save command : PU in info 2 will stop saving items to file*/
192 #define PICODATA_ITEMINFO1_CMD_PROSDOMAIN     'd' /* 100 prosody domain : domain type in info 2, domain name in item content */
193 #define PICODATA_ITEMINFO1_CMD_SPELL          'e' /* 101 spell command : info 2 contains start/stop info,
194                                                     spell type/pause len as little endian uint16 in item content */
195 #define PICODATA_ITEMINFO1_CMD_IGNSIG         'i' /* ignore signal command : info 2 contains start/stop info */
196 #define PICODATA_ITEMINFO1_CMD_PHONEME        'o' /* phoneme command : info 2 contains start/stop info, phonemes in item content */
197 #define PICODATA_ITEMINFO1_CMD_IGNORE         'I' /* ignore text command : info 2 contains start/stop info */
198 #define PICODATA_ITEMINFO1_CMD_SIL            'z' /* silence command : info 2 contains type of silence;
199                                                      silence duration as little endian uint16 in item content */
200 #define PICODATA_ITEMINFO1_CMD_CONTEXT        'c' /* context command : context name in item content */
201 #define PICODATA_ITEMINFO1_CMD_VOICE          'v' /* context command : voice name in item content */
202 #define PICODATA_ITEMINFO1_CMD_MARKER         'm' /* marker command : marker name in item content */
203 #define PICODATA_ITEMINFO1_CMD_PITCH          'P' /* 80 pitch command : abs/rel info in info 2; pitch level as little endian
204                                                      uint16 in item content; relative value is in promille */
205 #define PICODATA_ITEMINFO1_CMD_SPEED          'R' /* 82 speed command : abs/rel info in info 2, speed level as little endian
206                                                      uint16 in item content; elative value is in promille */
207 #define PICODATA_ITEMINFO1_CMD_VOLUME         'V' /* 86 volume command : abs/rel info in info 2, volume level as little endian
208                                                      uint16 in item content; relative value is in promille */
209 #define PICODATA_ITEMINFO1_CMD_SPEAKER        'S' /* 83 speaker command : abs/rel info in info 2, speaker level as little endian
210                                                      uint16 in item content; relative value is in promille */
211 
212 /* iteminfo2 for PLAY/SAVE */
213 #define PICODATA_ITEMINFO2_CMD_TO_TOK  't'  /* CMD+PLAY/SAVE+TOKENISATION*/
214 #define PICODATA_ITEMINFO2_CMD_TO_PR   'g'  /* CMD+PLAY/SAVE+PREPROC*/
215 #define PICODATA_ITEMINFO2_CMD_TO_WA   'w'  /* CMD+PLAY/SAVE+WORDANA*/
216 #define PICODATA_ITEMINFO2_CMD_TO_SA   'a'  /* CMD+PLAY/SAVE+SENTANA*/
217 #define PICODATA_ITEMINFO2_CMD_TO_ACPH 'h'  /* CMD+PLAY/SAVE+ACCENTUATION&PHRASING*/
218 #define PICODATA_ITEMINFO2_CMD_TO_SPHO 'p'  /* CMD+PLAY/SAVE+ACCENTUATION&PHRASING*/
219 #define PICODATA_ITEMINFO2_CMD_TO_PAM  'q'  /* CMD+PLAY/SAVE+PHONETIC-ACOUSTIC MAPPING*/
220 #define PICODATA_ITEMINFO2_CMD_TO_CEP  'c'  /* CMD+PLAY/SAVE+CEP_SMOOTHER*/
221 #define PICODATA_ITEMINFO2_CMD_TO_SIG  's'  /* CMD+PLAY/SAVE+SIG_GEN */
222 
223 #if 0
224 #define PICODATA_ITEMINFO2_CMD_TO_FST  'f'  /* CMD+PLAY/SAVE+FST for Syll and Phonotactic constraints*/
225 #endif
226 
227 #define PICODATA_ITEMINFO2_CMD_TO_UNKNOWN 255
228 
229 /* iteminfo2 for start/end commands */
230 #define PICODATA_ITEMINFO2_CMD_START  's'
231 #define PICODATA_ITEMINFO2_CMD_END    'e'
232 
233 /* iteminfo2 for speed/pitch/volume commands */
234 #define PICODATA_ITEMINFO2_CMD_ABSOLUTE 'a'
235 #define PICODATA_ITEMINFO2_CMD_RELATIVE 'r'
236 
237 /* len for CMD item could be >= 0 */
238 /* ------------------------- TOKEN item type ---------------------------- */
239 /* iteminfo1: simple token type : */
240 #define PICODATA_ITEMINFO1_TOKTYPE_SPACE     'W'
241 #define PICODATA_ITEMINFO1_TOKTYPE_LETTERV   'V'
242 #define PICODATA_ITEMINFO1_TOKTYPE_LETTER    'L'
243 #define PICODATA_ITEMINFO1_TOKTYPE_DIGIT     'D'
244 #define PICODATA_ITEMINFO1_TOKTYPE_SEQ       'S'
245 #define PICODATA_ITEMINFO1_TOKTYPE_CHAR      'C'
246 #define PICODATA_ITEMINFO1_TOKTYPE_BEGIN     'B'
247 #define PICODATA_ITEMINFO1_TOKTYPE_END       'E'
248 #define PICODATA_ITEMINFO1_TOKTYPE_UNDEFINED 'U'
249 /* iteminfo2 : token subtype */
250 /* len for WORDTOK item is ALWAYS > 0, if len==0 an error should be raised */
251 
252 /**
253  * @addtogroup picodata
254  *
255  * ------------------------- WORDGRAPH item type ----------------------------
256  * - iteminfo1 : POS and multi-POS values defined in lingware
257  * - iteminfo2 : not applicable
258  * - len for WORDGRAPH item is ALWAYS > 0, if len==0 an error should be raised
259  *     (currently picopr may produce empty WORDGRAPH that is eliminated by picowa)
260  * \n------------------------- WORDINDEX item type ----------------------------
261  * - iteminfo1 : POS and multi-POS values defined in lingware
262  * - iteminfo2 : not applicable
263  * - len for WORDINDEX item is ALWAYS > 0, if len==0 an error should be raised
264  * \n------------------------- WORDPHON item type ----------------------------
265  * - iteminfo1 : POS values defined in lingware
266  * - iteminfo2 : Uses PICODATA_ACC0 .. ACC4
267  *  -len WORDPHON item is ALWAYS > 0, if len==0 an error should be raised
268  * \n------------------------- SYLLPHON item type ----------------------------
269  * - iteminfo1 : not applicable
270  * - iteminfo2 : Uses PICODATA_ACC0 .. ACC4
271  * - len for SYLLPHON item is ALWAYS > 0, if len==0 an error should be raised
272  * \n------------------------- PHONE item type (PRODUCED BY PAM)-----------------
273  * - iteminfo1 : phonId : the phonetic identity of the phone
274  * - iteminfo2 : n_S_P_Phone : number of states per phoneme
275  * - len for PHON item is ALWAYS > 0, if len==0 an error should be raised
276  * \n------------------------- FRAME_PAR item type (PRODUCED BY CEP) --------
277  * - iteminfo1 : format (float, fixed)
278  * - iteminfo2 : vector size
279  * - len for FRAME_PAR item is ALWAYS > 0, if len==0 an error should be raised
280  * \n------------------------- FRAME  item type (PRODUCED BY SIG) -----------
281  * - iteminfo1 : number of samples per frame
282  * - iteminfo2 : number of bytes per sample
283  * - len for FRAME item is ALWAYS > 0, if len==0 an error should be raised
284  *
285  */
286 #define PICODATA_ITEMINFO1_FRAME_PAR_DATA_FORMAT_FIXED  '\x78' /* 120 'x' fixed point */
287 #define PICODATA_ITEMINFO1_FRAME_PAR_DATA_FORMAT_FLOAT  '\x66' /* 102 'f' floating point */
288 
289 /* ***************************************************************
290  *                   items: CharBuffer functions                 *
291  *****************************************************************/
292 
293 /* gets a single item (head and content) from a CharBuffer in buf;
294    blenmax is the max length (in number of bytes) of buf; blen is
295    set to the number of bytes gotten in buf; return values:
296      PICO_OK                 <- one item gotten
297      PICO_EOF                <- no item available, cb is empty
298      PICO_EXC_BUF_UNDERFLOW  <- cb not empty, but no valid item
299      PICO_EXC_BUF_OVERFLOW   <- buf not large enough
300 */
301 pico_status_t picodata_cbGetItem(register picodata_CharBuffer this,
302         picoos_uint8 *buf, const picoos_uint16 blenmax,
303         picoos_uint16 *blen);
304 
305 /* gets the speech data (without item head) from a CharBuffer in buf;
306    blenmax is the max length (in number of bytes) of buf; blen is
307    set to the number of bytes gotten in buf; return values:
308      PICO_OK                 <- speech data of one item gotten
309      PICO_EOF                <- no item available, cb is empty
310      PICO_EXC_BUF_UNDERFLOW  <- cb not empty, but no valid item
311      PICO_EXC_BUF_OVERFLOW   <- buf not large enough
312 */
313 pico_status_t picodata_cbGetSpeechData(register picodata_CharBuffer this,
314         picoos_uint8 *buf, const picoos_uint16 blenmax,
315         picoos_uint16 *blen);
316 
317 /* puts a single item (head and content) to a CharBuffer; clenmax is
318    the max length (in number of bytes) accessible in content; clen is
319    set to the number of bytes put from content; return values:
320      PICO_OK                 <- one item put
321      PICO_EXC_BUF_UNDERFLOW  <- no valid item in buf
322      PICO_EXC_BUF_OVERFLOW   <- cb not large enough
323 */
324 pico_status_t picodata_cbPutItem(register picodata_CharBuffer this,
325         const picoos_uint8 *buf, const picoos_uint16 blenmax,
326         picoos_uint16 *blen);
327 
328 /* unsafe, just for measuring purposes */
329 picoos_uint8 picodata_cbGetFrontItemType(register picodata_CharBuffer this);
330 
331 /* ***************************************************************
332  *                   items: support function                     *
333  *****************************************************************/
334 
335 /* checks, whether item of type 'ch' is a valid item type */
336 picoos_uint8 is_valid_itemtype(const picoos_uint8 ch);
337 
338 /* gets from buf a single item, values in head set and item content
339    copied to content; blenmax and clenmax are the max lengths (in
340    number of bytes) accessible in buf and content; clen is set to the
341    number of bytes gotten in content; return values:
342      PICO_OK                 <- all ok
343      PICO_EXC_BUF_UNDERFLOW  <- blenmax problem, or no valid item
344      PICO_EXC_BUF_OVERFLOW   <- overflow in content
345 */
346 pico_status_t picodata_get_itemparts_nowarn(
347         const picoos_uint8 *buf, const picoos_uint16 blenmax,
348         picodata_itemhead_t *head, picoos_uint8 *content,
349         const picoos_uint16 clenmax, picoos_uint16 *clen);
350 
351 /* gets from buf a single item, values in head set and item content
352    copied to content; blenmax and clenmax are the max lengths (in
353    number of bytes) accessible in buf and content; clen is set to the
354    number of bytes gotten in content; return values:
355      PICO_OK                 <- all ok
356      PICO_EXC_BUF_UNDERFLOW  <- blenmax problem, or no valid item
357      PICO_EXC_BUF_OVERFLOW   <- overflow in content
358 */
359 pico_status_t picodata_get_itemparts(
360         const picoos_uint8 *buf, const picoos_uint16 blenmax,
361         picodata_itemhead_t *head, picoos_uint8 *content,
362         const picoos_uint16 clenmax, picoos_uint16 *clen);
363 
364 /* puts a single item to buf; values in head and content copied to
365    buf; clenmax is the max length (in number of bytes) accessible in
366    content; blenmax is the max length (bytes) accessible in buf; blen
367    is set to the number of bytes put to buf; return values:
368      PICO_OK                 <- all ok
369      PICO_EXC_BUF_UNDERFLOW  <- clenmax problem, or no valid item
370      PICO_EXC_BUF_OVERFLOW   <- overflow in buf
371 */
372 pico_status_t picodata_put_itemparts(const picodata_itemhead_t *head,
373         const picoos_uint8 *content, const picoos_uint16 clenmax,
374         picoos_uint8 *buf, const picoos_uint16 blenmax, picoos_uint16 *blen);
375 
376 /* gets from buf info of a single item, values in head are set and
377    content is set to the start of content in buf (not copied!);
378    content is set to NULL if the content length is 0; blenmax is the
379    max lengths (in number of bytes) accessible in buf; return values:
380      PICO_OK                 <- all ok
381      PICO_EXC_BUF_UNDERFLOW  <- blenmax problem, or no valid item
382 */
383 pico_status_t picodata_get_iteminfo(
384         picoos_uint8 *buf, const picoos_uint16 blenmax,
385         picodata_itemhead_t *head, picoos_uint8 **content);
386 
387 /* copies the item in inbuf to outbuf after first checking if there is
388    a valid item in inbuf; inlenmax and outlenmax are the max length
389    (in number of byte) accessible in the buffers); in *numb the total
390    number of bytes copied to outbuf (incl. header) is returned; return
391    values:
392    PICO_OK                 <- item copied
393    PICO_EXC_BUF_OVERFLOW   <- overflow in outbuf
394    PICO_ERR_OTHER          <- no valid item in inbuf
395 */
396 pico_status_t picodata_copy_item(const picoos_uint8 *inbuf,
397         const picoos_uint16 inlenmax, picoos_uint8 *outbuf,
398         const picoos_uint16 outlenmax, picoos_uint16 *numb);
399 
400 /* sets the info1 field in the header contained in the item in buf;
401    return values:
402    PICO_OK                 <- all ok
403    PICO_EXC_BUF_UNDERFLOW  <- underflow in buf
404 */
405 pico_status_t picodata_set_iteminfo1(picoos_uint8 *buf,
406         const picoos_uint16 blenmax, const picoos_uint8 info);
407 
408 /* sets the info2 field in the header contained in the item in buf;
409    return values:
410    PICO_OK                 <- all ok
411    PICO_EXC_BUF_UNDERFLOW  <- underflow in buf
412 */
413 pico_status_t picodata_set_iteminfo2(picoos_uint8 *buf,
414         const picoos_uint16 blenmax, const picoos_uint8 info);
415 
416 /* sets the len field in the header contained in the item in buf;
417    return values:
418    PICO_OK                 <- all ok
419    PICO_EXC_BUF_UNDERFLOW  <- underflow in buf
420 */
421 pico_status_t picodata_set_itemlen(picoos_uint8 *buf,
422         const picoos_uint16 blenmax, const picoos_uint8 len);
423 
424 /* check item validity and return TRUE if valid; return FALSE if
425    invalid; ilenmax is the max index to be used in item
426 */
427 picoos_uint8 picodata_is_valid_item(const picoos_uint8 *item,
428         const picoos_uint16 ilenmax);
429 
430 /* return TRUE if head is a valid item head, FALSE otherwise */
431 picoos_uint8 picodata_is_valid_itemhead(const picodata_itemhead_t *head);
432 
433 
434 /* ***************************************************************
435  *                   ProcessingUnit                              *
436  *****************************************************************/
437 /* public */
438 
439 #define PICODATA_MAX_ITEMSIZE (picoos_uint16) (PICODATA_ITEM_HEADSIZE + 256)
440 
441 /* different buffer sizes per processing unit */
442 #define PICODATA_BUFSIZE_DEFAULT (picoos_uint16) PICODATA_MAX_ITEMSIZE
443 #define PICODATA_BUFSIZE_TEXT    (picoos_uint16)  1 * PICODATA_BUFSIZE_DEFAULT
444 #define PICODATA_BUFSIZE_TOK     (picoos_uint16)  2 * PICODATA_BUFSIZE_DEFAULT
445 #define PICODATA_BUFSIZE_PR      (picoos_uint16)  2 * PICODATA_BUFSIZE_DEFAULT
446 #define PICODATA_BUFSIZE_WA      (picoos_uint16)  2 * PICODATA_BUFSIZE_DEFAULT
447 #define PICODATA_BUFSIZE_SA      (picoos_uint16)  2 * PICODATA_BUFSIZE_DEFAULT
448 #define PICODATA_BUFSIZE_ACPH    (picoos_uint16)  2 * PICODATA_BUFSIZE_DEFAULT
449 #define PICODATA_BUFSIZE_SPHO    (picoos_uint16)  4 * PICODATA_BUFSIZE_DEFAULT
450 #define PICODATA_BUFSIZE_PAM     (picoos_uint16)  4 * PICODATA_BUFSIZE_DEFAULT
451 #define PICODATA_BUFSIZE_CEP     (picoos_uint16) 16 * PICODATA_BUFSIZE_DEFAULT
452 #define PICODATA_BUFSIZE_SIG     (picoos_uint16) 16 * PICODATA_BUFSIZE_DEFAULT
453 #define PICODATA_BUFSIZE_SINK     (picoos_uint16) 1 * PICODATA_BUFSIZE_DEFAULT
454 
455 /* different types of processing units */
456 typedef enum picodata_putype {
457     PICODATA_PUTYPE_TEXT,   /* text */
458     PICODATA_PUTYPE_TOK,    /* tokenizer output */
459     PICODATA_PUTYPE_PR,     /* preprocessor output */
460     PICODATA_PUTYPE_WA,     /* word analysis */
461     PICODATA_PUTYPE_SA,     /* sentence analysis */
462     PICODATA_PUTYPE_ACPH,     /* accentuation and phrasing */
463     PICODATA_PUTYPE_SPHO,   /* sentence phonology (textana postproc) */
464     PICODATA_PUTYPE_PAM,    /* phonetics to acoustics mapper processing unit */
465     PICODATA_PUTYPE_CEP,    /* cepstral smoothing processing unit */
466     PICODATA_PUTYPE_SIG,     /* signal generation processing unit*/
467     PICODATA_PUTYPE_SINK     /* item sink unit*/
468 } picodata_putype_t;
469 
470 picoos_uint16 picodata_get_default_buf_size (picodata_putype_t puType);
471 
472 /* result values returned from the pu->puStep() methode */
473 typedef enum picodata_step_result {
474     PICODATA_PU_ERROR,
475     /* PICODATA_PU_EMPTY, *//* reserved (no internal data to be processed) */
476     PICODATA_PU_IDLE, /* need more input to process internal data */
477     PICODATA_PU_BUSY, /* processing internal data */
478     PICODATA_PU_ATOMIC, /* same as pu_busy, but wants to get next time slot (while in an "atomar" operation) */
479     PICODATA_PU_OUT_FULL /* can't proceed because output is full. (next time slot to be assigned to pu's output's consumer) */
480 } picodata_step_result_t;
481 
482 typedef struct picodata_processing_unit * picodata_ProcessingUnit;
483 
484 picodata_ProcessingUnit picodata_newProcessingUnit(
485         picoos_MemoryManager mm,
486         picoos_Common common,
487         picodata_CharBuffer cbIn,
488         picodata_CharBuffer cbOut,
489         picorsrc_Voice voice);
490 
491 void picodata_disposeProcessingUnit(
492         picoos_MemoryManager mm,
493         picodata_ProcessingUnit * this);
494 
495 picodata_CharBuffer picodata_getCbIn(picodata_ProcessingUnit this);
496 picodata_CharBuffer picodata_getCbOut(picodata_ProcessingUnit this);
497 pico_status_t picodata_setCbIn(picodata_ProcessingUnit this, picodata_CharBuffer cbIn);
498 pico_status_t picodata_setCbOut(picodata_ProcessingUnit this, picodata_CharBuffer cbOut);
499 
500 /* protected */
501 typedef pico_status_t (* picodata_puInitializeMethod) (register picodata_ProcessingUnit this, picoos_int32 mode);
502 typedef pico_status_t (* picodata_puTerminateMethod) (register picodata_ProcessingUnit this);
503 typedef picodata_step_result_t (* picodata_puStepMethod) (register picodata_ProcessingUnit this, picoos_int16 mode, picoos_uint16 * numBytesOutput);
504 typedef pico_status_t (* picodata_puSubDeallocateMethod) (register picodata_ProcessingUnit this, picoos_MemoryManager mm);
505 
506 typedef struct picodata_processing_unit
507 {
508     /* public */
509     picodata_puInitializeMethod initialize;
510     picodata_puStepMethod       step;
511     picodata_puTerminateMethod  terminate;
512     picorsrc_Voice              voice;
513 
514     /* protected */
515     picoos_Common                  common;
516     picodata_CharBuffer            cbIn, cbOut;
517     picodata_puSubDeallocateMethod subDeallocate;
518     void * subObj;
519 
520 } picodata_processing_unit_t;
521 
522 /* currently, only wav input and output is supported */
523 #define PICODATA_PUTYPE_TEXT_OUTPUT_EXTENSION   (picoos_uchar*)".txt"
524 #define PICODATA_PUTYPE_TOK_INPUT_EXTENSION     PICODATA_PUTYPE_TEXT_OUTPUT_EXTENSION
525 #define PICODATA_PUTYPE_TOK_OUTPUT_EXTENSION    (picoos_uchar*)".tok"
526 #define PICODATA_PUTYPE_PR_INPUT_EXTENSION      PICODATA_PUTYPE_TOK_OUTPUT_EXTENSION
527 #define PICODATA_PUTYPE_PR_OUTPUT_EXTENSION     (picoos_uchar*)".pr"
528 #define PICODATA_PUTYPE_WA_INPUT_EXTENSION      PICODATA_PUTYPE_PR_OUTPUT_EXTENSION
529 #define PICODATA_PUTYPE_WA_OUTPUT_EXTENSION     (picoos_uchar*)".wa"
530 #define PICODATA_PUTYPE_SA_INPUT_EXTENSION      PICODATA_PUTYPE_WA_OUTPUT_EXTENSION
531 #define PICODATA_PUTYPE_SA_OUTPUT_EXTENSION     (picoos_uchar*)".sa"
532 #define PICODATA_PUTYPE_ACPH_INPUT_EXTENSION    PICODATA_PUTYPE_SA_OUTPUT_EXTENSION
533 #define PICODATA_PUTYPE_ACPH_OUTPUT_EXTENSION   (picoos_uchar*)".acph"
534 #define PICODATA_PUTYPE_SPHO_INPUT_EXTENSION    PICODATA_PUTYPE_ACPH_OUTPUT_EXTENSION
535 #define PICODATA_PUTYPE_SPHO_OUTPUT_EXTENSION   (picoos_uchar*)".spho"
536 #define PICODATA_PUTYPE_PAM_INPUT_EXTENSION     PICODATA_PUTYPE_SPHO_OUTPUT_EXTENSION
537 #define PICODATA_PUTYPE_PAM_OUTPUT_EXTENSION    (picoos_uchar*)".pam"
538 #define PICODATA_PUTYPE_CEP_INPUT_EXTENSION     PICODATA_PUTYPE_PAM_OUTPUT_EXTENSION
539 #define PICODATA_PUTYPE_CEP_OUTPUT_EXTENSION    (picoos_uchar*)".cep"
540 #define PICODATA_PUTYPE_SIG_INPUT_EXTENSION     PICODATA_PUTYPE_CEP_OUTPUT_EXTENSION   /*PP 11.7.08*/
541 #define PICODATA_PUTYPE_SIG_OUTPUT_EXTENSION    (picoos_uchar*)".sig"
542 #define PICODATA_PUTYPE_SINK_INPUT_EXTENSION    PICODATA_PUTYPE_SIG_OUTPUT_EXTENSION
543 
544 /*wav input is for play wav files in sig */
545 #define PICODATA_PUTYPE_WAV_INPUT_EXTENSION    (picoos_uchar*)".wav"                    /*PP 11.7.08*/
546 
547 /*wav output is for saving wav (binary) files in sig*/
548 #define PICODATA_PUTYPE_WAV_OUTPUT_EXTENSION    (picoos_uchar*)".wav"                    /*PP 14.7.08*/
549 
550 /* ***************************************************************
551  *                   auxiliary routines                          *
552  *****************************************************************/
553 
554 picoos_uint8 picodata_getPuTypeFromExtension(picoos_uchar * filename, picoos_bool input);
555 
556 #define PICODATA_XSAMPA (picoos_uchar *)"xsampa"
557 #define PICODATA_SAMPA (picoos_uchar *)"sampa"
558 #define PICODATA_SVOXPA (picoos_uchar *)"svoxpa"
559 
560 /*----------------------------------------------------------*/
561 /** @brief   maps an input phone string to its internal representation
562  *
563  * @param transducer initialized SimpleTransducer
564  * @param xsampa_parser fst converting xsampa char input to xsampa ids
565  * @param svoxpa_parser
566  * @param xsampa2svoxpa_mapper
567  * @param inputPhones input phone string in alphabet 'alphabet'
568  * @param alphabet input alphabet
569  * @retval outputPhoneIds output phone string in internal representation
570  * @param maxOutputPhoneIds
571  * @return PICO_OK=mapping done, PICO_ERR_OTHER:unknown alphabet, unknown phones
572  */
573 /*---------------------------------------------------------*/
574 pico_status_t picodata_mapPAStrToPAIds(
575         picotrns_SimpleTransducer transducer,
576         picoos_Common common,
577         picokfst_FST xsampa_parser,
578         picokfst_FST svoxpa_parser,
579         picokfst_FST xsampa2svoxpa_mapper,
580         picoos_uchar * inputPhones,
581         picoos_uchar * alphabet,
582         picoos_uint8 * outputPhoneIds,
583         picoos_int32 maxOutputPhoneIds);
584 
585 /* number of binary digits after the comma for fixed-point calculation */
586 #define PICODATA_PRECISION 10
587 /* constant 0.5 in PICODATA_PRECISION */
588 #define PICODATA_PREC_HALF 512
589 
590 void picodata_transformDurations(
591         picoos_uint8 frame_duration_exp,
592         picoos_int8 array_length,
593         picoos_uint8 * inout,
594         const picoos_uint16 * weight,  /* integer weights */
595         picoos_int16 mintarget, /* minimum target duration in ms */
596         picoos_int16 maxtarget, /* maximum target duration in ms */
597         picoos_int16 facttarget, /* factor to be multiplied with original length to get the target
598                                      the factor is fixed-point with precision PRECISION, i.e.
599                                      the factor as float would be facttarget / PRECISION_FACT
600                                      if factor is 0, only min/max are considered */
601         picoos_int16 * dur_rest /* in/out, rest in ms */
602         );
603 
604 
605 
606 /* ***************************************************************
607  *                   For Debugging only                          *
608  *****************************************************************/
609 
610 #if defined (PICO_DEBUG)
611 
612 /* convert (pretty print) item head 'head' and put output in 'str',
613    strsize is the maximum length of 'str' in bytes */
614 picoos_char * picodata_head_to_string(const picodata_itemhead_t *head,
615                                       picoos_char * str, picoos_uint16 strsize);
616 
617 /* put 'pref6ch' (max. 6 char prefix) and a pretty print output of
618    'item' in 'str', strlenmax is the maximum length of 'str' in
619    bytes */
620 void picodata_info_item(const picoknow_KnowledgeBase kb,
621                         const picoos_uint8 *pref6ch,
622                         const picoos_uint8 *item,
623                         const picoos_uint16 itemlenmax,
624                         const picoos_char *filterfn);
625 
626 
627 #define PICODATA_INFO_ITEM(kb, pref, item, itemlenmax)   \
628     PICODBG_INFO_CTX(); \
629     picodata_info_item(kb, pref, item, itemlenmax, (picoos_char *)__FILE__)
630 
631 
632 
633 #else
634 
635 #define PICODATA_INFO_ITEM(kb, pref, item, itemlenmax)
636 
637 #endif
638 
639 #ifdef __cplusplus
640 }
641 #endif
642 
643 #endif /*PICODATA_H_*/
644