From c736f623b5d4e1628d307ef29edfe0d443726f9f Mon Sep 17 00:00:00 2001 From: mick grierson Date: Tue, 20 Oct 2015 16:37:02 +0100 Subject: adding biquad example from Rebecca --- maximilian_examples/13.Advanced-Filters.cpp | 50 ++++++++++++++++++++++ maximilian_examples/13.Sequencing.cpp | 66 ----------------------------- 2 files changed, 50 insertions(+), 66 deletions(-) create mode 100644 maximilian_examples/13.Advanced-Filters.cpp delete mode 100644 maximilian_examples/13.Sequencing.cpp diff --git a/maximilian_examples/13.Advanced-Filters.cpp b/maximilian_examples/13.Advanced-Filters.cpp new file mode 100644 index 0000000..b04d3d8 --- /dev/null +++ b/maximilian_examples/13.Advanced-Filters.cpp @@ -0,0 +1,50 @@ +//Using BPF equation from http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt +//Example contributed by Rebecca Fiebrink + +#include "maximilian.h" + +float xs[3], ys[3]; +float a0, a1, a2, b0, b1, b2; +float f0 = 400; //THE FREQUENCY +float Q = 1.0; + +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; + + //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]; + + *output = ys[0]; + + ys[2] = ys[1]; ys[1] = ys[0]; + xs[2] = xs[1]; xs[1] = xs[0]; +} diff --git a/maximilian_examples/13.Sequencing.cpp b/maximilian_examples/13.Sequencing.cpp deleted file mode 100644 index de7172b..0000000 --- a/maximilian_examples/13.Sequencing.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "maximilian.h" - -double outputs[2],moreoutputs[2]; //some track outputs -double filtered,patch1,patch2,tune,delayed, -mixed,ramp,filtered2,noise,pan,more;//a bunch of patch cables -int beat,lastbeat,morebeats,lastmorebeats;//some rhythmic elemts -double env[4]={200,0,0,50};//the kick drum pitch envelope data -double env2[6]={10000,0,9000,5,0,5};//the hi hat pitch envelope dat -double melody[14]={600,0,0,650,0,0,400,0,0,425,0,300,0,315};//the melody data -int rhythm1[16]={1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0};//another way of doing a rhythm -maxiOsc a,c,d,e,g,h,i,j,squarewave;//some oscillators -maxiEnvelope b,f;//two envelopers -maxiDelayline delay;//a delay line -maxiFilter myfilter,antia;// a FAT filter -maxiMix mymix,bobbins;//some panning busses -maxiSample beats; - -void setup() {//some inits - b.amplitude=env[0];//starting value for envelope b - f.amplitude=env2[0];//same for f - beats.load("/Users/chris/src/Maximilian/beat2.wav");//put a path to a soundfile here. Wav format only. - printf("Summary:\n%s", beats.getSummary());//get info on samples if you like - -} - -void play(double *output) {//this is where the magic happens. Very slow magic. - beat=((int) c.phasor(8));//this oscillator is now a counter - morebeats=((int) e.phasor(0.5,0,16));//so is this one - patch1=b.line(4,env);//here's envelope b - patch2=f.line(6,env2);//here's envelop f - tune=g.saw(melody[morebeats]*0.25);//here's the melody, which occurs at certain times - - if (lastbeat!=beat) {//this is a nice sample and hold routine for the kick drum - f.trigger(0, env2[0]);//it runs off the hi hat. - - - if (rhythm1[morebeats]==1) { - b.trigger(0, env[0]);//and gets played when it's time. - } - } - lastbeat=beat;//let's start again. It's a loop - ramp=i.phasor(0.5,1,2048);//create a basic ramp - pan=j.phasor(0.25);//some panning from a phasor (object is equal power) - delayed=delay.dl(tune, ramp, 0.9)*0.125;//the delay line - //then it all gets mixed. - mixed=((a.sinewave(patch1)*0.5)+((d.saw(patch2))*0.125)+(delayed*0.3)*0.5); - //add some noise - noise=i.noise()*0.25; - filtered2=beats.play(1*(1./16.),0,beats.length); - // filtered2=beats.play(-1); - - more=squarewave.pulse(melody[morebeats],pan)*0.05; - //filter the noise! this lores takes values between 1 and 100 for res, and freq for cutoff. - filtered=myfilter.lores(filtered2, 1+(pan*10000), 10)*0.4; - - //now we send the sounds to some stereo busses. - mymix.stereo(more+mixed+delayed, outputs, 1-pan); - bobbins.stereo(filtered, moreoutputs, pan);//invert the pan - - //mixing - - output[0]=outputs[0]+moreoutputs[0];//stick it in the out!! - output[1]=outputs[1]+moreoutputs[1]; - -} - -- cgit v1.3