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 /main.cpp | |
| parent | 2b01058183bdbab5ddf50905d34db2138946e276 (diff) | |
basic drum machine example
Diffstat (limited to 'main.cpp')
| -rwxr-xr-x | main.cpp | 55 |
1 files changed, 39 insertions, 16 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 |
