Mercurial > hg > asa
view AccessibleSpectrumAnalyser.h @ 1:2ca5d7440b5c tip
added README
author | Fiore Martin <f.martin@qmul.ac.uk> |
---|---|
date | Fri, 26 Feb 2016 16:11:20 +0000 |
parents | 3004dd663202 |
children |
line wrap: on
line source
#ifndef __ACCESSIBLESPECTRUMANALYSER__ #define __ACCESSIBLESPECTRUMANALYSER__ #include "IPlug_include_in_plug_hdr.h" #include <cmath> #include "fft.h" #include "FreqView.h" #include "stk/include/SineWave.h" #include "stk/include/Envelope.h" #include "stk/include/ADSR.h" class AccessibleSpectrumAnalyser : public IPlug { public: AccessibleSpectrumAnalyser(IPlugInstanceInfo instanceInfo); ~AccessibleSpectrumAnalyser(); void Reset(); void OnParamChange(int paramIdx); void ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames); inline WDL_FFT_REAL magnitude(const WDL_FFT_COMPLEX & c) const { return 2 * sqrt(WDL_FFT_REAL(c.re * c.re + c.im * c.im)) / mNormFactor;// kFFTbufSize if rect window ; //return 2 * sqrt(WDL_FFT_REAL(c.re * c.re + c.im * c.im)) / kFFTbufSize ; //if rect window ; } /* for dry/wet mix */ inline double mix(double dry, double wet) const { return dry * mDry + wet * mWet; } inline static double midi2Freq(int note) { return 440. * pow(2., (note - 69.) / 12.); } inline double calculateSelectionEndFromView() { return BOUNDED(mFreqView->getSelectionStart() + mFreqView->getSelectionSize(), mFreqView->getSelectionStart()+kMinSelectionSize, GetSampleRate()/2); } inline bool binWithinSelection(int i) const { double binHz = i * mBinSizeHz; return ( binHz > mFreqView->getSelectionStart() && binHz <mSelectionEnd); } void addClippingSonification(double** inputs, double** outputs, int nFrames); private: static const int kFFTbufSize = 2048; static const double k2pi; static const IColor kBgColor; static const double kClippingCeilingSnap; static const double kMinSelectionSize; WDL_FFT_COMPLEX mFFTbuffer[kFFTbufSize]; WDL_FFT_COMPLEX sortedbuffer[kFFTbufSize]; WDL_FFT_COMPLEX unsortedbuffer[kFFTbufSize]; int mFFTBufferIndx; FreqView* mFreqView; std::vector<float> mHannTable; double mNormFactor; double mBinSizeHz; double mDry; double mWet; double mSelectionEnd; double mThreshold; struct Sonification { /* the sine wave that is played */ stk::SineWave ugen; /* envelope of the sine wave */ stk::ADSR envelope; struct Panning { double left; double right; const double coeff; Panning(): coeff(std::sqrt(2)/2) {} /* position ranges from 0 to 1 */ void calculatePanningCoeff(double position) { /* map [0,1] to [-pi/4, pi/4] radians */ double theta = ((position*2)-1) * (PI/4); /* calculate left and right amplitudes */ left = coeff * (std::cos(theta) - std::sin(theta)); right = coeff * (std::cos(theta) + std::sin(theta)); } } panning; /* resets all the ugens. When srate is less than 0, type and ugen freq are not affected by resetas well as sample rate. */ void reset(double srate = -1.0); } mSonification; }; #endif