aboutsummaryrefslogtreecommitdiffstats
path: root/maximilian_examples/8.Counting2.cpp
diff options
context:
space:
mode:
authormick grierson <mickgrierson@gmail.com>2015-09-22 09:21:43 +0100
committermick grierson <mickgrierson@gmail.com>2015-09-22 09:21:43 +0100
commit5be3472f0f61d2e479f42759fed6fafd2a0e739a (patch)
tree49f128d4b56d43b3499ffd824b57b7f8b8d8345a /maximilian_examples/8.Counting2.cpp
parentc814dd99dc3c347914c2057b77d1390ba41cfae5 (diff)
more work for kadenze mooc
Diffstat (limited to 'maximilian_examples/8.Counting2.cpp')
-rwxr-xr-xmaximilian_examples/8.Counting2.cpp41
1 files changed, 26 insertions, 15 deletions
diff --git a/maximilian_examples/8.Counting2.cpp b/maximilian_examples/8.Counting2.cpp
index ce016d0..05984c5 100755
--- a/maximilian_examples/8.Counting2.cpp
+++ b/maximilian_examples/8.Counting2.cpp
@@ -1,24 +1,35 @@
+// This example shows how you can create a basic counter with a phasor.
+// A phasor oscillator can create a ramp between any two values.
+// It takes three inputs - frequency, start value and stop value.
+// These are all double precision floats, so it's a continuous slide.
+// If you write it into an integer, it will round it off for you.
+// This creates a bunch of steps.
+
#include "maximilian.h"
-maxiOsc myCounter,mySwitchableOsc;//these oscillators will help us count and make sound.
+maxiOsc myCounter,mySquare;//these oscillators will help us count and play sound
int CurrentCount;//we're going to put the current count in this variable so that we can use it more easily.
-double myOscOutput;//we're going to stick the output here to make it easier to mess with stuff.
+
void setup() {//some inits
- //nothing to go here this time
+ //nothing to go here this time
}
void play(double *output) {
-
- CurrentCount=myCounter.phasor(1, 1, 9);//phasor can take three arguments; frequency, start value and end value.
-
- if (CurrentCount<5)//simple if statement
-
- myOscOutput=mySwitchableOsc.square(CurrentCount*100);
-
- else if (CurrentCount>=5)//and the 'else' bit.
-
- myOscOutput=mySwitchableOsc.sinewave(CurrentCount*50);//one osc object can produce whichever waveform you want.
-
- *output=myOscOutput;//point me at your speakers and fire.
+
+ // Here you can see that CurrentCount is an int. It's taking the continuous output of the phasor and convering it.
+ // You don't need to explicityly 'cast' (i.e. change) the value from a float to an int.
+ // It happens automagically in these cases.
+
+ // Once every second, CurrentCount counts from 1 until it gets to 9, then resets itself.
+ // When it reaches 9 it resets, so the values you get are 1-8.
+
+ CurrentCount=myCounter.phasor(1, 1, 9);//phasor can take three arguments; frequency, start value and end value.
+
+ // If we multiply the output of CurrentCount by 100, we get 100,200,300,400,500,600,700,800 in that order.
+ // These become the frequency of the oscillator.
+ // In this case, the oscillator is an antialiased sawtooth wave. Yum.
+ output[0]=mySquare.sawn(CurrentCount*100);
+ output[1]=output[0];
+
}