eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

intonation.cpp 32KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2007 by Jonathan Duddington *
  3. * email: [email protected] *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write see: *
  17. * <http://www.gnu.org/licenses/>. *
  18. ***************************************************************************/
  19. #include "StdAfx.h"
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <wctype.h>
  23. #include "speak_lib.h"
  24. #include "speech.h"
  25. #include "phoneme.h"
  26. #include "synthesize.h"
  27. #include "voice.h"
  28. #include "translate.h"
  29. /* Note this module is mostly old code that needs to be rewritten to
  30. provide a more flexible intonation system.
  31. */
  32. static int tone_pitch_env; /* used to return pitch envelope */
  33. static int vowel_ix;
  34. static int vowel_ix_top;
  35. static int *vowel_tab;
  36. /* Pitch data for tone types */
  37. /*****************************/
  38. #define PITCHfall 0
  39. #define PITCHrise 1
  40. #define PITCHfrise 2 // and 3 must be for the varient preceded by 'r'
  41. #define PITCHfrise2 4 // and 5 must be the 'r' variant
  42. #define PITCHdrop 6
  43. #define PITCHdrop2 8
  44. //#define PITCHsemi_r 10
  45. //#define PITCH1fall 11
  46. //#define PITCH1fall2 12
  47. /* 0 fall */
  48. unsigned char env_fall[128] = {
  49. 0xff, 0xfd, 0xfa, 0xf8, 0xf6, 0xf4, 0xf2, 0xf0, 0xee, 0xec, 0xea, 0xe8, 0xe6, 0xe4, 0xe2, 0xe0,
  50. 0xde, 0xdc, 0xda, 0xd8, 0xd6, 0xd4, 0xd2, 0xd0, 0xce, 0xcc, 0xca, 0xc8, 0xc6, 0xc4, 0xc2, 0xc0,
  51. 0xbe, 0xbc, 0xba, 0xb8, 0xb6, 0xb4, 0xb2, 0xb0, 0xae, 0xac, 0xaa, 0xa8, 0xa6, 0xa4, 0xa2, 0xa0,
  52. 0x9e, 0x9c, 0x9a, 0x98, 0x96, 0x94, 0x92, 0x90, 0x8e, 0x8c, 0x8a, 0x88, 0x86, 0x84, 0x82, 0x80,
  53. 0x7e, 0x7c, 0x7a, 0x78, 0x76, 0x74, 0x72, 0x70, 0x6e, 0x6c, 0x6a, 0x68, 0x66, 0x64, 0x62, 0x60,
  54. 0x5e, 0x5c, 0x5a, 0x58, 0x56, 0x54, 0x52, 0x50, 0x4e, 0x4c, 0x4a, 0x48, 0x46, 0x44, 0x42, 0x40,
  55. 0x3e, 0x3c, 0x3a, 0x38, 0x36, 0x34, 0x32, 0x30, 0x2e, 0x2c, 0x2a, 0x28, 0x26, 0x24, 0x22, 0x20,
  56. 0x1e, 0x1c, 0x1a, 0x18, 0x16, 0x14, 0x12, 0x10, 0x0e, 0x0c, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x00 };
  57. /* 1 rise */
  58. unsigned char env_rise[128] = {
  59. 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
  60. 0x20, 0x22, 0x24, 0x26, 0x28, 0x2a, 0x2c, 0x2e, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e,
  61. 0x40, 0x42, 0x44, 0x46, 0x48, 0x4a, 0x4c, 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e,
  62. 0x60, 0x62, 0x64, 0x66, 0x68, 0x6a, 0x6c, 0x6e, 0x70, 0x72, 0x74, 0x76, 0x78, 0x7a, 0x7c, 0x7e,
  63. 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, 0x90, 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9c, 0x9e,
  64. 0xa0, 0xa2, 0xa4, 0xa6, 0xa8, 0xaa, 0xac, 0xae, 0xb0, 0xb2, 0xb4, 0xb6, 0xb8, 0xba, 0xbc, 0xbe,
  65. 0xc0, 0xc2, 0xc4, 0xc6, 0xc8, 0xca, 0xcc, 0xce, 0xd0, 0xd2, 0xd4, 0xd6, 0xd8, 0xda, 0xdc, 0xde,
  66. 0xe0, 0xe2, 0xe4, 0xe6, 0xe8, 0xea, 0xec, 0xee, 0xf0, 0xf2, 0xf4, 0xf6, 0xf8, 0xfa, 0xfd, 0xff };
  67. unsigned char env_frise[128] = {
  68. 0xff, 0xf4, 0xea, 0xe0, 0xd6, 0xcc, 0xc3, 0xba, 0xb1, 0xa8, 0x9f, 0x97, 0x8f, 0x87, 0x7f, 0x78,
  69. 0x71, 0x6a, 0x63, 0x5c, 0x56, 0x50, 0x4a, 0x44, 0x3f, 0x39, 0x34, 0x2f, 0x2b, 0x26, 0x22, 0x1e,
  70. 0x1a, 0x17, 0x13, 0x10, 0x0d, 0x0b, 0x08, 0x06, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  71. 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x07, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x13, 0x15, 0x17,
  72. 0x1a, 0x1d, 0x1f, 0x22, 0x25, 0x28, 0x2c, 0x2e, 0x30, 0x32, 0x34, 0x36, 0x39, 0x3b, 0x3d, 0x40,
  73. 0x42, 0x45, 0x47, 0x4a, 0x4c, 0x4f, 0x51, 0x54, 0x57, 0x5a, 0x5d, 0x5f, 0x62, 0x65, 0x68, 0x6b,
  74. 0x6e, 0x71, 0x74, 0x78, 0x7b, 0x7e, 0x81, 0x85, 0x88, 0x8b, 0x8f, 0x92, 0x96, 0x99, 0x9d, 0xa0,
  75. 0xa4, 0xa8, 0xac, 0xaf, 0xb3, 0xb7, 0xbb, 0xbf, 0xc3, 0xc7, 0xcb, 0xcf, 0xd3, 0xd7, 0xdb, 0xe0 };
  76. static unsigned char env_r_frise[128] = {
  77. 0xcf, 0xcc, 0xc9, 0xc6, 0xc3, 0xc0, 0xbd, 0xb9, 0xb4, 0xb0, 0xab, 0xa7, 0xa2, 0x9c, 0x97, 0x92,
  78. 0x8c, 0x86, 0x81, 0x7b, 0x75, 0x6f, 0x69, 0x63, 0x5d, 0x57, 0x50, 0x4a, 0x44, 0x3e, 0x38, 0x33,
  79. 0x2d, 0x27, 0x22, 0x1c, 0x17, 0x12, 0x0d, 0x08, 0x04, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00,
  80. 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x07, 0x08, 0x0a, 0x0c, 0x0d, 0x0f, 0x12, 0x14, 0x16,
  81. 0x19, 0x1b, 0x1e, 0x21, 0x24, 0x27, 0x2a, 0x2d, 0x30, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3f, 0x41,
  82. 0x43, 0x46, 0x48, 0x4b, 0x4d, 0x50, 0x52, 0x55, 0x58, 0x5a, 0x5d, 0x60, 0x63, 0x66, 0x69, 0x6c,
  83. 0x6f, 0x72, 0x75, 0x78, 0x7b, 0x7e, 0x81, 0x85, 0x88, 0x8b, 0x8f, 0x92, 0x96, 0x99, 0x9d, 0xa0,
  84. 0xa4, 0xa8, 0xac, 0xaf, 0xb3, 0xb7, 0xbb, 0xbf, 0xc3, 0xc7, 0xcb, 0xcf, 0xd3, 0xd7, 0xdb, 0xe0 };
  85. static unsigned char env_frise2[128] = {
  86. 0xff, 0xf9, 0xf4, 0xee, 0xe9, 0xe4, 0xdf, 0xda, 0xd5, 0xd0, 0xcb, 0xc6, 0xc1, 0xbd, 0xb8, 0xb3,
  87. 0xaf, 0xaa, 0xa6, 0xa1, 0x9d, 0x99, 0x95, 0x90, 0x8c, 0x88, 0x84, 0x80, 0x7d, 0x79, 0x75, 0x71,
  88. 0x6e, 0x6a, 0x67, 0x63, 0x60, 0x5d, 0x59, 0x56, 0x53, 0x50, 0x4d, 0x4a, 0x47, 0x44, 0x41, 0x3e,
  89. 0x3c, 0x39, 0x37, 0x34, 0x32, 0x2f, 0x2d, 0x2b, 0x28, 0x26, 0x24, 0x22, 0x20, 0x1e, 0x1c, 0x1a,
  90. 0x19, 0x17, 0x15, 0x14, 0x12, 0x11, 0x0f, 0x0e, 0x0d, 0x0c, 0x0a, 0x09, 0x08, 0x07, 0x06, 0x05,
  91. 0x05, 0x04, 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  92. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x04, 0x04, 0x05, 0x06, 0x07, 0x08,
  93. 0x09, 0x0a, 0x0b, 0x0c, 0x0e, 0x0f, 0x10, 0x12, 0x13, 0x15, 0x17, 0x18, 0x1a, 0x1c, 0x1e, 0x20 };
  94. static unsigned char env_r_frise2[128] = {
  95. 0xd0, 0xce, 0xcd, 0xcc, 0xca, 0xc8, 0xc7, 0xc5, 0xc3, 0xc1, 0xc0, 0xbd, 0xbb, 0xb8, 0xb5, 0xb3,
  96. 0xb0, 0xad, 0xaa, 0xa7, 0xa3, 0xa0, 0x9d, 0x99, 0x96, 0x92, 0x8f, 0x8b, 0x87, 0x84, 0x80, 0x7c,
  97. 0x78, 0x74, 0x70, 0x6d, 0x69, 0x65, 0x61, 0x5d, 0x59, 0x55, 0x51, 0x4d, 0x4a, 0x46, 0x42, 0x3e,
  98. 0x3b, 0x37, 0x34, 0x31, 0x2f, 0x2d, 0x2a, 0x28, 0x26, 0x24, 0x22, 0x20, 0x1e, 0x1c, 0x1a, 0x19,
  99. 0x17, 0x15, 0x14, 0x12, 0x11, 0x0f, 0x0e, 0x0d, 0x0c, 0x0a, 0x09, 0x08, 0x07, 0x06, 0x05, 0x05,
  100. 0x04, 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  101. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x04, 0x04, 0x05, 0x06, 0x07, 0x08,
  102. 0x09, 0x0a, 0x0b, 0x0c, 0x0e, 0x0f, 0x10, 0x12, 0x13, 0x15, 0x17, 0x18, 0x1a, 0x1c, 0x1e, 0x20 };
  103. /*
  104. unsigned char env_drop[128] = {
  105. 0xff, 0xf9, 0xf4, 0xee, 0xe9, 0xe4, 0xdf, 0xda, 0xd5, 0xd0, 0xcb, 0xc6, 0xc1, 0xbc, 0xb8, 0xb3,
  106. 0xaf, 0xaa, 0xa6, 0xa2, 0x9d, 0x99, 0x95, 0x91, 0x8d, 0x89, 0x85, 0x81, 0x7d, 0x79, 0x76, 0x72,
  107. 0x6f, 0x6b, 0x68, 0x64, 0x61, 0x5e, 0x5b, 0x58, 0x55, 0x52, 0x4f, 0x4c, 0x49, 0x46, 0x44, 0x41,
  108. 0x3e, 0x3c, 0x39, 0x37, 0x35, 0x33, 0x30, 0x2e, 0x2c, 0x2a, 0x28, 0x27, 0x25, 0x23, 0x21, 0x20,
  109. 0x1e, 0x1d, 0x1b, 0x1a, 0x19, 0x18, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x10, 0x0f, 0x0e,
  110. 0x0e, 0x0d, 0x0c, 0x0c, 0x0c, 0x0b, 0x0b, 0x0b, 0x0b, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  111. 0x0b, 0x0b, 0x0b, 0x0c, 0x0c, 0x0c, 0x0d, 0x0e, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x12, 0x13, 0x14,
  112. 0x15, 0x16, 0x17, 0x19, 0x1a, 0x1b, 0x1d, 0x1e, 0x20, 0x21, 0x23, 0x24, 0x26, 0x28, 0x2a, 0x2c };
  113. unsigned char env_r_drop[128] = {
  114. 0xcf, 0xce, 0xcd, 0xcc, 0xcb, 0xca, 0xc8, 0xc6, 0xc5, 0xc3, 0xc1, 0xbe, 0xbc, 0xb9, 0xb7, 0xb4,
  115. 0xb1, 0xae, 0xab, 0xa8, 0xa5, 0xa2, 0x9e, 0x9b, 0x97, 0x94, 0x90, 0x8c, 0x89, 0x85, 0x81, 0x7d,
  116. 0x79, 0x75, 0x71, 0x6d, 0x69, 0x65, 0x61, 0x5d, 0x59, 0x55, 0x51, 0x4e, 0x4a, 0x46, 0x42, 0x3e,
  117. 0x3b, 0x38, 0x36, 0x34, 0x32, 0x30, 0x2e, 0x2c, 0x2b, 0x29, 0x27, 0x25, 0x24, 0x22, 0x21, 0x1f,
  118. 0x1e, 0x1c, 0x1b, 0x1a, 0x19, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x11, 0x10, 0x0f, 0x0e,
  119. 0x0e, 0x0d, 0x0d, 0x0c, 0x0c, 0x0c, 0x0b, 0x0b, 0x0b, 0x0b, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  120. 0x0b, 0x0b, 0x0b, 0x0b, 0x0c, 0x0c, 0x0c, 0x0d, 0x0d, 0x0e, 0x0f, 0x0f, 0x10, 0x11, 0x12, 0x13,
  121. 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1c, 0x1d, 0x1e, 0x20, 0x21, 0x23, 0x24, 0x26, 0x28 };
  122. unsigned char env_drop2[128] = {
  123. 0xff, 0xfc, 0xf9, 0xf6, 0xf3, 0xf0, 0xed, 0xea, 0xe7, 0xe5, 0xe2, 0xdf, 0xdc, 0xda, 0xd7, 0xd5,
  124. 0xd2, 0xcf, 0xcd, 0xca, 0xc8, 0xc5, 0xc3, 0xc0, 0xbe, 0xbc, 0xb9, 0xb7, 0xb4, 0xb2, 0xb0, 0xae,
  125. 0xab, 0xa9, 0xa7, 0xa5, 0xa3, 0xa1, 0x9f, 0x9d, 0x9b, 0x99, 0x97, 0x95, 0x93, 0x91, 0x8f, 0x8d,
  126. 0x8b, 0x89, 0x88, 0x86, 0x84, 0x83, 0x81, 0x7f, 0x7e, 0x7c, 0x7a, 0x79, 0x77, 0x76, 0x74, 0x73,
  127. 0x71, 0x70, 0x6f, 0x6d, 0x6c, 0x6a, 0x69, 0x68, 0x67, 0x65, 0x64, 0x63, 0x62, 0x61, 0x60, 0x5f,
  128. 0x5e, 0x5d, 0x5c, 0x5b, 0x5a, 0x59, 0x58, 0x57, 0x56, 0x55, 0x54, 0x54, 0x53, 0x52, 0x51, 0x51,
  129. 0x50, 0x4f, 0x4f, 0x4e, 0x4e, 0x4d, 0x4d, 0x4c, 0x4c, 0x4b, 0x4b, 0x4a, 0x4a, 0x4a, 0x49, 0x49,
  130. 0x49, 0x48, 0x48, 0x48, 0x48, 0x48, 0x48, 0x47, 0x47, 0x47, 0x47, 0x47, 0x47, 0x47, 0x47, 0x48 };
  131. unsigned char env_r_drop2[128] = {
  132. 0xcf, 0xce, 0xcd, 0xcd, 0xcc, 0xcb, 0xcb, 0xca, 0xc9, 0xc8, 0xc7, 0xc6, 0xc5, 0xc4, 0xc3, 0xc2,
  133. 0xc1, 0xc0, 0xbf, 0xbd, 0xbc, 0xbb, 0xba, 0xb8, 0xb7, 0xb6, 0xb4, 0xb3, 0xb2, 0xb0, 0xaf, 0xad,
  134. 0xac, 0xaa, 0xa9, 0xa7, 0xa6, 0xa4, 0xa3, 0xa1, 0x9f, 0x9e, 0x9c, 0x9a, 0x99, 0x97, 0x96, 0x94,
  135. 0x92, 0x91, 0x8f, 0x8d, 0x8c, 0x8a, 0x88, 0x87, 0x85, 0x83, 0x82, 0x80, 0x7e, 0x7d, 0x7b, 0x7a,
  136. 0x78, 0x76, 0x75, 0x73, 0x72, 0x70, 0x6f, 0x6d, 0x6c, 0x6b, 0x6a, 0x69, 0x68, 0x68, 0x67, 0x66,
  137. 0x65, 0x64, 0x63, 0x62, 0x61, 0x60, 0x5f, 0x5f, 0x5e, 0x5d, 0x5c, 0x5b, 0x5b, 0x5a, 0x59, 0x58,
  138. 0x58, 0x57, 0x56, 0x56, 0x55, 0x54, 0x54, 0x53, 0x52, 0x52, 0x51, 0x51, 0x50, 0x4f, 0x4f, 0x4e,
  139. 0x4e, 0x4d, 0x4d, 0x4c, 0x4c, 0x4b, 0x4b, 0x4b, 0x4a, 0x4a, 0x49, 0x49, 0x49, 0x48, 0x48, 0x48 };
  140. // 10 semi_r
  141. unsigned char env_semi_r[128] = {
  142. 0x00, 0x01, 0x02, 0x04, 0x05, 0x07, 0x08, 0x09, 0x0b, 0x0c, 0x0e, 0x0f, 0x11, 0x12, 0x14, 0x15,
  143. 0x17, 0x18, 0x1a, 0x1b, 0x1d, 0x1f, 0x20, 0x22, 0x23, 0x25, 0x27, 0x28, 0x2a, 0x2c, 0x2d, 0x2f,
  144. 0x31, 0x33, 0x35, 0x37, 0x39, 0x3b, 0x3d, 0x3f, 0x42, 0x44, 0x46, 0x48, 0x4a, 0x4c, 0x4e, 0x50,
  145. 0x52, 0x54, 0x57, 0x59, 0x5b, 0x5d, 0x5f, 0x61, 0x63, 0x65, 0x67, 0x69, 0x6c, 0x6e, 0x70, 0x72,
  146. 0x74, 0x76, 0x78, 0x7a, 0x7c, 0x7e, 0x80, 0x82, 0x84, 0x86, 0x87, 0x89, 0x8b, 0x8d, 0x8f, 0x90,
  147. 0x92, 0x94, 0x96, 0x97, 0x99, 0x9b, 0x9c, 0x9e, 0x9f, 0xa1, 0xa2, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8,
  148. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xad, 0xae, 0xaf, 0xb0, 0xb0, 0xb1, 0xb2, 0xb2, 0xb3, 0xb3,
  149. 0xb4, 0xb4, 0xb4, 0xb5, 0xb5, 0xb6, 0xb6, 0xb6, 0xb6, 0xb7, 0xb7, 0xb7, 0xb7, 0xb7, 0xb7, 0xb8 };
  150. // 11 drop3
  151. unsigned char env_drop3[128] = {
  152. 0xff, 0xf8, 0xf2, 0xec, 0xe7, 0xe1, 0xdb, 0xd5, 0xd0, 0xca, 0xc5, 0xc0, 0xbb, 0xb5, 0xb1, 0xac,
  153. 0xa7, 0xa3, 0x9e, 0x9b, 0x97, 0x93, 0x90, 0x8c, 0x89, 0x86, 0x83, 0x80, 0x7d, 0x7b, 0x78, 0x76,
  154. 0x73, 0x71, 0x6f, 0x6d, 0x6b, 0x68, 0x66, 0x64, 0x62, 0x5f, 0x5d, 0x5b, 0x59, 0x57, 0x56, 0x54,
  155. 0x52, 0x50, 0x4e, 0x4d, 0x4b, 0x49, 0x48, 0x46, 0x44, 0x43, 0x41, 0x40, 0x3e, 0x3d, 0x3b, 0x3a,
  156. 0x39, 0x37, 0x35, 0x34, 0x32, 0x31, 0x2f, 0x2d, 0x2c, 0x2a, 0x29, 0x28, 0x26, 0x25, 0x23, 0x22,
  157. 0x21, 0x1f, 0x1e, 0x1d, 0x1b, 0x1a, 0x19, 0x18, 0x17, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f,
  158. 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x0a, 0x09, 0x08, 0x08, 0x07, 0x06, 0x06, 0x05, 0x05, 0x04,
  159. 0x04, 0x03, 0x03, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  160. // 12 r_drop3
  161. unsigned char env_r_drop3[128] = {
  162. 0xcf, 0xce, 0xcd, 0xcc, 0xcb, 0xca, 0xc8, 0xc7, 0xc5, 0xc4, 0xc2, 0xc0, 0xbe, 0xbc, 0xba, 0xb8,
  163. 0xb5, 0xb3, 0xb1, 0xae, 0xac, 0xa9, 0xa6, 0xa4, 0xa1, 0x9e, 0x9b, 0x98, 0x95, 0x92, 0x8f, 0x8c,
  164. 0x89, 0x86, 0x83, 0x80, 0x7d, 0x7a, 0x76, 0x73, 0x70, 0x6d, 0x6a, 0x67, 0x63, 0x60, 0x5d, 0x5a,
  165. 0x57, 0x54, 0x51, 0x4e, 0x4b, 0x48, 0x45, 0x43, 0x40, 0x3d, 0x3b, 0x39, 0x37, 0x36, 0x34, 0x33,
  166. 0x32, 0x30, 0x2f, 0x2d, 0x2c, 0x2b, 0x2a, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20,
  167. 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, 0x17, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11,
  168. 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0d, 0x0c, 0x0b, 0x0b, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x07, 0x06,
  169. 0x06, 0x05, 0x05, 0x04, 0x04, 0x03, 0x03, 0x02, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 };
  170. */
  171. // long vowel fall
  172. static unsigned char env_long_fall[128] = {
  173. 254,249,250,251,252,253,254,254, 255,255,255,255,254,254,253,252,
  174. 251,250,249,247,244,242,238,234, 230,225,221,217,213,209,206,203,
  175. 199,195,191,187,183,179,175,172, 168,165,162,159,156,153,150,148,
  176. 145,143,140,138,136,134,132,130, 128,126,123,120,117,114,111,107,
  177. 104,100,96,91, 86,82,77,73, 70,66,63,60, 58,55,53,51,
  178. 49,47,46,45, 43,42,40,38, 36,34,31,28, 26,24,22,20,
  179. 18,16,14,12, 11,10,9,8, 8,8,8,8, 9,8,8,8,
  180. 8,8,7,7, 6,6,6,5, 4,4,3,3, 2,1,1,0 };
  181. unsigned char *envelope_data[16] = {
  182. env_fall, env_rise, env_frise, env_r_frise,
  183. env_frise2, env_r_frise2,
  184. env_long_fall, env_long_fall, env_fall, env_fall,
  185. env_fall, env_fall, env_fall, env_fall,
  186. env_fall, env_fall
  187. };
  188. /* all pitches given in Hz above pitch_base */
  189. // pitch change during the main part of the clause
  190. static int drops_0[8] = {0x400,0x400,0x700,0x700,0x700,0xa00,0x0e00,0x0e00};
  191. static int drops_1[8] = {0x400,0x400,0x600,0x600,0xc00,0xc00,0x0e00,0x0e00};
  192. static int drops_2[8] = {0x400,0x400,0x600,0x600,-0x800,0xc00,0x0e00,0x0e00};
  193. typedef struct {
  194. unsigned char pitch_env0; /* pitch envelope, tonic syllable at end */
  195. unsigned char tonic_max0;
  196. unsigned char tonic_min0;
  197. unsigned char pitch_env1; /* followed by unstressed */
  198. unsigned char tonic_max1;
  199. unsigned char tonic_min1;
  200. unsigned char pre_start;
  201. unsigned char pre_end;
  202. unsigned char body_start;
  203. unsigned char body_end;
  204. int *body_drops;
  205. unsigned char body_max_steps;
  206. unsigned char body_lower_u;
  207. unsigned char tail_start;
  208. unsigned char tail_end;
  209. unsigned char tail_shape;
  210. } TONE_TABLE;
  211. #define N_TONE_TABLE 15
  212. static TONE_TABLE tone_table[N_TONE_TABLE] = {
  213. {PITCHfall, 30, 5, PITCHfall, 30, 7, // statement
  214. 20, 25, 34, 22, drops_0, 3, 3, 12, 8, 0},
  215. {PITCHfrise, 38,10, PITCHfrise2, 36,10, // comma, or question
  216. 20, 25, 34, 20, drops_0, 3, 3, 15, 25, 0},
  217. {PITCHdrop, 38, 1, PITCHdrop, 42,25, // exclamation
  218. 20, 25, 34, 22, drops_0, 3, 3, 12, 8, 0},
  219. {PITCHfall, 30, 5, PITCHfall, 30, 7, // statement
  220. 20, 25, 34, 22, drops_1, 3, 3, 12, 8, 0},
  221. {PITCHfrise, 38,10, PITCHfrise2, 36,10, // comma, or question
  222. 20, 25, 34, 20, drops_1, 3, 3, 15, 25, 0},
  223. {PITCHfall, 30, 5, PITCHfall, 30, 7, // exclamation
  224. 20, 25, 34, 22, drops_1, 3, 3, 12, 8, 0},
  225. {PITCHfall, 30, 5, PITCHfall, 30, 7, // statement
  226. 20, 25, 34, 22, drops_2, 3, 3, 12, 8, 0},
  227. {PITCHfrise, 38,10, PITCHfrise2, 36,10, // comma, or question
  228. 20, 25, 34, 20, drops_2, 3, 3, 15, 25, 0},
  229. {PITCHfall, 30, 5, PITCHfall, 30, 7, // exclamation
  230. 20, 25, 34, 22, drops_2, 3, 3, 12, 8, 0},
  231. // alternatives
  232. {PITCHfall, 36, 6, PITCHfall, 36, 8,
  233. 30, 20, 18, 34, drops_0, 3, 3, 12, 8, 0},
  234. {PITCHfrise, 38, 8, PITCHfrise2, 36, 8,
  235. 30, 20, 18, 34, drops_0, 3, 3, 20, 32, 0},
  236. {PITCHfall, 36, 6, PITCHfall, 36, 8,
  237. 30, 20, 18, 34, drops_0, 3, 3, 12, 8, 0},
  238. };
  239. /* indexed by stress */
  240. static int min_drop[] = {0x300,0x300,0x300,0x300,0x300,0x500,0xc00,0xc00};
  241. #define SECONDARY 3
  242. #define PRIMARY 4
  243. #define PRIMARY_MARKED 6
  244. #define BODY_RESET 7
  245. #define FIRST_TONE 8 /* first of the tone types */
  246. static int number_pre;
  247. static int number_body;
  248. static int number_tail;
  249. static int last_primary;
  250. static int tone_type;
  251. static int tone_posn;
  252. static int annotation;
  253. static int no_tonic;
  254. static void count_pitch_vowels()
  255. /******************************/
  256. {
  257. int ix;
  258. int stress;
  259. int stage=0; /* 0=pre, 1=body, 2=tail */
  260. int max_stress = 0;
  261. int max_stress_posn = 0;
  262. int tone_type_marker = 0;
  263. int marked_stress_count = 0;
  264. number_pre=0; /* number of vowels before 1st primary stress */
  265. number_body=0;
  266. number_tail=0; /* number between tonic syllable and next primary */
  267. for(ix=vowel_ix; ix<vowel_ix_top; ix++)
  268. {
  269. stress = vowel_tab[ix] & 0x3f; /* marked stress level */
  270. if(stress >= max_stress)
  271. {
  272. max_stress = stress;
  273. max_stress_posn = ix;
  274. }
  275. if(stress >= PRIMARY)
  276. {
  277. if(stress > PRIMARY)
  278. {
  279. marked_stress_count++;
  280. }
  281. last_primary = ix;
  282. }
  283. switch(stage)
  284. {
  285. case 0:
  286. if(stress < PRIMARY)
  287. number_pre++;
  288. else
  289. {
  290. stage = 1;
  291. ix = ix-1;
  292. }
  293. break;
  294. case 1:
  295. if(stress >= FIRST_TONE)
  296. {
  297. tone_type_marker = stress;
  298. tone_posn = ix;
  299. stage = 2;
  300. }
  301. break;
  302. case 2:
  303. if(stress < PRIMARY)
  304. number_tail++;
  305. else
  306. stage = 3;
  307. break;
  308. }
  309. }
  310. if(no_tonic)
  311. {
  312. tone_posn = vowel_ix_top;
  313. }
  314. else
  315. if((tone_type_marker >= FIRST_TONE) && (tone_type_marker < (N_TONE_TABLE + FIRST_TONE)))
  316. {
  317. tone_type = tone_type_marker - FIRST_TONE;
  318. }
  319. else
  320. {
  321. /* no tonic syllable found, use highest stress */
  322. vowel_tab[max_stress_posn] = FIRST_TONE;
  323. number_tail = vowel_ix_top - max_stress_posn - 1;
  324. tone_posn = max_stress_posn;
  325. }
  326. if(marked_stress_count > 1)
  327. annotation = 1;
  328. else
  329. annotation = 0;
  330. } /* end of count_pitch_vowels */
  331. static int count_increments(int ix, int end_ix, int min_stress)
  332. /*************************************************************/
  333. /* Count number of primary stresses up to tonic syllable or body_reset */
  334. {
  335. int count = 0;
  336. int stress;
  337. while(ix < end_ix)
  338. {
  339. stress = vowel_tab[ix++] & 0x3f;
  340. if(stress >= BODY_RESET)
  341. break;
  342. else
  343. if(stress >= min_stress)
  344. count++;
  345. }
  346. return(count);
  347. } /* end of count_increments */
  348. static void set_pitch(int ix, int base, int drop)
  349. /***********************************************/
  350. // Set the pitch of a vowel in vowel_tab. Base & drop are Hz * 256
  351. {
  352. int pitch1, pitch2;
  353. int flags = 0;
  354. /* adjust experimentally */
  355. int pitch_range2 = 148;
  356. int pitch_base2 = 72;
  357. // fprintf(f_log,"base=%3d,drop=%3d ",base>>8,drop>>8);
  358. // pitch_range2 = pitch_range + 20;
  359. // pitch_base2 = pitch_base - (128-72);
  360. if(base < 0) base = 0;
  361. pitch2 = ((base * pitch_range2 ) >> 15) + pitch_base2;
  362. if(drop < 0)
  363. {
  364. flags = 0x80;
  365. drop = -drop;
  366. }
  367. pitch1 = pitch2 + ((drop * pitch_range2) >> 15);
  368. //x = (pitch1 - pitch2) / 4; // TEST
  369. //pitch1 -= x;
  370. //pitch2 += x;
  371. if(pitch1 > 511) pitch1 = 511;
  372. if(pitch2 > 511) pitch2 = 511;
  373. // fprintf(f_log," %d p1=%3d p2=%3d %x\n",vowel_tab[ix] & 0x3f,pitch1,pitch2,flags);
  374. vowel_tab[ix] = (vowel_tab[ix] & 0x3f) + flags
  375. + (pitch1 << 8) + (pitch2 << 17);
  376. } /* end of set_pitch */
  377. static int calc_pitch_segment(int ix, int end_ix, TONE_TABLE *t, int min_stress)
  378. /******************************************************************************/
  379. /* Calculate pitches until next RESET or tonic syllable, or end.
  380. Increment pitch if stress is >= min_stress.
  381. Used for tonic segment */
  382. {
  383. int stress;
  384. int pitch=0;
  385. int increment=0;
  386. int n_primary=0;
  387. int initial;
  388. int overflow=0;
  389. int *drops;
  390. static char overflow_tab[5] = {0, 5, 3, 1, 0};
  391. drops = t->body_drops;
  392. initial = 1;
  393. while(ix < end_ix)
  394. {
  395. stress = vowel_tab[ix] & 0x3f;
  396. if(stress == BODY_RESET)
  397. initial = 1;
  398. if(initial || (stress >= min_stress))
  399. {
  400. if(initial)
  401. {
  402. initial = 0;
  403. overflow = 0;
  404. n_primary = count_increments(ix,end_ix,min_stress);
  405. if(n_primary > t->body_max_steps)
  406. n_primary = t->body_max_steps;
  407. if(n_primary > 1)
  408. {
  409. increment = (t->body_end - t->body_start) << 8;
  410. increment = increment / (n_primary -1);
  411. }
  412. else
  413. increment = 0;
  414. pitch = t->body_start << 8;
  415. }
  416. else
  417. {
  418. if(n_primary > 0)
  419. pitch += increment;
  420. else
  421. {
  422. pitch = (t->body_end << 8) - (increment * overflow_tab[overflow++])/4;
  423. if(overflow > 4) overflow = 0;
  424. }
  425. }
  426. n_primary--;
  427. }
  428. if(((annotation==0) && (stress >= PRIMARY)) || (stress >= PRIMARY_MARKED))
  429. {
  430. vowel_tab[ix] = PRIMARY_MARKED;
  431. set_pitch(ix,pitch,drops[stress]);
  432. }
  433. else
  434. if(stress >= SECONDARY)
  435. {
  436. /* use secondary stress for unmarked word stress, if no annotation */
  437. set_pitch(ix,pitch,drops[stress]);
  438. }
  439. else
  440. {
  441. /* unstressed, drop pitch if preceded by PRIMARY */
  442. if((vowel_tab[ix-1] & 0x3f) >= SECONDARY)
  443. set_pitch(ix,pitch - (t->body_lower_u << 8), drops[stress]);
  444. else
  445. set_pitch(ix,pitch,drops[stress]);
  446. }
  447. ix++;
  448. }
  449. return(ix);
  450. } /* end of calc_pitch_segment */
  451. static int calc_pitch_segment2(int ix, int end_ix, int start_p, int end_p, int min_stress)
  452. /****************************************************************************************/
  453. /* Linear pitch rise/fall, change pitch at min_stress or stronger
  454. Used for pre-head and tail */
  455. {
  456. int stress;
  457. int pitch;
  458. int increment;
  459. int n_increments;
  460. int drop;
  461. if(ix >= end_ix)
  462. return(ix);
  463. n_increments = count_increments(ix,end_ix,min_stress);
  464. increment = (end_p - start_p) << 8;
  465. if(n_increments > 1)
  466. {
  467. increment = increment / n_increments;
  468. }
  469. pitch = start_p << 8;
  470. while(ix < end_ix)
  471. {
  472. stress = vowel_tab[ix] & 0x3f;
  473. if(increment > 0)
  474. {
  475. set_pitch(ix,pitch,-increment);
  476. pitch += increment;
  477. }
  478. else
  479. {
  480. drop = -increment;
  481. if(drop < min_drop[stress])
  482. drop = min_drop[stress];
  483. pitch += increment;
  484. set_pitch(ix,pitch,drop);
  485. }
  486. ix++;
  487. }
  488. return(ix);
  489. } /* end of calc_pitch_segment2 */
  490. static int calc_pitches(int *syllable_tab, int num, int sentence_tone)
  491. /********************************************************************/
  492. /* Calculate pitch values for the vowels in this tone group */
  493. {
  494. int ix;
  495. TONE_TABLE *t;
  496. int drop;
  497. t = &tone_table[tone_type];
  498. ix = vowel_ix;
  499. /* vowels before the first primary stress */
  500. /******************************************/
  501. if(number_pre > 0)
  502. {
  503. ix = calc_pitch_segment2(ix,ix+number_pre,t->pre_start,t->pre_end, 0);
  504. }
  505. /* body of tonic segment */
  506. /*************************/
  507. if(annotation)
  508. ix = calc_pitch_segment(ix,tone_posn, t, PRIMARY_MARKED);
  509. else
  510. ix = calc_pitch_segment(ix,tone_posn, t, PRIMARY);
  511. if(no_tonic)
  512. return(0);
  513. /* tonic syllable */
  514. /******************/
  515. if(number_tail == 0)
  516. {
  517. tone_pitch_env = t->pitch_env0;
  518. drop = t->tonic_max0 - t->tonic_min0;
  519. set_pitch(ix++,t->tonic_min0 << 8,drop << 8);
  520. }
  521. else
  522. {
  523. tone_pitch_env = t->pitch_env1;
  524. drop = t->tonic_max1 - t->tonic_min1;
  525. set_pitch(ix++,t->tonic_min1 << 8,drop << 8);
  526. }
  527. /* tail, after the tonic syllable */
  528. /**********************************/
  529. calc_pitch_segment2(ix,vowel_ix_top,t->tail_start,t->tail_end,0);
  530. return(tone_pitch_env);
  531. } /* end of calc_pitches */
  532. static int calc_pitch_segmentX(int ix, int end_ix, TONE_TABLE *t, int min_stress)
  533. /******************************************************************************/
  534. /* Calculate pitches until next RESET or tonic syllable, or end.
  535. Increment pitch if stress is >= min_stress.
  536. Used for tonic segment */
  537. // EXPERIMENTAL VERSION
  538. {
  539. int stress;
  540. int pitch=0;
  541. int n_primary;
  542. int initial;
  543. int *drops;
  544. int prev_stress=0;
  545. int n_unstressed;
  546. int j;
  547. drops = t->body_drops; // pitch fall or raise for each stress value
  548. n_primary = count_increments(ix,end_ix,min_stress)-1; // number if primary stress in the clause -1
  549. initial = 1;
  550. while(ix < end_ix) // for each syllable
  551. {
  552. for(j=ix; j<end_ix; j++)
  553. {
  554. // how many unstressed syllables before the next primary stress ?
  555. if((vowel_tab[j] & 0x3f) > SECONDARY)
  556. break;
  557. }
  558. n_unstressed = (j - ix - 1);
  559. stress = vowel_tab[ix] & 0x3f; // stress value of this syllable
  560. pitch = 0x1000; // set a base pitch
  561. pitch += ((n_primary % 3) * 0x0500); // some variety. add an offset that changes after each primary stress
  562. if(stress >= PRIMARY)
  563. {
  564. vowel_tab[ix] = PRIMARY_MARKED;
  565. set_pitch(ix,pitch+0x100, -0x0900);
  566. n_primary--;
  567. }
  568. // else
  569. // if(stress >= SECONDARY)
  570. // {
  571. // set_pitch(ix,pitch,drops[stress]);
  572. // }
  573. else
  574. {
  575. if(ix > 0)
  576. prev_stress = vowel_tab[ix-1] & 0x3f; // stress level of previous syllable
  577. if(prev_stress >= PRIMARY)
  578. {
  579. // an unstressed syllable which follows a primary stress syllable
  580. set_pitch(ix,pitch+0x0200, 0x0800);
  581. }
  582. else
  583. {
  584. stress = 0; // treat secondary stress the same as unstressed ??
  585. set_pitch(ix,pitch + n_unstressed*0x300, drops[stress]);
  586. }
  587. n_unstressed--;
  588. }
  589. ix++;
  590. }
  591. return(ix);
  592. } /* end of calc_pitch_segmentX */
  593. static int calc_pitchesX(int *syllable_tab, int num, int sentence_tone)
  594. /********************************************************************/
  595. /* Calculate pitch values for the vowels in this tone group */
  596. // EXPERMENTAL VERSION of calc_pitches()
  597. {
  598. int ix;
  599. TONE_TABLE *t;
  600. int drop;
  601. t = &tone_table[tone_type];
  602. ix = vowel_ix;
  603. /* body of tonic segment */
  604. /*************************/
  605. if(annotation)
  606. ix = calc_pitch_segmentX(ix,tone_posn, t, PRIMARY_MARKED);
  607. else
  608. ix = calc_pitch_segmentX(ix,tone_posn, t, PRIMARY);
  609. if(no_tonic)
  610. return(0);
  611. /* tonic syllable */
  612. /******************/
  613. if(number_tail == 0)
  614. {
  615. tone_pitch_env = t->pitch_env0;
  616. drop = t->tonic_max0 - t->tonic_min0;
  617. set_pitch(ix++,t->tonic_min0 << 8,drop << 8);
  618. }
  619. else
  620. {
  621. tone_pitch_env = t->pitch_env1;
  622. drop = t->tonic_max1 - t->tonic_min1;
  623. set_pitch(ix++,t->tonic_min1 << 8,drop << 8);
  624. }
  625. /* tail, after the tonic syllable */
  626. /**********************************/
  627. calc_pitch_segment2(ix,vowel_ix_top,t->tail_start,t->tail_end,0);
  628. return(tone_pitch_env);
  629. } /* end of calc_pitchesX */
  630. void Translator::CalcPitches_Tone(int clause_tone)
  631. {//===============================================
  632. // clause_tone: 0=. 1=, 2=?, 3=! 4=none
  633. PHONEME_LIST *p;
  634. int ix;
  635. int count_stressed=0;
  636. int final_stressed=0;
  637. int tone_ph;
  638. int pause;
  639. int tone_promoted;
  640. PHONEME_TAB *tph;
  641. PHONEME_TAB *prev_tph; // forget across word boundary
  642. PHONEME_TAB *prevw_tph; // remember across word boundary
  643. PHONEME_TAB *prev2_tph; // 2 tones previous
  644. PHONEME_LIST *prev_p;
  645. int pitch_adjust = 10; // pitch gradient through the clause - inital value
  646. int pitch_decrement = 0; // decrease by this for each stressed syllable
  647. int pitch_low = 10; // until it drops to this
  648. int pitch_high = 10; // then reset to this
  649. p = &phoneme_list[0];
  650. // count number of stressed syllables
  651. p = &phoneme_list[0];
  652. for(ix=0; ix<n_phoneme_list; ix++, p++)
  653. {
  654. if((p->type == phVOWEL) && (p->tone >= 4))
  655. {
  656. final_stressed = ix;
  657. count_stressed++;
  658. }
  659. }
  660. // language specific, changes to tones
  661. if(translator_name == L('v','i'))
  662. {
  663. // LANG=vi
  664. p = &phoneme_list[final_stressed];
  665. p->tone = 7;
  666. if(p->tone_ph == 0)
  667. p->tone_ph = LookupPh("7"); // change tone 1 to falling tone at end of clause
  668. }
  669. pause = 1;
  670. tone_promoted = 0;
  671. prev_p = p = &phoneme_list[0];
  672. prev_tph = prevw_tph = phoneme_tab[phonPAUSE];
  673. // perform tone sandhi
  674. for(ix=0; ix<n_phoneme_list; ix++, p++)
  675. {
  676. if((p->type == phPAUSE) && (p->ph->std_length > 50))
  677. {
  678. pause = 1; // there is a pause since the previous vowel
  679. }
  680. if(p->newword)
  681. {
  682. prev_tph = phoneme_tab[phonPAUSE]; // forget across word boundaries
  683. }
  684. if(p->type == phVOWEL)
  685. {
  686. tone_ph = p->tone_ph;
  687. tph = phoneme_tab[tone_ph];
  688. // Mandarin
  689. if(translator_name == L('z','h'))
  690. {
  691. if(tone_ph == 0)
  692. {
  693. if(pause || tone_promoted)
  694. {
  695. tone_ph = LookupPh("55"); // no previous vowel, use tone 1
  696. tone_promoted = 1;
  697. }
  698. else
  699. {
  700. tone_ph = LookupPh("11"); // default tone 5
  701. }
  702. p->tone_ph = tone_ph;
  703. tph = phoneme_tab[tone_ph];
  704. }
  705. else
  706. {
  707. tone_promoted = 0;
  708. }
  709. if(prev_tph->mnemonic == 0x343132) // [214]
  710. {
  711. if(tph->mnemonic == 0x343132) // [214]
  712. prev_p->tone_ph = LookupPh("35");
  713. else
  714. prev_p->tone_ph = LookupPh("21");
  715. }
  716. if((prev_tph->mnemonic == 0x3135) && (tph->mnemonic == 0x3135)) // [51] + [51]
  717. {
  718. prev_p->tone_ph = LookupPh("53");
  719. }
  720. if(tph->mnemonic == 0x3131) // [11] Tone 5
  721. {
  722. // tone 5, change its level depending on the previous tone (across word boundaries)
  723. if(prevw_tph->mnemonic == 0x3535)
  724. p->tone_ph = LookupPh("22");
  725. if(prevw_tph->mnemonic == 0x3533)
  726. p->tone_ph = LookupPh("33");
  727. if(prevw_tph->mnemonic == 0x343132)
  728. p->tone_ph = LookupPh("44");
  729. // tone 5 is unstressed (shorter)
  730. p->tone = 1; // diminished stress
  731. }
  732. }
  733. prev_p = p;
  734. prev2_tph = prevw_tph;
  735. prevw_tph = prev_tph = tph;
  736. pause = 0;
  737. }
  738. }
  739. // convert tone numbers to pitch
  740. p = &phoneme_list[0];
  741. for(ix=0; ix<n_phoneme_list; ix++, p++)
  742. {
  743. if(p->type == phVOWEL)
  744. {
  745. tone_ph = p->tone_ph;
  746. if(p->tone != 1) // TEST, consider all syllables as stressed
  747. {
  748. if(ix == final_stressed)
  749. {
  750. // the last stressed syllable
  751. pitch_adjust = pitch_low;
  752. }
  753. else
  754. {
  755. pitch_adjust -= pitch_decrement;
  756. if(pitch_adjust <= pitch_low)
  757. pitch_adjust = pitch_high;
  758. }
  759. }
  760. if(tone_ph ==0)
  761. {
  762. tone_ph = phonDEFAULTTONE; // no tone specified, use default tone 1
  763. p->tone_ph = tone_ph;
  764. }
  765. p->pitch1 = pitch_adjust + phoneme_tab[tone_ph]->start_type;
  766. p->pitch2 = pitch_adjust + phoneme_tab[tone_ph]->end_type;
  767. }
  768. }
  769. } // end of Translator::CalcPitches_Tone
  770. void Translator::CalcPitches(int clause_tone)
  771. {//==========================================
  772. // clause_tone: 0=. 1=, 2=?, 3=! 4=none
  773. PHONEME_LIST *p;
  774. int ix;
  775. int x;
  776. int st_ix;
  777. int tonic_ix=0;
  778. int tonic_env;
  779. int max_stress=0;
  780. int option;
  781. int st_ix_changed = -1;
  782. int syllable_tab[N_PHONEME_LIST];
  783. if(langopts.intonation == 1)
  784. {
  785. CalcPitches_Tone(clause_tone);
  786. return;
  787. }
  788. st_ix=0;
  789. p = &phoneme_list[0];
  790. for(ix=0; ix<n_phoneme_list; ix++, p++)
  791. {
  792. if(p->synthflags & SFLAG_SYLLABLE)
  793. {
  794. syllable_tab[st_ix] = p->tone;
  795. if(option_tone2 == 1)
  796. {
  797. // reduce number of full-stress words
  798. if((p->tone == 4) && ((st_ix % 2) != 1))
  799. {
  800. syllable_tab[st_ix] = 3;
  801. st_ix_changed = st_ix;
  802. }
  803. }
  804. if(option_tone2 == 2)
  805. {
  806. // reduce all full-stress words, except last
  807. if(p->tone == 4)
  808. {
  809. syllable_tab[st_ix] = 3;
  810. st_ix_changed = st_ix;
  811. }
  812. }
  813. st_ix++;
  814. if(p->tone >= max_stress)
  815. {
  816. max_stress = p->tone;
  817. tonic_ix = ix;
  818. }
  819. }
  820. }
  821. if(st_ix_changed >= 0)
  822. syllable_tab[st_ix_changed] = 4;
  823. if(st_ix == 0)
  824. return; // no vowels, nothing to do
  825. option = option_tone1 & 0xf;
  826. if(option > 4)
  827. option = 0;
  828. tone_type = punct_to_tone[option][clause_tone]; /* unless changed by count_pitch_vowels */
  829. if(clause_tone == 4)
  830. no_tonic = 1; /* incomplete clause, used for abbreviations such as Mr. Dr. Mrs. */
  831. else
  832. no_tonic = 0;
  833. /* transfer vowel data from ph_list to syllable_tab */
  834. vowel_tab = syllable_tab;
  835. vowel_ix_top = st_ix;
  836. count_pitch_vowels();
  837. if((option_tone1 & 0xf0)== 0x10)
  838. tonic_env = calc_pitchesX(syllable_tab,st_ix,clause_tone);
  839. else
  840. tonic_env = calc_pitches(syllable_tab,st_ix,clause_tone);
  841. // unpack pitch data
  842. st_ix=0;
  843. p = &phoneme_list[0];
  844. for(ix=0; ix<n_phoneme_list; ix++, p++)
  845. {
  846. p->tone = syllable_tab[st_ix] & 0x3f;
  847. if(p->synthflags & SFLAG_SYLLABLE)
  848. {
  849. x = ((syllable_tab[st_ix] >> 8) & 0x1ff) - 72;
  850. if(x < 0) x = 0;
  851. p->pitch1 = x;
  852. x = ((syllable_tab[st_ix] >> 17) & 0x1ff) - 72;
  853. if(x < 0) x = 0;
  854. p->pitch2 = x;
  855. p->env = PITCHfall;
  856. if(syllable_tab[st_ix] & 0x80)
  857. {
  858. // if(p->pitch1 > p->pitch2)
  859. // p->env = PITCHfall;
  860. // else
  861. p->env = PITCHrise;
  862. }
  863. if(p->pitch1 > p->pitch2)
  864. {
  865. // swap so that pitch2 is the higher
  866. x = p->pitch1;
  867. p->pitch1 = p->pitch2;
  868. p->pitch2 = x;
  869. }
  870. if(ix==tonic_ix) p->env = tonic_env;
  871. st_ix++;
  872. }
  873. }
  874. } // end of Translator::CalcPitches