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.

vowelchart.cpp 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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 <math.h>
  20. #include "wx/wx.h"
  21. #include <wx/dcmemory.h>
  22. #include <wx/dc.h>
  23. #include <wx/bitmap.h>
  24. #include <wx/dirdlg.h>
  25. #include "wx/filename.h"
  26. #include "wx/wfstream.h"
  27. #include "speak_lib.h"
  28. #include "main.h"
  29. #include "speech.h"
  30. #include "phoneme.h"
  31. #include "synthesize.h"
  32. #include "voice.h"
  33. #include "spect.h"
  34. #include "translate.h"
  35. #include "options.h"
  36. /* Read a file of vowel symbols and f1,f2 formants, and produce a vowel diagram
  37. */
  38. extern wxString path_phsource;
  39. extern char *phondata_ptr;
  40. extern USHORT *phoneme_index;
  41. extern int n_phoneme_tables;
  42. // size of the vowelchart png
  43. #define WIDTH 1580
  44. #define HEIGHT 800
  45. #define ROUND(x) ((int) ((x) + 0.5))
  46. static int HslValue (double n1, double n2, double hue)
  47. {//===================================================
  48. double value;
  49. if (hue > 255)
  50. hue -= 255;
  51. else if (hue < 0)
  52. hue += 255;
  53. if (hue < 42.5)
  54. value = n1 + (n2 - n1) * (hue / 42.5);
  55. else if (hue < 127.5)
  56. value = n2;
  57. else if (hue < 170)
  58. value = n1 + (n2 - n1) * ((170 - hue) / 42.5);
  59. else
  60. value = n1;
  61. return ROUND (value * 255.0);
  62. }
  63. /**
  64. * @hue: Hue channel, returns Red channel
  65. * @saturation: Saturation channel, returns Green channel
  66. * @lightness: Lightness channel, returns Blue channel
  67. *
  68. * The arguments are pointers to int, with the values pointed to in the
  69. * following ranges: H [0, 360], L [0, 255], S [0, 255].
  70. *
  71. * The function changes the arguments to point to the RGB value
  72. * corresponding, with the returned values all in the range [0, 255].
  73. **/
  74. void HslToRgb (int *hue, int *saturation, int *lightness)
  75. {//======================================================
  76. double h, s, l;
  77. h = (*hue * 256)/360;
  78. s = *saturation;
  79. l = *lightness;
  80. if (s == 0)
  81. {
  82. /* achromatic case */
  83. *hue = (int)l;
  84. *lightness = (int)l;
  85. *saturation = (int)l;
  86. }
  87. else
  88. {
  89. double m1, m2;
  90. if (l < 128)
  91. m2 = (l * (255 + s)) / 65025.0;
  92. else
  93. m2 = (l + s - (l * s) / 255.0) / 255.0;
  94. m1 = (l / 127.5) - m2;
  95. /* chromatic case */
  96. *hue = HslValue (m1, m2, h + 85);
  97. *saturation = HslValue (m1, m2, h);
  98. *lightness = HslValue (m1, m2, h - 85);
  99. }
  100. }
  101. static int vowel_posn[N_PHONEME_TAB];
  102. static int vowel_posn_ix;
  103. static double log2a(double x)
  104. {//========================
  105. // log2(x) = log(x) / log(2)
  106. return(log(x) / 0.693147);
  107. }
  108. static int VowelX(int f2)
  109. {//======================
  110. return(WIDTH - int((log2a(f2) - 9.40)*WIDTH/1.9));
  111. // return(WIDTH - int((log2a(f2) - 9.49)*WIDTH/1.8));
  112. }
  113. static int VowelY(int f1)
  114. {//======================
  115. return(int((log2a(f1) - 7.85)*HEIGHT/2.15));
  116. }
  117. static int VowelZ(int f3)
  118. {//======================
  119. int z;
  120. // range 2000-3000Hz, log2= 10.96 to 11.55
  121. z = int((log2a(f3) - 11.05)*256/0.50);
  122. if(z < 0) z = 0;
  123. if(z > 255) z = 255;
  124. return(z);
  125. }
  126. static void DrawVowel(wxDC *dc, wxString name, int f1, int f2, int f3, int g1, int g2)
  127. {//==================================================================================
  128. int ix;
  129. int posn;
  130. int collisions;
  131. int x,y,z,x2,y2;
  132. int r,g,b;
  133. wxBrush brush;
  134. y = VowelY(f1);
  135. x = VowelX(f2);
  136. z = VowelZ(f3);
  137. if(y < 0) y = 0;
  138. if(y > (HEIGHT-4)) y= (HEIGHT-4);
  139. if(x < 0) x = 0;
  140. if(x > (WIDTH-12)) x = (WIDTH-12);
  141. r = z;
  142. g = 255;
  143. b = 100 + z/2;
  144. HslToRgb(&r,&g,&b);
  145. brush.SetColour(r,g,b);
  146. dc->SetBrush(brush);
  147. dc->DrawCircle(x,y,4);
  148. // check for a label already at this position
  149. collisions = 0;
  150. posn = (x/8)*WIDTH + (y/8);
  151. for(ix=0; ix<vowel_posn_ix; ix++)
  152. {
  153. if(posn == vowel_posn[ix])
  154. collisions++;
  155. }
  156. vowel_posn[vowel_posn_ix++] = posn;
  157. dc->DrawText(name,x+4,y+(collisions*10));
  158. if(g2 != 0xffff)
  159. {
  160. y2 = VowelY(g1);
  161. x2 = VowelX(g2);
  162. dc->DrawLine(x,y,x2,y2);
  163. }
  164. }
  165. static int VowelChartDir(wxDC *dc, wxBitmap *bitmap)
  166. {//=================================================
  167. int ix;
  168. int nf;
  169. int count = 0;
  170. SpectSeq *spectseq;
  171. SpectFrame *frame1;
  172. SpectFrame *frame2=NULL;
  173. wxFileName filename;
  174. wxString dir = wxDirSelector(_T("Directory of vowel files"),path_phsource);
  175. if(dir.IsEmpty()) return(0);
  176. wxString path = wxFindFirstFile(dir+_T("/*"),wxFILE);
  177. while (!path.empty())
  178. {
  179. if((spectseq = new SpectSeq) == NULL) break;
  180. filename = wxFileName(path);
  181. wxFileInputStream stream(path);
  182. if(stream.Ok() == FALSE)
  183. {
  184. path = wxFindNextFile();
  185. continue;
  186. }
  187. spectseq->Load(stream);
  188. nf = 0;
  189. frame1 = NULL;
  190. if(spectseq->numframes > 0)
  191. {
  192. frame2 = spectseq->frames[0];
  193. }
  194. for(ix=0; ix<spectseq->numframes; ix++)
  195. {
  196. if(spectseq->frames[ix]->keyframe)
  197. {
  198. nf++;
  199. frame2 = spectseq->frames[ix];
  200. if(frame2->markers & FRFLAG_VOWEL_CENTRE)
  201. frame1 = frame2;
  202. }
  203. }
  204. if((nf >= 3) && (frame1 != NULL))
  205. {
  206. DrawVowel(dc,wxString(filename.GetName()),
  207. frame1->peaks[1].pkfreq, frame1->peaks[2].pkfreq, frame1->peaks[3].pkfreq,
  208. frame2->peaks[1].pkfreq, frame2->peaks[2].pkfreq);
  209. count++;
  210. }
  211. delete spectseq;
  212. path = wxFindNextFile();
  213. }
  214. filename.SetPath(dir);
  215. filename.SetFullName(_T("vowelchart.png"));
  216. bitmap->SaveFile(filename.GetFullPath(),wxBITMAP_TYPE_PNG);
  217. return(count);
  218. }
  219. static int VowelChartList(wxDC *dc, wxBitmap *bitmap, char *fname)
  220. {//===============================================================
  221. // Plot a graph of vowel formants.
  222. // y-axis is decreasing f1 (closeness)
  223. // x-axis is decreasing f2 (backness)
  224. FILE *f_in;
  225. int ix;
  226. int f1,f2,f3,g1,g2;
  227. int colour;
  228. int count=0;
  229. wxFileName filename;
  230. char name[40];
  231. char buf[200];
  232. wxString path;
  233. if(fname != NULL)
  234. {
  235. path = wxString(fname,wxConvLocal);
  236. }
  237. else
  238. {
  239. path = wxFileSelector(_T("Read file of vowel formants"),path_phsource,
  240. _T(""),_T(""),_T("*"),wxOPEN);
  241. }
  242. if(path.IsEmpty())
  243. {
  244. return(0);
  245. }
  246. filename = wxFileName(path);
  247. strcpy(buf,path.mb_str(wxConvLocal));
  248. f_in = fopen(buf,"r");
  249. if(f_in == NULL)
  250. {
  251. wxLogError(_T("Can't read file: %s"),buf);
  252. return(0);
  253. }
  254. while(fgets(buf,sizeof(buf),f_in) != NULL)
  255. {
  256. g2 = 0xffff;
  257. ix = sscanf(buf,"%s %d %d %d %d %d %d",name,&colour,&f1,&f2,&f3,&g1,&g2);
  258. if(ix >= 4)
  259. {
  260. if(colour == 1)
  261. {
  262. dc->SetPen(*wxMEDIUM_GREY_PEN);
  263. dc->SetTextForeground(wxColour(100,100,128));
  264. }
  265. else
  266. {
  267. dc->SetPen(*wxBLACK_PEN);
  268. dc->SetTextForeground(*wxBLACK);
  269. }
  270. DrawVowel(dc,wxString(name,wxConvLocal),
  271. f1,f2,f3,g1,g2);
  272. count++;
  273. }
  274. }
  275. filename.SetExt(_T("png"));
  276. bitmap->SaveFile(filename.GetFullPath(),wxBITMAP_TYPE_PNG);
  277. return(count);
  278. }
  279. void VowelChart(int control, char *fname)
  280. {//======================================
  281. // Plot a graph of vowel formants.
  282. // y-axis is decreasing f1 (closeness)
  283. // x-axis is decreasing f2 (backness)
  284. // control=1 from directory of lists
  285. // control=2 from single list
  286. // control=3 from directory of phoneme source data files
  287. int ix;
  288. int x,y;
  289. int count;
  290. wxFileName filename;
  291. wxBitmap bitmap(WIDTH,HEIGHT);
  292. // Create a memory DC
  293. wxMemoryDC dc;
  294. dc.SelectObject(bitmap);
  295. dc.SetBrush(*wxWHITE_BRUSH);
  296. dc.SetFont(*wxSWISS_FONT);
  297. dc.Clear();
  298. // draw grid
  299. dc.SetPen(*wxLIGHT_GREY_PEN);
  300. for(ix=200; ix<=1000; ix+=50)
  301. {
  302. y = VowelY(ix);
  303. dc.DrawLine(0,y,WIDTH,y);
  304. if((ix % 100) == 0)
  305. dc.DrawText(wxString::Format(_T("%d"),ix),1,y);
  306. }
  307. for(ix=700; ix<=2400; ix+=100)
  308. {
  309. x = VowelX(ix);
  310. dc.DrawLine(x,0,x,HEIGHT);
  311. if((ix % 200)==0)
  312. dc.DrawText(wxString::Format(_T("%d"),ix),x+1,0);
  313. }
  314. dc.SetPen(*wxBLACK_PEN);
  315. vowel_posn_ix = 0;
  316. if(control==3)
  317. count = VowelChartDir(&dc, &bitmap);
  318. else
  319. count = VowelChartList(&dc, &bitmap, fname);
  320. dc.SetTextForeground(*wxBLACK);
  321. if(control != 1)
  322. wxLogStatus(_T("Plotted %d vowels"),count);
  323. }
  324. void FindPhonemesUsed(void)
  325. {//========================
  326. int hash;
  327. char *p;
  328. unsigned int *pw;
  329. char *next;
  330. unsigned char c;
  331. int count = 0;
  332. int ignore;
  333. char phonetic[N_WORD_PHONEMES];
  334. // look through all the phoneme strings in the **_rules data
  335. // and mark these phoneme codes as used.
  336. p = translator->data_dictrules;
  337. while(*p != 0)
  338. {
  339. if(*p == RULE_CONDITION)
  340. p+=2;
  341. if(*p == RULE_LINENUM)
  342. p+=3;
  343. if(*p == RULE_GROUP_END)
  344. {
  345. p++;
  346. if(*p == 0) break;
  347. }
  348. if(*p == RULE_GROUP_START)
  349. {
  350. if(p[1] == RULE_REPLACEMENTS)
  351. {
  352. p++;
  353. pw = (unsigned int *)(((long)p+4) & ~3); // advance to next word boundary
  354. while(pw[0] != 0)
  355. {
  356. pw += 2; // find the end of the replacement list, each entry is 2 words.
  357. }
  358. p = (char *)(pw+1);
  359. continue;
  360. }
  361. if(p[1] == RULE_LETTERGP2)
  362. {
  363. while(*p != RULE_GROUP_END) p++;
  364. continue;
  365. }
  366. p += (strlen(p)+1);
  367. }
  368. while((c = *p) != 0)
  369. {
  370. if(c == RULE_CONDITION)
  371. p++; // next byte is the condition number, which may be 3 (= RULE_PHONEMES)
  372. if(c == RULE_PHONEMES)
  373. break;
  374. p++;
  375. }
  376. count++;
  377. if(c == RULE_PHONEMES)
  378. {
  379. ignore = 0;
  380. p++;
  381. while((c = *p) != 0)
  382. {
  383. if(c == phonSWITCH)
  384. ignore = 1;
  385. if(ignore == 0)
  386. phoneme_tab_flags[c] |= 2;
  387. p++;
  388. }
  389. }
  390. p++;
  391. }
  392. // NOTE, we should recognise langopts.textmode and ignore the *_list file (lang=zh)
  393. for(hash=0; hash<N_HASH_DICT; hash++)
  394. {
  395. p = translator->dict_hashtab[hash];
  396. if(p == NULL)
  397. continue;
  398. while(*p != 0)
  399. {
  400. next = p + p[0];
  401. if((p[1] & 0x80) == 0)
  402. {
  403. p += ((p[1] & 0x3f) + 2);
  404. strcpy(phonetic,p);
  405. p += strlen(phonetic) +1;
  406. // examine flags
  407. ignore = 0;
  408. while(p < next)
  409. {
  410. if(*p == BITNUM_FLAG_TEXTMODE)
  411. {
  412. ignore = 1;
  413. break;
  414. }
  415. p++;
  416. }
  417. if(ignore == 0)
  418. {
  419. p = phonetic;
  420. while((c = *p) != 0)
  421. {
  422. if(c == phonSWITCH)
  423. break;
  424. phoneme_tab_flags[c] |= 2;
  425. p++;
  426. }
  427. }
  428. }
  429. p = next;
  430. }
  431. }
  432. } // end of FindPhonemesUsed
  433. #define N_VOWELFMT_ADDR 20
  434. int n_vowelfmt_addr;
  435. int vowelfmt_addr[N_VOWELFMT_ADDR]; // FMT() statements found in a phoneme definition
  436. static void FindVowelFmt(int prog_start, int length)
  437. {//=================================================
  438. USHORT *prog;
  439. USHORT instn;
  440. int prog_end;
  441. prog_end = prog_start + length;
  442. n_vowelfmt_addr = 0;
  443. for(prog = &phoneme_index[prog_start]; prog < &phoneme_index[prog_end]; prog++)
  444. {
  445. instn = *prog;
  446. switch(instn >> 12)
  447. {
  448. case 2:
  449. case 3:
  450. // conditions
  451. while((instn & 0xe000) == 0x2000)
  452. {
  453. instn = *(++prog);
  454. }
  455. prog--;
  456. break;
  457. case 10: // Vowelin, Vowelout
  458. prog += 3;
  459. break;
  460. case 9:
  461. case 12: // WAV
  462. case 13: // VowelStart
  463. case 14: // VowelEnd
  464. case 15: // addWav
  465. prog++;
  466. break;
  467. case 11: // FMT
  468. if(n_vowelfmt_addr < N_VOWELFMT_ADDR)
  469. {
  470. vowelfmt_addr[n_vowelfmt_addr++] = ((instn & 0xf) << 18) + (prog[1] << 2);
  471. }
  472. prog++;
  473. break;
  474. }
  475. }
  476. } // end of FindVowelFmt
  477. static int prog_log_sorter(PHONEME_PROG_LOG *p1, PHONEME_PROG_LOG *p2)
  478. {//===================================================================
  479. return(p1->addr - p2->addr);
  480. }
  481. void MakeVowelLists(void)
  482. {//======================
  483. // For each phoneme table, make a list of its vowels and their
  484. // formant frequencies (f1,f2,f3) for use by VowelChart()
  485. int table;
  486. int ix;
  487. int phcode;
  488. PHONEME_TAB *ph;
  489. FILE *f;
  490. FILE *f_prog_log;
  491. SPECT_SEQ *seq;
  492. SPECT_SEQK *seqk;
  493. frame_t *frame;
  494. int n_prog_log;
  495. int vowelfmt_ix;
  496. int colour;
  497. int voice_found;
  498. PHONEME_PROG_LOG *prog_log_table;
  499. PHONEME_PROG_LOG *found_prog;
  500. PHONEME_PROG_LOG this_prog;
  501. char dirname[sizeof(path_source)+20];
  502. char fname[sizeof(dirname)+40];
  503. char save_voice_name[80];
  504. strcpy(save_voice_name,voice_name2);
  505. sprintf(fname,"%s%s",path_source,"compile_prog_log");
  506. if((f_prog_log = fopen(fname,"rb")) == NULL)
  507. {
  508. wxLogError(_T("Can't read 'compile_prog_log;"));
  509. return;
  510. }
  511. ix = GetFileLength(fname);
  512. prog_log_table = (PHONEME_PROG_LOG *)malloc(ix);
  513. if(prog_log_table == NULL)
  514. return;
  515. ix = fread(prog_log_table, 1, ix, f_prog_log);
  516. fclose(f_prog_log);
  517. n_prog_log = ix / sizeof(PHONEME_PROG_LOG);
  518. progress = new wxProgressDialog(_T("Vowel charts"),_T(""),n_phoneme_tables);
  519. sprintf(dirname,"%s%s",path_source,"vowelcharts");
  520. mkdir(dirname,S_IRWXU | S_IRGRP | S_IROTH);
  521. sprintf(fname,"%s/vowel_log",dirname);
  522. for(table=0; table<n_phoneme_tables; table++)
  523. {
  524. sprintf(fname,"%s/%s",dirname,phoneme_tab_list[table].name);
  525. if((f = fopen(fname,"w"))==NULL) continue;
  526. progress->Update(table);
  527. // select the phoneme table by name
  528. // if(SetVoiceByName(phoneme_tab_list[table].name) != 0) continue;
  529. if(SelectPhonemeTableName(phoneme_tab_list[table].name) < 0) continue;
  530. voice_found = 0;
  531. if((LoadVoice(phoneme_tab_list[table].name, 0) != NULL) && (translator->data_dictrules != NULL))
  532. {
  533. voice_found = 1;
  534. FindPhonemesUsed();
  535. }
  536. // phoneme table is terminated by a phoneme with no name (=0)
  537. for(phcode=1; phcode < n_phoneme_tab; phcode++)
  538. {
  539. ph = phoneme_tab[phcode];
  540. if((ph==NULL) || (ph->type != phVOWEL) || (ph->program == 0))
  541. continue;
  542. if(voice_found && (phoneme_tab_flags[phcode] & 3) == 0)
  543. {
  544. continue; // inherited, and not used
  545. }
  546. // find the size of this program
  547. this_prog.addr = ph->program;
  548. found_prog = (PHONEME_PROG_LOG *)bsearch((void *)&this_prog, (void *)prog_log_table, n_prog_log, sizeof(PHONEME_PROG_LOG), (int(*)(const void *,const void *))prog_log_sorter);
  549. FindVowelFmt(ph->program, found_prog->length);
  550. for(vowelfmt_ix=0; vowelfmt_ix < n_vowelfmt_addr; vowelfmt_ix++)
  551. {
  552. ix = vowelfmt_addr[vowelfmt_ix];
  553. seq = (SPECT_SEQ *)(&phondata_ptr[ix]);
  554. seqk = (SPECT_SEQK *)seq;
  555. if(seq->frame[0].frflags & FRFLAG_KLATT)
  556. frame = &seqk->frame[1];
  557. else
  558. frame = (frame_t *)&seq->frame[1];
  559. if((n_vowelfmt_addr - vowelfmt_ix) == 1)
  560. colour = 0;
  561. else
  562. colour = 1;
  563. fprintf(f,"%s\t %d %3d %4d %4d",WordToString(ph->mnemonic), colour,
  564. frame->ffreq[1],frame->ffreq[2],frame->ffreq[3]);
  565. if(seq->frame[0].frflags & FRFLAG_KLATT)
  566. frame = &seqk->frame[seqk->n_frames-1];
  567. else
  568. frame = (frame_t *)&seq->frame[seq->n_frames-1];
  569. fprintf(f," %3d %4d %4d\n",frame->ffreq[1],frame->ffreq[2],frame->ffreq[3]);
  570. }
  571. }
  572. fclose(f);
  573. VowelChart(1,fname); // draw the vowel chart
  574. }
  575. free(prog_log_table);
  576. LoadVoice(voice_name2,0); // reset the original phoneme table
  577. delete progress;
  578. LoadVoiceVariant(save_voice_name,0);
  579. }
  580. #define N_ENVELOPES 30
  581. int n_envelopes = 0;
  582. char envelope_paths[N_ENVELOPES][80];
  583. unsigned char envelope_dat[N_ENVELOPES][ENV_LEN];
  584. #define HT_ENV 140
  585. #define WD_ENV 128*2
  586. void DrawEnvelopes()
  587. {//================
  588. int ix_env;
  589. int y_base;
  590. int x;
  591. FILE *f_txt=NULL;
  592. unsigned char *env;
  593. char name[200];
  594. wxBitmap bitmap(WD_ENV,HT_ENV*n_envelopes);
  595. // Create a memory DC
  596. wxMemoryDC dc;
  597. dc.SelectObject(bitmap);
  598. dc.SetBrush(*wxWHITE_BRUSH);
  599. dc.SetFont(*wxSWISS_FONT);
  600. dc.Clear();
  601. sprintf(name,"%s%s",path_source,"envelopes.txt");
  602. // f_txt = fopen(name,"w");
  603. for(ix_env=0; ix_env<n_envelopes; ix_env++)
  604. {
  605. y_base = HT_ENV * ix_env;
  606. dc.SetPen(*wxLIGHT_GREY_PEN);
  607. dc.DrawLine(0,y_base+0,256,y_base+0);
  608. dc.DrawLine(0,y_base+64,256,y_base+64);
  609. dc.DrawLine(0,y_base+128,256,y_base+128);
  610. dc.DrawLine(128,y_base+0,128,y_base+128);
  611. dc.SetPen(*wxBLACK_PEN);
  612. strncpy0(name,envelope_paths[ix_env],sizeof(name));
  613. dc.DrawText(wxString(name,wxConvLocal),1,y_base);
  614. env = envelope_dat[ix_env];
  615. y_base = y_base+128;
  616. for(x=0; x<127; x++)
  617. {
  618. dc.DrawLine(x*2, y_base-env[x]/2, (x+1)*2, y_base-env[x+1]/2);
  619. }
  620. if(f_txt != NULL)
  621. {
  622. fprintf(f_txt,"%s\n",name);
  623. for(x=0; x<128; x++)
  624. {
  625. fprintf(f_txt," 0x%.2x,",env[x]);
  626. if((x & 0xf) == 0xf)
  627. fputc('\n',f_txt);
  628. }
  629. fputc('\n',f_txt);
  630. }
  631. }
  632. bitmap.SaveFile(path_phsource+_T("/envelopes.png"),wxBITMAP_TYPE_PNG);
  633. if(f_txt != NULL)
  634. fclose(f_txt);
  635. }