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.

compiledata.cpp 87KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2013 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, see: *
  17. * <http://www.gnu.org/licenses/>. *
  18. ***************************************************************************/
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22. #include <stdlib.h>
  23. #include <time.h>
  24. #include "wx/wx.h"
  25. #include "wx/wfstream.h"
  26. #include "wx/dir.h"
  27. #include "wx/filename.h"
  28. #include <wx/numdlg.h>
  29. #include "speak_lib.h"
  30. #include "main.h"
  31. #include "speech.h"
  32. #include "options.h"
  33. #include "phoneme.h"
  34. #include "synthesize.h"
  35. #include "voice.h"
  36. #include "spect.h"
  37. #ifdef PLATFORM_POSIX
  38. #include <unistd.h>
  39. #endif
  40. extern void FindPhonemesUsed(void);
  41. extern void DisplayErrorFile(const char *fname);
  42. extern int utf8_in(int *c, const char *buf);
  43. extern int utf8_out(unsigned int c, char *buf);
  44. extern void DrawEnvelopes();
  45. extern void ReadPhondataManifest();
  46. char path_source[sizeof(path_home)+20];
  47. typedef struct { // total 48 bytes
  48. short frflags;
  49. unsigned char length;
  50. unsigned char rms;
  51. short ffreq[4]; // f0,1,2,3
  52. unsigned char ffreq2[6]; // nasal(*2) f4,5,6,7,8(*20)
  53. unsigned char fheight[9]; // f0-8
  54. unsigned char fwidth[6]; // width/4 f0-5
  55. unsigned char fright[4]; // width/4 f0-3
  56. unsigned char bw[6]; // nasal, f1,2,3,4,5 (*2)
  57. unsigned char klattp[5]; // amp, tilt, kopen, asp,
  58. } frame_t3;
  59. typedef struct {
  60. const char *mnem;
  61. int type;
  62. int data;
  63. } keywtab_t;
  64. #define k_AND 1
  65. #define k_OR 2
  66. #define k_THEN 3
  67. #define k_NOT 4
  68. #define kTHISSTRESS 0x800
  69. // keyword types
  70. enum {
  71. tPHONEME_TYPE = 1,
  72. tPHONEME_FLAG,
  73. tTRANSITION,
  74. tPLACE,
  75. tSTATEMENT,
  76. tINSTRN1,
  77. tWHICH_PHONEME,
  78. tTEST,
  79. };
  80. static keywtab_t k_conditions[] = {
  81. {"AND", 0, k_AND},
  82. {"OR", 0, k_OR},
  83. {"THEN", 0, k_THEN},
  84. {"NOT", 0, k_NOT},
  85. {"prevPh", tWHICH_PHONEME, 0},
  86. {"prevPhW", tWHICH_PHONEME, 5},
  87. {"thisPh", tWHICH_PHONEME, 1},
  88. {"nextPh", tWHICH_PHONEME, 2},
  89. {"next2Ph", tWHICH_PHONEME, 3},
  90. {"nextPhW", tWHICH_PHONEME, 4},
  91. {"next2PhW", tWHICH_PHONEME, 6},
  92. {"nextVowel",tWHICH_PHONEME, 7},
  93. {"prevVowel",tWHICH_PHONEME, 8},
  94. // {"next2PhW", tWHICH_PHONEME, 0x800},
  95. // {"numVowels", tTEST, 0x000},
  96. {"PreVoicing", tTEST, 0xf01},
  97. {"KlattSynth", tTEST, 0xf02},
  98. {"MbrolaSynth", tTEST, 0xf03},
  99. {NULL, 0, 0}
  100. };
  101. static keywtab_t k_properties[] = {
  102. {"isPause", 0, phPAUSE},
  103. {"isVowel", 0, phVOWEL},
  104. {"isNasal", 0, phNASAL},
  105. {"isLiquid", 0, phLIQUID},
  106. {"isUStop", 0, phSTOP},
  107. {"isVFricative", 0, phVFRICATIVE},
  108. {"isPalatal", 0, i_isPalatal},
  109. {"isRhotic", 0, i_isRhotic},
  110. {"isSibilant", 0, i_isSibilant},
  111. {"isFlag1", 0, i_isFlag1},
  112. {"isFlag2", 0, i_isFlag2},
  113. {"isFlag3", 0, i_isFlag3},
  114. {"isVel", 0, i_isVel},
  115. {"isDiminished", 0, i_isDiminished},
  116. {"isUnstressed", 0, i_isUnstressed},
  117. {"isNotStressed",0, i_isNotStressed},
  118. {"isStressed", 0, i_isStressed},
  119. {"isMaxStress", 0, i_isMaxStress},
  120. {"isBreak", 0, i_isBreak},
  121. {"isPause2", 0, i_isBreak}, // synonym for isBreak
  122. {"isWordStart", 0, i_isWordStart},
  123. {"notWordStart", 0, i_notWordStart},
  124. {"isWordEnd", 0, i_isWordEnd},
  125. {"isAfterStress",0, i_isAfterStress},
  126. {"isNotVowel", 0, i_isNotVowel},
  127. {"isFinalVowel", 0, i_isFinalVowel},
  128. {"isVoiced", 0, i_isVoiced}, // voiced consonant, or vowel
  129. {"isFirstVowel", 0, i_isFirstVowel},
  130. {"isSecondVowel", 0, i_isSecondVowel},
  131. {"isSeqFlag1", 0, i_isSeqFlag1},
  132. {"isTranslationGiven", 0, i_IsTranslationGiven}, // phoneme translation given in **_list or as [[...]]
  133. {NULL, 0, 0}
  134. };
  135. enum {
  136. kPHONEMESTART = 1,
  137. kUTF8_BOM,
  138. kPROCEDURE,
  139. kENDPHONEME,
  140. kENDPROCEDURE,
  141. kEQUIVALENTS,
  142. kPHONEMENUMBER,
  143. kPHONEMETABLE,
  144. kINCLUDE,
  145. kIMPORT_PH,
  146. kSTARTTYPE,
  147. kENDTYPE,
  148. kSTRESSTYPE,
  149. kVOICINGSWITCH,
  150. kIF,
  151. kELSE,
  152. kELIF,
  153. kENDIF,
  154. kCALLPH,
  155. kSWITCH_PREVVOWEL,
  156. kSWITCH_NEXTVOWEL,
  157. kENDSWITCH,
  158. kFMT,
  159. kWAV,
  160. kVOWELSTART,
  161. kVOWELENDING,
  162. kANDWAV,
  163. kVOWELIN,
  164. kVOWELOUT,
  165. kTONESPEC,
  166. kRETURN,
  167. kCONTINUE,
  168. };
  169. enum {
  170. kTUNE = 1,
  171. kENDTUNE,
  172. kTUNE_PREHEAD,
  173. kTUNE_ONSET,
  174. kTUNE_HEAD,
  175. kTUNE_HEADENV,
  176. kTUNE_HEADEXTEND,
  177. kTUNE_HEADLAST,
  178. kTUNE_NUCLEUS0,
  179. kTUNE_NUCLEUS1,
  180. kTUNE_SPLIT,
  181. };
  182. static const char utf8_bom[] = {0xef,0xbb,0xbf,0};
  183. static keywtab_t k_intonation[] = {
  184. {"tune", 0, kTUNE},
  185. {"endtune", 0, kENDTUNE},
  186. {"prehead", 0, kTUNE_PREHEAD},
  187. {"onset", 0, kTUNE_ONSET},
  188. {"head", 0, kTUNE_HEAD},
  189. {"headenv", 0, kTUNE_HEADENV},
  190. {"headextend", 0, kTUNE_HEADEXTEND},
  191. {"headlast", 0, kTUNE_HEADLAST},
  192. {"nucleus0", 0, kTUNE_NUCLEUS0},
  193. {"nucleus", 0, kTUNE_NUCLEUS1},
  194. {"split", 0, kTUNE_SPLIT},
  195. {NULL, 0, -1}
  196. };
  197. static keywtab_t keywords[] = {
  198. {"vowel", tPHONEME_TYPE, phVOWEL},
  199. {"liquid", tPHONEME_TYPE, phLIQUID},
  200. {"pause", tPHONEME_TYPE, phPAUSE},
  201. {"stress", tPHONEME_TYPE, phSTRESS},
  202. {"virtual", tPHONEME_TYPE, phVIRTUAL},
  203. {"fricative", tPHONEME_TYPE, phFRICATIVE},
  204. {"vstop", tPHONEME_TYPE, phVSTOP},
  205. {"vfricative",tPHONEME_TYPE, phVFRICATIVE},
  206. {"delete_phoneme", tPHONEME_TYPE, phDELETED},
  207. // type of consonant
  208. {"stop", tPHONEME_TYPE, phSTOP},
  209. {"frc", tPHONEME_TYPE, phFRICATIVE},
  210. {"nasal", tPHONEME_TYPE, phNASAL},
  211. {"flp", tPHONEME_TYPE, phVSTOP},
  212. {"afr", tPHONEME_TYPE, phSTOP}, // treat as stop
  213. {"apr", tPHONEME_TYPE, phFRICATIVE}, // [h] voiceless approximant
  214. // keywords
  215. {"phonemenumber",tSTATEMENT, kPHONEMENUMBER},
  216. {"phonemetable",tSTATEMENT, kPHONEMETABLE},
  217. {"include", tSTATEMENT, kINCLUDE},
  218. {utf8_bom, tSTATEMENT, kUTF8_BOM},
  219. {"phoneme", tSTATEMENT, kPHONEMESTART},
  220. {"procedure", tSTATEMENT, kPROCEDURE},
  221. {"endphoneme", tSTATEMENT, kENDPHONEME},
  222. {"endprocedure", tSTATEMENT, kENDPROCEDURE},
  223. {"equivalents", tSTATEMENT, kEQUIVALENTS},
  224. {"import_phoneme", tSTATEMENT, kIMPORT_PH},
  225. {"stress_type",tSTATEMENT, kSTRESSTYPE},
  226. {"starttype", tSTATEMENT, kSTARTTYPE},
  227. {"endtype", tSTATEMENT, kENDTYPE},
  228. {"voicingswitch", tSTATEMENT, kVOICINGSWITCH},
  229. {"IF", tSTATEMENT, kIF},
  230. {"ELSE", tSTATEMENT, kELSE},
  231. {"ELIF", tSTATEMENT, kELIF},
  232. {"ELSEIF", tSTATEMENT, kELIF}, // same as ELIF
  233. {"ENDIF", tSTATEMENT, kENDIF},
  234. {"CALL", tSTATEMENT, kCALLPH},
  235. {"RETURN", tSTATEMENT, kRETURN},
  236. {"PrevVowelEndings", tSTATEMENT, kSWITCH_PREVVOWEL},
  237. {"NextVowelStarts", tSTATEMENT, kSWITCH_NEXTVOWEL},
  238. {"EndSwitch", tSTATEMENT, kENDSWITCH},
  239. {"Tone", tSTATEMENT, kTONESPEC},
  240. {"FMT", tSTATEMENT, kFMT},
  241. {"WAV", tSTATEMENT, kWAV},
  242. {"VowelStart", tSTATEMENT, kVOWELSTART},
  243. {"VowelEnding",tSTATEMENT, kVOWELENDING},
  244. {"addWav", tSTATEMENT, kANDWAV},
  245. {"Vowelin", tSTATEMENT, kVOWELIN},
  246. {"Vowelout", tSTATEMENT, kVOWELOUT},
  247. {"Continue", tSTATEMENT, kCONTINUE},
  248. {"ChangePhoneme", tINSTRN1, i_CHANGE_PHONEME},
  249. {"ReplaceNextPhoneme", tINSTRN1, i_REPLACE_NEXT_PHONEME},
  250. {"InsertPhoneme", tINSTRN1, i_INSERT_PHONEME},
  251. {"AppendPhoneme", tINSTRN1, i_APPEND_PHONEME},
  252. {"IfNextVowelAppend", tINSTRN1, i_APPEND_IFNEXTVOWEL},
  253. {"ChangeIfDiminished", tINSTRN1, i_CHANGE_IF + 0},
  254. {"ChangeIfUnstressed", tINSTRN1, i_CHANGE_IF + 1},
  255. {"ChangeIfNotStressed", tINSTRN1, i_CHANGE_IF + 2},
  256. {"ChangeIfStressed", tINSTRN1, i_CHANGE_IF + 3},
  257. {"PauseBefore",tINSTRN1, i_PAUSE_BEFORE},
  258. {"PauseAfter", tINSTRN1, i_PAUSE_AFTER},
  259. {"Length", tINSTRN1, i_SET_LENGTH},
  260. {"length", tINSTRN1, i_SET_LENGTH},
  261. {"LongLength", tINSTRN1, i_LONG_LENGTH},
  262. {"LengthAdd", tINSTRN1, i_ADD_LENGTH},
  263. {"Lengthmod", tINSTRN1, i_LENGTH_MOD},
  264. {"lengthmod", tINSTRN1, i_LENGTH_MOD},
  265. {"ipa", tINSTRN1, i_IPA_NAME},
  266. // flags
  267. {"wavef", tPHONEME_FLAG, phWAVE},
  268. {"unstressed", tPHONEME_FLAG, phUNSTRESSED},
  269. {"fortis", tPHONEME_FLAG, phFORTIS},
  270. {"sibilant", tPHONEME_FLAG, phSIBILANT},
  271. {"nolink", tPHONEME_FLAG, phNOLINK},
  272. {"trill", tPHONEME_FLAG, phTRILL},
  273. {"vowel2", tPHONEME_FLAG, phVOWEL2},
  274. {"palatal", tPHONEME_FLAG, phPALATAL},
  275. {"long", tPHONEME_FLAG, phLONG},
  276. {"brkafter", tPHONEME_FLAG, phBRKAFTER},
  277. {"rhotic", tPHONEME_FLAG, phRHOTIC},
  278. {"nonsyllabic",tPHONEME_FLAG, phNONSYLLABIC},
  279. {"lengthenstop",tPHONEME_FLAG, phLENGTHENSTOP},
  280. {"nopause", tPHONEME_FLAG, phNOPAUSE},
  281. {"prevoice", tPHONEME_FLAG, phPREVOICE},
  282. {"flag1", tPHONEME_FLAG, phFLAG1},
  283. {"flag2", tPHONEME_FLAG, phFLAG2},
  284. {"flag3", tPHONEME_FLAG, phFLAG3},
  285. // voiced / unvoiced
  286. {"vcd", tPHONEME_FLAG, phVOICED},
  287. {"vls", tPHONEME_FLAG, phFORTIS},
  288. // place of articulation, set bits 16-19 of phflags
  289. {"blb", tPLACE, 1},
  290. {"lbd", tPLACE, 2},
  291. {"dnt", tPLACE, 3},
  292. {"alv", tPLACE, 4},
  293. {"rfx", tPLACE, 5},
  294. {"pla", tPLACE, 6},
  295. {"pal", tPLACE, 7},
  296. {"vel", tPLACE, 8},
  297. {"lbv", tPLACE, 9},
  298. {"uvl", tPLACE, 10},
  299. {"phr", tPLACE, 11},
  300. {"glt", tPLACE, 12},
  301. // vowel transition attributes
  302. {"len=", tTRANSITION, 1},
  303. {"rms=", tTRANSITION, 2},
  304. {"f1=", tTRANSITION, 3},
  305. {"f2=", tTRANSITION, 4},
  306. {"f3=", tTRANSITION, 5},
  307. {"brk", tTRANSITION, 6},
  308. {"rate", tTRANSITION, 7},
  309. {"glstop", tTRANSITION, 8},
  310. {"lenadd", tTRANSITION, 9},
  311. {"f4", tTRANSITION, 10},
  312. {"gpaus", tTRANSITION, 11},
  313. {"colr=", tTRANSITION, 12},
  314. {"amp=", tTRANSITION, 13}, // set rms of 1st frame as fraction of rms of 2nd frame (1/30ths)
  315. {NULL, 0, -1}
  316. };
  317. static keywtab_t *keyword_tabs[] = {
  318. keywords, k_conditions, k_properties, k_intonation };
  319. static PHONEME_TAB *phoneme_out;
  320. static int n_phcodes_list[N_PHONEME_TABS];
  321. static PHONEME_TAB_LIST phoneme_tab_list2[N_PHONEME_TABS];
  322. static PHONEME_TAB *phoneme_tab2;
  323. static int phoneme_flags;
  324. static int place_articulation;
  325. static char *p_equivalence;
  326. static char equivalence_buf[20000];
  327. #define N_PROCS 50
  328. int n_procs;
  329. int proc_addr[N_PROCS];
  330. char proc_names[40][N_PROCS];
  331. #define MAX_PROG_BUF 2000
  332. USHORT *prog_out;
  333. USHORT *prog_out_max;
  334. USHORT prog_buf[MAX_PROG_BUF+20];
  335. static const char *KeyToMnem(keywtab_t *ktab, int type, int value)
  336. {//===============================================================
  337. while(ktab->mnem != NULL)
  338. {
  339. if(ktab->data == value)
  340. {
  341. if((type == -1) || (type == ktab->type))
  342. return(ktab->mnem);
  343. }
  344. ktab++;
  345. }
  346. return(NULL);
  347. }
  348. static void DecompilePhoneme(FILE *f_out, PHONEME_TAB *ph, int compile_phoneme)
  349. {//============================================================================
  350. USHORT *pc;
  351. int instn;
  352. int instn_category;
  353. int address, address2;
  354. int data1;
  355. int type2;
  356. int ix;
  357. int any;
  358. const char *name;
  359. char buf[120];
  360. static const char *INV = "Invalid";
  361. static const char *instn_category_string[16] = {
  362. "", "", "IF", "IF OR",
  363. "", "", "", "",
  364. "", "", "", "FMT",
  365. "WAV", "NextVowelStart", "PrevVowelEnd", "+wav" };
  366. static const char *nextPh_string[6] = {
  367. "prevPh", "thisPh", "nextPh", "next2Ph", "nextPhW", "**",
  368. };
  369. static const char *instn0_string[] = {
  370. "invalid", "RETURN", "Continue", "DeleteNextPhoneme",
  371. };
  372. static const char *instn10_string[] = {
  373. "", "VowelIn", "VowelOut", "Tone", "",
  374. };
  375. static const char *instn_jumps[] = {
  376. "JMP", INV, INV, INV,
  377. "JMP false", "SwitchNextVowelType", "SwitchPrevVowelType", INV};
  378. static char instn1_paramtype[] = {
  379. 0, 3, 3, 3, 3, 3, 3, 1,
  380. 1, 1, 1, 1, 1, 0, 0, 0,
  381. 3, 3, 3, 3, 3, 3, 3, 3,
  382. 0, 0, 0, 0, 0, 0, 0, 0};
  383. return;
  384. if(compile_phoneme)
  385. {
  386. fprintf(f_out,"\nPhoneme %s (%d)\n",WordToString(ph->mnemonic),ph->code);
  387. }
  388. else
  389. {
  390. fprintf(f_out,"\nProcedure %s\n",proc_names[n_procs]);
  391. }
  392. pc = prog_buf;
  393. while(pc < prog_out)
  394. {
  395. instn = *pc++;
  396. instn_category = (instn >> 12) & 0xf;
  397. data1 = instn & 0xff;
  398. type2 = (instn >> 8) & 0xf;
  399. fprintf(f_out, " %.3x: %.4x %s",(unsigned int)(pc-prog_buf),instn,instn_category_string[instn_category]);
  400. switch(instn_category)
  401. {
  402. case 0:
  403. case 1:
  404. type2 = instn >> 8;
  405. if(instn < 0x100)
  406. {
  407. if(data1 > 2)
  408. data1 = 0;
  409. fprintf(f_out,"%s",instn0_string[data1]);
  410. }
  411. else
  412. if(type2 == i_IPA_NAME)
  413. {
  414. for(ix = 0; ix < data1; ix += 2)
  415. {
  416. instn = *pc++;
  417. buf[ix] = instn >> 8;
  418. buf[ix+1] = instn & 0xff;
  419. }
  420. buf[ix] = 0;
  421. fprintf(f_out,"ipa %s",buf);
  422. }
  423. else
  424. {
  425. fprintf(f_out,"%s(",KeyToMnem(keywords, tINSTRN1, type2));
  426. switch(instn1_paramtype[type2])
  427. {
  428. case 0:
  429. fprintf(f_out,"%.4x",instn);
  430. break;
  431. case 1:
  432. fprintf(f_out,"%d",data1);
  433. break;
  434. case 3:
  435. fprintf(f_out,"%s",WordToString(phoneme_tab2[data1].mnemonic));
  436. break;
  437. }
  438. fprintf(f_out,")");
  439. }
  440. break;
  441. case 2:
  442. case 3:
  443. if(type2 < 12)
  444. {
  445. fprintf(f_out," %s(",nextPh_string[type2 % 6]);
  446. if(type2 >= 6)
  447. {
  448. switch(data1 >> 5)
  449. {
  450. case 0:
  451. name = KeyToMnem(keywords, tPHONEME_TYPE, (data1 & 0x1f));
  452. if(name != NULL)
  453. fprintf(f_out,"is%s",name);
  454. else
  455. fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f));
  456. break;
  457. case 1:
  458. fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f));
  459. break;
  460. case 2:
  461. fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f));
  462. break;
  463. case 4:
  464. name = KeyToMnem(k_properties, -1, 0x80+(data1 & 0x1f));
  465. if(name != NULL)
  466. fprintf(f_out,"%s",name);
  467. else
  468. fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f));
  469. break;
  470. default:
  471. fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f));
  472. break;
  473. }
  474. }
  475. else
  476. {
  477. fprintf(f_out,"%s",WordToString(phoneme_tab2[data1].mnemonic));
  478. }
  479. }
  480. else
  481. if(type2 == 8)
  482. {
  483. // list of numbers
  484. fprintf(f_out," StressLevel(");
  485. any = 0;
  486. for(ix=0; ix<8; ix++)
  487. {
  488. if(data1 & (1 << ix))
  489. {
  490. if(any)
  491. fputc(',',f_out);
  492. any = 1;
  493. fprintf(f_out,"%d",ix);
  494. }
  495. }
  496. }
  497. else
  498. {
  499. name = KeyToMnem(k_conditions, tTEST, instn & 0xfff);
  500. fprintf(f_out,"%s(",name);
  501. }
  502. fprintf(f_out,")");
  503. break;
  504. case 6:
  505. fprintf(f_out,"%s",instn_jumps[(instn >> 9) & 7]);
  506. fprintf(f_out," %d",instn & 0x1ff);
  507. break;
  508. case 9:
  509. address = ((data1 & 0xf) << 4) + *pc++;
  510. fprintf(f_out,"CALL %.5x",address);
  511. break;
  512. case 10:
  513. fprintf(f_out,"%s",instn10_string[type2]);
  514. switch(type2)
  515. {
  516. case 1:
  517. case 2:
  518. address = (data1 << 16) + pc[0];
  519. address2 = (pc[1] << 16) + pc[2];
  520. pc += 3;
  521. fprintf(f_out, " %.6x %.8x",address,address2);
  522. break;
  523. case 3:
  524. address = ((instn & 0xf) << 16) + *pc++;
  525. address2 = ((instn & 0xf0) << 12) + *pc++;
  526. fprintf(f_out, " %.5x %.5x",address,address2);
  527. break;
  528. }
  529. break;
  530. case 11:
  531. case 12:
  532. case 13:
  533. case 14:
  534. case 15:
  535. address = ((instn & 0xf) << 16) + *pc++;
  536. fprintf(f_out, " %d %.5x",(instn >> 4) & 0xff,address*4);
  537. break;
  538. }
  539. fprintf(f_out,"\n");
  540. }
  541. }
  542. static int n_phoneme_tabs;
  543. static int n_phcodes;
  544. // outout files
  545. static FILE *f_phdata;
  546. static FILE *f_phindex;
  547. static FILE *f_phtab;
  548. static FILE *f_phcontents;
  549. static FILE *f_errors = stderr;
  550. static FILE *f_prog_log = NULL;
  551. static FILE *f_report;
  552. static FILE *f_in;
  553. static int f_in_linenum;
  554. static int f_in_displ;
  555. static int linenum;
  556. static int count_references = 0;
  557. static int duplicate_references = 0;
  558. static int count_frames = 0;
  559. static int error_count = 0;
  560. static int resample_count = 0;
  561. static int resample_fails = 0;
  562. static int then_count = 0;
  563. static int after_if = 0;
  564. static char current_fname[80];
  565. static int markers_used[8];
  566. typedef struct {
  567. void *link;
  568. int value;
  569. int ph_mnemonic;
  570. short ph_table;
  571. char string[1];
  572. } REF_HASH_TAB;
  573. static REF_HASH_TAB *ref_hash_tab[256];
  574. #define N_ENVELOPES 30
  575. int n_envelopes = 0;
  576. char envelope_paths[N_ENVELOPES][80];
  577. unsigned char envelope_dat[N_ENVELOPES][ENV_LEN];
  578. typedef struct {
  579. FILE *file;
  580. int linenum;
  581. char fname[80];
  582. } STACK;
  583. #define N_STACK 12
  584. int stack_ix;
  585. STACK stack[N_STACK];
  586. #define N_IF_STACK 12
  587. int if_level;
  588. typedef struct {
  589. USHORT *p_then;
  590. USHORT *p_else;
  591. int returned;
  592. } IF_STACK;
  593. IF_STACK if_stack[N_IF_STACK];
  594. enum {
  595. tENDFILE = 1,
  596. tSTRING,
  597. tNUMBER,
  598. tSIGNEDNUMBER,
  599. tPHONEMEMNEM,
  600. tOPENBRACKET,
  601. tKEYWORD,
  602. tCONDITION,
  603. tPROPERTIES,
  604. tINTONATION,
  605. };
  606. int item_type;
  607. int item_terminator;
  608. #define N_ITEM_STRING 256
  609. char item_string[N_ITEM_STRING];
  610. static int ref_sorter(char **a, char **b)
  611. {//======================================
  612. int ix;
  613. REF_HASH_TAB *p1 = (REF_HASH_TAB *)(*a);
  614. REF_HASH_TAB *p2 = (REF_HASH_TAB *)(*b);
  615. ix = strcoll(p1->string,p2->string);
  616. if(ix != 0)
  617. return ix;
  618. ix = p1->ph_table - p2->ph_table;
  619. if(ix != 0)
  620. return ix;
  621. return(p1->ph_mnemonic - p2->ph_mnemonic);
  622. } /* end of ref_sorter */
  623. static void CompileReport(void)
  624. {//============================
  625. int ix;
  626. int hash;
  627. int n;
  628. REF_HASH_TAB *p;
  629. REF_HASH_TAB **list;
  630. const char *data_path;
  631. int prev_table;
  632. int procedure_num;
  633. int prev_mnemonic;
  634. if(f_report == NULL)
  635. return;
  636. // make a list of all the references and sort it
  637. list = (REF_HASH_TAB **)malloc((count_references)* sizeof(REF_HASH_TAB *));
  638. if(list == NULL)
  639. return;
  640. fprintf(f_report,"\n%d phoneme tables\n",n_phoneme_tabs);
  641. fprintf(f_report," new total\n");
  642. for(ix=0; ix<n_phoneme_tabs; ix++)
  643. {
  644. fprintf(f_report,"%8s %3d %4d\n",phoneme_tab_list2[ix].name, phoneme_tab_list2[ix].n_phonemes, n_phcodes_list[ix]+1);
  645. }
  646. fputc('\n',f_report);
  647. fprintf(f_report,"Data file Used by\n");
  648. ix = 0;
  649. for(hash=0; (hash < 256) && (ix < count_references); hash++)
  650. {
  651. p = ref_hash_tab[hash];
  652. while(p != NULL)
  653. {
  654. list[ix++] = p;
  655. p = (REF_HASH_TAB *)(p->link);
  656. }
  657. }
  658. n = ix;
  659. qsort((void *)list,n,sizeof(REF_HASH_TAB *),(int (*)(const void *,const void *))ref_sorter);
  660. data_path = "";
  661. prev_mnemonic = 0;
  662. prev_table = 0;
  663. for(ix=0; ix<n; ix++)
  664. {
  665. int j = 0;
  666. if(strcmp(list[ix]->string, data_path) != 0)
  667. {
  668. data_path = list[ix]->string;
  669. j = strlen(data_path);
  670. fprintf(f_report,"%s",data_path);
  671. }
  672. else
  673. {
  674. if((list[ix]->ph_table == prev_table) && (list[ix]->ph_mnemonic == prev_mnemonic))
  675. continue; // same phoneme, don't list twice
  676. }
  677. while(j < 14)
  678. {
  679. fputc(' ',f_report); // pad filename with spaces
  680. j++;
  681. }
  682. prev_mnemonic = list[ix]->ph_mnemonic;
  683. if((prev_mnemonic >> 24) == 'P')
  684. {
  685. // a procedure, not a phoneme
  686. procedure_num = atoi(WordToString(prev_mnemonic));
  687. fprintf(f_report," %s %s", phoneme_tab_list2[prev_table = list[ix]->ph_table].name, proc_names[procedure_num]);
  688. }
  689. else
  690. {
  691. fprintf(f_report," [%s] %s",WordToString(prev_mnemonic), phoneme_tab_list2[prev_table = list[ix]->ph_table].name);
  692. }
  693. fputc('\n',f_report);
  694. }
  695. for(ix=0; ix<n; ix++)
  696. {
  697. free(list[ix]);
  698. list[ix] = NULL;
  699. }
  700. free(list);
  701. list = NULL;
  702. fclose(f_report);
  703. } // end of CompileReport
  704. #ifdef PLATFORM_WINDOWS
  705. int strcasecmp(const char *s1, const char *s2)
  706. {
  707. int ix=0;
  708. int diff;
  709. for(;;)
  710. {
  711. if((diff = (tolower(s1[ix]) - tolower(s2[ix]))) != 0)
  712. return(diff);
  713. if((s1[ix] == 0) || (s2[ix] == 0))
  714. return(diff);
  715. ix++;
  716. }
  717. }
  718. #endif
  719. static int ph_sorter(char **a, char **b)
  720. {//======================================
  721. int ix;
  722. int t1, t2;
  723. char mnem1[6];
  724. PHONEME_TAB *p1 = (PHONEME_TAB *)(*a);
  725. PHONEME_TAB *p2 = (PHONEME_TAB *)(*b);
  726. t1 = p1->type;
  727. if(t1 > phVOWEL) t1 = phVOWEL+1;
  728. t2 = p2->type;
  729. if(t2 > phVOWEL) t2 = phVOWEL+1;
  730. if((ix = t1 - t2) != 0)
  731. return(ix);
  732. strcpy(mnem1,WordToString(p1->mnemonic));
  733. return(strcasecmp(mnem1,WordToString(p2->mnemonic)));
  734. } /* end of ph_sorter */
  735. static void PrintPhonemesUsed(FILE *f, const char *dsource, const char *dictname)
  736. {//==============================================================================
  737. int ix;
  738. PHONEME_TAB *ph;
  739. PHONEME_TAB *ph_tab[N_PHONEME_TAB];
  740. int count = 0;
  741. int n_ph = 0;
  742. int section = 0;
  743. time_t mod_time;
  744. char fname[sizeof(path_home)+45];
  745. struct stat statbuf;
  746. char time_string[20];
  747. const char *files[] = {"rules","list","listx"};
  748. // find the date-stamp of the dictionary source files
  749. mod_time = 0;
  750. for(ix=0; ix<3; ix++)
  751. {
  752. sprintf(fname,"%s%s_%s",dsource, dictname, files[ix]);
  753. if(stat(fname,&statbuf) == 0)
  754. {
  755. if(statbuf.st_mtime > mod_time)
  756. mod_time = statbuf.st_mtime;
  757. }
  758. }
  759. if(mod_time > 0)
  760. {
  761. strftime(time_string, sizeof(time_string), "%F", localtime(&mod_time));
  762. fprintf(f,"\n\nDictionary %s_dict %s\n",dictname, time_string);
  763. }
  764. else
  765. {
  766. fprintf(f,"\n\nDictionary %s_dict\n",dictname);
  767. }
  768. fflush(f);
  769. for(ix=0; (ix<N_PHONEME_TAB) && (phoneme_tab[ix] != NULL); ix++)
  770. {
  771. if(phoneme_tab_flags[ix] & 2)
  772. {
  773. ph_tab[n_ph++] = phoneme_tab[ix];
  774. }
  775. }
  776. qsort((void *)ph_tab,n_ph,sizeof(PHONEME_TAB *),(int (*)(const void *,const void *))ph_sorter);
  777. for(ix=0; ix<n_ph; ix++)
  778. {
  779. ph = ph_tab[ix];
  780. if(ph->type > 1)
  781. {
  782. if((ph->type > phVOWEL) && (section == 0))
  783. {
  784. section = 1;
  785. count = 0;
  786. fputc('\n',f);
  787. }
  788. if((count & 0x7) == 0)
  789. fputc('\n',f);
  790. fprintf(f,"%-4s ",WordToString(ph->mnemonic));
  791. count++;
  792. }
  793. }
  794. fputc('\n',f);
  795. } // end of PrintPhonemesUsed
  796. static wxString CompileAllDictionaries()
  797. {//=====================================
  798. wxString filename;
  799. wxFileName fname;
  800. wxString dictstr;
  801. wxString filetype;
  802. wxString report = _T("");
  803. int err;
  804. int errors = 0;
  805. int dict_count = 0;
  806. FILE *f_in;
  807. FILE *log;
  808. FILE *f_phused;
  809. char dictname[80];
  810. char fname_log[sizeof(path_dsource)+20];
  811. char save_voice_name[80];
  812. char path[sizeof(path_home)+40]; // path_dsource+20
  813. char buf[200];
  814. char voicename[80];
  815. if(!wxDirExists(path_dictsource))
  816. {
  817. if(gui_flag)
  818. {
  819. wxString dirname = wxDirSelector(_T("Directory of dictionary files"),path_phsource);
  820. if(!dirname.IsEmpty())
  821. {
  822. path_dictsource = dirname;
  823. strncpy0(path_dsource,path_dictsource.mb_str(wxConvLocal),sizeof(path_dsource)-1);
  824. strcat(path_dsource,"/");
  825. }
  826. }
  827. else
  828. {
  829. fprintf(stderr,"Can't find dictionary files: %s\n",path_dsource);
  830. }
  831. }
  832. wxDir dir(path_dictsource);
  833. if(!dir.IsOpened())
  834. {
  835. return(_T(" No dictionaries"));
  836. }
  837. strcpy(save_voice_name,voice_name2);
  838. sprintf(fname_log,"%s%s",path_dsource,"dict_log");
  839. log = fopen(fname_log,"w");
  840. sprintf(fname_log,"%s%s",path_dsource,"dict_phonemes");
  841. f_phused = fopen(fname_log,"w");
  842. if(f_phused)
  843. {
  844. fprintf(f_phused,"Phonemes which are used in the *_rules and *_list files\n");
  845. }
  846. bool cont = dir.GetFirst(&filename, _T("*_rules*"), wxDIR_FILES);
  847. while ( cont )
  848. {
  849. fname = wxFileName(filename);
  850. filetype = fname.GetName().AfterLast('_');
  851. if((filetype != _T("rules")) && (filetype != _T("rules.txt")))
  852. {
  853. cont = dir.GetNext(&filename);
  854. continue;
  855. }
  856. dictstr = fname.GetName().BeforeLast('_');
  857. strcpy(dictname,dictstr.mb_str(wxConvLocal));
  858. dict_count++;
  859. strcpy(voicename,dictname);
  860. // read the *_rules file to see if a phoneme table is specified though a voice name
  861. sprintf(path,"%s%s_rules.txt",path_dsource,dictname);
  862. if((f_in = fopen(path,"r")) == NULL)
  863. {
  864. sprintf(path,"%s%s_rules",path_dsource,dictname);
  865. f_in = fopen(path,"r");
  866. }
  867. if(f_in != NULL)
  868. {
  869. unsigned int ix;
  870. unsigned int c;
  871. for(ix=0; ix<20; ix++)
  872. {
  873. if(fgets(buf,sizeof(buf),f_in) == NULL)
  874. break;
  875. if(memcmp(buf,"//voice=",8)==0)
  876. {
  877. for(ix=0; ix<sizeof(voicename); ix++)
  878. {
  879. if(isspace(c = buf[ix+8]))
  880. {
  881. break;
  882. }
  883. voicename[ix] = c;
  884. }
  885. voicename[ix] = 0;
  886. break;
  887. }
  888. }
  889. fclose(f_in);
  890. }
  891. LoadVoice(voicename,0);
  892. if((err = CompileDictionary(path_dsource, dictname,log,NULL,0)) > 0)
  893. {
  894. report = report + dictstr + wxString::Format(_T(" %d, "),err);
  895. errors += err;
  896. }
  897. if(f_phused != NULL)
  898. {
  899. memset(phoneme_tab_flags,0,sizeof(phoneme_tab_flags));
  900. FindPhonemesUsed();
  901. PrintPhonemesUsed(f_phused, path_dsource, dictname);
  902. }
  903. cont = dir.GetNext(&filename);
  904. }
  905. if(log != NULL)
  906. fclose(log);
  907. if(f_phused != NULL)
  908. fclose(f_phused);
  909. LoadVoiceVariant(save_voice_name,0);
  910. if(errors == 0)
  911. return(wxString::Format(_T(" Compiled %d dictionaries"),dict_count));
  912. else
  913. {
  914. return(_T(" Dictionary errors: ") + report);
  915. }
  916. } // end of CompileAllDictionaries
  917. static void error(const char *format, const char *string)
  918. {//======================================================
  919. if(string==NULL)
  920. string = "";
  921. fprintf(f_errors,"%4d: ",linenum-1);
  922. fprintf(f_errors,format,string);
  923. fprintf(f_errors,"\n");
  924. error_count++;
  925. }
  926. static void Error(const char *string)
  927. {//==================================
  928. error("%s",string);
  929. }
  930. static FILE *fopen_log(FILE *f_log, const char *fname,const char *access)
  931. {//=====================================================================
  932. // performs fopen, but produces error message to f_log if it fails
  933. FILE *f;
  934. if((f = fopen(fname,access)) == NULL)
  935. {
  936. if(f_log != NULL)
  937. fprintf(f_log,"Can't access (%s) file '%s'\n",access,fname);
  938. }
  939. return(f);
  940. }
  941. static unsigned int StringToWord(const char *string)
  942. {//=================================================
  943. // Pack 4 characters into a word
  944. int ix;
  945. unsigned char c;
  946. unsigned int word;
  947. word = 0;
  948. for(ix=0; ix<4; ix++)
  949. {
  950. if(string[ix]==0) break;
  951. c = string[ix];
  952. word |= (c << (ix*8));
  953. }
  954. return(word);
  955. }
  956. static MNEM_TAB reserved_phonemes[] = {
  957. {"_\001", phonCONTROL}, // NOT USED
  958. {"%", phonSTRESS_U},
  959. {"%%", phonSTRESS_D},
  960. {",", phonSTRESS_2},
  961. {",,", phonSTRESS_3},
  962. {"'", phonSTRESS_P},
  963. {"''", phonSTRESS_P2},
  964. {"=", phonSTRESS_PREV}, // stress previous syllable
  965. {"_:", phonPAUSE}, // pause
  966. {"_", phonPAUSE_SHORT}, // short pause
  967. {"_!", phonPAUSE_NOLINK}, // short pause, no link
  968. {":", phonLENGTHEN},
  969. {"@", phonSCHWA},
  970. {"@-", phonSCHWA_SHORT},
  971. {"||", phonEND_WORD},
  972. {"1", phonDEFAULTTONE}, // (numeral 1) default tone (for tone language)
  973. {"#X1",phonCAPITAL}, // capital letter indication
  974. {"?", phonGLOTTALSTOP}, // glottal stop
  975. {"-", phonSYLLABIC}, // syllabic consonant
  976. {"_^_",phonSWITCH}, // Change language
  977. {"_X1",phonX1}, // a language specific action
  978. {"_|", phonPAUSE_VSHORT}, // very short pause
  979. {"_::",phonPAUSE_LONG}, // long pause
  980. {"t#", phonT_REDUCED}, // reduced version of [t]
  981. {"'!", phonSTRESS_TONIC}, // stress - emphasized
  982. {"_;_",phonPAUSE_CLAUSE}, // clause pause
  983. {"#@", phonVOWELTYPES}, // vowel type groups, these must be consecutive
  984. {"#a", phonVOWELTYPES+1},
  985. {"#e", phonVOWELTYPES+2},
  986. {"#i", phonVOWELTYPES+3},
  987. {"#o", phonVOWELTYPES+4},
  988. {"#u", phonVOWELTYPES+5},
  989. {NULL, 0} };
  990. static void ReservePhCodes()
  991. {//=========================
  992. // Reserve phoneme codes which have fixed numbers so that they can be
  993. // referred to from the program code.
  994. unsigned int word;
  995. MNEM_TAB *p;
  996. p = reserved_phonemes;
  997. while(p->mnem != NULL)
  998. {
  999. word = StringToWord(p->mnem);
  1000. phoneme_tab2[p->value].mnemonic = word;
  1001. phoneme_tab2[p->value].code = p->value;
  1002. if(n_phcodes <= p->value)
  1003. n_phcodes = p->value+1;
  1004. p++;
  1005. }
  1006. } // end of ReservePhCodes
  1007. static int LookupPhoneme(const char *string, int control)
  1008. {//======================================================
  1009. // control = 0 explicit declaration
  1010. // control = 1 declare phoneme if not found
  1011. // control = 2 start looking after control & stress phonemes
  1012. int ix;
  1013. int start;
  1014. int use;
  1015. unsigned int word;
  1016. if(strcmp(string,"NULL")==0)
  1017. return(1);
  1018. ix = strlen(string);
  1019. if((ix==0) || (ix> 4))
  1020. {
  1021. error("Bad phoneme name '%s'",string);
  1022. }
  1023. word = StringToWord(string);
  1024. // don't use phoneme number 0, reserved for string terminator
  1025. start = 1;
  1026. if(control==2)
  1027. start = 8; // don't look for control and stress phonemes (allows these characters to be
  1028. // used for other purposes)
  1029. use = 0;
  1030. for(ix=start; ix<n_phcodes; ix++)
  1031. {
  1032. if(phoneme_tab2[ix].mnemonic == word)
  1033. return(ix);
  1034. if((use==0) && (phoneme_tab2[ix].mnemonic == 0))
  1035. {
  1036. use = ix;
  1037. }
  1038. }
  1039. if(use == 0)
  1040. {
  1041. if(control == 0)
  1042. return(-1);
  1043. if(n_phcodes >= N_PHONEME_TAB-1)
  1044. return(-1); // phoneme table is full
  1045. use = n_phcodes++;
  1046. }
  1047. // add this phoneme to the phoneme table
  1048. phoneme_tab2[use].mnemonic = word;
  1049. phoneme_tab2[use].type = phINVALID;
  1050. phoneme_tab2[use].program = linenum; // for error report if the phoneme remains undeclared
  1051. return(use);
  1052. } // end of Compile::LookupPhoneme
  1053. static unsigned int get_char()
  1054. {//===========================
  1055. unsigned int c;
  1056. c = fgetc(f_in);
  1057. if(c == '\n')
  1058. linenum++;
  1059. return(c);
  1060. }
  1061. static void unget_char(unsigned int c)
  1062. {//===================================
  1063. ungetc(c,f_in);
  1064. if(c == '\n')
  1065. linenum--;
  1066. }
  1067. int CheckNextChar()
  1068. {//================
  1069. int c;
  1070. while(((c = get_char()) == ' ') || (c == '\t'));
  1071. unget_char(c);
  1072. return(c);
  1073. } // end of CheckNextChar
  1074. static int NextItem(int type)
  1075. {//==========================
  1076. int acc;
  1077. unsigned char c=0;
  1078. unsigned char c2;
  1079. int ix;
  1080. int sign;
  1081. char *p;
  1082. keywtab_t *pk;
  1083. item_type = -1;
  1084. f_in_displ = ftell(f_in);
  1085. f_in_linenum = linenum;
  1086. while(!feof(f_in))
  1087. {
  1088. c = get_char();
  1089. if(c=='/')
  1090. {
  1091. if((c2 = get_char())=='/')
  1092. {
  1093. // comment, ignore to end of line
  1094. while(!feof(f_in) && ((c = get_char()) != '\n'));
  1095. }
  1096. else
  1097. {
  1098. unget_char(c2);
  1099. }
  1100. }
  1101. if(!isspace(c))
  1102. {
  1103. break;
  1104. }
  1105. }
  1106. if(feof(f_in))
  1107. return(-2);
  1108. if(c == '(')
  1109. {
  1110. if(type == tOPENBRACKET)
  1111. return(1);
  1112. return(-1);
  1113. }
  1114. ix = 0;
  1115. while(!feof(f_in) && !isspace(c) && (c != '(') && (c != ')') && (c != ','))
  1116. {
  1117. if(c == '\\')
  1118. c = get_char();
  1119. item_string[ix++] = c;
  1120. c = get_char();
  1121. if(feof(f_in))
  1122. break;
  1123. if(item_string[ix-1] == '=')
  1124. break;
  1125. }
  1126. item_string[ix] = 0;
  1127. while(isspace(c))
  1128. {
  1129. c = get_char();
  1130. }
  1131. item_terminator = ' ';
  1132. if((c == ')') || (c == '(') || (c == ','))
  1133. item_terminator = c;
  1134. if((c == ')') || (c == ','))
  1135. c = ' ';
  1136. if(!feof(f_in))
  1137. unget_char(c);
  1138. if(type == tSTRING)
  1139. {
  1140. return(0);
  1141. }
  1142. if((type == tNUMBER) || (type == tSIGNEDNUMBER))
  1143. {
  1144. acc = 0;
  1145. sign = 1;
  1146. p = item_string;
  1147. if((*p == '-') && (type == tSIGNEDNUMBER))
  1148. {
  1149. sign = -1;
  1150. p++;
  1151. }
  1152. if(!isdigit(*p))
  1153. {
  1154. if((type == tNUMBER) && (*p == '-'))
  1155. error("Expected an unsigned number",NULL);
  1156. else
  1157. error("Expected a number",NULL);
  1158. }
  1159. while(isdigit(*p))
  1160. {
  1161. acc *= 10;
  1162. acc += (*p - '0');
  1163. p++;
  1164. }
  1165. return(acc * sign);
  1166. }
  1167. if((type >= tKEYWORD) && (type <= tINTONATION))
  1168. {
  1169. pk = keyword_tabs[type-tKEYWORD];
  1170. while(pk->mnem != NULL)
  1171. {
  1172. if(strcmp(item_string,pk->mnem)==0)
  1173. {
  1174. item_type = pk->type;
  1175. return(pk->data);
  1176. }
  1177. pk++;
  1178. }
  1179. item_type = -1;
  1180. return(-1); // keyword not found
  1181. }
  1182. if(type == tPHONEMEMNEM)
  1183. {
  1184. return(LookupPhoneme(item_string,2));
  1185. }
  1186. return(-1);
  1187. } // end of NextItem
  1188. static int NextItemMax(int max)
  1189. {//==============================
  1190. // Get a number, but restrict value to max
  1191. int value;
  1192. char msg[80];
  1193. value = NextItem(tNUMBER);
  1194. if(value > max)
  1195. {
  1196. sprintf(msg, "Value %d is greater than maximum %d", value, max);
  1197. error(msg, NULL);
  1198. value = max;
  1199. }
  1200. return(value);
  1201. }
  1202. static int NextItemBrackets(int type, int control)
  1203. {//===============================================
  1204. // Expect a parameter inside parantheses
  1205. // control: bit 0 0= need (
  1206. // bit 1 1= allow comma
  1207. int value;
  1208. if((control & 1) == 0)
  1209. {
  1210. if(!NextItem(tOPENBRACKET))
  1211. {
  1212. error("Expected '('", NULL);
  1213. }
  1214. }
  1215. value = NextItem(type);
  1216. if((control & 2) && (item_terminator == ','))
  1217. return(value);
  1218. if(item_terminator != ')')
  1219. {
  1220. error("Expected ')'", NULL);
  1221. }
  1222. return(value);
  1223. }
  1224. static void UngetItem()
  1225. {//====================
  1226. fseek(f_in,f_in_displ,SEEK_SET);
  1227. linenum = f_in_linenum;
  1228. } // end of UngetItem
  1229. static int Range(int value, int divide, int min, int max)
  1230. {//======================================================
  1231. if(value < 0)
  1232. value -= divide/2;
  1233. else
  1234. value += divide/2;
  1235. value = value / divide;
  1236. if(value > max)
  1237. value = max;
  1238. if(value < min)
  1239. value = min;
  1240. return(value - min);
  1241. }
  1242. int CompileVowelTransition(int which)
  1243. {//==================================
  1244. // Compile a vowel transition
  1245. int key;
  1246. int len=0;
  1247. int rms=0;
  1248. int f1=0;
  1249. int f2=0;
  1250. int f2_min=0;
  1251. int f2_max=0;
  1252. int f3_adj=0;
  1253. int f3_amp=0;
  1254. int flags=0;
  1255. int vcolour=0;
  1256. int x;
  1257. int instn = i_VOWELIN;
  1258. int word1;
  1259. int word2;
  1260. if(which==1)
  1261. {
  1262. // instn = i_VOWELIN;
  1263. len = 50 / 2; // defaults for transition into vowel
  1264. rms = 25 / 2;
  1265. if(phoneme_out->type == phSTOP)
  1266. {
  1267. len = 42 / 2; // defaults for transition into vowel
  1268. rms = 30 / 2;
  1269. }
  1270. }
  1271. else
  1272. if(which==2)
  1273. {
  1274. instn = i_VOWELOUT;
  1275. len = 36 / 2; // defaults for transition out of vowel
  1276. rms = 16 / 2;
  1277. }
  1278. for(;;)
  1279. {
  1280. key = NextItem(tKEYWORD);
  1281. if(item_type != tTRANSITION)
  1282. {
  1283. UngetItem();
  1284. break;
  1285. }
  1286. switch(key & 0xf)
  1287. {
  1288. case 1:
  1289. len = Range(NextItem(tNUMBER), 2, 0, 63) & 0x3f;
  1290. flags |= 1;
  1291. break;
  1292. case 2:
  1293. rms = Range(NextItem(tNUMBER), 2, 0, 31) & 0x1f;
  1294. flags |= 1;
  1295. break;
  1296. case 3:
  1297. f1 = NextItem(tNUMBER);
  1298. break;
  1299. case 4:
  1300. f2 = Range(NextItem(tNUMBER), 50, 0, 63) & 0x3f;
  1301. f2_min = Range(NextItem(tSIGNEDNUMBER), 50, -15, 15) & 0x1f;
  1302. f2_max = Range(NextItem(tSIGNEDNUMBER), 50, -15, 15) & 0x1f;
  1303. if(f2_min > f2_max)
  1304. {
  1305. x = f2_min;
  1306. f2_min = f2_max;
  1307. f2_max = x;
  1308. }
  1309. break;
  1310. case 5:
  1311. f3_adj = Range(NextItem(tSIGNEDNUMBER), 50, -15, 15) & 0x1f;
  1312. f3_amp = Range(NextItem(tNUMBER), 8, 0, 15) & 0x1f;
  1313. break;
  1314. case 6:
  1315. flags |= 2; // break
  1316. break;
  1317. case 7:
  1318. flags |= 4; // rate
  1319. break;
  1320. case 8:
  1321. flags |= 8; // glstop
  1322. break;
  1323. case 9:
  1324. flags |= 16; // lenadd
  1325. break;
  1326. case 10:
  1327. flags |= 32; // f4
  1328. break;
  1329. case 11:
  1330. flags |= 64; // paus
  1331. break;
  1332. case 12:
  1333. vcolour = NextItem(tNUMBER);
  1334. break;
  1335. case 13:
  1336. // set rms of 1st frame as fraction of rms of 2nd frame (1/30ths)
  1337. rms = (Range(NextItem(tNUMBER), 1, 0, 31) & 0x1f) | 0x20;
  1338. flags |= 1;
  1339. break;
  1340. }
  1341. }
  1342. word1 = len + (rms << 6) + (flags << 12);
  1343. word2 = f2 + (f2_min << 6) + (f2_max << 11) + (f3_adj << 16) + (f3_amp << 21) + (f1 << 26) + (vcolour << 29);
  1344. prog_out[0] = instn + ((word1 >> 16) & 0xff);
  1345. prog_out[1] = word1;
  1346. prog_out[2] = word2 >> 16;
  1347. prog_out[3] = word2;
  1348. prog_out += 4;
  1349. return(0);
  1350. } // end of VowelTransition
  1351. int LoadSpect(const char *path, int control)
  1352. {//=========================================
  1353. SpectSeq *spectseq;
  1354. int peak;
  1355. int displ;
  1356. int frame;
  1357. int n_frames;
  1358. int ix;
  1359. int x, x2;
  1360. int rms;
  1361. float total;
  1362. float pkheight;
  1363. int marker1_set=0;
  1364. int frame_vowelbreak=0;
  1365. int klatt_flag=0;
  1366. SpectFrame *fr;
  1367. frame_t *fr_out;
  1368. wxString path_sep = _T("/");
  1369. SPECT_SEQ seq_out;
  1370. SPECT_SEQK seqk_out;
  1371. // create SpectSeq and import data
  1372. spectseq = new SpectSeq;
  1373. if(spectseq == NULL)
  1374. {
  1375. Error("Failed to create SpectSeq");
  1376. return(0);
  1377. }
  1378. wxString filename = path_phsource + path_sep + wxString(path,wxConvLocal);
  1379. wxFileInputStream stream(filename);
  1380. if(stream.Ok() == FALSE)
  1381. {
  1382. error("Failed to open: '%s'",path);
  1383. return(0);
  1384. }
  1385. spectseq->Load(stream);
  1386. // do we need additional klatt data ?
  1387. for(frame=0; frame < spectseq->numframes; frame++)
  1388. {
  1389. for(ix=5; ix<N_KLATTP2; ix++)
  1390. {
  1391. if(spectseq->frames[frame]->klatt_param[ix] != 0)
  1392. klatt_flag = FRFLAG_KLATT;
  1393. }
  1394. }
  1395. displ = ftell(f_phdata);
  1396. seq_out.n_frames=0;
  1397. seq_out.sqflags=0;
  1398. seq_out.length_total=0;
  1399. total = 0;
  1400. for(frame=0; frame < spectseq->numframes; frame++)
  1401. {
  1402. #ifdef deleted
  1403. for(ix=0; ix<8; ix++)
  1404. {
  1405. // find which files have certain markers set
  1406. if(spectseq->frames[frame]->markers & (1<<ix))
  1407. {
  1408. markers_used[ix]++;
  1409. if((ix==3) || (ix==4))
  1410. {
  1411. fprintf(f_errors,"Marker %d: %s\n",ix,path);
  1412. }
  1413. }
  1414. }
  1415. #endif
  1416. if(spectseq->frames[frame]->keyframe)
  1417. {
  1418. if(seq_out.n_frames == 1)
  1419. {
  1420. frame_vowelbreak = frame;
  1421. }
  1422. if(spectseq->frames[frame]->markers & 0x2)
  1423. {
  1424. // marker 1 is set
  1425. marker1_set = 1;
  1426. }
  1427. seq_out.n_frames++;
  1428. if(frame > 0)
  1429. total += spectseq->frames[frame-1]->length;
  1430. }
  1431. }
  1432. seq_out.length_total = int(total);
  1433. if((control & 1) && (marker1_set == 0))
  1434. {
  1435. // This is a vowel, but no Vowel Break marker is set
  1436. // set a marker flag for the second frame of a vowel
  1437. spectseq->frames[frame_vowelbreak]->markers |= FRFLAG_VOWEL_CENTRE;
  1438. }
  1439. n_frames = 0;
  1440. for(frame=0; frame < spectseq->numframes; frame++)
  1441. {
  1442. fr = spectseq->frames[frame];
  1443. if(fr->keyframe)
  1444. {
  1445. if(klatt_flag)
  1446. fr_out = &seqk_out.frame[n_frames];
  1447. else
  1448. fr_out = (frame_t *)&seq_out.frame[n_frames];
  1449. x = int(fr->length + 0.5); // round to nearest mS
  1450. if(x > 255) x = 255;
  1451. fr_out->length = x;
  1452. fr_out->frflags = fr->markers | klatt_flag;
  1453. rms = int(fr->GetRms(spectseq->amplitude));
  1454. if(rms > 255) rms = 255;
  1455. fr_out->rms = rms;
  1456. if(n_frames == (seq_out.n_frames-1))
  1457. fr_out->length = 0; // give last frame zero length
  1458. // write: peak data
  1459. count_frames++;
  1460. for(peak=0; peak < 8; peak++)
  1461. {
  1462. if(peak < 7)
  1463. fr_out->ffreq[peak] = fr->peaks[peak].pkfreq;
  1464. pkheight = spectseq->amplitude * fr->amp_adjust * fr->peaks[peak].pkheight;
  1465. pkheight = pkheight/640000;
  1466. if(pkheight > 255) pkheight = 255;
  1467. fr_out->fheight[peak] = int(pkheight);
  1468. if(peak < 6)
  1469. {
  1470. x = fr->peaks[peak].pkwidth/4;
  1471. if(x > 255) x = 255;
  1472. fr_out->fwidth[peak] = x;
  1473. if(peak < 3)
  1474. {
  1475. x2 = fr->peaks[peak].pkright/4;
  1476. if(x2 > 255) x2 = 255;
  1477. fr_out->fright[peak] = x2;
  1478. }
  1479. }
  1480. if(peak < 4)
  1481. {
  1482. x = fr->peaks[peak].klt_bw / 2;
  1483. if(x > 255) x = 255;
  1484. fr_out->bw[peak] = x;
  1485. }
  1486. }
  1487. for(ix=0; ix<5; ix++)
  1488. {
  1489. fr_out->klattp[ix] = fr->klatt_param[ix];
  1490. fr_out->klattp[KLATT_FNZ] = fr->klatt_param[KLATT_FNZ] / 2;
  1491. }
  1492. if(klatt_flag)
  1493. {
  1494. // additional klatt parameters
  1495. for(ix=0; ix<5; ix++)
  1496. {
  1497. fr_out->klattp2[ix] = fr->klatt_param[ix+5];
  1498. }
  1499. for(peak=0; peak<7; peak++)
  1500. {
  1501. fr_out->klatt_ap[ix] = fr->peaks[peak].klt_ap;
  1502. x = fr->peaks[peak].klt_bp / 2;
  1503. if(x > 255) x = 255;
  1504. fr_out->klatt_bp[ix] = x;
  1505. }
  1506. }
  1507. if(fr_out->bw[1] == 0)
  1508. {
  1509. fr_out->bw[0] = 89 / 2;
  1510. fr_out->bw[1] = 90 / 2;
  1511. fr_out->bw[2] = 140 / 2;
  1512. fr_out->bw[3] = 260 / 2;
  1513. }
  1514. n_frames++;
  1515. }
  1516. }
  1517. if(klatt_flag)
  1518. {
  1519. seqk_out.n_frames = seq_out.n_frames;
  1520. seqk_out.sqflags = seq_out.sqflags;
  1521. seqk_out.length_total = seq_out.length_total;
  1522. ix = (char *)(&seqk_out.frame[seqk_out.n_frames]) - (char *)(&seqk_out);
  1523. ix = (ix+3) & 0xfffc; // round up to multiple of 4 bytes
  1524. fwrite(&seqk_out,ix,1,f_phdata);
  1525. }
  1526. else
  1527. {
  1528. ix = (char *)(&seq_out.frame[seq_out.n_frames]) - (char *)(&seq_out);
  1529. ix = (ix+3) & 0xfffc; // round up to multiple of 4 bytes
  1530. fwrite(&seq_out,ix,1,f_phdata);
  1531. }
  1532. delete spectseq;
  1533. return(displ);
  1534. } // end of LoadSpect
  1535. static int LoadWavefile(FILE *f, const char *fname)
  1536. {//================================================
  1537. int displ;
  1538. unsigned char c1;
  1539. unsigned char c3;
  1540. int c2;
  1541. int sample;
  1542. int sample2;
  1543. float x;
  1544. int max = 0;
  1545. int length;
  1546. int sr1, sr2;
  1547. int failed;
  1548. int len;
  1549. int resample_wav = 0;
  1550. const char *fname2;
  1551. char fname_temp[100];
  1552. char msg[120];
  1553. int scale_factor=0;
  1554. fseek(f,24,SEEK_SET);
  1555. sr1 = Read4Bytes(f);
  1556. sr2 = Read4Bytes(f);
  1557. fseek(f,40,SEEK_SET);
  1558. if((sr1 != samplerate_native) || (sr2 != sr1*2))
  1559. {
  1560. int fd_temp;
  1561. char command[sizeof(path_source)+200];
  1562. failed = 0;
  1563. #ifdef PLATFORM_POSIX
  1564. strcpy(fname_temp,"/tmp/espeakXXXXXX");
  1565. if((fd_temp = mkstemp(fname_temp)) >= 0)
  1566. {
  1567. close(fd_temp);
  1568. }
  1569. #else
  1570. strcpy(fname_temp,tmpnam(NULL));
  1571. #endif
  1572. fname2 = fname;
  1573. len = strlen(fname);
  1574. if(strcmp(&fname[len-4], ".wav") == 0)
  1575. {
  1576. strcpy(msg, fname);
  1577. msg[len-4] = 0;
  1578. fname2 = msg;
  1579. }
  1580. sprintf(command,"sox \"%s%s.wav\" -r %d -c1 -t wav %s\n",path_source,fname2,samplerate_native, fname_temp);
  1581. if(system(command) != 0)
  1582. {
  1583. failed = 1;
  1584. }
  1585. if(failed || (GetFileLength(fname_temp) <= 0))
  1586. {
  1587. if(resample_fails < 2)
  1588. error("Resample command failed: %s", command);
  1589. resample_fails++;
  1590. if(sr1 != samplerate_native)
  1591. {
  1592. sprintf(msg, "Can't resample (%d to %d): %s", sr1, samplerate_native, fname);
  1593. error("%s", msg);
  1594. }
  1595. else
  1596. {
  1597. error("WAV file is not mono: %s", fname);
  1598. }
  1599. remove(fname_temp);
  1600. return(0);
  1601. }
  1602. f = fopen(fname_temp,"rb");
  1603. if(f == NULL)
  1604. {
  1605. error("Can't read temp file: %s",fname_temp);
  1606. return(0);
  1607. }
  1608. if(f_report != NULL)
  1609. fprintf(f_report, "resampled %s\n", fname);
  1610. resample_count++;
  1611. resample_wav = 1;
  1612. fseek(f,40,SEEK_SET); // skip past the WAV header, up to before "data length"
  1613. }
  1614. displ = ftell(f_phdata);
  1615. // data contains: 4 bytes of length (n_samples * 2), followed by 2-byte samples (lsb byte first)
  1616. length = Read4Bytes(f);
  1617. while(!feof(f))
  1618. {
  1619. c1 = fgetc(f);
  1620. c3 = fgetc(f);
  1621. if(feof(f)) break;
  1622. c2 = c3 << 24;
  1623. c2 = c2 >> 16; // sign extend
  1624. sample = (c1 & 0xff) + c2;
  1625. if(sample > max)
  1626. max = sample;
  1627. else
  1628. if(sample < -max)
  1629. max = -sample;
  1630. }
  1631. scale_factor = (max / 127) + 1;
  1632. //fprintf(f_errors," sample len=%d max=%4x shift=%d\n",length,max,scale_factor);
  1633. #define MIN_FACTOR -1 // was 6, disable use of 16 bit samples
  1634. if(scale_factor > MIN_FACTOR)
  1635. {
  1636. length = length/2 + (scale_factor << 16);
  1637. }
  1638. Write4Bytes(f_phdata,length);
  1639. // fwrite(&length,4,1,f_phdata);
  1640. fseek(f,44,SEEK_SET);
  1641. while(!feof(f))
  1642. {
  1643. c1 = fgetc(f);
  1644. c3 = fgetc(f);
  1645. c2 = c3 << 24;
  1646. c2 = c2 >> 16; // sign extend
  1647. sample = (c1 & 0xff) + c2;
  1648. if(feof(f)) break;
  1649. if(scale_factor <= MIN_FACTOR)
  1650. {
  1651. fputc(sample & 0xff,f_phdata);
  1652. fputc(sample >> 8,f_phdata);
  1653. }
  1654. else
  1655. {
  1656. x = (float(sample) / scale_factor) + 0.5;
  1657. sample2= int(x);
  1658. if(sample2 > 127)
  1659. sample2 = 127;
  1660. if(sample2 < -128)
  1661. sample2 = -128;
  1662. fputc(sample2,f_phdata);
  1663. }
  1664. }
  1665. length = ftell(f_phdata);
  1666. while((length & 3) != 0)
  1667. {
  1668. // pad to a multiple of 4 bytes
  1669. fputc(0,f_phdata);
  1670. length++;
  1671. }
  1672. if(resample_wav != 0)
  1673. {
  1674. fclose(f);
  1675. remove(fname_temp);
  1676. }
  1677. return(displ | 0x800000); // set bit 23 to indicate a wave file rather than a spectrum
  1678. } // end of LoadWavefile
  1679. static int LoadEnvelope(FILE *f, const char *fname)
  1680. {//================================================
  1681. int displ;
  1682. char buf[128];
  1683. displ = ftell(f_phdata);
  1684. fseek(f,12,SEEK_SET);
  1685. if(fread(buf,128,1,f) == 0)
  1686. {
  1687. error("Failed to read envelope: %s",fname);
  1688. }
  1689. fwrite(buf,128,1,f_phdata);
  1690. if(n_envelopes < N_ENVELOPES)
  1691. {
  1692. strncpy0(envelope_paths[n_envelopes],fname,sizeof(envelope_paths[0]));
  1693. memcpy(envelope_dat[n_envelopes],buf,sizeof(envelope_dat[0]));
  1694. n_envelopes++;
  1695. }
  1696. return(displ);
  1697. } // end of LoadEnvelope
  1698. static int Hash8(const char *string)
  1699. //==================================
  1700. /* Generate a hash code from the specified string */
  1701. {
  1702. int c;
  1703. int chars=0;
  1704. int hash=0;
  1705. while((c = *string++) != 0)
  1706. {
  1707. c = tolower(c) - 'a';
  1708. hash = hash * 8 + c;
  1709. hash = (hash & 0x1ff) ^ (hash >> 8); /* exclusive or */
  1710. chars++;
  1711. }
  1712. return((hash+chars) & 0xff);
  1713. } // end of Hash8
  1714. static int LoadEnvelope2(FILE *f, const char *fname)
  1715. {//===================================================
  1716. int ix, ix2;
  1717. int n;
  1718. int x, y;
  1719. int displ;
  1720. int n_points;
  1721. double yy;
  1722. char line_buf[128];
  1723. float env_x[20];
  1724. float env_y[20];
  1725. int env_lin[20];
  1726. unsigned char env[ENV_LEN];
  1727. n_points = 0;
  1728. fgets(line_buf,sizeof(line_buf),f); // skip first line
  1729. while(!feof(f))
  1730. {
  1731. if(fgets(line_buf,sizeof(line_buf),f) == NULL)
  1732. break;
  1733. env_lin[n_points] = 0;
  1734. n = sscanf(line_buf,"%f %f %d",&env_x[n_points],&env_y[n_points],&env_lin[n_points]);
  1735. if(n >= 2)
  1736. {
  1737. env_x[n_points] *= (float)1.28; // convert range 0-100 to 0-128
  1738. n_points++;
  1739. }
  1740. }
  1741. env_x[n_points] = env_x[n_points-1];
  1742. env_y[n_points] = env_y[n_points-1];
  1743. ix = -1;
  1744. ix2 = 0;
  1745. for(x=0; x<ENV_LEN; x++)
  1746. {
  1747. if(x > env_x[ix+4])
  1748. ix++;
  1749. if(x >= env_x[ix2+1])
  1750. ix2++;
  1751. if(env_lin[ix2] > 0)
  1752. {
  1753. yy = env_y[ix2] + (env_y[ix2+1] - env_y[ix2]) * (float(x) - env_x[ix2]) / (env_x[ix2+1] - env_x[ix2]);
  1754. y = int(yy * 2.55);
  1755. }
  1756. else
  1757. if(n_points > 3)
  1758. y = (int)(polint(&env_x[ix],&env_y[ix],4,x) * 2.55); // convert to range 0-255
  1759. else
  1760. y = (int)(polint(&env_x[ix],&env_y[ix],3,x) * 2.55);
  1761. if(y < 0) y = 0;
  1762. if(y > 255) y = 255;
  1763. env[x] = y;
  1764. }
  1765. if(n_envelopes < N_ENVELOPES)
  1766. {
  1767. strncpy0(envelope_paths[n_envelopes],fname,sizeof(envelope_paths[0]));
  1768. memcpy(envelope_dat[n_envelopes],env,ENV_LEN);
  1769. n_envelopes++;
  1770. }
  1771. displ = ftell(f_phdata);
  1772. fwrite(env,1,128,f_phdata);
  1773. return(displ);
  1774. }
  1775. static int LoadDataFile(const char *path, int control)
  1776. {//===================================================
  1777. // load spectrum sequence or sample data from a file.
  1778. // return index into spect or sample data area. bit 23=1 if a sample
  1779. FILE *f;
  1780. int id;
  1781. int hash;
  1782. int addr = 0;
  1783. int type_code=' ';
  1784. REF_HASH_TAB *p, *p2;
  1785. char buf[sizeof(path_source)+120];
  1786. if(strcmp(path,"NULL")==0)
  1787. return(0);
  1788. if(strcmp(path,"DFT")==0)
  1789. return(1);
  1790. count_references++;
  1791. hash = Hash8(path);
  1792. p = ref_hash_tab[hash];
  1793. while(p != NULL)
  1794. {
  1795. if(strcmp(path,p->string)==0)
  1796. {
  1797. duplicate_references++;
  1798. addr = p->value; // already loaded this data
  1799. break;
  1800. }
  1801. p = (REF_HASH_TAB *)p->link;
  1802. }
  1803. if(addr == 0)
  1804. {
  1805. sprintf(buf,"%s%s",path_source,path);
  1806. if((f = fopen(buf,"rb")) == NULL)
  1807. {
  1808. sprintf(buf,"%s%s.wav",path_source,path);
  1809. if((f = fopen(buf,"rb")) == NULL)
  1810. {
  1811. error("Can't read file: %s",path);
  1812. return(0);
  1813. }
  1814. }
  1815. id = Read4Bytes(f);
  1816. rewind(f);
  1817. if(id == 0x43455053)
  1818. {
  1819. addr = LoadSpect(path, control);
  1820. type_code = 'S';
  1821. }
  1822. else
  1823. if(id == 0x46464952)
  1824. {
  1825. addr = LoadWavefile(f,path);
  1826. type_code = 'W';
  1827. }
  1828. else
  1829. if(id == 0x43544950)
  1830. {
  1831. addr = LoadEnvelope(f,path);
  1832. type_code = 'E';
  1833. }
  1834. else
  1835. if(id == 0x45564E45)
  1836. {
  1837. addr = LoadEnvelope2(f,path);
  1838. type_code = 'E';
  1839. }
  1840. else
  1841. {
  1842. error("File not SPEC or RIFF: %s",path);
  1843. addr = -1;
  1844. }
  1845. fclose(f);
  1846. if(addr > 0)
  1847. {
  1848. fprintf(f_phcontents,"%c 0x%.5x %s\n",type_code,addr & 0x7fffff,path);
  1849. }
  1850. }
  1851. // add this item to the hash table
  1852. if(addr > 0)
  1853. {
  1854. p = ref_hash_tab[hash];
  1855. p2 = (REF_HASH_TAB *)malloc(sizeof(REF_HASH_TAB)+strlen(path)+1);
  1856. p2->value = addr;
  1857. p2->ph_mnemonic = phoneme_out->mnemonic; // phoneme which uses this file
  1858. p2->ph_table = n_phoneme_tabs-1;
  1859. strcpy(p2->string,path);
  1860. p2->link = (char *)p;
  1861. ref_hash_tab[hash] = p2;
  1862. }
  1863. return(addr);
  1864. } // end of LoadDataFile
  1865. static int CompileToneSpec(void)
  1866. {//=============================
  1867. int pitch1=0;
  1868. int pitch2=0;
  1869. int pitch_env = 0;
  1870. int amp_env = 0;
  1871. pitch1 = NextItemBrackets(tNUMBER,2);
  1872. pitch2 = NextItemBrackets(tNUMBER,3);
  1873. if(item_terminator == ',')
  1874. {
  1875. NextItemBrackets(tSTRING,3);
  1876. pitch_env = LoadDataFile(item_string, 0);
  1877. }
  1878. if(item_terminator == ',')
  1879. {
  1880. NextItemBrackets(tSTRING,1);
  1881. amp_env = LoadDataFile(item_string, 0);
  1882. }
  1883. if(pitch1 < pitch2)
  1884. {
  1885. phoneme_out->start_type = pitch1;
  1886. phoneme_out->end_type = pitch2;
  1887. }
  1888. else
  1889. {
  1890. phoneme_out->start_type = pitch2;
  1891. phoneme_out->end_type = pitch1;
  1892. }
  1893. if(pitch_env != 0)
  1894. {
  1895. *prog_out++ = i_PITCHENV + ((pitch_env >> 16) & 0xf);
  1896. *prog_out++ = pitch_env;
  1897. }
  1898. if(amp_env != 0)
  1899. {
  1900. *prog_out++ = i_AMPENV + ((amp_env >> 16) & 0xf);
  1901. *prog_out++ = amp_env;
  1902. }
  1903. return(0);
  1904. } // end of CompileToneSpec
  1905. int CompileSound(int keyword, int isvowel)
  1906. {//=======================================
  1907. int addr;
  1908. int value = 0;
  1909. char path[N_ITEM_STRING];
  1910. static int sound_instns[] = {i_FMT, i_WAV, i_VWLSTART, i_VWLENDING, i_WAVADD};
  1911. NextItemBrackets(tSTRING,2);
  1912. strcpy(path, item_string);
  1913. if(item_terminator == ',')
  1914. {
  1915. if((keyword == kVOWELSTART) || (keyword == kVOWELENDING))
  1916. {
  1917. value = NextItemBrackets(tSIGNEDNUMBER,1);
  1918. if(value > 127)
  1919. {
  1920. value = 127;
  1921. error("Parameter > 127",NULL);
  1922. }
  1923. if(value < -128)
  1924. {
  1925. value = -128;
  1926. error("Parameter < -128",NULL);
  1927. }
  1928. }
  1929. else
  1930. {
  1931. value = NextItemBrackets(tNUMBER,1);
  1932. if(value > 255)
  1933. {
  1934. value = 255;
  1935. error("Parameter > 255",NULL);
  1936. }
  1937. }
  1938. }
  1939. addr = LoadDataFile(path, isvowel);
  1940. addr = addr / 4; // addr is words not bytes
  1941. *prog_out++ = sound_instns[keyword-kFMT] + ((value & 0xff) << 4) + ((addr >> 16) & 0xf);
  1942. *prog_out++ = addr & 0xffff;
  1943. return(0);
  1944. } // end of CompileSound
  1945. /*
  1946. Condition
  1947. bits 14,15 1
  1948. bit 13 1 = AND, 0 = OR
  1949. bit 12 spare
  1950. bit 8-11
  1951. =0-3 p,t,n,n2 data=phoneme code
  1952. =4-7 p,t,n,n2 data=(bits5-7: phtype, place, property, special) (bits0-4: data)
  1953. =8 data = stress bitmap
  1954. =9 special tests
  1955. */
  1956. int CompileIf(int elif)
  1957. {//====================
  1958. int key;
  1959. int finish = 0;
  1960. int word = 0;
  1961. int word2;
  1962. int data;
  1963. int bitmap;
  1964. int brackets;
  1965. int not_flag;
  1966. USHORT *prog_last_if = NULL;
  1967. then_count = 2;
  1968. after_if = 1;
  1969. while(!finish)
  1970. {
  1971. not_flag = 0;
  1972. word2 = 0;
  1973. if(prog_out >= prog_out_max)
  1974. {
  1975. error("Phoneme program too large", NULL);
  1976. return(0);
  1977. }
  1978. if((key = NextItem(tCONDITION)) < 0)
  1979. error("Expected a condition, not '%s'",item_string);
  1980. if((item_type == 0) && (key == k_NOT))
  1981. {
  1982. not_flag = 1;
  1983. if((key = NextItem(tCONDITION)) < 0)
  1984. error("Expected a condition, not '%s'",item_string);
  1985. }
  1986. if(item_type == tWHICH_PHONEME)
  1987. {
  1988. // prevPh(), thisPh(), nextPh(), next2Ph() etc
  1989. if(key >= 6)
  1990. {
  1991. // put the 'which' code in the next instruction
  1992. word2 = key;
  1993. key = 6;
  1994. }
  1995. key = key << 8;
  1996. data = NextItemBrackets(tPROPERTIES,0);
  1997. if(data >= 0)
  1998. {
  1999. word = key + data + 0x700;
  2000. }
  2001. else
  2002. {
  2003. data = LookupPhoneme(item_string,2);
  2004. word = key + data;
  2005. }
  2006. }
  2007. else
  2008. if(item_type == tTEST)
  2009. {
  2010. if(key == kTHISSTRESS)
  2011. {
  2012. bitmap = 0;
  2013. brackets = 2;
  2014. do {
  2015. data = NextItemBrackets(tNUMBER,brackets);
  2016. if(data > 7)
  2017. error("Expected list of stress levels",NULL);
  2018. bitmap |= (1 << data);
  2019. brackets = 3;
  2020. } while(item_terminator == ',');
  2021. word = i_StressLevel | bitmap;
  2022. }
  2023. else
  2024. {
  2025. word = key;
  2026. }
  2027. }
  2028. else
  2029. {
  2030. error("Unexpected keyword '%s'",item_string);
  2031. }
  2032. // output the word
  2033. prog_last_if = prog_out;
  2034. *prog_out++ = word | i_CONDITION;
  2035. if(word2 != 0)
  2036. *prog_out++ = word2;
  2037. if(not_flag)
  2038. *prog_out++ = i_NOT;
  2039. // expect AND, OR, THEN
  2040. switch(NextItem(tCONDITION))
  2041. {
  2042. case k_AND:
  2043. break;
  2044. case k_OR:
  2045. if(prog_last_if != NULL)
  2046. *prog_last_if |= i_OR;
  2047. break;
  2048. case k_THEN:
  2049. finish = 1;
  2050. break;
  2051. default:
  2052. error("Expected AND, OR, THEN",NULL);
  2053. break;
  2054. }
  2055. }
  2056. if(finish != 1)
  2057. {
  2058. }
  2059. if(elif == 0)
  2060. {
  2061. if_level++;
  2062. if_stack[if_level].p_else = NULL;
  2063. }
  2064. if_stack[if_level].returned = 0;
  2065. if_stack[if_level].p_then = prog_out;
  2066. *prog_out++ = i_JUMP_FALSE;
  2067. return(0);
  2068. } // end of CompileIf
  2069. void FillThen(int add)
  2070. {//===================
  2071. USHORT *p;
  2072. int offset;
  2073. p = if_stack[if_level].p_then;
  2074. if(p != NULL)
  2075. {
  2076. offset = prog_out - p + add;
  2077. if((then_count == 1) && (if_level == 1))
  2078. {
  2079. // The THEN part only contains one statement, we can remove the THEN jump
  2080. // and the interpreter will implicitly skip the statement.
  2081. while(p < prog_out)
  2082. {
  2083. p[0] = p[1];
  2084. p++;
  2085. }
  2086. prog_out--;
  2087. }
  2088. else
  2089. {
  2090. if(offset > MAX_JUMP)
  2091. {
  2092. error("IF block is too long",NULL);
  2093. }
  2094. *p = i_JUMP_FALSE + offset;
  2095. }
  2096. if_stack[if_level].p_then = NULL;
  2097. }
  2098. then_count = 0;
  2099. } // end of FillThen
  2100. int CompileElse(void)
  2101. {//==================
  2102. USHORT *ref;
  2103. USHORT *p;
  2104. if(if_level < 1)
  2105. {
  2106. error("ELSE not expected",NULL);
  2107. return(0);
  2108. }
  2109. if(if_stack[if_level].returned == 0)
  2110. {
  2111. FillThen(1);
  2112. }
  2113. else
  2114. {
  2115. FillThen(0);
  2116. }
  2117. if(if_stack[if_level].returned == 0)
  2118. {
  2119. ref = prog_out;
  2120. *prog_out++ = 0;
  2121. if((p = if_stack[if_level].p_else) != NULL)
  2122. {
  2123. *ref = ref - p; // backwards offset to the previous else
  2124. }
  2125. if_stack[if_level].p_else = ref;
  2126. }
  2127. return(0);
  2128. } // end of CompileElse
  2129. int CompileElif(void)
  2130. {//===================
  2131. if(if_level < 1)
  2132. {
  2133. error("ELIF not expected",NULL);
  2134. return(0);
  2135. }
  2136. CompileElse();
  2137. CompileIf(1);
  2138. return(0);
  2139. }
  2140. int CompileEndif(void)
  2141. {//===================
  2142. USHORT *p;
  2143. int chain;
  2144. int offset;
  2145. if(if_level < 1)
  2146. {
  2147. error("ENDIF not expected",NULL);
  2148. return(0);
  2149. }
  2150. FillThen(0);
  2151. if((p = if_stack[if_level].p_else) != NULL)
  2152. {
  2153. do
  2154. {
  2155. chain = *p; // a chain of previous else links
  2156. offset = prog_out - p;
  2157. if(offset > MAX_JUMP)
  2158. {
  2159. error("IF block is too long",NULL);
  2160. }
  2161. *p = i_JUMP + offset;
  2162. p -= chain;
  2163. } while (chain > 0);
  2164. }
  2165. if_level--;
  2166. return(0);
  2167. } // end of CompileEndif
  2168. static int CompileSwitch(int type)
  2169. {//===============================
  2170. // Type 0: EndSwitch
  2171. // 1: SwitchPrevVowelType
  2172. // 2: SwitchNextVowelType
  2173. if(type == 0)
  2174. {
  2175. // check the instructions in the Switch
  2176. return(0);
  2177. }
  2178. // count_VowelStart = 0;
  2179. // count_VowelEnding = 0;
  2180. if(type == 1)
  2181. *prog_out++ = i_SWITCH_PREVVOWEL+6;
  2182. if(type == 2)
  2183. *prog_out++ = i_SWITCH_NEXTVOWEL+6;
  2184. return(0);
  2185. } // end of CompileSwitch
  2186. static PHONEME_TAB_LIST *FindPhonemeTable(const char *string)
  2187. {//==========================================================
  2188. int ix;
  2189. for(ix=0; ix<n_phoneme_tabs; ix++)
  2190. {
  2191. if(strcmp(phoneme_tab_list2[ix].name, string) == 0)
  2192. {
  2193. return(&phoneme_tab_list2[ix]);
  2194. }
  2195. }
  2196. error("Unknown phoneme table: '%s'",string);
  2197. return(NULL);
  2198. } // end of FindPhonemeTable
  2199. static PHONEME_TAB *FindPhoneme(const char *string)
  2200. {//================================================
  2201. PHONEME_TAB_LIST *phtab = NULL;
  2202. int ix;
  2203. unsigned int mnem;
  2204. char *phname;
  2205. char buf[200];
  2206. // is this the name of a phoneme which is in scope
  2207. if((strlen(string) <= 4) && ((ix = LookupPhoneme(string,0)) != -1))
  2208. {
  2209. return(&phoneme_tab2[ix]);
  2210. }
  2211. // no, treat the name as phonemetable/phoneme
  2212. strcpy(buf,string);
  2213. if((phname = strchr(buf,'/')) != 0)
  2214. {
  2215. *phname++ = 0;
  2216. }
  2217. phtab = FindPhonemeTable(buf);
  2218. if(phtab == NULL)
  2219. {
  2220. return(NULL); // phoneme table not found
  2221. }
  2222. mnem = StringToWord(phname);
  2223. for(ix=1; ix<256; ix++)
  2224. {
  2225. if(mnem == phtab->phoneme_tab_ptr[ix].mnemonic)
  2226. {
  2227. return(&phtab->phoneme_tab_ptr[ix]);
  2228. }
  2229. }
  2230. error("Phoneme reference not found: '%s'",string);
  2231. return(NULL);
  2232. }
  2233. static void ImportPhoneme(void)
  2234. {//============================
  2235. unsigned int ph_mnem;
  2236. unsigned int ph_code;
  2237. PHONEME_TAB *ph;
  2238. NextItem(tSTRING);
  2239. if((ph = FindPhoneme(item_string)) == NULL)
  2240. return;
  2241. ph_mnem = phoneme_out->mnemonic;
  2242. ph_code = phoneme_out->code;
  2243. memcpy(phoneme_out,ph,sizeof(PHONEME_TAB));
  2244. phoneme_out->mnemonic = ph_mnem;
  2245. phoneme_out->code = ph_code;
  2246. if(phoneme_out->type != phVOWEL)
  2247. {
  2248. phoneme_out->end_type = 0; // voicingswitch, this must be set later to refer to a local phoneme
  2249. }
  2250. } // end of ImportPhoneme
  2251. static void CallPhoneme(void)
  2252. {//==========================
  2253. PHONEME_TAB *ph;
  2254. int ix;
  2255. int addr = 0;
  2256. NextItem(tSTRING);
  2257. // first look for a procedure name
  2258. for(ix=0; ix<n_procs; ix++)
  2259. {
  2260. if(strcmp(proc_names[ix],item_string) == 0)
  2261. {
  2262. addr = proc_addr[ix];
  2263. break;
  2264. }
  2265. }
  2266. if(ix == n_procs)
  2267. {
  2268. // procedure not found, try a phoneme name
  2269. if((ph = FindPhoneme(item_string)) == NULL)
  2270. return;
  2271. addr = ph->program;
  2272. if(phoneme_out->type == phINVALID)
  2273. {
  2274. // Phoneme type has not been set. Copy it from the called phoneme
  2275. phoneme_out->type = ph->type;
  2276. phoneme_flags = ph->phflags & ~phARTICULATION;
  2277. place_articulation = (ph->phflags & phARTICULATION) >> 16;
  2278. phoneme_out->start_type = ph->start_type;
  2279. phoneme_out->end_type = ph->end_type;
  2280. phoneme_out->std_length = ph->std_length;
  2281. phoneme_out->length_mod = ph->length_mod;
  2282. }
  2283. }
  2284. *prog_out++ = i_CALLPH + (addr >> 16);
  2285. *prog_out++ = addr;
  2286. } // end of CallPhoneme
  2287. static void DecThenCount()
  2288. {//=======================
  2289. if(then_count >0)
  2290. then_count--;
  2291. }
  2292. static void InstnPlusPhoneme(int instn)
  2293. {//====================================
  2294. int phcode;
  2295. DecThenCount();
  2296. phcode = NextItemBrackets(tPHONEMEMNEM,0);
  2297. *prog_out++ = instn + phcode;
  2298. }
  2299. int CompilePhoneme(int compile_phoneme)
  2300. {//====================================
  2301. int endphoneme = 0;
  2302. int keyword;
  2303. int value;
  2304. int phcode = 0;
  2305. int flags;
  2306. int ix;
  2307. int start;
  2308. int count;
  2309. int c;
  2310. char *p;
  2311. char number_buf[12];
  2312. char ipa_buf[N_ITEM_STRING+1];
  2313. PHONEME_TAB phoneme_out2;
  2314. PHONEME_PROG_LOG phoneme_prog_log;
  2315. prog_out = prog_buf;
  2316. prog_out_max = &prog_buf[MAX_PROG_BUF-1];
  2317. if_level = 0;
  2318. if_stack[0].returned = 0;
  2319. after_if = 0;
  2320. phoneme_flags = 0;
  2321. place_articulation = 0;
  2322. NextItem(tSTRING);
  2323. if(compile_phoneme)
  2324. {
  2325. phcode = LookupPhoneme(item_string,1); // declare phoneme if not already there
  2326. if(phcode == -1) return(0);
  2327. phoneme_out = &phoneme_tab2[phcode];
  2328. }
  2329. else
  2330. {
  2331. // declare a procedure
  2332. if(n_procs >= N_PROCS)
  2333. {
  2334. error("Too many procedures",NULL);
  2335. return(0);
  2336. }
  2337. strcpy(proc_names[n_procs], item_string);
  2338. phoneme_out = &phoneme_out2;
  2339. sprintf(number_buf,"%.3dP", n_procs);
  2340. phoneme_out->mnemonic = StringToWord(number_buf);
  2341. }
  2342. phoneme_out->code = phcode;
  2343. phoneme_out->program = 0;
  2344. phoneme_out->type = phINVALID;
  2345. phoneme_out->std_length = 0;
  2346. phoneme_out->start_type = 0;
  2347. phoneme_out->end_type = 0;
  2348. phoneme_out->length_mod = 0;
  2349. while(!endphoneme && !feof(f_in))
  2350. {
  2351. if((keyword = NextItem(tKEYWORD)) < 0)
  2352. {
  2353. if(keyword == -2)
  2354. {
  2355. error("Missing 'endphoneme' before end-of-file",NULL); // end of file
  2356. break;
  2357. }
  2358. error("Bad keyword in phoneme definition '%s'",item_string);
  2359. continue;
  2360. }
  2361. switch(item_type)
  2362. {
  2363. case tPHONEME_TYPE:
  2364. if(phoneme_out->type != phINVALID)
  2365. error("More than one phoneme type: %s",item_string);
  2366. phoneme_out->type = keyword;
  2367. break;
  2368. case tPLACE:
  2369. if(place_articulation > 0)
  2370. error("Place of articulation has already been given: %s",item_string);
  2371. place_articulation = keyword;
  2372. break;
  2373. case tPHONEME_FLAG:
  2374. phoneme_flags |= keyword;
  2375. break;
  2376. case tINSTRN1:
  2377. // instruction group 0, with 8 bit operands which set data in PHONEME_DATA
  2378. switch(keyword)
  2379. {
  2380. case i_CHANGE_PHONEME:
  2381. case i_APPEND_PHONEME:
  2382. case i_APPEND_IFNEXTVOWEL:
  2383. case i_INSERT_PHONEME:
  2384. case i_REPLACE_NEXT_PHONEME:
  2385. case i_VOICING_SWITCH:
  2386. case i_CHANGE_IF+0:
  2387. case i_CHANGE_IF+1:
  2388. case i_CHANGE_IF+2:
  2389. case i_CHANGE_IF+3:
  2390. InstnPlusPhoneme(keyword << 8);
  2391. break;
  2392. case i_PAUSE_BEFORE:
  2393. value = NextItemMax(255);
  2394. *prog_out++ = (i_PAUSE_BEFORE << 8) + value;
  2395. break;
  2396. case i_PAUSE_AFTER:
  2397. value = NextItemMax(255);
  2398. *prog_out++ = (i_PAUSE_AFTER << 8) + value;
  2399. break;
  2400. case i_SET_LENGTH:
  2401. value = NextItemMax(511);
  2402. if(after_if == 0)
  2403. {
  2404. phoneme_out->std_length = value/2;
  2405. }
  2406. else
  2407. {
  2408. *prog_out++ = (i_SET_LENGTH << 8) + value/2;
  2409. DecThenCount();
  2410. }
  2411. break;
  2412. case i_ADD_LENGTH:
  2413. value = NextItem(tSIGNEDNUMBER);
  2414. *prog_out++ = (i_ADD_LENGTH << 8) + value/2;
  2415. DecThenCount();
  2416. break;
  2417. case i_LENGTH_MOD:
  2418. value = NextItem(tNUMBER);
  2419. phoneme_out->length_mod = value;
  2420. break;
  2421. case i_IPA_NAME:
  2422. NextItem(tSTRING);
  2423. if(strcmp(item_string,"NULL")==0)
  2424. strcpy(item_string," ");
  2425. // copy the string, recognize characters in the form U+9999
  2426. flags = 0;
  2427. count = 0;
  2428. ix = 1;
  2429. for(p=item_string; *p != 0;)
  2430. {
  2431. p += utf8_in(&c, p);
  2432. if((c == '|') && (count > 0))
  2433. {
  2434. // '|' means don't allow a tie or joiner before this letter
  2435. flags |= (1 << (count -1));
  2436. }
  2437. else
  2438. if((c=='U') && (p[0]=='+'))
  2439. {
  2440. int j;
  2441. // U+9999
  2442. p++;
  2443. memcpy(number_buf,p,4); // U+ should be followed by 4 hex digits
  2444. number_buf[4] = 0;
  2445. c = '#';
  2446. sscanf(number_buf,"%x",&c);
  2447. // move past the 4 hexdecimal digits
  2448. for(j=0; j<4; j++)
  2449. {
  2450. if(!isalnum(*p))
  2451. break;
  2452. p++;
  2453. }
  2454. ix += utf8_out(c, &ipa_buf[ix]);
  2455. count++;
  2456. }
  2457. else
  2458. {
  2459. ix += utf8_out(c, &ipa_buf[ix]);
  2460. count++;
  2461. }
  2462. }
  2463. ipa_buf[0] = flags;
  2464. ipa_buf[ix] = 0;
  2465. start = 1;
  2466. if(flags != 0)
  2467. start = 0; // only include the flags byte if bits are set
  2468. value = strlen(&ipa_buf[start]); // number of UTF-8 bytes
  2469. *prog_out++ = (i_IPA_NAME << 8) + value;
  2470. for(ix=0; ix < value; ix += 2)
  2471. {
  2472. *prog_out++ = (ipa_buf[ix+start] << 8) + (ipa_buf[ix+start+1] & 0xff);
  2473. }
  2474. break;
  2475. }
  2476. break;
  2477. case tSTATEMENT:
  2478. switch(keyword)
  2479. {
  2480. case kIMPORT_PH:
  2481. ImportPhoneme();
  2482. phoneme_flags = phoneme_out->phflags;
  2483. break;
  2484. case kSTARTTYPE:
  2485. phcode = NextItem(tPHONEMEMNEM);
  2486. if(phcode == -1)
  2487. phcode = LookupPhoneme(item_string,1);
  2488. phoneme_out->start_type = phcode;
  2489. break;
  2490. case kENDTYPE:
  2491. phcode = NextItem(tPHONEMEMNEM);
  2492. if(phcode == -1)
  2493. phcode = LookupPhoneme(item_string,1);
  2494. if(phoneme_out->type == phVOWEL)
  2495. {
  2496. phoneme_out->end_type = phcode;
  2497. }
  2498. else
  2499. {
  2500. if(phcode != phoneme_out->start_type)
  2501. {
  2502. error("endtype must equal starttype for consonants",NULL);
  2503. }
  2504. }
  2505. break;
  2506. case kVOICINGSWITCH:
  2507. phcode = NextItem(tPHONEMEMNEM);
  2508. if(phcode == -1)
  2509. phcode = LookupPhoneme(item_string,1);
  2510. phoneme_out->end_type = phcode; // use end_type field for consonants as voicing_switch
  2511. break;
  2512. case kSTRESSTYPE:
  2513. value = NextItem(tNUMBER);
  2514. phoneme_out->std_length = value;
  2515. if(prog_out > prog_buf)
  2516. {
  2517. error("stress phonemes can't contain program instructions",NULL);
  2518. prog_out = prog_buf;
  2519. }
  2520. break;
  2521. case kIF:
  2522. endphoneme = CompileIf(0);
  2523. break;
  2524. case kELSE:
  2525. endphoneme = CompileElse();
  2526. break;
  2527. case kELIF:
  2528. endphoneme = CompileElif();
  2529. break;
  2530. case kENDIF:
  2531. endphoneme = CompileEndif();
  2532. break;
  2533. case kENDSWITCH:
  2534. break;
  2535. case kSWITCH_PREVVOWEL:
  2536. endphoneme = CompileSwitch(1);
  2537. break;
  2538. case kSWITCH_NEXTVOWEL:
  2539. endphoneme = CompileSwitch(2);
  2540. break;
  2541. case kCALLPH:
  2542. CallPhoneme();
  2543. break;
  2544. case kFMT:
  2545. if_stack[if_level].returned = 1;
  2546. DecThenCount();
  2547. if(phoneme_out->type == phVOWEL)
  2548. endphoneme = CompileSound(keyword,1);
  2549. else
  2550. endphoneme = CompileSound(keyword,0);
  2551. break;
  2552. case kWAV:
  2553. if_stack[if_level].returned = 1;
  2554. case kVOWELSTART:
  2555. case kVOWELENDING:
  2556. case kANDWAV:
  2557. DecThenCount();
  2558. endphoneme = CompileSound(keyword,0);
  2559. break;
  2560. case kVOWELIN:
  2561. DecThenCount();
  2562. endphoneme = CompileVowelTransition(1);
  2563. break;
  2564. case kVOWELOUT:
  2565. DecThenCount();
  2566. endphoneme = CompileVowelTransition(2);
  2567. break;
  2568. case kTONESPEC:
  2569. endphoneme = CompileToneSpec();
  2570. break;
  2571. case kCONTINUE:
  2572. *prog_out++ = i_CONTINUE;
  2573. DecThenCount();
  2574. break;
  2575. case kRETURN:
  2576. *prog_out++ = i_RETURN;
  2577. break;
  2578. case kINCLUDE:
  2579. case kPHONEMENUMBER:
  2580. case kPHONEMETABLE:
  2581. error("Missing 'endphoneme' before '%s'",item_string); // drop through to endphoneme
  2582. case kENDPHONEME:
  2583. case kENDPROCEDURE:
  2584. endphoneme = 1;
  2585. if(if_level > 0)
  2586. {
  2587. error("Missing ENDIF",NULL);
  2588. }
  2589. if((prog_out > prog_buf) && (if_stack[0].returned == 0))
  2590. {
  2591. *prog_out++ = i_RETURN;
  2592. }
  2593. break;
  2594. }
  2595. break;
  2596. }
  2597. }
  2598. if(endphoneme != 1)
  2599. {
  2600. error("'endphoneme' not expected here",NULL);
  2601. }
  2602. if(compile_phoneme)
  2603. {
  2604. if(phoneme_out->type == phINVALID)
  2605. {
  2606. error("Phoneme type is missing",NULL);
  2607. phoneme_out->type = 0;
  2608. }
  2609. phoneme_out->phflags = place_articulation << 16;
  2610. phoneme_out->phflags |= phoneme_flags;
  2611. if(phoneme_out->phflags & phVOICED)
  2612. {
  2613. if(phoneme_out->type == phSTOP)
  2614. phoneme_out->type = phVSTOP;
  2615. else
  2616. if(phoneme_out->type == phFRICATIVE)
  2617. phoneme_out->type = phVFRICATIVE;
  2618. }
  2619. if(phoneme_out->std_length == 0)
  2620. {
  2621. if(phoneme_out->type == phVOWEL)
  2622. phoneme_out->std_length = 180/2; // default length for vowel
  2623. }
  2624. phoneme_out->phflags |= phLOCAL; //declared in this phoneme table
  2625. if(phoneme_out->type == phDELETED)
  2626. {
  2627. phoneme_out->mnemonic = 0x01; // will not be recognised
  2628. }
  2629. }
  2630. DecompilePhoneme(f_errors, phoneme_out, compile_phoneme);
  2631. if(prog_out > prog_buf)
  2632. {
  2633. // write out the program for this phoneme
  2634. fflush(f_phindex);
  2635. phoneme_out->program = ftell(f_phindex) / sizeof(USHORT);
  2636. if(f_prog_log != NULL)
  2637. {
  2638. phoneme_prog_log.addr = phoneme_out->program;
  2639. phoneme_prog_log.length = prog_out - prog_buf;
  2640. fwrite(&phoneme_prog_log, 1, sizeof(phoneme_prog_log), f_prog_log);
  2641. }
  2642. if(compile_phoneme == 0)
  2643. {
  2644. proc_addr[n_procs++] = ftell(f_phindex) / sizeof(USHORT);
  2645. }
  2646. fwrite(prog_buf, sizeof(USHORT), prog_out - prog_buf, f_phindex);
  2647. }
  2648. return(0);
  2649. } // end of CompilePhoneme
  2650. static void WritePhonemeTables()
  2651. {//=============================
  2652. int ix;
  2653. int j;
  2654. int n;
  2655. int value;
  2656. int count;
  2657. PHONEME_TAB *p;
  2658. value = n_phoneme_tabs;
  2659. fputc(value,f_phtab);
  2660. fputc(0,f_phtab);
  2661. fputc(0,f_phtab);
  2662. fputc(0,f_phtab);
  2663. for(ix=0; ix<n_phoneme_tabs; ix++)
  2664. {
  2665. p = phoneme_tab_list2[ix].phoneme_tab_ptr;
  2666. n = n_phcodes_list[ix];
  2667. p[n].mnemonic = 0; // terminate the phoneme table
  2668. // count number of locally declared phonemes
  2669. count=0;
  2670. for(j=0; j<n; j++)
  2671. {
  2672. if(ix==0)
  2673. p[j].phflags |= phLOCAL; // write all phonemes in the base phoneme table
  2674. if(p[j].phflags & phLOCAL)
  2675. count++;
  2676. }
  2677. phoneme_tab_list2[ix].n_phonemes = count+1;
  2678. fputc(count+1,f_phtab);
  2679. fputc(phoneme_tab_list2[ix].includes,f_phtab);
  2680. fputc(0,f_phtab);
  2681. fputc(0,f_phtab);
  2682. Write4Bytes(f_phtab, phoneme_tab_list2[ix].equivalence_tables); // byte index into phondata for equivalence tables
  2683. fwrite(phoneme_tab_list2[ix].name,1,N_PHONEME_TAB_NAME,f_phtab);
  2684. for(j=0; j<n; j++)
  2685. {
  2686. if(p[j].phflags & phLOCAL)
  2687. {
  2688. // this bit is set temporarily to incidate a local phoneme, declared in
  2689. // in the current phoneme file
  2690. p[j].phflags &= ~phLOCAL;
  2691. fwrite(&p[j],sizeof(PHONEME_TAB),1,f_phtab);
  2692. }
  2693. }
  2694. fwrite(&p[n],sizeof(PHONEME_TAB),1,f_phtab); // include the extra list-terminator phoneme entry
  2695. free(p);
  2696. }
  2697. } // end of WritePhonemeTables
  2698. static void EndPhonemeTable()
  2699. {//==========================
  2700. int ix;
  2701. int *pw;
  2702. int length;
  2703. if(n_phoneme_tabs == 0)
  2704. return;
  2705. fprintf(f_errors,"\n");
  2706. // check that all referenced phonemes have been declared
  2707. for(ix=0; ix<n_phcodes; ix++)
  2708. {
  2709. if(phoneme_tab2[ix].type == phINVALID)
  2710. {
  2711. fprintf(f_errors,"%3d: Phoneme [%s] not declared, referenced at line %d\n",linenum,
  2712. WordToString(phoneme_tab2[ix].mnemonic),int(phoneme_tab2[ix].program));
  2713. error_count++;
  2714. phoneme_tab2[ix].type = 0; // prevent the error message repeating
  2715. }
  2716. }
  2717. n_phcodes_list[n_phoneme_tabs-1] = n_phcodes;
  2718. if((length = p_equivalence - equivalence_buf) > 0)
  2719. {
  2720. // terminate the list of phoneme equivalence tables
  2721. pw = (int *)p_equivalence;
  2722. pw[0] = 0;
  2723. // write the equivalence data into phondata, and remember it's address
  2724. ix = ftell(f_phdata);
  2725. fprintf(f_phcontents,"Q 0x%.5x %s\n", ix, phoneme_tab_list2[n_phoneme_tabs-1].name);
  2726. phoneme_tab_list2[n_phoneme_tabs-1].equivalence_tables = ix;
  2727. fwrite(equivalence_buf, length+4, 1, f_phdata);
  2728. }
  2729. }
  2730. static void StartPhonemeTable(const char *name)
  2731. {//============================================
  2732. int ix;
  2733. int j;
  2734. PHONEME_TAB *p;
  2735. fprintf(f_errors,"______________________________\nPhoneme Table: '%s'\n",name);
  2736. if(n_phoneme_tabs >= N_PHONEME_TABS-1)
  2737. {
  2738. Error("Too many phonemetables");
  2739. return;
  2740. }
  2741. p = (PHONEME_TAB *)calloc(sizeof(PHONEME_TAB),N_PHONEME_TAB);
  2742. if(p == NULL)
  2743. {
  2744. Error("Out of memory");
  2745. return;
  2746. }
  2747. if(gui_flag)
  2748. progress->Update(n_phoneme_tabs);
  2749. memset(&phoneme_tab_list2[n_phoneme_tabs], 0, sizeof(PHONEME_TAB_LIST));
  2750. phoneme_tab_list2[n_phoneme_tabs].phoneme_tab_ptr = phoneme_tab2 = p;
  2751. strncpy0(phoneme_tab_list2[n_phoneme_tabs].name, name, N_PHONEME_TAB_NAME);
  2752. n_phcodes = 1;
  2753. phoneme_tab_list2[n_phoneme_tabs].includes = 0;
  2754. p_equivalence = equivalence_buf;
  2755. if(n_phoneme_tabs > 0)
  2756. {
  2757. NextItem(tSTRING); // name of base phoneme table
  2758. for(ix=0; ix<n_phoneme_tabs; ix++)
  2759. {
  2760. if(strcmp(item_string,phoneme_tab_list2[ix].name)==0)
  2761. {
  2762. phoneme_tab_list2[n_phoneme_tabs].includes = ix+1;
  2763. // initialise the new phoneme table with the contents of this one
  2764. memcpy(phoneme_tab2,phoneme_tab_list2[ix].phoneme_tab_ptr,sizeof(PHONEME_TAB)*N_PHONEME_TAB);
  2765. n_phcodes = n_phcodes_list[ix];
  2766. // clear "local phoneme" bit"
  2767. for(j=0; j<n_phcodes; j++)
  2768. phoneme_tab2[j].phflags &= ~phLOCAL;
  2769. break;
  2770. }
  2771. }
  2772. if(ix == n_phoneme_tabs)
  2773. {
  2774. error("Can't find base phonemetable '%s'",item_string);
  2775. }
  2776. }
  2777. else
  2778. {
  2779. ReservePhCodes();
  2780. }
  2781. n_phoneme_tabs++;
  2782. } // end of StartPhonemeTable
  2783. static void CompileEquivalents()
  2784. {//=============================
  2785. // a list of phonemes in another language and the equivalent phoneme strings in this language
  2786. int ix;
  2787. int n_names;
  2788. int n_bytes;
  2789. int foreign_phoneme;
  2790. int foreign_error = 0;
  2791. int remove_stress = 0;
  2792. char *p_start;
  2793. char *p;
  2794. int foreign_table;
  2795. char foreign_table_name[40];
  2796. char line_buf[80];
  2797. char names[6][80];
  2798. char phcode[7];
  2799. char save_voice_name[80];
  2800. NextItem(tSTRING);
  2801. strcpy(foreign_table_name, item_string);
  2802. strcpy(save_voice_name,voice_name2);
  2803. if((foreign_table = SelectPhonemeTableName(foreign_table_name)) < 0)
  2804. {
  2805. if(strcmp(foreign_table_name, "NULL") != 0)
  2806. {
  2807. error("Unknown phoneme table '%s'", foreign_table_name);
  2808. }
  2809. foreign_error = 1;
  2810. foreign_phoneme = 0;
  2811. }
  2812. p_start = p_equivalence;
  2813. p_equivalence += 8;
  2814. p_start[0] = foreign_table;
  2815. linenum--;
  2816. while(!feof(f_in))
  2817. {
  2818. linenum++;
  2819. if(fgets(line_buf, sizeof(line_buf), f_in) == NULL)
  2820. break;
  2821. if((p = strstr(line_buf,"//")) != NULL)
  2822. *p = 0;
  2823. for(ix=0; ix<6; ix++)
  2824. names[ix][0] = 0;
  2825. n_names = sscanf(line_buf,"%s %s %s %s %s %s",names[0],names[1],names[2],names[3],names[4],names[5]);
  2826. if(n_names < 1)
  2827. continue;
  2828. if(strcmp(names[0],"endphoneme") == 0)
  2829. break;
  2830. if(foreign_error)
  2831. continue;
  2832. if(strcmp(names[0],"remove_stress") == 0)
  2833. {
  2834. remove_stress = 1;
  2835. continue;
  2836. }
  2837. if(p_equivalence > &equivalence_buf[sizeof(equivalence_buf) - 16])
  2838. {
  2839. error("'equivalents' tables are too large",NULL);
  2840. break;
  2841. }
  2842. if(foreign_error == 0)
  2843. {
  2844. phcode[0] = foreign_phoneme = LookupPhonemeString(names[0]);
  2845. if(foreign_phoneme == 0)
  2846. {
  2847. sprintf(line_buf,"%s/%s", foreign_table_name, names[0]);
  2848. error("Unknown phoneme '%s'", line_buf);
  2849. }
  2850. }
  2851. for(ix=1; ix<n_names; ix++)
  2852. {
  2853. phcode[ix] = LookupPhoneme(names[ix], 1);
  2854. }
  2855. // only write a translation if it has an effect
  2856. if((n_names > 2) || (phcode[0] != phcode[1]))
  2857. {
  2858. // write: foreign phoneme number, then a string of local phoneme numbers
  2859. memcpy(p_equivalence, phcode, n_names);
  2860. p_equivalence += n_names;
  2861. *p_equivalence++ = 0;
  2862. }
  2863. }
  2864. *p_equivalence++ = 0;
  2865. p_equivalence = (char *)((long int)(p_equivalence + 3) & ~0x3); // align to word boundary
  2866. n_bytes = p_equivalence - p_start;
  2867. p_start[1] = remove_stress;
  2868. n_bytes = n_bytes / 4;
  2869. p_start[2] = n_bytes >> 8; // index of next table
  2870. p_start[3] = n_bytes;
  2871. if(gui_flag != 0)
  2872. {
  2873. LoadVoice(voice_name2,0); // reset the original phoneme table
  2874. LoadVoiceVariant(save_voice_name,0);
  2875. }
  2876. } // end of CompileEquivalents
  2877. static void CompilePhonemeFiles()
  2878. {//==============================
  2879. int item;
  2880. FILE *f;
  2881. char buf[sizeof(path_source)+120];
  2882. linenum = 1;
  2883. count_references = 0;
  2884. duplicate_references = 0;
  2885. count_frames = 0;
  2886. n_procs = 0;
  2887. for(;;)
  2888. {
  2889. if(feof(f_in))
  2890. {
  2891. // end of file, go back to previous from, from which this was included
  2892. if(stack_ix == 0)
  2893. break; // end of top level, finished
  2894. fclose(f_in);
  2895. f_in = stack[--stack_ix].file;
  2896. strcpy(current_fname,stack[stack_ix].fname);
  2897. linenum = stack[stack_ix].linenum;
  2898. fprintf(f_errors,"\n\n");
  2899. }
  2900. item = NextItem(tKEYWORD);
  2901. switch(item)
  2902. {
  2903. case kUTF8_BOM:
  2904. break; // ignore bytes 0xef 0xbb 0xbf
  2905. case kINCLUDE:
  2906. NextItem(tSTRING);
  2907. sprintf(buf,"%s%s",path_source,item_string);
  2908. if((stack_ix < N_STACK) && (f = fopen_log(f_errors,buf,"rb")) != NULL)
  2909. {
  2910. fprintf(f_errors,"include %s\n",item_string);
  2911. stack[stack_ix].linenum = linenum;
  2912. strcpy(stack[stack_ix].fname,current_fname);
  2913. stack[stack_ix++].file = f_in;
  2914. f_in = f;
  2915. strncpy0(current_fname,item_string,sizeof(current_fname));
  2916. linenum = 1;
  2917. }
  2918. break;
  2919. case kPHONEMETABLE:
  2920. EndPhonemeTable();
  2921. NextItem(tSTRING); // name of the new phoneme table
  2922. StartPhonemeTable(item_string);
  2923. break;
  2924. case kPHONEMESTART:
  2925. if(n_phoneme_tabs == 0)
  2926. {
  2927. Error("phonemetable is missing");
  2928. return;
  2929. }
  2930. CompilePhoneme(1);
  2931. break;
  2932. case kPROCEDURE:
  2933. CompilePhoneme(0);
  2934. break;
  2935. case kEQUIVALENTS:
  2936. CompileEquivalents();
  2937. break;
  2938. default:
  2939. if(!feof(f_in))
  2940. Error("Keyword 'phoneme' expected");
  2941. break;
  2942. }
  2943. }
  2944. phoneme_tab2[n_phcodes+1].mnemonic = 0; // terminator
  2945. } // end of CompilePhonemeFiles
  2946. static void CompilePhonemeData2(const char *source)
  2947. {//================================================
  2948. char fname[sizeof(path_source)+40];
  2949. wxString report;
  2950. wxString report_dict;
  2951. #ifdef MAKE_ENVELOPES
  2952. make_envs();
  2953. #endif
  2954. wxLogStatus(_T("Compiling phoneme data: ")+wxString(path_source,wxConvLocal));
  2955. n_envelopes = 0;
  2956. error_count = 0;
  2957. resample_count = 0;
  2958. memset(markers_used,0,sizeof(markers_used));
  2959. f_errors = stderr;
  2960. if(!wxDirExists(path_phsource))
  2961. {
  2962. if(gui_flag)
  2963. {
  2964. wxString dirname = wxDirSelector(_T("Phoneme source directory"),path_phsource);
  2965. if(!dirname.IsEmpty())
  2966. {
  2967. path_phsource = dirname;
  2968. strncpy0(path_source,path_phsource.mb_str(wxConvLocal),sizeof(path_source)-1);
  2969. strcat(path_source,"/");
  2970. }
  2971. }
  2972. else
  2973. {
  2974. fprintf(stderr,"Can't find phoneme source directory: %s\n",path_source);
  2975. }
  2976. }
  2977. strncpy0(current_fname,source,sizeof(current_fname));
  2978. strncpy0(fname,path_phfile.mb_str(wxConvLocal),sizeof(fname));
  2979. f_in = fopen_log(f_errors,fname,"rb");
  2980. if(f_in == NULL)
  2981. {
  2982. if(gui_flag)
  2983. {
  2984. wxString phfile = wxFileSelector(_T("Master phonemes file"),path_phsource,
  2985. _T(""),_T(""),_T("*"),wxOPEN);
  2986. if(!phfile.IsEmpty())
  2987. {
  2988. path_phfile = phfile;
  2989. }
  2990. }
  2991. strncpy0(fname,path_phfile.mb_str(wxConvLocal),sizeof(fname));
  2992. f_in = fopen_log(f_errors,fname,"rb");
  2993. if(f_in == NULL)
  2994. {
  2995. wxLogError(_T("Can't read master phonemes file:\n") + wxString(fname,wxConvLocal));
  2996. return;
  2997. }
  2998. }
  2999. progress_max = 0;
  3000. while(fgets(fname,sizeof(fname),f_in) != NULL)
  3001. {
  3002. // count the number of phoneme tables declared in the master phonemes file
  3003. if(memcmp(fname,"phonemetable",12)==0)
  3004. progress_max++;
  3005. }
  3006. rewind(f_in);
  3007. sprintf(fname,"%s%s",path_source,"error_log");
  3008. if((f_errors = fopen_log(f_errors,fname,"w")) == NULL)
  3009. f_errors = stderr;
  3010. sprintf(fname,"%s%s",path_source,"compile_report");
  3011. f_report = fopen_log(f_errors, fname,"w");
  3012. sprintf(fname,"%s/%s",path_home,"phondata-manifest");
  3013. if((f_phcontents = fopen_log(f_phcontents,fname,"w")) == NULL)
  3014. f_phcontents = stderr;
  3015. fprintf (f_phcontents,
  3016. "# This file lists the type of data that has been compiled into the\n"
  3017. "# phondata file\n"
  3018. "#\n"
  3019. "# The first character of a line indicates the type of data:\n"
  3020. "# S - A SPECT_SEQ structure\n"
  3021. "# W - A wavefile segment\n"
  3022. "# E - An envelope\n"
  3023. "# Q - Phoneme equivalence tables\n"
  3024. "#\n"
  3025. "# Address is the displacement within phondata of this item\n"
  3026. "#\n"
  3027. "# Address Data file\n"
  3028. "# ------- ---------\n");
  3029. sprintf(fname,"%s/%s",path_home,"phondata");
  3030. f_phdata = fopen_log(f_errors,fname,"wb");
  3031. sprintf(fname,"%s/%s",path_home,"phonindex");
  3032. f_phindex = fopen_log(f_errors,fname,"wb");
  3033. sprintf(fname,"%s/%s",path_home,"phontab");
  3034. f_phtab = fopen_log(f_errors,fname,"wb");
  3035. if(f_phdata==NULL || f_phindex==NULL || f_phtab==NULL)
  3036. {
  3037. return;
  3038. }
  3039. sprintf(fname,"%scompile_prog_log",path_source);
  3040. f_prog_log = fopen_log(f_errors,fname,"wb");
  3041. if(gui_flag)
  3042. {
  3043. progress = new wxProgressDialog(_T("Compiling"),_T(""),progress_max);
  3044. }
  3045. else
  3046. {
  3047. fprintf(stderr,"Compiling phoneme data: %s\n",path_source);
  3048. }
  3049. // write a word so that further data doesn't start at displ=0
  3050. Write4Bytes(f_phdata,version_phdata);
  3051. Write4Bytes(f_phdata,samplerate_native);
  3052. Write4Bytes(f_phindex,version_phdata);
  3053. memset(ref_hash_tab,0,sizeof(ref_hash_tab));
  3054. n_phoneme_tabs = 0;
  3055. stack_ix = 0;
  3056. StartPhonemeTable("base");
  3057. CompilePhonemeFiles();
  3058. EndPhonemeTable();
  3059. WritePhonemeTables();
  3060. fprintf(f_errors,"\nRefs %d, Reused %d\n",count_references,duplicate_references);
  3061. fclose(f_in);
  3062. fclose(f_phdata);
  3063. if(f_prog_log != NULL)
  3064. fclose(f_prog_log);
  3065. fclose(f_phindex);
  3066. fclose(f_phtab);
  3067. fclose(f_phcontents);
  3068. LoadPhData(NULL);
  3069. if(gui_flag != 0)
  3070. LoadVoice(voice_name2,0);
  3071. CompileReport();
  3072. report_dict = CompileAllDictionaries();
  3073. #ifdef MAKE_ENVELOPES
  3074. DrawEnvelopes();
  3075. #endif
  3076. if(gui_flag)
  3077. {
  3078. delete progress;
  3079. }
  3080. if(resample_count > 0)
  3081. {
  3082. fprintf(f_errors, "\n%d WAV files resampled to %d Hz\n", resample_count, samplerate_native);
  3083. report.Printf(_T("Compiled phonemes: %d errors, %d files resampled to %d Hz. "),error_count, resample_count, samplerate_native);
  3084. }
  3085. else
  3086. {
  3087. report.Printf(_T("Compiled phonemes: %d errors."),error_count);
  3088. }
  3089. if(f_errors != stderr)
  3090. fclose(f_errors);
  3091. if(error_count > 0)
  3092. {
  3093. report += _T(" See file: '")+wxString(path_source,wxConvLocal)+_T("phsource/error_log'.");
  3094. wxLogError(report);
  3095. }
  3096. wxLogStatus(report + report_dict);
  3097. if(gui_flag == 0)
  3098. {
  3099. strncpy0(fname,(report+report_dict).mb_str(wxConvLocal),sizeof(fname));
  3100. fprintf(stderr,"%s\n",fname);
  3101. }
  3102. ReadPhondataManifest();
  3103. } // end of CompilePhonemeData
  3104. void CompileMbrola()
  3105. {//=================
  3106. char *p;
  3107. FILE *f_in;
  3108. FILE *f_out;
  3109. int percent;
  3110. int n;
  3111. int *pw;
  3112. int *pw_end;
  3113. int count = 0;
  3114. int control;
  3115. char phoneme[40];
  3116. char phoneme2[40];
  3117. char name1[40];
  3118. char name2[40];
  3119. char mbrola_voice[40];
  3120. char buf[sizeof(path_home)+30];
  3121. int mbrola_ctrl = 20; // volume in 1/16 ths
  3122. MBROLA_TAB data[N_PHONEME_TAB];
  3123. wxString filepath = wxFileSelector(_T("Read Mbrola phonemes file"),path_phsource+_T("/mbrola"),_T(""),_T(""),_T("*"),wxOPEN);
  3124. strcpy(buf,filepath.mb_str(wxConvLocal));
  3125. if((f_in = fopen(buf,"r")) == NULL)
  3126. {
  3127. wxLogError(_T("Can't read: ")+filepath);
  3128. return;
  3129. }
  3130. while(fgets(buf,sizeof(phoneme),f_in) != NULL)
  3131. {
  3132. buf[sizeof(phoneme)-1] = 0;
  3133. if((p = strstr(buf,"//")) != NULL)
  3134. *p = 0; // truncate line at comment
  3135. if(memcmp(buf,"volume",6)==0)
  3136. {
  3137. mbrola_ctrl = atoi(&buf[6]);
  3138. continue;
  3139. }
  3140. n = sscanf(buf,"%d %s %s %d %s %s",&control,phoneme,phoneme2,&percent,name1,name2);
  3141. if(n >= 5)
  3142. {
  3143. data[count].name = StringToWord(phoneme);
  3144. if(strcmp(phoneme2,"NULL")==0)
  3145. data[count].next_phoneme = 0;
  3146. else
  3147. if(strcmp(phoneme2,"VWL")==0)
  3148. data[count].next_phoneme = 2;
  3149. else
  3150. data[count].next_phoneme = StringToWord(phoneme2);
  3151. data[count].mbr_name = 0;
  3152. data[count].mbr_name2 = 0;
  3153. data[count].percent = percent;
  3154. data[count].control = control;
  3155. if(strcmp(name1,"NULL")!=0)
  3156. data[count].mbr_name = StringToWord(name1);
  3157. if(n == 6)
  3158. data[count].mbr_name2 = StringToWord(name2);
  3159. count++;
  3160. }
  3161. }
  3162. fclose(f_in);
  3163. wxFileName filename = wxFileName(filepath);
  3164. strcpy(mbrola_voice,filename.GetName().mb_str(wxConvLocal));
  3165. sprintf(buf,"%s/mbrola_ph/%s_phtrans",path_home,mbrola_voice);
  3166. if((f_out = fopen(buf,"wb")) == NULL)
  3167. {
  3168. wxLogError(_T("Can't write to: ")+wxString(buf,wxConvLocal));
  3169. return;
  3170. }
  3171. data[count].name = 0; // list terminator
  3172. Write4Bytes(f_out, mbrola_ctrl);
  3173. pw_end = (int *)(&data[count+1]);
  3174. for(pw = (int *)data; pw < pw_end; pw++)
  3175. {
  3176. Write4Bytes(f_out, *pw);
  3177. }
  3178. fclose(f_out);
  3179. wxLogStatus(_T("Mbrola translation file: %d phonemes"),count);
  3180. } // end of CompileMbrola
  3181. static const char *preset_tune_names[] = {
  3182. "s1", "c1", "q1", "e1", NULL};
  3183. static const TUNE default_tune = {
  3184. {0,0,0,0,0,0,0,0,0,0,0,0},
  3185. {0,0,0,0},
  3186. {0, 40, 24, 8, 0, 0, 0, 0},
  3187. 46, 57, PITCHfall, 16, 0, 0,
  3188. 255, 78, 50, 255,
  3189. 3, 5,
  3190. {-7,-7,-7}, {-7,-7,-7},
  3191. PITCHfall, 64, 8,
  3192. PITCHfall, 70, 18, 24, 12,
  3193. PITCHfall, 70, 18, 24, 12, 0,
  3194. {0,0,0,0,0,0,0,0}, 0
  3195. };
  3196. #define N_TUNE_NAMES 100
  3197. MNEM_TAB envelope_names[] = {
  3198. {"fall", 0},
  3199. {"rise", 2},
  3200. {"fall-rise", 4},
  3201. {"fall-rise2", 6},
  3202. {"rise-fall", 8},
  3203. {"fall-rise3",10},
  3204. {"fall-rise4",12},
  3205. {"fall2", 14},
  3206. {"rise2", 16},
  3207. {"rise-fall-rise", 18},
  3208. {NULL, -1} };
  3209. // env_fallrise3, env_fallrise3,
  3210. // env_fallrise4, env_fallrise4,
  3211. // env_fall2, env_fall2,
  3212. // env_rise2, env_rise2,
  3213. // env_risefallrise, env_risefallrise
  3214. int LookupEnvelope(const char *name)
  3215. {//=================================
  3216. return(LookupMnem(envelope_names, name));
  3217. }
  3218. void CompileIntonation()
  3219. {//=====================
  3220. int ix;
  3221. char *p;
  3222. char c;
  3223. int keyword;
  3224. int compiling_tune = 0;
  3225. int n_tune_names = 0;
  3226. int done_split;
  3227. int done_onset = 0;
  3228. int done_last = 0;
  3229. int n_preset_tunes = 0;
  3230. int found;
  3231. int tune_number = 0;
  3232. FILE *f_out;
  3233. wxString report;
  3234. TUNE *tune_data;
  3235. TUNE new_tune;
  3236. char name[12];
  3237. char fname_errors[sizeof(path_source)+120];
  3238. char tune_names[N_TUNE_NAMES][12];
  3239. char buf[sizeof(path_source)+120];
  3240. error_count = 0;
  3241. sprintf(fname_errors,"%s%s",path_source,"error_intonation");
  3242. if((f_errors = fopen(fname_errors,"w")) == NULL)
  3243. f_errors = stderr;
  3244. sprintf(buf,"%sintonation.txt",path_source);
  3245. if((f_in = fopen(buf, "r")) == NULL)
  3246. {
  3247. sprintf(buf,"%sintonation",path_source);
  3248. if((f_in = fopen_log(f_errors, buf, "r")) == NULL)
  3249. {
  3250. wxLogError(_T("Can't read file: ") + wxString(buf,wxConvLocal));
  3251. fclose(f_errors);
  3252. return;
  3253. }
  3254. }
  3255. for(ix=0; preset_tune_names[ix] != NULL; ix++)
  3256. {
  3257. strcpy(tune_names[ix], preset_tune_names[ix]);
  3258. }
  3259. n_tune_names = ix;
  3260. n_preset_tunes = ix;
  3261. // make a list of the tune names
  3262. while(!feof(f_in))
  3263. {
  3264. if(fgets(buf,sizeof(buf),f_in) == NULL)
  3265. break;
  3266. if((memcmp(buf,"tune",4)==0) && isspace(buf[4]))
  3267. {
  3268. p = &buf[5];
  3269. while(isspace(*p)) p++;
  3270. ix = 0;
  3271. while((ix < int(sizeof(name) - 1)) && !isspace(*p))
  3272. {
  3273. name[ix++] = *p++;
  3274. }
  3275. name[ix] = 0;
  3276. found = 0;
  3277. for(ix = 0; ix < n_tune_names; ix++)
  3278. {
  3279. if(strcmp(name, tune_names[ix]) == 0)
  3280. {
  3281. found = 1;
  3282. break;
  3283. }
  3284. }
  3285. if(found == 0)
  3286. {
  3287. strncpy0(tune_names[n_tune_names++], name, sizeof(name));
  3288. if(n_tune_names >= N_TUNE_NAMES)
  3289. break;
  3290. }
  3291. }
  3292. }
  3293. rewind(f_in);
  3294. linenum = 1;
  3295. tune_data = (TUNE *)calloc(sizeof(TUNE), n_tune_names);
  3296. if(tune_data == NULL)
  3297. {
  3298. fprintf(f_errors, "Failed to allocate data for tunes\n");
  3299. fclose(f_in);
  3300. fclose(f_errors);
  3301. return;
  3302. }
  3303. sprintf(buf,"%s/intonations",path_home);
  3304. f_out = fopen_log(f_errors, buf, "wb");
  3305. if(f_out == NULL)
  3306. {
  3307. fclose(f_in);
  3308. fclose(f_errors);
  3309. return;
  3310. }
  3311. while(!feof(f_in))
  3312. {
  3313. keyword = NextItem(tINTONATION);
  3314. switch(keyword)
  3315. {
  3316. case kTUNE:
  3317. if(compiling_tune)
  3318. {
  3319. }
  3320. compiling_tune = 1;
  3321. done_split = 0;
  3322. memcpy(&new_tune, &default_tune, sizeof(TUNE));
  3323. NextItem(tSTRING);
  3324. strncpy0(new_tune.name, item_string, sizeof(new_tune.name));
  3325. found = 0;
  3326. tune_number = 0;
  3327. for(ix=0; ix < n_tune_names; ix++)
  3328. {
  3329. if(strcmp(new_tune.name, tune_names[ix]) == 0)
  3330. {
  3331. found = 1;
  3332. tune_number = ix;
  3333. if(tune_data[ix].name[0] != 0)
  3334. found = 2;
  3335. break;
  3336. }
  3337. }
  3338. // fprintf(f_errors,"tune %s (%d)\n", new_tune.name, tune_number);
  3339. if(found == 2)
  3340. {
  3341. error("Duplicate tune name: '%s'",new_tune.name);
  3342. }
  3343. if(found == 0)
  3344. {
  3345. error("Bad tune name: '%s;", new_tune.name);
  3346. }
  3347. break;
  3348. case kENDTUNE:
  3349. compiling_tune = 0;
  3350. if(done_onset == 0)
  3351. {
  3352. new_tune.unstr_start[0] = new_tune.unstr_start[1];
  3353. new_tune.unstr_end[0] = new_tune.unstr_end[1];
  3354. }
  3355. if(done_last == 0)
  3356. {
  3357. new_tune.unstr_start[2] = new_tune.unstr_start[1];
  3358. new_tune.unstr_end[2] = new_tune.unstr_end[1];
  3359. }
  3360. memcpy(&tune_data[tune_number], &new_tune, sizeof(TUNE));
  3361. break;
  3362. case kTUNE_PREHEAD:
  3363. new_tune.prehead_start = NextItem(tNUMBER);
  3364. new_tune.prehead_end = NextItem(tNUMBER);
  3365. break;
  3366. case kTUNE_ONSET:
  3367. new_tune.onset = NextItem(tNUMBER);
  3368. new_tune.unstr_start[0] = NextItem(tSIGNEDNUMBER);
  3369. new_tune.unstr_end[0] = NextItem(tSIGNEDNUMBER);
  3370. done_onset = 1;
  3371. break;
  3372. case kTUNE_HEADLAST:
  3373. new_tune.head_last = NextItem(tNUMBER);
  3374. new_tune.unstr_start[2] = NextItem(tSIGNEDNUMBER);
  3375. new_tune.unstr_end[2] = NextItem(tSIGNEDNUMBER);
  3376. done_last = 1;
  3377. break;
  3378. case kTUNE_HEADENV:
  3379. NextItem(tSTRING);
  3380. if((ix = LookupEnvelope(item_string)) < 0)
  3381. error("Bad envelope name: '%s'",item_string);
  3382. else
  3383. new_tune.stressed_env = ix;
  3384. new_tune.stressed_drop = NextItem(tNUMBER);
  3385. break;
  3386. case kTUNE_HEAD:
  3387. new_tune.head_max_steps = NextItem(tNUMBER);
  3388. new_tune.head_start = NextItem(tNUMBER);
  3389. new_tune.head_end = NextItem(tNUMBER);
  3390. new_tune.unstr_start[1] = NextItem(tSIGNEDNUMBER);
  3391. new_tune.unstr_end[1] = NextItem(tSIGNEDNUMBER);
  3392. break;
  3393. case kTUNE_HEADEXTEND:
  3394. // up to 8 numbers
  3395. for(ix=0; ix < int(sizeof(new_tune.head_extend)); ix++)
  3396. {
  3397. if(!isdigit(c = CheckNextChar()) && (c != '-'))
  3398. break;
  3399. new_tune.head_extend[ix] = (NextItem(tSIGNEDNUMBER) * 64) / 100; // convert from percentage to 64ths
  3400. }
  3401. new_tune.n_head_extend = ix; // number of values
  3402. break;
  3403. case kTUNE_NUCLEUS0:
  3404. NextItem(tSTRING);
  3405. if((ix = LookupEnvelope(item_string)) < 0)
  3406. {
  3407. error("Bad envelope name: '%s'",item_string);
  3408. break;
  3409. }
  3410. new_tune.nucleus0_env = ix;
  3411. new_tune.nucleus0_max = NextItem(tNUMBER);
  3412. new_tune.nucleus0_min = NextItem(tNUMBER);
  3413. break;
  3414. case kTUNE_NUCLEUS1:
  3415. NextItem(tSTRING);
  3416. if((ix = LookupEnvelope(item_string)) < 0)
  3417. {
  3418. error("Bad envelope name: '%s'",item_string);
  3419. break;
  3420. }
  3421. new_tune.nucleus1_env = ix;
  3422. new_tune.nucleus1_max = NextItem(tNUMBER);
  3423. new_tune.nucleus1_min = NextItem(tNUMBER);
  3424. new_tune.tail_start = NextItem(tNUMBER);
  3425. new_tune.tail_end = NextItem(tNUMBER);
  3426. if(!done_split)
  3427. {
  3428. // also this as the default setting for 'split'
  3429. new_tune.split_nucleus_env = ix;
  3430. new_tune.split_nucleus_max = new_tune.nucleus1_max;
  3431. new_tune.split_nucleus_min = new_tune.nucleus1_min;
  3432. new_tune.split_tail_start = new_tune.tail_start;
  3433. new_tune.split_tail_end = new_tune.tail_end;
  3434. }
  3435. break;
  3436. case kTUNE_SPLIT:
  3437. NextItem(tSTRING);
  3438. if((ix = LookupEnvelope(item_string)) < 0)
  3439. {
  3440. error("Bad envelope name: '%s'",item_string);
  3441. break;
  3442. }
  3443. done_split = 1;
  3444. new_tune.split_nucleus_env = ix;
  3445. new_tune.split_nucleus_max = NextItem(tNUMBER);
  3446. new_tune.split_nucleus_min = NextItem(tNUMBER);
  3447. new_tune.split_tail_start = NextItem(tNUMBER);
  3448. new_tune.split_tail_end = NextItem(tNUMBER);
  3449. NextItem(tSTRING);
  3450. item_string[12] = 0;
  3451. for(ix=0; ix < n_tune_names; ix++)
  3452. {
  3453. if(strcmp(item_string, tune_names[ix]) == 0)
  3454. break;
  3455. }
  3456. if(ix == n_tune_names)
  3457. error("Tune '%s' not found",item_string);
  3458. else
  3459. new_tune.split_tune = ix;
  3460. break;
  3461. default:
  3462. error("Unexpected: '%s'",item_string);
  3463. break;
  3464. }
  3465. }
  3466. for(ix = 0; ix < n_preset_tunes; ix++)
  3467. {
  3468. if(tune_data[ix].name[0] == 0)
  3469. {
  3470. error("Tune '%s' not defined", preset_tune_names[ix]);
  3471. }
  3472. }
  3473. fwrite(tune_data, n_tune_names, sizeof(TUNE), f_out);
  3474. fclose(f_in);
  3475. fclose(f_out);
  3476. report.Printf(_T("Compiled %d intonation tunes: %d errors."),n_tune_names, error_count);
  3477. wxLogStatus(report);
  3478. if(error_count > 0)
  3479. {
  3480. DisplayErrorFile(fname_errors);
  3481. }
  3482. LoadPhData(NULL);
  3483. } // end of CompileIntonation
  3484. void CompilePhonemeData()
  3485. {
  3486. WavegenInit(22050, 0);
  3487. WavegenSetVoice(voice);
  3488. CompilePhonemeData2("phonemes");
  3489. }
  3490. void CompileSampleRate()
  3491. {
  3492. long value;
  3493. #ifndef PLATFORM_POSIX
  3494. wxLogError(_T("Change Sample Rate needs the 'sox' program. It probably doesn't work on Windows"));
  3495. #endif
  3496. value = wxGetNumberFromUser(_T("Compile phoneme data with a specified sample rate"), _T("Sample rate"), _T("Resample (needs 'sox' program)"), 22050, 5000, 48000);
  3497. if(value > 1000)
  3498. {
  3499. WavegenInit(value, 0);
  3500. WavegenSetVoice(voice);
  3501. CompilePhonemeData2("phonemes");
  3502. }
  3503. }