diff options
| author | Mick Grierson <mickgrierson@strangebook.local> | 2011-10-28 15:13:23 +0100 |
|---|---|---|
| committer | Mick Grierson <mickgrierson@strangebook.local> | 2011-10-28 15:13:23 +0100 |
| commit | 46ee21d048ec62e9532fb009a3ffa99ced28b149 (patch) | |
| tree | 3d07d70d57391b8c692aef209620dc7dbf5eb6be /maximilian_examples/19.Enveloping2.cpp | |
| parent | 139ef699ec4eb864e3c240832a05026b85a042e1 (diff) | |
added new enveloping example
Diffstat (limited to 'maximilian_examples/19.Enveloping2.cpp')
| -rw-r--r-- | maximilian_examples/19.Enveloping2.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/maximilian_examples/19.Enveloping2.cpp b/maximilian_examples/19.Enveloping2.cpp new file mode 100644 index 0000000..112c5e8 --- /dev/null +++ b/maximilian_examples/19.Enveloping2.cpp @@ -0,0 +1,55 @@ +#include "maximilian.h" + +//this tutorial explains how to use the maxiEnv + +maxiSample sound1; + +maxiOsc timer,snarePhase; //and a timer + +maxiEnv envelope;//this is going to be an envelope + +int currentCount,lastCount,playHead, + +sequence[16]={1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0}; //This is the sequence for the kick + +int sampleTrigger; + +double sampleOut; + +void setup() {//some inits + + //YOU HAVE TO PROVIDE THE SAMPLES.... + + sound1.load("/Users/mickgrierson/Documents/audio/68373__juskiddink__Cello_open_string_bowed.wav");//load in your samples. Provide the full path to a wav file. + + + printf("Summary:\n%s", sound1.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(8);//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 + + sampleTrigger=sequence[playHead%16]; + playHead++;//iterate the playhead + lastCount=0;//reset the metrotest + + } + + //the envelope we're using here is an AR envelope. + //It has an input (which in this case is a sound) + //It has an attack coefficient, a hold val (in samples) + //and a release coefficient. Finally, it has a trigger input. + //If you stick a 1 in the trigger input, it retriggers the envelope + sampleOut=envelope.ar(sound1.play(1.), 0.1, 0.9999, 1, sampleTrigger); // + + output[0]=sampleOut;//left channel + output[1]=sampleOut;//right channel + + sampleTrigger = 0;//set trigger to 0 at the end of each sample to guarantee retriggering. + +}
\ No newline at end of file |
