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

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