f@0: #ifndef __ACCESSIBLESPECTRUMANALYSER__ f@0: #define __ACCESSIBLESPECTRUMANALYSER__ f@0: f@0: #include "IPlug_include_in_plug_hdr.h" f@0: f@0: #include f@0: f@0: #include "fft.h" f@0: #include "FreqView.h" f@0: f@0: #include "stk/include/SineWave.h" f@0: #include "stk/include/Envelope.h" f@0: #include "stk/include/ADSR.h" f@0: f@0: f@0: f@0: class AccessibleSpectrumAnalyser : public IPlug f@0: { f@0: public: f@0: f@0: AccessibleSpectrumAnalyser(IPlugInstanceInfo instanceInfo); f@0: ~AccessibleSpectrumAnalyser(); f@0: f@0: void Reset(); f@0: void OnParamChange(int paramIdx); f@0: f@0: void ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames); f@0: f@0: inline WDL_FFT_REAL magnitude(const WDL_FFT_COMPLEX & c) const f@0: { f@0: return 2 * sqrt(WDL_FFT_REAL(c.re * c.re + c.im * c.im)) / mNormFactor;// kFFTbufSize if rect window ; f@0: //return 2 * sqrt(WDL_FFT_REAL(c.re * c.re + c.im * c.im)) / kFFTbufSize ; //if rect window ; f@0: } f@0: f@0: /* for dry/wet mix */ f@0: inline double mix(double dry, double wet) const f@0: { f@0: return dry * mDry + wet * mWet; f@0: } f@0: f@0: inline static double midi2Freq(int note) f@0: { f@0: return 440. * pow(2., (note - 69.) / 12.); f@0: } f@0: f@0: inline double calculateSelectionEndFromView() f@0: { f@0: return BOUNDED(mFreqView->getSelectionStart() + mFreqView->getSelectionSize(), f@0: mFreqView->getSelectionStart()+kMinSelectionSize, f@0: GetSampleRate()/2); f@0: } f@0: f@0: inline bool binWithinSelection(int i) const f@0: { f@0: double binHz = i * mBinSizeHz; f@0: f@0: return ( binHz > mFreqView->getSelectionStart() && binHz mHannTable; f@0: double mNormFactor; f@0: f@0: double mBinSizeHz; f@0: f@0: double mDry; f@0: double mWet; f@0: double mSelectionEnd; f@0: double mThreshold; f@0: f@0: f@0: struct Sonification f@0: { f@0: /* the sine wave that is played */ f@0: stk::SineWave ugen; f@0: f@0: /* envelope of the sine wave */ f@0: stk::ADSR envelope; f@0: f@0: struct Panning f@0: { f@0: double left; f@0: double right; f@0: f@0: const double coeff; f@0: f@0: Panning(): coeff(std::sqrt(2)/2) {} f@0: f@0: /* position ranges from 0 to 1 */ f@0: void calculatePanningCoeff(double position) f@0: { f@0: /* map [0,1] to [-pi/4, pi/4] radians */ f@0: double theta = ((position*2)-1) * (PI/4); f@0: f@0: /* calculate left and right amplitudes */ f@0: left = coeff * (std::cos(theta) - std::sin(theta)); f@0: right = coeff * (std::cos(theta) + std::sin(theta)); f@0: f@0: } f@0: f@0: } panning; f@0: f@0: /* resets all the ugens. When srate is less than 0, type and ugen freq are f@0: not affected by resetas well as sample rate. f@0: */ f@0: void reset(double srate = -1.0); f@0: f@0: f@0: } mSonification; f@0: f@0: }; f@0: f@0: #endif