annotate 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
rev   line source
f@0 1 #ifndef __ACCESSIBLESPECTRUMANALYSER__
f@0 2 #define __ACCESSIBLESPECTRUMANALYSER__
f@0 3
f@0 4 #include "IPlug_include_in_plug_hdr.h"
f@0 5
f@0 6 #include <cmath>
f@0 7
f@0 8 #include "fft.h"
f@0 9 #include "FreqView.h"
f@0 10
f@0 11 #include "stk/include/SineWave.h"
f@0 12 #include "stk/include/Envelope.h"
f@0 13 #include "stk/include/ADSR.h"
f@0 14
f@0 15
f@0 16
f@0 17 class AccessibleSpectrumAnalyser : public IPlug
f@0 18 {
f@0 19 public:
f@0 20
f@0 21 AccessibleSpectrumAnalyser(IPlugInstanceInfo instanceInfo);
f@0 22 ~AccessibleSpectrumAnalyser();
f@0 23
f@0 24 void Reset();
f@0 25 void OnParamChange(int paramIdx);
f@0 26
f@0 27 void ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames);
f@0 28
f@0 29 inline WDL_FFT_REAL magnitude(const WDL_FFT_COMPLEX & c) const
f@0 30 {
f@0 31 return 2 * sqrt(WDL_FFT_REAL(c.re * c.re + c.im * c.im)) / mNormFactor;// kFFTbufSize if rect window ;
f@0 32 //return 2 * sqrt(WDL_FFT_REAL(c.re * c.re + c.im * c.im)) / kFFTbufSize ; //if rect window ;
f@0 33 }
f@0 34
f@0 35 /* for dry/wet mix */
f@0 36 inline double mix(double dry, double wet) const
f@0 37 {
f@0 38 return dry * mDry + wet * mWet;
f@0 39 }
f@0 40
f@0 41 inline static double midi2Freq(int note)
f@0 42 {
f@0 43 return 440. * pow(2., (note - 69.) / 12.);
f@0 44 }
f@0 45
f@0 46 inline double calculateSelectionEndFromView()
f@0 47 {
f@0 48 return BOUNDED(mFreqView->getSelectionStart() + mFreqView->getSelectionSize(),
f@0 49 mFreqView->getSelectionStart()+kMinSelectionSize,
f@0 50 GetSampleRate()/2);
f@0 51 }
f@0 52
f@0 53 inline bool binWithinSelection(int i) const
f@0 54 {
f@0 55 double binHz = i * mBinSizeHz;
f@0 56
f@0 57 return ( binHz > mFreqView->getSelectionStart() && binHz <mSelectionEnd);
f@0 58 }
f@0 59
f@0 60 void addClippingSonification(double** inputs, double** outputs, int nFrames);
f@0 61
f@0 62 private:
f@0 63
f@0 64 static const int kFFTbufSize = 2048;
f@0 65 static const double k2pi;
f@0 66 static const IColor kBgColor;
f@0 67 static const double kClippingCeilingSnap;
f@0 68 static const double kMinSelectionSize;
f@0 69
f@0 70
f@0 71 WDL_FFT_COMPLEX mFFTbuffer[kFFTbufSize];
f@0 72 WDL_FFT_COMPLEX sortedbuffer[kFFTbufSize];
f@0 73 WDL_FFT_COMPLEX unsortedbuffer[kFFTbufSize];
f@0 74 int mFFTBufferIndx;
f@0 75
f@0 76 FreqView* mFreqView;
f@0 77
f@0 78 std::vector<float> mHannTable;
f@0 79 double mNormFactor;
f@0 80
f@0 81 double mBinSizeHz;
f@0 82
f@0 83 double mDry;
f@0 84 double mWet;
f@0 85 double mSelectionEnd;
f@0 86 double mThreshold;
f@0 87
f@0 88
f@0 89 struct Sonification
f@0 90 {
f@0 91 /* the sine wave that is played */
f@0 92 stk::SineWave ugen;
f@0 93
f@0 94 /* envelope of the sine wave */
f@0 95 stk::ADSR envelope;
f@0 96
f@0 97 struct Panning
f@0 98 {
f@0 99 double left;
f@0 100 double right;
f@0 101
f@0 102 const double coeff;
f@0 103
f@0 104 Panning(): coeff(std::sqrt(2)/2) {}
f@0 105
f@0 106 /* position ranges from 0 to 1 */
f@0 107 void calculatePanningCoeff(double position)
f@0 108 {
f@0 109 /* map [0,1] to [-pi/4, pi/4] radians */
f@0 110 double theta = ((position*2)-1) * (PI/4);
f@0 111
f@0 112 /* calculate left and right amplitudes */
f@0 113 left = coeff * (std::cos(theta) - std::sin(theta));
f@0 114 right = coeff * (std::cos(theta) + std::sin(theta));
f@0 115
f@0 116 }
f@0 117
f@0 118 } panning;
f@0 119
f@0 120 /* resets all the ugens. When srate is less than 0, type and ugen freq are
f@0 121 not affected by resetas well as sample rate.
f@0 122 */
f@0 123 void reset(double srate = -1.0);
f@0 124
f@0 125
f@0 126 } mSonification;
f@0 127
f@0 128 };
f@0 129
f@0 130 #endif