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 33KB

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