diff options
| author | mick grierson <mickgrierson@gmail.com> | 2015-10-20 15:38:43 +0100 |
|---|---|---|
| committer | mick grierson <mickgrierson@gmail.com> | 2015-10-20 15:38:43 +0100 |
| commit | 566a7be10156a028aa045cfa64d9fa33ceb0b760 (patch) | |
| tree | 32aa568c2a0e2e303cfe164e22c5a7d77aeb2529 /main.cpp | |
| parent | 5390b6d45411f99e9343dd6301346747972feecd (diff) | |
biquad
Diffstat (limited to 'main.cpp')
| -rwxr-xr-x | main.cpp | 60 |
1 files changed, 38 insertions, 22 deletions
@@ -1,33 +1,49 @@ +//Using BPF equation from http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt #include "maximilian.h" -maxiOsc mySine; // This is the oscillator we will use to generate the test tone -maxiClock myClock; // This will allow us to generate a clock signal and do things at specific times -double freq; // This is a variable that we will use to hold and set the current frequency of the oscillator +float xs[3], ys[3]; +float a0, a1, a2, b0, b1, b2; +float f0 = 400; //THE FREQUENCY +float Q = 1.0; -void setup() { +maxiOsc mySwitchableOsc; + +void setup() {//some inits + double w0 = 2*PI*f0/44100; + double alpha = sin(w0)/(2*Q); + //Band-pass reson: +// b0 = alpha; +// b1 = 0; +// b2 = -1 * alpha; +// a0 = 1 + alpha; +// a1 = -2*cos(w0); +// a2 = 1 - alpha; + + //Notch: + b0 = 1; + b1 = -2*cos(w0); + b2 = 1; + a0 = 1 + alpha; + a1 = -2*cos(w0); + a2 = 1 - alpha; - myClock.setTicksPerBeat(1);//This sets the number of ticks per beat - myClock.setTempo(120);// This sets the tempo in Beats Per Minute - freq=20; // Here we initialise the variable + //LPF: +// b0 = (1 - cos(w0))/2; +// b1 = 1 - cos(w0); +// b2 = (1 - cos(w0))/2; +// a0 = 1 + alpha; +// a1 = -2*cos(w0); +// a2 = 1 - alpha; } void play(double *output) { + xs[0] = mySwitchableOsc.sawn(400); + ys[0] = (b0/a0)*xs[0] + (b1/a0)*xs[1] + (b2/a0)*xs[2] + - (a1/a0)*ys[1] - (a2/a0)*ys[2]; - myClock.ticker(); // This makes the clock object count at the current samplerate - - //This is a 'conditional'. It does a test and then does something if the test is true - - if (myClock.tick) { // If there is an actual tick at this time, this will be true. - - freq+=100; // DO SOMETHING - - } // The curly braces close the conditional - - //output[0] is the left output. output[1] is the right output - - output[0]=mySine.sinewave(freq);//simple as that! - output[1]=output[0]; + *output = ys[0]; + ys[2] = ys[1]; ys[1] = ys[0]; + xs[2] = xs[1]; xs[1] = xs[0]; } - |
