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

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