aboutsummaryrefslogtreecommitdiffstats
path: root/maximilian_examples
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
parentc814dd99dc3c347914c2057b77d1390ba41cfae5 (diff)
more work for kadenze mooc
Diffstat (limited to 'maximilian_examples')
-rwxr-xr-xmaximilian_examples/1.TestTone.cpp18
-rwxr-xr-xmaximilian_examples/10.Filters.cpp1
-rw-r--r--maximilian_examples/16.Replicant.cpp70
-rwxr-xr-xmaximilian_examples/2.TwoTones.cpp3
-rwxr-xr-xmaximilian_examples/3.AM1.cpp3
-rwxr-xr-xmaximilian_examples/4.AM2.cpp1
-rwxr-xr-xmaximilian_examples/5.FM1.cpp3
-rwxr-xr-xmaximilian_examples/6.FM2.cpp3
-rwxr-xr-xmaximilian_examples/7.Counting.cpp33
-rwxr-xr-xmaximilian_examples/7.Counting1.cpp33
-rwxr-xr-xmaximilian_examples/8.Counting2.cpp41
-rwxr-xr-xmaximilian_examples/8.Counting3.cpp28
-rwxr-xr-xmaximilian_examples/8.Counting4.cpp28
-rwxr-xr-xmaximilian_examples/9.Envelopes.cpp1
-rw-r--r--maximilian_examples/arrays.cpp60
15 files changed, 228 insertions, 98 deletions
diff --git a/maximilian_examples/1.TestTone.cpp b/maximilian_examples/1.TestTone.cpp
index b8da07c..c27941c 100755
--- a/maximilian_examples/1.TestTone.cpp
+++ b/maximilian_examples/1.TestTone.cpp
@@ -1,19 +1,15 @@
-//This example shows how to create one of the most fundamental building blocks in computer audio. The sine wave.
-//The sine wave is an oscillator - it oscillates back and forth between two values in a particular shape.
-
-
#include "maximilian.h"
-maxiOsc mySine;//let's create an oscillator and give it a name.
-
+//This shows how the fundamental building block of digital audio - the sine wave.
+//
+maxiOsc mySine;//One oscillator - can be called anything. Can be any of the available waveforms.
void setup() {//some inits
//nothing to go here this time
}
-void play(double *output) {//this is where the magic happens. Very slow magic.
-
- //output[0] is the left output. output[1] is the right output
- output[0]=mySine.sinewave(440);//simple as that!
+void play(double *output) {
+
+ output[0]=mySine.sinewave(440);
+ output[1]=output[0];
}
-
diff --git a/maximilian_examples/10.Filters.cpp b/maximilian_examples/10.Filters.cpp
index 41e779a..2c1240c 100755
--- a/maximilian_examples/10.Filters.cpp
+++ b/maximilian_examples/10.Filters.cpp
@@ -44,5 +44,6 @@ void play(double *output) {
myFilteredOutput=myFilter.lores(myOscOutput,myCurrentVolume*1000,10);
output[0]=myFilteredOutput;//left speaker
+ output[1]=output[0];
}
diff --git a/maximilian_examples/16.Replicant.cpp b/maximilian_examples/16.Replicant.cpp
index ae166bd..7684902 100644
--- a/maximilian_examples/16.Replicant.cpp
+++ b/maximilian_examples/16.Replicant.cpp
@@ -1,6 +1,6 @@
#include "maximilian.h"
-//Bizarelly, this sounds a little bit like Kraftwerk's 'Metropolis', although it isn't. Funny that.
+//Bizarelly, this sounds a little bit like Kraftwerk's 'Metropolis', although it isn't. Funny that.
maxiOsc sound,bass,timer,mod,lead,lead2,leadmod;//here are the synth bits
maxiEnv envelope, leadenvelope;//some envelopes
@@ -21,41 +21,41 @@ int leadLinePitch[15]={69,67,65,64,67,66,64,62,65,64,62,57,55,60,57};
void setup() {//some inits
-
+
}
void play(double *output) {//this is where the magic happens. Very slow magic.
-
- currentCount=(int)timer.phasor(9);//this sets up a metronome that ticks every so often
-
- if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
- trigger=1;//play the arpeggiator line
- trigger2=leadLineTrigger[playHead%256];//play the lead line
- if (trigger2==1) {//if we are going to play a note
- leadPitch=mtof.mtof(leadLinePitch[newnote]);//get the next pitch val
- newnote++;//and iterate
- if (newnote>14) {
- newnote=0;//make sure we don't go over the edge of the array
- }
- }
- currentPitch=mtof.mtof(pitch[(playHead%4)]+chord[currentChord%8]);//write the frequency val into currentPitch
- playHead++;//iterate the playhead
- if (playHead%32==0) {//wrap every 4 bars
- currentChord++;//change the chord
- }
- //cout << "tick\n";//the clock ticks
- lastCount=0;//set lastCount to 0
- }
-
- bassout=filter2.lores(envelope.adsr(bass.saw(currentPitch*0.5)+sound.pulse(currentPitch*0.5,mod.phasor(1)),1,0.9995, 0.25, 0.9995, 1, trigger),9250,2);//new, simple ADSR.
- leadout=filter.lores(leadenvelope.ar(lead2.saw(leadPitch*4)+lead.pulse(leadPitch+(leadmod.sinebuf(1.9)*1.5), 0.6), 0.00005, 0.999975, 50000, trigger2),5900,10);//leadline
-
- delayout=(leadout+(delay.dl(leadout, 14000, 0.8)*0.5))/2;//add some delay
-
- if(trigger!=0)trigger=0;//set the trigger to off if you want it to trigger immediately next time.
-
-
- output[0]=(bassout+delayout)/2;//sum output
- output[1]=(bassout+delayout)/2;
-
+
+ currentCount=(int)timer.phasor(9);//this sets up a metronome that ticks every so often
+
+ if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
+ trigger=1;//play the arpeggiator line
+ trigger2=leadLineTrigger[playHead%256];//play the lead line
+ if (trigger2==1) {//if we are going to play a note
+ leadPitch=mtof.mtof(leadLinePitch[newnote]);//get the next pitch val
+ newnote++;//and iterate
+ if (newnote>14) {
+ newnote=0;//make sure we don't go over the edge of the array
+ }
+ }
+ currentPitch=mtof.mtof(pitch[(playHead%4)]+chord[currentChord%8]);//write the frequency val into currentPitch
+ playHead++;//iterate the playhead
+ if (playHead%32==0) {//wrap every 4 bars
+ currentChord++;//change the chord
+ }
+ //cout << "tick\n";//the clock ticks
+ lastCount=0;//set lastCount to 0
+ }
+
+ bassout=filter2.lores(envelope.adsr(bass.saw(currentPitch*0.5)+sound.pulse(currentPitch*0.5,mod.phasor(1)),1,0.9995, 0.25, 0.9995, 1, trigger),9250,2);//new, simple ADSR.
+ leadout=filter.lores(leadenvelope.ar(lead2.saw(leadPitch*4)+lead.pulse(leadPitch+(leadmod.sinebuf(1.9)*1.5), 0.6), 0.00005, 0.999975, 50000, trigger2),5900,10);//leadline
+
+ delayout=(leadout+(delay.dl(leadout, 14000, 0.8)*0.5))/2;//add some delay
+
+ if(trigger!=0)trigger=0;//set the trigger to off if you want it to trigger immediately next time.
+
+
+ output[0]=(bassout)/2;//sum output
+ output[1]=(bassout)/2;
+
} \ No newline at end of file
diff --git a/maximilian_examples/2.TwoTones.cpp b/maximilian_examples/2.TwoTones.cpp
index fb29288..2c94711 100755
--- a/maximilian_examples/2.TwoTones.cpp
+++ b/maximilian_examples/2.TwoTones.cpp
@@ -12,6 +12,7 @@ void play(double *output) {//this is where the magic happens. Very slow magic.
//output[0] is the left output. output[1] is the right output
output[0]=mySine.sinewave(440)+myOtherSine.sinewave(441);//these two sines will beat together. They're now a bit too loud though..
-
+ output[1]=output[0];
+
}
diff --git a/maximilian_examples/3.AM1.cpp b/maximilian_examples/3.AM1.cpp
index 384a7f5..5d75942 100755
--- a/maximilian_examples/3.AM1.cpp
+++ b/maximilian_examples/3.AM1.cpp
@@ -17,5 +17,6 @@ void play(double *output) {
// When you multiply something by -1, its phase is inverted but it retains its amplitude.
// So you hear 2 waves per second, not 1, even though the frequency is 1.
output[0]=mySine.sinewave(440)*myOtherSine.sinewave(1);
-
+ output[1]=output[0];
+
}
diff --git a/maximilian_examples/4.AM2.cpp b/maximilian_examples/4.AM2.cpp
index 7e80f38..2827a28 100755
--- a/maximilian_examples/4.AM2.cpp
+++ b/maximilian_examples/4.AM2.cpp
@@ -20,5 +20,6 @@ void play(double *output) {
//So you hear two new waves, one going up, one going down.
output[0]=mySine.sinewave(440)*myOtherSine.sinewave(myPhasor.phasor(0.01,0,440));
+ output[1]=output[0];
}
diff --git a/maximilian_examples/5.FM1.cpp b/maximilian_examples/5.FM1.cpp
index 14f6593..d0ce736 100755
--- a/maximilian_examples/5.FM1.cpp
+++ b/maximilian_examples/5.FM1.cpp
@@ -31,4 +31,5 @@ void play(double *output) {
}
// In complex FM systems you can have lots of modulators stacked together in interesting ways, and theoretically this can make any sound.
-// John Chowning is the guy you probably want to talk to about that. \ No newline at end of file
+// John Chowning is the guy you probably want to talk to about that.
+output[1]=output[0];
diff --git a/maximilian_examples/6.FM2.cpp b/maximilian_examples/6.FM2.cpp
index d9eddf5..4c6ec8a 100755
--- a/maximilian_examples/6.FM2.cpp
+++ b/maximilian_examples/6.FM2.cpp
@@ -12,5 +12,6 @@ void setup() {//some inits
void play(double *output) {
output[0]=mySine.sinewave(myOtherSine.sinewave(myLastSine.sinewave(0.1)*30)*440);//awesome bassline
-
+ output[1]=output[0];
+
}
diff --git a/maximilian_examples/7.Counting.cpp b/maximilian_examples/7.Counting.cpp
deleted file mode 100755
index e620b3a..0000000
--- a/maximilian_examples/7.Counting.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-// 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,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.
-
-
-void setup() {//some inits
- //nothing to go here this time
-}
-
-void play(double *output) {
-
- // 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);
-}
diff --git a/maximilian_examples/7.Counting1.cpp b/maximilian_examples/7.Counting1.cpp
new file mode 100755
index 0000000..6bdfd85
--- /dev/null
+++ b/maximilian_examples/7.Counting1.cpp
@@ -0,0 +1,33 @@
+
+#include "maximilian.h"
+
+maxiOsc mySine; // This is the oscillator we will use to generate the test tone
+maxiClock myClock; // This will allow us to generate a clock signal and do things at specific times
+double freq; // This is a variable that we will use to hold and set the current frequency of the oscillator
+
+void setup() {
+
+ myClock.setTicksPerBeat(1);//This sets the number of ticks per beat
+ myClock.setTempo(120);// This sets the tempo in Beats Per Minute
+ freq=20; // Here we initialise the variable
+}
+
+void play(double *output) {
+
+ myClock.ticker(); // This makes the clock object count at the current samplerate
+
+ //This is a 'conditional'. It does a test and then does something if the test is true
+
+ if (myClock.tick) { // If there is an actual tick at this time, this will be true.
+
+ freq+=100; // DO SOMETHING
+
+ } // The curly braces close the conditional
+
+ //output[0] is the left output. output[1] is the right output
+
+ output[0]=mySine.sinewave(freq);//simple as that!
+ output[1]=output[0];
+
+}
+
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];
+
}
diff --git a/maximilian_examples/8.Counting3.cpp b/maximilian_examples/8.Counting3.cpp
new file mode 100755
index 0000000..36adc01
--- /dev/null
+++ b/maximilian_examples/8.Counting3.cpp
@@ -0,0 +1,28 @@
+#include "maximilian.h"
+
+maxiOsc myCounter,mySwitchableOsc;//these oscillators will help us count and make 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
+}
+
+void play(double *output) {
+
+ CurrentCount=myCounter.phasor(1, 1, 9);//phasor can take three arguments; frequency, start value and end value.
+
+// here we use a conditional to make something happen at a specific time.
+
+ 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[0]=myOscOutput;
+ output[1]=output[0];
+
+}
diff --git a/maximilian_examples/8.Counting4.cpp b/maximilian_examples/8.Counting4.cpp
new file mode 100755
index 0000000..cecf548
--- /dev/null
+++ b/maximilian_examples/8.Counting4.cpp
@@ -0,0 +1,28 @@
+#include "maximilian.h"
+
+maxiOsc myCounter,mySwitchableOsc,another;//these oscillators will help us count and make 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.
+int myArray[10]={100,200,300,400,300,200,100,240,640,360};
+
+void setup() {//some inits
+ //nothing to go here this time
+}
+
+void play(double *output) {
+
+ CurrentCount=myCounter.phasor(1*((another.sawn(0.1)+1)/2), 1, 9);//phasor can take three arguments; frequency, start value and end value.
+
+ if (CurrentCount<5) {//simple if statement
+
+ myOscOutput=mySwitchableOsc.square(myArray[CurrentCount]);
+ }
+
+ else if (CurrentCount>=5) {//and the 'else' bit.
+
+ myOscOutput=mySwitchableOsc.sawn(myArray[CurrentCount]);//one osc object can produce whichever waveform you want.
+ }
+ output[0]=myOscOutput;//point me at your speakers and fire.
+ output[1]=output[0];
+
+}
diff --git a/maximilian_examples/9.Envelopes.cpp b/maximilian_examples/9.Envelopes.cpp
index 2cf74f6..138fb0d 100755
--- a/maximilian_examples/9.Envelopes.cpp
+++ b/maximilian_examples/9.Envelopes.cpp
@@ -47,5 +47,6 @@ void play(double *output) {
output[0]=myOscOutput*myCurrentVolume;//left speaker
+ output[1]=output[0];
}
diff --git a/maximilian_examples/arrays.cpp b/maximilian_examples/arrays.cpp
new file mode 100644
index 0000000..1badd9b
--- /dev/null
+++ b/maximilian_examples/arrays.cpp
@@ -0,0 +1,60 @@
+//
+// arrays.cpp
+//
+//
+// Created by Michael Grierson on 14/09/2015.
+//
+//
+
+#include "maximilian.h"
+
+currentChord=0;//some other control variables
+int pitch[8]={57,57,59,60};//the bassline for the arpeggio
+int chord[8]={0,0,7,2,5,5,0,0};//the root chords for the arpeggio
+float currentPitch,leadPitch;//the final pitch variables
+
+//here's the lead line trigger array, followed by the pitches
+int leadLineTrigger[256]={1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+int leadLinePitch[15]={69,67,65,64,67,66,64,62,65,64,62,57,55,60,57};
+
+
+
+void setup() {//some inits
+
+}
+
+void play(double *output) {//this is where the magic happens. Very slow magic.
+
+ currentCount=(int)timer.phasor(9);//this sets up a metronome that ticks every so often
+
+ if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
+ trigger=1;//play the arpeggiator line
+ trigger2=leadLineTrigger[playHead%256];//play the lead line
+ if (trigger2==1) {//if we are going to play a note
+ leadPitch=mtof.mtof(leadLinePitch[newnote]);//get the next pitch val
+ newnote++;//and iterate
+ if (newnote>14) {
+ newnote=0;//make sure we don't go over the edge of the array
+ }
+ }
+ currentPitch=mtof.mtof(pitch[(playHead%4)]+chord[currentChord%8]);//write the frequency val into currentPitch
+ playHead++;//iterate the playhead
+ if (playHead%32==0) {//wrap every 4 bars
+ currentChord++;//change the chord
+ }
+ //cout << "tick\n";//the clock ticks
+ lastCount=0;//set lastCount to 0
+ }
+
+ bassout=filter2.lores(envelope.adsr(bass.saw(currentPitch*0.5)+sound.pulse(currentPitch*0.5,mod.phasor(1)),1,0.9995, 0.25, 0.9995, 1, trigger),9250,2);//new, simple ADSR.
+ leadout=filter.lores(leadenvelope.ar(lead2.saw(leadPitch*4)+lead.pulse(leadPitch+(leadmod.sinebuf(1.9)*1.5), 0.6), 0.00005, 0.999975, 50000, trigger2),5900,10);//leadline
+
+ delayout=(leadout+(delay.dl(leadout, 14000, 0.8)*0.5))/2;//add some delay
+
+ if(trigger!=0)trigger=0;//set the trigger to off if you want it to trigger immediately next time.
+
+
+ output[0]=(bassout+delayout)/2;//sum output
+ output[1]=(bassout+delayout)/2;
+
+} \ No newline at end of file