diff options
| author | Mick Grierson <mickgrierson@strangebook.local> | 2011-10-21 16:58:50 +0100 |
|---|---|---|
| committer | Mick Grierson <mickgrierson@strangebook.local> | 2011-10-21 16:58:50 +0100 |
| commit | 6dcd4a08f246122ea71f5813eec16ddb30c5d80f (patch) | |
| tree | a4d596f759972efcda71b96d8ea14bfab94ccdd1 | |
| parent | 2b01058183bdbab5ddf50905d34db2138946e276 (diff) | |
basic drum machine example
| -rwxr-xr-x | main.cpp | 55 | ||||
| -rw-r--r-- | maximilian.cpp | 8 | ||||
| -rwxr-xr-x | maximilian.h | 1 | ||||
| -rw-r--r-- | maximilian_examples/18.DrumMachine.cpp | 53 |
4 files changed, 97 insertions, 20 deletions
@@ -1,30 +1,53 @@ #include "maximilian.h" -maxiSample beats; //We give our sample a name. It's called beats this time. We could have loads of them, but they have to have different names. -maxiDyn compressor; //this is a compressor -double out; +maxiSample kick,snare; //We give our sample a name. It's called beats this time. We could have loads of them, but they have to have different names. + +maxiOsc timer; + +int currentCount,lastCount,playHead,hit[16]={1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0}; +int snarehit[16]={0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0}; + +int kicktrigger,snaretrigger; + +double sampleOut; void setup() {//some inits - beats.load("/Users/mickgrierson/Documents/audio/audio2/orbital1.wav");//load in your samples. Provide the full path to a wav file. - printf("Summary:\n%s", beats.getSummary());//get info on samples if you like. + kick.load("/Users/mickgrierson/Documents/audio/blip.wav");//load in your samples. Provide the full path to a wav file. + snare.load("/Users/mickgrierson/Documents/audio/snare.wav");//load in your samples. Provide the full path to a wav file. + + printf("Summary:\n%s", kick.getSummary());//get info on samples if you like. + //beats.getLength(); } void play(double *output) {//this is where the magic happens. Very slow magic. + currentCount=(int)timer.phasor(4);//this sets up a metronome that ticks 8 times a second - //here, we're just compressing the file in real-time - //arguments are input,ratio,threshold,attack,release. a long attack is something like 0.0001 and a long release is like 0.9999. - out=compressor.compressor(beats.play(),10,0.1,0.2,0.9995); - - output[0]=out; - output[1]=out; + if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound + + kicktrigger=hit[playHead%16]; + snaretrigger=snarehit[playHead%16]; + playHead++; + lastCount=0; + } - // *output=beats.play(0.69);//play the file with a speed setting. 1. is normal speed. - // *output=beats.play(0.5,0,44100);//linear interpolationplay with a frequency input, start point and end point. Useful for syncing. - // *output=beats.play4(0.5,0,44100);//cubic interpolation play with a frequency input, start point and end point. Useful for syncing. - -} + if (kicktrigger==1) { + + kick.trigger(); + + } + + if (snaretrigger==1) { + + snare.trigger(); + + } + + sampleOut=kick.playOnce()+snare.playOnce();//just play the file. Looping is default for all play functions. + *output=sampleOut; + +}
\ No newline at end of file diff --git a/maximilian.cpp b/maximilian.cpp index c7396e1..d55793d 100644 --- a/maximilian.cpp +++ b/maximilian.cpp @@ -257,7 +257,7 @@ double maxiFilter::hipass(double input, double cutoff) { double maxiFilter::lores(double input,double cutoff1, double resonance) { cutoff=cutoff1*0.5; if (cutoff<10) cutoff=10; - if (cutoff>(maxiSettings::sampleRate*0.25)) cutoff=(maxiSettings::sampleRate*0.25); + if (cutoff>(maxiSettings::sampleRate*0.5)) cutoff=(maxiSettings::sampleRate*0.5); if (resonance<1.) resonance = 1.; z=cos(TWOPI*cutoff/maxiSettings::sampleRate); c=2-2*z; @@ -273,7 +273,7 @@ double maxiFilter::lores(double input,double cutoff1, double resonance) { double maxiFilter::hires(double input,double cutoff1, double resonance) { cutoff=cutoff1*0.5; if (cutoff<10) cutoff=10; - if (cutoff>(maxiSettings::sampleRate*0.25)) cutoff=(maxiSettings::sampleRate*0.25); + if (cutoff>(maxiSettings::sampleRate*0.5)) cutoff=(maxiSettings::sampleRate*0.5); if (resonance<1.) resonance = 1.; z=cos(TWOPI*cutoff/maxiSettings::sampleRate); c=2-2*z; @@ -434,7 +434,8 @@ double maxiSample::play() { position=(position+1); remainder = position - (long) position; if ((long) position>length) position=0; - output = (double) ((1-remainder) * buffer[1+ (long) position] + remainder * buffer[2+(long) position])/32767;//linear interpolation + output = + (double) ((1-remainder) * buffer[1+ (long) position] + remainder * buffer[2+(long) position])/32767;//linear interpolation return(output); } @@ -832,7 +833,6 @@ void maxiSample::getLength() { } - /* OK this compressor and gate are now ready to use. The envelopes, like all the envelopes in this recent update, use stupid algorithms for incrementing - consequently a long attack is something like 0.0001 and a long release is like 0.9999. Annoyingly, a short attack is 0.1, and a short release is 0.99. I'll sort this out laters */ diff --git a/maximilian.h b/maximilian.h index 88b4843..2170782 100755 --- a/maximilian.h +++ b/maximilian.h @@ -183,6 +183,7 @@ public: long length; void getLength(); + char* myData; // get/set for the Path property diff --git a/maximilian_examples/18.DrumMachine.cpp b/maximilian_examples/18.DrumMachine.cpp new file mode 100644 index 0000000..a655ffb --- /dev/null +++ b/maximilian_examples/18.DrumMachine.cpp @@ -0,0 +1,53 @@ +#include "maximilian.h" + +maxiSample kick,snare; //We give our sample a name. It's called beats this time. We could have loads of them, but they have to have different names. + +maxiOsc timer; + +int currentCount,lastCount,playHead,hit[16]={1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0}; +int snarehit[16]={0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0}; + +int kicktrigger,snaretrigger; + +double sampleOut; + +void setup() {//some inits + + kick.load("/Users/mickgrierson/Documents/audio/blip.wav");//load in your samples. Provide the full path to a wav file. + snare.load("/Users/mickgrierson/Documents/audio/snare.wav");//load in your samples. Provide the full path to a wav file. + + + printf("Summary:\n%s", kick.getSummary());//get info on samples if you like. + //beats.getLength(); +} + +void play(double *output) {//this is where the magic happens. Very slow magic. + + currentCount=(int)timer.phasor(4);//this sets up a metronome that ticks 8 times a second + + + if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound + + kicktrigger=hit[playHead%16]; + snaretrigger=snarehit[playHead%16]; + playHead++; + lastCount=0; + } + + if (kicktrigger==1) { + + kick.trigger(); + + } + + if (snaretrigger==1) { + + snare.trigger(); + + } + + sampleOut=kick.playOnce()+snare.playOnce();//just play the file. Looping is default for all play functions. + + *output=sampleOut; + +}
\ No newline at end of file |
