eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

synth_mbrola.cpp 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2007 by Jonathan Duddington *
  3. * email: [email protected] *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write see: *
  17. * <http://www.gnu.org/licenses/>. *
  18. ***************************************************************************/
  19. #include "StdAfx.h"
  20. #include <stdio.h>
  21. #include <ctype.h>
  22. #include <wctype.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <math.h>
  26. #include "speak_lib.h"
  27. #include "speech.h"
  28. #include "phoneme.h"
  29. #include "synthesize.h"
  30. #include "translate.h"
  31. #include "voice.h"
  32. int option_mbrola_phonemes;
  33. #ifdef INCLUDE_MBROLA
  34. extern int Read4Bytes(FILE *f);
  35. extern void SetPitch2(voice_t *voice, int pitch1, int pitch2, int *pitch_base, int *pitch_range);
  36. extern unsigned char *outbuf;
  37. #ifndef PLATFORM_WINDOWS
  38. #include "mbrowrap.h"
  39. #else
  40. #include <windows.h>
  41. typedef void (WINAPI *PROCVV)(void);
  42. typedef void (WINAPI *PROCVI)(int);
  43. typedef void (WINAPI *PROCVF)(float);
  44. typedef int (WINAPI *PROCIV)();
  45. typedef int (WINAPI *PROCIC) (char *);
  46. typedef int (WINAPI *PROCISI)(short *,int);
  47. typedef char* (WINAPI *PROCVCI)(char *,int);
  48. PROCIC init_MBR;
  49. PROCIC write_MBR;
  50. PROCIV flush_MBR;
  51. PROCISI read_MBR;
  52. PROCVV close_MBR;
  53. PROCVV reset_MBR;
  54. PROCIV lastError_MBR;
  55. PROCVCI lastErrorStr_MBR;
  56. PROCVI setNoError_MBR;
  57. PROCIV getFreq_MBR;
  58. PROCVF setVolumeRatio_MBR;
  59. HINSTANCE hinstDllMBR = NULL;
  60. BOOL load_MBR()
  61. {
  62. if(hinstDllMBR != NULL)
  63. return TRUE; // already loaded
  64. if ((hinstDllMBR=LoadLibraryA("mbrola.dll")) == 0)
  65. return FALSE;
  66. init_MBR =(PROCIC) GetProcAddress(hinstDllMBR,"init_MBR");
  67. write_MBR =(PROCIC) GetProcAddress(hinstDllMBR,"write_MBR");
  68. flush_MBR =(PROCIV) GetProcAddress(hinstDllMBR,"flush_MBR");
  69. read_MBR =(PROCISI) GetProcAddress(hinstDllMBR,"read_MBR");
  70. close_MBR =(PROCVV) GetProcAddress(hinstDllMBR,"close_MBR");
  71. reset_MBR =(PROCVV) GetProcAddress(hinstDllMBR,"reset_MBR");
  72. lastError_MBR =(PROCIV) GetProcAddress(hinstDllMBR,"lastError_MBR");
  73. lastErrorStr_MBR =(PROCVCI) GetProcAddress(hinstDllMBR,"lastErrorStr_MBR");
  74. setNoError_MBR =(PROCVI) GetProcAddress(hinstDllMBR,"setNoError_MBR");
  75. setVolumeRatio_MBR =(PROCVF) GetProcAddress(hinstDllMBR,"setVolumeRatio_MBR");
  76. return TRUE;
  77. }
  78. void unload_MBR()
  79. {
  80. if (hinstDllMBR)
  81. {
  82. FreeLibrary (hinstDllMBR);
  83. hinstDllMBR=NULL;
  84. }
  85. }
  86. #endif // windows
  87. static MBROLA_TAB *mbrola_tab = NULL;
  88. static int mbrola_control = 0;
  89. static int mbr_name_prefix = 0;
  90. espeak_ERROR LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, int srate)
  91. {//===================================================================================
  92. // Load a phoneme name translation table from espeak-data/mbrola
  93. int size;
  94. int ix;
  95. int *pw;
  96. FILE *f_in;
  97. char path[sizeof(path_home)+15];
  98. mbrola_name[0] = 0;
  99. mbrola_delay = 0;
  100. mbr_name_prefix = 0;
  101. if(mbrola_voice == NULL)
  102. {
  103. samplerate = samplerate_native;
  104. SetParameter(espeakVOICETYPE,0,0);
  105. return(EE_OK);
  106. }
  107. sprintf(path,"%s/mbrola/%s",path_home,mbrola_voice);
  108. #ifdef PLATFORM_POSIX
  109. // if not found, then also look in
  110. // usr/share/mbrola/xx, /usr/share/mbrola/xx/xx, /usr/share/mbrola/voices/xx
  111. if(GetFileLength(path) <= 0)
  112. {
  113. sprintf(path,"/usr/share/mbrola/%s",mbrola_voice);
  114. if(GetFileLength(path) <= 0)
  115. {
  116. sprintf(path,"/usr/share/mbrola/%s/%s",mbrola_voice,mbrola_voice);
  117. if(GetFileLength(path) <= 0)
  118. {
  119. sprintf(path,"/usr/share/mbrola/voices/%s",mbrola_voice);
  120. }
  121. }
  122. }
  123. close_MBR();
  124. #endif
  125. #ifdef PLATFORM_WINDOWS
  126. if(load_MBR() == FALSE) // load mbrola.dll
  127. {
  128. fprintf(stderr, "Can't load mbrola.dll\n");
  129. return(EE_INTERNAL_ERROR);
  130. }
  131. #endif
  132. if(init_MBR(path) != 0) // initialise the required mbrola voice
  133. return(EE_NOT_FOUND);
  134. setNoError_MBR(1); // don't stop on phoneme errors
  135. // read eSpeak's mbrola phoneme translation data, eg. en1_phtrans
  136. sprintf(path,"%s/mbrola_ph/%s",path_home,phtrans);
  137. size = GetFileLength(path);
  138. if((f_in = fopen(path,"rb")) == NULL) {
  139. close_MBR();
  140. return(EE_NOT_FOUND);
  141. }
  142. if((mbrola_tab = (MBROLA_TAB *)realloc(mbrola_tab,size)) == NULL)
  143. {
  144. fclose(f_in);
  145. close_MBR();
  146. return(EE_INTERNAL_ERROR);
  147. }
  148. mbrola_control = Read4Bytes(f_in);
  149. pw = (int *)mbrola_tab;
  150. for(ix=4; ix<size; ix+=4)
  151. {
  152. *pw++ = Read4Bytes(f_in);
  153. }
  154. size = fread(mbrola_tab,1,size,f_in);
  155. fclose(f_in);
  156. setVolumeRatio_MBR((float)(mbrola_control & 0xff) /16.0f);
  157. // srate = getFreq_MBR();
  158. samplerate = srate;
  159. if(srate == 22050)
  160. SetParameter(espeakVOICETYPE,0,0);
  161. else
  162. SetParameter(espeakVOICETYPE,1,0);
  163. strcpy(mbrola_name,mbrola_voice);
  164. // mbrola_delay = 3800; // improve synchronization of events
  165. mbrola_delay = 1000; // improve synchronization of events
  166. return(EE_OK);
  167. } // end of LoadMbrolaTable
  168. static int GetMbrName(PHONEME_LIST *plist, PHONEME_TAB *ph, PHONEME_TAB *ph_prev, PHONEME_TAB *ph_next, int *name2, int *split, int *control)
  169. {//==========================================================================================================================================
  170. // Look up a phoneme in the mbrola phoneme name translation table
  171. // It may give none, 1, or 2 mbrola phonemes
  172. MBROLA_TAB *pr;
  173. PHONEME_TAB *other_ph;
  174. int found = 0;
  175. static int mnem;
  176. // control
  177. // bit 0 skip the next phoneme
  178. // bit 1 match this and Previous phoneme
  179. // bit 2 only at the start of a word
  180. // bit 3 don't match two phonemes across a word boundary
  181. // bit 4 add this phoneme name as a prefix to the next phoneme name (used for de4 phoneme prefix '?')
  182. // bit 5 only in stressed syllable
  183. // bit 6 only at the end of a word
  184. *name2=0;
  185. *split=0;
  186. *control=0;
  187. mnem = ph->mnemonic;
  188. pr = mbrola_tab;
  189. while(pr->name != 0)
  190. {
  191. if(mnem == pr->name)
  192. {
  193. if(pr->next_phoneme == 0)
  194. found = 1;
  195. else
  196. if((pr->next_phoneme == ':') && (plist->synthflags & SFLAG_LENGTHEN))
  197. {
  198. found = 1;
  199. }
  200. else
  201. {
  202. if(pr->control & 2)
  203. other_ph = ph_prev;
  204. else
  205. if((pr->control & 8) && ((plist+1)->newword))
  206. other_ph = phoneme_tab[phPAUSE]; // don't match the next phoneme over a word boundary
  207. else
  208. other_ph = ph_next;
  209. if((pr->next_phoneme == other_ph->mnemonic) ||
  210. ((pr->next_phoneme == 2) && (other_ph->type == phVOWEL)) ||
  211. ((pr->next_phoneme == '_') && (other_ph->type == phPAUSE)))
  212. {
  213. found = 1;
  214. }
  215. }
  216. if((pr->control & 4) && (plist->newword == 0)) // only at start of word
  217. found = 0;
  218. if((pr->control & 0x40) && (plist[1].newword == 0)) // only at the end of a word
  219. found = 0;
  220. if((pr->control & 0x20) && (plist->stresslevel < plist->wordstress))
  221. found = 0; // only in stressed syllables
  222. if(found)
  223. {
  224. *name2 = pr->mbr_name2;
  225. *split = pr->percent;
  226. *control = pr->control;
  227. if(pr->control & 0x10)
  228. {
  229. mbr_name_prefix = pr->mbr_name;
  230. return(0);
  231. }
  232. mnem = pr->mbr_name;
  233. break;
  234. }
  235. }
  236. pr++;
  237. }
  238. if(mbr_name_prefix != 0)
  239. {
  240. mnem = (mnem << 8) | (mbr_name_prefix & 0xff);
  241. }
  242. mbr_name_prefix = 0;
  243. return(mnem);
  244. }
  245. static char *WritePitch(int env, int pitch1, int pitch2, int split, int final)
  246. {//===========================================================================
  247. // final=1: only give the final pitch value.
  248. int x;
  249. int ix;
  250. int pitch_base;
  251. int pitch_range;
  252. int p1,p2,p_end;
  253. unsigned char *pitch_env;
  254. int max = -1;
  255. int min = 999;
  256. int y_max=0;
  257. int y_min=0;
  258. int env100 = 80; // apply the pitch change only over this proportion of the mbrola phoneme(s)
  259. int y2;
  260. int y[4];
  261. int env_split;
  262. char buf[50];
  263. static char output[50];
  264. output[0] = 0;
  265. pitch_env = envelope_data[env];
  266. SetPitch2(voice, pitch1, pitch2, &pitch_base, &pitch_range);
  267. env_split = (split * 128)/100;
  268. if(env_split < 0)
  269. env_split = 0-env_split;
  270. // find max and min in the pitch envelope
  271. for(x=0; x<128; x++)
  272. {
  273. if(pitch_env[x] > max)
  274. {
  275. max = pitch_env[x];
  276. y_max = x;
  277. }
  278. if(pitch_env[x] < min)
  279. {
  280. min = pitch_env[x];
  281. y_min = x;
  282. }
  283. }
  284. // set an additional pitch point half way through the phoneme.
  285. // but look for a maximum or a minimum and use that instead
  286. y[2] = 64;
  287. if((y_max > 0) && (y_max < 127))
  288. {
  289. y[2] = y_max;
  290. }
  291. if((y_min > 0) && (y_min < 127))
  292. {
  293. y[2] = y_min;
  294. }
  295. y[1] = y[2] / 2;
  296. y[3] = y[2] + (127 - y[2])/2;
  297. // set initial pitch
  298. p1 = ((pitch_env[0]*pitch_range)>>8) + pitch_base; // Hz << 12
  299. p_end = ((pitch_env[127]*pitch_range)>>8) + pitch_base;
  300. if(split >= 0)
  301. {
  302. sprintf(buf," 0 %d",p1/4096);
  303. strcat(output,buf);
  304. }
  305. // don't use intermediate pitch points for linear rise and fall
  306. if(env > 1)
  307. {
  308. for(ix=1; ix<4; ix++)
  309. {
  310. p2 = ((pitch_env[y[ix]]*pitch_range)>>8) + pitch_base;
  311. if(split > 0)
  312. {
  313. y2 = (y[ix] * env100)/env_split;
  314. }
  315. else
  316. if(split < 0)
  317. {
  318. y2 = ((y[ix]-env_split) * env100)/env_split;
  319. }
  320. else
  321. {
  322. y2 = (y[ix] * env100)/128;
  323. }
  324. if((y2 > 0) && (y2 <= env100))
  325. {
  326. sprintf(buf," %d %d",y2,p2/4096);
  327. strcat(output,buf);
  328. }
  329. }
  330. }
  331. p_end = p_end/4096;
  332. if(split <= 0)
  333. {
  334. sprintf(buf," %d %d",env100,p_end);
  335. strcat(output,buf);
  336. }
  337. if(env100 < 100)
  338. {
  339. sprintf(buf," %d %d",100,p_end);
  340. strcat(output,buf);
  341. }
  342. strcat(output,"\n");
  343. if(final)
  344. sprintf(output,"\t100 %d\n",p_end);
  345. return(output);
  346. } // end of WritePitch
  347. int MbrolaTranslate(PHONEME_LIST *plist, int n_phonemes, int resume, FILE *f_mbrola)
  348. {//=================================================================================
  349. // Generate a mbrola pho file
  350. unsigned int name;
  351. int len;
  352. int len1;
  353. PHONEME_TAB *ph;
  354. PHONEME_TAB *ph_next;
  355. PHONEME_TAB *ph_prev;
  356. PHONEME_LIST *p;
  357. PHONEME_LIST *next;
  358. PHONEME_DATA phdata;
  359. FMT_PARAMS fmtp;
  360. int pause = 0;
  361. int released;
  362. int name2;
  363. int control;
  364. int done;
  365. int len_percent;
  366. const char *final_pitch;
  367. char *ptr;
  368. char mbr_buf[120];
  369. static int phix;
  370. static int embedded_ix;
  371. static int word_count;
  372. if (!resume) {
  373. phix = 1;
  374. embedded_ix = 0;
  375. word_count = 0;
  376. }
  377. while (phix < n_phonemes)
  378. {
  379. if (WcmdqFree() < MIN_WCMDQ)
  380. return 1;
  381. ptr = mbr_buf;
  382. p = &plist[phix];
  383. next = &plist[phix+1];
  384. ph = p->ph;
  385. ph_prev = plist[phix-1].ph;
  386. ph_next = plist[phix+1].ph;
  387. if(p->synthflags & SFLAG_EMBEDDED)
  388. {
  389. DoEmbedded(&embedded_ix, p->sourceix);
  390. }
  391. if(p->newword & 4)
  392. DoMarker(espeakEVENT_SENTENCE, (p->sourceix & 0x7ff) + clause_start_char, 0, count_sentences);
  393. if(p->newword & 1)
  394. DoMarker(espeakEVENT_WORD, (p->sourceix & 0x7ff) + clause_start_char, p->sourceix >> 11, clause_start_word + word_count++);
  395. name = GetMbrName(p,ph,ph_prev,ph_next,&name2,&len_percent,&control);
  396. if(control & 1)
  397. phix++;
  398. if(name == 0) {
  399. phix++;
  400. continue; // ignore this phoneme
  401. }
  402. if((ph->type == phPAUSE) && (name == ph->mnemonic))
  403. {
  404. // a pause phoneme, which has not been changed by the translation
  405. name = '_';
  406. len = (p->length * speed.pause_factor)/256;
  407. // if(len == 0) continue;
  408. if(len == 0)
  409. len = 1;
  410. }
  411. else
  412. len = (80 * speed.wav_factor)/256;
  413. if(ph->code != phonEND_WORD)
  414. DoMarker(espeakEVENT_PHONEME, (p->sourceix & 0x7ff) + clause_start_char, 0, ph->mnemonic);
  415. ptr += sprintf(ptr,"%s\t",WordToString(name));
  416. if(name2 == '_')
  417. {
  418. // add a pause after this phoneme
  419. pause = len_percent;
  420. name2 = 0;
  421. }
  422. done = 0;
  423. final_pitch = "";
  424. switch(ph->type)
  425. {
  426. case phVOWEL:
  427. len = ph->std_length;
  428. if(p->synthflags & SFLAG_LENGTHEN)
  429. len += phoneme_tab[phonLENGTHEN]->std_length; // phoneme was followed by an extra : symbol
  430. if(ph_next->type == phPAUSE)
  431. len += 50; // lengthen vowels before a pause
  432. len = (len * p->length)/256;
  433. if(name2 == 0)
  434. {
  435. char *pitch = WritePitch(p->env,p->pitch1,p->pitch2,0,0);
  436. ptr += sprintf(ptr,"%d\t%s", len, pitch);
  437. }
  438. else
  439. {
  440. char *pitch;
  441. pitch = WritePitch(p->env,p->pitch1,p->pitch2,len_percent,0);
  442. len1 = (len * len_percent)/100;
  443. ptr += sprintf(ptr,"%d\t%s", len1, pitch);
  444. pitch = WritePitch(p->env,p->pitch1,p->pitch2,-len_percent,0);
  445. ptr += sprintf(ptr,"%s\t%d\t%s", WordToString(name2), len-len1, pitch);
  446. }
  447. done = 1;
  448. break;
  449. case phSTOP:
  450. released = 0;
  451. if(next->type==phVOWEL) released = 1;
  452. if(next->type==phLIQUID && !next->newword) released = 1;
  453. if(released == 0)
  454. p->synthflags |= SFLAG_NEXT_PAUSE;
  455. InterpretPhoneme(NULL, 0, p, &phdata);
  456. len = DoSample3(&phdata, 0, -1);
  457. len = (len * 1000)/samplerate; // convert to mS
  458. len += PauseLength(p->prepause,1);
  459. break;
  460. case phVSTOP:
  461. len = (80 * speed.wav_factor)/256;
  462. break;
  463. case phFRICATIVE:
  464. len = 0;
  465. InterpretPhoneme(NULL, 0, p, &phdata);
  466. if(p->synthflags & SFLAG_LENGTHEN)
  467. len = DoSample3(&phdata, p->length, -1); // play it twice for [s:] etc.
  468. len += DoSample3(&phdata, p->length, -1);
  469. len = (len * 1000)/samplerate; // convert to mS
  470. break;
  471. case phNASAL:
  472. if(next->type != phVOWEL)
  473. {
  474. memset(&fmtp, 0, sizeof(fmtp));
  475. InterpretPhoneme(NULL, 0, p, &phdata);
  476. fmtp.fmt_addr = phdata.sound_addr[pd_FMT];
  477. len = DoSpect2(p->ph, 0, &fmtp, p, -1);
  478. // len = DoSpect(p->ph,prev->ph,phoneme_tab[phonPAUSE],2,p,-1);
  479. len = (len * 1000)/samplerate;
  480. if(next->type == phPAUSE)
  481. len += 50;
  482. final_pitch = WritePitch(p->env,p->pitch1,p->pitch2,0,1);
  483. }
  484. break;
  485. case phLIQUID:
  486. if(next->type == phPAUSE)
  487. {
  488. len += 50;
  489. final_pitch = WritePitch(p->env,p->pitch1,p->pitch2,0,1);
  490. }
  491. break;
  492. }
  493. if(!done)
  494. {
  495. if(name2 != 0)
  496. {
  497. len1 = (len * len_percent)/100;
  498. ptr += sprintf(ptr,"%d\n%s\t",len1,WordToString(name2));
  499. len -= len1;
  500. }
  501. ptr += sprintf(ptr,"%d%s\n",len,final_pitch);
  502. }
  503. if(pause)
  504. {
  505. len += PauseLength(pause,0);
  506. ptr += sprintf(ptr,"_ \t%d\n",PauseLength(pause,0));
  507. pause = 0;
  508. }
  509. if(f_mbrola)
  510. {
  511. fwrite(mbr_buf,1,(ptr-mbr_buf),f_mbrola); // write .pho to a file
  512. }
  513. else
  514. {
  515. int res = write_MBR(mbr_buf);
  516. if (res < 0)
  517. return 0; /* don't get stuck on error */
  518. if (res == 0)
  519. return 1;
  520. wcmdq[wcmdq_tail][0] = WCMD_MBROLA_DATA;
  521. wcmdq[wcmdq_tail][1] = len;
  522. WcmdqInc();
  523. }
  524. phix++;
  525. }
  526. if(!f_mbrola)
  527. {
  528. flush_MBR();
  529. // flush the mbrola output buffer
  530. wcmdq[wcmdq_tail][0] = WCMD_MBROLA_DATA;
  531. wcmdq[wcmdq_tail][1] = 500;
  532. WcmdqInc();
  533. }
  534. return 0;
  535. } // end of MbrolaTranslate
  536. int MbrolaGenerate(PHONEME_LIST *phoneme_list, int *n_ph, int resume)
  537. {//==================================================================
  538. FILE *f_mbrola = NULL;
  539. if(*n_ph == 0)
  540. return(0);
  541. if(option_mbrola_phonemes)
  542. {
  543. // send mbrola data to a file, not to the mbrola library
  544. f_mbrola = f_trans;
  545. }
  546. int again = MbrolaTranslate(phoneme_list, *n_ph, resume, f_mbrola);
  547. if (!again)
  548. *n_ph = 0;
  549. return again;
  550. }
  551. int MbrolaFill(int length, int resume, int amplitude)
  552. {//==================================================
  553. // Read audio data from Mbrola (length is in millisecs)
  554. static int n_samples;
  555. int req_samples, result;
  556. int ix;
  557. short value16;
  558. int value;
  559. if (!resume)
  560. n_samples = samplerate * length / 1000;
  561. req_samples = (out_end - out_ptr)/2;
  562. if (req_samples > n_samples)
  563. req_samples = n_samples;
  564. result = read_MBR((short *)out_ptr, req_samples);
  565. if (result <= 0)
  566. return 0;
  567. for(ix=0; ix < result; ix++)
  568. {
  569. value16 = out_ptr[0] + (out_ptr[1] << 8);
  570. value = value16 * amplitude;
  571. value = value / 40; // adjust this constant to give a suitable amplitude for mbrola voices
  572. if(value > 0x7fff)
  573. value = 0x7fff;
  574. if(value < -0x8000)
  575. value = 0x8000;
  576. out_ptr[0] = value;
  577. out_ptr[1] = value >> 8;
  578. out_ptr += 2;
  579. }
  580. n_samples -= result;
  581. return n_samples ? 1 : 0;
  582. }
  583. void MbrolaReset(void)
  584. {//===================
  585. // Reset the Mbrola engine and flush the pending audio
  586. reset_MBR();
  587. }
  588. #else // INCLUDE_MBROLA
  589. // mbrola interface is not compiled, provide dummy functions.
  590. espeak_ERROR LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, int srate)
  591. {
  592. return(EE_INTERNAL_ERROR);
  593. }
  594. int MbrolaGenerate(PHONEME_LIST *phoneme_list, int *n_ph, int resume)
  595. {
  596. return(0);
  597. }
  598. int MbrolaFill(int length, int resume, int amplitude)
  599. {
  600. return(0);
  601. }
  602. void MbrolaReset(void)
  603. {
  604. }
  605. #endif // INCLUDE_MBROLA