1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
|
/*
* Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file picopam.c
*
* Phonetic to Acoustic Mapping PU - Implementation
*
* Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland
* All rights reserved.
*
* History:
* - 2009-04-20 -- initial version
*
*/
#include "picodefs.h"
#include "picoos.h"
#include "picodbg.h"
#include "picodata.h"
#include "picopam.h"
#include "picokdt.h"
#include "picokpdf.h"
#include "picoktab.h"
#include "picokdbg.h"
#include "picodsp.h"
#ifdef __cplusplus
extern "C" {
#endif
#if 0
}
#endif
#define PICOPAM_IN_BUFF_SIZE PICODATA_BUFSIZE_PAM /*input buffer size for PAM */
#define PICOPAM_OUT_PAM_SIZE PICODATA_BUFSIZE_PAM /*output buffer size for PAM*/
#define PICOPAM_DT_NRLFZ 5 /* nr of lfz decision trees per phoneme */
#define PICOPAM_DT_NRMGC 5 /* nr of mgc decision trees per phoneme */
#define PICOPAM_NRSTPF 5 /* nr of states per phone */
#define PICOPAM_COLLECT 0
#define PICOPAM_SCHEDULE 1
#define PICOPAM_IMMEDIATE 2
#define PICOPAM_FORWARD 3
#define PICOPAM_FORWARD_FORCE_TERM 4
#define PICOPAM_PROCESS 5
#define PICOPAM_PLAY 6
#define PICOPAM_FEED 7
#define PICOPAM_CONTINUE 100
#define PICOPAM_GOTO_SCHEDULE 1
#define PICOPAM_FLUSH_RECEIVED 6
#define PICOPAM_GOTO_FEED 7
#define PICOPAM_PRE_SYLL_ENDED 10
#define PICOPAM_BREAK_ADD_SIZE 4 /*syllable feature vector increment dued to BREAK and SILENCE*/
#define PICOPAM_VECT_SIZE 64+PICOPAM_BREAK_ADD_SIZE /*syllable feature vector size (bytes)*/
#define PICOPAM_INVEC_SIZE 60 /*phone feature vector size */
#define PICOPAM_MAX_SYLL_PER_SENT 100 /*maximum number of syllables per sentece*/
#define PICOPAM_MAX_PH_PER_SENT 400 /*maximum number of phonemes per sentece*/
#define PICOPAM_MAX_ITEM_PER_SENT 255 /*maximum number of attached items per sentence*/
#define PICOPAM_MAX_ITEM_SIZE_PER_SENT 4096 /*maximum size of attached items per sentence*/
#define PICOPAM_READY 20 /*PAM could start backward processing*/
#define PICOPAM_MORE 21 /*PAM has still to collect */
#define PICOPAM_NA 22 /*PAM has not to deal with this item*/
#define PICOPAM_ERR 23 /*input item is not a valid item*/
/*sentence types:cfr pam_map_sentence_type*/
#define PICOPAM_DECLARATIVE 0
#define PICOPAM_INTERROGATIVE 1
#define PICOPAM_EXCLAMATIVE 2
#define PICOPAM_T 0
#define PICOPAM_P 1
#define PICOPAM_p 2
#define PICOPAM_Y 3
#if 1
#define PAM_PHR2_WITH_PR1 1 /*deal with PHR2 boundaries as with PHR1*/
#else
#define PAM_PHR2_WITH_PR3 1 /*deal with PHR2 boundaries as with PHR3*/
#endif
#define PICOPAM_DONT_CARE_VALUE 250 /*don't care value for tree printout */
#define PICOPAM_DONT_CARE_VAL 10 /*don't care value for tree feeding */
#define PICOPAM_PH_DONT_CARE_VAL 7 /*don't care value for tree feeding (phonetic)*/
#define PICOPAM_MAX_STATES_PER_PHONE 5 /*number of states per phone */
#define PICOPAM_STATE_SIZE_IN_ITEM 6 /*size of a state in frame item */
#define PICOPAM_FRAME_ITEM_SIZE 4+PICOPAM_MAX_STATES_PER_PHONE*PICOPAM_STATE_SIZE_IN_ITEM
#define PICOPAM_DIR_FORW 0 /*forward adapter processing*/
#define PICOPAM_DIR_BACK 1 /*backward adapter processing*/
#define PICOPAM_DIR_SIL 2 /*final silence attributes*/
#define PICOPAM_SYLL_PAUSE 0 /*syllable but containing a pause phone*/
#define PICOPAM_SYLL_SYLL 1 /*a real syllable with phonemes*/
#define PICOPAM_EVENT_P_BOUND 0 /*primary boundary*/
#define PICOPAM_EVENT_S_BOUND 1 /*secondary boundary*/
#define PICOPAM_EVENT_W_BOUND 3 /*word boundary*/
#define PICOPAM_EVENT_SYLL 4 /*syllable*/
/* ----- CONSTANTS FOR BREAK COMMAND SUPPORT ----- */
#define PICOPAM_PWIDX_SBEG 0
#define PICOPAM_PWIDX_PHR1 1
#define PICOPAM_PWIDX_PHR2 2
#define PICOPAM_PWIDX_SEND 3
#define PICOPAM_PWIDX_DEFA 4
#define PICOPAM_PWIDX_SIZE 5
/*----------------------------------------------------------------*/
/*structure related to the feature vectors for feeding the trees */
/*NOTE : the same data structure is used to manage the syllables */
/* Using the first 8 fields for marking the boundaries */
/* and using the last 4 bytes as follows */
/* byte 61 : 1st attached non PAM item id(0=no item attached) */
/* in the "sSyllItemOffs" data structure */
/* byte 62 : last attached non PAM item id(0=no item attached)*/
/* in the "sSyllItemOffs" data structure */
/* byte 63..64 : offset of the start of the syllable in */
/* the "sPhIds" data structure */
typedef struct
{
picopal_uint8 phoneV[PICOPAM_VECT_SIZE];
} sFtVect, *pSftVect;
/*----------------------------------------------------------
Name : pam_subobj
Function: subobject definition for the pam processing
Shortcut: pam
---------------------------------------------------------*/
typedef struct pam_subobj
{
/*----------------------PU voice management------------------------------*/
/* picorsrc_Voice voice; */
/*----------------------PU state management------------------------------*/
picoos_uint8 procState; /* where to take up work at next processing step */
picoos_uint8 retState; /* where to go back from feed state at next p.s. */
picoos_uint8 needMoreInput; /* more data necessary to start processing */
/*----------------------PU input management------------------------------*/
picoos_uint8 inBuf[PICOPAM_IN_BUFF_SIZE]; /* internal input buffer */
picoos_uint16 inBufSize; /* actually allocated size */
picoos_uint16 inReadPos, inWritePos; /* next pos to read/write from/to inBuf*/
/*----------------------PU output management-----------------------------*/
picoos_uint8 outBuf[PICOPAM_OUT_PAM_SIZE]; /* internal output buffer */
picoos_uint16 outBufSize; /* actually allocated size */
picoos_uint16 outReadPos, outWritePos; /* next pos to read/write from/to outBuf*/
/*---------------------- adapter working buffers --------------------*/
picoos_uint8 *sPhFeats; /*feature vector for a single phone */
sFtVect *sSyllFeats; /*Syllable feature vector set for the
full sentence */
picoos_uint8 *sPhIds; /*phone ids for the full sentence */
picoos_uint8 *sSyllItems; /*items attached to the syllable */
picoos_int16 *sSyllItemOffs;/*offset of items attached to the syllable*/
/*---------------------- adapter general variables ---------------------*/
picoos_int16 nTotalPhonemes; /*number of phonemes in the sentence*/
picoos_int16 nCurrPhoneme; /*current phoneme in the sentence */
picoos_int16 nSyllPhoneme; /*current phoneme in the syllable */
picoos_int16 nCurrSyllable; /*current syllable in the sentence */
picoos_int16 nTotalSyllables; /*number of syllables in the sentence -> J1*/
picoos_uint8 nLastAttachedItemId;/*last attached item id*/
picoos_uint8 nCurrAttachedItem; /*current attached item*/
picoos_int16 nAttachedItemsSize; /*total size of the attached items*/
picoos_uint8 sType; /*Sentence type*/
picoos_uint8 pType; /*Phrase type*/
picoos_single pMod; /*pitch modifier*/
picoos_single dMod; /*Duration modifier*/
picoos_single dRest; /*Duration modifier rest*/
/*---------------------- adapter specific component variables ----------*/
picoos_uint8 a3_overall_syllable; /* A3 */
picoos_uint8 a3_primary_phrase_syllable;
picoos_uint8 b4_b5_syllable; /* B4,B5 */
picoos_uint8 b6_b7_syllable; /* B6,B7 */
picoos_uint8 b6_b7_state;
picoos_uint8 b8_b9_stressed_syllable; /* B8,B9 */
picoos_uint8 b10_b11_accented_syllable; /* B10,B11 */
picoos_uint8 b12_b13_syllable; /* B12,B13 */
picoos_uint8 b12_b13_state;
picoos_uint8 b14_b15_syllable; /* B14,B15 */
picoos_uint8 b14_b15_state;
picoos_uint8 b17_b19_syllable; /* B17,B19 */
picoos_uint8 b17_b19_state;
picoos_uint8 b18_b20_b21_syllable; /* B18,B20,B21 */
picoos_uint8 b18_b20_b21_state;
picoos_uint8 c3_overall_syllable; /* C3 */
picoos_uint8 c3_primary_phrase_syllable;
picoos_uint8 d2_syllable_in_word; /* D2 */
picoos_uint8 d2_prev_syllable_in_word;
picoos_uint8 d2_current_primary_phrase_word;
picoos_int8 e1_syllable_word_start; /* E1 */
picoos_int8 e1_syllable_word_end;
picoos_uint8 e1_content;
picoos_int8 e2_syllable_word_start; /* E2 */
picoos_int8 e2_syllable_word_end;
picoos_uint8 e3_e4_word; /* E3,E4 */
picoos_uint8 e3_e4_state;
picoos_uint8 e5_e6_content_word; /* E5,E6 */
picoos_uint8 e5_e6_content;
picoos_uint8 e7_e8_word; /* E7,E8 */
picoos_uint8 e7_e8_content;
picoos_uint8 e7_e8_state;
picoos_uint8 e9_e11_word; /* E9,E11 */
picoos_uint8 e9_e11_saw_word;
picoos_uint8 e9_e11_state;
picoos_uint8 e10_e12_e13_word; /* E10,E12,E13 */
picoos_uint8 e10_e12_e13_state;
picoos_uint8 e10_e12_e13_saw_word;
picoos_uint8 f2_overall_word; /* F2 */
picoos_uint8 f2_word_syllable;
picoos_uint8 f2_next_word_syllable;
picoos_uint8 f2_current_primary_phrase_word;
picoos_int8 g1_current_secondary_phrase_syllable; /*G1 */
picoos_int8 g1_current_syllable;
picoos_int8 g2_current_secondary_phrase_word; /*G2 */
picoos_int8 g2_current_word;
picoos_uint8 h1_current_secondary_phrase_syll; /*H1 */
picoos_uint8 h2_current_secondary_phrase_word; /*H2 */
picoos_uint8 h3_h4_current_secondary_phrase_word; /*H3,H4 */
picoos_uint8 h5_current_phrase_type; /*H5 */
picoos_uint8 h5_syllable; /* H5 */
picoos_uint8 h5_state;
picoos_uint8 i1_secondary_phrase_syllable; /*I1 */
picoos_uint8 i1_next_secondary_phrase_syllable;
picoos_uint8 i2_secondary_phrase_word; /*I2 */
picoos_uint8 i2_next_secondary_phrase_word;
picoos_uint8 j1_utterance_syllable; /*J1 */
picoos_uint8 j2_utterance_word; /*J2 */
picoos_uint8 j3_utterance_sec_phrases; /*J3 */
/*---------------------- constant data -------------------*/
picoos_uint16 sil_weights[PICOPAM_PWIDX_SIZE][PICOPAM_MAX_STATES_PER_PHONE];
/*---------------------- LINGWARE related data -------------------*/
picokdt_DtPAM dtdur; /* dtdur knowledge base */
picokdt_DtPAM dtlfz[PICOPAM_DT_NRLFZ]; /* dtlfz knowledge bases */
picokdt_DtPAM dtmgc[PICOPAM_DT_NRMGC]; /* dtmgc knowledge bases */
/*---------------------- Pdfs related data -------------------*/
picokpdf_PdfDUR pdfdur; /* pdfdur knowledge base */
picokpdf_PdfMUL pdflfz; /* pdflfz knowledge base */
/*---------------------- Tree traversal related data -------------------*/
picoos_uint16 durIndex;
picoos_uint8 numFramesState[PICOPAM_DT_NRLFZ];
picoos_uint16 lf0Index[PICOPAM_DT_NRLFZ];
picoos_uint16 mgcIndex[PICOPAM_DT_NRMGC];
/*---------------------- temps for updating the feature vector ---------*/
picoos_uint16 phonDur;
picoos_single phonF0[PICOPAM_DT_NRLFZ];
/*---------------------- Phones related data -------------------*/
picoktab_Phones tabphones;
} pam_subobj_t;
/* ----- CONSTANTS FOR FEATURE VECTOR BUILDING (NOT PREFIXED WITH "PICOPAM_" FOR BREVITY) ----- */
#define P1 0 /*field 1 of the input vector*/
#define P2 1
#define P3 2
#define P4 3
#define P5 4
#define P6 5
#define P7 6
#define bnd 6 /*boundary type item associated to the syllable = P7 */
#define P8 7
#define A3 8
#define B1 9
#define B2 10
#define B3 11
#define B4 12
#define B5 13
#define B6 14
#define B7 15
#define B8 16
#define B9 17
#define B10 18
#define B11 19
#define B12 20
#define B13 21
#define B14 22
#define B15 23
#define B16 24
#define B17 25
#define B18 26
#define B19 27
#define B20 28
#define B21 29
#define C3 30
#define D2 31
#define E1 32
#define E2 33
#define E3 34
#define E4 35
#define E5 36
#define E6 37
#define E7 38
#define E8 39
#define E9 40
#define E10 41
#define E11 42
#define E12 43
#define E13 44
#define F2 45
#define G1 46
#define G2 47
#define H1 48
#define H2 49
#define H3 50
#define H4 51
#define H5 52
#define I1 53
#define I2 54
#define J1 55
#define J2 56
#define J3 57
#define DUR 58 /*duration component*/
#define F0 59 /*F0 component*/
#define ITM 60 /*Item Offset into sSyllItems item list*/
#define itm 61 /*second byte of the Item Offset */
#define FID 62 /*Phoneme offset in the sPhIds phoneme list*/
#define fid 63 /*second byte of the Phoneme offset */
#define Min 64 /*offset to min syllable duration (uint 16,pauses)*/
#define Max 66 /*offset to max syllable duration (uint 16,pauses)*/
/* -------------------------------------------------------------------
PAM feature vector indices position changes,
------------------------------------------------------------------- */
#define T_B1 8
#define T_B2 9
#define T_B3 10
#define T_B4 11
#define T_B5 12
#define T_B6 13
#define T_B7 14
#define T_B8 15
#define T_B9 16
#define T_B10 17
#define T_B11 18
#define T_B12 19
#define T_B13 20
#define T_B14 21
#define T_B15 22
#define T_B16 23
#define T_B17 24
#define T_B18 25
#define T_B19 26
#define T_B20 27
#define T_B21 28
#define T_E1 29
#define T_E2 30
#define T_E3 31
#define T_E4 32
#define T_E5 33
#define T_E6 34
#define T_E7 35
#define T_E8 36
#define T_E9 37
#define T_E10 38
#define T_E11 39
#define T_E12 40
#define T_E13 41
#define T_A3 42
#define T_C3 43
#define T_D2 44
#define T_F2 45
#define T_G1 46
#define T_I1 47
#define T_G2 48
#define T_I2 49
#define T_H1 50
#define T_H2 51
#define T_H3 52
#define T_H4 53
#define T_H5 54
/*------------------------------------------------------------------
Service routines :
------------------------------------------------------------------*/
static pico_status_t pam_initialize(register picodata_ProcessingUnit this);
static pico_status_t pam_terminate(register picodata_ProcessingUnit this);
static pico_status_t pam_allocate(picoos_MemoryManager mm, pam_subobj_t *pam);
static void pam_deallocate(picoos_MemoryManager mm, pam_subobj_t *pam);
static pico_status_t pam_subobj_deallocate(register picodata_ProcessingUnit this,
picoos_MemoryManager mm);
/*------------------------------------------------------------------
Processing routines :
------------------------------------------------------------------*/
static picodata_step_result_t pam_step(register picodata_ProcessingUnit this,
picoos_int16 mode, picoos_uint16 * numBytesOutput);
static pico_status_t pam_deal_with(const picoos_uint8 *item);
/*Utility*/
static picoos_uint8 pam_get_vowel_name(register picodata_ProcessingUnit this,
picoos_uint8 *item, picoos_uint8 *pos);
static picoos_uint8 pam_get_pause_id(register picodata_ProcessingUnit this);
static picoos_uint8 pam_map_sentence_type(picoos_uint8 iteminfo1,
picoos_uint8 iteminfo2);
static picoos_uint8 pam_map_phrase_type(picoos_uint8 iteminfo1,
picoos_uint8 iteminfo2);
/*Adapter*/
static pico_status_t pam_reset_processors(register picodata_ProcessingUnit this);
static pico_status_t pam_reset_processors_back(
register picodata_ProcessingUnit this);
static pico_status_t pam_create_syllable(register picodata_ProcessingUnit this,
picoos_uint8 syllType, picoos_uint8 *sContent, picoos_uint8 sentType,
picoos_uint8 phType, picoos_uint8 uBoundType, picoos_uint16 uMin,
picoos_uint16 uMax);
static pico_status_t pam_process_event_feature(
register picodata_ProcessingUnit this, picoos_uint8 nFeat,
picoos_uint8 event_type, picoos_uint8 direction);
static pico_status_t pam_process_event(register picodata_ProcessingUnit this,
picoos_uint8 event_type, picoos_uint8 direction);
static pico_status_t pam_adapter_forward_step(
register picodata_ProcessingUnit this, picoos_uint8 *itemBase);
static pico_status_t pam_adapter_backward_step(
register picodata_ProcessingUnit this);
static pico_status_t pam_do_pause(register picodata_ProcessingUnit this);
static pico_status_t pam_adapter_do_pauses(register picodata_ProcessingUnit this);
/*-------------- tree traversal ---------------------------------------*/
static pico_status_t pam_expand_vector(register picodata_ProcessingUnit this);
static picoos_uint8 pam_do_tree(register picodata_ProcessingUnit this,
const picokdt_DtPAM dtpam, const picoos_uint8 *invec,
const picoos_uint8 inveclen, picokdt_classify_result_t *dtres);
static pico_status_t pam_get_f0(register picodata_ProcessingUnit this,
picoos_uint16 *lf0Index, picoos_uint8 nState, picoos_single *phonF0);
static pico_status_t pam_get_duration(register picodata_ProcessingUnit this,
picoos_uint16 durIndex, picoos_uint16 *phonDur,
picoos_uint8 *numFramesState);
static pico_status_t pam_update_vector(register picodata_ProcessingUnit this);
/*-------------- FINAL ITEM FEEDING -----------------------------------------*/
static pico_status_t pam_put_item(register picodata_ProcessingUnit this,
picoos_uint8 *outBuff, picoos_uint16 outWritePos,
picoos_uint8 *bytesWr);
static pico_status_t pam_put_term(picoos_uint8 *outBuff,
picoos_uint16 outWritePos, picoos_uint8 *bytesWr);
static pico_status_t is_pam_command(const picoos_uint8 *qItem);
static void get_default_boundary_limit(picoos_uint8 uBoundType,
picoos_uint16 *uMinDur, picoos_uint16 *uMaxDur);
/* -------------------------------------------------------------
* Pico System functions
* -------------------------------------------------------------
*/
/**
* allocation for PAM memory on pam PU
* @param mm : handle to engine memory manager
* @param pam : handle to a pam struct
* @return PICO_OK : allocation successful
* @return PICO_ERR_OTHER : allocation errors
* @callgraph
* @callergraph
*/
static pico_status_t pam_allocate(picoos_MemoryManager mm, pam_subobj_t *pam)
{
picoos_uint8 *data;
picoos_int16 *dataI;
pam->sSyllFeats = NULL;
pam->sPhIds = NULL;
pam->sPhFeats = NULL;
pam->sSyllItems = NULL;
pam->sSyllItemOffs = NULL;
/*-----------------------------------------------------------------
* PAM Local buffers ALLOCATION
------------------------------------------------------------------*/
/*PAM Local buffers*/
data = (picopal_uint8 *) picoos_allocate(mm, sizeof(sFtVect)
* PICOPAM_MAX_SYLL_PER_SENT);
if (data == NULL)
return PICO_ERR_OTHER;
pam->sSyllFeats = (sFtVect*) data;
data = (picopal_uint8 *) picoos_allocate(mm, sizeof(picopal_uint8)
* PICOPAM_MAX_PH_PER_SENT);
if (data == NULL) {
pam_deallocate(mm, pam);
return PICO_ERR_OTHER;
}
pam->sPhIds = (picopal_uint8*) data;
data = (picopal_uint8 *) picoos_allocate(mm, sizeof(picopal_uint8)
* PICOPAM_VECT_SIZE);
if (data == NULL) {
pam_deallocate(mm, pam);
return PICO_ERR_OTHER;
}
pam->sPhFeats = (picopal_uint8*) data;
data = (picopal_uint8 *) picoos_allocate(mm, sizeof(picopal_uint8)
* PICOPAM_MAX_ITEM_SIZE_PER_SENT);
if (data == NULL) {
pam_deallocate(mm, pam);
return PICO_ERR_OTHER;
}
pam->sSyllItems = (picopal_uint8*) data;
dataI = (picoos_int16 *) picoos_allocate(mm, sizeof(picoos_int16)
* PICOPAM_MAX_ITEM_PER_SENT);
if (data == NULL) {
pam_deallocate(mm, pam);
return PICO_ERR_OTHER;
}
pam->sSyllItemOffs = (picoos_int16*) dataI;
return PICO_OK;
}/*pam_allocate*/
/**
* frees allocation for DSP memory on PAM PU
* @param mm : memory manager
* @param pam : pam PU internal sub-object
* @return void
* @remarks modified and inserted in sub obj removal PP 15.09.08
* @callgraph
* @callergraph
*/
static void pam_deallocate(picoos_MemoryManager mm, pam_subobj_t *pam)
{
/*-----------------------------------------------------------------
* Memory de-allocations
* ------------------------------------------------------------------*/
if (pam->sSyllFeats != NULL)
picoos_deallocate(mm, (void *) &pam->sSyllFeats);
if (pam->sPhIds != NULL)
picoos_deallocate(mm, (void *) &pam->sPhIds);
if (pam->sPhFeats != NULL)
picoos_deallocate(mm, (void *) &pam->sPhFeats);
if (pam->sSyllItems != NULL)
picoos_deallocate(mm, (void *) &pam->sSyllItems);
if (pam->sSyllItemOffs != NULL)
picoos_deallocate(mm, (void *) &pam->sSyllItemOffs);
}/*pam_deallocate*/
/**
* initialization of a pam PU
* @param this : handle to a PU struct
* @return PICO_OK : init OK
* @return PICO_ERR_OTHER : error on getting pkbs addresses
* @callgraph
* @callergraph
*/
static pico_status_t pam_initialize(register picodata_ProcessingUnit this)
{
pico_status_t nI, nJ;
pam_subobj_t *pam;
if (NULL == this || NULL == this->subObj) {
return PICO_ERR_OTHER;
}
pam = (pam_subobj_t *) this->subObj;
pam->inBufSize = PICOPAM_IN_BUFF_SIZE;
pam->outBufSize = PICOPAM_OUT_PAM_SIZE;
pam->inReadPos = 0;
pam->inWritePos = 0;
pam->outReadPos = 0;
pam->outWritePos = 0;
pam->needMoreInput = 0;
pam->procState = 0;
/*-----------------------------------------------------------------
* MANAGE INTERNAL INITIALIZATION
------------------------------------------------------------------*/
/*init the syllable structure*/
for (nI = 0; nI < PICOPAM_MAX_SYLL_PER_SENT; nI++)
for (nJ = 0; nJ < PICOPAM_VECT_SIZE; nJ++)
pam->sSyllFeats[nI].phoneV[nJ] = 0;
for (nI = 0; nI < PICOPAM_MAX_PH_PER_SENT; nI++)
pam->sPhIds[nI] = 0;
for (nI = 0; nI < PICOPAM_VECT_SIZE; nI++)
pam->sPhFeats[nI] = 0;
for (nI = 0; nI < PICOPAM_MAX_ITEM_SIZE_PER_SENT; nI++)
pam->sSyllItems[nI] = 0;
for (nI = 0; nI < PICOPAM_MAX_ITEM_PER_SENT; nI++)
pam->sSyllItemOffs[nI] = 0;
/*Other variables*/
pam_reset_processors(this);
pam->nLastAttachedItemId = pam->nCurrAttachedItem = 0;
pam->nAttachedItemsSize = 0;
/*pitch and duration modifiers*/
pam->pMod = 1.0f;
pam->dMod = 1.0f;
pam->dRest = 0.0f;
/* constant tables */
{
picoos_uint8 i, j;
picoos_uint16 tmp_weights[PICOPAM_PWIDX_SIZE][PICOPAM_MAX_STATES_PER_PHONE] = {
{10, 10, 10, 10, 1 }, /*SBEG*/
{ 1, 4, 8, 4, 1 }, /*PHR1*/
{ 1, 4, 8, 4, 1 }, /*PHR2*/
{ 1, 10, 10, 10, 10 },/*SEND*/
{ 1, 1, 1, 1, 1 } /*DEFAULT*/
};
for (i = 0; i < PICOPAM_PWIDX_SIZE; i++) {
for (j = 0; j < PICOPAM_PWIDX_SIZE; j++) {
pam->sil_weights[j][j] = tmp_weights[i][j];
}
}
}
/*-----------------------------------------------------------------
* MANAGE LINGWARE INITIALIZATION IF NEEDED
------------------------------------------------------------------*/
/* kb dtdur */
pam->dtdur = picokdt_getDtPAM(this->voice->kbArray[PICOKNOW_KBID_DT_DUR]);
if (pam->dtdur == NULL) {
picoos_emRaiseException(this->common->em, PICO_EXC_KB_MISSING, NULL,
NULL);
return PICO_ERR_OTHER;
}PICODBG_DEBUG(("got dtdur"));
/* kb dtlfz* */
pam->dtlfz[0] = picokdt_getDtPAM(
this->voice->kbArray[PICOKNOW_KBID_DT_LFZ1]);
pam->dtlfz[1] = picokdt_getDtPAM(
this->voice->kbArray[PICOKNOW_KBID_DT_LFZ2]);
pam->dtlfz[2] = picokdt_getDtPAM(
this->voice->kbArray[PICOKNOW_KBID_DT_LFZ3]);
pam->dtlfz[3] = picokdt_getDtPAM(
this->voice->kbArray[PICOKNOW_KBID_DT_LFZ4]);
pam->dtlfz[4] = picokdt_getDtPAM(
this->voice->kbArray[PICOKNOW_KBID_DT_LFZ5]);
for (nI = 0; nI < PICOPAM_DT_NRLFZ; nI++) {
if (pam->dtlfz[nI] == NULL) {
picoos_emRaiseException(this->common->em, PICO_EXC_KB_MISSING,
NULL, NULL);
return PICO_ERR_OTHER;
}PICODBG_DEBUG(("got dtlfz%d", nI+1));
}
/* kb dtmgc* */
pam->dtmgc[0] = picokdt_getDtPAM(
this->voice->kbArray[PICOKNOW_KBID_DT_MGC1]);
pam->dtmgc[1] = picokdt_getDtPAM(
this->voice->kbArray[PICOKNOW_KBID_DT_MGC2]);
pam->dtmgc[2] = picokdt_getDtPAM(
this->voice->kbArray[PICOKNOW_KBID_DT_MGC3]);
pam->dtmgc[3] = picokdt_getDtPAM(
this->voice->kbArray[PICOKNOW_KBID_DT_MGC4]);
pam->dtmgc[4] = picokdt_getDtPAM(
this->voice->kbArray[PICOKNOW_KBID_DT_MGC5]);
for (nI = 0; nI < PICOPAM_DT_NRMGC; nI++) {
if (pam->dtmgc[nI] == NULL) {
picoos_emRaiseException(this->common->em, PICO_EXC_KB_MISSING,
NULL, NULL);
return PICO_ERR_OTHER;
}PICODBG_DEBUG(("got dtmgc%d", nI+1));
}
/* kb pdfdur* */
pam->pdfdur = picokpdf_getPdfDUR(
this->voice->kbArray[PICOKNOW_KBID_PDF_DUR]);
if (pam->pdfdur == NULL) {
picoos_emRaiseException(this->common->em, PICO_EXC_KB_MISSING, NULL,
NULL);
return PICO_ERR_OTHER;
}PICODBG_DEBUG(("got pdfdur"));
/* kb pdflfz* */
pam->pdflfz = picokpdf_getPdfMUL(
this->voice->kbArray[PICOKNOW_KBID_PDF_LFZ]);
if (pam->pdflfz == NULL) {
picoos_emRaiseException(this->common->em, PICO_EXC_KB_MISSING, NULL,
NULL);
return PICO_ERR_OTHER;
}PICODBG_DEBUG(("got pdflfz"));
/* kb tabphones */
pam->tabphones = picoktab_getPhones(
this->voice->kbArray[PICOKNOW_KBID_TAB_PHONES]);
if (pam->tabphones == NULL) {
picoos_emRaiseException(this->common->em, PICO_EXC_KB_MISSING, NULL,
NULL);
return PICO_ERR_OTHER;
}PICODBG_DEBUG(("got tabphones"));
return PICO_OK;
}/*pam_initialize*/
/**
* termination of a pam PU
* @param this : handle to a pam PU struct
* @return PICO_OK
* @callgraph
* @callergraph
*/
static pico_status_t pam_terminate(register picodata_ProcessingUnit this)
{
pam_subobj_t *pam;
if (NULL == this || NULL == this->subObj) {
return PICO_ERR_OTHER;
}
pam = (pam_subobj_t *) this->subObj;
return PICO_OK;
}/*pam_terminate*/
/**
* deallocaton of a pam PU
* @param this : handle to a pam PU struct
* @param mm : engine memory manager
* @return PICO_OK
* @callgraph
* @callergraph
*/
static pico_status_t pam_subobj_deallocate(register picodata_ProcessingUnit this,
picoos_MemoryManager mm)
{
pam_subobj_t* pam;
if (NULL != this) {
pam = (pam_subobj_t *) this->subObj;
mm = mm; /* avoid warning "var not used in this function"*/
/*-----------------------------------------------------------------
* Memory de-allocations
* ------------------------------------------------------------------*/
if (pam->sSyllFeats != NULL) {
picoos_deallocate(this->common->mm, (void *) &pam->sSyllFeats);
}
if (pam->sPhIds != NULL) {
picoos_deallocate(this->common->mm, (void *) &pam->sPhIds);
}
if (pam->sPhFeats != NULL) {
picoos_deallocate(this->common->mm, (void *) &pam->sPhFeats);
}
if (pam->sSyllItems != NULL) {
picoos_deallocate(this->common->mm, (void *) &pam->sSyllItems);
}
if (pam->sSyllItemOffs != NULL) {
picoos_deallocate(this->common->mm, (void *) &pam->sSyllItemOffs);
}
picoos_deallocate(this->common->mm, (void *) &this->subObj);
}
return PICO_OK;
}/*pam_subobj_deallocate*/
/**
* creates a new pam processing unit
* @param mm : engine memory manager
* @param common : engine common object pointer
* @param cbIn : pointer to input buffer
* @param cbOut : pointer to output buffer
* @param voice : pointer to voice structure
* @return this : pam PU handle if success
* @return NULL : if error
* @callgraph
* @callergraph
*/
picodata_ProcessingUnit picopam_newPamUnit(picoos_MemoryManager mm,
picoos_Common common, picodata_CharBuffer cbIn,
picodata_CharBuffer cbOut, picorsrc_Voice voice)
{
register pam_subobj_t * pam;
picodata_ProcessingUnit this = picodata_newProcessingUnit(mm, common, cbIn,
cbOut, voice);
if (this == NULL) {
return NULL;
}
this->initialize = pam_initialize;
PICODBG_DEBUG(("picotok_newPamUnit -- set this->step to pam_step"));
this->step = pam_step;
this->terminate = pam_terminate;
this->subDeallocate = pam_subobj_deallocate;
this->subObj = picoos_allocate(mm, sizeof(pam_subobj_t));
if (this->subObj == NULL) {
PICODBG_ERROR(("Error in Pam Object allocation"));
picoos_deallocate(mm, (void*) &this);
return NULL;
};
/*-----------------------------------------------------------------
* Allocate internal memory for PAM (only at PU creation time)
* ------------------------------------------------------------------*/
pam = (pam_subobj_t *) this->subObj;
if (PICO_OK != pam_allocate(mm, pam)) {
PICODBG_ERROR(("Error in Pam buffers Allocation"));
picoos_deallocate(mm, (void *) &this->subObj);
picoos_deallocate(mm, (void *) &this);
return NULL;
}
/*-----------------------------------------------------------------
* Initialize memory for PAM (this may be re-used elsewhere, e.g.Reset)
* ------------------------------------------------------------------*/
if (PICO_OK != pam_initialize(this)) {
PICODBG_ERROR(("problem initializing the pam sub-object"));
}
return this;
}/*picopam_newPamUnit*/
/*-------------------------------------------------------------------------------
PROCESSING AND INTERNAL FUNCTIONS
--------------------------------------------------------------------------------*/
/**
* initializes default duration limits for boundary items
* @param uBoundType : type of input boundary type
* @param *uMinDur, *uMaxDur : addresses of values to initialize
* @return void
* @remarks so far initializes to 0 both values; this will leave the values given by tree prediction
* @callgraph
* @callergraph
*/
static void get_default_boundary_limit(picoos_uint8 uBoundType,
picoos_uint16 *uMinDur, picoos_uint16 *uMaxDur)
{
switch (uBoundType) {
case PICODATA_ITEMINFO1_BOUND_SBEG:
*uMinDur = 0;
*uMaxDur = 20;
break;
case PICODATA_ITEMINFO1_BOUND_SEND:
*uMinDur = 550;
*uMaxDur = 650;
break;
case PICODATA_ITEMINFO1_BOUND_TERM:
*uMinDur = 0;
*uMaxDur = 0;
break;
case PICODATA_ITEMINFO1_BOUND_PHR0:
*uMinDur = 0;
*uMaxDur = 0;
break;
case PICODATA_ITEMINFO1_BOUND_PHR1:
*uMinDur = 275;
*uMaxDur = 325;
break;
case PICODATA_ITEMINFO1_BOUND_PHR2:
*uMinDur = 4;
*uMaxDur = 60;
break;
case PICODATA_ITEMINFO1_BOUND_PHR3:
*uMinDur = 0;
*uMaxDur = 0;
break;
default:
break;
}
}/*get_default_boundary_limit*/
/**
* checks if "neededSize" is available on "nCurrPhoneme"
* @param pam : pam subobj
* @param neededSize : the requested size
* @return PICO_OK : size is available
* @return !=PICO_OK : size not available
* @callgraph
* @callergraph
*/
static pico_status_t check_phones_size(pam_subobj_t *pam,
picoos_int16 neededSize)
{
if ((pam->nCurrPhoneme + neededSize) > PICOPAM_MAX_PH_PER_SENT - 1) {
return PICO_ERR_OTHER;
}
return PICO_OK;
}/*check_phones_size*/
/**
* checks if neededSize is available on "nCurrSyllable"
* @param pam : pam subobj
* @param neededSize : the requested size
* @return PICO_OK : size is available
* @return !=PICO_OK : size not available
* @callgraph
* @callergraph
*/
static pico_status_t check_syllables_size(pam_subobj_t *pam,
picoos_int16 neededSize)
{
if ((pam->nCurrSyllable + neededSize) > PICOPAM_MAX_SYLL_PER_SENT - 1) {
return PICO_ERR_OTHER;
}
return PICO_OK;
}/*check_syllables_size*/
/**
* verifies that local storage has enough space to receive 1 item
* @param this : pointer to current PU struct
* @param item : pointer to current item head
* @return TRUE : resource limits would be reached during processing of input item
* @return FALSE : item could be processed normally
* @remarks item pointed to by *item should be already valid
* @callgraph
* @callergraph
*/
static pico_status_t pamCheckResourceLimits(
register picodata_ProcessingUnit this, const picoos_uint8 *item)
{
register pam_subobj_t * pam;
picodata_itemhead_t head;
pico_status_t sResult;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
pam = (pam_subobj_t *) this->subObj;
sResult = TRUE; /*default : resource limits reached*/
head.type = item[0];
head.info1 = item[1];
head.info2 = item[2];
head.len = item[3];
switch (head.type) {
/*commands that generate syllables/phonemes*/
case PICODATA_ITEM_SYLLPHON:
if (pam->nCurrSyllable >= PICOPAM_MAX_SYLL_PER_SENT - 2) {
return sResult; /*no room for more syllables*/
}
if ((pam->nCurrPhoneme + head.len) >= PICOPAM_MAX_PH_PER_SENT - 2) {
return sResult; /*no room for more phoneme*/
}
break;
case PICODATA_ITEM_BOUND:
if ((head.info1 == PICODATA_ITEMINFO1_BOUND_SBEG) || (head.info1
== PICODATA_ITEMINFO1_BOUND_SEND) || (head.info1
== PICODATA_ITEMINFO1_BOUND_TERM) || (head.info1
== PICODATA_ITEMINFO1_BOUND_PHR1)
#ifdef PAM_PHR2_WITH_PR1
|| (head.info1 == PICODATA_ITEMINFO1_BOUND_PHR2)
#endif
) {
if (pam->nCurrSyllable >= PICOPAM_MAX_SYLL_PER_SENT - 2) {
return sResult; /*no room for more syllables*/
}
if ((pam->nCurrPhoneme + 1) >= PICOPAM_MAX_PH_PER_SENT - 2) {
return sResult; /*no room for more phoneme*/
}
}
break;
default:
/*all other commands has to be queued*/
if ((pam->nAttachedItemsSize + head.len)
>= PICOPAM_MAX_ITEM_SIZE_PER_SENT - 1) {
return sResult; /*no room for more items*/
}
break;
}
return FALSE; /*no resource limits apply to current item*/
} /*pamCheckResourceLimits*/
/**
* selects items to be sent to next PU immedately
* @param this : pointer to current PU struct
* @param item : pointer to current item head
* @return TRUE : item should be passed on next PU NOW
* @return FALSE : item should not be passed on next PU now but should be processed
* @remarks item pointed to by *item should be already valid
* @callgraph
* @callergraph
*/
static pico_status_t pam_check_immediate(register picodata_ProcessingUnit this,
const picoos_uint8 *item)
{
register pam_subobj_t * pam;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
pam = (pam_subobj_t *) this->subObj;
if (pam->nCurrSyllable <= -1) {
if (item[0] == PICODATA_ITEM_SYLLPHON)
return FALSE;
if ((item[0] == PICODATA_ITEM_BOUND) && (item[1]
== PICODATA_ITEMINFO1_BOUND_SBEG))
return FALSE;
if (is_pam_command((picoos_uint8 *) item) == TRUE)
return FALSE;
return TRUE; /*no need to process data : send it*/
}
return FALSE; /*syllable struct not void : do standard processing*/
} /*pam_check_immediate*/
/**
* checks if the input item has to be queued in local storage for later resynch
* @param this : pointer to current PU struct
* @param item : pointer to current item head
* @return TRUE : item should be queued
* @return FALSE : item should not be queued
* @remarks item pointed to by *item should be already valid
* @callgraph
* @callergraph
*/
static pico_status_t pam_hastobe_queued(register picodata_ProcessingUnit this,
const picoos_uint8 *item)
{
register pam_subobj_t * pam;
picodata_itemhead_t head;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
pam = (pam_subobj_t *) this->subObj;
head.type = item[0];
head.info1 = item[1];
switch (head.type) {
/*commands that generate syllables/phonemes*/
case PICODATA_ITEM_SYLLPHON:
return FALSE; /*no queue needed*/
break;
case PICODATA_ITEM_BOUND:
if ((head.info1 == PICODATA_ITEMINFO1_BOUND_PHR3)
#ifdef PAM_PHR2_WITH_PR3
||(head.info1==PICODATA_ITEMINFO1_BOUND_PHR2)
#endif
|| (head.info1 == PICODATA_ITEMINFO1_BOUND_PHR0)) {
return FALSE; /*no queue needed*/
}
break;
default:
/*all other items has to be queued*/
break;
}
return TRUE; /*item has to be queued*/
} /*pam_hastobe_queued*/
/**
* queue item in local storage for later resynch
* @param this : pointer to current PU struct
* @param item : pointer to current item head
* @return TRUE : item queued
* @return FALSE : item not queued because of errors
* @remarks item pointed to by *item should be already valid
* @callgraph
* @callergraph
*/
static pico_status_t pam_queue(register picodata_ProcessingUnit this,
const picoos_uint8 *item)
{
register pam_subobj_t * pam;
picodata_itemhead_t head;
picoos_uint8 nI;
pico_status_t sResult;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
pam = (pam_subobj_t *) this->subObj;
sResult = TRUE; /*default : item queued*/
head.type = item[0];
head.info1 = item[1];
head.info2 = item[2];
head.len = item[3];
/*test condition on enough room to store current item in the "sSyllItems" area*/
if ((pam->nAttachedItemsSize + head.len + sizeof(picodata_itemhead_t))
>= PICOPAM_MAX_ITEM_SIZE_PER_SENT - 1) {
return FALSE; /*resource limit reached*/
}
/*store current offset*/
pam->sSyllItemOffs[pam->nLastAttachedItemId] = pam->nAttachedItemsSize;
/*store the item to the "sSyllItems" area*/
for (nI = 0; nI < (head.len + sizeof(picodata_itemhead_t)); nI++) {
pam->sSyllItems[pam->nAttachedItemsSize + nI] = item[nI];
}
/*increment the attached items area*/
pam->nAttachedItemsSize += nI;
/*increment id*/
pam->nLastAttachedItemId++;
/*set start(if not initialized) and end ids of queued items in sSyllFeats*/
if (pam->nCurrSyllable > -1) {
/*normal case : the item is attached to current syllable*/
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[ITM] == 0) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[ITM]
= pam->nLastAttachedItemId;
}
pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm]
= pam->nLastAttachedItemId;
} else {
/*special case : an item is requested to be queued even if no
syllables has been assigned to the sentence structure :
-->> use syll 0*/
if (pam->sSyllFeats[0].phoneV[ITM] == 0) {
pam->sSyllFeats[0].phoneV[ITM] = pam->nLastAttachedItemId;
}
pam->sSyllFeats[0].phoneV[itm] = pam->nLastAttachedItemId;
}
return TRUE; /*item queued successfully*/
} /*pam_queue*/
/**
* selects items to be dealth with by the PU processing
* @param item : pointer to current item head
* @return TRUE : item should be processed
* @return FALSE : item should not be processed (maybe it ontains commands or items for other PUs)
* @remarks item pointed to by *item should be already valid
* @callgraph
* @callergraph
*/
static pico_status_t pam_deal_with(const picoos_uint8 *item)
{
picodata_itemhead_t head;
pico_status_t sResult;
sResult = FALSE;
head.type = item[0];
head.info1 = item[1];
head.info2 = item[2];
head.len = item[3];
switch (head.type) {
case PICODATA_ITEM_SYLLPHON:
case PICODATA_ITEM_BOUND:
sResult = TRUE;
break;
default:
break;
}
return sResult;
} /*pam_deal_with*/
/**
* returns true if more items has to be produced for current syllable
* @param this : Pam object pointer
* @return TRUE : item is to be produced
* @return FALSE : item is not to be produced
* @remarks item pointed to by *item should be already valid
* @callgraph
* @callergraph
*/
static picoos_uint8 pamHasToProcess(register picodata_ProcessingUnit this)
{
register pam_subobj_t * pam;
picoos_uint8 nCond1, nCond2, nCond3;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
pam = (pam_subobj_t *) this->subObj;
/*conditions originating a "NOT to be processed" result */
nCond1 = pam->nCurrSyllable <= -1;
nCond2 = pam->nCurrSyllable >= pam->nTotalSyllables;
nCond3 = pam->nSyllPhoneme
>= pam->sSyllFeats[pam->nCurrSyllable].phoneV[B3];
if ((nCond1) || (nCond2) || (nCond3))
return FALSE;
return TRUE;
} /*pamHasToProcess*/
/**
* modifies the process flags in order to point to next valid syllable phone or item to be produced
* @param this : Pam object pointer
* @return TRUE : item has to be produced
* @return FALSE : item has not to be produced
* @callgraph
* @callergraph
*/
static pico_status_t pamUpdateProcess(register picodata_ProcessingUnit this)
{
register pam_subobj_t * pam;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
pam = (pam_subobj_t *) this->subObj;
if (pam->nCurrSyllable == -1) {
/*this to be able to manage sudden PU cleanup after FLUSH CMD*/
return PICO_OK;
}
/*check number of phonemes for current syllable*/
if (pam->nSyllPhoneme < pam->sSyllFeats[pam->nCurrSyllable].phoneV[B3] - 1) {
pam->nSyllPhoneme++;
return PICO_OK;
}
if (pam->nSyllPhoneme == pam->sSyllFeats[pam->nCurrSyllable].phoneV[B3] - 1) {
/*this helps in identifyng the end of syllable condition in PamHasToProcess*/
pam->nSyllPhoneme++;
}
/*previous syllable phonemes are complete: test if any items are tied to this syllable*/
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[ITM] > 0) {
/*there are items tied to this syllable*/
if (pam->nCurrAttachedItem == 0) {
/*if it is the first item to be regenerated initialize it*/
pam->nCurrAttachedItem
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[ITM];
return PICO_OK;
} else {
/*not the first item : check if more*/
if (pam->nCurrAttachedItem
< pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm]) {
/*more tied items to be regenerated*/
pam->nCurrAttachedItem++;
return PICO_OK;
}
}
}
/*previous syllable phonemes and items are complete: switch to next syllable*/
if (pam->nCurrSyllable < pam->nTotalSyllables - 1) {
pam->nCurrSyllable++;
pam->nSyllPhoneme = 0;
pam->nCurrAttachedItem = 0;
return PICO_OK;
}
/*no more phonemes or items to be produced*/
pam->nCurrSyllable++;
pam->nSyllPhoneme = 0;
return PICO_ERR_OTHER;
} /*pamUpdateProcess*/
/**
* returns true if more items has to be popped for current syllable
* @param this : Pam object pointer
* @return TRUE : item has to be popped
* @return FALSE : item has not to be popped
* @callgraph
* @callergraph
*/
static picoos_uint8 pamHasToPop(register picodata_ProcessingUnit this)
{
register pam_subobj_t * pam;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
pam = (pam_subobj_t *) this->subObj;
/*Preliminary condition : at least 1 syllable*/
if (pam->nCurrSyllable <= -1)
return FALSE;
/*Preliminary condition : not maximum number of syllables*/
if (pam->nCurrSyllable >= pam->nTotalSyllables)
return FALSE;
/*Preliminary condition : start and end offset in current item > 0 */
if ((pam->sSyllFeats[pam->nCurrSyllable].phoneV[ITM] <= 0)
|| (pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm] <= 0))
return FALSE;
/*Final condition : current popped item less or eq to maximum*/
if (pam->nCurrAttachedItem
> pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm])
return FALSE;
return TRUE;
} /*pamHasToPop*/
/**
* returns the address of an item to be popped from the current syllable queue
* @param this : Pam object pointer
* @return pop_address : item address
* @return NULL : item not poppable
* @callgraph
* @callergraph
*/
static picoos_uint8 *pamPopItem(register picodata_ProcessingUnit this)
{
register pam_subobj_t * pam;
picoos_uint8 nItem;
if (NULL == this || NULL == this->subObj) {
return NULL;
}
pam = (pam_subobj_t *) this->subObj;
/*Preliminary condition : at least 1 syllable*/
if (pam->nCurrSyllable <= -1)
return NULL;
/*Preliminary condition : not maximum number of syllables*/
if (pam->nCurrSyllable >= pam->nTotalSyllables)
return NULL;
/*Preliminary condition : start and end offset in current item > 0 */
if ((pam->sSyllFeats[pam->nCurrSyllable].phoneV[ITM] <= 0)
|| (pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm] <= 0))
return NULL;
/*Final condition : current popped item less than maximum*/
if (pam->nCurrAttachedItem
> pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm])
return NULL;
nItem = pam->nCurrAttachedItem;
/*please note : nItem-1 should match with actions performed in function "pam_queue(..)" */
return &(pam->sSyllItems[pam->sSyllItemOffs[nItem - 1]]);
} /*pamPopItem*/
/**
* returns the address of an item popped from the syllable 0 queue
* @param this : Pam object pointer
* @return pop_address : item address
* @return NULL : item not poppable
* @remarks the item is popped only if it has been inserted in the queue before the first
* @remarks item assigned to the syllable 0 i.e.
* @remarks AttachedItem<=pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm]-1
* @callgraph
* @callergraph
*/
static picoos_uint8 *pamPopAttachedSy0(register picodata_ProcessingUnit this)
{
register pam_subobj_t * pam;
picoos_uint8 nItem;
if (NULL == this || NULL == this->subObj) {
return NULL;
}
pam = (pam_subobj_t *) this->subObj;
/*should be syllable 0*/
if (pam->nCurrSyllable != 0)
return NULL;
/*start and end offset in current item > 0 */
if ((pam->sSyllFeats[pam->nCurrSyllable].phoneV[ITM] <= 0)
|| (pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm] <= 0))
return NULL;
/*if current popped item is > 0 test end condition*/
if (pam->nCurrAttachedItem > 0) {
/*Other condition : current popped item less than maximum*/
if (pam->nCurrAttachedItem
> pam->sSyllFeats[pam->nCurrSyllable].phoneV[itm] - 1)
return NULL;
}
nItem = pam->nCurrAttachedItem;
return &(pam->sSyllItems[pam->sSyllItemOffs[nItem]]);
} /*pamPopAttachedSy0*/
/**
* pdf access for duration
* @param this : Pam object pointer
* @param durIndex : index of duration in the pdf
* @param phonDur : pointer to base of array where to store the duration values
* @param numFramesState : pointer to base of array where to store the number of frames per state
* @return PICO_OK : pdf retrieved
* @return PICO_ERR_OTHER : pdf not retrieved
* @remarks Modifies phonDur (the requested duration value)
* @remarks Modifies numFramesState (the requested number of frames per state (vector))
* @callgraph
* @callergraph
*/
static pico_status_t pam_get_duration(register picodata_ProcessingUnit this,
picoos_uint16 durIndex, picoos_uint16 *phonDur,
picoos_uint8 *numFramesState)
{
pam_subobj_t *pam;
picokpdf_PdfDUR pdf;
picoos_uint8 *durItem;
picoos_uint16 nFrameSize, nI;
picoos_single fValue;
pam = (pam_subobj_t *) this->subObj;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
pdf = pam->pdfdur;
/*make the index 0 based*/
if (durIndex > 0)
durIndex--;
/* check */
if (durIndex > pdf->numframes - 1) {
PICODBG_ERROR(("PAM durPdf access error, index overflow -> index: %d , numframes: %d", durIndex, pdf->numframes));
return PICO_ERR_OTHER;
}
/* base pointer */
durItem = &(pdf->content[durIndex * pdf->vecsize]);
if (durItem == NULL) {
PICODBG_ERROR(("PAM durPdf access error , frame pointer = NULL"));
return PICO_ERR_OTHER;
}
nFrameSize = pdf->sampperframe / 16;
*phonDur = ((pdf->phonquant[((*durItem) & 0xF0) >> 4]) * nFrameSize);
numFramesState[0] = pdf->statequant[((*durItem) & 0x0F)];
durItem++;
numFramesState[1] = pdf->statequant[((*durItem) & 0xF0) >> 4];
numFramesState[2] = pdf->statequant[((*durItem) & 0x0F)];
durItem++;
numFramesState[3] = pdf->statequant[((*durItem) & 0xF0) >> 4];
numFramesState[4] = pdf->statequant[((*durItem) & 0x0F)];
/*modification of the duration information based on the duration modifier*/
*phonDur = (picoos_uint16) (((picoos_single) * phonDur) * pam->dMod);
for (nI = 0; nI < 5; nI++) {
fValue = pam->dRest + (picoos_single) numFramesState[nI] * pam->dMod;
numFramesState[nI] = (picoos_uint8) (fValue);
pam->dRest = fValue - (picoos_single) numFramesState[nI];
}
return PICO_OK;
}/*pam_get_duration*/
/**
* pdf access for pitch
* @param this : Pam object pointer
* @param lf0Index : pointer to variable to receive index of pitch in the pdf
* @param nI : number of the phone's state
* @param phonF0 : pointer to variable to receive the pitch value
* @return PICO_OK : pdf retrieved
* @return PICO_ERR_OTHER : pdf not retrieved
* @remarks Modifies phonDur (the requested duration value)
* @remarks Modifies phonF0 (the requested pitch value (scalar))
* @callgraph
* @callergraph
*/
static pico_status_t pam_get_f0(register picodata_ProcessingUnit this,
picoos_uint16 *lf0Index, picoos_uint8 nI, picoos_single *phonF0)
{
pam_subobj_t *pam;
picoos_uint8 *lfItem, numstreams;
picoos_uint16 lf0IndexOffset, sTemp;
picoos_single lfum, lfivar, lfz;
pam = (pam_subobj_t *) this->subObj;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
lf0IndexOffset = lf0Index[nI];
/*make the index 0 based*/
if (lf0IndexOffset > 0)
lf0IndexOffset--;
lf0IndexOffset += pam->pdflfz->stateoffset[nI];
if (lf0IndexOffset > pam->pdflfz->numframes - 1) {
PICODBG_ERROR(("PAM flfzPdf access error, index overflow -> index: %d , numframes: %d", lf0Index, pam->pdflfz->numframes));
return PICO_ERR_OTHER;
}
/* base pointer */
lf0IndexOffset *= pam->pdflfz->vecsize;
lfItem = &(pam->pdflfz->content[lf0IndexOffset]);
sTemp = (picoos_uint16) (((lfItem[1] << 8)) | lfItem[0]);
lfum = (picoos_single) (sTemp << (pam->pdflfz->meanpowUm[0]));
numstreams = 3;
lfivar = (picoos_single) (((picoos_uint16) lfItem[numstreams * 2])
<< pam->pdflfz->ivarpow[0]);
lfz = (picoos_single) lfum / (picoos_single) lfivar;
lfz = (picoos_single) exp((double) lfz);
phonF0[nI] = (picoos_single) lfz;
/*pitch modoification*/
phonF0[nI] *= pam->pMod;
return PICO_OK;
}/*pam_get_f0*/
/**
* elementary rounding function
* @param fIn : (real) input value
* @return the rounded value
* @callgraph
* @callergraph
*/
static picoos_single f_round(picoos_single fIn)
{
picoos_int32 iVal;
picoos_single fVal;
iVal = (picoos_int32) fIn;
fVal = (picoos_single) iVal;
if (fIn > (picoos_single) 0.0f) {
if ((fIn - fVal) < (picoos_single) 0.5f)
return fVal;
else
return fVal + (picoos_single) 1.0f;
} else {
if ((fVal - fIn) < (picoos_single) 0.5f)
return fVal;
else
return fVal - (picoos_single) 1.0f;
}
}/*f_round*/
/**
* updates the input vector for PAM
* @param this : Pam object pointer
* @return PICO_OK : update successful
* @return PICO_ERR_OTHER : errors on retrieving the PU pointer
* @remarks Modifies pam->sPhFeats[]
* @callgraph
* @callergraph
*/
static pico_status_t pam_update_vector(register picodata_ProcessingUnit this)
{
pam_subobj_t *pam;
picoos_uint8 numstates, nI;
picoos_single fDur, f0avg, f0quant, minf0, maxf0, durquant1, durquant2,
mindur, maxdur1, maxdur2;
pam = (pam_subobj_t *) this->subObj;
if (NULL == this || NULL == this->subObj) {
return PICO_ERR_OTHER;
}
/*default init*/
pam->sPhFeats[DUR] = 0;
pam->sPhFeats[F0] = 0;
/*
Hard coded parameters for quantization
*/
numstates = PICOPAM_NRSTPF;
f0quant = 30.0f;
minf0 = 90.0f;
maxf0 = 360.0f;
durquant1 = 20.0f;
durquant2 = 100.0f;
mindur = 40.0f;
maxdur1 = 160.0f;
maxdur2 = 600.0f;
f0avg = 0.0f;
for (nI = 0; nI < numstates; nI++)
f0avg += pam->phonF0[nI];
f0avg /= (picoos_single) numstates;
f0avg = f_round(f0avg / f0quant) * f0quant;
if (f0avg < minf0)
f0avg = minf0;
if (f0avg > maxf0)
f0avg = maxf0;
/*make initial silence of sentence shorter (see also pam_put_item)*/
if ((pam->nCurrSyllable == 0) && (pam->nSyllPhoneme == 0)) {
pam->phonDur = 2 * 4;
}
fDur = (picoos_single) pam->phonDur;
fDur = f_round(fDur / durquant1) * durquant1;
if (fDur < mindur)
fDur = mindur;
if (fDur > maxdur1) {
fDur = f_round(fDur / durquant2) * durquant2;
if (fDur > maxdur2)
fDur = maxdur2;
}
pam->sPhFeats[DUR] = (picoos_uint8) (fDur / (picoos_single) 10.0f);
pam->sPhFeats[F0] = (picoos_uint8) (f0avg / (picoos_single) 10.0f);
return PICO_OK;
}/*pam_update_vector*/
/**
* compress a single feature in the range 0..9
* @param inVal : the value to be compressed
* @return compVal : the compressed value
* @callgraph
* @callergraph
*/
static picoos_uint8 pamCompressComponent(picoos_uint8 inVal)
{
if (inVal <= 5)
return inVal;
if ((5 < inVal) && (inVal <= 10))
return 6;
if ((10 < inVal) && (inVal <= 20))
return 7;
if ((20 < inVal) && (inVal <= 30))
return 8;
return 9;
}/*pamCompressComponent*/
/**
* prepares the input vector for tree feeding
* @param this : Pam object pointer
* @return PICO_OK : vector expanded
* @return PICO_ERR_OTHER : errors on expansion or retrieving the PU pointer
* @remarks Modifies pam->sPhFeats[]
* @callgraph
* @callergraph
*/
static pico_status_t pam_expand_vector(register picodata_ProcessingUnit this)
{
pam_subobj_t *pam;
picoos_uint8 *inVect, *phonVect, *outVect, nI;
picoos_int16 nOffs, nOffs1, nLen;
pam = (pam_subobj_t *) this->subObj;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
inVect = &(pam->sSyllFeats[pam->nCurrSyllable].phoneV[0]);
phonVect = &(pam->sPhIds[0]);
outVect = &(pam->sPhFeats[0]);
/*just copy back*/
for (nI = 0; nI < PICOPAM_INVEC_SIZE; nI++)
outVect[nI] = inVect[nI];
/*now fill missing fields*/
picoos_mem_copy((void*) &(inVect[FID]), &nOffs, sizeof(nOffs));
/*offset to first phone of current syllable*/
nOffs = nOffs + pam->nSyllPhoneme; /*offset to current phone of current syllable*/
nLen = inVect[B3]; /*len of current syllable*/
if (pam->nSyllPhoneme >= nLen) {
/*error on addressing current phone*/
return PICO_ERR_OTHER;
}
/*previous of the previous phone*/
nOffs1 = nOffs - 2;
if (nOffs1 >= 0)
outVect[P1] = phonVect[nOffs1];
else
outVect[P1] = PICOPAM_PH_DONT_CARE_VAL;
/*previous phone*/
nOffs1 = nOffs - 1;
if (nOffs1 >= 0)
outVect[P2] = phonVect[nOffs1];
else
outVect[P2] = PICOPAM_PH_DONT_CARE_VAL;
/*^current phone*/
outVect[P3] = phonVect[nOffs];
/*next phone*/
nOffs1 = nOffs + 1;
if (nOffs1 < pam->nTotalPhonemes)
outVect[P4] = phonVect[nOffs1];
else
outVect[P4] = PICOPAM_PH_DONT_CARE_VAL;
/*next of the next phone*/
nOffs1 = nOffs + 2;
if (nOffs1 < pam->nTotalPhonemes)
outVect[P5] = phonVect[nOffs1];
else
outVect[P5] = PICOPAM_PH_DONT_CARE_VAL;
/*pos of curr phone with respect to left syllable boundary*/
outVect[P6] = pam->nSyllPhoneme + 1;
/*pos of curr phone with respect to right syllable boundary*/
outVect[P7] = nLen - pam->nSyllPhoneme;
/*is current phone in consonant syllable boundary? (1:yes)*/
if (pam->nSyllPhoneme < inVect[P8])
outVect[P8] = 1;
else
outVect[P8] = 0;
return PICO_OK;
}/*pam_expand_vector*/
/**
* compresses the input vector for PAM
* @param this : Pam object pointer
* @return PICO_OK : compression successful
* @return PICO_ERR_OTHER : errors on retrieving the PU pointer
* @remarks Modifies pam->sPhFeats[]
* @callgraph
* @callergraph
*/
static pico_status_t pamCompressVector(register picodata_ProcessingUnit this)
{
pam_subobj_t *pam;
picoos_uint8 *outVect, nI;
pam = (pam_subobj_t *) this->subObj;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
outVect = &(pam->sPhFeats[0]);
for (nI = 0; nI < PICOPAM_INVEC_SIZE; nI++) {
switch (nI) {
case P1:
case P2:
case P3:
case P4:
case P5:
case B1:
case B2:
case B16:
case E1:
case H5:
/*don't do any compression*/
break;
default:
/*do compression*/
if (outVect[nI] != PICOPAM_DONT_CARE_VALUE)
outVect[nI] = pamCompressComponent(outVect[nI]);
else
outVect[nI] = PICOPAM_DONT_CARE_VAL;
break;
}
}
return PICO_OK;
}/*pamCompressVector*/
/**
* reorganizes the input vector for PAM
* @param this : Pam object pointer
* @return PICO_OK : reorganization successful
* @return PICO_ERR_OTHER : errors on retrieving the PU pointer
* @remarks Modifies pam->sPhFeats[]
* @callgraph
* @callergraph
*/
static pico_status_t pamReorgVector(register picodata_ProcessingUnit this)
{
pam_subobj_t *pam;
picoos_uint8 *outVect, inVect[60], nI;
pam = (pam_subobj_t *) this->subObj;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
outVect = &(pam->sPhFeats[0]);
for (nI = 0; nI < PICOPAM_INVEC_SIZE; nI++) inVect[nI] = outVect[nI];
/*reorganize*/
for (nI = T_B1; nI <= T_H5; nI++) {
switch (nI) {
case T_B1:
outVect[T_B1] = inVect[B1];
break;
case T_B2:
outVect[T_B2] = inVect[B2];
break;
case T_B3:
outVect[T_B3] = inVect[B3];
break;
case T_B4:
outVect[T_B4] = inVect[B4];
break;
case T_B5:
outVect[T_B5] = inVect[B5];
break;
case T_B6:
outVect[T_B6] = inVect[B6];
break;
case T_B7:
outVect[T_B7] = inVect[B7];
break;
case T_B8:
outVect[T_B8] = inVect[B8];
break;
case T_B9:
outVect[T_B9] = inVect[B9];
break;
case T_B10:
outVect[T_B10] = inVect[B10];
break;
case T_B11:
outVect[T_B11] = inVect[B11];
break;
case T_B12:
outVect[T_B12] = inVect[B12];
break;
case T_B13:
outVect[T_B13] = inVect[B13];
break;
case T_B14:
outVect[T_B14] = inVect[B14];
break;
case T_B15:
outVect[T_B15] = inVect[B15];
break;
case T_B16:
outVect[T_B16] = inVect[B16];
break;
case T_B17:
outVect[T_B17] = inVect[B17];
break;
case T_B18:
outVect[T_B18] = inVect[B18];
break;
case T_B19:
outVect[T_B19] = inVect[B19];
break;
case T_B20:
outVect[T_B20] = inVect[B20];
break;
case T_B21:
outVect[T_B21] = inVect[B21];
break;
case T_E1:
outVect[T_E1] = inVect[E1];
break;
case T_E2:
outVect[T_E2] = inVect[E2];
break;
case T_E3:
outVect[T_E3] = inVect[E3];
break;
case T_E4:
outVect[T_E4] = inVect[E4];
break;
case T_E5:
outVect[T_E5] = inVect[E5];
break;
case T_E6:
outVect[T_E6] = inVect[E6];
break;
case T_E7:
outVect[T_E7] = inVect[E7];
break;
case T_E8:
outVect[T_E8] = inVect[E8];
break;
case T_E9:
outVect[T_E9] = inVect[E9];
break;
case T_E10:
outVect[T_E10] = inVect[E10];
break;
case T_E11:
outVect[T_E11] = inVect[E11];
break;
case T_E12:
outVect[T_E12] = inVect[E12];
break;
case T_E13:
outVect[T_E13] = inVect[E13];
break;
case T_A3:
outVect[T_A3] = inVect[A3];
break;
case T_C3:
outVect[T_C3] = inVect[C3];
break;
case T_D2:
outVect[T_D2] = inVect[D2];
break;
case T_F2:
outVect[T_F2] = inVect[F2];
break;
case T_G1:
outVect[T_G1] = inVect[G1];
break;
case T_I1:
outVect[T_I1] = inVect[I1];
break;
case T_G2:
outVect[T_G2] = inVect[G2];
break;
case T_I2:
outVect[T_I2] = inVect[I2];
break;
case T_H1:
outVect[T_H1] = inVect[H1];
break;
case T_H2:
outVect[T_H2] = inVect[H2];
break;
case T_H3:
outVect[T_H3] = inVect[H3];
break;
case T_H4:
outVect[T_H4] = inVect[H4];
break;
case T_H5:
outVect[T_H5] = inVect[H5];
break;
}
}
return PICO_OK;
}/*pamReorgVector*/
/**
* puts a PAM item into PU output buffer
* @param this : Pam object pointer
* @param outBuff : output buffer base pointer
* @param outWritePos : offset in output buffer
* @param *bytesWr : actual bytes written
* @return PICO_OK : put successful
* @return PICO_ERR_OTHER : errors on retrieving the PU pointer
* @callgraph
* @callergraph
*/
static pico_status_t pam_put_item(register picodata_ProcessingUnit this,
picoos_uint8 *outBuff, picoos_uint16 outWritePos, picoos_uint8 *bytesWr)
{
pam_subobj_t *pam;
picoos_uint8 *sDest, nI, nType, nIdx, fde;
picoos_uint32 pos, pos32;
picoos_int16 ft, dt;
picoos_uint16 uMinDur, uMaxDur;
pam = (pam_subobj_t *) this->subObj;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
sDest = &(outBuff[outWritePos]);
sDest[0] = PICODATA_ITEM_PHONE; /*Item type*/
sDest[1] = pam->sPhFeats[P3]; /*phonetic id*/
sDest[2] = PICOPAM_NRSTPF; /*number of states per phone*/
sDest[3] = sizeof(picoos_uint16) * PICOPAM_NRSTPF * 3; /*size of the item*/
pos = 4;
/*make initial silence of sentence shorter (see also UpdateVector)*/
if ((pam->nCurrSyllable == 0) && (pam->nSyllPhoneme == 0)) {
for (nI = 0; nI < PICOPAM_NRSTPF - 1; nI++)
pam->numFramesState[nI] = 0;
pam->numFramesState[nI] = 2;
} else {
/*manage silence syllables with prescribed durations*/
pos32 = Min;
picoos_read_mem_pi_uint16(pam->sSyllFeats[pam->nCurrSyllable].phoneV,
&pos32, &uMinDur);
pos32 = Max;
picoos_read_mem_pi_uint16(pam->sSyllFeats[pam->nCurrSyllable].phoneV,
&pos32, &uMaxDur);
if (uMaxDur > 0) {
/* Select weights*/
nType = pam->sSyllFeats[pam->nCurrSyllable].phoneV[bnd];
switch (nType) {
case PICODATA_ITEMINFO1_BOUND_SBEG:
nIdx = PICOPAM_PWIDX_SBEG;
break;
case PICODATA_ITEMINFO1_BOUND_PHR1:
nIdx = PICOPAM_PWIDX_PHR1;
break;
case PICODATA_ITEMINFO1_BOUND_PHR2:
nIdx = PICOPAM_PWIDX_PHR2;
break;
case PICODATA_ITEMINFO1_BOUND_SEND:
case PICODATA_ITEMINFO1_BOUND_TERM:
nIdx = PICOPAM_PWIDX_SEND;
break;
default:
nIdx = PICOPAM_PWIDX_DEFA;
break;
}
fde = 2;
ft = 0;
dt = 0;
picodata_transformDurations(
fde, /* 2's exponent of frame duration in ms, e.g. 2 for 4ms, 3 for 8ms */
PICOPAM_NRSTPF, /* number of states per phone */
&(pam->numFramesState[0]), /* estimated durations */
pam->sil_weights[nIdx], /* integer weights */
uMinDur, /* minimum target duration in ms */
uMaxDur, /* maximum target duration in ms */
ft, /* factor to be multiplied to get the target */
&dt /* in/out, rest in ms */
);
}
}
/*put data*/
for (nI = 0; nI < PICOPAM_NRSTPF; nI++) {
picoos_write_mem_pi_uint16(sDest, &pos,
(picoos_uint16) pam->numFramesState[nI]);
picoos_write_mem_pi_uint16(sDest, &pos,
(picoos_uint16) pam->lf0Index[nI]);
picoos_write_mem_pi_uint16(sDest, &pos,
(picoos_uint16) pam->mgcIndex[nI]);
}
*bytesWr = sizeof(picodata_itemhead_t) + sizeof(picoos_uint16)
* PICOPAM_NRSTPF * 3;
return PICO_OK;
}/*pam_put_item*/
/**
* puts a non PAM (queued) item into PU output buffer
* @param qItem : pointer to item to put
* @param outBuff : output buffer base pointer
* @param outWritePos : offset in output buffer
* @param *bytesWr : actual bytes written
* @return PICO_OK : put successful
* @return PICO_ERR_OTHER : errors on retrieving the PU pointer
* @callgraph
* @callergraph
*/
static pico_status_t pam_put_qItem(picoos_uint8 *qItem, picoos_uint8 *outBuff,
picoos_uint16 outWritePos, picoos_uint8 *bytesWr)
{
picoos_uint8 *sDest, nI;
sDest = &(outBuff[outWritePos]);
*bytesWr = sizeof(picodata_itemhead_t);
for (nI = 0; nI < (sizeof(picodata_itemhead_t) + qItem[3]); nI++) {
sDest[nI] = qItem[nI];
}
*bytesWr = nI;
return PICO_OK;
}/*pam_put_qItem*/
/**
* tells if an item is a PAM command (except play)
* @param qItem : input item to test
* @return TRUE : qItem is a PAM command (except play)
* @return FALSE : qItem not a PAM command
* @callgraph
* @callergraph
*/
static pico_status_t is_pam_command(const picoos_uint8 * qItem)
{
switch (qItem[0]) {
case PICODATA_ITEM_CMD:
switch (qItem[1]) {
case PICODATA_ITEMINFO1_CMD_FLUSH:
/* flush is for all PU's and as such it is also for PAM*/
case PICODATA_ITEMINFO1_CMD_PITCH:
case PICODATA_ITEMINFO1_CMD_SPEED:
return TRUE;
break;
default:
break;
}
}
return FALSE;
}/*is_pam_command*/
/**
* tells if an item is a PAM PLAY command
* @param qItem : input item to test
* @return TRUE : qItem is a PAM PLAY command
* @return FALSE : qItem not a PAM PLAY command
* @callgraph
* @callergraph
*/
static pico_status_t is_pam_play_command(picoos_uint8 *qItem)
{
switch (qItem[0]) {
case PICODATA_ITEM_CMD:
switch (qItem[1]) {
case PICODATA_ITEMINFO1_CMD_PLAY:
if (qItem[2] == PICODATA_ITEMINFO2_CMD_TO_PAM)
return TRUE;
break;
default:
break;
}
}
return FALSE;
}/*is_pam_play_command*/
/**
* command processor for PAM pu
* @param this : Pam item subobject
* @param qItem : input item pointer
* @return PICOPAM_FLUSH_RECEIVED : when a FLUSH is received
* @return PICOPAM_CONTINUE : normal command processing
* @return PICODATA_PU_ERROR : errors in accessing data
* @callgraph
* @callergraph
*/
static pico_status_t pamDoCommand(register picodata_ProcessingUnit this,
picoos_uint8 *qItem)
{
pam_subobj_t *pam;
picoos_single fValue;
picoos_uint16 nValue;
picoos_uint32 nPos;
pam = (pam_subobj_t *) this->subObj;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
if (qItem[0] == PICODATA_ITEM_CMD) {
switch (qItem[1]) {
case PICODATA_ITEMINFO1_CMD_FLUSH:
/* flush is for all PU's and as such it is also for PAM : implement the flush!!*/
pam_reset_processors(this);
pam->nLastAttachedItemId = pam->nCurrAttachedItem = 0;
pam->nAttachedItemsSize = 0;
return PICOPAM_FLUSH_RECEIVED;
break;
case PICODATA_ITEMINFO1_CMD_PITCH:
case PICODATA_ITEMINFO1_CMD_SPEED:
nPos = 4;
picoos_read_mem_pi_uint16(qItem, &nPos, &nValue);
if (qItem[2] == 'a') {
/*absloute modifier*/
fValue = (picoos_single) nValue / (picoos_single) 100.0f;
if (qItem[1] == PICODATA_ITEMINFO1_CMD_PITCH)
pam->pMod = fValue;
if (qItem[1] == PICODATA_ITEMINFO1_CMD_SPEED)
pam->dMod = (1.0f / fValue);
}
if (qItem[2] == 'r') {
/*relative modifier*/
fValue = (picoos_single) nValue / (picoos_single) 1000.0f;
if (qItem[1] == PICODATA_ITEMINFO1_CMD_PITCH)
pam->pMod *= (1.0f / fValue);
if (qItem[1] == PICODATA_ITEMINFO1_CMD_SPEED)
pam->dMod *= (1.0f / fValue);
}
return PICOPAM_CONTINUE;
break;
default:
break;
}/*end switch switch (qItem[1])*/
}/*end if (qItem[0]==PICODATA_ITEM_CMD)*/
return PICOPAM_CONTINUE;
}/*pamDoCommand*/
/**
* defines if an item has to be sent to following PUs
* @param qItem : input item pointer
* @return TRUE : item has to be transmitted to following PUs
* @return FALSE : item has to be consumed internallz on PAM
* @callgraph
* @callergraph
*/
static pico_status_t isItemToPut(picoos_uint8 *qItem)
{
switch (qItem[0]) {
case PICODATA_ITEM_CMD:
/* is a command*/
if (PICODATA_ITEMINFO1_CMD_SPEED == qItem[1]) {
/* SPEED consumed here*/
return FALSE;
}
break;
case PICODATA_ITEM_BOUND:
switch (qItem[1]) {
case PICODATA_ITEMINFO1_BOUND_SBEG:
case PICODATA_ITEMINFO1_BOUND_PHR0:
case PICODATA_ITEMINFO1_BOUND_PHR1:
case PICODATA_ITEMINFO1_BOUND_PHR2:
case PICODATA_ITEMINFO1_BOUND_PHR3:
/*boudary items consumed here except SEND,TERM*/
return FALSE;
break;
default:
break;
}
break;
default:
break;
}
/*all other items not explicitly mentioned here
are transmitted to next PUs*/
return TRUE;
}/*isItemToPut*/
/**
* pushes a boundary TERM item into some buffer
* @param outBuff : output buffer base pointer
* @param outWritePos : offset in output buffer
* @param *bytesWr : actual bytes written
* @return PICO_OK
* @remarks used while forcing TERM input items in forward processing
* @callgraph
* @callergraph
*/
static pico_status_t pam_put_term(picoos_uint8 *outBuff,
picoos_uint16 outWritePos, picoos_uint8 *bytesWr)
{
picoos_uint8 *sDest;
sDest = &(outBuff[outWritePos]);
sDest[0] = PICODATA_ITEM_BOUND; /*Item type*/
sDest[1] = PICODATA_ITEMINFO1_BOUND_TERM;
sDest[2] = PICODATA_ITEMINFO2_BOUNDTYPE_T;
sDest[3] = 0; /*item size*/
*bytesWr = 4;
return PICO_OK;
}/*pam_put_term*/
/**
* translates one full phone into a PHONE Item including DT Dur, F0 and CEP trees feature generation and traversal
* @param this : Pam item subobject pointer
* @return PICO_OK : processing successful
* @return PICODATA_PU_ERROR : error accessing PAM object
* @return !=PICO_OK : processing errors
* @callgraph
* @callergraph
*/
static pico_status_t pamPhoneProcess(register picodata_ProcessingUnit this)
{
pam_subobj_t *pam;
pico_status_t sResult;
picokdt_classify_result_t dTreeResult;
picoos_uint8 nI, bWr;
pam = (pam_subobj_t *) this->subObj;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
/*expands current phone in current syllable in the corresponding vector pam->sPhFeats[]*/
sResult = pam_expand_vector(this);
sResult = pamCompressVector(this);
sResult = pamReorgVector(this);
/*tree traversal for duration*/
if (!pam_do_tree(this, pam->dtdur, &(pam->sPhFeats[0]), PICOPAM_INVEC_SIZE,
&dTreeResult)) {
PICODBG_WARN(("problem using pam tree dtdur, using fallback value"));
dTreeResult.class = 0;
}
pam->durIndex = dTreeResult.class;
sResult = pam_get_duration(this, pam->durIndex, &(pam->phonDur),
&(pam->numFramesState[0]));
/*tree traversal for pitch*/
for (nI = 0; nI < PICOPAM_MAX_STATES_PER_PHONE; nI++) {
if (!pam_do_tree(this, pam->dtlfz[nI], &(pam->sPhFeats[0]),
PICOPAM_INVEC_SIZE, &dTreeResult)) {
PICODBG_WARN(("problem using pam tree lf0Tree, using fallback value"));
dTreeResult.class = 0;
}
pam->lf0Index[nI] = dTreeResult.class;
}
/*pdf access for pitch*/
for (nI = 0; nI < PICOPAM_MAX_STATES_PER_PHONE; nI++) {
sResult = pam_get_f0(this, &(pam->lf0Index[0]), nI, &(pam->phonF0[0]));
}
/*update vector with duration and pitch for cep tree traversal*/
sResult = pam_update_vector(this);
/*cep tree traversal*/
for (nI = 0; nI < PICOPAM_MAX_STATES_PER_PHONE; nI++) {
if (!pam_do_tree(this, pam->dtmgc[nI], &(pam->sPhFeats[0]),
PICOPAM_INVEC_SIZE, &dTreeResult)) {
PICODBG_WARN(("problem using pam tree lf0Tree, using fallback value"));
dTreeResult.class = 0;
}
pam->mgcIndex[nI] = dTreeResult.class;
}
/*put item to output buffer*/
sResult = pam_put_item(this, pam->outBuf, pam->outWritePos, &bWr);
if (sResult == PICO_OK)
pam->outWritePos += bWr;
else
return sResult;
return PICO_OK;
}/*pamPhoneProcess*/
/**
* manages first syllable attached items when seen before SBEG
* @param this : Pam item subobject pointer
* @return PICO_OK (0) : default return code --> means no more items to be processed before 1st syllable
* @return PICOPAM_GOTO_FEED : go to feed state after this
* @return PICOPAM_GOTO_SCHEDULE : flush received
* @return PICODATA_PU_ERROR : errors
* @callgraph
* @callergraph
*/
static pico_status_t pamDoPreSyll(register picodata_ProcessingUnit this)
{
pam_subobj_t *pam;
pico_status_t sResult;
picoos_uint8 bWr, nRc;
picoos_uint8 *qItem;
nRc = PICOPAM_PRE_SYLL_ENDED;
pam = (pam_subobj_t *) this->subObj;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
/*regenerate initial items before the phonemes*/
if (((qItem = pamPopAttachedSy0(this)) != NULL) && !((qItem[0]
== PICODATA_ITEM_BOUND) && (qItem[1]
== PICODATA_ITEMINFO1_BOUND_SBEG))) {
if (isItemToPut(qItem)) {
pam_put_qItem(qItem, pam->outBuf, pam->outWritePos, &bWr);/*popped item has to be sent to next PU*/
pam->outWritePos += bWr;
nRc = PICOPAM_GOTO_FEED;
}
if (is_pam_command(qItem) == TRUE) {
nRc = pamDoCommand(this, qItem); /*popped item is a PAM command : do it NOW!!*/
if ((nRc == PICOPAM_FLUSH_RECEIVED) || (nRc == PICODATA_PU_ERROR)) {
/*FLUSH command RECEIVED or errors: stop ALL PROCESSING*/
return nRc;
}
}
pam->nCurrAttachedItem++;
if (nRc == 0)
return PICOPAM_CONTINUE;
else
return nRc;
}
/*SBEG item management*/
if ((qItem != NULL) && (qItem[0] == PICODATA_ITEM_BOUND) && (qItem[1]
== PICODATA_ITEMINFO1_BOUND_SBEG)) {
sResult = pam_put_qItem(qItem, pam->outBuf, pam->outWritePos, &bWr);
pam->outWritePos += bWr;
pam->nCurrAttachedItem++;
nRc = PICOPAM_GOTO_FEED;
}
return nRc;
}/*pamDoPreSyll*/
/**
* performs a step of the pam processing
* @param this : Pam item subobject pointer
* @param mode : mode for the PU
* @param *numBytesOutput : pointer to output number fo bytes produced
* @return PICODATA_PU_IDLE : nothing to do
* @return PICODATA_PU_BUSY : still tasks undergoing
* @return PICODATA_PU_ERROR : errors on processing
* @callgraph
* @callergraph
*/
static picodata_step_result_t pam_step(register picodata_ProcessingUnit this,
picoos_int16 mode, picoos_uint16 * numBytesOutput)
{
register pam_subobj_t * pam;
pico_status_t sResult;
picoos_uint16 blen, numinb, numoutb;
pico_status_t rv;
picoos_uint8 bWr;
picoos_uint8 bForcedItem[4];
picoos_uint8 *qItem;
numinb = 0;
numoutb = 0;
rv = PICO_OK;
if (NULL == this || NULL == this->subObj) {
return PICODATA_PU_ERROR;
}
pam = (pam_subobj_t *) this->subObj;
mode = mode; /* avoid warning "var not used in this function"*/
/*Init number of output bytes*/
*numBytesOutput = 0;
while (1) { /* exit via return */
PICODBG_DEBUG(("pam_step -- doing state %i",pam->procState));
switch (pam->procState) {
case PICOPAM_COLLECT:
/* *************** item collector ***********************************/
/*collecting items from the PU input buffer*/
sResult = picodata_cbGetItem(this->cbIn,
&(pam->inBuf[pam->inWritePos]), pam->inBufSize
- pam->inWritePos, &blen);
if (sResult != PICO_OK) {
if (sResult == PICO_EOF) {
/*no items available : remain in state 0 and return idle*/
return PICODATA_PU_IDLE;
} else {
/*errors : remain in state 0 and return error*/
PICODBG_DEBUG(("pam_step(PICOPAM_COLLECT) -- Errors on item buffer input, status: %d",sResult));
return PICODATA_PU_ERROR;
}
}
PICODBG_DEBUG(("pam_step -- got item, status: %d",sResult));
sResult = picodata_is_valid_item(
&(pam->inBuf[pam->inWritePos]), blen);
if (sResult != TRUE) {
/*input item is not valid : consume the input item and stay in COLLECT*/
pam->inWritePos += blen;
pam->inReadPos += blen;
if (pam->inReadPos >= pam->inWritePos) {
pam->inReadPos = 0;
pam->inWritePos = 0;
}PICODBG_DEBUG(("pam_step -- item is not valid, type: %d",pam->inBuf[pam->inWritePos]));
return PICODATA_PU_BUSY;
}
/*update input write pointer + move to "schedule" state*/
pam->inWritePos += blen;
pam->procState = PICOPAM_SCHEDULE;
return PICODATA_PU_BUSY;
case PICOPAM_SCHEDULE:
/* check out if more items are available */
if (pam->inReadPos >= pam->inWritePos) {
/*no more items : back to collect state*/
pam->procState = PICOPAM_COLLECT;
return PICODATA_PU_BUSY;
}
/* we have one full valid item, with len>0 starting at
pam->inBuf[pam->inReadPos]; here we decide how to elaborate it */
/* PLAY management */
if (is_pam_play_command(&(pam->inBuf[pam->inReadPos])) == TRUE) {
/*consume the input item : it has been managed*/
pam->inReadPos += pam->inBuf[pam->inReadPos + 3]
+ sizeof(picodata_itemhead_t);
if (pam->inReadPos >= pam->inWritePos) {
pam->inReadPos = 0;
pam->inWritePos = 0;
}
/*stay in schedule*/
return PICODATA_PU_BUSY;
}
if (pam_check_immediate(this, &(pam->inBuf[pam->inReadPos]))) {
/* item has to be sent to next PU NOW : switch to "immediate" state */
pam->procState = PICOPAM_IMMEDIATE;
return PICODATA_PU_BUSY;
}
if (pamCheckResourceLimits(this, &(pam->inBuf[pam->inReadPos]))) {
/* item would not fit into local buffers -->> free some space -->>
switch to "force term" state */
pam->procState = PICOPAM_FORWARD_FORCE_TERM;
return PICODATA_PU_BUSY;
}
if (pam_deal_with(&(pam->inBuf[pam->inReadPos]))) {
/* item has to be managed by the "forward" state : switch to forward state*/
pam->procState = PICOPAM_FORWARD;
return PICODATA_PU_BUSY;
}
if (pam_hastobe_queued(this, &(pam->inBuf[pam->inReadPos]))) {
/* item is not for PAM so it has to be queued internally */
pam_queue(this, &(pam->inBuf[pam->inReadPos]));
/*consume the input item : it has been queued*/
pam->inReadPos += pam->inBuf[pam->inReadPos + 3]
+ sizeof(picodata_itemhead_t);
if (pam->inReadPos >= pam->inWritePos) {
pam->inReadPos = 0;
pam->inWritePos = 0;
}
return PICODATA_PU_BUSY;
}
/*if we get here something wrong happened. Being the the item valid,
switch to "immediate" state -> send it to next PU -> */
PICODBG_DEBUG(("pam_step (PICOPAM_SCHEDULE) -- unexpected item is sent to next PU !!"));
pam->procState = PICOPAM_IMMEDIATE;
return PICODATA_PU_BUSY;
break; /*PICOPAM_SCHEDULE*/
case PICOPAM_FORWARD:
/*we have one full valid item, with len>0 starting at pam->inBuf[pam->inReadPos].
furthermore this item should be in the set {BOUND,SYLL}.
No other items should arrive here*/
sResult = pam_adapter_forward_step(this,
&(pam->inBuf[pam->inReadPos]));
/*decide if this item has to be queued for later re-synchronization
normally this is only done for SEND/TERM items*/
if (pam_hastobe_queued(this, &(pam->inBuf[pam->inReadPos]))) {
/*item has to be queued iternally in local storage*/
pam_queue(this, &(pam->inBuf[pam->inReadPos]));
}
/*now assign next state according to Forward results*/
switch (sResult) {
case PICOPAM_READY:
pam->needMoreInput = FALSE;
/*consume the input item : it has already been stored*/
pam->inReadPos += pam->inBuf[pam->inReadPos + 3]
+ sizeof(picodata_itemhead_t);
if (pam->inReadPos >= pam->inWritePos) {
pam->inReadPos = 0;
pam->inWritePos = 0;
}
/*activate backward processing*/
sResult = pam_adapter_backward_step(this);
if (sResult == PICO_OK) {
pam->procState = PICOPAM_PROCESS;
return PICODATA_PU_BUSY;
} else {
PICODBG_DEBUG(("pam_step (PICOPAM_FORWARD) -- wrong return from BackwardStep: %d -- Buffered sentence will be discarded",sResult));
pam_reset_processors(this);
pam->nLastAttachedItemId = pam->nCurrAttachedItem
= 0;
pam->nAttachedItemsSize = 0;
pam->procState = PICOPAM_SCHEDULE;
return PICODATA_PU_BUSY;
}
break;
case PICOPAM_MORE:
pam->needMoreInput = TRUE;
/*consume the input item : it has already been stored*/
pam->inReadPos += pam->inBuf[pam->inReadPos + 3]
+ sizeof(picodata_itemhead_t);
if (pam->inReadPos >= pam->inWritePos) {
/*input is finished and PAM need more data :
clenaup input buffer + switch state back to "schedule state"
*/
pam->inReadPos = 0;
pam->inWritePos = 0;
pam->procState = PICOPAM_SCHEDULE;
return PICODATA_PU_ATOMIC;
} else {
/*input is not finished and need more data :
remain in state "PICOPAM_FORWARD" */
return PICODATA_PU_ATOMIC;
}
break;
case PICOPAM_NA:
default:
/*this item has not been stored in internal buffers:
assign this item to the management of
"immediate" state*/
pam->procState = PICOPAM_IMMEDIATE;
return PICODATA_PU_BUSY;
break;
} /*end switch sResult*/
break; /*PICOPAM_FORWARD*/
case PICOPAM_FORWARD_FORCE_TERM:
/*we have one full valid item, with len>0
starting at pam->inBuf[pam->inReadPos] but we decided
to force a TERM item before, without losing the item in
inBuf[inReadPos] : --> generate a TERM item and do the
forward processing */
pam_put_term(bForcedItem, 0, &bWr);
sResult = pam_adapter_forward_step(this, &(bForcedItem[0]));
switch (sResult) {
case PICOPAM_READY:
pam_queue(this, &(bForcedItem[0]));
/*activate backward processing*/
sResult = pam_adapter_backward_step(this);
if (sResult == PICO_OK) {
pam->procState = PICOPAM_PROCESS;
return PICODATA_PU_BUSY;
} else {
PICODBG_DEBUG(("pam_step (PICOPAM_FORWARD_FORCE_TERM) -- wrong return from BackwardStep: %d -- Buffered sentence will be discarded",sResult));
pam_reset_processors(this);
pam->nLastAttachedItemId = pam->nCurrAttachedItem
= 0;
pam->nAttachedItemsSize = 0;
pam->procState = PICOPAM_SCHEDULE;
return PICODATA_PU_BUSY;
}
break;
default:
PICODBG_DEBUG(("pam_step (PICOPAM_FORWARD_FORCE_TERM) -- Forced a TERM but processing do not appear to end -- Buffered sentence will be discarded",sResult));
pam_reset_processors(this);
pam->nLastAttachedItemId = pam->nCurrAttachedItem = 0;
pam->nAttachedItemsSize = 0;
pam->procState = PICOPAM_SCHEDULE;
return PICODATA_PU_BUSY;
break;
} /*end switch sResult*/
break; /*PICOPAM_FORWARD_FORCE_TERM*/
case PICOPAM_PROCESS:
if ((PICOPAM_FRAME_ITEM_SIZE + 4) > (pam->outBufSize
- pam->outWritePos)) {
/*WARNING (buffer overflow): leave status unchanged until output buffer free */
return PICODATA_PU_BUSY;
}
if (pam->nCurrSyllable == 0) {
sResult = pamDoPreSyll(this);
if (sResult == PICOPAM_GOTO_FEED) {
/*
items pushed to output buffer :
switch to "feed" but then back
to "process"
*/
pam->retState = PICOPAM_PROCESS;
pam->procState = PICOPAM_FEED;
return PICODATA_PU_BUSY;
}
if (sResult == PICOPAM_CONTINUE) {
/*
items processed (maybe commands) :
return (maybe we need to process other
items in pre_syll) and then back to "process"
*/
pam->retState = PICOPAM_PROCESS;
pam->procState = PICOPAM_PROCESS;
return PICODATA_PU_BUSY;
}
if ((sResult == PICOPAM_FLUSH_RECEIVED) || (sResult
== PICODATA_PU_ERROR)) {
/*
items processed were a flush or
problems found: switch to "schedule"
and abort all processing
*/
pam->retState = PICOPAM_SCHEDULE;
pam->procState = PICOPAM_SCHEDULE;
return PICODATA_PU_BUSY;
}
if (sResult == PICOPAM_PRE_SYLL_ENDED) {
/*
we get here when pam->nCurrSyllable==0 and
no more items to be processed before the syllable
*/
sResult = sResult;
}
}
if (pamHasToProcess(this)) {
if (pamPhoneProcess(this) == PICO_OK) {
sResult = pamUpdateProcess(this);
pam->procState = PICOPAM_FEED; /*switch to feed*/
return PICODATA_PU_BUSY;
} else {
PICODBG_DEBUG(("pam_step(PICOPAM_PROCESS) --- NULL return from pamPhoneProcess"));
return PICODATA_PU_ERROR;
}
}
if (pamHasToPop(this) != FALSE) {
if ((qItem = pamPopItem(this)) == NULL) {
PICODBG_DEBUG(("pam_step(PICOPAM_PROCESS) --- NULL return from pamPopItem"));
return PICODATA_PU_ERROR;
}
if (isItemToPut(qItem)) {
/*popped item has to be sent to next PU*/
sResult = pam_put_qItem(qItem, pam->outBuf,
pam->outWritePos, &bWr);
if (sResult != PICO_OK) {
PICODBG_DEBUG(("pam_step(PICOPAM_PROCESS) --- Error on writing item to output buffer"));
return PICODATA_PU_ERROR;
}
pam->outWritePos += bWr; /*item write ok*/
pam->procState = PICOPAM_FEED; /*switch to feed*/
}
/*moved command processing here (after pam_put_qItem) because of FLUSH command could erase
* the syllable structure and make it impossible to transmit the flush to other PUs*/
if (is_pam_command(qItem) == TRUE) {
sResult = pamDoCommand(this, qItem); /*popped item is a PAM command : do it NOW!!*/
if ((sResult == PICOPAM_FLUSH_RECEIVED) || (sResult
== PICODATA_PU_ERROR)) {
pam->retState = PICOPAM_SCHEDULE;
pam->procState = PICOPAM_SCHEDULE; /*switch to schedule */
return PICODATA_PU_BUSY;
}
}
/*update PAM status: if more items attached to the current syllable
stay in current syllable, otherwise move to next syllable and switch
to processing phones */
sResult = pamUpdateProcess(this); /*both "doCommand" or "put" : update PAM status*/
return PICODATA_PU_BUSY;
} else {
pam->procState = PICOPAM_SCHEDULE; /*switch to schedule */
return PICODATA_PU_BUSY;
}
break; /*PICOPAM_PROCESS*/
case PICOPAM_IMMEDIATE:
/* *** item is output NOW!!! */
/*context: full valid item, with len> starting at pam->inBuf[pam->inReadPos]*/
numinb = PICODATA_ITEM_HEADSIZE
+ pam->inBuf[pam->inReadPos + 3];
sResult = picodata_copy_item(&(pam->inBuf[pam->inReadPos]),
numinb, &(pam->outBuf[pam->outWritePos]),
pam->outBufSize - pam->outWritePos, &numoutb);
if (sResult == PICO_OK) {
pam->inReadPos += numinb;
if (pam->inReadPos >= pam->inWritePos) {
pam->inReadPos = 0;
pam->inWritePos = 0;
pam->needMoreInput = FALSE;
}
pam->outWritePos += numoutb;
pam->procState = PICOPAM_FEED; /*switch to FEED state*/
pam->retState = PICOPAM_SCHEDULE; /*back to SCHEDULE after FEED*/
} else {
/*
PICO_EXC_BUF_IGNORE
PICO_EXC_BUF_UNDERFLOW
PICO_EXC_BUF_OVERFLOW
*/
PICODBG_DEBUG(("pam_step(PICOPAM_IMMEDIATE) --- wrong return from picodata_copy_item:%d",sResult));
return PICODATA_PU_ERROR;
}
return PICODATA_PU_BUSY;
break; /*PICOPAM_IMMEDIATE*/
case PICOPAM_FEED:
/* *************** item output/feeding ***********************************/
/*feeding items to PU output buffer*/
sResult = picodata_cbPutItem(this->cbOut,
&(pam->outBuf[pam->outReadPos]), pam->outWritePos
- pam->outReadPos, &numoutb);
PICODBG_DEBUG(("pam_step -- put item, status: %d",sResult));
if (PICO_OK == sResult) {
PICODATA_INFO_ITEM(this->voice->kbArray[PICOKNOW_KBID_DBG],
(picoos_uint8 *)"pam: ",
pam->outBuf + pam->outReadPos, pam->outBufSize);
pam->outReadPos += numoutb;
*numBytesOutput = numoutb;
if (pam->outReadPos >= pam->outWritePos) {
/*reset the output pointers*/
pam->outReadPos = 0;
pam->outWritePos = 0;
/*switch to appropriate state*/
switch (pam->retState) {
case PICOPAM_IMMEDIATE:
pam->procState = PICOPAM_IMMEDIATE;
pam->retState = PICOPAM_SCHEDULE;
return PICODATA_PU_BUSY;
break;
case PICOPAM_PLAY:
pam->procState = PICOPAM_PLAY;
pam->retState = PICOPAM_SCHEDULE;
return PICODATA_PU_BUSY;
break;
default:
break;
}
/*Define next state
a)process (if current sentence has more data to process)
b)schedule (no more data to process in current sentence)
NOTE : case b)also happens when dealing with non BOUND/SYLL items*/
if ((pamHasToProcess(this)) || (pamHasToPop(this))) {
pam->procState = PICOPAM_PROCESS;
} else {
pam->nCurrSyllable = -1;
pam_reset_processors(this);
pam->nLastAttachedItemId = pam->nCurrAttachedItem
= 0;
pam->nAttachedItemsSize = 0;
pam->nSyllPhoneme = 0;
pam->procState = PICOPAM_SCHEDULE;
}
}
return PICODATA_PU_BUSY;
} else if (PICO_EXC_BUF_OVERFLOW == sResult) {
PICODBG_DEBUG(("pam_step ** feeding, overflow, PICODATA_PU_OUT_FULL"));
return PICODATA_PU_OUT_FULL;
} else if ((PICO_EXC_BUF_UNDERFLOW == sResult)
|| (PICO_ERR_OTHER == sResult)) {
PICODBG_DEBUG(("pam_step ** feeding problem, discarding item"));
pam->outReadPos = 0;
pam->outWritePos = 0;
pam->procState = PICOPAM_COLLECT;
return PICODATA_PU_ERROR;
}
break; /*PICOPAM_FEED*/
default:
/*NOT feeding items*/
sResult = PICO_EXC_BUF_IGNORE;
break;
}/*end switch*/
return PICODATA_PU_BUSY; /*check if there is more data to process after feeding*/
}/*end while*/
return PICODATA_PU_IDLE;
}/*pam_step*/
/**
* performs one step of a PamTree
* @param this : Pam item subobject pointer
* @param dtpam : the Pam decision tree
* @param *invec : the input vector pointer
* @param inveclen : length of the input vector
* @param *dtres : the classification result
* @return dtres->set : the result of tree traversal
* @callgraph
* @callergraph
*/
static picoos_uint8 pam_do_tree(register picodata_ProcessingUnit this,
const picokdt_DtPAM dtpam, const picoos_uint8 *invec,
const picoos_uint8 inveclen, picokdt_classify_result_t *dtres)
{
picoos_uint8 okay;
okay = TRUE;
/* construct input vector, which is set in dtpam */
if (!picokdt_dtPAMconstructInVec(dtpam, invec, inveclen)) {
/* error constructing invec */
PICODBG_WARN(("problem with invec"));
picoos_emRaiseWarning(this->common->em, PICO_WARN_INVECTOR, NULL, NULL);
okay = FALSE;
}
/* classify */
if (okay && (!picokdt_dtPAMclassify(dtpam))) {
/* error doing classification */
PICODBG_WARN(("problem classifying"));
picoos_emRaiseWarning(this->common->em, PICO_WARN_CLASSIFICATION, NULL,
NULL);
okay = FALSE;
}
/* decompose */
if (okay && (!picokdt_dtPAMdecomposeOutClass(dtpam, dtres))) {
/* error decomposing */
PICODBG_WARN(("problem decomposing"));
picoos_emRaiseWarning(this->common->em, PICO_WARN_OUTVECTOR, NULL, NULL);
okay = FALSE;
}
PICODBG_TRACE(("dtpam output class: %d", dtres->class));
return dtres->set;
}/*pam_do_tree*/
/**
* returns the carrier vowel id inside a syllable
* @param this : Pam item subobject pointer
* @param item : the full syllable item
* @param *pos : pointer to the variable to receive the position of the carrier vowel
* @return the phonetic id for the carrier vowel inside the syllable
* @callgraph
* @callergraph
*/
static picoos_uint8 pam_get_vowel_name(register picodata_ProcessingUnit this,
picoos_uint8 *item, picoos_uint8 *pos)
{
pam_subobj_t *pam;
picoos_uint8 *phon, nI, nCond1;
if (NULL == this || NULL == this->subObj) {
return 0;
}
pam = (pam_subobj_t *) this->subObj;
if (item == NULL)
return 0;
if (item[3] == 0)
return 0;
phon = &item[4];
for (nI = 0; nI < item[3]; nI++) {
nCond1 = picoktab_isSyllCarrier(pam->tabphones, phon[nI]);
if (nCond1) {
*pos = nI;
return phon[nI];
}
}
return 0;
}/*pam_get_vowel_name */
/**
* returns the pause phone id in the current ph.alphabet
* @param this : Pam sub object pointer
* @return the (numeric) phonetic id of the pause phone in current phonetic alphabet
* @return 0 : errors on getting the pam subobject pointer
* @callgraph
* @callergraph
*/
static picoos_uint8 pam_get_pause_id(register picodata_ProcessingUnit this)
{
picoos_uint8 nVal1;
/*picoos_uint8 nVal2; */
pam_subobj_t *pam;
if (NULL == this || NULL == this->subObj) {
return 0;
}
pam = (pam_subobj_t *) this->subObj;
nVal1 = picoktab_getPauseID(pam->tabphones);
return nVal1;
}/*pam_get_pause_id */
/**
* returns the pam sentence type (declarative, interrogative...)
* @param iteminfo1 : the boundary item info 1
* @param iteminfo2 : the boundary item info 2
* @return the sentence type suitably encoded for trees
* @callgraph
* @callergraph
*/
static picoos_uint8 pam_map_sentence_type(picoos_uint8 iteminfo1,
picoos_uint8 iteminfo2)
{
switch (iteminfo2) {
case PICODATA_ITEMINFO2_BOUNDTYPE_P:
return PICOPAM_DECLARATIVE;
case PICODATA_ITEMINFO2_BOUNDTYPE_T:
return PICOPAM_DECLARATIVE;
case PICODATA_ITEMINFO2_BOUNDTYPE_Q:
return PICOPAM_INTERROGATIVE;
case PICODATA_ITEMINFO2_BOUNDTYPE_E:
return PICOPAM_DECLARATIVE;
default:
return PICOPAM_DECLARATIVE;
}
iteminfo1 = iteminfo1; /* avoid warning "var not used in this function"*/
return PICOPAM_DECLARATIVE;
}/*pam_map_sentence_type */
/**
* returns the pam phrase type
* @param iteminfo1 : the boundary item info 1
* @param iteminfo2 : the boundary item info 2
* @return the phrase type suitably encoded for trees
* @callgraph
* @callergraph
*/
static picoos_uint8 pam_map_phrase_type(picoos_uint8 iteminfo1,
picoos_uint8 iteminfo2)
{
switch (iteminfo2) {
case PICODATA_ITEMINFO2_BOUNDTYPE_P:
switch (iteminfo1) {
case PICODATA_ITEMINFO1_BOUND_PHR1:
# ifdef PAM_PHR2_WITH_PR1
case PICODATA_ITEMINFO1_BOUND_PHR2:
# endif
return PICOPAM_P; /*current_prhase type = "P" (encoded to 1) */
break;
case PICODATA_ITEMINFO1_BOUND_PHR3:
# ifdef PAM_PHR2_WITH_PR3
case PICODATA_ITEMINFO1_BOUND_PHR2 :
# endif
return PICOPAM_p; /*current_prhase type = "p" (encoded to 2) */
break;
case PICODATA_ITEMINFO1_BOUND_SBEG:
return PICOPAM_P; /*current_prhase type = "P" (encoded to 1) */
break;
default:
PICODBG_DEBUG(("Map pam_map_phrase_type : unexpected iteminfo1"));
return PICOPAM_P; /*current_prhase type = "P" (encoded to 1) */
break;
}
case PICODATA_ITEMINFO2_BOUNDTYPE_T:
return PICOPAM_T; /*current_prhase type = "T" (encoded to 0) */
break;
case PICODATA_ITEMINFO2_BOUNDTYPE_E:
return PICOPAM_T; /*current_prhase type = "T" (encoded to 0) */
break;
case PICODATA_ITEMINFO2_BOUNDTYPE_Q:
return PICOPAM_Y; /*current_prhase type = "T" (encoded to 0) */
break;
default:
PICODBG_DEBUG(("Map pam_map_phrase_type : unexpected iteminfo2"));
return PICOPAM_T; /*current_prhase type = "T" (encoded to 0) */
break;
}PICODBG_DEBUG(("Map pam_map_phrase_type : unexpected iteminfo2"));
return PICOPAM_T; /*current_prhase type = "T" (encoded to 0) */
}/*pam_map_phrase_type */
/**
* does the cleanup of the sub object processors flags at sentence start
* @param this : pointer to PAM PU sub object pointer
* @return PICO_OK : reset OK
* @return PICO_ERR_OTHER : errors on getting pam sub obj pointer
* @callgraph
* @callergraph
*/
static pico_status_t pam_reset_processors(register picodata_ProcessingUnit this)
{
pam_subobj_t *pam;
if (NULL == this || NULL == this->subObj) {
return PICO_ERR_OTHER;
}
pam = (pam_subobj_t *) this->subObj;
pam->nCurrSyllable = -1;
pam->nTotalPhonemes = pam->nSyllPhoneme = pam->nCurrPhoneme
= pam->nTotalSyllables = pam->sType = pam->pType = 0;
pam->dRest = 0.0f;
/*set all to 0*/
pam->a3_overall_syllable = pam->a3_primary_phrase_syllable = pam->b4_b5_syllable =
pam->b6_b7_syllable = pam->b6_b7_state = pam->b8_b9_stressed_syllable =
pam->b10_b11_accented_syllable = pam->b12_b13_syllable = pam->b12_b13_state =
pam->b14_b15_syllable = pam->b14_b15_state = pam->b17_b19_syllable =
pam->b17_b19_state = pam->b18_b20_b21_syllable = pam->b18_b20_b21_state =
pam->c3_overall_syllable= pam->c3_primary_phrase_syllable = pam->d2_syllable_in_word =
pam->d2_prev_syllable_in_word = pam->d2_current_primary_phrase_word = pam->e1_syllable_word_start =
pam->e1_syllable_word_end= pam->e1_content = pam->e2_syllable_word_start =
pam->e2_syllable_word_end= pam->e3_e4_word = pam->e3_e4_state =
pam->e5_e6_content_word = pam->e5_e6_content = pam->e7_e8_word =
pam->e7_e8_content = pam->e7_e8_state = pam->e9_e11_word =
pam->e9_e11_saw_word = pam->e9_e11_state = pam->e10_e12_e13_word =
pam->e10_e12_e13_state = pam->e10_e12_e13_saw_word = pam->f2_overall_word =
pam->f2_word_syllable = pam->f2_next_word_syllable = pam->f2_current_primary_phrase_word =
pam->g1_current_secondary_phrase_syllable = pam->g1_current_syllable =
pam->g2_current_secondary_phrase_word = pam->g2_current_word =
pam->h1_current_secondary_phrase_syll = pam->h2_current_secondary_phrase_word =
pam->h3_h4_current_secondary_phrase_word = pam->h5_current_phrase_type =
pam->h5_syllable = pam->h5_state = pam->i1_secondary_phrase_syllable =
pam->i1_next_secondary_phrase_syllable = pam->i2_secondary_phrase_word =
pam->i2_next_secondary_phrase_word = pam->j1_utterance_syllable =
pam->j2_utterance_word = pam->j3_utterance_sec_phrases = 0;
/*Override 0 with 1*/
pam->b4_b5_syllable = pam->b17_b19_syllable = pam->b18_b20_b21_syllable =
pam->e9_e11_word = pam->e10_e12_e13_word = pam->e7_e8_word =
pam->h2_current_secondary_phrase_word = 1;
/*Override 0 with -1*/
pam->e1_syllable_word_start = pam->e1_syllable_word_end = pam->e2_syllable_word_start =
pam->e2_syllable_word_end = -1;
return PICO_OK;
}/*pam_reset_processors*/
/**
* does the cleanup of the sub object processors flags before the backward step
* @param this : pointer to PAM PU sub object pointer
* @return PICO_OK : reset OK
* @return PICO_ERR_OTHER : errors on getting pam sub obj pointer
* @callgraph
* @callergraph
*/
static pico_status_t pam_reset_processors_back(
register picodata_ProcessingUnit this)
{
pam_subobj_t *pam;
if (NULL == this || NULL == this->subObj) {
return PICO_ERR_OTHER;
}
pam = (pam_subobj_t *) this->subObj;
/*set all to 0*/
pam->a3_overall_syllable
= pam->a3_primary_phrase_syllable
= pam->b4_b5_syllable
= pam->b6_b7_syllable
= pam->b6_b7_state
= pam->b8_b9_stressed_syllable
= pam->b10_b11_accented_syllable
= pam->b12_b13_syllable
= pam->b12_b13_state
= pam->b14_b15_syllable
= pam->b14_b15_state
= pam->b17_b19_syllable
= pam->b17_b19_state
= pam->b18_b20_b21_syllable
= pam->b18_b20_b21_state
= pam->c3_overall_syllable
= pam->c3_primary_phrase_syllable
= pam->d2_syllable_in_word
= pam->d2_prev_syllable_in_word
= pam->d2_current_primary_phrase_word
= pam->e1_syllable_word_start
= pam->e1_syllable_word_end
= pam->e1_content
= pam->e2_syllable_word_start
= pam->e2_syllable_word_end
= pam->e3_e4_word
= pam->e3_e4_state
= pam->e5_e6_content_word
= pam->e5_e6_content
= pam->e7_e8_word
= pam->e7_e8_content
= pam->e7_e8_state
= pam->e9_e11_word
= pam->e9_e11_saw_word
= pam->e9_e11_state
= pam->e10_e12_e13_word
= pam->e10_e12_e13_state
= pam->e10_e12_e13_saw_word
= pam->f2_overall_word
= pam->f2_word_syllable
= pam->f2_next_word_syllable
= pam->f2_current_primary_phrase_word
= pam->g1_current_secondary_phrase_syllable
= pam->g1_current_syllable
= pam->g2_current_secondary_phrase_word
= pam->g2_current_word
= pam->h1_current_secondary_phrase_syll
= pam->h2_current_secondary_phrase_word
= pam->h3_h4_current_secondary_phrase_word
= pam->h5_current_phrase_type
= pam->h5_state
= pam->i1_secondary_phrase_syllable
= pam->i1_next_secondary_phrase_syllable
= pam->i2_secondary_phrase_word
= pam->i2_next_secondary_phrase_word
= 0;
/*Override 0 with 1*/
pam->b4_b5_syllable = pam->b17_b19_syllable = pam->b18_b20_b21_syllable
= pam->e9_e11_word = pam->e10_e12_e13_word = pam->e7_e8_word
= pam->h2_current_secondary_phrase_word = 1;
/*Override 0 with -1*/
pam->e1_syllable_word_start = pam->e1_syllable_word_end
= pam->e2_syllable_word_start = pam->e2_syllable_word_end = -1;
return PICO_OK;
}/*pam_reset_processors_back*/
/**
* processes an input event for a specific feature
* @param this : pointer to PAM PU sub object pointer
* @param nFeat : feature column to process
* @param event_type : event id among syll/boundprim/boundsec/boundword
* @param direction : forward(0)/backward(1)
* @return PICO_OK : process OK
* @return PICO_ERR_OTHER : errors on getting pam sub obj pointer
* @callgraph
* @callergraph
*/
static pico_status_t pam_process_event_feature(
register picodata_ProcessingUnit this, picoos_uint8 nFeat,
picoos_uint8 event_type, picoos_uint8 direction)
{
picoos_uint8 sDest, nI;
picoos_uint16 syllCurr;
pam_subobj_t *pam;
if (NULL == this || NULL == this->subObj) {
return PICO_ERR_OTHER;
}
pam = (pam_subobj_t *) this->subObj;
syllCurr = pam->nCurrSyllable;
switch (nFeat) {
case A3:
/*processor for A3*/
switch (direction) {
case PICOPAM_DIR_FORW:
if (event_type == PICOPAM_EVENT_SYLL) {
if ((pam->sSyllFeats[pam->nCurrSyllable].phoneV[P1]
== 1) || (pam->a3_primary_phrase_syllable >= 1)) {
if (pam->a3_overall_syllable < 1)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[A3]
= 0;
else
pam->sSyllFeats[pam->nCurrSyllable].phoneV[A3]
= pam->sSyllFeats[pam->nCurrSyllable
- 1].phoneV[B3];
} else {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[A3] = 0;
}
pam->a3_primary_phrase_syllable++;
pam->a3_overall_syllable++;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->a3_primary_phrase_syllable = 0;
}
break;
case PICOPAM_DIR_BACK:
/*do nothing*/
break;
}
break;
case B1:
case B2:
case B3:
/*done in createSyllable*/
break;
case B4:/*processor for B4,B5*/
switch (direction) {
case PICOPAM_DIR_FORW:
sDest = B4;
break;
case PICOPAM_DIR_BACK:
sDest = B5;
break;
default:
sDest = B4;
break;
}
if (event_type == PICOPAM_EVENT_SYLL) {
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[P1] == 0) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= pam->b4_b5_syllable;
pam->b4_b5_syllable++;
} else {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest] = 0;
}
}
if ((event_type == PICOPAM_EVENT_W_BOUND) || (event_type
== PICOPAM_EVENT_S_BOUND) || (event_type
== PICOPAM_EVENT_P_BOUND)) {
pam->b4_b5_syllable = 1;
}
break;
case B5:/*processor for B5 : done in B4*/
break;
case B6:/*processor for B6,B7*/
switch (direction) {
case PICOPAM_DIR_FORW:
sDest = B6;
break;
case PICOPAM_DIR_BACK:
sDest = B7;
break;
default:
sDest = B6;
break;
}
switch (pam->b6_b7_state) {
case 0:
if (event_type == PICOPAM_EVENT_SYLL)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= PICOPAM_DONT_CARE_VALUE;
if (event_type == PICOPAM_EVENT_S_BOUND) {
pam->b6_b7_syllable = 1;
pam->b6_b7_state = 1;
}
break;
case 1:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= pam->b6_b7_syllable;
pam->b6_b7_syllable++;
}
if (event_type == PICOPAM_EVENT_S_BOUND) {
pam->b6_b7_syllable = 1;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->b6_b7_state = 0;
}
break;
default:
break;
}
break;
case B7:/*Done in B6*/
break;
case B8:/*processor for B8,B9*/
switch (direction) {
case PICOPAM_DIR_FORW:
sDest = B8;
break;
case PICOPAM_DIR_BACK:
sDest = B9;
break;
default:
sDest = B8;
break;
}
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= pam->b8_b9_stressed_syllable;
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[B1] == 1)
pam->b8_b9_stressed_syllable++;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->b8_b9_stressed_syllable = 0;
}
break;
case B9:/*done in B8*/
break;
case B10:/*processor for B10, B11*/
switch (direction) {
case PICOPAM_DIR_FORW:
sDest = B10;
break;
case PICOPAM_DIR_BACK:
sDest = B11;
break;
default:
sDest = B10;
break;
}
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= pam->b10_b11_accented_syllable;
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[B2] == 1)
pam->b10_b11_accented_syllable++;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->b10_b11_accented_syllable = 0;
}
break;
case B11:/*done in B10*/
break;
case B12:/*processor for B12,B13*/
switch (direction) {
case PICOPAM_DIR_FORW:
sDest = B12;
break;
case PICOPAM_DIR_BACK:
sDest = B13;
break;
default:
sDest = B12;
break;
}
switch (pam->b12_b13_state) {
case 0:
if (event_type == PICOPAM_EVENT_SYLL) {
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[B1] == 0)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= PICOPAM_DONT_CARE_VALUE;
else {
pam->b12_b13_syllable = 0;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= PICOPAM_DONT_CARE_VALUE;
pam->b12_b13_state = 1;
}
}
break;
case 1:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= pam->b12_b13_syllable;
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[B1] == 1)
pam->b12_b13_syllable = 0;
else
pam->b12_b13_syllable++;
pam->b12_b13_state = 2;
}
if (event_type == PICOPAM_EVENT_P_BOUND)
pam->b12_b13_state = 0;
break;
case 2:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= pam->b12_b13_syllable;
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[B1] == 1)
pam->b12_b13_syllable = 0;
else
pam->b12_b13_syllable++;
}
if (event_type == PICOPAM_EVENT_P_BOUND)
pam->b12_b13_state = 0;
break;
default:
break;
}
break;
case B13:/*done in B12*/
break;
case B14:/*processor for B14, B15*/
switch (direction) {
case PICOPAM_DIR_FORW:
sDest = B14;
break;
case PICOPAM_DIR_BACK:
sDest = B15;
break;
default:
sDest = B14;
break;
}
switch (pam->b14_b15_state) {
case 0:
if (event_type == PICOPAM_EVENT_SYLL) {
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[B2] == 0)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= PICOPAM_DONT_CARE_VALUE;
else {
pam->b14_b15_syllable = 0;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= PICOPAM_DONT_CARE_VALUE;
pam->b14_b15_state = 1;
}
}
break;
case 1:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= pam->b14_b15_syllable;
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[B2] == 1)
pam->b14_b15_syllable = 0;
else
pam->b14_b15_syllable++;
pam->b14_b15_state = 2;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->b14_b15_state = 0;
}
break;
case 2:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= pam->b14_b15_syllable;
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[B2] == 1)
pam->b14_b15_syllable = 0;
else
pam->b14_b15_syllable++;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->b14_b15_state = 0;
}
break;
default:
break;
}
break;
case B15:/*Processor for B15 : done in B14*/
break;
case B16:/*done in createSyllable*/
break;
case B17:/*processor for B17, B19 unified */
switch (direction) {
case PICOPAM_DIR_FORW:
switch (pam->b17_b19_state) {
case 0:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B17]
= PICOPAM_DONT_CARE_VALUE;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B19]
= pam->b17_b19_syllable;
pam->b17_b19_syllable++;
}
if (((event_type == PICOPAM_EVENT_P_BOUND)
|| (event_type == PICOPAM_EVENT_S_BOUND))
&& (pam->b17_b19_syllable > 1)) {
if (event_type == PICOPAM_EVENT_P_BOUND)
pam->b17_b19_syllable = 1;
pam->b17_b19_state = 1;
}
break;
case 1:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B17]
= pam->b17_b19_syllable;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B19]
= PICOPAM_DONT_CARE_VALUE;
pam->b17_b19_syllable++;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->b17_b19_syllable = 1;
}
break;
default:
break;
}
break;
case PICOPAM_DIR_BACK:
/*do nothing*/
break;
}
break;
case B18:/*processor for B18, B20, B21 unfied*/
switch (direction) {
case PICOPAM_DIR_FORW:/*do nothing*/
break;
case PICOPAM_DIR_BACK:
switch (pam->b18_b20_b21_state) {
case 0:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B18]
= PICOPAM_DONT_CARE_VALUE;
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[P6]
== PICOPAM_DECLARATIVE) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B20]
= pam->b18_b20_b21_syllable;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B21]
= PICOPAM_DONT_CARE_VALUE;
} else {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B20]
= PICOPAM_DONT_CARE_VALUE;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B21]
= pam->b18_b20_b21_syllable;
}
pam->b18_b20_b21_syllable++;
}
if (((event_type == PICOPAM_EVENT_P_BOUND)
|| (event_type == PICOPAM_EVENT_S_BOUND))
&& (pam->b18_b20_b21_syllable > 1)) {
if (event_type == PICOPAM_EVENT_P_BOUND)
pam->b18_b20_b21_syllable = 1;
pam->b18_b20_b21_state = 1;
}
break;
case 1:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B18]
= pam->b18_b20_b21_syllable;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B20]
= PICOPAM_DONT_CARE_VALUE;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B21]
= PICOPAM_DONT_CARE_VALUE;
pam->b18_b20_b21_syllable++;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->b18_b20_b21_syllable = 1;
}
break;
default:
break;
}
break;
}
break;
case B19:/*processor for B19 : done in B17*/
break;
case B20:/*processor for B20 : done in B18*/
break;
case B21:/*processor for B21 : done in B18*/
break;
case C3:/*processor for C3*/
switch (direction) {
case PICOPAM_DIR_FORW:
/*do nothing*/
break;
case PICOPAM_DIR_BACK:
if (event_type == PICOPAM_EVENT_SYLL) {
if ((pam->sSyllFeats[pam->nCurrSyllable].phoneV[P1]
== 1) || (pam->c3_primary_phrase_syllable >= 1)) {
if (pam->c3_overall_syllable < 1)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[C3]
= 0;
else
pam->sSyllFeats[pam->nCurrSyllable].phoneV[C3]
= pam->sSyllFeats[pam->nCurrSyllable
+ 1].phoneV[B3];
} else {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[C3] = 0;
}
pam->c3_primary_phrase_syllable++;
pam->c3_overall_syllable++;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->c3_primary_phrase_syllable = 0;
}
break;
}
break;
case D2:/*processor for D2*/
switch (direction) {
case PICOPAM_DIR_FORW:
if (event_type == PICOPAM_EVENT_SYLL) {
if ((pam->sSyllFeats[pam->nCurrSyllable].phoneV[P1]
== 1) || (pam->d2_current_primary_phrase_word
>= 1))
pam->sSyllFeats[pam->nCurrSyllable].phoneV[D2]
= pam->d2_prev_syllable_in_word;
else
pam->sSyllFeats[pam->nCurrSyllable].phoneV[D2] = 0;
pam->d2_syllable_in_word++;
}
if ((event_type == PICOPAM_EVENT_W_BOUND) || (event_type
== PICOPAM_EVENT_S_BOUND) || (event_type
== PICOPAM_EVENT_P_BOUND)) {
pam->d2_current_primary_phrase_word = 1;
pam->d2_prev_syllable_in_word
= pam->d2_syllable_in_word;
pam->d2_syllable_in_word = 0;
/*pam->d2_current_primary_phrase_word++;*/
}
if ((event_type == PICOPAM_EVENT_P_BOUND)) {
pam->d2_current_primary_phrase_word = 0;
}
break;
case PICOPAM_DIR_BACK:
/*do nothing*/
break;
}
break;
case E1:/*processor for E1*/
switch (direction) {
case PICOPAM_DIR_FORW: /*remember : content syllable indicator already on P5*/
if (event_type == PICOPAM_EVENT_SYLL) {
if (pam->e1_syllable_word_start == -1)
pam->e1_syllable_word_start
= (picoos_int8) pam->nCurrSyllable;
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[P5] == 1)
pam->e1_content = 1;
pam->e1_syllable_word_end
= (picoos_int8) pam->nCurrSyllable;
}
if ((event_type == PICOPAM_EVENT_W_BOUND) || (event_type
== PICOPAM_EVENT_S_BOUND) || (event_type
== PICOPAM_EVENT_P_BOUND)) {
if ((pam->e1_syllable_word_start != -1)
&& (pam->e1_syllable_word_end != -1)) {
for (nI = pam->e1_syllable_word_start; nI
<= pam->e1_syllable_word_end; nI++)
pam->sSyllFeats[nI].phoneV[E1]
= pam->e1_content;
}
pam->e1_content = 0;
pam->e1_syllable_word_start = -1;
pam->e1_syllable_word_end = -1;
}
break;
case PICOPAM_DIR_BACK:
/*do nothing*/
break;
}
break;
case E2:/*processor for E2*/
switch (direction) {
case PICOPAM_DIR_FORW:
if (event_type == PICOPAM_EVENT_SYLL) {
if (pam->e2_syllable_word_start == -1)
pam->e2_syllable_word_start
= (picoos_int8) pam->nCurrSyllable;
pam->e2_syllable_word_end
= (picoos_int8) pam->nCurrSyllable;
}
if ((event_type == PICOPAM_EVENT_W_BOUND) || (event_type
== PICOPAM_EVENT_S_BOUND) || (event_type
== PICOPAM_EVENT_P_BOUND)) {
if ((pam->e2_syllable_word_start != -1)
&& (pam->e2_syllable_word_end != -1)) {
for (nI = pam->e2_syllable_word_start; nI
<= pam->e2_syllable_word_end; nI++)
pam->sSyllFeats[nI].phoneV[E2]
= pam->e2_syllable_word_end
- pam->e2_syllable_word_start
+ 1;
}
pam->e1_content = 0;
pam->e2_syllable_word_start = -1;
pam->e2_syllable_word_end = -1;
}
break;
case PICOPAM_DIR_BACK:
break;
}
break;
case E3:/*processor for E3,E4*/
switch (direction) {
case PICOPAM_DIR_FORW:
sDest = E3;
break;
case PICOPAM_DIR_BACK:
sDest = E4;
break;
default:
sDest = E3;
break;
}
switch (pam->e3_e4_state) {
case 0:
if (event_type == PICOPAM_EVENT_SYLL)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= PICOPAM_DONT_CARE_VALUE;
if (event_type == PICOPAM_EVENT_S_BOUND) {
pam->e3_e4_word = 1;
pam->e3_e4_state = 1;
}
break;
case 1:
if (event_type == PICOPAM_EVENT_SYLL)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= pam->e3_e4_word;
if (event_type == PICOPAM_EVENT_S_BOUND)
pam->e3_e4_word = 1;
if (event_type == PICOPAM_EVENT_W_BOUND)
pam->e3_e4_word++;
if (event_type == PICOPAM_EVENT_P_BOUND)
pam->e3_e4_state = 0;
break;
default:
break;
}
break;
case E4:/*processor for E4 : done in E3*/
break;
case E5:/*processor for E5,E6*/
switch (direction) {
case PICOPAM_DIR_FORW:
sDest = E5;
break;
case PICOPAM_DIR_BACK:
sDest = E6;
break;
default:
sDest = E5;
break;
}
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= pam->e5_e6_content_word;
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[P5] == 1)
pam->e5_e6_content = 1;
}
if ((event_type == PICOPAM_EVENT_W_BOUND) || (event_type
== PICOPAM_EVENT_S_BOUND) || (event_type
== PICOPAM_EVENT_P_BOUND)) {
if (pam->e5_e6_content == 1)
pam->e5_e6_content_word++;
pam->e5_e6_content = 0;
if (event_type == PICOPAM_EVENT_P_BOUND)
pam->e5_e6_content_word = 0;
}
break;
case E6:/*processor for E6 : done in E5*/
break;
case E7:/*processor for E7,E8*/
switch (direction) {
case PICOPAM_DIR_FORW:
sDest = E7;
break;
case PICOPAM_DIR_BACK:
sDest = E8;
break;
default:
sDest = E7;
break;
}
switch (pam->e7_e8_state) {
case 0:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= PICOPAM_DONT_CARE_VALUE;
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[P5] == 1)
pam->e7_e8_content = 1;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->e7_e8_content = 0;
}
if ((event_type == PICOPAM_EVENT_W_BOUND) || (event_type
== PICOPAM_EVENT_S_BOUND)) {
if (pam->e7_e8_content == 1) {
pam->e7_e8_word = 0;
pam->e7_e8_content = 0;
pam->e7_e8_state = 1;
}
}
break;
case 1:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= pam->e7_e8_word;
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[P5] == 1)
pam->e7_e8_content = 1;
}
if ((event_type == PICOPAM_EVENT_W_BOUND) || (event_type
== PICOPAM_EVENT_S_BOUND)) {
if (pam->e7_e8_content == 1) {
pam->e7_e8_word = 0;
pam->e7_e8_content = 0;
} else {
pam->e7_e8_word++;
}
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->e7_e8_state = 0;
pam->e7_e8_content = 0; /*<<<<<< added */
}
default:
break;
}
break;
case E8:/*processor for E8 : done in E7*/
break;
case E9:
/*processor for E9, E11*/
switch (direction) {
case PICOPAM_DIR_FORW:
switch (pam->e9_e11_state) {
case 0:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E9]
= PICOPAM_DONT_CARE_VALUE;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E11]
= pam->e9_e11_word;
pam->e9_e11_saw_word = 1; /*new variable, needs to be initialized to 0*/
}
if (event_type == PICOPAM_EVENT_W_BOUND)
pam->e9_e11_word++;
if (((event_type == PICOPAM_EVENT_P_BOUND)
|| (event_type == PICOPAM_EVENT_S_BOUND))
&& (pam->e9_e11_saw_word == 1)) { /* modified*/
if (event_type == PICOPAM_EVENT_P_BOUND)
pam->e9_e11_word = 1;
else
pam->e9_e11_word++; /*modified*/
pam->e9_e11_state = 1;
}
break;
case 1:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E9]
= pam->e9_e11_word;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E11]
= PICOPAM_DONT_CARE_VALUE;
}
if ((event_type == PICOPAM_EVENT_W_BOUND)
|| (event_type == PICOPAM_EVENT_S_BOUND))
pam->e9_e11_word++;
if (event_type == PICOPAM_EVENT_P_BOUND)
pam->e9_e11_word = 1;
break;
default:
break;
}
break;
case PICOPAM_DIR_BACK:
/*do nothing*/
break;
}
break;
case E10:/*processor for E10, E12, E13 unified*/
switch (direction) {
case PICOPAM_DIR_FORW:/*do nothing*/
break;
case PICOPAM_DIR_BACK:
switch (pam->e10_e12_e13_state) {
case 0:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E10]
= PICOPAM_DONT_CARE_VALUE;
pam->e10_e12_e13_saw_word = 1;
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[P6]
== PICOPAM_DECLARATIVE) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E12]
= pam->e10_e12_e13_word;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E13]
= PICOPAM_DONT_CARE_VALUE;
} else {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E12]
= PICOPAM_DONT_CARE_VALUE;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E13]
= pam->e10_e12_e13_word;
}
}
if (event_type == PICOPAM_EVENT_W_BOUND)
pam->e10_e12_e13_word++;
/*if (((event_type==PICOPAM_EVENT_P_BOUND)||(event_type==PICOPAM_EVENT_S_BOUND))&&(pam->e10_e12_e13_word>1)) {*/
if (((event_type == PICOPAM_EVENT_P_BOUND)
|| (event_type == PICOPAM_EVENT_S_BOUND))
&& (pam->e10_e12_e13_saw_word > 0)) {
if (event_type == PICOPAM_EVENT_P_BOUND)
pam->e10_e12_e13_word = 1;
else
pam->e10_e12_e13_word++;
pam->e10_e12_e13_state = 1;
}
break;
case 1:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E10]
= pam->e10_e12_e13_word;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E12]
= PICOPAM_DONT_CARE_VALUE;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E13]
= PICOPAM_DONT_CARE_VALUE;
}
if ((event_type == PICOPAM_EVENT_W_BOUND)
|| (event_type == PICOPAM_EVENT_S_BOUND))
pam->e10_e12_e13_word++;
if (event_type == PICOPAM_EVENT_P_BOUND)
pam->e10_e12_e13_word = 1;
break;
default:
break;
}
break;
}
break;
case E11:/*processor for E11 : done in E9*/
break;
case E12:/*processor for E12 : done in E10*/
break;
case E13:/*processor for E13 : done in E10*/
break;
case F2:
switch (direction) {
case PICOPAM_DIR_FORW:/*do nothing*/
break;
case PICOPAM_DIR_BACK:
if (event_type == PICOPAM_EVENT_SYLL) {
if (pam->f2_current_primary_phrase_word >= 1)/*at least second word in current primary phrase*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[F2]
= pam->f2_next_word_syllable;
else
/*first word in current primary phrase*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[F2] = 0;
pam->f2_word_syllable++;
}
if ((event_type == PICOPAM_EVENT_W_BOUND) || (event_type
== PICOPAM_EVENT_S_BOUND) || (event_type
== PICOPAM_EVENT_P_BOUND)) {/*word - end : switch*/
pam->f2_next_word_syllable = pam->f2_word_syllable;
pam->f2_word_syllable = 0;
}
if (event_type == PICOPAM_EVENT_P_BOUND)/*mark first word in current primary phrase*/
pam->f2_current_primary_phrase_word = 0;
else /*mark next word in current primary phrase(enables output in PICOPAM_EVENT_SYLL)*/
if ((event_type == PICOPAM_EVENT_W_BOUND) || (event_type
== PICOPAM_EVENT_S_BOUND))
pam->f2_current_primary_phrase_word++;
break;
}
break;
case G1:
switch (direction) {
case PICOPAM_DIR_FORW:
if (event_type == PICOPAM_EVENT_SYLL) {
if (pam->g1_current_secondary_phrase_syllable > 0)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[G1]
= pam->g1_current_secondary_phrase_syllable;
else
pam->sSyllFeats[pam->nCurrSyllable].phoneV[G1] = 0;
pam->g1_current_syllable++;
}
if (event_type == PICOPAM_EVENT_S_BOUND) {
pam->g1_current_secondary_phrase_syllable
= pam->g1_current_syllable;
pam->g1_current_syllable = 0;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->g1_current_secondary_phrase_syllable = 0;
pam->g1_current_syllable = 0;
}
case PICOPAM_DIR_BACK: /*do nothing*/
break;
}
break;
case G2:
switch (direction) {
case PICOPAM_DIR_FORW:
if (event_type == PICOPAM_EVENT_SYLL) {
if (pam->g2_current_secondary_phrase_word > 0)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[G2]
= pam->g2_current_secondary_phrase_word;
else
pam->sSyllFeats[pam->nCurrSyllable].phoneV[G2] = 0;
}
if (event_type == PICOPAM_EVENT_W_BOUND)
pam->g2_current_word++;
if (event_type == PICOPAM_EVENT_S_BOUND) {
pam->g2_current_secondary_phrase_word
= pam->g2_current_word + 1;
pam->g2_current_word = 0;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->g2_current_secondary_phrase_word = 0;
pam->g2_current_word = 0;
}
break;
case PICOPAM_DIR_BACK: /*do nothing*/
break;
}
break;
case H1:
switch (direction) {
case PICOPAM_DIR_FORW:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->h1_current_secondary_phrase_syll++;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H1]
= pam->h1_current_secondary_phrase_syll;
}
if ((event_type == PICOPAM_EVENT_S_BOUND) || (event_type
== PICOPAM_EVENT_P_BOUND))
pam->h1_current_secondary_phrase_syll = 0;
break;
case PICOPAM_DIR_BACK:
if (event_type == PICOPAM_EVENT_SYLL)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H1]
= pam->h1_current_secondary_phrase_syll;
if (event_type == PICOPAM_EVENT_S_BOUND)
pam->h1_current_secondary_phrase_syll
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[H1];
if (event_type == PICOPAM_EVENT_P_BOUND)
pam->h1_current_secondary_phrase_syll
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[H1];
break;
}
break;
case H2:
switch (direction) {
case PICOPAM_DIR_FORW:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H2]
= pam->h2_current_secondary_phrase_word;
}
if (event_type == PICOPAM_EVENT_W_BOUND) {
pam->h2_current_secondary_phrase_word++;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H2]
= pam->h2_current_secondary_phrase_word;
}
if (event_type == PICOPAM_EVENT_S_BOUND) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H2]
= pam->h2_current_secondary_phrase_word + 1;
pam->h2_current_secondary_phrase_word = 0;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
if (pam->nCurrSyllable > 1)
pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[H2]
= pam->h2_current_secondary_phrase_word + 1;
pam->h2_current_secondary_phrase_word = 0;
}
break;
case PICOPAM_DIR_BACK:
if (event_type == PICOPAM_EVENT_SYLL)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H2]
= pam->h2_current_secondary_phrase_word;
if (event_type == PICOPAM_EVENT_S_BOUND)
pam->h2_current_secondary_phrase_word
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[H2];
if (event_type == PICOPAM_EVENT_P_BOUND)
pam->h2_current_secondary_phrase_word
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[H2];
break;
}
break;
case H3:/*processor for H3,H4 unified */
switch (direction) {
case PICOPAM_DIR_FORW:
sDest = H3;
break;
case PICOPAM_DIR_BACK:
sDest = H4;
break;
default:
sDest = H3;
break;
}
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[sDest]
= pam->h3_h4_current_secondary_phrase_word;
}
if ((event_type == PICOPAM_EVENT_S_BOUND) || (event_type
== PICOPAM_EVENT_P_BOUND))
pam->h3_h4_current_secondary_phrase_word++;
break;
case H4: /*processor for H4 : already in H3*/
break;
case H5:/*processor for H5*/
switch (direction) {
case PICOPAM_DIR_FORW:
break;
case PICOPAM_DIR_BACK:
switch (pam->h5_state) {
case 0:
if (event_type == PICOPAM_EVENT_SYLL)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H5]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[H5];
if (event_type == PICOPAM_EVENT_S_BOUND) {
pam->h5_state = 1;
}
break;
case 1:
if (event_type == PICOPAM_EVENT_SYLL) {
if ((pam->sSyllFeats[pam->nCurrSyllable].phoneV[H5]
== PICOPAM_P)
&& (pam->sSyllFeats[pam->nCurrSyllable].phoneV[P1]
== 0))
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H5]
= PICOPAM_p;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->h5_state = 0;
}
break;
default:
break;
}
break;
default:
break;
}
break;
case I1:/*processor for I1*/
switch (direction) {
case PICOPAM_DIR_FORW:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->i1_secondary_phrase_syllable++;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[I1]
= pam->i1_secondary_phrase_syllable;
}
if ((event_type == PICOPAM_EVENT_S_BOUND) || (event_type
== PICOPAM_EVENT_P_BOUND))
pam->i1_secondary_phrase_syllable = 0;
break;
case PICOPAM_DIR_BACK:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[I1]
= pam->i1_next_secondary_phrase_syllable;
}
if (event_type == PICOPAM_EVENT_S_BOUND) {
pam->i1_next_secondary_phrase_syllable
= pam->i1_secondary_phrase_syllable;
pam->i1_secondary_phrase_syllable
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[I1];
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->i1_next_secondary_phrase_syllable = 0;
pam->i1_secondary_phrase_syllable
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[I1];
}
break;
}
break;
case I2: /*processor for I2*/
switch (direction) {
case PICOPAM_DIR_FORW:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[I2]
= pam->i2_secondary_phrase_word;
}
if (event_type == PICOPAM_EVENT_W_BOUND)
pam->i2_secondary_phrase_word++;
if ((event_type == PICOPAM_EVENT_P_BOUND) || (event_type
== PICOPAM_EVENT_S_BOUND))
pam->i2_secondary_phrase_word = 1;
break;
case PICOPAM_DIR_BACK:
if (event_type == PICOPAM_EVENT_SYLL) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[I2]
= pam->i2_next_secondary_phrase_word;
}
if (event_type == PICOPAM_EVENT_S_BOUND) {
pam->i2_next_secondary_phrase_word
= pam->i2_secondary_phrase_word;
pam->i2_secondary_phrase_word
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[I2];
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->i2_next_secondary_phrase_word = 0;
pam->i2_secondary_phrase_word
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[I2];
}
break;
}
break;
case J1: /*processor for J1 */
switch (direction) {
case PICOPAM_DIR_FORW:
if (event_type == PICOPAM_EVENT_SYLL) {
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[P1] != 1)
pam->j1_utterance_syllable++;
}
break;
case PICOPAM_DIR_BACK:
pam->sSyllFeats[pam->nCurrSyllable].phoneV[J1]
= pam->j1_utterance_syllable;
break;
}
break;
case J2: /*processor for J2*/
switch (direction) {
case PICOPAM_DIR_FORW:
if ((event_type == PICOPAM_EVENT_W_BOUND) || (event_type
== PICOPAM_EVENT_S_BOUND) || (event_type
== PICOPAM_EVENT_P_BOUND))
pam->j2_utterance_word++;
break;
case PICOPAM_DIR_BACK:
pam->sSyllFeats[pam->nCurrSyllable].phoneV[J2]
= pam->j2_utterance_word - 1;
break;
}
break;
case J3: /*processor for J3*/
switch (direction) {
case PICOPAM_DIR_FORW:
if (event_type == PICOPAM_EVENT_S_BOUND) {
pam->j3_utterance_sec_phrases++;
break;
}
if (event_type == PICOPAM_EVENT_P_BOUND) {
pam->j3_utterance_sec_phrases++;
break;
}
break;
case PICOPAM_DIR_BACK:
pam->sSyllFeats[pam->nCurrSyllable].phoneV[J3]
= pam->j3_utterance_sec_phrases - 1;
break;
}
break;
}
return PICO_OK;
}/*pam_process_event_feature*/
/**
* processes an input event spanning it to all column features
* @param this : pointer to PAM PU sub object pointer
* @param event_type : event id among syll/boundprim/boundsec/boundword
* @param direction : forward(0)/backward(1)
* @return PICO_OK : process OK
* @return PICO_ERR_OTHER : errors on getting pam sub obj pointer
* @callgraph
* @callergraph
*/
static pico_status_t pam_process_event(register picodata_ProcessingUnit this,
picoos_uint8 event_type, picoos_uint8 direction)
{
picoos_uint8 nFeat;
pico_status_t nResult;
pam_subobj_t *pam;
if (NULL == this || NULL == this->subObj) {
return PICO_ERR_OTHER;
}
pam = (pam_subobj_t *) this->subObj;
if (direction == PICOPAM_DIR_FORW) {
if (event_type == PICOPAM_EVENT_P_BOUND)
/*primary boundary*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[P2] = 1;
if (event_type == PICOPAM_EVENT_S_BOUND)
/*secondary boundary*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[P3] = 1;
if (event_type == PICOPAM_EVENT_W_BOUND)
/*word boundary*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[P4] = 1;
}
for (nFeat = A3; nFeat <= J3; nFeat++) {
nResult = pam_process_event_feature(this, nFeat, event_type, direction);
if (nResult != PICO_OK)
return nResult;
}
return PICO_OK;
}/*pam_process_event*/
/**
* inserts a syllable inside the subobj sentence data struct.
* @param this : pointer to PAM PU sub object pointer
* @param syllType : the syllable type (pause/syllable)
* @param sContent : the item content
* @param sentType : the sentence type
* @param phType : the phrase type
* @param uBoundType : the boundary type (only for silence syllables)
* @param uMinDur, uMaxDur : the mimimum and maximum duration (only for silence syllables)
* @return PICO_OK : syllable creation successful
* @return PICO_ERR_OTHER : errors in one internal function (check_phones_size..)
* @callgraph
* @callergraph
*/
static pico_status_t pam_create_syllable(register picodata_ProcessingUnit this,
picoos_uint8 syllType, picoos_uint8 *sContent, picoos_uint8 sentType,
picoos_uint8 phType, picoos_uint8 uBoundType, picoos_uint16 uMinDur,
picoos_uint16 uMaxDur)
{
pam_subobj_t *pam;
picoos_uint8 nI;
picoos_uint8 pos;
/* picoos_uint8 *npUi16; */
picoos_uint32 pos32;
if (NULL == this || NULL == this->subObj) {
return PICO_ERR_OTHER;
}
pam = (pam_subobj_t *) this->subObj;
pos = 0;
/*check buffer full condition on number of syllables*/
if (check_syllables_size(pam, 1) != PICO_OK) {
return PICO_ERR_OTHER;
}
if (syllType == PICOPAM_SYLL_PAUSE) {
/*check buffer full condition on number of phonemes*/
if (check_phones_size(pam, 1) != PICO_OK) {
return PICO_ERR_OTHER;
}
}
if (syllType == PICOPAM_SYLL_SYLL) {
/*check item availability*/
if (sContent == NULL) {
return PICO_ERR_OTHER;
}
/*check buffer full condition on number of phonemes*/
if (check_phones_size(pam, sContent[3]) != PICO_OK) {
return PICO_ERR_OTHER;
}
}
/*open new syllable*/
pam->nCurrSyllable = pam->nCurrSyllable + 1;
/*cleanup*/
for (nI = 0; nI < PICOPAM_VECT_SIZE; nI++) {
if (pam->nCurrSyllable > 0) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[nI] = 0;
} else {
if ((nI >= ITM) && (nI <= itm)) {
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[nI] > 0) {
/*do not cleanup "attached item offset" fields (ITM, itm):
an already existing attached item could be lost*/
} else {
/*cleanup "attached item offset"*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[nI] = 0;
}
} else {
/*cleanup all fields except "attached item offset" (ITM, itm)*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[nI] = 0;
}
}
}
/*set minimum and maximum duration values*/
if ((uMinDur == 0) && (uMaxDur == 0) && (syllType == PICOPAM_SYLL_PAUSE)) {
/*both 0 : use default duration limits for boundaries*/
get_default_boundary_limit(uBoundType, &uMinDur, &uMaxDur);
}
if (uMinDur > 0) {
pos32 = Min;
picoos_write_mem_pi_uint16(pam->sSyllFeats[pam->nCurrSyllable].phoneV,
&pos32, uMinDur);
}
if (uMaxDur > 0) {
pos32 = Max;
picoos_write_mem_pi_uint16(pam->sSyllFeats[pam->nCurrSyllable].phoneV,
&pos32, uMaxDur);
}
/*END OF BREAK COMMAND SUPPORT*/
if (syllType == PICOPAM_SYLL_PAUSE) {
/*initialize a pause syllable*/
if (sentType == PICOPAM_DECLARATIVE)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[P6]
= PICOPAM_DECLARATIVE;
if (sentType == PICOPAM_INTERROGATIVE)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[P6]
= PICOPAM_INTERROGATIVE;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[bnd] = uBoundType;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[P1] = 1; /*this means the syllable contains a pause-silence*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[P8] = 1;
/*b1,b2,b9,b11,b13,b15,e1,e6,e8,e10 already set to 0*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B3]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[B4]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[B5]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[B6]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[B7]
= 1;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B16]
= PICOPAM_PH_DONT_CARE_VAL; /*name of the vowel in the syllable = NONE */
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E2]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[E3]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[E4] = 1;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H5] = phType;
/*Store current phonetic codes in input phonetic string*/
pam->sPhIds[pam->nCurrPhoneme] = pam_get_pause_id(this);
picoos_mem_copy((void*) &pam->nCurrPhoneme,
&(pam->sSyllFeats[pam->nCurrSyllable].phoneV[FID]),
sizeof(pam->nCurrPhoneme));
pam->nCurrPhoneme++;
pam->nTotalPhonemes++;
/*add 1 to total number of syllables*/
pam->nTotalSyllables++;
return PICO_OK;
}
if (syllType == PICOPAM_SYLL_SYLL) {
/*initialize a real syllable*/
if (sContent[2] > PICODATA_ACC0)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[P5] = 1; /*set content syllable indicator*/
if (sentType == PICOPAM_DECLARATIVE)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[P6]
= PICOPAM_DECLARATIVE;
if (sentType == PICOPAM_INTERROGATIVE)
pam->sSyllFeats[pam->nCurrSyllable].phoneV[P6]
= PICOPAM_INTERROGATIVE;
if ((sContent[2] >= PICODATA_ACC1) && (sContent[2] <= PICODATA_ACC4))
/*stressed*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B1] = 1;
if ((sContent[2] >= PICODATA_ACC1) && (sContent[2] <= PICODATA_ACC2))
/*accented*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B2] = 1;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B3] = sContent[3];/*len*/
if (pam->nCurrSyllable > 30)
pam->nCurrSyllable = pam->nCurrSyllable;
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B16] = pam_get_vowel_name(this,
sContent, &pos); /*name of the vowel in the syllable*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[P8] = pos; /*temp for storing the position of the vowel*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H5] = phType;
/*Store current phonetic codes in input phonetic string*/
picoos_mem_copy((void*) &pam->nCurrPhoneme,
&(pam->sSyllFeats[pam->nCurrSyllable].phoneV[FID]),
sizeof(pam->nCurrPhoneme));
for (nI = 0; nI < sContent[3]; nI++)
pam->sPhIds[pam->nCurrPhoneme + nI] = sContent[4 + nI];
pam->nCurrPhoneme += nI;
pam->nTotalPhonemes += nI;
/*add 1 to total number of syllables*/
pam->nTotalSyllables++;
return PICO_OK;
}
/*if no SyllType has been identified -->> error*/
return PICO_ERR_OTHER;
}/*pam_create_syllable*/
/**
* performs the forward step of the PAM adapter
* @param this : pointer to PAM PU sub object pointer
* @param itemBase : pointer to current item
* @return PICOPAM_READY : forward step ok, the sentence is complete
* @return PICOPAM_MORE : forward step ok, but more data needed to complete the sentence
* @return PICO_ERR_OTHER : errors in one internal function (CreateSyllable..)
* @callgraph
* @callergraph
*/
static pico_status_t pam_adapter_forward_step(
register picodata_ProcessingUnit this, picoos_uint8 *itemBase)
{
register pam_subobj_t * pam;
pico_status_t sResult;
picoos_uint16 uMinDur, uMaxDur;
picoos_uint32 nPos;
if (NULL == this || NULL == this->subObj) {
return PICO_ERR_OTHER;
}
pam = (pam_subobj_t *) this->subObj;
uMinDur = uMaxDur = 0; /*default 0 : not initialized*/
switch (itemBase[0]) {
case PICODATA_ITEM_BOUND:
/*received a boundary item*/
switch (itemBase[1]) {
case PICODATA_ITEMINFO1_BOUND_SBEG:
case PICODATA_ITEMINFO1_BOUND_PHR1:
#ifdef PAM_PHR2_WITH_PR1
case PICODATA_ITEMINFO1_BOUND_PHR2:
#endif
case PICODATA_ITEMINFO1_BOUND_SEND:
case PICODATA_ITEMINFO1_BOUND_TERM:
if (itemBase[3] == 2 * sizeof(picoos_uint16)) {
/*only when the item len duration is equal to 2 int16 --> get the values*/
nPos = 4;
picoos_read_mem_pi_uint16(itemBase, &nPos, &uMinDur);
picoos_read_mem_pi_uint16(itemBase, &nPos, &uMaxDur);
}
break;
default:
break;
}
switch (itemBase[1]) {
case PICODATA_ITEMINFO1_BOUND_SBEG:
/* received a sentence init boundary */
pam_reset_processors(this); /*reset all processor variables*/
pam->sType
= pam_map_sentence_type(itemBase[1], itemBase[2]);
pam->pType = pam_map_phrase_type(itemBase[1], itemBase[2]);
/*create silence syll and process P_BOUND event*/
sResult = pam_create_syllable(this, PICOPAM_SYLL_PAUSE, NULL,
pam->sType, pam->pType, itemBase[1], uMinDur,
uMaxDur);
if (sResult != PICO_OK)
return sResult;
sResult = pam_process_event(this, PICOPAM_EVENT_P_BOUND,
PICOPAM_DIR_FORW);
if (sResult != PICO_OK)
return sResult;
return PICOPAM_MORE;
break;
case PICODATA_ITEMINFO1_BOUND_PHR1:
#ifdef PAM_PHR2_WITH_PR1
case PICODATA_ITEMINFO1_BOUND_PHR2:
#endif
/*received a primary boundary*/
pam->sType
= pam_map_sentence_type(itemBase[1], itemBase[2]);
pam->pType = pam_map_phrase_type(itemBase[1], itemBase[2]);
/*create silence syll and process P_BOUND event*/
sResult = pam_create_syllable(this, PICOPAM_SYLL_PAUSE, NULL,
pam->sType, pam->pType, itemBase[1], uMinDur,
uMaxDur);
if (sResult != PICO_OK)
return sResult;
sResult = pam_process_event(this, PICOPAM_EVENT_P_BOUND,
PICOPAM_DIR_FORW);
if (sResult != PICO_OK)
return sResult;
return PICOPAM_MORE;
break;
#ifdef PAM_PHR2_WITH_PR3
case PICODATA_ITEMINFO1_BOUND_PHR2 :
#endif
case PICODATA_ITEMINFO1_BOUND_PHR3:
/*received a secondary boundary*/
/*process S_BOUND event*/
sResult = pam_process_event(this, PICOPAM_EVENT_S_BOUND,
PICOPAM_DIR_FORW);
/*determine new sentence and Phrase types for following syllables*/
pam->sType
= pam_map_sentence_type(itemBase[1], itemBase[2]);
pam->pType = pam_map_phrase_type(itemBase[1], itemBase[2]);
if (sResult != PICO_OK)
return sResult;
return PICOPAM_MORE;
break;
case PICODATA_ITEMINFO1_BOUND_PHR0:
/*received a word end boundary*/
/*process W_BOUND event*/
sResult = pam_process_event(this, PICOPAM_EVENT_W_BOUND,
PICOPAM_DIR_FORW);
if (sResult != PICO_OK)
return sResult;
return PICOPAM_MORE;
break;
case PICODATA_ITEMINFO1_BOUND_SEND:
/*received a SEND boundary*/
/*insert a new silence syllable and process P_BOUND event*/
/*create silence syll and process P_BOUND event*/
sResult = pam_create_syllable(this, PICOPAM_SYLL_PAUSE, NULL,
pam->sType, pam->pType, itemBase[1], uMinDur,
uMaxDur);
if (sResult != PICO_OK)
return sResult;
sResult = pam_process_event(this, PICOPAM_EVENT_P_BOUND,
PICOPAM_DIR_FORW);
if (sResult != PICO_OK)
return sResult;
return PICOPAM_READY;
break;
case PICODATA_ITEMINFO1_BOUND_TERM:
/* received a flush boundary*/
if (pam->nCurrSyllable == -1) {
return PICOPAM_NA;
}
/*insert a new silence syllable and process P_BOUND event*/
/*create silence syll and process P_BOUND event*/
sResult = pam_create_syllable(this, PICOPAM_SYLL_PAUSE, NULL,
pam->sType, pam->pType, itemBase[1], uMinDur,
uMaxDur);
if (sResult != PICO_OK)
return sResult;
sResult = pam_process_event(this, PICOPAM_EVENT_P_BOUND,
PICOPAM_DIR_FORW);
if (sResult != PICO_OK)
return sResult;
return PICOPAM_READY;
break;
default:
/*boundary type not known*/
return PICOPAM_NA;
break;
}/*end switch (itemBase[1])*/
break; /*end case PICODATA_ITEM_BOUND*/
case PICODATA_ITEM_SYLLPHON:
/*received a syllable item*/
/* ------------------------------------------------------------------
following code has to be used if we do expect
SYLL items arrive even without SBEG items starting the sentence.
this may happen after a term has been issued to make room in local storage.
*/
if (pam->nCurrSyllable == -1) {
pam_reset_processors(this);
/*insert an SBEG with sType and pType taken from previous sentence*/
sResult = pam_create_syllable(this, PICOPAM_SYLL_PAUSE, NULL,
pam->sType, pam->pType, PICODATA_ITEMINFO1_BOUND_SBEG,
0, 0);
if (sResult != PICO_OK)
return sResult;
sResult = pam_process_event(this, PICOPAM_EVENT_P_BOUND,
PICOPAM_DIR_FORW);
if (sResult != PICO_OK)
return sResult;
}
/* ------------------------------------------------------------------*/
sResult = pam_create_syllable(this, PICOPAM_SYLL_SYLL, itemBase,
pam->sType, pam->pType, 0, 0, 0);
if (sResult != PICO_OK)
return sResult;
sResult = pam_process_event(this, PICOPAM_EVENT_SYLL,
PICOPAM_DIR_FORW);
if (sResult != PICO_OK)
return sResult;
return PICOPAM_MORE;
break;
default:
return PICOPAM_NA;
break;
}
return PICO_ERR_OTHER;
}/*pam_adapter_forward_step*/
/**
* performs the backward step of the PAM adapter
* @param this : pointer to PAM PU sub object pointer
* @return PICO_OK : backward step complete
* @return PICO_ERR_OTHER : errors on retrieving the PU pointer
* @remarks derived in some parts from the pam forward code
* @callgraph
* @callergraph
*/
static pico_status_t pam_adapter_backward_step(
register picodata_ProcessingUnit this)
{
register pam_subobj_t * pam;
picoos_uint8 nProcessed;
picoos_uint16 nSyll;
if (NULL == this || NULL == this->subObj) {
return PICO_ERR_OTHER;
}
pam = (pam_subobj_t *) this->subObj;
/*Resets the processors for the backward step*/
pam_reset_processors_back(this);
/*Do the backward step*/
nSyll = pam->nCurrSyllable;
while (pam->nCurrSyllable >= 0) {
nProcessed = 0;
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[P2] == 1) {
/*primary boundary*/
pam_process_event(this, PICOPAM_EVENT_P_BOUND, PICOPAM_DIR_BACK);
pam->nCurrSyllable--;
nProcessed = 1;
}
if ((nProcessed == 0)
&& (pam->sSyllFeats[pam->nCurrSyllable].phoneV[P3] == 1)) {
/*secondary boundary*/
pam_process_event(this, PICOPAM_EVENT_S_BOUND, PICOPAM_DIR_BACK);
pam_process_event(this, PICOPAM_EVENT_SYLL, PICOPAM_DIR_BACK);
pam->nCurrSyllable--;
nProcessed = 1;
}
if ((nProcessed == 0)
&& (pam->sSyllFeats[pam->nCurrSyllable].phoneV[P4] == 1)) {
/*word boundary*/
pam_process_event(this, PICOPAM_EVENT_W_BOUND, PICOPAM_DIR_BACK);
pam_process_event(this, PICOPAM_EVENT_SYLL, PICOPAM_DIR_BACK);
pam->nCurrSyllable--;
nProcessed = 1;
}
if (nProcessed == 0) {
/*non boundaried syllable*/
pam_process_event(this, PICOPAM_EVENT_SYLL, PICOPAM_DIR_BACK);
pam->nCurrSyllable--;
nProcessed = 0;
}
}/*end while (pam->nCurrSyllable>=0)*/
/*reset syllpointer to original value*/
pam->nCurrSyllable = nSyll;
/*Perform pause processing*/
pam_adapter_do_pauses(this);
pam->nCurrSyllable = 0;
pam->nSyllPhoneme = 0;
return PICO_OK;
}/*pam_adapter_backward_step*/
/**
* processes a pause (silence) syllable after backward processing
* @param this : pointer to PAM PU sub object pointer : processes a pause (silence) syllable after backward processing
* @return PICO_OK : backward step complete
* @return PICO_ERR_OTHER : errors on retrieving the PU pointer
* @remarks pam->nCurrSyllable should point to a pause item
* @remarks this function should be called after backward processing
* @remarks this function corresponds to initializing silence phonemes with
* @remarks values derived from previous or following syllables
* @callgraph
* @callergraph
*/
static pico_status_t pam_do_pause(register picodata_ProcessingUnit this)
{
picoos_uint16 syllCurr;
pam_subobj_t *pam;
if (NULL == this || NULL == this->subObj) {
return PICO_ERR_OTHER;
}
pam = (pam_subobj_t *) this->subObj;
syllCurr = pam->nCurrSyllable;
/*processor for all features that can be inherited from previous syll (or word/phrase)*/
if (pam->nCurrSyllable > 0) {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[A3]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[B3];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B8]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[B8];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B10]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[B10];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B12]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[B12];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B14]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[B14];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B17]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[B17];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B19]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[B19];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B20]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[B20];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B21]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[B21];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[D2]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[E2];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[G1]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[H1];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[G2]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[H2];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E5]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[E5];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E7]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[E7];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E9]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[E9];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E11]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[E11];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E12]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[E12];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E13]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[E13];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[E13]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[E13];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H1]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[H1];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H2]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[H2];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H3]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[H3];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H4]
= pam->sSyllFeats[pam->nCurrSyllable - 1].phoneV[H4];
} else {
pam->sSyllFeats[pam->nCurrSyllable].phoneV[A3]
=pam->sSyllFeats[pam->nCurrSyllable].phoneV[B8]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[B10]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[B12]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[B14]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[B17]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[B19]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[B20]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[B21]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[E5]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[E9]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[E11]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[E12]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[H1]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[H2]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[H3]
= 0;
/*init values different from 0*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H4]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[J3];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[H5] = PICOPAM_p;
}
/*processor for all features that can be inherited from next syll (or word/phrase)*/
if (pam->nCurrSyllable < pam->nTotalSyllables - 1) {
/*non last syllable*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[C3]
= pam->sSyllFeats[pam->nCurrSyllable + 1].phoneV[B3];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[F2]
= pam->sSyllFeats[pam->nCurrSyllable + 1].phoneV[E2];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[I1]
= pam->sSyllFeats[pam->nCurrSyllable + 1].phoneV[H1];
pam->sSyllFeats[pam->nCurrSyllable].phoneV[I2]
= pam->sSyllFeats[pam->nCurrSyllable + 1].phoneV[H2];
} else {
/*last syllable*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[C3]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[F2]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[I1]
= pam->sSyllFeats[pam->nCurrSyllable].phoneV[I2]
= 0;
}
/*Other fixed values derived from de-facto standard*/
pam->sSyllFeats[pam->nCurrSyllable].phoneV[B18] = 0;
return PICO_OK;
}/*pam_do_pause*/
/**
* performs the initialization of pause "syllables"
* @param this : pointer to PAM PU sub object pointer : processes a pause (silence) syllable after backward processing
* @return PICO_OK : pause processing successful
* @return PICO_ERR_OTHER : errors on retrieving the PU pointer
* @callgraph
* @callergraph
*/
static pico_status_t pam_adapter_do_pauses(register picodata_ProcessingUnit this)
{
register pam_subobj_t * pam;
picoos_uint16 nSyll;
if (NULL == this || NULL == this->subObj) {
return PICO_ERR_OTHER;
}
pam = (pam_subobj_t *) this->subObj;
/*Do the pause processing*/
nSyll = pam->nCurrSyllable;
while (pam->nCurrSyllable >= 0) {
if (pam->sSyllFeats[pam->nCurrSyllable].phoneV[P2] == 1) {
/*pause processing*/
pam_do_pause(this);
}
pam->nCurrSyllable--;
}/*end while (pam->nCurrSyllable>=0)*/
/*reset syllpointer to original value*/
pam->nCurrSyllable = nSyll;
return PICOPAM_READY;
}/*pam_adapter_do_pauses*/
#ifdef __cplusplus
}
#endif
/* picopam.c end */
|