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

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