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

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