aboutsummaryrefslogtreecommitdiffstats
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rwxr-xr-xmain.cpp60
1 files changed, 38 insertions, 22 deletions
diff --git a/main.cpp b/main.cpp
index 88447ec..dbce5bf 100755
--- a/main.cpp
+++ b/main.cpp
@@ -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];
}
-