12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983 |
- /***************************************************************************
- * Copyright (C) 2005 to 2011 by Jonathan Duddington *
- * email: [email protected] *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 3 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, see: *
- * <http://www.gnu.org/licenses/>. *
- ***************************************************************************/
-
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdlib.h>
- #include <time.h>
-
- #include "wx/wx.h"
- #include "wx/wfstream.h"
- #include "wx/dir.h"
- #include "wx/filename.h"
-
- #include "speak_lib.h"
- #include "main.h"
- #include "speech.h"
- #include "options.h"
- #include "phoneme.h"
- #include "synthesize.h"
- #include "voice.h"
- #include "spect.h"
-
- #ifdef PLATFORM_POSIX
- #include <unistd.h>
- #endif
-
- extern void FindPhonemesUsed(void);
- extern void DisplayErrorFile(const char *fname);
- extern int utf8_out(unsigned int c, char *buf);
- char path_source[sizeof(path_home)+20];
-
-
- typedef struct { // total 48 bytes
- short frflags;
- unsigned char length;
- unsigned char rms;
- short ffreq[4]; // f0,1,2,3
- unsigned char ffreq2[6]; // nasal(*2) f4,5,6,7,8(*20)
- unsigned char fheight[9]; // f0-8
- unsigned char fwidth[6]; // width/4 f0-5
- unsigned char fright[4]; // width/4 f0-3
- unsigned char bw[6]; // nasal, f1,2,3,4,5 (*2)
- unsigned char klattp[5]; // amp, tilt, kopen, asp,
- } frame_t3;
-
-
- typedef struct {
- const char *mnem;
- int type;
- int data;
- } keywtab_t;
-
- #define k_AND 1
- #define k_OR 2
- #define k_THEN 3
-
- #define kTHISSTRESS 0x800
-
- // keyword types
- enum {
- tPHONEME_TYPE = 1,
- tPHONEME_FLAG,
- tTRANSITION,
- tPLACE,
- tSTATEMENT,
- tINSTRN1,
- tWHICH_PHONEME,
- tTEST,
- };
-
- static keywtab_t k_conditions[] = {
- {"AND", 0, k_AND},
- {"OR", 0, k_OR},
- {"THEN", 0, k_THEN},
- {"prevPh", tWHICH_PHONEME, 0x000},
- {"prevPhW", tWHICH_PHONEME, 0x500},
- {"thisPh", tWHICH_PHONEME, 0x100},
- {"nextPh", tWHICH_PHONEME, 0x200},
- {"next2Ph", tWHICH_PHONEME, 0x300},
- {"nextPhW", tWHICH_PHONEME, 0x400},
- {"next2PhW", tWHICH_PHONEME, 0x700},
- {"nextVowel",tWHICH_PHONEME, 0x600},
-
- // {"numVowels", tTEST, 0x000},
- // {"afterStress", tTEST, 0x000},
-
- {"PreVoicing", tTEST, 0xf01},
- {"KlattSynth", tTEST, 0xf02},
- {"MbrolaSynth", tTEST, 0xf03},
- {NULL, 0, 0}
- };
-
-
-
- static keywtab_t k_properties[] = {
- {"isPause", 0, phPAUSE},
- {"isVowel", 0, phVOWEL},
- {"isNasal", 0, phNASAL},
- {"isLiquid", 0, phLIQUID},
- {"isUStop", 0, phSTOP},
- {"isVFricative", 0, phVFRICATIVE},
-
- {"isPalatal", 0, i_isPalatal},
- {"isRhotic", 0, i_isRhotic},
- {"isSibilant", 0, i_isSibilant},
- {"isFlag1", 0, i_isFlag1},
- {"isFlag2", 0, i_isFlag2},
- {"isFlag3", 0, i_isFlag3},
-
- {"isVel", 0, i_isVel},
-
- {"isDiminished", 0, i_isDiminished},
- {"isUnstressed", 0, i_isUnstressed},
- {"isNotStressed",0, i_isNotStressed},
- {"isStressed", 0, i_isStressed},
- {"isMaxStress", 0, i_isMaxStress},
-
- {"isBreak", 0, i_isBreak},
- {"isPause2", 0, i_isBreak}, // synonym for isBreak
- {"isWordStart", 0, i_isWordStart},
- {"notWordStart", 0, i_notWordStart},
- {"isWordEnd", 0, i_isWordEnd},
- {"isAfterStress",0, i_isAfterStress},
- {"isNotVowel", 0, i_isNotVowel},
- {"isFinalVowel", 0, i_isFinalVowel},
- {"isVoiced", 0, i_isVoiced}, // voiced consonant, or vowel
- {"isFirstVowel", 0, i_isFirstVowel},
- {"isSecondVowel", 0, i_isSecondVowel},
- {"isSeqFlag1", 0, i_isSeqFlag1},
-
- {NULL, 0, 0}
- };
-
- enum {
- kPHONEMESTART = 1,
- kPROCEDURE,
- kENDPHONEME,
- kENDPROCEDURE,
- kEQUIVALENTS,
- kPHONEMENUMBER,
- kPHONEMETABLE,
- kINCLUDE,
- kIMPORT_PH,
-
- kSTARTTYPE,
- kENDTYPE,
- kSTRESSTYPE,
- kVOICINGSWITCH,
-
- kIF,
- kELSE,
- kELIF,
- kENDIF,
- kCALLPH,
-
- kSWITCH_PREVVOWEL,
- kSWITCH_NEXTVOWEL,
- kENDSWITCH,
-
- kFMT,
- kWAV,
- kVOWELSTART,
- kVOWELENDING,
- kANDWAV,
-
- kVOWELIN,
- kVOWELOUT,
- kTONESPEC,
-
- kRETURN,
- kCONTINUE,
- };
-
-
- enum {
- kTUNE = 1,
- kENDTUNE,
- kTUNE_PREHEAD,
- kTUNE_ONSET,
- kTUNE_HEAD,
- kTUNE_HEADENV,
- kTUNE_HEADEXTEND,
- kTUNE_HEADLAST,
- kTUNE_NUCLEUS0,
- kTUNE_NUCLEUS1,
- kTUNE_SPLIT,
- };
-
- static keywtab_t k_intonation[] = {
- {"tune", 0, kTUNE},
- {"endtune", 0, kENDTUNE},
- {"prehead", 0, kTUNE_PREHEAD},
- {"onset", 0, kTUNE_ONSET},
- {"head", 0, kTUNE_HEAD},
- {"headenv", 0, kTUNE_HEADENV},
- {"headextend", 0, kTUNE_HEADEXTEND},
- {"headlast", 0, kTUNE_HEADLAST},
- {"nucleus0", 0, kTUNE_NUCLEUS0},
- {"nucleus", 0, kTUNE_NUCLEUS1},
- {"split", 0, kTUNE_SPLIT},
- {NULL, 0, -1}
- };
-
- static keywtab_t keywords[] = {
- {"vowel", tPHONEME_TYPE, phVOWEL},
- {"liquid", tPHONEME_TYPE, phLIQUID},
- {"pause", tPHONEME_TYPE, phPAUSE},
- {"stress", tPHONEME_TYPE, phSTRESS},
- {"virtual", tPHONEME_TYPE, phVIRTUAL},
-
- {"fricative", tPHONEME_TYPE, phFRICATIVE},
- {"vstop", tPHONEME_TYPE, phVSTOP},
- {"vfricative",tPHONEME_TYPE, phVFRICATIVE},
- {"delete_phoneme", tPHONEME_TYPE, phDELETED},
-
- // type of consonant
- {"stop", tPHONEME_TYPE, phSTOP},
- {"frc", tPHONEME_TYPE, phFRICATIVE},
- {"nasal", tPHONEME_TYPE, phNASAL},
- {"flp", tPHONEME_TYPE, phVSTOP},
- {"afr", tPHONEME_TYPE, phSTOP}, // treat as stop
- {"apr", tPHONEME_TYPE, phFRICATIVE}, // [h] voiceless approximant
-
-
- // keywords
- {"phonemenumber",tSTATEMENT, kPHONEMENUMBER},
- {"phonemetable",tSTATEMENT, kPHONEMETABLE},
- {"include", tSTATEMENT, kINCLUDE},
-
- {"phoneme", tSTATEMENT, kPHONEMESTART},
- {"procedure", tSTATEMENT, kPROCEDURE},
- {"endphoneme", tSTATEMENT, kENDPHONEME},
- {"endprocedure", tSTATEMENT, kENDPROCEDURE},
- {"equivalents", tSTATEMENT, kEQUIVALENTS},
- {"import_phoneme", tSTATEMENT, kIMPORT_PH},
- {"stress_type",tSTATEMENT, kSTRESSTYPE},
- {"starttype", tSTATEMENT, kSTARTTYPE},
- {"endtype", tSTATEMENT, kENDTYPE},
- {"voicingswitch", tSTATEMENT, kVOICINGSWITCH},
-
-
- {"IF", tSTATEMENT, kIF},
- {"ELSE", tSTATEMENT, kELSE},
- {"ELIF", tSTATEMENT, kELIF},
- {"ELSEIF", tSTATEMENT, kELIF}, // same as ELIF
- {"ENDIF", tSTATEMENT, kENDIF},
- {"CALL", tSTATEMENT, kCALLPH},
- {"RETURN", tSTATEMENT, kRETURN},
-
- {"PrevVowelEndings", tSTATEMENT, kSWITCH_PREVVOWEL},
- {"NextVowelStarts", tSTATEMENT, kSWITCH_NEXTVOWEL},
- {"EndSwitch", tSTATEMENT, kENDSWITCH},
-
- {"Tone", tSTATEMENT, kTONESPEC},
- {"FMT", tSTATEMENT, kFMT},
- {"WAV", tSTATEMENT, kWAV},
- {"VowelStart", tSTATEMENT, kVOWELSTART},
- {"VowelEnding",tSTATEMENT, kVOWELENDING},
- {"addWav", tSTATEMENT, kANDWAV},
-
-
- {"Vowelin", tSTATEMENT, kVOWELIN},
- {"Vowelout", tSTATEMENT, kVOWELOUT},
- {"Continue", tSTATEMENT, kCONTINUE},
-
- {"ChangePhoneme", tINSTRN1, i_CHANGE_PHONEME},
- {"ReplaceNextPhoneme", tINSTRN1, i_REPLACE_NEXT_PHONEME},
- {"InsertPhoneme", tINSTRN1, i_INSERT_PHONEME},
- {"AppendPhoneme", tINSTRN1, i_APPEND_PHONEME},
- {"IfNextVowelAppend", tINSTRN1, i_APPEND_IFNEXTVOWEL},
- {"ChangeIfDiminished", tINSTRN1, i_CHANGE_IF + 0},
- {"ChangeIfUnstressed", tINSTRN1, i_CHANGE_IF + 1},
- {"ChangeIfNotStressed", tINSTRN1, i_CHANGE_IF + 2},
- {"ChangeIfStressed", tINSTRN1, i_CHANGE_IF + 3},
-
- {"PauseBefore",tINSTRN1, i_PAUSE_BEFORE},
- {"PauseAfter", tINSTRN1, i_PAUSE_AFTER},
- {"Length", tINSTRN1, i_SET_LENGTH},
- {"length", tINSTRN1, i_SET_LENGTH},
- {"LongLength", tINSTRN1, i_LONG_LENGTH},
- {"LengthAdd", tINSTRN1, i_ADD_LENGTH},
- {"Lengthmod", tINSTRN1, i_LENGTH_MOD},
- {"lengthmod", tINSTRN1, i_LENGTH_MOD},
- {"ipa", tINSTRN1, i_IPA_NAME},
-
- // flags
- {"wavef", tPHONEME_FLAG, phWAVE},
- {"unstressed", tPHONEME_FLAG, phUNSTRESSED},
- {"fortis", tPHONEME_FLAG, phFORTIS},
- {"sibilant", tPHONEME_FLAG, phSIBILANT},
- {"nolink", tPHONEME_FLAG, phNOLINK},
- {"trill", tPHONEME_FLAG, phTRILL},
- {"vowel2", tPHONEME_FLAG, phVOWEL2},
- {"palatal", tPHONEME_FLAG, phPALATAL},
- {"long", tPHONEME_FLAG, phLONG},
- {"brkafter", tPHONEME_FLAG, phBRKAFTER},
- {"rhotic", tPHONEME_FLAG, phRHOTIC},
- {"nonsyllabic",tPHONEME_FLAG, phNONSYLLABIC},
- {"lengthenstop",tPHONEME_FLAG, phLENGTHENSTOP},
- {"nopause", tPHONEME_FLAG, phNOPAUSE},
- {"prevoice", tPHONEME_FLAG, phPREVOICE},
-
- {"flag1", tPHONEME_FLAG, phFLAG1},
- {"flag2", tPHONEME_FLAG, phFLAG2},
- {"flag3", tPHONEME_FLAG, phFLAG3},
-
- // voiced / unvoiced
- {"vcd", tPHONEME_FLAG, phVOICED},
- {"vls", tPHONEME_FLAG, phFORTIS},
-
- // place of articulation, set bits 16-19 of phflags
- {"blb", tPLACE, 1},
- {"lbd", tPLACE, 2},
- {"dnt", tPLACE, 3},
- {"alv", tPLACE, 4},
- {"rfx", tPLACE, 5},
- {"pla", tPLACE, 6},
- {"pal", tPLACE, 7},
- {"vel", tPLACE, 8},
- {"lbv", tPLACE, 9},
- {"uvl", tPLACE, 10},
- {"phr", tPLACE, 11},
- {"glt", tPLACE, 12},
-
- // vowel transition attributes
- {"len=", tTRANSITION, 1},
- {"rms=", tTRANSITION, 2},
- {"f1=", tTRANSITION, 3},
- {"f2=", tTRANSITION, 4},
- {"f3=", tTRANSITION, 5},
- {"brk", tTRANSITION, 6},
- {"rate", tTRANSITION, 7},
- {"glstop", tTRANSITION, 8},
- {"lenadd", tTRANSITION, 9},
- {"f4", tTRANSITION, 10},
- {"gpaus", tTRANSITION, 11},
- {"colr=", tTRANSITION, 12},
- {"amp=", tTRANSITION, 13}, // set rms of 1st frame as fraction of rms of 2nd frame (1/30ths)
-
- {NULL, 0, -1}
- };
-
-
- static keywtab_t *keyword_tabs[] = {
- keywords, k_conditions, k_properties, k_intonation };
-
-
- static PHONEME_TAB *phoneme_out;
-
- static int n_phcodes_list[N_PHONEME_TABS];
- static PHONEME_TAB_LIST phoneme_tab_list2[N_PHONEME_TABS];
- static PHONEME_TAB *phoneme_tab2;
- static int phoneme_flags;
- static int place_articulation;
-
- static char *p_equivalence;
- static char equivalence_buf[20000];
-
-
- #define N_PROCS 50
- int n_procs;
- int proc_addr[N_PROCS];
- char proc_names[40][N_PROCS];
-
- #define MAX_PROG_BUF 2000
- USHORT *prog_out;
- USHORT *prog_out_max;
- USHORT prog_buf[MAX_PROG_BUF+20];
-
-
- static const char *KeyToMnem(keywtab_t *ktab, int type, int value)
- {//===============================================================
- while(ktab->mnem != NULL)
- {
- if(ktab->data == value)
- {
- if((type == -1) || (type == ktab->type))
- return(ktab->mnem);
- }
- ktab++;
- }
- return(NULL);
- }
-
- static void DecompilePhoneme(FILE *f_out, PHONEME_TAB *ph, int compile_phoneme)
- {//============================================================================
- USHORT *pc;
- int instn;
- int instn_category;
- int address, address2;
- int data1;
- int type2;
- int ix;
- int any;
- const char *name;
- char buf[120];
-
- static const char *INV = "Invalid";
-
- static const char *instn_category_string[16] = {
- "", "", "IF", "IF OR",
- "", "", "", "",
- "", "", "", "FMT",
- "WAV", "NextVowelStart", "PrevVowelEnd", "+wav" };
-
- static const char *nextPh_string[6] = {
- "prevPh", "thisPh", "nextPh", "next2Ph", "nextPhW", "**",
- };
-
- static const char *instn0_string[] = {
- "invalid", "RETURN", "Continue", "DeleteNextPhoneme",
- };
-
- static const char *instn10_string[] = {
- "", "VowelIn", "VowelOut", "Tone", "",
- };
-
- static const char *instn_jumps[] = {
- "JMP", INV, INV, INV,
- "JMP false", "SwitchNextVowelType", "SwitchPrevVowelType", INV};
-
- static char instn1_paramtype[] = {
- 0, 3, 3, 3, 3, 3, 3, 1,
- 1, 1, 1, 1, 1, 0, 0, 0,
- 3, 3, 3, 3, 3, 3, 3, 3,
- 0, 0, 0, 0, 0, 0, 0, 0};
-
- return;
-
- if(compile_phoneme)
- {
- fprintf(f_out,"\nPhoneme %s (%d)\n",WordToString(ph->mnemonic),ph->code);
- }
- else
- {
- fprintf(f_out,"\nProcedure %s\n",proc_names[n_procs]);
- }
-
- pc = prog_buf;
- while(pc < prog_out)
- {
- instn = *pc++;
- instn_category = (instn >> 12) & 0xf;
- data1 = instn & 0xff;
- type2 = (instn >> 8) & 0xf;
- fprintf(f_out, " %.3x: %.4x %s",pc-prog_buf,instn,instn_category_string[instn_category]);
-
- switch(instn_category)
- {
- case 0:
- case 1:
- type2 = instn >> 8;
-
- if(instn < 0x100)
- {
- if(data1 > 2)
- data1 = 0;
- fprintf(f_out,"%s",instn0_string[data1]);
- }
- else
- if(type2 == i_IPA_NAME)
- {
- for(ix = 0; ix < data1; ix += 2)
- {
- instn = *pc++;
- buf[ix] = instn >> 8;
- buf[ix+1] = instn & 0xff;
- }
- buf[ix] = 0;
- fprintf(f_out,"ipa %s",buf);
- }
- else
- {
- fprintf(f_out,"%s(",KeyToMnem(keywords, tINSTRN1, type2));
- switch(instn1_paramtype[type2])
- {
- case 0:
- fprintf(f_out,"%.4x",instn);
- break;
- case 1:
- fprintf(f_out,"%d",data1);
- break;
- case 3:
- fprintf(f_out,"%s",WordToString(phoneme_tab2[data1].mnemonic));
- break;
- }
- fprintf(f_out,")");
- }
- break;
-
- case 2:
- case 3:
- if(type2 < 12)
- {
- fprintf(f_out," %s(",nextPh_string[type2 % 6]);
- if(type2 >= 6)
- {
- switch(data1 >> 5)
- {
- case 0:
- name = KeyToMnem(keywords, tPHONEME_TYPE, (data1 & 0x1f));
- if(name != NULL)
- fprintf(f_out,"is%s",name);
- else
- fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f));
- break;
- case 1:
- fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f));
- break;
- case 2:
- fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f));
- break;
- case 4:
- name = KeyToMnem(k_properties, -1, 0x80+(data1 & 0x1f));
- if(name != NULL)
- fprintf(f_out,"%s",name);
- else
- fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f));
- break;
- default:
- fprintf(f_out,"%d %d",(data1 >> 5),(data1 & 0x1f));
- break;
- }
- }
- else
- {
- fprintf(f_out,"%s",WordToString(phoneme_tab2[data1].mnemonic));
- }
- }
- else
- if(type2 == 8)
- {
- // list of numbers
- fprintf(f_out," StressLevel(");
- any = 0;
- for(ix=0; ix<8; ix++)
- {
- if(data1 & (1 << ix))
- {
- if(any)
- fputc(',',f_out);
- any = 1;
- fprintf(f_out,"%d",ix);
- }
- }
- }
- else
- {
- name = KeyToMnem(k_conditions, tTEST, instn & 0xfff);
- fprintf(f_out,"%s(",name);
- }
- fprintf(f_out,")");
- break;
-
- case 6:
- fprintf(f_out,"%s",instn_jumps[(instn >> 9) & 7]);
- fprintf(f_out," %d",instn & 0x1ff);
- break;
-
- case 9:
- address = ((data1 & 0xf) << 4) + *pc++;
- fprintf(f_out,"CALL %.5x",address);
- break;
-
- case 10:
- fprintf(f_out,"%s",instn10_string[type2]);
- switch(type2)
- {
- case 1:
- case 2:
- address = (data1 << 16) + pc[0];
- address2 = (pc[1] << 16) + pc[2];
- pc += 3;
- fprintf(f_out, " %.6x %.8x",address,address2);
- break;
- case 3:
- address = ((instn & 0xf) << 16) + *pc++;
- address2 = ((instn & 0xf0) << 12) + *pc++;
- fprintf(f_out, " %.5x %.5x",address,address2);
- break;
- }
- break;
-
- case 11:
- case 12:
- case 13:
- case 14:
- case 15:
- address = ((instn & 0xf) << 16) + *pc++;
- fprintf(f_out, " %d %.5x",(instn >> 4) & 0xff,address*4);
- break;
- }
- fprintf(f_out,"\n");
- }
- }
-
-
-
-
-
- static int n_phoneme_tabs;
- static int n_phcodes;
-
- // outout files
- static FILE *f_phdata;
- static FILE *f_phindex;
- static FILE *f_phtab;
- static FILE *f_phcontents;
- static FILE *f_errors = stderr;
- static FILE *f_prog_log = NULL;
-
-
- static FILE *f_in;
- static int f_in_linenum;
- static int f_in_displ;
-
-
- static int linenum;
- static int count_references = 0;
- static int duplicate_references = 0;
- static int count_frames = 0;
- static int error_count = 0;
- static int then_count = 0;
- static int after_if = 0;
-
- static char current_fname[80];
-
- static int markers_used[8];
-
- typedef struct {
- void *link;
- int value;
- int ph_mnemonic;
- short ph_table;
- char string[1];
- } REF_HASH_TAB;
-
- static REF_HASH_TAB *ref_hash_tab[256];
-
-
- #define N_ENVELOPES 30
- static int n_envelopes = 0;
- static char envelope_paths[N_ENVELOPES][80];
- static unsigned char envelope_dat[N_ENVELOPES][ENV_LEN];
-
-
- typedef struct {
- FILE *file;
- int linenum;
- char fname[80];
- } STACK;
-
- #define N_STACK 12
- int stack_ix;
- STACK stack[N_STACK];
-
- #define N_IF_STACK 12
- int if_level;
- typedef struct {
- USHORT *p_then;
- USHORT *p_else;
- int returned;
- } IF_STACK;
- IF_STACK if_stack[N_IF_STACK];
-
-
- enum {
- tENDFILE = 1,
- tSTRING,
- tNUMBER,
- tSIGNEDNUMBER,
- tPHONEMEMNEM,
- tOPENBRACKET,
- tKEYWORD,
- tCONDITION,
- tPROPERTIES,
- tINTONATION,
- };
-
- int item_type;
- int item_terminator;
- #define N_ITEM_STRING 256
- char item_string[N_ITEM_STRING];
-
-
-
- static int ref_sorter(char **a, char **b)
- {//======================================
- int ix;
-
- REF_HASH_TAB *p1 = (REF_HASH_TAB *)(*a);
- REF_HASH_TAB *p2 = (REF_HASH_TAB *)(*b);
-
- ix = strcoll(p1->string,p2->string);
- if(ix != 0)
- return ix;
-
- ix = p1->ph_table - p2->ph_table;
- if(ix != 0)
- return ix;
-
- return(p1->ph_mnemonic - p2->ph_mnemonic);
- } /* end of ref_sorter */
-
-
-
- static void CompileReport(void)
- {//============================
- int ix;
- int hash;
- int n;
- REF_HASH_TAB *p;
- REF_HASH_TAB **list;
- FILE *f_report;
- const char *data_path;
- int prev_table;
- int prev_mnemonic;
- char fname[sizeof(path_source)+20];
-
- // make a list of all the references and sort it
- list = (REF_HASH_TAB **)malloc((count_references)* sizeof(REF_HASH_TAB *));
- if(list == NULL)
- return;
-
- sprintf(fname,"%scompile_report",path_source);
- f_report = fopen(fname,"w");
- if(f_report == NULL)
- {
- free(list);
- return;
- }
-
- fprintf(f_report,"%d phoneme tables\n",n_phoneme_tabs);
- fprintf(f_report," new total\n");
- for(ix=0; ix<n_phoneme_tabs; ix++)
- {
- fprintf(f_report,"%8s %3d %4d\n",phoneme_tab_list2[ix].name, phoneme_tab_list2[ix].n_phonemes, n_phcodes_list[ix]+1);
- }
- fputc('\n',f_report);
-
- fprintf(f_report,"Data file Used by\n");
- ix = 0;
- for(hash=0; (hash < 256) && (ix < count_references); hash++)
- {
- p = ref_hash_tab[hash];
- while(p != NULL)
- {
- list[ix++] = p;
- p = (REF_HASH_TAB *)(p->link);
- }
- }
- n = ix;
- qsort((void *)list,n,sizeof(REF_HASH_TAB *),(int (*)(const void *,const void *))ref_sorter);
-
- data_path = "";
- prev_mnemonic = 0;
- prev_table = 0;
- for(ix=0; ix<n; ix++)
- {
- int j = 0;
-
- if(strcmp(list[ix]->string, data_path) != 0)
- {
- data_path = list[ix]->string;
- j = strlen(data_path);
- fprintf(f_report,"%s",data_path);
- }
- else
- {
- if((list[ix]->ph_table == prev_table) && (list[ix]->ph_mnemonic == prev_mnemonic))
- continue; // same phoneme, don't list twice
- }
-
- while(j < 14)
- {
- fputc(' ',f_report); // pad filename with spaces
- j++;
- }
-
- fprintf(f_report," [%s] %s",WordToString(prev_mnemonic = list[ix]->ph_mnemonic), phoneme_tab_list2[prev_table = list[ix]->ph_table].name);
- fputc('\n',f_report);
- }
-
- for(ix=0; ix<n; ix++)
- {
- free(list[ix]);
- list[ix] = NULL;
- }
-
- free(list);
- list = NULL;
- fclose(f_report);
- } // end of CompileReport
-
-
- #ifdef PLATFORM_WINDOWS
- int strcasecmp(const char *s1, const char *s2)
- {
- int ix=0;
- int diff;
-
- for(;;)
- {
- if((diff = (tolower(s1[ix]) - tolower(s2[ix]))) != 0)
- return(diff);
-
- if((s1[ix] == 0) || (s2[ix] == 0))
- return(diff);
-
- ix++;
- }
- }
- #endif
-
-
- static int ph_sorter(char **a, char **b)
- {//======================================
- int ix;
- int t1, t2;
- char mnem1[6];
-
- PHONEME_TAB *p1 = (PHONEME_TAB *)(*a);
- PHONEME_TAB *p2 = (PHONEME_TAB *)(*b);
-
- t1 = p1->type;
- if(t1 > phVOWEL) t1 = phVOWEL+1;
-
- t2 = p2->type;
- if(t2 > phVOWEL) t2 = phVOWEL+1;
-
- if((ix = t1 - t2) != 0)
- return(ix);
-
- strcpy(mnem1,WordToString(p1->mnemonic));
- return(strcasecmp(mnem1,WordToString(p2->mnemonic)));
- } /* end of ph_sorter */
-
-
-
- static void PrintPhonemesUsed(FILE *f, const char *dsource, const char *dictname)
- {//==============================================================================
- int ix;
- PHONEME_TAB *ph;
- PHONEME_TAB *ph_tab[N_PHONEME_TAB];
- int count = 0;
- int n_ph = 0;
- int section = 0;
- time_t mod_time;
- char fname[sizeof(path_home)+45];
- struct stat statbuf;
- char time_string[20];
- const char *files[] = {"rules","list","listx"};
-
- // find the date-stamp of the dictionary source files
- mod_time = 0;
- for(ix=0; ix<3; ix++)
- {
- sprintf(fname,"%s%s_%s",dsource, dictname, files[ix]);
- if(stat(fname,&statbuf) == 0)
- {
- if(statbuf.st_mtime > mod_time)
- mod_time = statbuf.st_mtime;
- }
- }
-
- if(mod_time > 0)
- {
- strftime(time_string, sizeof(time_string), "%F", localtime(&mod_time));
- fprintf(f,"\n\nDictionary %s_dict %s\n",dictname, time_string);
- }
- else
- {
- fprintf(f,"\n\nDictionary %s_dict\n",dictname);
- }
- fflush(f);
-
- for(ix=0; (ix<N_PHONEME_TAB) && (phoneme_tab[ix] != NULL); ix++)
- {
- if(phoneme_tab_flags[ix] & 2)
- {
- ph_tab[n_ph++] = phoneme_tab[ix];
- }
- }
-
- qsort((void *)ph_tab,n_ph,sizeof(PHONEME_TAB *),(int (*)(const void *,const void *))ph_sorter);
-
- for(ix=0; ix<n_ph; ix++)
- {
- ph = ph_tab[ix];
-
- if(ph->type > 1)
- {
- if((ph->type > phVOWEL) && (section == 0))
- {
- section = 1;
- count = 0;
- fputc('\n',f);
- }
- if((count & 0x7) == 0)
- fputc('\n',f);
- fprintf(f,"%-4s ",WordToString(ph->mnemonic));
- count++;
- }
- }
- fputc('\n',f);
- } // end of PrintPhonemesUsed
-
-
-
- static wxString CompileAllDictionaries()
- {//=====================================
- wxString filename;
- wxFileName fname;
- wxString dictstr;
- wxString filetype;
- wxString report = _T("");
- int err;
- int errors = 0;
- int dict_count = 0;
- FILE *f_in;
- FILE *log;
- FILE *f_phused;
- char dictname[80];
- char fname_log[sizeof(path_dsource)+20];
- char save_voice_name[80];
- char path[sizeof(path_home)+40]; // path_dsource+20
- char buf[200];
- char voicename[80];
-
- if(!wxDirExists(path_dictsource))
- {
- if(gui_flag)
- {
- wxString dirname = wxDirSelector(_T("Directory of dictionary files"),path_phsource);
- if(!dirname.IsEmpty())
- {
- path_dictsource = dirname;
- strncpy0(path_dsource,path_dictsource.mb_str(wxConvLocal),sizeof(path_dsource)-1);
- strcat(path_dsource,"/");
- }
- }
- else
- {
- fprintf(stderr,"Can't find dictionary files: %s\n",path_dsource);
- }
- }
-
- wxDir dir(path_dictsource);
- if(!dir.IsOpened())
- {
- return(_T(" No dictionaries"));
- }
-
- strcpy(save_voice_name,voice_name2);
-
- sprintf(fname_log,"%s%s",path_dsource,"dict_log");
- log = fopen(fname_log,"w");
- sprintf(fname_log,"%s%s",path_dsource,"dict_phonemes");
- f_phused = fopen(fname_log,"w");
-
- if(f_phused)
- {
- fprintf(f_phused,"Phonemes which are used in the *_rules and *_list files\n");
- }
-
- bool cont = dir.GetFirst(&filename, _T("*_rules*"), wxDIR_FILES);
- while ( cont )
- {
- fname = wxFileName(filename);
- filetype = fname.GetName().AfterLast('_');
- if((filetype != _T("rules")) && (filetype != _T("rules.txt")))
- {
- cont = dir.GetNext(&filename);
- continue;
- }
-
- dictstr = fname.GetName().BeforeLast('_');
- strcpy(dictname,dictstr.mb_str(wxConvLocal));
-
- dict_count++;
- strcpy(voicename,dictname);
-
- // read the *_rules file to see if a phoneme table is specified though a voice name
- sprintf(path,"%s%s_rules.txt",path_dsource,dictname);
- if((f_in = fopen(path,"r")) == NULL)
- {
- sprintf(path,"%s%s_rules",path_dsource,dictname);
- f_in = fopen(path,"r");
- }
-
- if(f_in != NULL)
- {
- unsigned int ix;
- unsigned int c;
-
- for(ix=0; ix<20; ix++)
- {
- if(fgets(buf,sizeof(buf),f_in) == NULL)
- break;
-
- if(memcmp(buf,"//voice=",8)==0)
- {
- for(ix=0; ix<sizeof(voicename); ix++)
- {
- if(isspace(c = buf[ix+8]))
- {
- break;
- }
- voicename[ix] = c;
- }
- voicename[ix] = 0;
- break;
- }
- }
- fclose(f_in);
- }
-
- LoadVoice(voicename,0);
-
- if((err = CompileDictionary(path_dsource, dictname,log,NULL,0)) > 0)
- {
- report = report + dictstr + wxString::Format(_T(" %d, "),err);
- errors += err;
- }
-
- if(f_phused != NULL)
- {
- memset(phoneme_tab_flags,0,sizeof(phoneme_tab_flags));
- FindPhonemesUsed();
- PrintPhonemesUsed(f_phused, path_dsource, dictname);
- }
-
- cont = dir.GetNext(&filename);
- }
- if(log != NULL)
- fclose(log);
- if(f_phused != NULL)
- fclose(f_phused);
-
- LoadVoiceVariant(save_voice_name,0);
-
- if(errors == 0)
- return(wxString::Format(_T(" Compiled %d dictionaries"),dict_count));
- else
- {
- return(_T(" Dictionary errors: ") + report);
- }
-
- } // end of CompileAllDictionaries
-
-
-
-
- static void error(const char *format, const char *string)
- {//======================================================
- if(string==NULL)
- string = "";
- fprintf(f_errors,"%4d: ",linenum-1);
- fprintf(f_errors,format,string);
- fprintf(f_errors,"\n");
- error_count++;
- }
-
- static void Error(const char *string)
- {//==================================
- error("%s",string);
- }
-
- static FILE *fopen_log(FILE *f_log, const char *fname,const char *access)
- {//=====================================================================
- // performs fopen, but produces error message to f_log if it fails
- FILE *f;
-
- if((f = fopen(fname,access)) == NULL)
- {
- if(f_log != NULL)
- fprintf(f_log,"Can't access (%s) file '%s'\n",access,fname);
- }
- return(f);
- }
-
-
- static unsigned int StringToWord(const char *string)
- {//=================================================
- // Pack 4 characters into a word
- int ix;
- unsigned char c;
- unsigned int word;
-
- word = 0;
- for(ix=0; ix<4; ix++)
- {
- if(string[ix]==0) break;
- c = string[ix];
- word |= (c << (ix*8));
- }
- return(word);
- }
-
-
- static MNEM_TAB reserved_phonemes[] = {
- {"_\001", phonCONTROL}, // NOT USED
- {"%", phonSTRESS_U},
- {"%%", phonSTRESS_D},
- {",", phonSTRESS_2},
- {",,", phonSTRESS_3},
- {"'", phonSTRESS_P},
- {"''", phonSTRESS_P2},
- {"=", phonSTRESS_PREV}, // stress previous syllable
- {"_:", phonPAUSE}, // pause
- {"_", phonPAUSE_SHORT}, // short pause
- {"_!", phonPAUSE_NOLINK}, // short pause, no link
- {":", phonLENGTHEN},
- {"@", phonSCHWA},
- {"@-", phonSCHWA_SHORT},
- {"||", phonEND_WORD},
- {"1", phonDEFAULTTONE}, // (numeral 1) default tone (for tone language)
- {"#X1",phonCAPITAL}, // capital letter indication
- {"?", phonGLOTTALSTOP}, // glottal stop
- {"-", phonSYLLABIC}, // syllabic consonant
- {"_^_",phonSWITCH}, // Change language
- {"_X1",phonX1}, // a language specific action
- {"_|", phonPAUSE_VSHORT}, // very short pause
- {"_::",phonPAUSE_LONG}, // long pause
- {"t#", phonT_REDUCED}, // reduced version of [t]
- {"'!", phonSTRESS_TONIC}, // stress - emphasized
- {"_;_",phonPAUSE_CLAUSE}, // clause pause
-
- {"#@", phonVOWELTYPES}, // vowel type groups, these must be consecutive
- {"#a", phonVOWELTYPES+1},
- {"#e", phonVOWELTYPES+2},
- {"#i", phonVOWELTYPES+3},
- {"#o", phonVOWELTYPES+4},
- {"#u", phonVOWELTYPES+5},
- {NULL, 0} };
-
-
- static void ReservePhCodes()
- {//=========================
- // Reserve phoneme codes which have fixed numbers so that they can be
- // referred to from the program code.
- unsigned int word;
- MNEM_TAB *p;
-
- p = reserved_phonemes;
- while(p->mnem != NULL)
- {
- word = StringToWord(p->mnem);
- phoneme_tab2[p->value].mnemonic = word;
- phoneme_tab2[p->value].code = p->value;
- if(n_phcodes <= p->value)
- n_phcodes = p->value+1;
- p++;
- }
- } // end of ReservePhCodes
-
-
- static int LookupPhoneme(const char *string, int control)
- {//======================================================
- // control = 0 explicit declaration
- // control = 1 declare phoneme if not found
- // control = 2 start looking after control & stress phonemes
-
- int ix;
- int start;
- int use;
- unsigned int word;
-
- if(strcmp(string,"NULL")==0)
- return(1);
-
- ix = strlen(string);
- if((ix==0) || (ix> 4))
- {
- error("Bad phoneme name '%s'",string);
- }
- word = StringToWord(string);
-
- // don't use phoneme number 0, reserved for string terminator
- start = 1;
-
- if(control==2)
- start = 8; // don't look for control and stress phonemes (allows these characters to be
- // used for other purposes)
-
- use = 0;
- for(ix=start; ix<n_phcodes; ix++)
- {
- if(phoneme_tab2[ix].mnemonic == word)
- return(ix);
-
- if((use==0) && (phoneme_tab2[ix].mnemonic == 0))
- {
- use = ix;
- }
- }
-
- if(use == 0)
- {
- if(control == 0)
- return(-1);
- if(n_phcodes >= N_PHONEME_TAB-1)
- return(-1); // phoneme table is full
- use = n_phcodes++;
- }
-
- // add this phoneme to the phoneme table
- phoneme_tab2[use].mnemonic = word;
- phoneme_tab2[use].type = phINVALID;
- phoneme_tab2[use].program = linenum; // for error report if the phoneme remains undeclared
- return(use);
- } // end of Compile::LookupPhoneme
-
-
-
- static unsigned int get_char()
- {//===========================
- unsigned int c;
- c = fgetc(f_in);
- if(c == '\n')
- linenum++;
- return(c);
- }
-
- static void unget_char(unsigned int c)
- {//===================================
- ungetc(c,f_in);
- if(c == '\n')
- linenum--;
- }
-
-
- int CheckNextChar()
- {//================
- int c;
- while(((c = get_char()) == ' ') || (c == '\t'));
- unget_char(c);
- return(c);
- } // end of CheckNextChar
-
-
- static int NextItem(int type)
- {//==========================
- int acc;
- unsigned char c=0;
- unsigned char c2;
- int ix;
- int sign;
- int keyword;
- char *p;
- keywtab_t *pk;
-
- item_type = -1;
-
- f_in_displ = ftell(f_in);
- f_in_linenum = linenum;
-
- while(!feof(f_in))
- {
- c = get_char();
- if(c=='/')
- {
- if((c2 = get_char())=='/')
- {
- // comment, ignore to end of line
- while(!feof(f_in) && ((c = get_char()) != '\n'));
- }
- else
- {
- unget_char(c2);
- }
- }
- if(!isspace(c))
- {
- break;
- }
- }
- if(feof(f_in))
- return(-2);
-
- if(c == '(')
- {
- if(type == tOPENBRACKET)
- return(1);
- return(-1);
- }
-
- ix = 0;
- while(!feof(f_in) && !isspace(c) && (c != '(') && (c != ')') && (c != ','))
- {
- if(c == '\\')
- c = get_char();
- item_string[ix++] = c;
- c = get_char();
- if(feof(f_in))
- break;
- if(item_string[ix-1] == '=')
- break;
- }
- item_string[ix] = 0;
-
- while(isspace(c))
- {
- c = get_char();
- }
-
- item_terminator = ' ';
- if((c == ')') || (c == '(') || (c == ','))
- item_terminator = c;
-
- if((c == ')') || (c == ','))
- c = ' ';
-
- if(!feof(f_in))
- unget_char(c);
-
- keyword = -1;
-
- if(type == tSTRING)
- {
- return(0);
- }
-
- if((type == tNUMBER) || (type == tSIGNEDNUMBER))
- {
- acc = 0;
- sign = 1;
- p = item_string;
-
- if((*p == '-') && (type == tSIGNEDNUMBER))
- {
- sign = -1;
- p++;
- }
- if(!isdigit(*p))
- {
- if((type == tNUMBER) && (*p == '-'))
- error("Expected an unsigned number",NULL);
- else
- error("Expected a number",NULL);
- }
- while(isdigit(*p))
- {
- acc *= 10;
- acc += (*p - '0');
- p++;
- }
- return(acc * sign);
- }
-
-
- if((type >= tKEYWORD) && (type <= tINTONATION))
- {
- pk = keyword_tabs[type-tKEYWORD];
- while(pk->mnem != NULL)
- {
- if(strcmp(item_string,pk->mnem)==0)
- {
- item_type = pk->type;
- return(pk->data);
- }
- pk++;
- }
- item_type = -1;
- return(-1); // keyword not found
- }
- if(type == tPHONEMEMNEM)
- {
- return(LookupPhoneme(item_string,2));
- }
- return(-1);
- } // end of NextItem
-
-
-
- static int NextItemBrackets(int type, int control)
- {//===============================================
- // Expect a parameter inside parantheses
- // control: bit 0 0= need (
- // bit 1 1= allow comma
-
- int value;
-
- if((control & 1) == 0)
- {
- if(!NextItem(tOPENBRACKET))
- {
- error("Expected '('", NULL);
- }
- }
-
- value = NextItem(type);
- if((control & 2) && (item_terminator == ','))
- return(value);
-
- if(item_terminator != ')')
- {
- error("Expected ')'", NULL);
- }
- return(value);
-
- }
-
-
- static void UngetItem()
- {//====================
- fseek(f_in,f_in_displ,SEEK_SET);
- linenum = f_in_linenum;
- } // end of UngetItem
-
-
-
-
- static int Range(int value, int divide, int min, int max)
- {//======================================================
- if(value < 0)
- value -= divide/2;
- else
- value += divide/2;
- value = value / divide;
-
- if(value > max)
- value = max;
- if(value < min)
- value = min;
- return(value - min);
- }
-
-
- int CompileVowelTransition(int which)
- {//==================================
- // Compile a vowel transition
- int key;
- int len=0;
- int rms=0;
- int f1=0;
- int f2=0;
- int f2_min=0;
- int f2_max=0;
- int f3_adj=0;
- int f3_amp=0;
- int flags=0;
- int vcolour=0;
- int x;
- int instn = i_VOWELIN;
- int word1;
- int word2;
-
- if(which==1)
- {
- // instn = i_VOWELIN;
- len = 50 / 2; // defaults for transition into vowel
- rms = 25 / 2;
-
- if(phoneme_out->type == phSTOP)
- {
- len = 42 / 2; // defaults for transition into vowel
- rms = 30 / 2;
- }
- }
- else
- if(which==2)
- {
- instn = i_VOWELOUT;
- len = 36 / 2; // defaults for transition out of vowel
- rms = 16 / 2;
- }
-
- for(;;)
- {
- key = NextItem(tKEYWORD);
- if(item_type != tTRANSITION)
- {
- UngetItem();
- break;
- }
-
- switch(key & 0xf)
- {
- case 1:
- len = Range(NextItem(tNUMBER), 2, 0, 63) & 0x3f;
- flags |= 1;
- break;
- case 2:
- rms = Range(NextItem(tNUMBER), 2, 0, 31) & 0x1f;
- flags |= 1;
- break;
- case 3:
- f1 = NextItem(tNUMBER);
- break;
- case 4:
- f2 = Range(NextItem(tNUMBER), 50, 0, 63) & 0x3f;
- f2_min = Range(NextItem(tSIGNEDNUMBER), 50, -15, 15) & 0x1f;
- f2_max = Range(NextItem(tSIGNEDNUMBER), 50, -15, 15) & 0x1f;
- if(f2_min > f2_max)
- {
- x = f2_min;
- f2_min = f2_max;
- f2_max = x;
- }
- break;
- case 5:
- f3_adj = Range(NextItem(tSIGNEDNUMBER), 50, -15, 15) & 0x1f;
- f3_amp = Range(NextItem(tNUMBER), 8, 0, 15) & 0x1f;
- break;
- case 6:
- flags |= 2; // break
- break;
- case 7:
- flags |= 4; // rate
- break;
- case 8:
- flags |= 8; // glstop
- break;
- case 9:
- flags |= 16; // lenadd
- break;
- case 10:
- flags |= 32; // f4
- break;
- case 11:
- flags |= 64; // paus
- break;
- case 12:
- vcolour = NextItem(tNUMBER);
- break;
- case 13:
- // set rms of 1st frame as fraction of rms of 2nd frame (1/30ths)
- rms = (Range(NextItem(tNUMBER), 1, 0, 31) & 0x1f) | 0x20;
- flags |= 1;
- break;
- }
- }
- word1 = len + (rms << 6) + (flags << 12);
- word2 = f2 + (f2_min << 6) + (f2_max << 11) + (f3_adj << 16) + (f3_amp << 21) + (f1 << 26) + (vcolour << 29);
- prog_out[0] = instn + ((word1 >> 16) & 0xff);
- prog_out[1] = word1;
- prog_out[2] = word2 >> 16;
- prog_out[3] = word2;
- prog_out += 4;
-
- return(0);
- } // end of VowelTransition
-
-
-
- int LoadSpect(const char *path, int control)
- {//=========================================
- SpectSeq *spectseq;
- int peak;
- int displ;
- int frame;
- int n_frames;
- int ix;
- int x, x2;
- int rms;
- float total;
- float pkheight;
- int marker1_set=0;
- int frame_vowelbreak=0;
- int klatt_flag=0;
- SpectFrame *fr;
- frame_t *fr_out;
- wxString path_sep = _T("/");
-
- SPECT_SEQ seq_out;
- SPECT_SEQK seqk_out;
-
- // create SpectSeq and import data
- spectseq = new SpectSeq;
- if(spectseq == NULL)
- {
- Error("Failed to create SpectSeq");
- return(0);
- }
-
- wxString filename = path_phsource + path_sep + wxString(path,wxConvLocal);
- wxFileInputStream stream(filename);
-
- if(stream.Ok() == FALSE)
- {
- error("Failed to open: '%s'",path);
- return(0);
- }
- spectseq->Load(stream);
-
- // do we need additional klatt data ?
- for(frame=0; frame < spectseq->numframes; frame++)
- {
- for(ix=5; ix<N_KLATTP2; ix++)
- {
- if(spectseq->frames[frame]->klatt_param[ix] != 0)
- klatt_flag = FRFLAG_KLATT;
- }
- }
-
- displ = ftell(f_phdata);
-
- seq_out.n_frames=0;
- seq_out.sqflags=0;
- seq_out.length_total=0;
-
- total = 0;
- for(frame=0; frame < spectseq->numframes; frame++)
- {
-
- #ifdef deleted
- for(ix=0; ix<8; ix++)
- {
- // find which files have certain markers set
- if(spectseq->frames[frame]->markers & (1<<ix))
- {
- markers_used[ix]++;
- if((ix==3) || (ix==4))
- {
- fprintf(f_errors,"Marker %d: %s\n",ix,path);
- }
- }
- }
- #endif
-
- if(spectseq->frames[frame]->keyframe)
- {
- if(seq_out.n_frames == 1)
- {
- frame_vowelbreak = frame;
- }
- if(spectseq->frames[frame]->markers & 0x2)
- {
- // marker 1 is set
- marker1_set = 1;
- }
-
- seq_out.n_frames++;
- if(frame > 0)
- total += spectseq->frames[frame-1]->length;
- }
- }
- seq_out.length_total = int(total);
-
- if((control & 1) && (marker1_set == 0))
- {
- // This is a vowel, but no Vowel Break marker is set
- // set a marker flag for the second frame of a vowel
- spectseq->frames[frame_vowelbreak]->markers |= FRFLAG_VOWEL_CENTRE;
- }
-
- n_frames = 0;
- for(frame=0; frame < spectseq->numframes; frame++)
- {
- fr = spectseq->frames[frame];
-
- if(fr->keyframe)
- {
- if(klatt_flag)
- fr_out = &seqk_out.frame[n_frames];
- else
- fr_out = (frame_t *)&seq_out.frame[n_frames];
-
- x = int(fr->length + 0.5); // round to nearest mS
- if(x > 255) x = 255;
- fr_out->length = x;
-
- fr_out->frflags = fr->markers | klatt_flag;
-
- rms = int(fr->GetRms(spectseq->amplitude));
- if(rms > 255) rms = 255;
- fr_out->rms = rms;
-
- if(n_frames == (seq_out.n_frames-1))
- fr_out->length = 0; // give last frame zero length
-
- // write: peak data
- count_frames++;
- for(peak=0; peak < 8; peak++)
- {
- if(peak < 7)
- fr_out->ffreq[peak] = fr->peaks[peak].pkfreq;
-
- pkheight = spectseq->amplitude * fr->amp_adjust * fr->peaks[peak].pkheight;
- pkheight = pkheight/640000;
- if(pkheight > 255) pkheight = 255;
- fr_out->fheight[peak] = int(pkheight);
-
- if(peak < 6)
- {
- x = fr->peaks[peak].pkwidth/4;
- if(x > 255) x = 255;
- fr_out->fwidth[peak] = x;
-
- if(peak < 3)
- {
- x2 = fr->peaks[peak].pkright/4;
- if(x2 > 255) x2 = 255;
- fr_out->fright[peak] = x2;
- }
- }
-
- if(peak < 4)
- {
- x = fr->peaks[peak].klt_bw / 2;
- if(x > 255) x = 255;
- fr_out->bw[peak] = x;
- }
- }
-
- for(ix=0; ix<5; ix++)
- {
- fr_out->klattp[ix] = fr->klatt_param[ix];
-
- fr_out->klattp[KLATT_FNZ] = fr->klatt_param[KLATT_FNZ] / 2;
- }
-
- if(klatt_flag)
- {
- // additional klatt parameters
- for(ix=0; ix<5; ix++)
- {
- fr_out->klattp2[ix] = fr->klatt_param[ix+5];
- }
-
- for(peak=0; peak<7; peak++)
- {
- fr_out->klatt_ap[ix] = fr->peaks[peak].klt_ap;
-
- x = fr->peaks[peak].klt_bp / 2;
- if(x > 255) x = 255;
- fr_out->klatt_bp[ix] = x;
- }
- }
-
- if(fr_out->bw[1] == 0)
- {
- fr_out->bw[0] = 89 / 2;
- fr_out->bw[1] = 90 / 2;
- fr_out->bw[2] = 140 / 2;
- fr_out->bw[3] = 260 / 2;
- }
-
- n_frames++;
- }
- }
-
- if(klatt_flag)
- {
- seqk_out.n_frames = seq_out.n_frames;
- seqk_out.sqflags = seq_out.sqflags;
- seqk_out.length_total = seq_out.length_total;
-
- ix = (char *)(&seqk_out.frame[seqk_out.n_frames]) - (char *)(&seqk_out);
- ix = (ix+3) & 0xfffc; // round up to multiple of 4 bytes
- fwrite(&seqk_out,ix,1,f_phdata);
- }
- else
- {
- ix = (char *)(&seq_out.frame[seq_out.n_frames]) - (char *)(&seq_out);
- ix = (ix+3) & 0xfffc; // round up to multiple of 4 bytes
- fwrite(&seq_out,ix,1,f_phdata);
- }
-
- delete spectseq;
- return(displ);
- } // end of LoadSpect
-
-
-
- static int LoadWavefile(FILE *f, const char *fname)
- {//================================================
- int displ;
- unsigned char c1;
- unsigned char c3;
- int c2;
- int sample;
- int sample2;
- float x;
- int max = 0;
- int length;
- int sr1, sr2;
- int resample_wav = 0;
- char fname_temp[100];
- int scale_factor=0;
-
- fseek(f,24,SEEK_SET);
- sr1 = Read4Bytes(f);
- sr2 = Read4Bytes(f);
- fseek(f,40,SEEK_SET);
-
- if((sr1 != samplerate_native) || (sr2 != sr1*2))
- {
- #ifdef PLATFORM_WINDOWS
- if(sr1 != samplerate_native)
- {
- fprintf(f_errors,"Wrong samplerate %d, wants %d\n",sr1,samplerate_native);
- error("Wrong samplerate: %s",fname);
- }
- if(sr2 != sr1*2)
- {
- error("Not mono: %s",fname);
- }
- #else
- {
- int fd_temp;
- char command[sizeof(path_source)+200];
- strcpy(fname_temp,"/tmp/espeakXXXXXX");
- if((fd_temp = mkstemp(fname_temp)) >= 0)
- {
- close(fd_temp);
- sprintf(command,"sox \"%s%s.wav\" -r %d -c 1 -w %s polyphase\n",path_source,fname,samplerate_native,fname_temp);
- if(system(command) < 0)
- {
- error("Failed to resample: %s",command);
- return(0);
- }
- }
-
- f = fopen(fname_temp,"rb");
- if(f == NULL)
- {
- error("Can't read temp file: %s",fname_temp);
- return(0);
- }
- resample_wav = 1;
- fseek(f,40,SEEK_SET); // skip past the WAV header, up to before "data length"
- }
- #endif
- }
-
- displ = ftell(f_phdata);
-
- // data contains: 4 bytes of length (n_samples * 2), followed by 2-byte samples (lsb byte first)
- length = Read4Bytes(f);
-
- while(!feof(f))
- {
- c1 = fgetc(f);
- c3 = fgetc(f);
- if(feof(f)) break;
-
- c2 = c3 << 24;
- c2 = c2 >> 16; // sign extend
-
- sample = (c1 & 0xff) + c2;
-
- if(sample > max)
- max = sample;
- else
- if(sample < -max)
- max = -sample;
-
- }
-
- scale_factor = (max / 127) + 1;
-
- //fprintf(f_errors," sample len=%d max=%4x shift=%d\n",length,max,scale_factor);
-
- #define MIN_FACTOR -1 // was 6, disable use of 16 bit samples
- if(scale_factor > MIN_FACTOR)
- {
- length = length/2 + (scale_factor << 16);
- }
-
- Write4Bytes(f_phdata,length);
- // fwrite(&length,4,1,f_phdata);
- fseek(f,44,SEEK_SET);
-
- while(!feof(f))
- {
- c1 = fgetc(f);
- c3 = fgetc(f);
- c2 = c3 << 24;
- c2 = c2 >> 16; // sign extend
-
- sample = (c1 & 0xff) + c2;
-
- if(feof(f)) break;
-
- if(scale_factor <= MIN_FACTOR)
- {
- fputc(sample & 0xff,f_phdata);
- fputc(sample >> 8,f_phdata);
- }
- else
- {
- x = (float(sample) / scale_factor) + 0.5;
- sample2= int(x);
- if(sample2 > 127)
- sample2 = 127;
- if(sample2 < -128)
- sample2 = -128;
- fputc(sample2,f_phdata);
- }
- }
-
- length = ftell(f_phdata);
- while((length & 3) != 0)
- {
- // pad to a multiple of 4 bytes
- fputc(0,f_phdata);
- length++;
- }
-
- if(resample_wav != 0)
- {
- fclose(f);
- remove(fname_temp);
- }
- return(displ | 0x800000); // set bit 23 to indicate a wave file rather than a spectrum
- } // end of LoadWavefile
-
-
-
- static int LoadEnvelope(FILE *f, const char *fname)
- {//================================================
- int displ;
- char buf[128];
-
- displ = ftell(f_phdata);
-
- fseek(f,12,SEEK_SET);
- if(fread(buf,128,1,f) == 0)
- {
- error("Failed to read envelope: %s",fname);
- }
- fwrite(buf,128,1,f_phdata);
-
- if(n_envelopes < N_ENVELOPES)
- {
- strncpy0(envelope_paths[n_envelopes],fname,sizeof(envelope_paths[0]));
- memcpy(envelope_dat[n_envelopes],buf,sizeof(envelope_dat[0]));
- n_envelopes++;
- }
-
- return(displ);
- } // end of LoadEnvelope
-
-
-
- static int Hash8(const char *string)
- //==================================
- /* Generate a hash code from the specified string */
- {
- int c;
- int chars=0;
- int hash=0;
-
- while((c = *string++) != 0)
- {
- c = tolower(c) - 'a';
- hash = hash * 8 + c;
- hash = (hash & 0x1ff) ^ (hash >> 8); /* exclusive or */
- chars++;
- }
-
- return((hash+chars) & 0xff);
- } // end of Hash8
-
-
-
- static int LoadEnvelope2(FILE *f, const char *fname)
- {//===================================================
- int ix, ix2;
- int n;
- int x, y;
- int displ;
- int n_points;
- double yy;
- char line_buf[128];
- float env_x[20];
- float env_y[20];
- int env_lin[20];
- unsigned char env[ENV_LEN];
-
- n_points = 0;
- fgets(line_buf,sizeof(line_buf),f); // skip first line
- while(!feof(f))
- {
- if(fgets(line_buf,sizeof(line_buf),f) == NULL)
- break;
-
- env_lin[n_points] = 0;
- n = sscanf(line_buf,"%f %f %d",&env_x[n_points],&env_y[n_points],&env_lin[n_points]);
- if(n >= 2)
- {
- env_x[n_points] *= (float)1.28; // convert range 0-100 to 0-128
- n_points++;
- }
- }
- env_x[n_points] = env_x[n_points-1];
- env_y[n_points] = env_y[n_points-1];
-
- ix = -1;
- ix2 = 0;
- for(x=0; x<ENV_LEN; x++)
- {
- if(x > env_x[ix+4])
- ix++;
- if(x >= env_x[ix2+1])
- ix2++;
-
- if(env_lin[ix2] > 0)
- {
- yy = env_y[ix2] + (env_y[ix2+1] - env_y[ix2]) * (float(x) - env_x[ix2]) / (env_x[ix2+1] - env_x[ix2]);
- y = int(yy * 2.55);
- }
- else
- if(n_points > 3)
- y = (int)(polint(&env_x[ix],&env_y[ix],4,x) * 2.55); // convert to range 0-255
- else
- y = (int)(polint(&env_x[ix],&env_y[ix],3,x) * 2.55);
- if(y < 0) y = 0;
- if(y > 255) y = 255;
- env[x] = y;
- }
-
-
- if(n_envelopes < N_ENVELOPES)
- {
- strncpy0(envelope_paths[n_envelopes],fname,sizeof(envelope_paths[0]));
- memcpy(envelope_dat[n_envelopes],env,ENV_LEN);
- n_envelopes++;
- }
-
- displ = ftell(f_phdata);
- fwrite(env,1,128,f_phdata);
-
- return(displ);
- }
-
- static int LoadDataFile(const char *path, int control)
- {//===================================================
- // load spectrum sequence or sample data from a file.
- // return index into spect or sample data area. bit 23=1 if a sample
-
- FILE *f;
- int id;
- int hash;
- int addr = 0;
- int type_code=' ';
- REF_HASH_TAB *p, *p2;
- char buf[sizeof(path_source)+120];
-
- if(strcmp(path,"NULL")==0)
- return(0);
- if(strcmp(path,"DFT")==0)
- return(1);
-
- count_references++;
-
- hash = Hash8(path);
- p = ref_hash_tab[hash];
- while(p != NULL)
- {
- if(strcmp(path,p->string)==0)
- {
- duplicate_references++;
- addr = p->value; // already loaded this data
- break;
- }
- p = (REF_HASH_TAB *)p->link;
- }
-
- if(addr == 0)
- {
- sprintf(buf,"%s%s",path_source,path);
-
- if((f = fopen(buf,"rb")) == NULL)
- {
- sprintf(buf,"%s%s.wav",path_source,path);
- if((f = fopen(buf,"rb")) == NULL)
- {
- error("Can't read file: %s",path);
- return(0);
- }
- }
-
- id = Read4Bytes(f);
- rewind(f);
-
- if(id == 0x43455053)
- {
- addr = LoadSpect(path, control);
- type_code = 'S';
- }
- else
- if(id == 0x46464952)
- {
- addr = LoadWavefile(f,path);
- type_code = 'W';
- }
- else
- if(id == 0x43544950)
- {
- addr = LoadEnvelope(f,path);
- type_code = 'E';
- }
- else
- if(id == 0x45564E45)
- {
- addr = LoadEnvelope2(f,path);
- type_code = 'E';
- }
- else
- {
- error("File not SPEC or RIFF: %s",path);
- addr = -1;
- }
- fclose(f);
-
- if(addr > 0)
- {
- fprintf(f_phcontents,"%c 0x%.5x %s\n",type_code,addr & 0x7fffff,path);
- }
- }
-
- // add this item to the hash table
- if(addr > 0)
- {
- p = ref_hash_tab[hash];
- p2 = (REF_HASH_TAB *)malloc(sizeof(REF_HASH_TAB)+strlen(path)+1);
- p2->value = addr;
- p2->ph_mnemonic = phoneme_out->mnemonic; // phoneme which uses this file
- p2->ph_table = n_phoneme_tabs-1;
- strcpy(p2->string,path);
- p2->link = (char *)p;
- ref_hash_tab[hash] = p2;
- }
-
- return(addr);
- } // end of LoadDataFile
-
-
- static int CompileToneSpec(void)
- {//=============================
- int pitch1=0;
- int pitch2=0;
- int pitch_env = 0;
- int amp_env = 0;
-
- pitch1 = NextItemBrackets(tNUMBER,2);
- pitch2 = NextItemBrackets(tNUMBER,3);
-
- if(item_terminator == ',')
- {
- NextItemBrackets(tSTRING,3);
- pitch_env = LoadDataFile(item_string, 0);
- }
-
- if(item_terminator == ',')
- {
- NextItemBrackets(tSTRING,1);
- amp_env = LoadDataFile(item_string, 0);
- }
-
- if(pitch1 < pitch2)
- {
- phoneme_out->start_type = pitch1;
- phoneme_out->end_type = pitch2;
- }
- else
- {
- phoneme_out->start_type = pitch2;
- phoneme_out->end_type = pitch1;
- }
-
- if(pitch_env != 0)
- {
- *prog_out++ = i_PITCHENV + ((pitch_env >> 16) & 0xf);
- *prog_out++ = pitch_env;
- }
- if(amp_env != 0)
- {
- *prog_out++ = i_AMPENV + ((amp_env >> 16) & 0xf);
- *prog_out++ = amp_env;
- }
-
- return(0);
- } // end of CompileToneSpec
-
-
-
- int CompileSound(int keyword, int isvowel)
- {//=======================================
- int addr;
- int value = 0;
- char path[N_ITEM_STRING];
- static int sound_instns[] = {i_FMT, i_WAV, i_VWLSTART, i_VWLENDING, i_WAVADD};
-
- NextItemBrackets(tSTRING,2);
- strcpy(path, item_string);
- if(item_terminator == ',')
- {
- if((keyword == kVOWELSTART) || (keyword == kVOWELENDING))
- {
- value = NextItemBrackets(tSIGNEDNUMBER,1);
- if(value > 127)
- {
- value = 127;
- error("Parameter > 127",NULL);
- }
- if(value < -128)
- {
- value = -128;
- error("Parameter < -128",NULL);
- }
- }
- else
- {
- value = NextItemBrackets(tNUMBER,1);
- if(value > 255)
- {
- value = 255;
- error("Parameter > 255",NULL);
- }
- }
- }
- addr = LoadDataFile(path, isvowel);
- addr = addr / 4; // addr is words not bytes
-
- *prog_out++ = sound_instns[keyword-kFMT] + ((value & 0xff) << 4) + ((addr >> 16) & 0xf);
- *prog_out++ = addr & 0xffff;
- return(0);
- } // end of CompileSound
-
-
-
- /*
- Condition
- bits 14,15 1
- bit 13 1 = AND, 0 = OR
- bit 12 spare
- bit 8-11
- =0-3 p,t,n,n2 data=phoneme code
- =4-7 p,t,n,n2 data=(bits5-7: phtype, place, property, special) (bits0-4: data)
- =8 data = stress bitmap
- =9 special tests
- */
-
- int CompileIf(int elif)
- {//====================
- int key;
- int finish = 0;
- int word = 0;
- int data;
- int bitmap;
- int brackets;
- USHORT *prog_last_if = NULL;
-
- then_count = 2;
- after_if = 1;
-
- while(!finish)
- {
- if(prog_out >= prog_out_max)
- {
- error("Phoneme program too large", NULL);
- return(0);
- }
-
- if((key = NextItem(tCONDITION)) < 0)
- error("Expected a condition, not '%s'",item_string);
-
- if(item_type == tWHICH_PHONEME)
- {
- // prevPh(), thisPh(), nextPh(), next2Ph()
- data = NextItemBrackets(tPROPERTIES,0);
- if(data >= 0)
- {
- word = key + data + 0x700;
- }
- else
- {
- data = LookupPhoneme(item_string,2);
- word = key + data;
- }
- }
- else
- if(item_type == tTEST)
- {
- if(key == kTHISSTRESS)
- {
- bitmap = 0;
- brackets = 2;
- do {
- data = NextItemBrackets(tNUMBER,brackets);
- if(data > 7)
- error("Expected list of stress levels",NULL);
- bitmap |= (1 << data);
-
- brackets = 3;
- } while(item_terminator == ',');
- word = i_StressLevel | bitmap;
- }
- else
- {
- word = key;
- }
- }
- else
- {
- error("Unexpected keyword '%s'",item_string);
- }
-
- // output the word
- prog_last_if = prog_out;
- *prog_out++ = word | i_CONDITION;
-
- // expect AND, OR, THEN
- switch(NextItem(tCONDITION))
- {
- case k_AND:
- break;
- case k_OR:
- if(prog_last_if != NULL)
- *prog_last_if |= i_OR;
- break;
- case k_THEN:
- finish = 1;
- break;
- default:
- error("Expected AND, OR, THEN",NULL);
- break;
- }
- }
-
- if(finish != 1)
- {
- }
-
- if(elif == 0)
- {
- if_level++;
- if_stack[if_level].p_else = NULL;
- }
-
- if_stack[if_level].returned = 0;
- if_stack[if_level].p_then = prog_out;
- *prog_out++ = i_JUMP_FALSE;
-
- return(0);
- } // end of CompileIf
-
-
- void FillThen(int add)
- {//===================
- USHORT *p;
- int offset;
-
- p = if_stack[if_level].p_then;
- if(p != NULL)
- {
- offset = prog_out - p + add;
-
- if((then_count == 1) && (if_level == 1))
- {
- // The THEN part only contains one statement, we can remove the THEN jump
- // and the interpreter will implicitly skip the statement.
- while(p < prog_out)
- {
- p[0] = p[1];
- p++;
- }
- prog_out--;
- }
- else
- {
- if(offset > MAX_JUMP)
- {
- error("IF block is too long",NULL);
- }
- *p = i_JUMP_FALSE + offset;
- }
- if_stack[if_level].p_then = NULL;
- }
-
- then_count = 0;
- } // end of FillThen
-
-
- int CompileElse(void)
- {//==================
- USHORT *ref;
- USHORT *p;
-
- if(if_level < 1)
- {
- error("ELSE not expected",NULL);
- return(0);
- }
-
- if(if_stack[if_level].returned == 0)
- {
- FillThen(1);
- }
- else
- {
- FillThen(0);
- }
-
- if(if_stack[if_level].returned == 0)
- {
- ref = prog_out;
- *prog_out++ = 0;
-
- if((p = if_stack[if_level].p_else) != NULL)
- {
- *ref = ref - p; // backwards offset to the previous else
- }
- if_stack[if_level].p_else = ref;
- }
-
- return(0);
- } // end of CompileElse
-
-
- int CompileElif(void)
- {//===================
- if(if_level < 1)
- {
- error("ELIF not expected",NULL);
- return(0);
- }
-
- CompileElse();
- CompileIf(1);
- return(0);
- }
-
-
- int CompileEndif(void)
- {//===================
- USHORT *p;
- int chain;
- int offset;
-
- if(if_level < 1)
- {
- error("ENDIF not expected",NULL);
- return(0);
- }
-
- FillThen(0);
-
- if((p = if_stack[if_level].p_else) != NULL)
- {
- do
- {
- chain = *p; // a chain of previous else links
-
- offset = prog_out - p;
- if(offset > MAX_JUMP)
- {
- error("IF block is too long",NULL);
- }
- *p = i_JUMP + offset;
-
- p -= chain;
- } while (chain > 0);
- }
-
- if_level--;
- return(0);
- } // end of CompileEndif
-
-
- static int CompileSwitch(int type)
- {//===============================
- // Type 0: EndSwitch
- // 1: SwitchPrevVowelType
- // 2: SwitchNextVowelType
-
- if(type == 0)
- {
- // check the instructions in the Switch
- return(0);
- }
-
- // count_VowelStart = 0;
- // count_VowelEnding = 0;
-
- if(type == 1)
- *prog_out++ = i_SWITCH_PREVVOWEL+6;
- if(type == 2)
- *prog_out++ = i_SWITCH_NEXTVOWEL+6;
- return(0);
- } // end of CompileSwitch
-
-
-
- static PHONEME_TAB_LIST *FindPhonemeTable(const char *string)
- {//==========================================================
- int ix;
-
- for(ix=0; ix<n_phoneme_tabs; ix++)
- {
- if(strcmp(phoneme_tab_list2[ix].name, string) == 0)
- {
- return(&phoneme_tab_list2[ix]);
- }
- }
- error("Unknown phoneme table: '%s'",string);
- return(NULL);
- } // end of FindPhonemeTable
-
-
-
- static PHONEME_TAB *FindPhoneme(const char *string)
- {//================================================
- PHONEME_TAB_LIST *phtab = NULL;
- int ix;
- unsigned int mnem;
- char *phname;
- char buf[200];
-
- // is this the name of a phoneme which is in scope
- if((strlen(string) <= 4) && ((ix = LookupPhoneme(string,0)) != -1))
- {
- return(&phoneme_tab2[ix]);
- }
-
- // no, treat the name as phonemetable/phoneme
- strcpy(buf,string);
- if((phname = strchr(buf,'/')) != 0)
- {
- *phname++ = 0;
- }
-
- phtab = FindPhonemeTable(buf);
- if(phtab == NULL)
- {
- return(NULL); // phoneme table not found
- }
-
- mnem = StringToWord(phname);
- for(ix=1; ix<256; ix++)
- {
- if(mnem == phtab->phoneme_tab_ptr[ix].mnemonic)
- {
- return(&phtab->phoneme_tab_ptr[ix]);
- }
- }
-
- error("Phoneme reference not found: '%s'",string);
- return(NULL);
- }
-
-
- static void ImportPhoneme(void)
- {//============================
- unsigned int ph_mnem;
- unsigned int ph_code;
- PHONEME_TAB *ph;
-
- NextItem(tSTRING);
-
- if((ph = FindPhoneme(item_string)) == NULL)
- return;
-
- ph_mnem = phoneme_out->mnemonic;
- ph_code = phoneme_out->code;
- memcpy(phoneme_out,ph,sizeof(PHONEME_TAB));
- phoneme_out->mnemonic = ph_mnem;
- phoneme_out->code = ph_code;
- if(phoneme_out->type != phVOWEL)
- {
- phoneme_out->end_type = 0; // voicingswitch, this must be set later to refer to a local phoneme
- }
-
- } // end of ImportPhoneme
-
-
- static void CallPhoneme(void)
- {//==========================
- PHONEME_TAB *ph;
- int ix;
- int addr = 0;
-
- NextItem(tSTRING);
-
- // first look for a procedure name
- for(ix=0; ix<n_procs; ix++)
- {
- if(strcmp(proc_names[ix],item_string) == 0)
- {
- addr = proc_addr[ix];
- break;
- }
- }
- if(ix == n_procs)
- {
- // procedure not found, try a phoneme name
- if((ph = FindPhoneme(item_string)) == NULL)
- return;
- addr = ph->program;
-
- if(phoneme_out->type == phINVALID)
- {
- // Phoneme type has not been set. Copy it from the called phoneme
- phoneme_out->type = ph->type;
- phoneme_flags = ph->phflags & ~phARTICULATION;
- place_articulation = (ph->phflags & phARTICULATION) >> 16;
- phoneme_out->start_type = ph->start_type;
- phoneme_out->end_type = ph->end_type;
- phoneme_out->std_length = ph->std_length;
- phoneme_out->length_mod = ph->length_mod;
- }
- }
-
- *prog_out++ = i_CALLPH + (addr >> 16);
- *prog_out++ = addr;
- } // end of CallPhoneme
-
-
- static void DecThenCount()
- {//=======================
- if(then_count >0)
- then_count--;
- }
-
- static void InstnPlusPhoneme(int instn)
- {//====================================
- int phcode;
- DecThenCount();
-
- phcode = NextItemBrackets(tPHONEMEMNEM,0);
- *prog_out++ = instn + phcode;
- }
-
-
- int CompilePhoneme(int compile_phoneme)
- {//====================================
- int endphoneme = 0;
- int keyword;
- int value;
- int phcode = 0;
- int ix;
- unsigned int c;
- char *p;
- char number_buf[12];
- char ipa_buf[N_ITEM_STRING];
- PHONEME_TAB phoneme_out2;
- PHONEME_PROG_LOG phoneme_prog_log;
-
- prog_out = prog_buf;
- prog_out_max = &prog_buf[MAX_PROG_BUF-1];
- if_level = 0;
- if_stack[0].returned = 0;
- after_if = 0;
- phoneme_flags = 0;
- place_articulation = 0;
-
- NextItem(tSTRING);
- if(compile_phoneme)
- {
- phcode = LookupPhoneme(item_string,1); // declare phoneme if not already there
- if(phcode == -1) return(0);
- phoneme_out = &phoneme_tab2[phcode];
- }
- else
- {
- // declare a procedure
- if(n_procs >= N_PROCS)
- {
- error("Too many procedures",NULL);
- return(0);
- }
- strcpy(proc_names[n_procs], item_string);
- phoneme_out = &phoneme_out2;
- }
-
- phoneme_out->code = phcode;
- phoneme_out->program = 0;
- phoneme_out->type = phINVALID;
- phoneme_out->std_length = 0;
- phoneme_out->start_type = 0;
- phoneme_out->end_type = 0;
- phoneme_out->length_mod = 0;
-
- while(!endphoneme && !feof(f_in))
- {
- if((keyword = NextItem(tKEYWORD)) < 0)
- {
- if(keyword == -2)
- {
- error("Missing 'endphoneme' before end-of-file",NULL); // end of file
- break;
- }
- error("Bad keyword in phoneme definition '%s'",item_string);
- continue;
- }
-
- switch(item_type)
- {
- case tPHONEME_TYPE:
- if(phoneme_out->type != phINVALID)
- error("More than one phoneme type: %s",item_string);
- phoneme_out->type = keyword;
- break;
-
- case tPLACE:
- if(place_articulation > 0)
- error("Place of articulation has already been given: %s",item_string);
- place_articulation = keyword;
- break;
-
- case tPHONEME_FLAG:
- phoneme_flags |= keyword;
- break;
-
- case tINSTRN1:
- // instruction group 0, with 8 bit operands which set data in PHONEME_DATA
- switch(keyword)
- {
- case i_CHANGE_PHONEME:
- case i_APPEND_PHONEME:
- case i_APPEND_IFNEXTVOWEL:
- case i_INSERT_PHONEME:
- case i_REPLACE_NEXT_PHONEME:
- case i_VOICING_SWITCH:
- case i_CHANGE_IF+0:
- case i_CHANGE_IF+1:
- case i_CHANGE_IF+2:
- case i_CHANGE_IF+3:
- InstnPlusPhoneme(keyword << 8);
- break;
-
- case i_PAUSE_BEFORE:
- value = NextItem(tNUMBER);
- *prog_out++ = (i_PAUSE_BEFORE << 8) + value;
- break;
-
- case i_PAUSE_AFTER:
- value = NextItem(tNUMBER);
- *prog_out++ = (i_PAUSE_AFTER << 8) + value;
- break;
-
- case i_SET_LENGTH:
- value = NextItem(tNUMBER);
- if(after_if == 0)
- {
- phoneme_out->std_length = value/2;
- }
- else
- {
- *prog_out++ = (i_SET_LENGTH << 8) + value/2;
- DecThenCount();
- }
- break;
-
- case i_ADD_LENGTH:
- value = NextItem(tSIGNEDNUMBER);
- *prog_out++ = (i_ADD_LENGTH << 8) + value/2;
- DecThenCount();
- break;
-
- case i_LENGTH_MOD:
- value = NextItem(tNUMBER);
- phoneme_out->length_mod = value;
- break;
-
- case i_IPA_NAME:
- NextItem(tSTRING);
-
- if(strcmp(item_string,"NULL")==0)
- strcpy(item_string," ");
-
- // copy the string, recognize characters in the form U+9999
- p = item_string;
- ix = 0;
- while((c = *p++) != 0)
- {
- if((c=='U') && (p[0]=='+'))
- {
- // U+9999
- memcpy(number_buf,&p[1],4); // U+ should be followed by 4 hex digits
- number_buf[4] = 0;
- c = 0;
- sscanf(number_buf,"%x",&c);
- p += 5;
- ix += utf8_out(c, &ipa_buf[ix]);
- }
- else
- {
- ipa_buf[ix++] = c;
- }
- }
- ipa_buf[ix] = 0;
- value = strlen(ipa_buf); // number of UTF-8 bytes
-
- *prog_out++ = (i_IPA_NAME << 8) + value;
- for(ix=0; ix < value; ix += 2)
- {
- *prog_out++ = (ipa_buf[ix] << 8) + (ipa_buf[ix+1] & 0xff);
- }
- break;
- }
- break;
-
- case tSTATEMENT:
- switch(keyword)
- {
- case kIMPORT_PH:
- ImportPhoneme();
- phoneme_flags = phoneme_out->phflags;
- break;
-
- case kSTARTTYPE:
- phcode = NextItem(tPHONEMEMNEM);
- if(phcode == -1)
- phcode = LookupPhoneme(item_string,1);
- phoneme_out->start_type = phcode;
- break;
-
- case kENDTYPE:
- phcode = NextItem(tPHONEMEMNEM);
- if(phcode == -1)
- phcode = LookupPhoneme(item_string,1);
- if(phoneme_out->type == phVOWEL)
- {
- phoneme_out->end_type = phcode;
- }
- else
- {
- if(phcode != phoneme_out->start_type)
- {
- error("endtype must equal starttype for consonants",NULL);
- }
- }
- break;
-
- case kVOICINGSWITCH:
- phcode = NextItem(tPHONEMEMNEM);
- if(phcode == -1)
- phcode = LookupPhoneme(item_string,1);
- phoneme_out->end_type = phcode; // use end_type field for consonants as voicing_switch
- break;
-
- case kSTRESSTYPE:
- value = NextItem(tNUMBER);
- phoneme_out->std_length = value;
- if(prog_out > prog_buf)
- {
- error("stress phonemes can't contain program instructions",NULL);
- prog_out = prog_buf;
- }
- break;
-
- case kIF:
- endphoneme = CompileIf(0);
- break;
-
- case kELSE:
- endphoneme = CompileElse();
- break;
-
- case kELIF:
- endphoneme = CompileElif();
- break;
-
- case kENDIF:
- endphoneme = CompileEndif();
- break;
-
- case kENDSWITCH:
- break;
-
- case kSWITCH_PREVVOWEL:
- endphoneme = CompileSwitch(1);
- break;
-
- case kSWITCH_NEXTVOWEL:
- endphoneme = CompileSwitch(2);
- break;
-
- case kCALLPH:
- CallPhoneme();
- break;
-
- case kFMT:
- if_stack[if_level].returned = 1;
- DecThenCount();
- if(phoneme_out->type == phVOWEL)
- endphoneme = CompileSound(keyword,1);
- else
- endphoneme = CompileSound(keyword,0);
- break;
-
- case kWAV:
- if_stack[if_level].returned = 1;
- case kVOWELSTART:
- case kVOWELENDING:
- case kANDWAV:
- DecThenCount();
- endphoneme = CompileSound(keyword,0);
- break;
-
- case kVOWELIN:
- DecThenCount();
- endphoneme = CompileVowelTransition(1);
- break;
-
- case kVOWELOUT:
- DecThenCount();
- endphoneme = CompileVowelTransition(2);
- break;
-
- case kTONESPEC:
- endphoneme = CompileToneSpec();
- break;
-
- case kCONTINUE:
- *prog_out++ = i_CONTINUE;
- DecThenCount();
- break;
-
- case kRETURN:
- *prog_out++ = i_RETURN;
- break;
-
- case kINCLUDE:
- case kPHONEMENUMBER:
- case kPHONEMETABLE:
- error("Missing 'endphoneme' before '%s'",item_string); // drop through to endphoneme
- case kENDPHONEME:
- case kENDPROCEDURE:
- endphoneme = 1;
- if(if_level > 0)
- {
- error("Missing ENDIF",NULL);
- }
- if((prog_out > prog_buf) && (if_stack[0].returned == 0))
- {
- *prog_out++ = i_RETURN;
- }
- break;
- }
-
- break;
- }
- }
-
- if(endphoneme != 1)
- {
- error("'endphoneme' not expected here",NULL);
- }
-
- if(compile_phoneme)
- {
- if(phoneme_out->type == phINVALID)
- {
- error("Phoneme type is missing",NULL);
- phoneme_out->type = 0;
- }
- phoneme_out->phflags = place_articulation << 16;
- phoneme_out->phflags |= phoneme_flags;
-
- if(phoneme_out->phflags & phVOICED)
- {
- if(phoneme_out->type == phSTOP)
- phoneme_out->type = phVSTOP;
- else
- if(phoneme_out->type == phFRICATIVE)
- phoneme_out->type = phVFRICATIVE;
- }
-
- if(phoneme_out->std_length == 0)
- {
- if(phoneme_out->type == phVOWEL)
- phoneme_out->std_length = 180/2; // default length for vowel
- }
-
- phoneme_out->phflags |= phLOCAL; //declared in this phoneme table
-
- if(phoneme_out->type == phDELETED)
- {
- phoneme_out->mnemonic = 0x01; // will not be recognised
- }
- }
-
- DecompilePhoneme(f_errors, phoneme_out, compile_phoneme);
-
- if(prog_out > prog_buf)
- {
- // write out the program for this phoneme
- fflush(f_phindex);
- phoneme_out->program = ftell(f_phindex) / sizeof(USHORT);
-
- if(f_prog_log != NULL)
- {
- phoneme_prog_log.addr = phoneme_out->program;
- phoneme_prog_log.length = prog_out - prog_buf;
- fwrite(&phoneme_prog_log, 1, sizeof(phoneme_prog_log), f_prog_log);
- }
-
- if(compile_phoneme == 0)
- {
- proc_addr[n_procs++] = ftell(f_phindex) / sizeof(USHORT);
- }
- fwrite(prog_buf, sizeof(USHORT), prog_out - prog_buf, f_phindex);
- }
-
- return(0);
- } // end of CompilePhoneme
-
-
-
-
-
- static void WritePhonemeTables()
- {//=============================
- int ix;
- int j;
- int n;
- int value;
- int count;
- PHONEME_TAB *p;
-
- value = n_phoneme_tabs;
- fputc(value,f_phtab);
- fputc(0,f_phtab);
- fputc(0,f_phtab);
- fputc(0,f_phtab);
-
- for(ix=0; ix<n_phoneme_tabs; ix++)
- {
- p = phoneme_tab_list2[ix].phoneme_tab_ptr;
- n = n_phcodes_list[ix];
- p[n].mnemonic = 0; // terminate the phoneme table
-
- // count number of locally declared phonemes
- count=0;
- for(j=0; j<n; j++)
- {
- if(ix==0)
- p[j].phflags |= phLOCAL; // write all phonemes in the base phoneme table
-
- if(p[j].phflags & phLOCAL)
- count++;
- }
- phoneme_tab_list2[ix].n_phonemes = count+1;
-
- fputc(count+1,f_phtab);
- fputc(phoneme_tab_list2[ix].includes,f_phtab);
- fputc(0,f_phtab);
- fputc(0,f_phtab);
- Write4Bytes(f_phtab, phoneme_tab_list2[ix].equivalence_tables); // byte index into phondata for equivalence tables
-
- fwrite(phoneme_tab_list2[ix].name,1,N_PHONEME_TAB_NAME,f_phtab);
-
- for(j=0; j<n; j++)
- {
- if(p[j].phflags & phLOCAL)
- {
- // this bit is set temporarily to incidate a local phoneme, declared in
- // in the current phoneme file
- p[j].phflags &= ~phLOCAL;
- fwrite(&p[j],sizeof(PHONEME_TAB),1,f_phtab);
- }
- }
- fwrite(&p[n],sizeof(PHONEME_TAB),1,f_phtab); // include the extra list-terminator phoneme entry
- free(p);
- }
- } // end of WritePhonemeTables
-
-
- static void EndPhonemeTable()
- {//==========================
- int ix;
- int *pw;
- int length;
-
- if(n_phoneme_tabs == 0)
- return;
-
- fprintf(f_errors,"\n");
-
- // check that all referenced phonemes have been declared
- for(ix=0; ix<n_phcodes; ix++)
- {
- if(phoneme_tab2[ix].type == phINVALID)
- {
- fprintf(f_errors,"%3d: Phoneme [%s] not declared, referenced at line %d\n",linenum,
- WordToString(phoneme_tab2[ix].mnemonic),int(phoneme_tab2[ix].program));
- error_count++;
- phoneme_tab2[ix].type = 0; // prevent the error message repeating
- }
- }
-
- n_phcodes_list[n_phoneme_tabs-1] = n_phcodes;
-
- if((length = p_equivalence - equivalence_buf) > 0)
- {
- // terminate the list of phoneme equivalence tables
- pw = (int *)p_equivalence;
- pw[0] = 0;
-
- // write the equivalence data into phondata, and remember it's address
- ix = ftell(f_phdata);
- fprintf(f_phcontents,"Q 0x%.5x %s\n", ix, phoneme_tab_list2[n_phoneme_tabs-1].name);
- phoneme_tab_list2[n_phoneme_tabs-1].equivalence_tables = ix;
- fwrite(equivalence_buf, length+4, 1, f_phdata);
- }
- }
-
-
- static void StartPhonemeTable(const char *name)
- {//============================================
- int ix;
- int j;
- PHONEME_TAB *p;
-
- fprintf(f_errors,"______________________________\nPhoneme Table: '%s'\n",name);
-
- if(n_phoneme_tabs >= N_PHONEME_TABS-1)
- {
- Error("Too many phonemetables");
- return;
- }
- p = (PHONEME_TAB *)calloc(sizeof(PHONEME_TAB),N_PHONEME_TAB);
-
- if(p == NULL)
- {
- Error("Out of memory");
- return;
- }
-
- if(gui_flag)
- progress->Update(n_phoneme_tabs);
-
- memset(&phoneme_tab_list2[n_phoneme_tabs], 0, sizeof(PHONEME_TAB_LIST));
- phoneme_tab_list2[n_phoneme_tabs].phoneme_tab_ptr = phoneme_tab2 = p;
- strncpy0(phoneme_tab_list2[n_phoneme_tabs].name, name, N_PHONEME_TAB_NAME);
- n_phcodes = 1;
- phoneme_tab_list2[n_phoneme_tabs].includes = 0;
- p_equivalence = equivalence_buf;
-
- if(n_phoneme_tabs > 0)
- {
- NextItem(tSTRING); // name of base phoneme table
- for(ix=0; ix<n_phoneme_tabs; ix++)
- {
- if(strcmp(item_string,phoneme_tab_list2[ix].name)==0)
- {
- phoneme_tab_list2[n_phoneme_tabs].includes = ix+1;
-
- // initialise the new phoneme table with the contents of this one
- memcpy(phoneme_tab2,phoneme_tab_list2[ix].phoneme_tab_ptr,sizeof(PHONEME_TAB)*N_PHONEME_TAB);
- n_phcodes = n_phcodes_list[ix];
-
- // clear "local phoneme" bit"
- for(j=0; j<n_phcodes; j++)
- phoneme_tab2[j].phflags &= ~phLOCAL;
- break;
- }
- }
- if(ix == n_phoneme_tabs)
- {
- error("Can't find base phonemetable '%s'",item_string);
- }
- }
- else
- {
- ReservePhCodes();
- }
-
- n_phoneme_tabs++;
- } // end of StartPhonemeTable
-
-
- static void CompileEquivalents()
- {//=============================
- // a list of phonemes in another language and the equivalent phoneme strings in this language
-
- int ix;
- int n_names;
- int n_bytes;
- int foreign_phoneme;
- int foreign_error = 0;
- int remove_stress = 0;
- char *p_start;
- char *p;
- int foreign_table;
- char foreign_table_name[40];
- char line_buf[80];
- char names[6][80];
- char phcode[7];
- char save_voice_name[80];
-
- NextItem(tSTRING);
- strcpy(foreign_table_name, item_string);
- strcpy(save_voice_name,voice_name2);
-
- if((foreign_table = SelectPhonemeTableName(foreign_table_name)) < 0)
- {
- if(strcmp(foreign_table_name, "NULL") != 0)
- {
- error("Unknown phoneme table '%s'", foreign_table_name);
- }
- foreign_error = 1;
- foreign_phoneme = 0;
- }
-
- p_start = p_equivalence;
- p_equivalence += 8;
-
- p_start[0] = foreign_table;
-
- linenum--;
- while(!feof(f_in))
- {
- linenum++;
- if(fgets(line_buf, sizeof(line_buf), f_in) == NULL)
- break;
-
- if((p = strstr(line_buf,"//")) != NULL)
- *p = 0;
-
- for(ix=0; ix<6; ix++)
- names[ix][0] = 0;
- n_names = sscanf(line_buf,"%s %s %s %s %s %s",names[0],names[1],names[2],names[3],names[4],names[5]);
- if(n_names < 1)
- continue;
-
- if(strcmp(names[0],"endphoneme") == 0)
- break;
-
- if(foreign_error)
- continue;
-
- if(strcmp(names[0],"remove_stress") == 0)
- {
- remove_stress = 1;
- continue;
- }
-
- if(p_equivalence > &equivalence_buf[sizeof(equivalence_buf) - 16])
- {
- error("'equivalents' tables are too large",NULL);
- break;
- }
-
- if(foreign_error == 0)
- {
- phcode[0] = foreign_phoneme = LookupPhonemeString(names[0]);
- if(foreign_phoneme == 0)
- {
- sprintf(line_buf,"%s/%s", foreign_table_name, names[0]);
- error("Unknown phoneme '%s'", line_buf);
- }
- }
-
- for(ix=1; ix<n_names; ix++)
- {
- phcode[ix] = LookupPhoneme(names[ix], 1);
- }
-
- // only write a translation if it has an effect
- if((n_names > 2) || (phcode[0] != phcode[1]))
- {
- // write: foreign phoneme number, then a string of local phoneme numbers
- memcpy(p_equivalence, phcode, n_names);
- p_equivalence += n_names;
- *p_equivalence++ = 0;
- }
- }
- *p_equivalence++ = 0;
-
- p_equivalence = (char *)((long int)(p_equivalence + 3) & ~0x3); // align to word boundary
- n_bytes = p_equivalence - p_start;
- p_start[1] = remove_stress;
- n_bytes = n_bytes / 4;
- p_start[2] = n_bytes >> 8; // index of next table
- p_start[3] = n_bytes;
-
- LoadVoice(voice_name2,0); // reset the original phoneme table
- LoadVoiceVariant(save_voice_name,0);
- } // end of CompileEquivalents
-
-
-
- static void CompilePhonemeFiles()
- {//==============================
- int item;
- FILE *f;
- char buf[sizeof(path_source)+120];
-
- linenum = 1;
-
- count_references = 0;
- duplicate_references = 0;
- count_frames = 0;
- n_procs = 0;
-
- for(;;)
- {
- if(feof(f_in))
- {
- // end of file, go back to previous from, from which this was included
-
- if(stack_ix == 0)
- break; // end of top level, finished
- fclose(f_in);
- f_in = stack[--stack_ix].file;
- strcpy(current_fname,stack[stack_ix].fname);
- linenum = stack[stack_ix].linenum;
- fprintf(f_errors,"\n\n");
- }
-
- item = NextItem(tKEYWORD);
-
- switch(item)
- {
- case kINCLUDE:
- NextItem(tSTRING);
- sprintf(buf,"%s%s",path_source,item_string);
- if((stack_ix < N_STACK) && (f = fopen_log(f_errors,buf,"rb")) != NULL)
- {
- fprintf(f_errors,"include %s\n",item_string);
- stack[stack_ix].linenum = linenum;
- strcpy(stack[stack_ix].fname,current_fname);
- stack[stack_ix++].file = f_in;
-
- f_in = f;
- strncpy0(current_fname,item_string,sizeof(current_fname));
- linenum = 1;
- }
- break;
-
- case kPHONEMETABLE:
- EndPhonemeTable();
- NextItem(tSTRING); // name of the new phoneme table
- StartPhonemeTable(item_string);
- break;
-
- case kPHONEMESTART:
- if(n_phoneme_tabs == 0)
- {
- Error("phonemetable is missing");
- return;
- }
- CompilePhoneme(1);
- break;
-
- case kPROCEDURE:
- CompilePhoneme(0);
- break;
-
- case kEQUIVALENTS:
- CompileEquivalents();
- break;
-
- default:
- if(!feof(f_in))
- Error("Keyword 'phoneme' expected");
- break;
- }
- }
- phoneme_tab2[n_phcodes+1].mnemonic = 0; // terminator
- } // end of CompilePhonemeFiles
-
-
-
- static void CompilePhonemeData2(const char *source)
- {//================================================
- char fname[sizeof(path_source)+40];
- wxString report;
- wxString report_dict;
-
- #ifdef MAKE_ENVELOPES
- make_envs();
- #endif
-
- n_envelopes = 0;
- error_count = 0;
- memset(markers_used,0,sizeof(markers_used));
-
- f_errors = stderr;
-
- strncpy0(current_fname,source,sizeof(current_fname));
-
- strncpy0(fname,path_phfile.mb_str(wxConvLocal),sizeof(fname));
- f_in = fopen_log(f_errors,fname,"rb");
- if(f_in == NULL)
- {
- if(gui_flag)
- {
- wxString phfile = wxFileSelector(_T("Master phonemes file"),path_phsource,
- _T(""),_T(""),_T("*"),wxOPEN);
-
- if(!phfile.IsEmpty())
- {
- path_phfile = phfile;
- }
- }
-
- strncpy0(fname,path_phfile.mb_str(wxConvLocal),sizeof(fname));
- f_in = fopen_log(f_errors,fname,"rb");
- if(f_in == NULL)
- {
- wxLogError(_T("Can't read master phonemes file:\n") + wxString(fname,wxConvLocal));
- return;
- }
- }
-
- progress_max = 0;
- while(fgets(fname,sizeof(fname),f_in) != NULL)
- {
- // count the number of phoneme tables declared in the master phonemes file
- if(memcmp(fname,"phonemetable",12)==0)
- progress_max++;
- }
- rewind(f_in);
-
- sprintf(fname,"%s%s",path_source,"error_log");
- if((f_errors = fopen_log(f_errors,fname,"w")) == NULL)
- f_errors = stderr;
-
- sprintf(fname,"%s/%s",path_home,"phondata-manifest");
- if((f_phcontents = fopen_log(f_phcontents,fname,"w")) == NULL)
- f_phcontents = stderr;
-
- fprintf (f_phcontents,
- "# This file lists the type of data that has been compiled into the\n"
- "# phondata file\n"
- "#\n"
- "# The first character of a line indicates the type of data:\n"
- "# S - A SPECT_SEQ structure\n"
- "# W - A wavefile segment\n"
- "# E - An envelope\n"
- "# Q - Phoneme equivalence tables\n"
- "#\n"
- "# Address is the displacement within phondata of this item\n"
- "#\n"
- "# Address Data file\n"
- "# ------- ---------\n");
-
-
- sprintf(fname,"%s/%s",path_home,"phondata");
- f_phdata = fopen_log(f_errors,fname,"wb");
-
- sprintf(fname,"%s/%s",path_home,"phonindex");
- f_phindex = fopen_log(f_errors,fname,"wb");
-
- sprintf(fname,"%s/%s",path_home,"phontab");
- f_phtab = fopen_log(f_errors,fname,"wb");
-
- if(f_phdata==NULL || f_phindex==NULL || f_phtab==NULL)
- {
- return;
- }
-
- sprintf(fname,"%scompile_prog_log",path_source);
- f_prog_log = fopen_log(f_errors,fname,"wb");
-
- if(gui_flag)
- {
- progress = new wxProgressDialog(_T("Compiling"),_T(""),progress_max);
- }
- else
- {
- fprintf(stderr,"Compiling phoneme data: %s\n",path_source);
- }
-
- // write a word so that further data doesn't start at displ=0
- Write4Bytes(f_phdata,version_phdata);
- Write4Bytes(f_phindex,version_phdata);
-
- memset(ref_hash_tab,0,sizeof(ref_hash_tab));
-
- n_phoneme_tabs = 0;
- stack_ix = 0;
- StartPhonemeTable("base");
- CompilePhonemeFiles();
-
- EndPhonemeTable();
- WritePhonemeTables();
-
- fprintf(f_errors,"\nRefs %d, Reused %d\n",count_references,duplicate_references);
- fclose(f_in);
- fclose(f_phdata);
- fclose(f_errors);
- fclose(f_prog_log);
- fclose(f_phindex);
- fclose(f_phtab);
- fclose(f_phcontents);
-
- LoadPhData();
- LoadVoice(voice_name2,0);
-
- CompileReport();
- report_dict = CompileAllDictionaries();
- #ifdef deleted
- DrawEnvelopes();
- #endif
-
- if(gui_flag)
- {
- delete progress;
- }
-
- report.Printf(_T("Compiled phonemes: %d errors."),error_count);
- if(error_count > 0)
- {
- report += _T(" See file: 'phsource/error_log'.");
- wxLogError(report);
- }
- wxLogStatus(report + report_dict);
-
- if(gui_flag == 0)
- {
- strncpy0(fname,(report+report_dict).mb_str(wxConvLocal),sizeof(fname));
- fprintf(stderr,"%s\n",fname);
-
- }
- } // end of CompilePhonemeData
-
-
-
- void CompileMbrola()
- {//=================
- char *p;
- FILE *f_in;
- FILE *f_out;
- int percent;
- int n;
- int *pw;
- int *pw_end;
- int count = 0;
- int control;
- char phoneme[40];
- char phoneme2[40];
- char name1[40];
- char name2[40];
- char mbrola_voice[40];
- char buf[sizeof(path_home)+30];
- int mbrola_ctrl = 20; // volume in 1/16 ths
- MBROLA_TAB data[N_PHONEME_TAB];
-
- wxString filepath = wxFileSelector(_T("Read Mbrola phonemes file"),path_phsource+_T("/mbrola"),_T(""),_T(""),_T("*"),wxOPEN);
- strcpy(buf,filepath.mb_str(wxConvLocal));
- if((f_in = fopen(buf,"r")) == NULL)
- {
- wxLogError(_T("Can't read: ")+filepath);
- return;
- }
-
- while(fgets(buf,sizeof(phoneme),f_in) != NULL)
- {
- buf[sizeof(phoneme)-1] = 0;
-
- if((p = strstr(buf,"//")) != NULL)
- *p = 0; // truncate line at comment
-
- if(memcmp(buf,"volume",6)==0)
- {
- mbrola_ctrl = atoi(&buf[6]);
- continue;
- }
-
- n = sscanf(buf,"%d %s %s %d %s %s",&control,phoneme,phoneme2,&percent,name1,name2);
- if(n >= 5)
- {
- data[count].name = StringToWord(phoneme);
- if(strcmp(phoneme2,"NULL")==0)
- data[count].next_phoneme = 0;
- else
- if(strcmp(phoneme2,"VWL")==0)
- data[count].next_phoneme = 2;
- else
- data[count].next_phoneme = StringToWord(phoneme2);
- data[count].mbr_name = 0;
- data[count].mbr_name2 = 0;
- data[count].percent = percent;
- data[count].control = control;
- if(strcmp(name1,"NULL")!=0)
- data[count].mbr_name = StringToWord(name1);
- if(n == 6)
- data[count].mbr_name2 = StringToWord(name2);
-
- count++;
- }
- }
- fclose(f_in);
-
- wxFileName filename = wxFileName(filepath);
- strcpy(mbrola_voice,filename.GetName().mb_str(wxConvLocal));
- sprintf(buf,"%s/mbrola_ph/%s_phtrans",path_home,mbrola_voice);
- if((f_out = fopen(buf,"wb")) == NULL)
- {
- wxLogError(_T("Can't write to: ")+wxString(buf,wxConvLocal));
- return;
- }
-
- data[count].name = 0; // list terminator
- Write4Bytes(f_out, mbrola_ctrl);
-
- pw_end = (int *)(&data[count+1]);
- for(pw = (int *)data; pw < pw_end; pw++)
- {
- Write4Bytes(f_out, *pw);
- }
- fclose(f_out);
- wxLogStatus(_T("Mbrola translation file: %d phonemes"),count);
- } // end of CompileMbrola
-
-
-
- static const char *preset_tune_names[] = {
- "s1", "c1", "q1", "e1", NULL};
-
- static const TUNE default_tune = {
- {0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0},
- {0, 40, 24, 8, 0, 0, 0, 0},
- 46, 57, PITCHfall, 16, 0, 0,
- 255, 78, 50, 255,
- 3, 5,
- {-7,-7,-7}, {-7,-7,-7},
- PITCHfall, 64, 8,
- PITCHfall, 70, 18, 24, 12,
- PITCHfall, 70, 18, 24, 12, 0,
- {0,0,0,0,0,0,0,0}, 0
- };
-
- #define N_TUNE_NAMES 100
-
- MNEM_TAB envelope_names[] = {
- {"fall", 0},
- {"rise", 2},
- {"fall-rise", 4},
- {"fall-rise2", 6},
- {"rise-fall", 8},
- {"fall-rise3",10},
- {"fall-rise4",12},
- {"fall2", 14},
- {"rise2", 16},
- {"rise-fall-rise", 18},
- {NULL, -1} };
-
-
- // env_fallrise3, env_fallrise3,
- // env_fallrise4, env_fallrise4,
- // env_fall2, env_fall2,
- // env_rise2, env_rise2,
- // env_risefallrise, env_risefallrise
-
- int LookupEnvelope(const char *name)
- {//=================================
- return(LookupMnem(envelope_names, name));
- }
-
-
- void CompileIntonation()
- {//=====================
- int ix;
- char *p;
- char c;
- int keyword;
- int compiling_tune = 0;
- int n_tune_names = 0;
- int done_split;
- int done_onset = 0;
- int done_last = 0;
- int n_preset_tunes = 0;
- int found;
- int tune_number = 0;
- FILE *f_out;
- wxString report;
- TUNE *tune_data;
- TUNE new_tune;
-
-
- char name[12];
- char fname_errors[sizeof(path_source)+120];
- char tune_names[N_TUNE_NAMES][12];
- char buf[sizeof(path_source)+120];
-
- error_count = 0;
-
- sprintf(fname_errors,"%s%s",path_source,"error_intonation");
- if((f_errors = fopen(fname_errors,"w")) == NULL)
- f_errors = stderr;
-
- sprintf(buf,"%sintonation.txt",path_source);
- if((f_in = fopen(buf, "r")) == NULL)
- {
- sprintf(buf,"%sintonation",path_source);
- if((f_in = fopen_log(f_errors, buf, "r")) == NULL)
- {
- wxLogError(_T("Can't read file: ") + wxString(buf,wxConvLocal));
- fclose(f_errors);
- return;
- }
- }
-
-
- for(ix=0; preset_tune_names[ix] != NULL; ix++)
- {
- strcpy(tune_names[ix], preset_tune_names[ix]);
- }
- n_tune_names = ix;
- n_preset_tunes = ix;
-
- // make a list of the tune names
- while(!feof(f_in))
- {
- if(fgets(buf,sizeof(buf),f_in) == NULL)
- break;
-
- if((memcmp(buf,"tune",4)==0) && isspace(buf[4]))
- {
- p = &buf[5];
- while(isspace(*p)) p++;
-
- ix = 0;
- while((ix < int(sizeof(name) - 1)) && !isspace(*p))
- {
- name[ix++] = *p++;
- }
- name[ix] = 0;
-
- found = 0;
- for(ix = 0; ix < n_tune_names; ix++)
- {
- if(strcmp(name, tune_names[ix]) == 0)
- {
- found = 1;
- break;
- }
- }
-
- if(found == 0)
- {
- strncpy0(tune_names[n_tune_names++], name, sizeof(name));
-
- if(n_tune_names >= N_TUNE_NAMES)
- break;
- }
- }
- }
- rewind(f_in);
- linenum = 1;
-
- tune_data = (TUNE *)calloc(sizeof(TUNE), n_tune_names);
- if(tune_data == NULL)
- {
- fprintf(f_errors, "Failed to allocate data for tunes\n");
- fclose(f_in);
- fclose(f_errors);
- return;
- }
-
- sprintf(buf,"%s/intonations",path_home);
- f_out = fopen_log(f_errors, buf, "wb");
- if(f_out == NULL)
- {
- fclose(f_in);
- fclose(f_errors);
- return;
- }
-
- while(!feof(f_in))
- {
- keyword = NextItem(tINTONATION);
-
- switch(keyword)
- {
- case kTUNE:
- if(compiling_tune)
- {
- }
- compiling_tune = 1;
- done_split = 0;
-
- memcpy(&new_tune, &default_tune, sizeof(TUNE));
- NextItem(tSTRING);
- strncpy0(new_tune.name, item_string, sizeof(new_tune.name));
-
- found = 0;
- tune_number = 0;
- for(ix=0; ix < n_tune_names; ix++)
- {
- if(strcmp(new_tune.name, tune_names[ix]) == 0)
- {
- found = 1;
- tune_number = ix;
-
- if(tune_data[ix].name[0] != 0)
- found = 2;
- break;
- }
- }
- // fprintf(f_errors,"tune %s (%d)\n", new_tune.name, tune_number);
- if(found == 2)
- {
- error("Duplicate tune name: '%s'",new_tune.name);
- }
- if(found == 0)
- {
- error("Bad tune name: '%s;", new_tune.name);
- }
- break;
-
- case kENDTUNE:
- compiling_tune = 0;
-
- if(done_onset == 0)
- {
- new_tune.unstr_start[0] = new_tune.unstr_start[1];
- new_tune.unstr_end[0] = new_tune.unstr_end[1];
- }
- if(done_last == 0)
- {
- new_tune.unstr_start[2] = new_tune.unstr_start[1];
- new_tune.unstr_end[2] = new_tune.unstr_end[1];
- }
- memcpy(&tune_data[tune_number], &new_tune, sizeof(TUNE));
- break;
-
- case kTUNE_PREHEAD:
- new_tune.prehead_start = NextItem(tNUMBER);
- new_tune.prehead_end = NextItem(tNUMBER);
- break;
-
- case kTUNE_ONSET:
- new_tune.onset = NextItem(tNUMBER);
- new_tune.unstr_start[0] = NextItem(tSIGNEDNUMBER);
- new_tune.unstr_end[0] = NextItem(tSIGNEDNUMBER);
- done_onset = 1;
- break;
-
- case kTUNE_HEADLAST:
- new_tune.head_last = NextItem(tNUMBER);
- new_tune.unstr_start[2] = NextItem(tSIGNEDNUMBER);
- new_tune.unstr_end[2] = NextItem(tSIGNEDNUMBER);
- done_last = 1;
- break;
-
- case kTUNE_HEADENV:
- NextItem(tSTRING);
- if((ix = LookupEnvelope(item_string)) < 0)
- error("Bad envelope name: '%s'",item_string);
- else
- new_tune.stressed_env = ix;
- new_tune.stressed_drop = NextItem(tNUMBER);
- break;
-
- case kTUNE_HEAD:
- new_tune.head_max_steps = NextItem(tNUMBER);
- new_tune.head_start = NextItem(tNUMBER);
- new_tune.head_end = NextItem(tNUMBER);
- new_tune.unstr_start[1] = NextItem(tSIGNEDNUMBER);
- new_tune.unstr_end[1] = NextItem(tSIGNEDNUMBER);
- break;
-
- case kTUNE_HEADEXTEND:
- // up to 8 numbers
- for(ix=0; ix < int(sizeof(new_tune.head_extend)); ix++)
- {
- if(!isdigit(c = CheckNextChar()) && (c != '-'))
- break;
-
- new_tune.head_extend[ix] = (NextItem(tSIGNEDNUMBER) * 64) / 100; // convert from percentage to 64ths
- }
- new_tune.n_head_extend = ix; // number of values
- break;
-
- case kTUNE_NUCLEUS0:
- NextItem(tSTRING);
- if((ix = LookupEnvelope(item_string)) < 0)
- {
- error("Bad envelope name: '%s'",item_string);
- break;
- }
- new_tune.nucleus0_env = ix;
- new_tune.nucleus0_max = NextItem(tNUMBER);
- new_tune.nucleus0_min = NextItem(tNUMBER);
- break;
-
- case kTUNE_NUCLEUS1:
- NextItem(tSTRING);
- if((ix = LookupEnvelope(item_string)) < 0)
- {
- error("Bad envelope name: '%s'",item_string);
- break;
- }
- new_tune.nucleus1_env = ix;
- new_tune.nucleus1_max = NextItem(tNUMBER);
- new_tune.nucleus1_min = NextItem(tNUMBER);
- new_tune.tail_start = NextItem(tNUMBER);
- new_tune.tail_end = NextItem(tNUMBER);
-
- if(!done_split)
- {
- // also this as the default setting for 'split'
- new_tune.split_nucleus_env = ix;
- new_tune.split_nucleus_max = new_tune.nucleus1_max;
- new_tune.split_nucleus_min = new_tune.nucleus1_min;
- new_tune.split_tail_start = new_tune.tail_start;
- new_tune.split_tail_end = new_tune.tail_end;
- }
- break;
-
- case kTUNE_SPLIT:
- NextItem(tSTRING);
- if((ix = LookupEnvelope(item_string)) < 0)
- {
- error("Bad envelope name: '%s'",item_string);
- break;
- }
- done_split = 1;
- new_tune.split_nucleus_env = ix;
- new_tune.split_nucleus_max = NextItem(tNUMBER);
- new_tune.split_nucleus_min = NextItem(tNUMBER);
- new_tune.split_tail_start = NextItem(tNUMBER);
- new_tune.split_tail_end = NextItem(tNUMBER);
- NextItem(tSTRING);
- item_string[12] = 0;
- for(ix=0; ix < n_tune_names; ix++)
- {
- if(strcmp(item_string, tune_names[ix]) == 0)
- break;
- }
-
- if(ix == n_tune_names)
- error("Tune '%s' not found",item_string);
- else
- new_tune.split_tune = ix;
- break;
-
- default:
- error("Unexpected: '%s'",item_string);
- break;
- }
- }
-
- for(ix = 0; ix < n_preset_tunes; ix++)
- {
- if(tune_data[ix].name[0] == 0)
- {
- error("Tune '%s' not defined", preset_tune_names[ix]);
- }
- }
- fwrite(tune_data, n_tune_names, sizeof(TUNE), f_out);
- fclose(f_in);
- fclose(f_out);
- fclose(f_errors);
-
- report.Printf(_T("Compiled %d intonation tunes: %d errors."),n_tune_names, error_count);
- wxLogStatus(report);
-
- if(error_count > 0)
- {
- DisplayErrorFile(fname_errors);
- }
- LoadPhData();
-
- } // end of CompileIntonation
-
-
-
- void CompilePhonemeData()
- {
- CompilePhonemeData2("phonemes");
- return;
- }
|