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

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