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.c 16KB

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