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.

spect.cpp 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. /***************************************************************************
  2. * Copyright (C) 2005 to 2007 by Jonathan Duddington *
  3. * email: [email protected] *
  4. * Copyright (C) 2013 by 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 "wx/wx.h"
  21. #include "speak_lib.h"
  22. #include "speech.h"
  23. #include "main.h"
  24. #include "phoneme.h"
  25. #include "synthesize.h"
  26. #include "voice.h"
  27. #include "spect.h"
  28. #include "options.h"
  29. #include "wx/txtstrm.h"
  30. #include "wx/brush.h"
  31. #include "wx/datstrm.h"
  32. extern int PeaksToHarmspect(wavegen_peaks_t *peaks, int pitch, int *htab, int control);
  33. extern unsigned char pk_shape1[];
  34. extern int pk_select;
  35. extern char voice_name[];
  36. wxPen BLUE_PEN(wxColour(0,0,255),2,wxSOLID);
  37. wxBrush BRUSH_SELECTED_PEAK(wxColour(255,180,180),wxSOLID);
  38. wxBrush BRUSH_MARKER[N_MARKERS] = {
  39. wxBrush(wxColour(200,0,255),wxSOLID),
  40. wxBrush(wxColour(255,0,0),wxSOLID),
  41. wxBrush(wxColour(255,200,0),wxSOLID),
  42. wxBrush(wxColour(0,255,0),wxSOLID),
  43. wxBrush(wxColour(0,255,255),wxSOLID),
  44. wxBrush(wxColour(200,0,255),wxSOLID),
  45. wxBrush(wxColour(200,0,255),wxSOLID),
  46. wxBrush(wxColour(255,0,200),wxSOLID) };
  47. #define DRAWPEAKWIDTH 2000
  48. #define PEAKSHAPEW 256
  49. #include <math.h>
  50. static int default_freq[N_PEAKS] =
  51. {200,500,1200,3000,3500,4000,6900,7800,9000};
  52. static int default_width[N_PEAKS] =
  53. {750,500,550,550,600,700,700,700,700};
  54. static int default_klt_bw[N_PEAKS] =
  55. {89,90,140,260,260,260,500,500,500};
  56. float SpectTilt(int value, int freq)
  57. {//=================================
  58. float x;
  59. float y;
  60. if((currentcanvas == NULL) || (currentcanvas->spectseq->bass_reduction == 0))
  61. return(float(value));
  62. y = value*value*2;
  63. if(freq < 600)
  64. {
  65. return(sqrt(y/2.5));
  66. }
  67. else
  68. if(freq < 1050)
  69. {
  70. x = 1.0 + ((1050.0-freq)* 1.5)/450.0;
  71. return(sqrt(y/x));
  72. }
  73. else
  74. {
  75. return(sqrt(y));
  76. }
  77. }
  78. SpectFrame::SpectFrame(SpectFrame *copy)
  79. : FONT_SMALL(8,wxSWISS,wxNORMAL,wxNORMAL)
  80. , FONT_MEDIUM(9,wxSWISS,wxNORMAL,wxNORMAL)
  81. {//=====================================
  82. int ix;
  83. FONT_SMALL = wxFont(8, wxSWISS, wxNORMAL, wxNORMAL); // wxWidgets 3, Font creation needs a GTK+ Window
  84. FONT_MEDIUM = wxFont(9, wxSWISS, wxNORMAL, wxNORMAL);
  85. selected = 0;
  86. keyframe = 0;
  87. spect = NULL;
  88. markers = 0;
  89. pitch = 0;
  90. nx = 0;
  91. time = 0;
  92. length = 0;
  93. amp_adjust = 100;
  94. length_adjust = 0;
  95. for(ix=0; ix<N_PEAKS; ix++)
  96. {
  97. formants[ix].freq = 0;
  98. peaks[ix].pkfreq = default_freq[ix];
  99. peaks[ix].pkheight = 0;
  100. peaks[ix].pkwidth = default_width[ix];
  101. peaks[ix].pkright = default_width[ix];
  102. peaks[ix].klt_bw = default_klt_bw[ix];
  103. peaks[ix].klt_ap = 0;
  104. peaks[ix].klt_bp = default_klt_bw[ix];
  105. }
  106. memset(klatt_param, 0, sizeof(klatt_param));
  107. klatt_param[KLATT_AV] = 59;
  108. klatt_param[KLATT_Kopen] = 40;
  109. if(copy != NULL)
  110. {
  111. *this = *copy;
  112. spect = new USHORT[nx];
  113. memcpy(spect,copy->spect,sizeof(USHORT)*nx);
  114. }
  115. }
  116. SpectFrame::~SpectFrame()
  117. {//=======================
  118. if(spect != NULL)
  119. delete spect;
  120. }
  121. int SpectFrame::Import(wxInputStream& stream1)
  122. {//==========================================
  123. // Import Pratt analysis data
  124. int ix;
  125. double x;
  126. unsigned short *spect_data;
  127. wxTextInputStream stream(stream1);
  128. stream >> time;
  129. stream >> pitch;
  130. stream >> nx;
  131. stream >> dx;
  132. if(stream1.Eof())
  133. return(1);
  134. for(ix=0; ix<N_PEAKS; ix++)
  135. {
  136. peaks[ix].pkfreq = default_freq[ix];
  137. peaks[ix].pkheight = 0;
  138. peaks[ix].pkwidth = default_width[ix];
  139. peaks[ix].pkright = default_width[ix];
  140. }
  141. for(ix=1; ix<=5; ix++)
  142. {
  143. stream >> x;
  144. formants[ix].freq = (int)x;
  145. if(x > 0)
  146. peaks[ix].pkfreq = (int)x;
  147. stream >> x;
  148. formants[ix].bandw = (int)x;
  149. }
  150. spect_data = new USHORT[nx];
  151. if(spect_data == NULL)
  152. {
  153. wxLogError(_T("Failed to allocate memory"));
  154. return(1);
  155. }
  156. max_y = 0;
  157. for(ix=0; ix<nx; ix++)
  158. {
  159. stream >> x;
  160. spect_data[ix] = (int)(sqrt(x) * 16386);
  161. if(spect_data[ix] > max_y)
  162. max_y = spect_data[ix];
  163. }
  164. spect = spect_data;
  165. return(0);
  166. } // End of SpectFrame::Import
  167. int SpectFrame::ImportSPC2(wxInputStream& stream, float &time_acc)
  168. {//===============================================================
  169. int ix;
  170. int size;
  171. unsigned short *spect_data;
  172. CYCLE cy;
  173. CYCLE *p;
  174. float len;
  175. static char peak_factor[8] = {4,5,11,20,20,25,32,32};
  176. stream.Read(&cy,44);
  177. size = SPC2_size_cycle(&cy);
  178. p = (CYCLE *)malloc(size);
  179. if(p == NULL)
  180. {
  181. return(1);
  182. }
  183. stream.SeekI(-44,wxFromCurrent);
  184. stream.Read(p,size);
  185. time = time_acc;
  186. len = cy.length / 15625.0;
  187. time_acc += len;
  188. pitch = float(cy.pitch) / 16.0;
  189. nx = cy.n_harm;
  190. dx = pitch;
  191. for(ix=0; ix<7; ix++)
  192. {
  193. peaks[ix].pkfreq = cy.peak_data[ix].freq * peak_factor[ix];
  194. if(peaks[ix].pkfreq == 0)
  195. peaks[ix].pkfreq = default_freq[ix];
  196. peaks[ix].pkheight = cy.peak_data[ix].height * 40;
  197. peaks[ix].pkwidth = cy.peak_data[ix].width_l * 12;
  198. peaks[ix].pkright = cy.peak_data[ix].width_r * 12;
  199. }
  200. for(ix=7; ix<=8; ix++)
  201. {
  202. peaks[ix].pkfreq = default_freq[ix]; // default
  203. peaks[ix].pkheight = 0;
  204. peaks[ix].pkwidth = peaks[ix].pkright = default_width[ix];
  205. }
  206. if(((cy.flags & 0x80)==0) && (peaks[1].pkheight > 0))
  207. keyframe = 1;
  208. if(cy.flags & 0x08)
  209. markers |= 4;
  210. if(cy.flags & 0x10)
  211. markers |= 2;
  212. if(cy.flags & 0x04)
  213. markers |= 8;
  214. spect_data = new USHORT[nx];
  215. if(spect_data == NULL)
  216. {
  217. wxLogError(_T("Failed to allocate memory"));
  218. return(1);
  219. }
  220. max_y = 0;
  221. for(ix=0; ix<nx; ix++)
  222. {
  223. spect_data[ix] = p->data[ix];
  224. if(spect_data[ix] > max_y)
  225. max_y = spect_data[ix];
  226. }
  227. if(nx==0)
  228. {
  229. nx = int(8000/dx);
  230. spect_data = new USHORT[nx];
  231. for(ix=0; ix<nx; ix++)
  232. spect_data[ix] = 1;
  233. max_y = 1;
  234. }
  235. spect = spect_data;
  236. free(p);
  237. return(0);
  238. } // end of ImportSPC2
  239. int SpectFrame::Load(wxInputStream& stream, int file_format_type)
  240. {//==============================================================
  241. int ix;
  242. int x;
  243. unsigned short *spect_data;
  244. wxDataInputStream s(stream);
  245. time = s.ReadDouble();
  246. pitch = s.ReadDouble();
  247. length = s.ReadDouble();
  248. dx = s.ReadDouble();
  249. nx = s.Read16();
  250. markers = s.Read16();
  251. amp_adjust = s.Read16();
  252. if(file_format_type == 2)
  253. {
  254. ix = s.Read16(); // spare
  255. ix = s.Read16(); // spare
  256. }
  257. for(ix=0; ix<N_PEAKS; ix++)
  258. {
  259. formants[ix].freq = s.Read16();
  260. formants[ix].bandw = s.Read16();
  261. peaks[ix].pkfreq = s.Read16();
  262. if((peaks[ix].pkheight = s.Read16()) > 0)
  263. keyframe = 1;
  264. peaks[ix].pkwidth = s.Read16();
  265. peaks[ix].pkright = s.Read16();
  266. if(file_format_type == 2)
  267. {
  268. peaks[ix].klt_bw = s.Read16();
  269. peaks[ix].klt_ap = s.Read16();
  270. peaks[ix].klt_bp = s.Read16();
  271. }
  272. }
  273. if(file_format_type > 0)
  274. {
  275. for(ix=0; ix<N_KLATTP2; ix++)
  276. {
  277. klatt_param[ix] = s.Read16();
  278. }
  279. }
  280. spect_data = new USHORT[nx];
  281. if(spect_data == NULL)
  282. {
  283. wxLogError(_T("Failed to allocate memory"));
  284. return(1);
  285. }
  286. max_y = 0;
  287. for(ix=0; ix<nx; ix++)
  288. {
  289. x = spect_data[ix] = s.Read16();
  290. if(x > max_y) max_y = x;
  291. }
  292. spect = spect_data;
  293. return(0);
  294. } // End of SpectFrame::Load
  295. int SpectFrame::Save(wxOutputStream& stream, int file_format_type)
  296. {//===============================================================
  297. int ix;
  298. wxDataOutputStream s(stream);
  299. s.WriteDouble(time);
  300. s.WriteDouble(pitch);
  301. s.WriteDouble(length);
  302. s.WriteDouble(dx);
  303. s.Write16(nx);
  304. s.Write16(markers);
  305. s.Write16(amp_adjust);
  306. if(file_format_type == 2)
  307. {
  308. s.Write16(0); // spare
  309. s.Write16(0); // spare
  310. }
  311. for(ix=0; ix<N_PEAKS; ix++)
  312. {
  313. s.Write16(formants[ix].freq);
  314. s.Write16(formants[ix].bandw);
  315. s.Write16(peaks[ix].pkfreq);
  316. s.Write16(keyframe ? peaks[ix].pkheight : 0);
  317. s.Write16(peaks[ix].pkwidth);
  318. s.Write16(peaks[ix].pkright);
  319. if(file_format_type == 2)
  320. {
  321. s.Write16(peaks[ix].klt_bw);
  322. s.Write16(peaks[ix].klt_ap);
  323. s.Write16(peaks[ix].klt_bp);
  324. }
  325. }
  326. if(file_format_type > 0)
  327. {
  328. for(ix=0; ix<N_KLATTP2; ix++)
  329. {
  330. s.Write16(klatt_param[ix]);
  331. }
  332. }
  333. for(ix=0; ix<nx; ix++)
  334. {
  335. s.Write16(spect[ix]);
  336. }
  337. return(0);
  338. } // end of SpectFrame::Save
  339. void SpectFrame::ZeroPeaks()
  340. {//=========================
  341. int pk;
  342. for(pk=0; pk<N_PEAKS; pk++)
  343. peaks[pk].pkheight = 0;
  344. }
  345. void SpectFrame::CopyPeaks(SpectFrame *sf)
  346. {//=======================================
  347. memcpy(peaks,sf->peaks,sizeof(peaks));
  348. memcpy(klatt_param, sf->klatt_param, sizeof(klatt_param));
  349. keyframe = sf->keyframe;
  350. }
  351. void SpectFrame::ToggleMarker(int n)
  352. {//=================================
  353. markers ^= 1<<n;
  354. }
  355. void SpectFrame::ApplyVoiceMods()
  356. {//==============================
  357. // apply the modifications to the formants which are defined in the current voice
  358. int pk;
  359. char voice_name1[40];
  360. strcpy(voice_name1, voice_name2); // remember current voice name
  361. if(LoadVoice(path_modifiervoice.mb_str(wxConvLocal),0x13) == NULL)
  362. {
  363. wxLogError(_T("Can't read voice: ")+path_modifiervoice);
  364. OnOptions2(MENU_PATH4);
  365. return;
  366. }
  367. wxLogStatus(_T("Convert using voice: ")+path_modifiervoice);
  368. for(pk=0; pk<N_PEAKS; pk++)
  369. {
  370. peaks[pk].pkfreq = (peaks[pk].pkfreq * voice->freq2[pk])/256;
  371. peaks[pk].pkheight = (peaks[pk].pkheight * voice->height2[pk])/256;
  372. peaks[pk].pkwidth = (peaks[pk].pkwidth * voice->width2[pk])/256;
  373. peaks[pk].pkright = (peaks[pk].pkright * voice->width2[pk])/256;
  374. }
  375. LoadVoice(voice_name1,1);
  376. }
  377. double SpectFrame::GetRms(int seq_amplitude)
  378. {//=========================================
  379. int h;
  380. float total=0;
  381. int maxh;
  382. int height;
  383. int htab[400];
  384. wavegen_peaks_t wpeaks[9];
  385. for(h=0; h<9; h++)
  386. {
  387. height = (peaks[h].pkheight * seq_amplitude * amp_adjust)/10000;
  388. wpeaks[h].height = height << 8;
  389. wpeaks[h].freq = peaks[h].pkfreq << 16;
  390. wpeaks[h].left = peaks[h].pkwidth << 16;
  391. wpeaks[h].right = peaks[h].pkright << 16;
  392. }
  393. maxh = PeaksToHarmspect(wpeaks,90<<16,htab,0);
  394. for(h=1; h<maxh; h++)
  395. {
  396. total += ((htab[h] * htab[h]) >> 10);
  397. }
  398. rms = sqrt(total) / 7.25;
  399. // DrawPeaks(NULL,0,0,amp);
  400. return(rms);
  401. }
  402. void SpectFrame::DrawPeaks(wxDC *dc, int offy, int frame_width, int seq_amplitude, double scale_x)
  403. {//==============================================================================================
  404. // dc==NULL means don't draw, just calculate RMS
  405. int peak;
  406. peak_t *pk;
  407. int x1,x2,x3,width,ix;
  408. int y1, y2;
  409. double yy;
  410. int max_ix;
  411. int height;
  412. int pkright;
  413. int pkwidth;
  414. int buf[DRAWPEAKWIDTH*2];
  415. max_ix = int(9000 * scale_x);
  416. memset(buf,0,sizeof(buf));
  417. for(peak=0; peak<N_PEAKS; peak++)
  418. {
  419. pk = &peaks[peak];
  420. if((pk->pkfreq == 0) || (pk->pkheight==0)) continue;
  421. height = pk->pkheight;
  422. pkright = pk->pkright;
  423. pkwidth = pk->pkwidth;
  424. x1 = (int)(pk->pkfreq*scale_x);
  425. x2 = (int)((pk->pkfreq + pkright)*scale_x);
  426. x3 = (int)((pk->pkfreq - pkwidth)*scale_x);
  427. if(x3 >= DRAWPEAKWIDTH)
  428. continue; // whole peak is off the scale
  429. if((width = x2-x1) <= 0) continue;
  430. for(ix=0; ix<width; ix++)
  431. {
  432. buf[x1+ix] += height * pk_shape1[(ix*PEAKSHAPEW)/width];
  433. }
  434. if((width = x1-x3) <= 0) continue;
  435. for(ix=1; ix<width; ix++)
  436. {
  437. if(x3+ix >= 0)
  438. {
  439. buf[x3+ix] += height * pk_shape1[((width-ix)*PEAKSHAPEW)/width];
  440. }
  441. }
  442. }
  443. rms = buf[0]>>12;
  444. rms = rms*rms*23;
  445. rms = rms*rms;
  446. if(dc != NULL) dc->SetPen(*wxGREEN_PEN);
  447. x1 = 0;
  448. y1 = offy - ((buf[0] * FRAME_HEIGHT) >> 21);
  449. for(ix=1; ix<max_ix; ix++)
  450. {
  451. yy = buf[ix]>>12;
  452. yy = yy*yy*23;
  453. rms += (yy*yy);
  454. x2 = ix;
  455. y2 = offy - ((buf[ix] * FRAME_HEIGHT) >> 21);
  456. if(dc != NULL) dc->DrawLine(x1,y1,x2,y2);
  457. x1 = x2;
  458. y1 = y2;
  459. }
  460. rms = sqrt(rms)/200000.0;
  461. // apply adjustment from spectseq amplitude
  462. rms = rms * seq_amplitude * amp_adjust / 10000.0;
  463. rms = GetRms(seq_amplitude);
  464. } // end of SpectFrame::DrawPeaks
  465. void SpectFrame::Draw(wxDC& dc, int offy, int frame_width, double scalex, double scaley)
  466. {//=====================================================================================
  467. int pt;
  468. int peak;
  469. peak_t *pk;
  470. int ix;
  471. double x0, x1;
  472. int y0, y1;
  473. int x, x2, x3;
  474. double xinc;
  475. double yf;
  476. int font_height;
  477. wxString text;
  478. if(currentcanvas == NULL)
  479. return;
  480. dc.SetFont(*wxSWISS_FONT);
  481. xinc = dx * scalex;
  482. x0 = xinc;
  483. x1 = nx * xinc;
  484. if(selected) // this frame is selected
  485. {
  486. // highlight selected peak by drawing a red triangle
  487. pk = &peaks[pk_select];
  488. x2 = int(pk->pkright * scalex * 0.44);
  489. x3 = int(pk->pkwidth * scalex * 0.44);
  490. x = int((pk->pkfreq) * scalex);
  491. y1 = (pk->pkheight * FRAME_HEIGHT) >> 14;
  492. if(y1 < 5) y1 = 5;
  493. wxPoint triangle[3];
  494. dc.SetBrush(BRUSH_SELECTED_PEAK);
  495. dc.SetPen(*wxTRANSPARENT_PEN);
  496. triangle[0] = wxPoint(0,-y1);
  497. triangle[1] = wxPoint(x2,0);
  498. triangle[2] = wxPoint(-x3,0);
  499. dc.DrawPolygon(3,triangle,x,offy);
  500. }
  501. // draw the measured formants
  502. dc.SetPen(BLUE_PEN);
  503. for(peak=1; peak<=5; peak++)
  504. {
  505. if(formants[peak].freq != 0)
  506. {
  507. // set height from linear interpolation of the adjacent
  508. // points in the spectrum
  509. pt = (int)(formants[peak].freq / dx);
  510. y0 = spect[pt-1];
  511. y1 = spect[pt];
  512. yf = (y1-y0) * (formants[peak].freq - pt*dx)/dx;
  513. y1 = offy - (int)((y0+yf) * scaley);
  514. x1 = formants[peak].freq * scalex;
  515. dc.DrawLine((int)x1,offy,(int)x1,y1);
  516. }
  517. }
  518. // draw the spectrum outline
  519. if(keyframe)
  520. dc.SetPen(*wxBLACK_PEN);
  521. else
  522. dc.SetPen(*wxMEDIUM_GREY_PEN);
  523. if(spect != NULL)
  524. {
  525. y0 = offy - (int)(spect[0] * scaley);
  526. for(pt=1; pt<nx; pt++)
  527. {
  528. x1 = x0 + xinc;
  529. y1 = offy - (int)(SpectTilt(spect[pt],int(pt*dx)) * scaley);
  530. dc.DrawLine((int)x0,y0,(int)x1,y1);
  531. x0 = x1;
  532. y0 = y1;
  533. }
  534. }
  535. if(currentcanvas->zoom < 2)
  536. dc.SetFont(FONT_SMALL);
  537. else
  538. dc.SetFont(FONT_MEDIUM);
  539. // Markers
  540. x = frame_width - 120 - 32;
  541. for(ix=0; ix<N_MARKERS; ix++)
  542. {
  543. if(markers & 1<<ix)
  544. {
  545. dc.SetBrush(BRUSH_MARKER[ix]);
  546. y0 = offy-FRAME_HEIGHT+22;
  547. dc.DrawRectangle(x,y0,22,22);
  548. if(currentcanvas->zoom > 2)
  549. {
  550. text.Printf(_T("%d"),ix);
  551. dc.DrawText(text,x+2,y0);
  552. }
  553. x -= 26;
  554. }
  555. }
  556. DrawPeaks(&dc,offy,frame_width,currentcanvas->spectseq->amplitude,scalex);
  557. font_height = int(15 / currentcanvas->zoomy);
  558. text.Printf(_T("%3dmS %.1fHz"),int(time*1000),pitch);
  559. dc.DrawText(text,frame_width-130,offy-FRAME_HEIGHT+20+font_height);
  560. if(keyframe || rms > 0)
  561. {
  562. text.Printf(_T("%3d"),(int)rms);
  563. dc.DrawText(text,frame_width-130,offy-FRAME_HEIGHT+20+font_height*2);
  564. }
  565. dc.SetPen(*wxBLACK_PEN);
  566. dc.DrawLine(0,offy,frame_width,offy); // base line
  567. } // end of SpectFrame::Draw
  568. void SpectFrame::KlattDefaults()
  569. {//============================
  570. // set default values for Klatt parameters
  571. int pk;
  572. int bw;
  573. int bw3;
  574. klatt_param[KLATT_AV] = 59;
  575. klatt_param[KLATT_AVp] = 0;
  576. klatt_param[KLATT_Fric] = 0;
  577. klatt_param[KLATT_FricBP] = 0;
  578. klatt_param[KLATT_Aspr] = 0;
  579. klatt_param[KLATT_Turb] = 0;
  580. klatt_param[KLATT_Skew] = 0;
  581. klatt_param[KLATT_Tilt] = 0;
  582. klatt_param[KLATT_Kopen] = 40;
  583. klatt_param[KLATT_FNZ] = 280;
  584. bw = 60;
  585. if(peaks[1].pkfreq < 400)
  586. bw = 55;
  587. if(peaks[1].pkfreq > 600)
  588. bw = 70;
  589. if(peaks[1].pkfreq > 650)
  590. bw = 80;
  591. if(peaks[1].pkfreq > 750)
  592. bw = 90;
  593. peaks[1].pkwidth = bw;
  594. bw = 90;
  595. bw3 = 150;
  596. if(peaks[2].pkfreq < 1000)
  597. {
  598. bw = 80;
  599. bw3 = 120;
  600. }
  601. if(peaks[2].pkfreq > 1600)
  602. {
  603. bw = 100;
  604. bw3 = 200;
  605. }
  606. if(peaks[2].pkfreq > 2000)
  607. {
  608. bw = 110;
  609. bw3 = 250;
  610. }
  611. peaks[2].pkwidth = bw;
  612. peaks[3].pkwidth = bw3;
  613. peaks[4].pkwidth = 200;
  614. peaks[5].pkwidth = 200;
  615. peaks[6].pkwidth = 500;
  616. peaks[0].pkfreq = 280; // FNP
  617. peaks[0].pkwidth = 280; // FNZ
  618. peaks[7].pkfreq = 7800;
  619. peaks[7].pkwidth = 0;
  620. peaks[8].pkfreq = 9000;
  621. peaks[8].pkwidth = 0;
  622. for(pk=0; pk<=8; pk++)
  623. {
  624. peaks[pk].pkheight = peaks[pk].pkwidth << 6;
  625. peaks[pk].pkright = 0;
  626. }
  627. }