CSL  6.0
SpectralProc.cpp
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This is an automatically generated file created by the Jucer!
5 
6  Creation date: 9 Jan 2009 5:22:37 pm
7 
8  Be careful when adding custom code to these files, as only the code within
9  the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
10  and re-saved.
11 
12  Jucer version: 1.11
13 
14  ------------------------------------------------------------------------------
15 
16  The Jucer is part of the JUCE library - "Jules' Utility Class Extensions"
17  Copyright 2004-6 by Raw Material Software ltd.
18 
19  ==============================================================================
20 */
21 
22 //[Headers] You can add your own extra header files here...
23 
24 //[/Headers]
25 
26 #include "SpectralProc.h"
27 
28 
29 //[MiscUserDefs] You can add your own user definitions and misc code here...
30 
31 #include "PAIO.h" /// PortAudio IO
32 
33 using namespace std;
34 using namespace csl;
35 
36 //[/MiscUserDefs]
37 
38 //==============================================================================
40  : playButton (0),
41  quitButton (0),
42  oscilloscope (0),
43  label (0),
44  spectrogram (0),
45  offsetSlider (0),
46  loadButton (0),
47  analyzeButton (0),
48  filterButton (0),
49  playSource (0),
50  fftLenCombo (0),
51  winCombo (0),
52  label2 (0),
53  label3 (0),
54  label4 (0),
55  hiPassSlider (0),
56  label5 (0),
57  loPassSlider (0),
58  label6 (0),
59  thresholdSlider (0),
60  scaleCombo (0),
61  displayCombo (0),
62  label7 (0),
63  label8 (0),
64  overlapCombo (0),
65  label9 (0),
66  label10 (0),
67  timeSlider (0),
68  label11 (0),
69  pitchSlider (0),
70  fileInfo (0)
71 {
72  addAndMakeVisible (playButton = new TextButton (T("playNote")));
73  playButton->setButtonText (T("Play Resynth"));
74  playButton->addButtonListener (this);
75 
76  addAndMakeVisible (quitButton = new TextButton (T("quitAction")));
77  quitButton->setButtonText (T("Quit"));
78  quitButton->addButtonListener (this);
79 
80  addAndMakeVisible (oscilloscope = new AudioWaveformDisplay());
81  oscilloscope->setName (T("new component"));
82 
83  addAndMakeVisible (label = new Label (T("CSL test"),
84  T("CSL Spectral Processing")));
85  label->setFont (Font (Font::getDefaultSerifFontName(), 24.0000f, Font::bold));
86  label->setJustificationType (Justification::centredLeft);
87  label->setEditable (false, false, false);
88  label->setColour (Label::textColourId, Colour (0xff2013da));
89  label->setColour (TextEditor::textColourId, Colours::black);
90  label->setColour (TextEditor::backgroundColourId, Colour (0x0));
91 
92  addAndMakeVisible (spectrogram = new AudioSpectrumDisplay());
93  spectrogram->setName (T("new component"));
94 
95  addAndMakeVisible (offsetSlider = new Slider (T("new slider")));
96  offsetSlider->setRange (0, 1, 0);
97  offsetSlider->setSliderStyle (Slider::LinearHorizontal);
98  offsetSlider->setTextBoxStyle (Slider::NoTextBox, true, 80, 20);
99  offsetSlider->addListener (this);
100 
101  addAndMakeVisible (loadButton = new TextButton (T("new button")));
102  loadButton->setButtonText (T("File"));
103  loadButton->addButtonListener (this);
104 
105  addAndMakeVisible (analyzeButton = new TextButton (T("new button")));
106  analyzeButton->setButtonText (T("Analyze"));
107  analyzeButton->addButtonListener (this);
108 
109  addAndMakeVisible (filterButton = new TextButton (T("new button")));
110  filterButton->setButtonText (T("Apply Filter"));
111  filterButton->addButtonListener (this);
112 
113  addAndMakeVisible (playSource = new TextButton (T("playSource")));
114  playSource->setButtonText (T("Play Source"));
115  playSource->addButtonListener (this);
116 
117  addAndMakeVisible (fftLenCombo = new ComboBox (T("new combo box")));
118  fftLenCombo->setEditableText (true);
119  fftLenCombo->setJustificationType (Justification::centredLeft);
120  fftLenCombo->setTextWhenNothingSelected (String::empty);
121  fftLenCombo->setTextWhenNoChoicesAvailable (T("(no choices)"));
122  fftLenCombo->addItem (T("128"), 1);
123  fftLenCombo->addItem (T("256"), 2);
124  fftLenCombo->addItem (T("512"), 3);
125  fftLenCombo->addItem (T("1024"), 4);
126  fftLenCombo->addItem (T("2048"), 5);
127  fftLenCombo->addItem (T("4096"), 6);
128  fftLenCombo->addItem (T("8192"), 7);
129  fftLenCombo->addListener (this);
130 
131  addAndMakeVisible (winCombo = new ComboBox (T("new combo box")));
132  winCombo->setEditableText (false);
133  winCombo->setJustificationType (Justification::centredLeft);
134  winCombo->setTextWhenNothingSelected (String::empty);
135  winCombo->setTextWhenNoChoicesAvailable (T("(no choices)"));
136  winCombo->addItem (T("Rect"), 1);
137  winCombo->addItem (T("Tri"), 2);
138  winCombo->addItem (T("Hanning"), 3);
139  winCombo->addItem (T("Hamming"), 4);
140  winCombo->addListener (this);
141 
142  addAndMakeVisible (label2 = new Label (T("new label"),
143  T("Window")));
144  label2->setFont (Font (15.0000f, Font::plain));
145  label2->setJustificationType (Justification::centredLeft);
146  label2->setEditable (false, false, false);
147  label2->setColour (TextEditor::textColourId, Colours::black);
148  label2->setColour (TextEditor::backgroundColourId, Colour (0x0));
149 
150  addAndMakeVisible (label3 = new Label (T("new label"),
151  T("Hi-Pass")));
152  label3->setFont (Font (15.0000f, Font::plain));
153  label3->setJustificationType (Justification::centredLeft);
154  label3->setEditable (false, false, false);
155  label3->setColour (TextEditor::textColourId, Colours::black);
156  label3->setColour (TextEditor::backgroundColourId, Colour (0x0));
157 
158  addAndMakeVisible (label4 = new Label (T("new label"),
159  T("FFT Len")));
160  label4->setFont (Font (15.0000f, Font::plain));
161  label4->setJustificationType (Justification::centredLeft);
162  label4->setEditable (false, false, false);
163  label4->setColour (TextEditor::textColourId, Colours::black);
164  label4->setColour (TextEditor::backgroundColourId, Colour (0x0));
165 
166  addAndMakeVisible (hiPassSlider = new Slider (T("new slider")));
167  hiPassSlider->setRange (0, 10000, 0);
168  hiPassSlider->setSliderStyle (Slider::LinearHorizontal);
169  hiPassSlider->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
170  hiPassSlider->addListener (this);
171 
172  addAndMakeVisible (label5 = new Label (T("new label"),
173  T("Lo-Pass")));
174  label5->setFont (Font (15.0000f, Font::plain));
175  label5->setJustificationType (Justification::centredLeft);
176  label5->setEditable (false, false, false);
177  label5->setColour (TextEditor::textColourId, Colours::black);
178  label5->setColour (TextEditor::backgroundColourId, Colour (0x0));
179 
180  addAndMakeVisible (loPassSlider = new Slider (T("new slider")));
181  loPassSlider->setRange (0, 10000, 0);
182  loPassSlider->setSliderStyle (Slider::LinearHorizontal);
183  loPassSlider->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
184  loPassSlider->addListener (this);
185 
186  addAndMakeVisible (label6 = new Label (T("new label"),
187  T("Threshold")));
188  label6->setFont (Font (15.0000f, Font::plain));
189  label6->setJustificationType (Justification::centredLeft);
190  label6->setEditable (false, false, false);
191  label6->setColour (TextEditor::textColourId, Colours::black);
192  label6->setColour (TextEditor::backgroundColourId, Colour (0x0));
193 
194  addAndMakeVisible (thresholdSlider = new Slider (T("new slider")));
195  thresholdSlider->setRange (0, 1, 0);
196  thresholdSlider->setSliderStyle (Slider::LinearHorizontal);
197  thresholdSlider->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
198  thresholdSlider->addListener (this);
199 
200  addAndMakeVisible (scaleCombo = new ComboBox (T("new combo box")));
201  scaleCombo->setEditableText (true);
202  scaleCombo->setJustificationType (Justification::centredLeft);
203  scaleCombo->setTextWhenNothingSelected (String::empty);
204  scaleCombo->setTextWhenNoChoicesAvailable (T("(no choices)"));
205  scaleCombo->addItem (T("Lin"), 1);
206  scaleCombo->addItem (T("Log"), 2);
207  scaleCombo->addListener (this);
208 
209  addAndMakeVisible (displayCombo = new ComboBox (T("new combo box")));
210  displayCombo->setEditableText (false);
211  displayCombo->setJustificationType (Justification::centredLeft);
212  displayCombo->setTextWhenNothingSelected (String::empty);
213  displayCombo->setTextWhenNoChoicesAvailable (T("(no choices)"));
214  displayCombo->addItem (T("Spectrum"), 1);
215  displayCombo->addItem (T("Spectrogram"), 2);
216  displayCombo->addListener (this);
217 
218  addAndMakeVisible (label7 = new Label (T("new label"),
219  T("Display")));
220  label7->setFont (Font (15.0000f, Font::plain));
221  label7->setJustificationType (Justification::centredLeft);
222  label7->setEditable (false, false, false);
223  label7->setColour (TextEditor::textColourId, Colours::black);
224  label7->setColour (TextEditor::backgroundColourId, Colour (0x0));
225 
226  addAndMakeVisible (label8 = new Label (T("new label"),
227  T("Scale")));
228  label8->setFont (Font (15.0000f, Font::plain));
229  label8->setJustificationType (Justification::centredLeft);
230  label8->setEditable (false, false, false);
231  label8->setColour (TextEditor::textColourId, Colours::black);
232  label8->setColour (TextEditor::backgroundColourId, Colour (0x0));
233 
234  addAndMakeVisible (overlapCombo = new ComboBox (T("new combo box")));
235  overlapCombo->setEditableText (false);
236  overlapCombo->setJustificationType (Justification::centredLeft);
237  overlapCombo->setTextWhenNothingSelected (String::empty);
238  overlapCombo->setTextWhenNoChoicesAvailable (T("(no choices)"));
239  overlapCombo->addItem (T("8"), 1);
240  overlapCombo->addItem (T("4"), 2);
241  overlapCombo->addItem (T("2"), 3);
242  overlapCombo->addItem (T("1"), 4);
243  overlapCombo->addItem (T("0.5"), 5);
244  overlapCombo->addItem (T("0.25"), 6);
245  overlapCombo->addListener (this);
246 
247  addAndMakeVisible (label9 = new Label (T("new label"),
248  T("Overlap")));
249  label9->setFont (Font (15.0000f, Font::plain));
250  label9->setJustificationType (Justification::centredLeft);
251  label9->setEditable (false, false, false);
252  label9->setColour (TextEditor::textColourId, Colours::black);
253  label9->setColour (TextEditor::backgroundColourId, Colour (0x0));
254 
255  addAndMakeVisible (label10 = new Label (T("new label"),
256  T("Time Scale")));
257  label10->setFont (Font (15.0000f, Font::plain));
258  label10->setJustificationType (Justification::centredLeft);
259  label10->setEditable (false, false, false);
260  label10->setColour (TextEditor::textColourId, Colours::black);
261  label10->setColour (TextEditor::backgroundColourId, Colour (0x0));
262 
263  addAndMakeVisible (timeSlider = new Slider (T("new slider")));
264  timeSlider->setRange (0.1, 10, 0);
265  timeSlider->setSliderStyle (Slider::LinearHorizontal);
266  timeSlider->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
267  timeSlider->addListener (this);
268 
269  addAndMakeVisible (label11 = new Label (T("new label"),
270  T("Pitch Scale")));
271  label11->setFont (Font (15.0000f, Font::plain));
272  label11->setJustificationType (Justification::centredLeft);
273  label11->setEditable (false, false, false);
274  label11->setColour (TextEditor::textColourId, Colours::black);
275  label11->setColour (TextEditor::backgroundColourId, Colour (0x0));
276 
277  addAndMakeVisible (pitchSlider = new Slider (T("new slider")));
278  pitchSlider->setRange (0.1, 10, 0);
279  pitchSlider->setSliderStyle (Slider::LinearHorizontal);
280  pitchSlider->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
281  pitchSlider->addListener (this);
282 
283  addAndMakeVisible (fileInfo = new Label (T("new label"),
284  T("File info")));
285  fileInfo->setFont (Font (15.0000f, Font::plain));
286  fileInfo->setJustificationType (Justification::centredLeft);
287  fileInfo->setEditable (false, false, false);
288  fileInfo->setColour (TextEditor::textColourId, Colours::black);
289  fileInfo->setColour (TextEditor::backgroundColourId, Colour (0x0));
290 
291 
292  //[UserPreSize]
293 
294  oscilloscope->initialise(0, 0, 0, false); // channel, rate, window, zeroX
295  spectrogram->initialise(0, 0, 0, false);
296 
297  //[/UserPreSize]
298 
299  setSize (800, 600);
300 
301  //[Constructor] You can add your own custom stuff here..
302 
303  mSndFile = 0;
304  mOutFile = 0;
305  mIO = 0;
306 
307  mSamples = 0;
308  mChannels = 0;
309  mSRate = 0;
310  totread = 0;
311  mFFTLen = 0;
312  mNumWins = 0;
313 
314  fftLenCombo->setSelectedItemIndex(3);
315  winCombo->setSelectedItemIndex(2);
316  scaleCombo->setSelectedItemIndex(0);
317  displayCombo->setSelectedItemIndex(0);
318  overlapCombo->setSelectedItemIndex(2);
319 
320  offsetSlider->setValue(0.0);
321  hiPassSlider->setValue(0.0);
322  loPassSlider->setValue(10000.0);
323  thresholdSlider->setValue(1.0);
324  timeSlider->setValue(1.0);
325  pitchSlider->setValue(1.0);
326  fileInfo->setText("No File", true);
327 // oscilloscope->start();
328 // spectrogram->start();
329 
330  //[/Constructor]
331 }
332 
334 {
335  //[Destructor_pre]. You can add your own custom destruction code here..
336  //[/Destructor_pre]
337 
338  deleteAndZero (playButton);
339  deleteAndZero (quitButton);
340  deleteAndZero (oscilloscope);
341  deleteAndZero (label);
342  deleteAndZero (spectrogram);
343  deleteAndZero (offsetSlider);
344  deleteAndZero (loadButton);
345  deleteAndZero (analyzeButton);
346  deleteAndZero (filterButton);
347  deleteAndZero (playSource);
348  deleteAndZero (fftLenCombo);
349  deleteAndZero (winCombo);
350  deleteAndZero (label2);
351  deleteAndZero (label3);
352  deleteAndZero (label4);
353  deleteAndZero (hiPassSlider);
354  deleteAndZero (label5);
355  deleteAndZero (loPassSlider);
356  deleteAndZero (label6);
357  deleteAndZero (thresholdSlider);
358  deleteAndZero (scaleCombo);
359  deleteAndZero (displayCombo);
360  deleteAndZero (label7);
361  deleteAndZero (label8);
362  deleteAndZero (overlapCombo);
363  deleteAndZero (label9);
364  deleteAndZero (label10);
365  deleteAndZero (timeSlider);
366  deleteAndZero (label11);
367  deleteAndZero (pitchSlider);
368  deleteAndZero (fileInfo);
369 
370  //[Destructor]. You can add your own custom destruction code here..
371  //[/Destructor]
372 }
373 
374 //==============================================================================
375 void CSLComponent::paint (Graphics& g)
376 {
377  //[UserPrePaint] Add your own custom painting code here..
378  //[/UserPrePaint]
379 
380  g.fillAll (Colour (0xffebd89b));
381 
382  //[UserPaint] Add your own custom painting code here..
383  //[/UserPaint]
384 }
385 
387 {
388  playButton->setBounds (600, 456, 150, 32);
389  quitButton->setBounds (704, 8, 88, 24);
390  oscilloscope->setBounds (8, 40, 784, 136);
391  label->setBounds (8, 568, 240, 24);
392  spectrogram->setBounds (8, 240, 784, 208);
393  offsetSlider->setBounds (8, 176, 784, 24);
394  loadButton->setBounds (8, 8, 48, 24);
395  analyzeButton->setBounds (592, 200, 160, 32);
396  filterButton->setBounds (424, 456, 152, 32);
397  playSource->setBounds (592, 8, 104, 24);
398  fftLenCombo->setBounds (72, 204, 88, 24);
399  winCombo->setBounds (232, 204, 104, 24);
400  label2->setBounds (168, 204, 63, 24);
401  label3->setBounds (384, 504, 64, 24);
402  label4->setBounds (8, 204, 63, 24);
403  hiPassSlider->setBounds (464, 504, 312, 24);
404  label5->setBounds (384, 536, 63, 24);
405  loPassSlider->setBounds (464, 536, 312, 24);
406  label6->setBounds (384, 568, 72, 24);
407  thresholdSlider->setBounds (464, 568, 312, 24);
408  scaleCombo->setBounds (80, 456, 88, 24);
409  displayCombo->setBounds (240, 456, 104, 24);
410  label7->setBounds (176, 456, 63, 24);
411  label8->setBounds (16, 456, 63, 24);
412  overlapCombo->setBounds (408, 204, 104, 24);
413  label9->setBounds (344, 204, 63, 24);
414  label10->setBounds (8, 504, 72, 24);
415  timeSlider->setBounds (88, 504, 288, 24);
416  label11->setBounds (8, 536, 72, 24);
417  pitchSlider->setBounds (88, 536, 288, 24);
418  fileInfo->setBounds (64, 8, 520, 24);
419  //[UserResized] Add your own custom resize handling here..
420  //[/UserResized]
421 }
422 
423 void CSLComponent::buttonClicked (Button* buttonThatWasClicked)
424 {
425  //[UserbuttonClicked_Pre]
426  //[/UserbuttonClicked_Pre]
427 
428  if (buttonThatWasClicked == playButton)
429  {
430  //[UserButtonCode_playButton] -- add your button handler code here..
431 
432  ////// PLAY //////
433  if (mOutFile == 0)
434  return;
435  mIO->setRoot(*mOutFile);
436  mIO->start();
437 
438  //[/UserButtonCode_playButton]
439  }
440  else if (buttonThatWasClicked == quitButton)
441  {
442  //[UserButtonCode_quitButton] -- add your button handler code here..
443 
444  JUCEApplication::quit(); ////// QUIT //////
445 
446  //[/UserButtonCode_quitButton]
447  }
448  else if (buttonThatWasClicked == loadButton)
449  {
450  //[UserButtonCode_loadButton] -- add your button handler code here..
451 
452  ////// LOAD FILE //////
453  FileChooser chooser (T("Choose file to open"),File::nonexistent,"*",true);
454  File inFile;
455  if ( ! chooser.browseForFileToOpen()) {
456  fileInfo->setText("No File",true);
457  return;
458  }
459  inFile = chooser.getResult();
461  mOutFile = 0;
462 
463  try {
464  mSndFile = new SoundFile(inFile.getFullPathName().toUTF8());
465  mSndFile->openForRead();
466  } catch (CException) {
467  logMsg(kLogError, "Cannot read sound file...");
468  return;
469  }
470  mSamples = mSndFile->duration();
471  mChannels = mSndFile->channels();
472  mSRate = mSndFile->frameRate();
473  mFFTLen = this->getFFTLen();
474  totread = 0;
475  if (mSRate != CGestalt::frameRate())
476  CGestalt::setFrameRate(mSRate);
477 
478  char msg[CSL_NAME_LEN];
479  sprintf(msg, "\"%s\" - %d Hz, %d ch, %d fr, %5.2f sec",
480  mSndFile->path().c_str(), mSRate, mChannels,
481  mSamples, mSndFile->durationInSecs());
482  printf("\nLoad file: \"%s\" - %d Hz, %d ch, %d fr, %5.2f sec, %d windows\n\n",
483  mSndFile->path().c_str(), mSRate, mChannels,
484  mSamples, mSndFile->durationInSecs(), mSamples / (mFFTLen ));
485  fileInfo->setText(msg,true);
486  mFFTLen = this->getFFTLen();
487  if (mFFTLen != CGestalt::blockSize())
488  CGestalt::setBlockSize(mFFTLen);
489  mIO = new PAIO(); // create the PortAudio IO object
490  mIO->open();
491  float *inPtr[1];
492  inPtr[0] = mSndFile->mSampleBuffer.mBuffers[0];
493  oscilloscope->audioDeviceIOCallback (0, 1, inPtr, 1, mSamples);
494  oscilloscope->repaint();
495 
496  //[/UserButtonCode_loadButton]
497  }
498  else if (buttonThatWasClicked == analyzeButton)
499  {
500  //[UserButtonCode_analyzeButton] -- add your button handler code here..
501 
502  ////// ANALYZE //////
503  if (mSndFile == 0)
504  return;
505  mFFTLen = this->getFFTLen();
506  mNumWins = mSamples / mFFTLen + 1;
507  printf("\nAnalyze: %d windows, FFTLen = %d\n", mNumWins, mFFTLen);
508  if (mFFTLen != CGestalt::blockSize())
509  CGestalt::setBlockSize(mFFTLen);
510 
511  // allocate buffers
514 
515  // setup FFT
516  FFT anFFT(*mSndFile, CSL_FFT_REAL, kFFTMeasure, mFFTLen);
517  Buffer tempBuffer(1, mFFTLen);
518  float *inPtr[1];
519 
520  // analysis loop
521  for (unsigned i = 0; i < mNumWins; i++) {
522  tempBuffer.mBuffers[0] = mSpectBuffer.mBuffers[i];
523  anFFT.nextBuffer(tempBuffer);
524  inPtr[0] = tempBuffer.mBuffers[0];
525  spectrogram->audioDeviceIOCallback (0, 1, inPtr, i, (int) mFFTLen);
526  }
527 
528  //[/UserButtonCode_analyzeButton]
529  }
530  else if (buttonThatWasClicked == filterButton)
531  {
532  //[UserButtonCode_filterButton] -- add your button handler code here..
533 
534  ////// SYNTHESIZE //////
535  if (mSndFile == 0)
536  return;
538  return;
539  printf("\nSynthesize: %d windows, FFTLen = %d\n", mNumWins, mFFTLen);
540  IFFT anIFFT; // create IFFT
541  mOutFile = new SoundFile();
542  Buffer * outBuffer = & mOutFile->mSampleBuffer;
543  outBuffer->setSize(1, mSamples + mFFTLen); // set up big output buffer
544  outBuffer->allocateBuffers();
545  Buffer tempBuffer(1, mFFTLen);
546 // tempBuffer.allocateBuffers();
547  // FFTW half-complex format = r0, r1, r2, ..., rn/2, i(n+1)/2-1, ..., i2, i1
548  for (unsigned i = 0; i < mNumWins; i++) { // synthesis loop
549  float * spect = mSpectBuffer.mBuffers[i];
550  tempBuffer.mBuffers[0] = & outBuffer->mBuffers[0][i*mFFTLen];
551  for (unsigned j = 0; j < mFFTLen / 2; j++) // spectral copy loop
552  anIFFT.setBin(j, spect[j + 1], spect[mFFTLen - (j + 1)]);
553  anIFFT.nextBuffer(tempBuffer);
554  }
555 
556  //[/UserButtonCode_filterButton]
557  }
558  else if (buttonThatWasClicked == playSource)
559  {
560  //[UserButtonCode_playSource] -- add your button handler code here..
561 
562  ////// PLAY SRC //////
563  if (mSndFile == 0)
564  return;
565  mIO->clearRoot();
566  mSndFile->trigger();
567  mIO->setRoot(*mSndFile);
568  mIO->start();
569 
570  //[/UserButtonCode_playSource]
571  }
572 
573  //[UserbuttonClicked_Post]
574 
575 // startTimer(200); // stars the timer to update the slider each 200 ms
576 
577  //[/UserbuttonClicked_Post]
578 }
579 
580 void CSLComponent::sliderValueChanged (Slider* sliderThatWasMoved)
581 {
582  //[UsersliderValueChanged_Pre]
583  //[/UsersliderValueChanged_Pre]
584 
585  if (sliderThatWasMoved == offsetSlider)
586  {
587  //[UserSliderCode_offsetSlider] -- add your slider handling code here..
588 
589  // drag in slider seeks in spectrum
590  if (mSndFile == 0) // not if no file loaded
591  return;
592  if ( ! mSpectBuffer.mAreBuffersAllocated) // or no analysis
593  return;
594  if (displayCombo->getSelectedItemIndex()) // or in spectrogram mode
595  return;
596 
597  float val = (float) offsetSlider->getValue() * (float) (mNumWins - 1);
598  spectrogram->setIndicator((unsigned) val);
599 // printf("\nSelect window %d\n", (unsigned) val);
600  spectrogram->repaint();
601 
602  //[/UserSliderCode_offsetSlider]
603  }
604  else if (sliderThatWasMoved == hiPassSlider)
605  {
606  //[UserSliderCode_hiPassSlider] -- add your slider handling code here..
607  //[/UserSliderCode_hiPassSlider]
608  }
609  else if (sliderThatWasMoved == loPassSlider)
610  {
611  //[UserSliderCode_loPassSlider] -- add your slider handling code here..
612  //[/UserSliderCode_loPassSlider]
613  }
614  else if (sliderThatWasMoved == thresholdSlider)
615  {
616  //[UserSliderCode_thresholdSlider] -- add your slider handling code here..
617  //[/UserSliderCode_thresholdSlider]
618  }
619  else if (sliderThatWasMoved == timeSlider)
620  {
621  //[UserSliderCode_timeSlider] -- add your slider handling code here..
622  //[/UserSliderCode_timeSlider]
623  }
624  else if (sliderThatWasMoved == pitchSlider)
625  {
626  //[UserSliderCode_pitchSlider] -- add your slider handling code here..
627  //[/UserSliderCode_pitchSlider]
628  }
629 
630  //[UsersliderValueChanged_Post]
631  //[/UsersliderValueChanged_Post]
632 }
633 
634 void CSLComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
635 {
636  //[UsercomboBoxChanged_Pre]
637  //[/UsercomboBoxChanged_Pre]
638 
639  if (comboBoxThatHasChanged == fftLenCombo)
640  {
641  //[UserComboBoxCode_fftLenCombo] -- add your combo box handling code here..
642  //[/UserComboBoxCode_fftLenCombo]
643  }
644  else if (comboBoxThatHasChanged == winCombo)
645  {
646  //[UserComboBoxCode_winCombo] -- add your combo box handling code here..
647  //[/UserComboBoxCode_winCombo]
648  }
649  else if (comboBoxThatHasChanged == scaleCombo)
650  {
651  //[UserComboBoxCode_scaleCombo] -- add your combo box handling code here..
652 
653  if (scaleCombo->getSelectedItemIndex() == 0) {
654  spectrogram->mLogDisplay = false;
655  printf("Select linear display (%d)\n", scaleCombo->getSelectedItemIndex());
656  } else {
657  spectrogram->mLogDisplay = true;
658  printf("Select log display\n");
659  }
660  spectrogram->repaint();
661 
662  //[/UserComboBoxCode_scaleCombo]
663  }
664  else if (comboBoxThatHasChanged == displayCombo)
665  {
666  //[UserComboBoxCode_displayCombo] -- add your combo box handling code here..
667 
668  if (displayCombo->getSelectedItemIndex() == 0) {
669  spectrogram->mSpectroDisplay = false;
670  printf("Select spectral slice display (%d)\n", scaleCombo->getSelectedItemIndex());
671  } else {
673  printf("Select spectrogram display\n");
674  }
675  spectrogram->repaint();
676 
677  //[/UserComboBoxCode_displayCombo]
678  }
679  else if (comboBoxThatHasChanged == overlapCombo)
680  {
681  //[UserComboBoxCode_overlapCombo] -- add your combo box handling code here..
682  //[/UserComboBoxCode_overlapCombo]
683  }
684 
685  //[UsercomboBoxChanged_Post]
686  //[/UsercomboBoxChanged_Post]
687 }
688 
689 
690 //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
691 
692 Component* createCSLComponent() {
693  return new CSLComponent();
694 }
695 
696 // timer callback updates the slider
697 
699 // offsetSlider->setValue(10 * (float) totread / (float) mSamples);
700 }
701 
703  int fftTable[] = { 128, 256, 512, 1024, 2048, 4096, 8192 };
704  return(fftTable[fftLenCombo->getSelectedItemIndex()]);
705 }
706 
708  int oTable[] = { 8.0, 4.0, 2.0, 1.0, 0.5, 0.25 };
709  return(oTable[overlapCombo->getSelectedItemIndex()]);
710 }
711 
712 //[/MiscUserCode]
713 
714 
715 //==============================================================================
716 #if 0
717 /* -- Jucer information section --
718 
719  This is where the Jucer puts all of its metadata, so don't change anything in here!
720 
721 BEGIN_JUCER_METADATA
722 
723 <JUCER_COMPONENT documentType="Component" className="CSLComponent" componentName=""
724  parentClasses="public Component, public Timer" constructorParams=""
725  variableInitialisers="" snapPixels="8" snapActive="1" snapShown="1"
726  overlayOpacity="0.330000013" fixedSize="1" initialWidth="800"
727  initialHeight="600">
728  <BACKGROUND backgroundColour="ffebd89b"/>
729  <TEXTBUTTON name="playNote" id="ed1811e776eea99b" memberName="playButton"
730  virtualName="" explicitFocusOrder="0" pos="600 456 150 32" buttonText="Play Resynth"
731  connectedEdges="0" needsCallback="1" radioGroupId="0"/>
732  <TEXTBUTTON name="quitAction" id="dbaf2871fd41de83" memberName="quitButton"
733  virtualName="" explicitFocusOrder="0" pos="704 8 88 24" buttonText="Quit"
734  connectedEdges="0" needsCallback="1" radioGroupId="0"/>
735  <GENERICCOMPONENT name="new component" id="d64c351a292a43a4" memberName="oscilloscope"
736  virtualName="" explicitFocusOrder="0" pos="8 40 784 136" class="AudioWaveformDisplay"
737  params=""/>
738  <LABEL name="CSL test" id="a9876f115ab3c22e" memberName="label" virtualName=""
739  explicitFocusOrder="0" pos="8 568 240 24" textCol="ff2013da"
740  edTextCol="ff000000" edBkgCol="0" labelText="CSL Spectral Processing"
741  editableSingleClick="0" editableDoubleClick="0" focusDiscardsChanges="0"
742  fontname="Default serif font" fontsize="24" bold="1" italic="0"
743  justification="33"/>
744  <GENERICCOMPONENT name="new component" id="4aa0f216430fecde" memberName="spectrogram"
745  virtualName="" explicitFocusOrder="0" pos="8 240 784 208" class="AudioWaveformDisplay"
746  params=""/>
747  <SLIDER name="new slider" id="c62ea84a7afde2e3" memberName="offsetSlider"
748  virtualName="" explicitFocusOrder="0" pos="8 176 784 24" min="0"
749  max="1" int="0" style="LinearHorizontal" textBoxPos="NoTextBox"
750  textBoxEditable="0" textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
751  <TEXTBUTTON name="new button" id="8a98399a2f7021e3" memberName="loadButton"
752  virtualName="" explicitFocusOrder="0" pos="8 8 48 24" buttonText="File"
753  connectedEdges="0" needsCallback="1" radioGroupId="0"/>
754  <TEXTBUTTON name="new button" id="ff32b69787adbf6c" memberName="analyzeButton"
755  virtualName="" explicitFocusOrder="0" pos="592 200 160 32" buttonText="Analyze"
756  connectedEdges="0" needsCallback="1" radioGroupId="0"/>
757  <TEXTBUTTON name="new button" id="3a78edfc8efb61b0" memberName="filterButton"
758  virtualName="" explicitFocusOrder="0" pos="424 456 152 32" buttonText="Apply Filter"
759  connectedEdges="0" needsCallback="1" radioGroupId="0"/>
760  <TEXTBUTTON name="playSource" id="cee4f69fb5f4995e" memberName="playSource"
761  virtualName="" explicitFocusOrder="0" pos="592 8 104 24" buttonText="Play Source"
762  connectedEdges="0" needsCallback="1" radioGroupId="0"/>
763  <COMBOBOX name="new combo box" id="fb6a849a3adce0ac" memberName="fftLenCombo"
764  virtualName="" explicitFocusOrder="0" pos="72 204 88 24" editable="1"
765  layout="33" items="128&#10;256&#10;512&#10;1024&#10;2048&#10;4096&#10;8192" textWhenNonSelected=""
766  textWhenNoItems="(no choices)"/>
767  <COMBOBOX name="new combo box" id="459ce4827300838b" memberName="winCombo"
768  virtualName="" explicitFocusOrder="0" pos="232 204 104 24" editable="0"
769  layout="33" items="Rect&#10;Tri&#10;Hanning&#10;Hamming" textWhenNonSelected=""
770  textWhenNoItems="(no choices)"/>
771  <LABEL name="new label" id="740396597f99f0ff" memberName="label2" virtualName=""
772  explicitFocusOrder="0" pos="168 204 63 24" edTextCol="ff000000"
773  edBkgCol="0" labelText="Window" editableSingleClick="0" editableDoubleClick="0"
774  focusDiscardsChanges="0" fontname="Default font" fontsize="15"
775  bold="0" italic="0" justification="33"/>
776  <LABEL name="new label" id="902a00a7ae61bc1e" memberName="label3" virtualName=""
777  explicitFocusOrder="0" pos="384 504 64 24" edTextCol="ff000000"
778  edBkgCol="0" labelText="Hi-Pass" editableSingleClick="0" editableDoubleClick="0"
779  focusDiscardsChanges="0" fontname="Default font" fontsize="15"
780  bold="0" italic="0" justification="33"/>
781  <LABEL name="new label" id="f62e67a204527431" memberName="label4" virtualName=""
782  explicitFocusOrder="0" pos="8 204 63 24" edTextCol="ff000000"
783  edBkgCol="0" labelText="FFT Len" editableSingleClick="0" editableDoubleClick="0"
784  focusDiscardsChanges="0" fontname="Default font" fontsize="15"
785  bold="0" italic="0" justification="33"/>
786  <SLIDER name="new slider" id="a51dbd1da4384224" memberName="hiPassSlider"
787  virtualName="" explicitFocusOrder="0" pos="464 504 312 24" min="0"
788  max="10000" int="0" style="LinearHorizontal" textBoxPos="TextBoxLeft"
789  textBoxEditable="1" textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
790  <LABEL name="new label" id="16c1b5d4f842ab95" memberName="label5" virtualName=""
791  explicitFocusOrder="0" pos="384 536 63 24" edTextCol="ff000000"
792  edBkgCol="0" labelText="Lo-Pass" editableSingleClick="0" editableDoubleClick="0"
793  focusDiscardsChanges="0" fontname="Default font" fontsize="15"
794  bold="0" italic="0" justification="33"/>
795  <SLIDER name="new slider" id="b94ee2e0cd4407fd" memberName="loPassSlider"
796  virtualName="" explicitFocusOrder="0" pos="464 536 312 24" min="0"
797  max="10000" int="0" style="LinearHorizontal" textBoxPos="TextBoxLeft"
798  textBoxEditable="1" textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
799  <LABEL name="new label" id="6278c834e0564462" memberName="label6" virtualName=""
800  explicitFocusOrder="0" pos="384 568 72 24" edTextCol="ff000000"
801  edBkgCol="0" labelText="Threshold" editableSingleClick="0" editableDoubleClick="0"
802  focusDiscardsChanges="0" fontname="Default font" fontsize="15"
803  bold="0" italic="0" justification="33"/>
804  <SLIDER name="new slider" id="241faa25d58e045" memberName="thresholdSlider"
805  virtualName="" explicitFocusOrder="0" pos="464 568 312 24" min="0"
806  max="1" int="0" style="LinearHorizontal" textBoxPos="TextBoxLeft"
807  textBoxEditable="1" textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
808  <COMBOBOX name="new combo box" id="81231ff6eb6dbc5b" memberName="scaleCombo"
809  virtualName="" explicitFocusOrder="0" pos="80 456 88 24" editable="1"
810  layout="33" items="Lin&#10;Log" textWhenNonSelected="" textWhenNoItems="(no choices)"/>
811  <COMBOBOX name="new combo box" id="ff0db135c97cc693" memberName="displayCombo"
812  virtualName="" explicitFocusOrder="0" pos="240 456 104 24" editable="0"
813  layout="33" items="Spectrum&#10;Spectrogram" textWhenNonSelected=""
814  textWhenNoItems="(no choices)"/>
815  <LABEL name="new label" id="ff70cdfd0e8ee6ac" memberName="label7" virtualName=""
816  explicitFocusOrder="0" pos="176 456 63 24" edTextCol="ff000000"
817  edBkgCol="0" labelText="Display" editableSingleClick="0" editableDoubleClick="0"
818  focusDiscardsChanges="0" fontname="Default font" fontsize="15"
819  bold="0" italic="0" justification="33"/>
820  <LABEL name="new label" id="8802d29b86aa6aea" memberName="label8" virtualName=""
821  explicitFocusOrder="0" pos="16 456 63 24" edTextCol="ff000000"
822  edBkgCol="0" labelText="Scale" editableSingleClick="0" editableDoubleClick="0"
823  focusDiscardsChanges="0" fontname="Default font" fontsize="15"
824  bold="0" italic="0" justification="33"/>
825  <COMBOBOX name="new combo box" id="98e9ad89310492cc" memberName="overlapCombo"
826  virtualName="" explicitFocusOrder="0" pos="408 204 104 24" editable="0"
827  layout="33" items="8&#10;4&#10;2&#10;1&#10;0.5&#10;0.25" textWhenNonSelected="" textWhenNoItems="(no choices)"/>
828  <LABEL name="new label" id="235b28d85dd079e9" memberName="label9" virtualName=""
829  explicitFocusOrder="0" pos="344 204 63 24" edTextCol="ff000000"
830  edBkgCol="0" labelText="Overlap" editableSingleClick="0" editableDoubleClick="0"
831  focusDiscardsChanges="0" fontname="Default font" fontsize="15"
832  bold="0" italic="0" justification="33"/>
833  <LABEL name="new label" id="45edf99a4f46d71f" memberName="label10" virtualName=""
834  explicitFocusOrder="0" pos="8 504 72 24" edTextCol="ff000000"
835  edBkgCol="0" labelText="Time Scale" editableSingleClick="0" editableDoubleClick="0"
836  focusDiscardsChanges="0" fontname="Default font" fontsize="15"
837  bold="0" italic="0" justification="33"/>
838  <SLIDER name="new slider" id="a7d8eb7cdc634436" memberName="timeSlider"
839  virtualName="" explicitFocusOrder="0" pos="88 504 288 24" min="0.1"
840  max="10" int="0" style="LinearHorizontal" textBoxPos="TextBoxLeft"
841  textBoxEditable="1" textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
842  <LABEL name="new label" id="6d9b01ae5485de4d" memberName="label11" virtualName=""
843  explicitFocusOrder="0" pos="8 536 72 24" edTextCol="ff000000"
844  edBkgCol="0" labelText="Pitch Scale" editableSingleClick="0"
845  editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default font"
846  fontsize="15" bold="0" italic="0" justification="33"/>
847  <SLIDER name="new slider" id="3c91ea4babc105f4" memberName="pitchSlider"
848  virtualName="" explicitFocusOrder="0" pos="88 536 288 24" min="0.1"
849  max="10" int="0" style="LinearHorizontal" textBoxPos="TextBoxLeft"
850  textBoxEditable="1" textBoxWidth="80" textBoxHeight="20" skewFactor="1"/>
851  <LABEL name="new label" id="1a8f7fc3a78b7e8b" memberName="fileInfo"
852  virtualName="" explicitFocusOrder="0" pos="64 8 520 24" edTextCol="ff000000"
853  edBkgCol="0" labelText="File info" editableSingleClick="0" editableDoubleClick="0"
854  focusDiscardsChanges="0" fontname="Default font" fontsize="15"
855  bold="0" italic="0" justification="33"/>
856 </JUCER_COMPONENT>
857 
858 END_JUCER_METADATA
859 */
860 #endif
void setBin(int binNumber, float realPart, float imagPart)
Definition: Spectral.cpp:81
void logMsg(const char *format,...)
These are the public logging messages.
Definition: CGestalt.cpp:292
void nextBuffer(Buffer &outputBuffer)
get a buffer of Frames – this is the core CSL "pull" function; the given buffer can be written into...
Definition: Spectral.cpp:137
bool mAreBuffersAllocated
are the buffers allocated?
Definition: CSL_Core.h:120
Slider * timeSlider
Definition: SpectralProc.h:117
Inverse FFT.
Definition: Spectral.h:47
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
TextButton * loadButton
Definition: SpectralProc.h:96
Label * label4
Definition: SpectralProc.h:104
void comboBoxChanged(ComboBox *comboBoxThatHasChanged) override
void setIndicator(unsigned value)
Definition: JCSL_Widgets.h:47
Label * label10
Definition: SpectralProc.h:116
unsigned mChannels
Definition: SpectralProc.h:81
Label * label2
Definition: SpectralProc.h:102
csl::IO * mIO
Definition: SpectralProc.h:78
TextButton * filterButton
Definition: SpectralProc.h:98
Label * label5
Definition: SpectralProc.h:106
virtual void open()
Definition: CSL_Core.h:759
TextButton * playSource
Definition: SpectralProc.h:99
virtual void audioDeviceIOCallback(const float **inputChannelData, int totalNumInputChannels, float **outputChannelData, int totalNumOutputChannels, int numSamples)
csl::Buffer mSpectBuffer
Definition: SpectralProc.h:76
Label * label7
Definition: SpectralProc.h:112
void freeBuffers()
fcn to free them
Definition: CSL_Core.cpp:141
Label * label3
Definition: SpectralProc.h:103
void setSize(unsigned numChannels, unsigned numFrames)
Definition: CSL_Core.cpp:75
Label * fileInfo
Definition: SpectralProc.h:120
unsigned mFFTLen
Definition: SpectralProc.h:84
SampleBufferVector mBuffers
the storage vector – pointers to (SampleBuffer) buffers
Definition: CSL_Core.h:182
ComboBox * scaleCombo
Definition: SpectralProc.h:110
ComboBox * displayCombo
Definition: SpectralProc.h:111
#define CSL_NAME_LEN
default string length
Definition: CSL_Types.h:121
std::unique_ptr< Label > label
csl::SoundFile * mOutFile
Definition: SpectralProc.h:77
unsigned mSamples
Definition: SpectralProc.h:80
virtual void start()
Definition: CSL_Core.h:761
~CSLComponent() override
float getOverlap()
ComboBox * overlapCombo
Definition: SpectralProc.h:114
std::unique_ptr< TextButton > playButton
void resized() override
Label * label8
Definition: SpectralProc.h:113
Forward FFT unit generator is an Effect because it handles an input It puts spectral frames in the ou...
Definition: Spectral.h:23
Slider * hiPassSlider
Definition: SpectralProc.h:105
AudioWaveformDisplay * oscilloscope
Definition: SpectralProc.h:92
csl::Buffer outBuffer
unsigned mNumWins
Definition: SpectralProc.h:85
Label * label11
Definition: SpectralProc.h:118
Label * label6
Definition: SpectralProc.h:108
The PortAudio IO class.
Definition: PAIO.h:21
unsigned getFFTLen()
Slider * loPassSlider
Definition: SpectralProc.h:107
Slider * thresholdSlider
Definition: SpectralProc.h:109
void buttonClicked(Button *buttonThatWasClicked) override
void setRoot(UnitGenerator &root)
set/clear my graph root generator
Definition: CSL_Core.cpp:1405
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Definition: CSL_Core.h:106
ComboBox * winCombo
Definition: SpectralProc.h:101
csl::SoundFile * mSndFile
Definition: SpectralProc.h:75
Slider * offsetSlider
Definition: SpectralProc.h:95
void clearRoot()
Definition: CSL_Core.cpp:1410
std::unique_ptr< TextButton > quitButton
void paint(Graphics &g) override
unsigned totread
Definition: SpectralProc.h:83
void allocateBuffers()
fcn to malloc storage buffers
Definition: CSL_Core.cpp:122
Slider * pitchSlider
Definition: SpectralProc.h:119
unsigned mSRate
Definition: SpectralProc.h:82
Component * createCSLComponent()
Label * label9
Definition: SpectralProc.h:115
void sliderValueChanged(Slider *sliderThatWasMoved) override
ComboBox * fftLenCombo
Definition: SpectralProc.h:100
AudioSpectrumDisplay * spectrogram
Definition: SpectralProc.h:94
Base class of CSL exceptions (written upper-case). Has a string message.
TextButton * analyzeButton
Definition: SpectralProc.h:97
virtual void audioDeviceIOCallback(const float **inputChannelData, int totalNumInputChannels, float **outputChannelData, int totalNumOutputChannels, int numSamples)