1b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*
2b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland
3b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
4b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * Licensed under the Apache License, Version 2.0 (the "License");
5b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * you may not use this file except in compliance with the License.
6b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * You may obtain a copy of the License at
7b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
8b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *     http://www.apache.org/licenses/LICENSE-2.0
9b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
10b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * Unless required by applicable law or agreed to in writing, software
11b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * distributed under the License is distributed on an "AS IS" BASIS,
12b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * See the License for the specific language governing permissions and
14b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * limitations under the License.
15b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
16b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
17b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @file picopam.c
18b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
19b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * Phonetic to Acoustic Mapping PU - Implementation
20b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
21b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland
22b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * All rights reserved.
23b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
24b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * History:
25b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * - 2009-04-20 -- initial version
26b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen *
27b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
28b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
29b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#include "picodefs.h"
30b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#include "picoos.h"
31b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#include "picodbg.h"
32b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#include "picodata.h"
33b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#include "picopam.h"
34b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#include "picokdt.h"
35b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#include "picokpdf.h"
36b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#include "picoktab.h"
37b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#include "picokdbg.h"
38b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#include "picodsp.h"
39b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
40b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#ifdef __cplusplus
41b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenextern "C" {
42b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#endif
43b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#if 0
44b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}
45b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#endif
46b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
47b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_IN_BUFF_SIZE PICODATA_BUFSIZE_PAM    /*input buffer size for PAM */
48b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_OUT_PAM_SIZE PICODATA_BUFSIZE_PAM    /*output buffer size for PAM*/
49b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_DT_NRLFZ    5    /* nr of lfz decision trees per phoneme */
50b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_DT_NRMGC    5    /* nr of mgc decision trees per phoneme */
51b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_NRSTPF      5    /* nr of states per phone */
52b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
53b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_COLLECT     0
54b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_SCHEDULE    1
55b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_IMMEDIATE   2
56b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_FORWARD     3
57b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_FORWARD_FORCE_TERM 4
58b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_PROCESS     5
59b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_PLAY        6
60b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_FEED        7
61b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
62b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_CONTINUE       100
63b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_GOTO_SCHEDULE  1
64b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_FLUSH_RECEIVED 6
65b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_GOTO_FEED      7
66b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_PRE_SYLL_ENDED 10
67b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
68b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_BREAK_ADD_SIZE 4        /*syllable feature vector increment dued to BREAK and SILENCE*/
69b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_VECT_SIZE 64+PICOPAM_BREAK_ADD_SIZE /*syllable feature vector size (bytes)*/
70b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_INVEC_SIZE 60           /*phone feature vector size */
71b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_MAX_SYLL_PER_SENT 100   /*maximum number of syllables per sentece*/
72b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_MAX_PH_PER_SENT 400     /*maximum number of phonemes  per sentece*/
73b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_MAX_ITEM_PER_SENT 255   /*maximum number of attached items per sentence*/
74b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_MAX_ITEM_SIZE_PER_SENT 4096 /*maximum size of attached items per sentence*/
75b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
76b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_READY 20 /*PAM could start backward processing*/
77b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_MORE  21 /*PAM has still to collect */
78b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_NA    22 /*PAM has not to deal with this item*/
79b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_ERR   23 /*input item is not a valid item*/
80b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
81b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*sentence types:cfr pam_map_sentence_type*/
82b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_DECLARATIVE   0
83b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_INTERROGATIVE 1
84b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_EXCLAMATIVE   2
85b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
86b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_T   0
87b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_P   1
88b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_p   2
89b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_Y   3
90b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
91b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#if 1
92b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PAM_PHR2_WITH_PR1 1 /*deal with PHR2 boundaries as with PHR1*/
93b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#else
94b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PAM_PHR2_WITH_PR3 1 /*deal with PHR2 boundaries as with PHR3*/
95b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#endif
96b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
97b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_DONT_CARE_VALUE  250 /*don't care value for tree printout    */
98b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_DONT_CARE_VAL    10  /*don't care value for tree feeding     */
99b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_PH_DONT_CARE_VAL 7   /*don't care value for tree feeding (phonetic)*/
100b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
101b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_MAX_STATES_PER_PHONE 5 /*number of states per phone    */
102b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_STATE_SIZE_IN_ITEM   6 /*size of a state in frame item */
103b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_FRAME_ITEM_SIZE      4+PICOPAM_MAX_STATES_PER_PHONE*PICOPAM_STATE_SIZE_IN_ITEM
104b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
105b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_DIR_FORW 0 /*forward adapter processing*/
106b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_DIR_BACK 1 /*backward adapter processing*/
107b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_DIR_SIL  2 /*final silence attributes*/
108b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
109b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_SYLL_PAUSE  0 /*syllable but containing a pause phone*/
110b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_SYLL_SYLL   1 /*a real syllable with phonemes*/
111b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
112b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_EVENT_P_BOUND 0 /*primary boundary*/
113b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_EVENT_S_BOUND 1 /*secondary boundary*/
114b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_EVENT_W_BOUND 3 /*word boundary*/
115b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_EVENT_SYLL    4 /*syllable*/
116b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
117b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* ----- CONSTANTS FOR BREAK COMMAND SUPPORT ----- */
118b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_PWIDX_SBEG 0
119b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_PWIDX_PHR1 1
120b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_PWIDX_PHR2 2
121b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_PWIDX_SEND 3
122b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_PWIDX_DEFA 4
123b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define PICOPAM_PWIDX_SIZE 5
124b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
125b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*----------------------------------------------------------------*/
126b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*structure related to the feature vectors for feeding the trees  */
127b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*NOTE : the same data structure is used to manage the syllables  */
128b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*       Using the first 8 fields for marking the boundaries      */
129b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*       and using the last 4 bytes as follows                    */
130b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*     byte 61 : 1st attached non PAM item id(0=no item attached) */
131b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*               in the "sSyllItemOffs" data structure            */
132b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*     byte 62 : last attached non PAM item id(0=no item attached)*/
133b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*               in the "sSyllItemOffs" data structure            */
134b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*     byte 63..64 : offset of the start of the syllable in       */
135b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*                   the "sPhIds" data structure                  */
136b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef struct
137b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
138b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picopal_uint8 phoneV[PICOPAM_VECT_SIZE];
139b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} sFtVect, *pSftVect;
140b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
141b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*----------------------------------------------------------
142b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen Name    :   pam_subobj
143b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen Function:   subobject definition for the pam processing
144b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen Shortcut:   pam
145b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen ---------------------------------------------------------*/
146b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chentypedef struct pam_subobj
147b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
148b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*----------------------PU voice management------------------------------*/
149b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /* picorsrc_Voice voice; */
150b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*----------------------PU state management------------------------------*/
151b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 procState; /* where to take up work at next processing step */
152b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 retState; /* where to go back from feed state at next p.s. */
153b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 needMoreInput; /* more data necessary to start processing   */
154b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*----------------------PU input management------------------------------*/
155b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 inBuf[PICOPAM_IN_BUFF_SIZE]; /* internal input buffer */
156b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint16 inBufSize; /* actually allocated size */
157b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint16 inReadPos, inWritePos; /* next pos to read/write from/to inBuf*/
158b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*----------------------PU output management-----------------------------*/
159b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 outBuf[PICOPAM_OUT_PAM_SIZE]; /* internal output buffer */
160b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint16 outBufSize; /* actually allocated size */
161b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint16 outReadPos, outWritePos; /* next pos to read/write from/to outBuf*/
162b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*---------------------- adapter working buffers    --------------------*/
163b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 *sPhFeats; /*feature vector for a single phone      */
164b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sFtVect *sSyllFeats; /*Syllable feature vector set for the
165b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     full sentence                          */
166b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 *sPhIds; /*phone ids for the full sentence        */
167b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 *sSyllItems; /*items attached to the syllable         */
168b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int16 *sSyllItemOffs;/*offset of items attached to the syllable*/
169b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*---------------------- adapter general variables ---------------------*/
170b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int16 nTotalPhonemes; /*number of phonemes in the sentence*/
171b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int16 nCurrPhoneme; /*current phoneme in the sentence   */
172b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int16 nSyllPhoneme; /*current phoneme in the syllable   */
173b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int16 nCurrSyllable; /*current syllable in the sentence  */
174b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int16 nTotalSyllables; /*number of syllables in the sentence -> J1*/
175b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 nLastAttachedItemId;/*last attached item id*/
176b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 nCurrAttachedItem; /*current attached item*/
177b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int16 nAttachedItemsSize; /*total size of the attached items*/
178b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 sType; /*Sentence type*/
179b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 pType; /*Phrase type*/
180b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_single pMod; /*pitch modifier*/
181b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_single dMod; /*Duration modifier*/
182b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_single dRest; /*Duration modifier rest*/
183b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*---------------------- adapter specific component variables ----------*/
184b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 a3_overall_syllable; /* A3 */
185b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 a3_primary_phrase_syllable;
186b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 b4_b5_syllable; /* B4,B5 */
187b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 b6_b7_syllable; /* B6,B7 */
188b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 b6_b7_state;
189b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 b8_b9_stressed_syllable; /* B8,B9 */
190b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 b10_b11_accented_syllable; /* B10,B11 */
191b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 b12_b13_syllable; /* B12,B13 */
192b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 b12_b13_state;
193b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 b14_b15_syllable; /* B14,B15 */
194b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 b14_b15_state;
195b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 b17_b19_syllable; /* B17,B19 */
196b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 b17_b19_state;
197b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 b18_b20_b21_syllable; /* B18,B20,B21 */
198b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 b18_b20_b21_state;
199b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 c3_overall_syllable; /* C3 */
200b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 c3_primary_phrase_syllable;
201b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 d2_syllable_in_word; /* D2 */
202b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 d2_prev_syllable_in_word;
203b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 d2_current_primary_phrase_word;
204b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int8 e1_syllable_word_start; /* E1 */
205b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int8 e1_syllable_word_end;
206b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 e1_content;
207b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int8 e2_syllable_word_start; /* E2 */
208b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int8 e2_syllable_word_end;
209b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 e3_e4_word; /* E3,E4 */
210b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 e3_e4_state;
211b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 e5_e6_content_word; /* E5,E6 */
212b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 e5_e6_content;
213b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 e7_e8_word; /* E7,E8 */
214b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 e7_e8_content;
215b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 e7_e8_state;
216b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 e9_e11_word; /* E9,E11 */
217b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 e9_e11_saw_word;
218b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 e9_e11_state;
219b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 e10_e12_e13_word; /* E10,E12,E13 */
220b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 e10_e12_e13_state;
221b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 e10_e12_e13_saw_word;
222b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 f2_overall_word; /* F2 */
223b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 f2_word_syllable;
224b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 f2_next_word_syllable;
225b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 f2_current_primary_phrase_word;
226b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int8 g1_current_secondary_phrase_syllable; /*G1 */
227b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int8 g1_current_syllable;
228b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int8 g2_current_secondary_phrase_word; /*G2 */
229b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int8 g2_current_word;
230b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 h1_current_secondary_phrase_syll; /*H1 */
231b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 h2_current_secondary_phrase_word; /*H2 */
232b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 h3_h4_current_secondary_phrase_word; /*H3,H4 */
233b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 h5_current_phrase_type; /*H5 */
234b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
235b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 h5_syllable; /* H5 */
236b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 h5_state;
237b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
238b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 i1_secondary_phrase_syllable; /*I1 */
239b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 i1_next_secondary_phrase_syllable;
240b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 i2_secondary_phrase_word; /*I2 */
241b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 i2_next_secondary_phrase_word;
242b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 j1_utterance_syllable; /*J1 */
243b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 j2_utterance_word; /*J2 */
244b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 j3_utterance_sec_phrases; /*J3 */
245b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*---------------------- constant data -------------------*/
246b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint16 sil_weights[PICOPAM_PWIDX_SIZE][PICOPAM_MAX_STATES_PER_PHONE];
247b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*---------------------- LINGWARE related data -------------------*/
248b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picokdt_DtPAM dtdur; /* dtdur knowledge base */
249b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picokdt_DtPAM dtlfz[PICOPAM_DT_NRLFZ]; /* dtlfz knowledge bases */
250b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picokdt_DtPAM dtmgc[PICOPAM_DT_NRMGC]; /* dtmgc knowledge bases */
251b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*---------------------- Pdfs related data -------------------*/
252b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picokpdf_PdfDUR pdfdur; /* pdfdur knowledge base */
253b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picokpdf_PdfMUL pdflfz; /* pdflfz knowledge base */
254b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*---------------------- Tree traversal related data -------------------*/
255b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint16 durIndex;
256b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 numFramesState[PICOPAM_DT_NRLFZ];
257b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint16 lf0Index[PICOPAM_DT_NRLFZ];
258b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint16 mgcIndex[PICOPAM_DT_NRMGC];
259b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*---------------------- temps for updating the feature vector ---------*/
260b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint16 phonDur;
261b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_single phonF0[PICOPAM_DT_NRLFZ];
262b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*---------------------- Phones related data  -------------------*/
263b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoktab_Phones tabphones;
264b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} pam_subobj_t;
265b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
266b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
267b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* ----- CONSTANTS FOR FEATURE VECTOR BUILDING (NOT PREFIXED WITH "PICOPAM_" FOR BREVITY) ----- */
268b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  P1  0              /*field 1 of the input vector*/
269b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  P2  1
270b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  P3  2
271b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  P4  3
272b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  P5  4
273b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  P6  5
274b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  P7  6
275b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  bnd 6              /*boundary type item associated to the syllable = P7 */
276b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  P8  7
277b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  A3  8
278b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B1  9
279b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B2  10
280b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B3  11
281b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B4  12
282b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B5  13
283b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B6  14
284b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B7  15
285b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B8  16
286b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B9  17
287b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B10 18
288b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B11 19
289b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B12 20
290b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B13 21
291b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B14 22
292b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B15 23
293b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B16 24
294b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B17 25
295b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B18 26
296b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B19 27
297b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B20 28
298b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  B21 29
299b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  C3  30
300b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  D2  31
301b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  E1  32
302b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  E2  33
303b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  E3  34
304b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  E4  35
305b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  E5  36
306b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  E6  37
307b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  E7  38
308b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  E8  39
309b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  E9  40
310b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  E10 41
311b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  E11 42
312b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  E12 43
313b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  E13 44
314b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  F2  45
315b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  G1  46
316b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  G2  47
317b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  H1  48
318b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  H2  49
319b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  H3  50
320b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  H4  51
321b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  H5  52
322b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  I1  53
323b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  I2  54
324b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  J1  55
325b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  J2  56
326b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  J3  57
327b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  DUR 58             /*duration component*/
328b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  F0  59             /*F0 component*/
329b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  ITM 60             /*Item Offset into sSyllItems item list*/
330b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  itm 61             /*second byte of the Item Offset */
331b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  FID 62             /*Phoneme offset in the sPhIds phoneme list*/
332b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  fid 63             /*second byte of the Phoneme offset */
333b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  Min 64             /*offset to min syllable duration (uint 16,pauses)*/
334b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  Max 66             /*offset to max syllable duration (uint 16,pauses)*/
335b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* -------------------------------------------------------------------
336b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen PAM feature vector indices position changes,
337b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen  ------------------------------------------------------------------- */
338b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B1  8
339b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B2  9
340b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B3  10
341b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B4  11
342b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B5  12
343b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B6  13
344b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B7  14
345b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B8  15
346b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B9  16
347b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B10 17
348b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B11 18
349b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B12 19
350b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B13 20
351b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B14 21
352b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B15 22
353b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B16 23
354b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B17 24
355b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B18 25
356b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B19 26
357b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B20 27
358b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_B21 28
359b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_E1  29
360b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_E2  30
361b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_E3  31
362b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_E4  32
363b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_E5  33
364b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_E6  34
365b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_E7  35
366b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_E8  36
367b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_E9  37
368b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_E10 38
369b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_E11 39
370b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_E12 40
371b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_E13 41
372b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_A3  42
373b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_C3  43
374b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_D2  44
375b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_F2  45
376b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_G1  46
377b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_I1  47
378b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_G2  48
379b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_I2  49
380b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_H1  50
381b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_H2  51
382b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_H3  52
383b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_H4  53
384b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#define  T_H5  54
385b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
386b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*------------------------------------------------------------------
387b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen Service routines :
388b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen ------------------------------------------------------------------*/
389e9f72c8954f29f10cb4feb16d328a1b5c1fd7169Jean-Michel Trivistatic pico_status_t pam_initialize(register picodata_ProcessingUnit this, picoos_int32 resetMode);
390b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_terminate(register picodata_ProcessingUnit this);
391b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_allocate(picoos_MemoryManager mm, pam_subobj_t *pam);
392b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic void pam_deallocate(picoos_MemoryManager mm, pam_subobj_t *pam);
393b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_subobj_deallocate(register picodata_ProcessingUnit this,
394b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_MemoryManager mm);
395b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*------------------------------------------------------------------
396b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen Processing routines :
397b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen ------------------------------------------------------------------*/
398b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic picodata_step_result_t pam_step(register picodata_ProcessingUnit this,
399b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_int16 mode, picoos_uint16 * numBytesOutput);
400b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_deal_with(const picoos_uint8 *item);
401b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*Utility*/
402b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic picoos_uint8 pam_get_vowel_name(register picodata_ProcessingUnit this,
403b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint8 *item, picoos_uint8 *pos);
404b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic picoos_uint8 pam_get_pause_id(register picodata_ProcessingUnit this);
405b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
406b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic picoos_uint8 pam_map_sentence_type(picoos_uint8 iteminfo1,
407b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint8 iteminfo2);
408b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic picoos_uint8 pam_map_phrase_type(picoos_uint8 iteminfo1,
409b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint8 iteminfo2);
410b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
411b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*Adapter*/
412b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_reset_processors(register picodata_ProcessingUnit this);
413b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_reset_processors_back(
414b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        register picodata_ProcessingUnit this);
415b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_create_syllable(register picodata_ProcessingUnit this,
416b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint8 syllType, picoos_uint8 *sContent, picoos_uint8 sentType,
417b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint8 phType, picoos_uint8 uBoundType, picoos_uint16 uMin,
418b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint16 uMax);
419b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_process_event_feature(
420b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        register picodata_ProcessingUnit this, picoos_uint8 nFeat,
421b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint8 event_type, picoos_uint8 direction);
422b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_process_event(register picodata_ProcessingUnit this,
423b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint8 event_type, picoos_uint8 direction);
424b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_adapter_forward_step(
425b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        register picodata_ProcessingUnit this, picoos_uint8 *itemBase);
426b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_adapter_backward_step(
427b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        register picodata_ProcessingUnit this);
428b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_do_pause(register picodata_ProcessingUnit this);
429b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_adapter_do_pauses(register picodata_ProcessingUnit this);
430b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*-------------- tree traversal ---------------------------------------*/
431b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_expand_vector(register picodata_ProcessingUnit this);
432b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic picoos_uint8 pam_do_tree(register picodata_ProcessingUnit this,
433b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        const picokdt_DtPAM dtpam, const picoos_uint8 *invec,
434b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        const picoos_uint8 inveclen, picokdt_classify_result_t *dtres);
435b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_get_f0(register picodata_ProcessingUnit this,
436b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint16 *lf0Index, picoos_uint8 nState, picoos_single *phonF0);
437b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_get_duration(register picodata_ProcessingUnit this,
438b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint16 durIndex, picoos_uint16 *phonDur,
439b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint8 *numFramesState);
440b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_update_vector(register picodata_ProcessingUnit this);
441b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*-------------- FINAL ITEM FEEDING -----------------------------------------*/
442b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_put_item(register picodata_ProcessingUnit this,
443b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                picoos_uint8 *outBuff, picoos_uint16 outWritePos,
444b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                picoos_uint8 *bytesWr);
445b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
446b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_put_term(picoos_uint8 *outBuff,
447b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint16 outWritePos, picoos_uint8 *bytesWr);
448b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
449b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t is_pam_command(const picoos_uint8 *qItem);
450b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
451b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic void get_default_boundary_limit(picoos_uint8 uBoundType,
452b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint16 *uMinDur, picoos_uint16 *uMaxDur);
453b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
454b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/* -------------------------------------------------------------
455b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * Pico System functions
456b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * -------------------------------------------------------------
457b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
458b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
459b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
460b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * allocation for PAM memory on pam PU
461b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    mm : handle to engine memory manager
462b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    pam : handle to a pam struct
463b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return  PICO_OK : allocation successful
464b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_ERR_OTHER : allocation errors
465b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
466b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
467b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
468b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_allocate(picoos_MemoryManager mm, pam_subobj_t *pam)
469b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
470b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 *data;
471b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int16 *dataI;
472b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
473b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sSyllFeats = NULL;
474b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sPhIds = NULL;
475b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sPhFeats = NULL;
476b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sSyllItems = NULL;
477b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sSyllItemOffs = NULL;
478b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
479b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*-----------------------------------------------------------------
480b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     * PAM Local buffers ALLOCATION
481b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     ------------------------------------------------------------------*/
482b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*PAM Local buffers*/
483b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    data = (picopal_uint8 *) picoos_allocate(mm, sizeof(sFtVect)
484b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            * PICOPAM_MAX_SYLL_PER_SENT);
485b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (data == NULL)
486b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
487b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sSyllFeats = (sFtVect*) data;
488b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
489b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    data = (picopal_uint8 *) picoos_allocate(mm, sizeof(picopal_uint8)
490b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            * PICOPAM_MAX_PH_PER_SENT);
491b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (data == NULL) {
492b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam_deallocate(mm, pam);
493b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
494b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
495b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sPhIds = (picopal_uint8*) data;
496b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
497b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    data = (picopal_uint8 *) picoos_allocate(mm, sizeof(picopal_uint8)
498b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            * PICOPAM_VECT_SIZE);
499b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (data == NULL) {
500b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam_deallocate(mm, pam);
501b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
502b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
503b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sPhFeats = (picopal_uint8*) data;
504b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
505b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    data = (picopal_uint8 *) picoos_allocate(mm, sizeof(picopal_uint8)
506b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            * PICOPAM_MAX_ITEM_SIZE_PER_SENT);
507b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (data == NULL) {
508b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam_deallocate(mm, pam);
509b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
510b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
511b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sSyllItems = (picopal_uint8*) data;
512b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
513b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    dataI = (picoos_int16 *) picoos_allocate(mm, sizeof(picoos_int16)
514b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            * PICOPAM_MAX_ITEM_PER_SENT);
515b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (data == NULL) {
516b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam_deallocate(mm, pam);
517b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
518b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
519b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sSyllItemOffs = (picoos_int16*) dataI;
520b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
521b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
522b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pam_allocate*/
523b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
524b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
525b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * frees allocation for DSP memory on PAM PU
526b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    mm : memory manager
527b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    pam : pam PU internal sub-object
528b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return   void
529b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks  modified and inserted in sub obj removal PP 15.09.08
530b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
531b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
532b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
533b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic void pam_deallocate(picoos_MemoryManager mm, pam_subobj_t *pam)
534b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
535b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*-----------------------------------------------------------------
536b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     * Memory de-allocations
537b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     * ------------------------------------------------------------------*/
538b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->sSyllFeats != NULL)
539b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_deallocate(mm, (void *) &pam->sSyllFeats);
540b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->sPhIds != NULL)
541b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_deallocate(mm, (void *) &pam->sPhIds);
542b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->sPhFeats != NULL)
543b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_deallocate(mm, (void *) &pam->sPhFeats);
544b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->sSyllItems != NULL)
545b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_deallocate(mm, (void *) &pam->sSyllItems);
546b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->sSyllItemOffs != NULL)
547b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_deallocate(mm, (void *) &pam->sSyllItemOffs);
548b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
549b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pam_deallocate*/
550b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
551b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
552b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * initialization of a pam PU
553b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : handle to a PU struct
554b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return     PICO_OK : init OK
555b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_ERR_OTHER : error on getting pkbs addresses
556b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
557b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
558b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
559e9f72c8954f29f10cb4feb16d328a1b5c1fd7169Jean-Michel Trivistatic pico_status_t pam_initialize(register picodata_ProcessingUnit this, picoos_int32 resetMode)
560b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
561b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pico_status_t nI, nJ;
562b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam_subobj_t *pam;
563b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
564b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
565b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
566b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
567b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
568b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->inBufSize = PICOPAM_IN_BUFF_SIZE;
569b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->outBufSize = PICOPAM_OUT_PAM_SIZE;
570b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->inReadPos = 0;
571b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->inWritePos = 0;
572b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->outReadPos = 0;
573b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->outWritePos = 0;
574b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->needMoreInput = 0;
575b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->procState = 0;
576b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
577b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*-----------------------------------------------------------------
578b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     * MANAGE INTERNAL INITIALIZATION
579b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     ------------------------------------------------------------------*/
580b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*init the syllable structure*/
581b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < PICOPAM_MAX_SYLL_PER_SENT; nI++)
582b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        for (nJ = 0; nJ < PICOPAM_VECT_SIZE; nJ++)
583b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            pam->sSyllFeats[nI].phoneV[nJ] = 0;
584b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
585b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < PICOPAM_MAX_PH_PER_SENT; nI++)
586b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->sPhIds[nI] = 0;
587b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
588b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < PICOPAM_VECT_SIZE; nI++)
589b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->sPhFeats[nI] = 0;
590b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
591b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < PICOPAM_MAX_ITEM_SIZE_PER_SENT; nI++)
592b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->sSyllItems[nI] = 0;
593b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
594b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < PICOPAM_MAX_ITEM_PER_SENT; nI++)
595b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->sSyllItemOffs[nI] = 0;
596b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
597b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*Other variables*/
598b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam_reset_processors(this);
599b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->nLastAttachedItemId = pam->nCurrAttachedItem = 0;
600b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->nAttachedItemsSize = 0;
601b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
602e9f72c8954f29f10cb4feb16d328a1b5c1fd7169Jean-Michel Trivi    if (resetMode == PICO_RESET_SOFT) {
6037bc39b0d41efe0d8733490d54e14bc392d9f0b6dJean-Michel Trivi        /*following initializations needed only at startup or after a full reset*/
6047bc39b0d41efe0d8733490d54e14bc392d9f0b6dJean-Michel Trivi        return PICO_OK;
6057bc39b0d41efe0d8733490d54e14bc392d9f0b6dJean-Michel Trivi    }
6067bc39b0d41efe0d8733490d54e14bc392d9f0b6dJean-Michel Trivi
607b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*pitch and duration modifiers*/
608b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->pMod = 1.0f;
609b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->dMod = 1.0f;
610b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->dRest = 0.0f;
611b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
612b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
613b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /* constant tables */
614b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    {
615b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint8 i, j;
616b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint16 tmp_weights[PICOPAM_PWIDX_SIZE][PICOPAM_MAX_STATES_PER_PHONE] = {
617b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        {10, 10, 10, 10, 1 }, /*SBEG*/
618b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        { 1, 4, 8, 4, 1 }, /*PHR1*/
619b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        { 1, 4, 8, 4, 1 }, /*PHR2*/
620b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        { 1, 10, 10, 10, 10 },/*SEND*/
621b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        { 1, 1, 1, 1, 1 } /*DEFAULT*/
622b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        };
623b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        for (i = 0; i < PICOPAM_PWIDX_SIZE; i++) {
624b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            for (j = 0; j < PICOPAM_PWIDX_SIZE; j++) {
625b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                pam->sil_weights[j][j] = tmp_weights[i][j];
626b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            }
627b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
628b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
6297bc39b0d41efe0d8733490d54e14bc392d9f0b6dJean-Michel Trivi
6307bc39b0d41efe0d8733490d54e14bc392d9f0b6dJean-Michel Trivi
631b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*-----------------------------------------------------------------
632b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     * MANAGE LINGWARE INITIALIZATION IF NEEDED
633b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     ------------------------------------------------------------------*/
634b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /* kb dtdur */
635b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->dtdur = picokdt_getDtPAM(this->voice->kbArray[PICOKNOW_KBID_DT_DUR]);
636b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->dtdur == NULL) {
637b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_emRaiseException(this->common->em, PICO_EXC_KB_MISSING, NULL,
638b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                NULL);
639b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
640b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }PICODBG_DEBUG(("got dtdur"));
641b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
642b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /* kb dtlfz* */
643b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->dtlfz[0] = picokdt_getDtPAM(
644b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            this->voice->kbArray[PICOKNOW_KBID_DT_LFZ1]);
645b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->dtlfz[1] = picokdt_getDtPAM(
646b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            this->voice->kbArray[PICOKNOW_KBID_DT_LFZ2]);
647b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->dtlfz[2] = picokdt_getDtPAM(
648b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            this->voice->kbArray[PICOKNOW_KBID_DT_LFZ3]);
649b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->dtlfz[3] = picokdt_getDtPAM(
650b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            this->voice->kbArray[PICOKNOW_KBID_DT_LFZ4]);
651b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->dtlfz[4] = picokdt_getDtPAM(
652b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            this->voice->kbArray[PICOKNOW_KBID_DT_LFZ5]);
653b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < PICOPAM_DT_NRLFZ; nI++) {
654b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (pam->dtlfz[nI] == NULL) {
655b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            picoos_emRaiseException(this->common->em, PICO_EXC_KB_MISSING,
656b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    NULL, NULL);
657b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            return PICO_ERR_OTHER;
658b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }PICODBG_DEBUG(("got dtlfz%d", nI+1));
659b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
660b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
661b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /* kb dtmgc* */
662b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->dtmgc[0] = picokdt_getDtPAM(
663b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            this->voice->kbArray[PICOKNOW_KBID_DT_MGC1]);
664b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->dtmgc[1] = picokdt_getDtPAM(
665b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            this->voice->kbArray[PICOKNOW_KBID_DT_MGC2]);
666b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->dtmgc[2] = picokdt_getDtPAM(
667b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            this->voice->kbArray[PICOKNOW_KBID_DT_MGC3]);
668b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->dtmgc[3] = picokdt_getDtPAM(
669b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            this->voice->kbArray[PICOKNOW_KBID_DT_MGC4]);
670b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->dtmgc[4] = picokdt_getDtPAM(
671b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            this->voice->kbArray[PICOKNOW_KBID_DT_MGC5]);
672b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < PICOPAM_DT_NRMGC; nI++) {
673b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (pam->dtmgc[nI] == NULL) {
674b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            picoos_emRaiseException(this->common->em, PICO_EXC_KB_MISSING,
675b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    NULL, NULL);
676b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            return PICO_ERR_OTHER;
677b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }PICODBG_DEBUG(("got dtmgc%d", nI+1));
678b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
679b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
680b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /* kb pdfdur* */
681b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->pdfdur = picokpdf_getPdfDUR(
682b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            this->voice->kbArray[PICOKNOW_KBID_PDF_DUR]);
683b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->pdfdur == NULL) {
684b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_emRaiseException(this->common->em, PICO_EXC_KB_MISSING, NULL,
685b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                NULL);
686b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
687b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }PICODBG_DEBUG(("got pdfdur"));
688b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
689b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /* kb pdflfz* */
690b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->pdflfz = picokpdf_getPdfMUL(
691b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            this->voice->kbArray[PICOKNOW_KBID_PDF_LFZ]);
692b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->pdflfz == NULL) {
693b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_emRaiseException(this->common->em, PICO_EXC_KB_MISSING, NULL,
694b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                NULL);
695b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
696b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }PICODBG_DEBUG(("got pdflfz"));
697b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
698b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /* kb tabphones */
699b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->tabphones = picoktab_getPhones(
700b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            this->voice->kbArray[PICOKNOW_KBID_TAB_PHONES]);
701b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->tabphones == NULL) {
702b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_emRaiseException(this->common->em, PICO_EXC_KB_MISSING, NULL,
703b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                NULL);
704b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
705b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }PICODBG_DEBUG(("got tabphones"));
706b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
707b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
708b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pam_initialize*/
709b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
710b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
711b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * termination of a pam PU
712b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : handle to a pam PU struct
713b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return PICO_OK
714b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
715b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
716b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
717b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_terminate(register picodata_ProcessingUnit this)
718b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
719b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
720b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam_subobj_t *pam;
721b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
722b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
723b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
724b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
725b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
726b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
727b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
728b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pam_terminate*/
729b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
730b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
731b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * deallocaton of a pam PU
732b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : handle to a pam PU struct
733b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    mm : engine memory manager
734b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return  PICO_OK
735b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
736b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
737b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
738b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_subobj_deallocate(register picodata_ProcessingUnit this,
739b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_MemoryManager mm)
740b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
741b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
742b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam_subobj_t* pam;
743b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
744b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL != this) {
745b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam = (pam_subobj_t *) this->subObj;
746b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        mm = mm; /* avoid warning "var not used in this function"*/
747b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        /*-----------------------------------------------------------------
748b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen         * Memory de-allocations
749b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen         * ------------------------------------------------------------------*/
750b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (pam->sSyllFeats != NULL) {
751b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            picoos_deallocate(this->common->mm, (void *) &pam->sSyllFeats);
752b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
753b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (pam->sPhIds != NULL) {
754b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            picoos_deallocate(this->common->mm, (void *) &pam->sPhIds);
755b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
756b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (pam->sPhFeats != NULL) {
757b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            picoos_deallocate(this->common->mm, (void *) &pam->sPhFeats);
758b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
759b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (pam->sSyllItems != NULL) {
760b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            picoos_deallocate(this->common->mm, (void *) &pam->sSyllItems);
761b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
762b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (pam->sSyllItemOffs != NULL) {
763b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            picoos_deallocate(this->common->mm, (void *) &pam->sSyllItemOffs);
764b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
765b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_deallocate(this->common->mm, (void *) &this->subObj);
766b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
767b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
768b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
769b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pam_subobj_deallocate*/
770b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
771b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
772b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * creates a new pam processing unit
773b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    mm    : engine memory manager
774b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    common : engine common object pointer
775b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    cbIn : pointer to input buffer
776b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    cbOut : pointer to output buffer
777b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    voice : pointer to voice structure
778b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return this : pam PU handle if success
779b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    NULL : if error
780b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
781b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
782b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
783b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenpicodata_ProcessingUnit picopam_newPamUnit(picoos_MemoryManager mm,
784b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_Common common, picodata_CharBuffer cbIn,
785b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picodata_CharBuffer cbOut, picorsrc_Voice voice)
786b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
787b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
788b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    register pam_subobj_t * pam;
789b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
790b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picodata_ProcessingUnit this = picodata_newProcessingUnit(mm, common, cbIn,
791b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            cbOut, voice);
792b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (this == NULL) {
793b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return NULL;
794b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
795b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    this->initialize = pam_initialize;
796b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
797b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    PICODBG_DEBUG(("picotok_newPamUnit -- set this->step to pam_step"));
798b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
799b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    this->step = pam_step;
800b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    this->terminate = pam_terminate;
801b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    this->subDeallocate = pam_subobj_deallocate;
802b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    this->subObj = picoos_allocate(mm, sizeof(pam_subobj_t));
803b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (this->subObj == NULL) {
804b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        PICODBG_ERROR(("Error in Pam Object allocation"));
805b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_deallocate(mm, (void*) &this);
806b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return NULL;
807b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    };
808b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
809b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*-----------------------------------------------------------------
810b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     * Allocate internal memory for PAM (only at PU creation time)
811b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     * ------------------------------------------------------------------*/
812b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
813b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (PICO_OK != pam_allocate(mm, pam)) {
814b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        PICODBG_ERROR(("Error in Pam buffers Allocation"));
815b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_deallocate(mm, (void *) &this->subObj);
816b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_deallocate(mm, (void *) &this);
817b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return NULL;
818b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
819b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
820b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*-----------------------------------------------------------------
821b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     * Initialize memory for PAM (this may be re-used elsewhere, e.g.Reset)
822b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     * ------------------------------------------------------------------*/
8237bc39b0d41efe0d8733490d54e14bc392d9f0b6dJean-Michel Trivi    if (PICO_OK != pam_initialize(this, PICO_RESET_FULL)) {
824b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        PICODBG_ERROR(("problem initializing the pam sub-object"));
825b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
826b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return this;
827b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*picopam_newPamUnit*/
828b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
829b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/*-------------------------------------------------------------------------------
830b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen PROCESSING AND INTERNAL FUNCTIONS
831b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen --------------------------------------------------------------------------------*/
832b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
833b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
834b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * initializes default duration limits for boundary items
835b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    uBoundType : type of input boundary type
836b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    *uMinDur, *uMaxDur : addresses of values to initialize
837b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return  void
838b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks    so far initializes to 0 both values; this will leave the values given by tree prediction
839b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
840b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
841b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
842b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic void get_default_boundary_limit(picoos_uint8 uBoundType,
843b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint16 *uMinDur, picoos_uint16 *uMaxDur)
844b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
845b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    switch (uBoundType) {
846b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEMINFO1_BOUND_SBEG:
847b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            *uMinDur = 0;
848b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            *uMaxDur = 20;
849b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
850b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEMINFO1_BOUND_SEND:
851b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            *uMinDur = 550;
852b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            *uMaxDur = 650;
853b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
854b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEMINFO1_BOUND_TERM:
855b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            *uMinDur = 0;
856b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            *uMaxDur = 0;
857b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
858b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEMINFO1_BOUND_PHR0:
859b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            *uMinDur = 0;
860b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            *uMaxDur = 0;
861b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
862b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEMINFO1_BOUND_PHR1:
863b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            *uMinDur = 275;
864b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            *uMaxDur = 325;
865b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
866b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEMINFO1_BOUND_PHR2:
867b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            *uMinDur = 4;
868b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            *uMaxDur = 60;
869b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
870b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEMINFO1_BOUND_PHR3:
871b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            *uMinDur = 0;
872b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            *uMaxDur = 0;
873b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
874b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        default:
875b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
876b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
877b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
878b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*get_default_boundary_limit*/
879b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
880b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
881b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * checks if "neededSize" is available on "nCurrPhoneme"
882b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    pam : pam subobj
883b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    neededSize : the requested size
884b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_OK : size is available
885b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    !=PICO_OK : size not available
886b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
887b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
888b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
889b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t check_phones_size(pam_subobj_t *pam,
890b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_int16 neededSize)
891b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
892b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if ((pam->nCurrPhoneme + neededSize) > PICOPAM_MAX_PH_PER_SENT - 1) {
893b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
894b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
895b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
896b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*check_phones_size*/
897b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
898b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
899b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * checks if neededSize is available on "nCurrSyllable"
900b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    pam : pam subobj
901b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    neededSize : the requested size
902b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_OK : size is available
903b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    !=PICO_OK : size not available
904b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
905b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
906b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
907b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t check_syllables_size(pam_subobj_t *pam,
908b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_int16 neededSize)
909b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
910b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if ((pam->nCurrSyllable + neededSize) > PICOPAM_MAX_SYLL_PER_SENT - 1) {
911b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
912b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
913b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
914b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*check_syllables_size*/
915b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
916b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
917b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * verifies that local storage has enough space to receive 1 item
918b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : pointer to current PU struct
919b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    item : pointer to current item head
920b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    TRUE : resource limits would be reached during processing of input item
921b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    FALSE : item could be processed normally
922b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks item pointed to by *item should be already valid
923b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
924b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
925b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
926b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pamCheckResourceLimits(
927b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        register picodata_ProcessingUnit this, const picoos_uint8 *item)
928b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
929b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    register pam_subobj_t * pam;
930b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picodata_itemhead_t head;
931b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pico_status_t sResult;
932b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
933b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
934b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
935b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
936b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sResult = TRUE; /*default : resource limits reached*/
937b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    head.type = item[0];
938b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    head.info1 = item[1];
939b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    head.info2 = item[2];
940b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    head.len = item[3];
941b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
942b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    switch (head.type) {
943b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        /*commands that generate syllables/phonemes*/
944b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEM_SYLLPHON:
945b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            if (pam->nCurrSyllable >= PICOPAM_MAX_SYLL_PER_SENT - 2) {
946b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                return sResult; /*no room for more syllables*/
947b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            }
948b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            if ((pam->nCurrPhoneme + head.len) >= PICOPAM_MAX_PH_PER_SENT - 2) {
949b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                return sResult; /*no room for more phoneme*/
950b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            }
951b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
952b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEM_BOUND:
953b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            if ((head.info1 == PICODATA_ITEMINFO1_BOUND_SBEG) || (head.info1
954b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    == PICODATA_ITEMINFO1_BOUND_SEND) || (head.info1
955b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    == PICODATA_ITEMINFO1_BOUND_TERM) || (head.info1
956b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    == PICODATA_ITEMINFO1_BOUND_PHR1)
957b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#ifdef PAM_PHR2_WITH_PR1
958b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    || (head.info1 == PICODATA_ITEMINFO1_BOUND_PHR2)
959b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#endif
960b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            ) {
961b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
962b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                if (pam->nCurrSyllable >= PICOPAM_MAX_SYLL_PER_SENT - 2) {
963b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    return sResult; /*no room for more syllables*/
964b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                }
965b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                if ((pam->nCurrPhoneme + 1) >= PICOPAM_MAX_PH_PER_SENT - 2) {
966b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    return sResult; /*no room for more phoneme*/
967b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                }
968b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            }
969b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
970b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
971b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        default:
972b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            /*all other commands has to be queued*/
973b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            if ((pam->nAttachedItemsSize + head.len)
974b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    >= PICOPAM_MAX_ITEM_SIZE_PER_SENT - 1) {
975b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                return sResult; /*no room for more items*/
976b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            }
977b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
978b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
979b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return FALSE; /*no resource limits apply to current item*/
980b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} /*pamCheckResourceLimits*/
981b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
982b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
983b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * selects items to be sent to next PU immedately
984b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : pointer to current PU struct
985b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    item : pointer to current item head
986b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    TRUE : item should be passed on next PU NOW
987b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    FALSE : item should not be passed on next PU now but should be processed
988b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks item pointed to by *item should be already valid
989b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
990b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
991b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
992b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_check_immediate(register picodata_ProcessingUnit this,
993b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        const picoos_uint8 *item)
994b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
995b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    register pam_subobj_t * pam;
996b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
997b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
998b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
999b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1000b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1001b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nCurrSyllable <= -1) {
1002b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (item[0] == PICODATA_ITEM_SYLLPHON)
1003b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            return FALSE;
1004b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if ((item[0] == PICODATA_ITEM_BOUND) && (item[1]
1005b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                == PICODATA_ITEMINFO1_BOUND_SBEG))
1006b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            return FALSE;
1007b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (is_pam_command((picoos_uint8 *) item) == TRUE)
1008b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            return FALSE;
1009b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return TRUE; /*no need to process data : send it*/
1010b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1011b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return FALSE; /*syllable struct not void : do standard processing*/
1012b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1013b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} /*pam_check_immediate*/
1014b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1015b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1016b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * checks if the input item has to be queued in local storage for later resynch
1017b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : pointer to current PU struct
1018b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    item : pointer to current item head
1019b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    TRUE : item should be queued
1020b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    FALSE : item should not be queued
1021b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks item pointed to by *item should be already valid
1022b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1023b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1024b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1025b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_hastobe_queued(register picodata_ProcessingUnit this,
1026b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        const picoos_uint8 *item)
1027b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1028b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    register pam_subobj_t * pam;
1029b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picodata_itemhead_t head;
1030b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
1031b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
1032b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1033b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1034b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    head.type = item[0];
1035b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    head.info1 = item[1];
1036b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1037b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    switch (head.type) {
1038b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        /*commands that generate syllables/phonemes*/
1039b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEM_SYLLPHON:
1040b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            return FALSE; /*no queue needed*/
1041b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
1042b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEM_BOUND:
1043b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            if ((head.info1 == PICODATA_ITEMINFO1_BOUND_PHR3)
1044b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#ifdef PAM_PHR2_WITH_PR3
1045b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    ||(head.info1==PICODATA_ITEMINFO1_BOUND_PHR2)
1046b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen#endif
1047b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    || (head.info1 == PICODATA_ITEMINFO1_BOUND_PHR0)) {
1048b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                return FALSE; /*no queue needed*/
1049b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            }
1050b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
1051b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1052b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        default:
1053b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            /*all other items has to be queued*/
1054b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
1055b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1056b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return TRUE; /*item has to be queued*/
1057b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} /*pam_hastobe_queued*/
1058b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1059b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1060b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * queue item in local storage for later resynch
1061b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : pointer to current PU struct
1062b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    item : pointer to current item head
1063b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    TRUE : item queued
1064b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    FALSE : item not queued because of errors
1065b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks item pointed to by *item should be already valid
1066b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1067b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1068b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1069b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_queue(register picodata_ProcessingUnit this,
1070b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        const picoos_uint8 *item)
1071b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1072b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    register pam_subobj_t * pam;
1073b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picodata_itemhead_t head;
1074b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 nI;
1075b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pico_status_t sResult;
1076b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
1077b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
1078b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1079b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1080b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sResult = TRUE; /*default : item queued*/
1081b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    head.type = item[0];
1082b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    head.info1 = item[1];
1083b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    head.info2 = item[2];
1084b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    head.len = item[3];
1085b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1086b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*test condition on enough room to store current item in the "sSyllItems" area*/
1087b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if ((pam->nAttachedItemsSize + head.len + sizeof(picodata_itemhead_t))
1088b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            >= PICOPAM_MAX_ITEM_SIZE_PER_SENT - 1) {
1089b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return FALSE; /*resource limit reached*/
1090b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1091b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*store current offset*/
1092b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sSyllItemOffs[pam->nLastAttachedItemId] = pam->nAttachedItemsSize;
1093b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*store the item to the "sSyllItems" area*/
1094b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < (head.len + sizeof(picodata_itemhead_t)); nI++) {
1095b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->sSyllItems[pam->nAttachedItemsSize + nI] = item[nI];
1096b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1097b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*increment the attached items area*/
1098b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->nAttachedItemsSize += nI;
1099b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1100b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*increment id*/
1101b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->nLastAttachedItemId++;
1102b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*set start(if not initialized) and end ids of queued items in sSyllFeats*/
1103b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nCurrSyllable > -1) {
1104b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        /*normal case : the item is attached to current syllable*/
1105b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[ITM] == 0) {
1106b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            pam->sSyllFeats[pam->nCurrSyllable].phoneV[ITM]
1107b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    = pam->nLastAttachedItemId;
1108b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
1109b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm]
1110b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                = pam->nLastAttachedItemId;
1111b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    } else {
1112b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        /*special case : an item is requested to be queued even if no
1113b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen         syllables has been assigned to the sentence structure :
1114b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen         -->> use syll 0*/
1115b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (pam->sSyllFeats[0].phoneV[ITM] == 0) {
1116b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            pam->sSyllFeats[0].phoneV[ITM] = pam->nLastAttachedItemId;
1117b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
1118b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->sSyllFeats[0].phoneV[itm] = pam->nLastAttachedItemId;
1119b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1120b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return TRUE; /*item queued successfully*/
1121b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} /*pam_queue*/
1122b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1123b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1124b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * selects items to be dealth with by the PU processing
1125b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    item : pointer to current item head
1126b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    TRUE : item should be processed
1127b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    FALSE : item should not be processed (maybe it ontains commands or items for other PUs)
1128b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks item pointed to by *item should be already valid
1129b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1130b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1131b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1132b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_deal_with(const picoos_uint8 *item)
1133b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1134b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picodata_itemhead_t head;
1135b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pico_status_t sResult;
1136b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sResult = FALSE;
1137b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    head.type = item[0];
1138b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    head.info1 = item[1];
1139b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    head.info2 = item[2];
1140b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    head.len = item[3];
1141b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    switch (head.type) {
1142b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEM_SYLLPHON:
1143b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEM_BOUND:
1144b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            sResult = TRUE;
1145b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
1146b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        default:
1147b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
1148b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1149b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return sResult;
1150b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} /*pam_deal_with*/
1151b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1152b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1153b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * returns true if more items has to be produced for current syllable
1154b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam object pointer
1155b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    TRUE : item is to be produced
1156b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    FALSE : item is not to be produced
1157b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks item pointed to by *item should be already valid
1158b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1159b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1160b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1161b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic picoos_uint8 pamHasToProcess(register picodata_ProcessingUnit this)
1162b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1163b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    register pam_subobj_t * pam;
1164b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 nCond1, nCond2, nCond3;
1165b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1166b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
1167b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
1168b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1169b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1170b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*conditions originating a "NOT to be processed" result */
1171b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    nCond1 = pam->nCurrSyllable <= -1;
1172b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    nCond2 = pam->nCurrSyllable >= pam->nTotalSyllables;
1173b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    nCond3 = pam->nSyllPhoneme
1174b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            >= pam->sSyllFeats[pam->nCurrSyllable].phoneV[B3];
1175b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1176b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if ((nCond1) || (nCond2) || (nCond3))
1177b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return FALSE;
1178b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1179b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return TRUE;
1180b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} /*pamHasToProcess*/
1181b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1182b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1183b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * modifies the process flags in order to point to next valid syllable phone or item to be produced
1184b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam object pointer
1185b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    TRUE : item has to be produced
1186b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    FALSE : item has not to be produced
1187b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1188b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1189b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1190b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pamUpdateProcess(register picodata_ProcessingUnit this)
1191b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1192b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    register pam_subobj_t * pam;
1193b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1194b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
1195b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
1196b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1197b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1198b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1199b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nCurrSyllable == -1) {
1200b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        /*this to be able to manage sudden PU cleanup after FLUSH CMD*/
1201b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_OK;
1202b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1203b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*check number of phonemes for current syllable*/
1204b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nSyllPhoneme < pam->sSyllFeats[pam->nCurrSyllable].phoneV[B3] - 1) {
1205b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->nSyllPhoneme++;
1206b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_OK;
1207b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1208b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nSyllPhoneme == pam->sSyllFeats[pam->nCurrSyllable].phoneV[B3] - 1) {
1209b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        /*this helps in identifyng the end of syllable condition in PamHasToProcess*/
1210b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->nSyllPhoneme++;
1211b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1212b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*previous syllable phonemes are complete: test if any items are tied to this syllable*/
1213b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[ITM] > 0) {
1214b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        /*there are items tied to this syllable*/
1215b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (pam->nCurrAttachedItem == 0) {
1216b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            /*if it is the first item to be regenerated initialize it*/
1217b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            pam->nCurrAttachedItem
1218b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    = pam->sSyllFeats[pam->nCurrSyllable].phoneV[ITM];
1219b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            return PICO_OK;
1220b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        } else {
1221b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            /*not the first item : check if more*/
1222b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            if (pam->nCurrAttachedItem
1223b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    < pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm]) {
1224b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                /*more tied items to be regenerated*/
1225b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                pam->nCurrAttachedItem++;
1226b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                return PICO_OK;
1227b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            }
1228b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
1229b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1230b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*previous syllable phonemes and items are complete: switch to next syllable*/
1231b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nCurrSyllable < pam->nTotalSyllables - 1) {
1232b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->nCurrSyllable++;
1233b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->nSyllPhoneme = 0;
1234b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->nCurrAttachedItem = 0;
1235b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_OK;
1236b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1237b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*no more phonemes or items to be produced*/
1238b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->nCurrSyllable++;
1239b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->nSyllPhoneme = 0;
1240b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_ERR_OTHER;
1241b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1242b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} /*pamUpdateProcess*/
1243b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1244b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1245b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * returns true if more items has to be popped for current syllable
1246b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam object pointer
1247b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    TRUE : item has to be popped
1248b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    FALSE : item has not to be popped
1249b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1250b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1251b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1252b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic picoos_uint8 pamHasToPop(register picodata_ProcessingUnit this)
1253b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1254b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    register pam_subobj_t * pam;
1255b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1256b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
1257b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
1258b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1259b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1260b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1261b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*Preliminary condition : at least 1 syllable*/
1262b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nCurrSyllable <= -1)
1263b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return FALSE;
1264b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1265b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*Preliminary condition : not maximum number of syllables*/
1266b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nCurrSyllable >= pam->nTotalSyllables)
1267b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return FALSE;
1268b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1269b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*Preliminary condition : start and end offset in current item > 0 */
1270b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if ((pam->sSyllFeats[pam->nCurrSyllable].phoneV[ITM] <= 0)
1271b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            || (pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm] <= 0))
1272b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return FALSE;
1273b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1274b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*Final condition : current popped item less or eq to maximum*/
1275b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nCurrAttachedItem
1276b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            > pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm])
1277b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return FALSE;
1278b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1279b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return TRUE;
1280b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} /*pamHasToPop*/
1281b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1282b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1283b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * returns the address of an item to be popped from the current syllable queue
1284b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam object pointer
1285b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    pop_address : item address
1286b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    NULL : item not poppable
1287b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1288b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1289b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1290b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic picoos_uint8 *pamPopItem(register picodata_ProcessingUnit this)
1291b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1292b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    register pam_subobj_t * pam;
1293b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 nItem;
1294b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
1295b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return NULL;
1296b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1297b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1298b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1299b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*Preliminary condition : at least 1 syllable*/
1300b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nCurrSyllable <= -1)
1301b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return NULL;
1302b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1303b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*Preliminary condition : not maximum number of syllables*/
1304b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nCurrSyllable >= pam->nTotalSyllables)
1305b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return NULL;
1306b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1307b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*Preliminary condition : start and end offset in current item > 0 */
1308b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if ((pam->sSyllFeats[pam->nCurrSyllable].phoneV[ITM] <= 0)
1309b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            || (pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm] <= 0))
1310b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return NULL;
1311b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1312b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*Final condition : current popped item less than maximum*/
1313b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nCurrAttachedItem
1314b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            > pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm])
1315b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return NULL;
1316b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1317b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    nItem = pam->nCurrAttachedItem;
1318b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*please note : nItem-1 should match with actions performed in function "pam_queue(..)" */
1319b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return &(pam->sSyllItems[pam->sSyllItemOffs[nItem - 1]]);
1320b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1321b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} /*pamPopItem*/
1322b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1323b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1324b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * returns the address of an item popped from the syllable 0 queue
1325b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam object pointer
1326b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    pop_address : item address
1327b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    NULL : item not poppable
1328b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks the item is popped only if it has been inserted in the queue before the first
1329b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks item assigned to the syllable 0 i.e.
1330b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks AttachedItem<=pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm]-1
1331b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1332b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1333b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1334b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic picoos_uint8 *pamPopAttachedSy0(register picodata_ProcessingUnit this)
1335b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1336b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    register pam_subobj_t * pam;
1337b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 nItem;
1338b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
1339b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return NULL;
1340b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1341b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1342b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1343b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*should be syllable 0*/
1344b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nCurrSyllable != 0)
1345b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return NULL;
1346b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1347b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*start and end offset in current item > 0 */
1348b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if ((pam->sSyllFeats[pam->nCurrSyllable].phoneV[ITM] <= 0)
1349b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            || (pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm] <= 0))
1350b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return NULL;
1351b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1352b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*if current popped item is > 0 test end condition*/
1353b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nCurrAttachedItem > 0) {
1354b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        /*Other condition : current popped item less than maximum*/
1355b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (pam->nCurrAttachedItem
1356b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                > pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm] - 1)
1357b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            return NULL;
1358b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1359b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    nItem = pam->nCurrAttachedItem;
1360b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return &(pam->sSyllItems[pam->sSyllItemOffs[nItem]]);
1361b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1362b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen} /*pamPopAttachedSy0*/
1363b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1364b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1365b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * pdf access for duration
1366b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam object pointer
1367b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    durIndex : index of duration in the pdf
1368b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    phonDur : pointer to base of array where to store the duration values
1369b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    numFramesState : pointer to base of array where to store the number of frames per state
1370b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_OK : pdf retrieved
1371b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_ERR_OTHER : pdf not retrieved
1372b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks Modifies phonDur (the requested duration value)
1373b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks Modifies numFramesState (the requested number of frames per state (vector))
1374b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1375b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1376b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1377b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_get_duration(register picodata_ProcessingUnit this,
1378b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint16 durIndex, picoos_uint16 *phonDur,
1379b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint8 *numFramesState)
1380b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1381b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam_subobj_t *pam;
1382b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picokpdf_PdfDUR pdf;
1383b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 *durItem;
1384b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint16 nFrameSize, nI;
1385b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_single fValue;
1386b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1387b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
1388b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
1389b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1390b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pdf = pam->pdfdur;
1391b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*make the index 0 based*/
1392b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (durIndex > 0)
1393b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        durIndex--;
1394b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1395b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /* check */
1396b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (durIndex > pdf->numframes - 1) {
1397b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        PICODBG_ERROR(("PAM durPdf access error, index overflow -> index: %d , numframes: %d", durIndex, pdf->numframes));
1398b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
1399b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1400b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /* base pointer */
1401b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    durItem = &(pdf->content[durIndex * pdf->vecsize]);
1402b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (durItem == NULL) {
1403b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        PICODBG_ERROR(("PAM durPdf access error , frame pointer = NULL"));
1404b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
1405b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1406b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    nFrameSize = pdf->sampperframe / 16;
1407b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    *phonDur = ((pdf->phonquant[((*durItem) & 0xF0) >> 4]) * nFrameSize);
1408b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    numFramesState[0] = pdf->statequant[((*durItem) & 0x0F)];
1409b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    durItem++;
1410b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    numFramesState[1] = pdf->statequant[((*durItem) & 0xF0) >> 4];
1411b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    numFramesState[2] = pdf->statequant[((*durItem) & 0x0F)];
1412b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    durItem++;
1413b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    numFramesState[3] = pdf->statequant[((*durItem) & 0xF0) >> 4];
1414b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    numFramesState[4] = pdf->statequant[((*durItem) & 0x0F)];
1415b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1416b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*modification of the duration information based on the duration modifier*/
1417b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    *phonDur = (picoos_uint16) (((picoos_single) * phonDur) * pam->dMod);
1418b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < 5; nI++) {
1419b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        fValue = pam->dRest + (picoos_single) numFramesState[nI] * pam->dMod;
1420b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        numFramesState[nI] = (picoos_uint8) (fValue);
1421b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->dRest = fValue - (picoos_single) numFramesState[nI];
1422b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1423b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
1424b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pam_get_duration*/
1425b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1426b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1427b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * pdf access for pitch
1428b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam object pointer
1429b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    lf0Index : pointer to variable to receive index of pitch in the pdf
1430b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    nI : number of the phone's state
1431b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    phonF0 : pointer to variable to receive the pitch value
1432b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_OK : pdf retrieved
1433b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_ERR_OTHER : pdf not retrieved
1434b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks Modifies phonDur (the requested duration value)
1435b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks Modifies phonF0 (the requested pitch value (scalar))
1436b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1437b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1438b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1439b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_get_f0(register picodata_ProcessingUnit this,
1440b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint16 *lf0Index, picoos_uint8 nI, picoos_single *phonF0)
1441b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1442b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam_subobj_t *pam;
1443b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 *lfItem, numstreams;
1444b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint16 lf0IndexOffset, sTemp;
1445b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_single lfum, lfivar, lfz;
1446b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1447b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1448b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
1449b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
1450b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1451b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    lf0IndexOffset = lf0Index[nI];
1452b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1453b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*make the index 0 based*/
1454b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (lf0IndexOffset > 0)
1455b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        lf0IndexOffset--;
1456b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1457b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    lf0IndexOffset += pam->pdflfz->stateoffset[nI];
1458b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (lf0IndexOffset > pam->pdflfz->numframes - 1) {
1459b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        PICODBG_ERROR(("PAM flfzPdf access error, index overflow -> index: %d , numframes: %d", lf0Index, pam->pdflfz->numframes));
1460b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
1461b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1462b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /* base pointer */
1463b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    lf0IndexOffset *= pam->pdflfz->vecsize;
1464b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1465b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    lfItem = &(pam->pdflfz->content[lf0IndexOffset]);
1466b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sTemp = (picoos_uint16) (((lfItem[1] << 8)) | lfItem[0]);
1467b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1468b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    lfum = (picoos_single) (sTemp << (pam->pdflfz->meanpowUm[0]));
1469b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    numstreams = 3;
1470b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    lfivar = (picoos_single) (((picoos_uint16) lfItem[numstreams * 2])
1471b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            << pam->pdflfz->ivarpow[0]);
1472b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    lfz = (picoos_single) lfum / (picoos_single) lfivar;
1473b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    lfz = (picoos_single) exp((double) lfz);
1474b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    phonF0[nI] = (picoos_single) lfz;
1475b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1476b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*pitch modoification*/
1477b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    phonF0[nI] *= pam->pMod;
1478b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
1479b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pam_get_f0*/
1480b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1481b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1482b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * elementary rounding function
1483b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    fIn : (real) input value
1484b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    the rounded value
1485b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1486b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1487b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1488b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic picoos_single f_round(picoos_single fIn)
1489b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1490b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int32 iVal;
1491b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_single fVal;
1492b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1493b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    iVal = (picoos_int32) fIn;
1494b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    fVal = (picoos_single) iVal;
1495b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1496b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (fIn > (picoos_single) 0.0f) {
1497b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if ((fIn - fVal) < (picoos_single) 0.5f)
1498b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            return fVal;
1499b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        else
1500b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            return fVal + (picoos_single) 1.0f;
1501b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    } else {
1502b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if ((fVal - fIn) < (picoos_single) 0.5f)
1503b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            return fVal;
1504b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        else
1505b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            return fVal - (picoos_single) 1.0f;
1506b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1507b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*f_round*/
1508b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1509b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1510b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * updates the input vector for PAM
1511b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam object pointer
1512b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_OK : update successful
1513b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_ERR_OTHER : errors on retrieving the PU pointer
1514b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks Modifies pam->sPhFeats[]
1515b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1516b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1517b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1518b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_update_vector(register picodata_ProcessingUnit this)
1519b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1520b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam_subobj_t *pam;
1521b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 numstates, nI;
1522b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_single fDur, f0avg, f0quant, minf0, maxf0, durquant1, durquant2,
1523b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            mindur, maxdur1, maxdur2;
1524b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1525b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1526b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
1527b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
1528b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1529b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*default init*/
1530b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sPhFeats[DUR] = 0;
1531b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sPhFeats[F0] = 0;
1532b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*
1533b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     Hard coded parameters for quantization
1534b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     */
1535b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    numstates = PICOPAM_NRSTPF;
1536b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    f0quant = 30.0f;
1537b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    minf0 = 90.0f;
1538b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    maxf0 = 360.0f;
1539b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1540b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    durquant1 = 20.0f;
1541b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    durquant2 = 100.0f;
1542b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    mindur = 40.0f;
1543b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    maxdur1 = 160.0f;
1544b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    maxdur2 = 600.0f;
1545b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    f0avg = 0.0f;
1546b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < numstates; nI++)
1547b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        f0avg += pam->phonF0[nI];
1548b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    f0avg /= (picoos_single) numstates;
1549b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1550b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    f0avg = f_round(f0avg / f0quant) * f0quant;
1551b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (f0avg < minf0)
1552b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        f0avg = minf0;
1553b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (f0avg > maxf0)
1554b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        f0avg = maxf0;
1555b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1556b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*make initial silence of sentence shorter (see also pam_put_item)*/
1557b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if ((pam->nCurrSyllable == 0) && (pam->nSyllPhoneme == 0)) {
1558b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->phonDur = 2 * 4;
1559b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1560b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1561b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    fDur = (picoos_single) pam->phonDur;
1562b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    fDur = f_round(fDur / durquant1) * durquant1;
1563b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (fDur < mindur)
1564b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        fDur = mindur;
1565b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (fDur > maxdur1) {
1566b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        fDur = f_round(fDur / durquant2) * durquant2;
1567b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (fDur > maxdur2)
1568b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            fDur = maxdur2;
1569b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1570b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sPhFeats[DUR] = (picoos_uint8) (fDur / (picoos_single) 10.0f);
1571b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->sPhFeats[F0] = (picoos_uint8) (f0avg / (picoos_single) 10.0f);
1572b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1573b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
1574b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pam_update_vector*/
1575b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1576b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1577b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * compress a single feature in the range 0..9
1578b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    inVal : the value to be compressed
1579b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    compVal : the compressed value
1580b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1581b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1582b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1583b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic picoos_uint8 pamCompressComponent(picoos_uint8 inVal)
1584b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1585b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (inVal <= 5)
1586b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return inVal;
1587b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if ((5 < inVal) && (inVal <= 10))
1588b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return 6;
1589b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if ((10 < inVal) && (inVal <= 20))
1590b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return 7;
1591b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if ((20 < inVal) && (inVal <= 30))
1592b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return 8;
1593b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return 9;
1594b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pamCompressComponent*/
1595b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1596b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1597b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * prepares the input vector for tree feeding
1598b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam object pointer
1599b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_OK : vector expanded
1600b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_ERR_OTHER : errors on expansion or retrieving the PU pointer
1601b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks Modifies pam->sPhFeats[]
1602b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1603b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1604b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1605b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_expand_vector(register picodata_ProcessingUnit this)
1606b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1607b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam_subobj_t *pam;
1608b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 *inVect, *phonVect, *outVect, nI;
1609b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int16 nOffs, nOffs1, nLen;
1610b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1611b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
1612b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
1613b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1614b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    inVect = &(pam->sSyllFeats[pam->nCurrSyllable].phoneV[0]);
1615b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    phonVect = &(pam->sPhIds[0]);
1616b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    outVect = &(pam->sPhFeats[0]);
1617b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*just copy back*/
1618b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < PICOPAM_INVEC_SIZE; nI++)
1619b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        outVect[nI] = inVect[nI];
1620b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*now fill missing fields*/
1621b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_mem_copy((void*) &(inVect[FID]), &nOffs, sizeof(nOffs));
1622b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*offset to first phone of current syllable*/
1623b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    nOffs = nOffs + pam->nSyllPhoneme; /*offset to current phone of current syllable*/
1624b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    nLen = inVect[B3]; /*len of current syllable*/
1625b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nSyllPhoneme >= nLen) {
1626b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        /*error on addressing current phone*/
1627b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICO_ERR_OTHER;
1628b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1629b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*previous of the previous phone*/
1630b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    nOffs1 = nOffs - 2;
1631b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (nOffs1 >= 0)
1632b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        outVect[P1] = phonVect[nOffs1];
1633b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    else
1634b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        outVect[P1] = PICOPAM_PH_DONT_CARE_VAL;
1635b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*previous  phone*/
1636b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    nOffs1 = nOffs - 1;
1637b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (nOffs1 >= 0)
1638b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        outVect[P2] = phonVect[nOffs1];
1639b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    else
1640b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        outVect[P2] = PICOPAM_PH_DONT_CARE_VAL;
1641b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*^current phone*/
1642b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    outVect[P3] = phonVect[nOffs];
1643b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1644b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*next phone*/
1645b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    nOffs1 = nOffs + 1;
1646b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (nOffs1 < pam->nTotalPhonemes)
1647b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        outVect[P4] = phonVect[nOffs1];
1648b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    else
1649b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        outVect[P4] = PICOPAM_PH_DONT_CARE_VAL;
1650b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*next of the next phone*/
1651b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    nOffs1 = nOffs + 2;
1652b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (nOffs1 < pam->nTotalPhonemes)
1653b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        outVect[P5] = phonVect[nOffs1];
1654b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    else
1655b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        outVect[P5] = PICOPAM_PH_DONT_CARE_VAL;
1656b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*pos of curr phone with respect to left syllable boundary*/
1657b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    outVect[P6] = pam->nSyllPhoneme + 1;
1658b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*pos of curr phone with respect to right syllable boundary*/
1659b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    outVect[P7] = nLen - pam->nSyllPhoneme;
1660b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*is current phone in consonant syllable boundary? (1:yes)*/
1661b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (pam->nSyllPhoneme < inVect[P8])
1662b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        outVect[P8] = 1;
1663b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    else
1664b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        outVect[P8] = 0;
1665b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
1666b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pam_expand_vector*/
1667b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1668b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1669b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * compresses the input vector for PAM
1670b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam object pointer
1671b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_OK : compression successful
1672b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_ERR_OTHER : errors on retrieving the PU pointer
1673b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks Modifies pam->sPhFeats[]
1674b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1675b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1676b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1677b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pamCompressVector(register picodata_ProcessingUnit this)
1678b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1679b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam_subobj_t *pam;
1680b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 *outVect, nI;
1681b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1682b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
1683b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
1684b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1685b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    outVect = &(pam->sPhFeats[0]);
1686b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < PICOPAM_INVEC_SIZE; nI++) {
1687b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        switch (nI) {
1688b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case P1:
1689b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case P2:
1690b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case P3:
1691b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case P4:
1692b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case P5:
1693b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case B1:
1694b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case B2:
1695b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case B16:
1696b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case E1:
1697b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case H5:
1698b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                /*don't do any compression*/
1699b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1700b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            default:
1701b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                /*do compression*/
1702b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                if (outVect[nI] != PICOPAM_DONT_CARE_VALUE)
1703b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    outVect[nI] = pamCompressComponent(outVect[nI]);
1704b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                else
1705b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    outVect[nI] = PICOPAM_DONT_CARE_VAL;
1706b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1707b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
1708b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1709b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
1710b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pamCompressVector*/
1711b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1712b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1713b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * reorganizes the input vector for PAM
1714b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam object pointer
1715b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_OK : reorganization successful
1716b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_ERR_OTHER : errors on retrieving the PU pointer
1717b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks Modifies pam->sPhFeats[]
1718b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1719b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1720b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1721b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pamReorgVector(register picodata_ProcessingUnit this)
1722b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1723b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam_subobj_t *pam;
1724b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 *outVect, inVect[60], nI;
1725b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1726b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
1727b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
1728b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1729b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    outVect = &(pam->sPhFeats[0]);
1730b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < PICOPAM_INVEC_SIZE; nI++) inVect[nI] = outVect[nI];
1731b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*reorganize*/
1732b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = T_B1; nI <= T_H5; nI++) {
1733b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        switch (nI) {
1734b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B1:
1735b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B1] = inVect[B1];
1736b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1737b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B2:
1738b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B2] = inVect[B2];
1739b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1740b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B3:
1741b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B3] = inVect[B3];
1742b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1743b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B4:
1744b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B4] = inVect[B4];
1745b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1746b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B5:
1747b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B5] = inVect[B5];
1748b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1749b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B6:
1750b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B6] = inVect[B6];
1751b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1752b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B7:
1753b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B7] = inVect[B7];
1754b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1755b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B8:
1756b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B8] = inVect[B8];
1757b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1758b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B9:
1759b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B9] = inVect[B9];
1760b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1761b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B10:
1762b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B10] = inVect[B10];
1763b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1764b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B11:
1765b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B11] = inVect[B11];
1766b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1767b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B12:
1768b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B12] = inVect[B12];
1769b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1770b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B13:
1771b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B13] = inVect[B13];
1772b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1773b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B14:
1774b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B14] = inVect[B14];
1775b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1776b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B15:
1777b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B15] = inVect[B15];
1778b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1779b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B16:
1780b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B16] = inVect[B16];
1781b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1782b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B17:
1783b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B17] = inVect[B17];
1784b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1785b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B18:
1786b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B18] = inVect[B18];
1787b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1788b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B19:
1789b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B19] = inVect[B19];
1790b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1791b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B20:
1792b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B20] = inVect[B20];
1793b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1794b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_B21:
1795b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_B21] = inVect[B21];
1796b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1797b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1798b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_E1:
1799b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_E1] = inVect[E1];
1800b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1801b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_E2:
1802b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_E2] = inVect[E2];
1803b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1804b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_E3:
1805b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_E3] = inVect[E3];
1806b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1807b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_E4:
1808b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_E4] = inVect[E4];
1809b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1810b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_E5:
1811b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_E5] = inVect[E5];
1812b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1813b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_E6:
1814b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_E6] = inVect[E6];
1815b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1816b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_E7:
1817b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_E7] = inVect[E7];
1818b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1819b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_E8:
1820b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_E8] = inVect[E8];
1821b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1822b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_E9:
1823b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_E9] = inVect[E9];
1824b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1825b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_E10:
1826b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_E10] = inVect[E10];
1827b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1828b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_E11:
1829b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_E11] = inVect[E11];
1830b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1831b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_E12:
1832b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_E12] = inVect[E12];
1833b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1834b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_E13:
1835b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_E13] = inVect[E13];
1836b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1837b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1838b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_A3:
1839b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_A3] = inVect[A3];
1840b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1841b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_C3:
1842b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_C3] = inVect[C3];
1843b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1844b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_D2:
1845b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_D2] = inVect[D2];
1846b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1847b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_F2:
1848b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_F2] = inVect[F2];
1849b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1850b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1851b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_G1:
1852b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_G1] = inVect[G1];
1853b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1854b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_I1:
1855b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_I1] = inVect[I1];
1856b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1857b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1858b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_G2:
1859b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_G2] = inVect[G2];
1860b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1861b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_I2:
1862b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_I2] = inVect[I2];
1863b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1864b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1865b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_H1:
1866b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_H1] = inVect[H1];
1867b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1868b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_H2:
1869b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_H2] = inVect[H2];
1870b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1871b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_H3:
1872b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_H3] = inVect[H3];
1873b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1874b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_H4:
1875b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_H4] = inVect[H4];
1876b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1877b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case T_H5:
1878b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                outVect[T_H5] = inVect[H5];
1879b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
1880b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
1881b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1882b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
1883b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pamReorgVector*/
1884b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1885b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1886b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * puts a PAM item into PU output buffer
1887b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam object pointer
1888b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    outBuff    : output buffer base pointer
1889b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    outWritePos : offset in output buffer
1890b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    *bytesWr : actual bytes written
1891b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_OK : put successful
1892b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_ERR_OTHER : errors on retrieving the PU pointer
1893b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1894b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1895b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1896b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_put_item(register picodata_ProcessingUnit this,
1897b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint8 *outBuff, picoos_uint16 outWritePos, picoos_uint8 *bytesWr)
1898b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1899b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam_subobj_t *pam;
1900b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 *sDest, nI, nType, nIdx, fde;
1901b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint32 pos, pos32;
1902b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_int16 ft, dt;
1903b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint16 uMinDur, uMaxDur;
1904b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
1905b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
1906b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
1907b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1908b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sDest = &(outBuff[outWritePos]);
1909b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sDest[0] = PICODATA_ITEM_PHONE; /*Item type*/
1910b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sDest[1] = pam->sPhFeats[P3]; /*phonetic id*/
1911b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sDest[2] = PICOPAM_NRSTPF; /*number of states per phone*/
1912b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sDest[3] = sizeof(picoos_uint16) * PICOPAM_NRSTPF * 3; /*size of the item*/
1913b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pos = 4;
1914b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*make initial silence of sentence shorter (see also UpdateVector)*/
1915b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if ((pam->nCurrSyllable == 0) && (pam->nSyllPhoneme == 0)) {
1916b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        for (nI = 0; nI < PICOPAM_NRSTPF - 1; nI++)
1917b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            pam->numFramesState[nI] = 0;
1918b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->numFramesState[nI] = 2;
1919b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    } else {
1920b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        /*manage silence syllables with prescribed durations*/
1921b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pos32 = Min;
1922b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_read_mem_pi_uint16(pam->sSyllFeats[pam->nCurrSyllable].phoneV,
1923b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                &pos32, &uMinDur);
1924b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pos32 = Max;
1925b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_read_mem_pi_uint16(pam->sSyllFeats[pam->nCurrSyllable].phoneV,
1926b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                &pos32, &uMaxDur);
1927b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1928b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (uMaxDur > 0) {
1929b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            /* Select weights*/
1930b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            nType = pam->sSyllFeats[pam->nCurrSyllable].phoneV[bnd];
1931b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            switch (nType) {
1932b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                case PICODATA_ITEMINFO1_BOUND_SBEG:
1933b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    nIdx = PICOPAM_PWIDX_SBEG;
1934b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    break;
1935b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                case PICODATA_ITEMINFO1_BOUND_PHR1:
1936b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    nIdx = PICOPAM_PWIDX_PHR1;
1937b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    break;
1938b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                case PICODATA_ITEMINFO1_BOUND_PHR2:
1939b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    nIdx = PICOPAM_PWIDX_PHR2;
1940b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    break;
1941b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                case PICODATA_ITEMINFO1_BOUND_SEND:
1942b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                case PICODATA_ITEMINFO1_BOUND_TERM:
1943b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    nIdx = PICOPAM_PWIDX_SEND;
1944b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    break;
1945b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                default:
1946b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    nIdx = PICOPAM_PWIDX_DEFA;
1947b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    break;
1948b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            }
1949b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            fde = 2;
1950b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            ft = 0;
1951b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            dt = 0;
1952b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            picodata_transformDurations(
1953b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    fde,            /* 2's exponent of frame duration in ms, e.g. 2 for 4ms, 3 for 8ms */
1954b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    PICOPAM_NRSTPF, /* number of states per phone */
1955b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    &(pam->numFramesState[0]), /* estimated durations */
1956b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    pam->sil_weights[nIdx],  /* integer weights */
1957b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    uMinDur,        /* minimum target duration in ms */
1958b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    uMaxDur,        /* maximum target duration in ms */
1959b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    ft,             /* factor to be multiplied to get the target */
1960b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    &dt             /* in/out, rest in ms */
1961b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    );
1962b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
1963b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1964b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*put data*/
1965b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < PICOPAM_NRSTPF; nI++) {
1966b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_write_mem_pi_uint16(sDest, &pos,
1967b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                (picoos_uint16) pam->numFramesState[nI]);
1968b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_write_mem_pi_uint16(sDest, &pos,
1969b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                (picoos_uint16) pam->lf0Index[nI]);
1970b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_write_mem_pi_uint16(sDest, &pos,
1971b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                (picoos_uint16) pam->mgcIndex[nI]);
1972b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1973b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    *bytesWr = sizeof(picodata_itemhead_t) + sizeof(picoos_uint16)
1974b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            * PICOPAM_NRSTPF * 3;
1975b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
1976b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pam_put_item*/
1977b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
1978b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
1979b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * puts a non PAM (queued) item into PU output buffer
1980b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    qItem : pointer to item to put
1981b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    outBuff    : output buffer base pointer
1982b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    outWritePos : offset in output buffer
1983b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    *bytesWr : actual bytes written
1984b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_OK : put successful
1985b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_ERR_OTHER : errors on retrieving the PU pointer
1986b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
1987b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
1988b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
1989b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_put_qItem(picoos_uint8 *qItem, picoos_uint8 *outBuff,
1990b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint16 outWritePos, picoos_uint8 *bytesWr)
1991b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
1992b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 *sDest, nI;
1993b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sDest = &(outBuff[outWritePos]);
1994b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    *bytesWr = sizeof(picodata_itemhead_t);
1995b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < (sizeof(picodata_itemhead_t) + qItem[3]); nI++) {
1996b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        sDest[nI] = qItem[nI];
1997b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
1998b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    *bytesWr = nI;
1999b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
2000b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pam_put_qItem*/
2001b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2002b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
2003b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * tells if an item is a PAM command (except play)
2004b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    qItem : input item to test
2005b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    TRUE : qItem is a PAM command (except play)
2006b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    FALSE : qItem not a PAM command
2007b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
2008b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
2009b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
2010b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t is_pam_command(const picoos_uint8 * qItem)
2011b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
2012b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    switch (qItem[0]) {
2013b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2014b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEM_CMD:
2015b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            switch (qItem[1]) {
2016b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                case PICODATA_ITEMINFO1_CMD_FLUSH:
2017b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    /* flush is for all PU's and as such it is also for PAM*/
2018b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                case PICODATA_ITEMINFO1_CMD_PITCH:
2019b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                case PICODATA_ITEMINFO1_CMD_SPEED:
2020b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    return TRUE;
2021b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    break;
2022b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                default:
2023b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    break;
2024b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            }
2025b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
2026b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return FALSE;
2027b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*is_pam_command*/
2028b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2029b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
2030b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * tells if an item is a PAM PLAY command
2031b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    qItem : input item to test
2032b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    TRUE : qItem is a PAM PLAY command
2033b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    FALSE : qItem not a PAM PLAY command
2034b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
2035b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
2036b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
2037b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t is_pam_play_command(picoos_uint8 *qItem)
2038b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
2039b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    switch (qItem[0]) {
2040b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2041b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEM_CMD:
2042b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            switch (qItem[1]) {
2043b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                case PICODATA_ITEMINFO1_CMD_PLAY:
2044b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    if (qItem[2] == PICODATA_ITEMINFO2_CMD_TO_PAM)
2045b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                        return TRUE;
2046b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    break;
2047b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                default:
2048b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    break;
2049b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            }
2050b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
2051b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return FALSE;
2052b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*is_pam_play_command*/
2053b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2054b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
2055b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * command processor for PAM pu
2056b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam item subobject
2057b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    qItem : input item pointer
2058b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICOPAM_FLUSH_RECEIVED : when a FLUSH is received
2059b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICOPAM_CONTINUE : normal command processing
2060b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICODATA_PU_ERROR : errors in accessing data
2061b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
2062b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
2063b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
2064b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pamDoCommand(register picodata_ProcessingUnit this,
2065b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint8 *qItem)
2066b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
2067b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam_subobj_t *pam;
2068b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_single fValue;
2069b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint16 nValue;
2070b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint32 nPos;
2071b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
2072b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
2073b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
2074b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
2075b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (qItem[0] == PICODATA_ITEM_CMD) {
2076b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        switch (qItem[1]) {
2077b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case PICODATA_ITEMINFO1_CMD_FLUSH:
2078b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                /* flush is for all PU's and as such it is also for PAM : implement the flush!!*/
2079b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                pam_reset_processors(this);
2080b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                pam->nLastAttachedItemId = pam->nCurrAttachedItem = 0;
2081b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                pam->nAttachedItemsSize = 0;
2082b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                return PICOPAM_FLUSH_RECEIVED;
2083b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
2084b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2085b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case PICODATA_ITEMINFO1_CMD_PITCH:
2086b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case PICODATA_ITEMINFO1_CMD_SPEED:
2087b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                nPos = 4;
2088b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                picoos_read_mem_pi_uint16(qItem, &nPos, &nValue);
2089b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                if (qItem[2] == 'a') {
2090b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    /*absloute modifier*/
2091b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    fValue = (picoos_single) nValue / (picoos_single) 100.0f;
2092b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    if (qItem[1] == PICODATA_ITEMINFO1_CMD_PITCH)
2093b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                        pam->pMod = fValue;
2094b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    if (qItem[1] == PICODATA_ITEMINFO1_CMD_SPEED)
2095b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                        pam->dMod = (1.0f / fValue);
2096b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                }
2097b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                if (qItem[2] == 'r') {
2098b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    /*relative modifier*/
2099b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    fValue = (picoos_single) nValue / (picoos_single) 1000.0f;
2100b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    if (qItem[1] == PICODATA_ITEMINFO1_CMD_PITCH)
2101b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                        pam->pMod *= (1.0f / fValue);
2102b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    if (qItem[1] == PICODATA_ITEMINFO1_CMD_SPEED)
2103b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                        pam->dMod *= (1.0f / fValue);
2104b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                }
2105b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                return PICOPAM_CONTINUE;
2106b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
2107b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2108b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            default:
2109b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                break;
2110b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }/*end switch  switch (qItem[1])*/
2111b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }/*end if (qItem[0]==PICODATA_ITEM_CMD)*/
2112b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICOPAM_CONTINUE;
2113b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pamDoCommand*/
2114b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2115b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
2116b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * defines if an item has to be sent to following PUs
2117b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    qItem : input item pointer
2118b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    TRUE : item has to be transmitted to following PUs
2119b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    FALSE : item has to be consumed internallz on PAM
2120b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
2121b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
2122b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
2123b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t isItemToPut(picoos_uint8 *qItem)
2124b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
2125b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    switch (qItem[0]) {
2126b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEM_CMD:
2127b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            /* is a command*/
2128b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            if (PICODATA_ITEMINFO1_CMD_SPEED == qItem[1]) {
2129b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                /* SPEED consumed here*/
2130b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                return FALSE;
2131b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            }
2132b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
2133b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        case PICODATA_ITEM_BOUND:
2134b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            switch (qItem[1]) {
2135b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                case PICODATA_ITEMINFO1_BOUND_SBEG:
2136b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                case PICODATA_ITEMINFO1_BOUND_PHR0:
2137b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                case PICODATA_ITEMINFO1_BOUND_PHR1:
2138b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                case PICODATA_ITEMINFO1_BOUND_PHR2:
2139b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                case PICODATA_ITEMINFO1_BOUND_PHR3:
2140b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    /*boudary items consumed here except SEND,TERM*/
2141b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    return FALSE;
2142b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    break;
2143b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                default:
2144b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    break;
2145b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            }
2146b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
2147b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        default:
2148b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            break;
2149b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
2150b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*all other items not explicitly mentioned here
2151b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen     are transmitted to next PUs*/
2152b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return TRUE;
2153b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*isItemToPut*/
2154b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2155b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
2156b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * pushes a boundary TERM item into some buffer
2157b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    outBuff : output buffer base pointer
2158b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    outWritePos : offset in output buffer
2159b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    *bytesWr : actual bytes written
2160b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_OK
2161b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @remarks    used while forcing TERM input items in forward processing
2162b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
2163b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
2164b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
2165b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pam_put_term(picoos_uint8 *outBuff,
2166b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_uint16 outWritePos, picoos_uint8 *bytesWr)
2167b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
2168b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 *sDest;
2169b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sDest = &(outBuff[outWritePos]);
2170b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sDest[0] = PICODATA_ITEM_BOUND; /*Item type*/
2171b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sDest[1] = PICODATA_ITEMINFO1_BOUND_TERM;
2172b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sDest[2] = PICODATA_ITEMINFO2_BOUNDTYPE_T;
2173b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sDest[3] = 0; /*item size*/
2174b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    *bytesWr = 4;
2175b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
2176b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pam_put_term*/
2177b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2178b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
2179b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * translates one full phone into a PHONE Item including DT Dur, F0 and CEP trees feature generation and traversal
2180b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam item subobject pointer
2181b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_OK : processing successful
2182b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICODATA_PU_ERROR : error accessing PAM object
2183b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    !=PICO_OK : processing errors
2184b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
2185b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
2186b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
2187b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pamPhoneProcess(register picodata_ProcessingUnit this)
2188b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
2189b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam_subobj_t *pam;
2190b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pico_status_t sResult;
2191b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picokdt_classify_result_t dTreeResult;
2192b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 nI, bWr;
2193b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2194b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
2195b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
2196b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
2197b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
2198b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*expands current phone in current syllable in the corresponding vector pam->sPhFeats[]*/
2199b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sResult = pam_expand_vector(this);
2200b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sResult = pamCompressVector(this);
2201b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sResult = pamReorgVector(this);
2202b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2203b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*tree traversal for duration*/
2204b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (!pam_do_tree(this, pam->dtdur, &(pam->sPhFeats[0]), PICOPAM_INVEC_SIZE,
2205b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            &dTreeResult)) {
2206b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        PICODBG_WARN(("problem using pam tree dtdur, using fallback value"));
2207b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        dTreeResult.class = 0;
2208b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
2209b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam->durIndex = dTreeResult.class;
2210b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sResult = pam_get_duration(this, pam->durIndex, &(pam->phonDur),
2211b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            &(pam->numFramesState[0]));
2212b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2213b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*tree traversal for pitch*/
2214b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < PICOPAM_MAX_STATES_PER_PHONE; nI++) {
2215b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (!pam_do_tree(this, pam->dtlfz[nI], &(pam->sPhFeats[0]),
2216b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                PICOPAM_INVEC_SIZE, &dTreeResult)) {
2217b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            PICODBG_WARN(("problem using pam tree lf0Tree, using fallback value"));
2218b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            dTreeResult.class = 0;
2219b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
2220b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->lf0Index[nI] = dTreeResult.class;
2221b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
2222b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2223b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*pdf access for pitch*/
2224b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < PICOPAM_MAX_STATES_PER_PHONE; nI++) {
2225b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        sResult = pam_get_f0(this, &(pam->lf0Index[0]), nI, &(pam->phonF0[0]));
2226b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
2227b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2228b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*update vector with duration and pitch for cep tree traversal*/
2229b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sResult = pam_update_vector(this);
2230b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*cep tree traversal*/
2231b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    for (nI = 0; nI < PICOPAM_MAX_STATES_PER_PHONE; nI++) {
2232b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2233b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (!pam_do_tree(this, pam->dtmgc[nI], &(pam->sPhFeats[0]),
2234b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                PICOPAM_INVEC_SIZE, &dTreeResult)) {
2235b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            PICODBG_WARN(("problem using pam tree lf0Tree, using fallback value"));
2236b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            dTreeResult.class = 0;
2237b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
2238b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->mgcIndex[nI] = dTreeResult.class;
2239b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
2240b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*put item to output buffer*/
2241b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    sResult = pam_put_item(this, pam->outBuf, pam->outWritePos, &bWr);
2242b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (sResult == PICO_OK)
2243b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->outWritePos += bWr;
2244b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    else
2245b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return sResult;
2246b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return PICO_OK;
2247b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pamPhoneProcess*/
2248b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2249b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
2250b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * manages first syllable attached items when seen before SBEG
2251b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this  : Pam item subobject pointer
2252b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICO_OK (0) : default return code --> means no more items to be processed before 1st syllable
2253b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICOPAM_GOTO_FEED : go to feed state after this
2254b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICOPAM_GOTO_SCHEDULE : flush received
2255b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICODATA_PU_ERROR : errors
2256b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
2257b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
2258b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
2259b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic pico_status_t pamDoPreSyll(register picodata_ProcessingUnit this)
2260b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
2261b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam_subobj_t *pam;
2262b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pico_status_t sResult;
2263b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 bWr, nRc;
2264b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 *qItem;
2265b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    nRc = PICOPAM_PRE_SYLL_ENDED;
2266b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
2267b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
2268b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
2269b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
2270b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*regenerate initial items before the phonemes*/
2271b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (((qItem = pamPopAttachedSy0(this)) != NULL) && !((qItem[0]
2272b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            == PICODATA_ITEM_BOUND) && (qItem[1]
2273b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            == PICODATA_ITEMINFO1_BOUND_SBEG))) {
2274b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen         if (isItemToPut(qItem)) {
2275b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            pam_put_qItem(qItem, pam->outBuf, pam->outWritePos, &bWr);/*popped item has to be sent to next PU*/
2276b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            pam->outWritePos += bWr;
2277b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            nRc = PICOPAM_GOTO_FEED;
2278b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
2279b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2280b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (is_pam_command(qItem) == TRUE) {
2281b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            nRc = pamDoCommand(this, qItem); /*popped item is a PAM command : do it NOW!!*/
2282b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            if ((nRc == PICOPAM_FLUSH_RECEIVED) || (nRc == PICODATA_PU_ERROR)) {
2283b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                /*FLUSH command RECEIVED or errors: stop ALL PROCESSING*/
2284b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                return nRc;
2285b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            }
2286b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        }
2287b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->nCurrAttachedItem++;
2288b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        if (nRc == 0)
2289b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            return PICOPAM_CONTINUE;
2290b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        else
2291b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            return nRc;
2292b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
2293b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*SBEG item management*/
2294b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if ((qItem != NULL) && (qItem[0] == PICODATA_ITEM_BOUND) && (qItem[1]
2295b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            == PICODATA_ITEMINFO1_BOUND_SBEG)) {
2296b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        sResult = pam_put_qItem(qItem, pam->outBuf, pam->outWritePos, &bWr);
2297b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->outWritePos += bWr;
2298b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        pam->nCurrAttachedItem++;
2299b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        nRc = PICOPAM_GOTO_FEED;
2300b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
2301b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    return nRc;
2302b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen}/*pamDoPreSyll*/
2303b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2304b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen/**
2305b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * performs a step of the pam processing
2306b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    this : Pam item subobject pointer
2307b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    mode : mode for the PU
2308b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @param    *numBytesOutput : pointer to output number fo bytes produced
2309b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICODATA_PU_IDLE : nothing to do
2310b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICODATA_PU_BUSY : still tasks undergoing
2311b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @return    PICODATA_PU_ERROR : errors on processing
2312b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callgraph
2313b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen * @callergraph
2314b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen */
2315b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chenstatic picodata_step_result_t pam_step(register picodata_ProcessingUnit this,
2316b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        picoos_int16 mode, picoos_uint16 * numBytesOutput)
2317b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen{
2318b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2319b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    register pam_subobj_t * pam;
2320b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2321b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pico_status_t sResult;
2322b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint16 blen, numinb, numoutb;
2323b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pico_status_t rv;
2324b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 bWr;
2325b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 bForcedItem[4];
2326b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    picoos_uint8 *qItem;
2327b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2328b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    numinb = 0;
2329b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    numoutb = 0;
2330b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    rv = PICO_OK;
2331b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2332b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    if (NULL == this || NULL == this->subObj) {
2333b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        return PICODATA_PU_ERROR;
2334b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    }
2335b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    pam = (pam_subobj_t *) this->subObj;
2336b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    mode = mode; /* avoid warning "var not used in this function"*/
2337b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    /*Init number of output bytes*/
2338b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    *numBytesOutput = 0;
2339b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2340b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen    while (1) { /* exit via return */
2341b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2342b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        PICODBG_DEBUG(("pam_step -- doing state %i",pam->procState));
2343b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2344b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen        switch (pam->procState) {
2345b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2346b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case PICOPAM_COLLECT:
2347b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                /* *************** item collector ***********************************/
2348b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                /*collecting items from the PU input buffer*/
2349b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                sResult = picodata_cbGetItem(this->cbIn,
2350b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                        &(pam->inBuf[pam->inWritePos]), pam->inBufSize
2351b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                                - pam->inWritePos, &blen);
2352b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                if (sResult != PICO_OK) {
2353b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    if (sResult == PICO_EOF) {
2354b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                        /*no items available : remain in state 0 and return idle*/
2355b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                        return PICODATA_PU_IDLE;
2356b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    } else {
2357b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                        /*errors : remain in state 0 and return error*/
2358b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                        PICODBG_DEBUG(("pam_step(PICOPAM_COLLECT) -- Errors on item buffer input, status: %d",sResult));
2359b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                        return PICODATA_PU_ERROR;
2360b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    }
2361b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                }
2362b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2363b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                PICODBG_DEBUG(("pam_step -- got item, status: %d",sResult));
2364b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                sResult = picodata_is_valid_item(
2365b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                        &(pam->inBuf[pam->inWritePos]), blen);
2366b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                if (sResult != TRUE) {
2367b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    /*input item is not valid : consume the input item and stay in COLLECT*/
2368b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    pam->inWritePos += blen;
2369b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    pam->inReadPos += blen;
2370b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    if (pam->inReadPos >= pam->inWritePos) {
2371b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                        pam->inReadPos = 0;
2372b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                        pam->inWritePos = 0;
2373b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    }PICODBG_DEBUG(("pam_step -- item is not valid, type: %d",pam->inBuf[pam->inWritePos]));
2374b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    return PICODATA_PU_BUSY;
2375b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                }
2376b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2377b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                /*update input write pointer + move to "schedule" state*/
2378b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                pam->inWritePos += blen;
2379b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                pam->procState = PICOPAM_SCHEDULE;
2380b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                return PICODATA_PU_BUSY;
2381b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2382b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen            case PICOPAM_SCHEDULE:
2383b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                /* check out if more items are available */
2384b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                if (pam->inReadPos >= pam->inWritePos) {
2385b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    /*no more items : back to collect state*/
2386b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    pam->procState = PICOPAM_COLLECT;
2387b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                    return PICODATA_PU_BUSY;
2388b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                }
2389b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                /* we have one full valid item, with len>0 starting at
2390b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen                 pam->inBuf[pam->inReadPos]; here we decide how to elaborate it */
2391b190149a69b110e6719ce0a41877a683f8db7ae7Charles Chen
2392