aboutsummaryrefslogtreecommitdiffstats
path: root/maximilian_examples
diff options
context:
space:
mode:
authormick grierson <mickgrierson@gmail.com>2015-10-01 09:54:19 +0100
committermick grierson <mickgrierson@gmail.com>2015-10-01 09:54:19 +0100
commite4eb667af04304cbe9c0be5997ebea2049178590 (patch)
tree5630e70df8199c9f53170c9ef4da1e4dac59e69c /maximilian_examples
parent537a5a959f8ec9c4fcb5fd016f2a6be65ca99f3c (diff)
parentdfa3efd8495628d55f55ee8c8c8576095c2089e4 (diff)
resolving merge conflict
Diffstat (limited to 'maximilian_examples')
-rwxr-xr-xmaximilian_examples/1.TestTone.cpp17
-rwxr-xr-xmaximilian_examples/10.Filters.cpp60
-rwxr-xr-xmaximilian_examples/11.Mixing.cpp40
-rwxr-xr-xmaximilian_examples/14.monosynth.cpp72
-rw-r--r--maximilian_examples/15.polysynth.cpp109
-rw-r--r--maximilian_examples/16.Replicant.cpp70
-rw-r--r--maximilian_examples/17.Compressor.cpp37
-rwxr-xr-xmaximilian_examples/2.TwoTones.cpp12
-rw-r--r--maximilian_examples/20.additive.cpp26
-rwxr-xr-xmaximilian_examples/3.AM1.cpp17
-rwxr-xr-xmaximilian_examples/4.AM2.cpp19
-rwxr-xr-xmaximilian_examples/5.FM1.cpp29
-rwxr-xr-xmaximilian_examples/6.FM2.cpp11
-rwxr-xr-xmaximilian_examples/7.Counting.cpp15
-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.cpp61
-rw-r--r--maximilian_examples/arrays.cpp60
20 files changed, 486 insertions, 299 deletions
diff --git a/maximilian_examples/1.TestTone.cpp b/maximilian_examples/1.TestTone.cpp
index 77783b4..c27941c 100755
--- a/maximilian_examples/1.TestTone.cpp
+++ b/maximilian_examples/1.TestTone.cpp
@@ -1,14 +1,15 @@
#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
+ //nothing to go here this time
}
-void play(double *output) {//this is where the magic happens. Very slow magic.
-
- *output=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 b80b512..2c1240c 100755
--- a/maximilian_examples/10.Filters.cpp
+++ b/maximilian_examples/10.Filters.cpp
@@ -1,33 +1,49 @@
+// Here is an example of a Maximilian filter being used.
+// There are a number of filters in Maximilian, including low and high pass filters.
+// There are also resonant filters and a state variable filter.
+
+
#include "maximilian.h"
maxiOsc myCounter,mySwitchableOsc;//
int CurrentCount;//
-double myOscOutput,myFilteredOutput;//
-double myEnvelopeData[6] = {500,0,1000,500,0,500};//this data will be used to make an envelope. Value and time to value in ms.
-maxiEnvelope myEnvelope;
+double myOscOutput,myCurrentVolume, myFilteredOutput;//
+maxiEnv myEnvelope;
maxiFilter myFilter;
void setup() {//some inits
- myEnvelope.amplitude=myEnvelopeData[0]; //initialise the envelope
+
+ //Timing is in ms
+
+ myEnvelope.setAttack(0);
+ myEnvelope.setDecay(1); // Needs to be at least 1
+ myEnvelope.setSustain(1);
+ myEnvelope.setRelease(1000);
+
}
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.saw(CurrentCount*50);//one osc object can produce whichever waveform you want.
-
- if (CurrentCount==1)
-
- myEnvelope.trigger(0,myEnvelopeData[0]); //trigger the envelope
-
- myFilteredOutput=myFilter.lores(myOscOutput,(myEnvelope.line(6, myEnvelopeData)),10);//lores takes an audio input, a frequency and a resonance factor (1-100)
-
- *output=myFilteredOutput;//point me at your speakers and fire.
+
+ myCurrentVolume=myEnvelope.adsr(1.,myEnvelope.trigger);
+
+ CurrentCount=myCounter.phasor(1, 1, 9);//phasor can take three arguments; frequency, start value and end value.
+
+ // You'll notice that these 'if' statements don't require curly braces "{}".
+ // This is because there is only one outcome if the statement is true.
+
+ if (CurrentCount==1) myEnvelope.trigger=1; //trigger the envelope
+
+ else myEnvelope.trigger=0;//release the envelope to make it fade out only if it's been triggered
+
+ myOscOutput=mySwitchableOsc.sawn(100);
+
+ // Below, the oscilator signals are being passed through a low pass filter.
+ // The middle input is the filter cutoff. It is being controlled by the envelope.
+ // Notice that the envelope is being amplified so that it scales between 0 and 1000.
+ // The last input is the resonance.
+ myFilteredOutput=myFilter.lores(myOscOutput,myCurrentVolume*1000,10);
+
+ output[0]=myFilteredOutput;//left speaker
+ output[1]=output[0];
+
}
diff --git a/maximilian_examples/11.Mixing.cpp b/maximilian_examples/11.Mixing.cpp
index 6fd7a34..8f6e33c 100755
--- a/maximilian_examples/11.Mixing.cpp
+++ b/maximilian_examples/11.Mixing.cpp
@@ -1,40 +1,18 @@
#include "maximilian.h"
-maxiOsc myCounter,mySwitchableOsc,myAutoPanner;//
-int CurrentCount;//
-double myOscOutput,myFilteredOutput,myPanPosition;//
-double myStereoOutput[2];// we need an output for each channel.
-double myEnvelopeData[6] = {500,0,1000,500,0,500};//this data will be used to make an envelope. Value and time to value in ms.
-maxiEnvelope myEnvelope;
-maxiFilter myFilter;
+maxiOsc myOsc,myAutoPanner;//
+double myStereoOutput[2];
maxiMix myOutputs;//this is the stereo mixer channel.
void setup() {//some inits
- myEnvelope.amplitude=myEnvelopeData[0]; //initialise the envelope
+
}
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.saw(CurrentCount*50);//one osc object can produce whichever waveform you want.
-
- if (CurrentCount==1)
-
- myEnvelope.trigger(0,myEnvelopeData[0]); //trigger the envelope
-
- myFilteredOutput=myFilter.lores(myOscOutput,(myEnvelope.line(6, myEnvelopeData)),10);//lores takes an audio input, a frequency and a resonance factor (1-100)
-
- myPanPosition=myAutoPanner.sinewave(1);
-
- myOutputs.stereo(myFilteredOutput,myStereoOutput,myPanPosition);//Stereo, Quad or 8 Channel. Specify the input to be mixed, the output[numberofchannels], and the pan (0-1,equal power).
- output[0]=myStereoOutput[0];//When working with mixing, you need to specify the outputs explicityly
- output[1]=myStereoOutput[1];//
-
+
+
+ myOutputs.stereo(myOsc.noise(),myStereoOutput,(myAutoPanner.sinewave(1)+1)/2);//Stereo, Quad or 8 Channel. Specify the input to be mixed, the output[numberofchannels], and the pan (0-1,equal power).
+ output[0]=myStereoOutput[0];//When working with mixing, you need to specify the outputs explicitly
+ output[1]=myStereoOutput[1];//
+
}
diff --git a/maximilian_examples/14.monosynth.cpp b/maximilian_examples/14.monosynth.cpp
index 5dd4e7e..265e3e4 100755
--- a/maximilian_examples/14.monosynth.cpp
+++ b/maximilian_examples/14.monosynth.cpp
@@ -5,11 +5,7 @@
//These are the synthesiser bits
maxiOsc VCO1,VCO2,LFO1,LFO2;
maxiFilter VCF;
-maxiEnvelope ADSR;
-
-//These are the control values for the envelope
-
-double adsrEnv[8]={1,5,0.125,250,0.125,125,0,500};
+maxiEnv ADSR;
//This is a bunch of control signals so that we can hear something
@@ -22,38 +18,42 @@ double VCO1out,VCO2out,LFO1out,LFO2out,VCFout,ADSRout;
void setup() {//some inits
-
-
+
+ ADSR.setAttack(1000);
+ ADSR.setDecay(1);
+ ADSR.setSustain(1);
+ ADSR.setRelease(1000);
}
void play(double *output) {
-
- //so this first bit is just a basic metronome so we can hear what we're doing.
-
- currentCount=(int)timer.phasor(0.5);//this sets up a metronome that ticks every 2 seconds
-
- if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
-
- ADSR.trigger(0, adsrEnv[0]);//trigger the envelope from the start
-
- cout << "tick\n";//the clock ticks
-
- lastCount=0;//set lastCount to 0
- }
-
- //and this is where we build the synth
-
-
- ADSRout=ADSR.line(8,adsrEnv);//our ADSR env has 8 value/time pairs.
-
- LFO1out=LFO1.sinebuf(0.2);//this lfo is a sinewave at 0.2 hz
-
- VCO1out=VCO1.pulse(55,0.6);//here's VCO1. it's a pulse wave at 55 hz, with a pulse width of 0.6
- VCO2out=VCO2.pulse(110+LFO1out,0.2);//here's VCO2. it's a pulse wave at 110hz with LFO modulation on the frequency, and width of 0.2
-
-
- VCFout=VCF.lores((VCO1out+VCO2out)*0.5, 250+(ADSRout*15000), 10);//now we stick the VCO's into the VCF, using the ADSR as the filter cutoff
-
- *output=VCFout*ADSRout;//finally we add the ADSR as an amplitude modulator
-
+
+ //so this first bit is just a basic metronome so we can hear what we're doing.
+
+ currentCount=(int)timer.phasor(0.5);//this sets up a metronome that ticks every 2 seconds
+
+
+ if (lastCount!=currentCount) {//if we have a new timer int this sample, play the sound
+ ADSR.trigger=1;
+
+ cout << "tick\n";//the clock ticks
+
+ lastCount=0;//set lastCount to 0
+ }
+
+ //and this is where we build the synth
+
+ ADSRout=ADSR.adsr(1.0,ADSR.trigger);
+
+ LFO1out=LFO1.sinebuf(0.2);//this lfo is a sinewave at 0.2 hz
+
+ VCO1out=VCO1.pulse(55,0.6);//here's VCO1. it's a pulse wave at 55 hz, with a pulse width of 0.6
+ VCO2out=VCO2.pulse(110+LFO1out,0.2);//here's VCO2. it's a pulse wave at 110hz with LFO modulation on the frequency, and width of 0.2
+
+
+ VCFout=VCF.lores((VCO1out+VCO2out)*0.5, ADSRout*10000, 10);//now we stick the VCO's into the VCF, using the ADSR as the filter cutoff
+
+ double finalSound=VCFout*ADSRout;//finally we add the ADSR as an amplitude modulator
+ ADSR.trigger=0;
+ output[0]=finalSound;
+ output[1]=finalSound;
}
diff --git a/maximilian_examples/15.polysynth.cpp b/maximilian_examples/15.polysynth.cpp
index 6cb5c44..fefc261 100644
--- a/maximilian_examples/15.polysynth.cpp
+++ b/maximilian_examples/15.polysynth.cpp
@@ -5,11 +5,7 @@
//These are the synthesiser bits
maxiOsc VCO1[6],VCO2[6],LFO1[6],LFO2[6];
maxiFilter VCF[6];
-maxiEnvelope ADSR[6];
-
-//These are the control values for the envelope
-
-double adsrEnv[8]={1,5,0.125,100,0.125,200,0,1000};
+maxiEnv ADSR[6];
//This is a bunch of control signals so that we can hear something
@@ -22,53 +18,64 @@ double VCO1out[6],VCO2out[6],LFO1out[6],LFO2out[6],VCFout[6],ADSRout[6],mix,pitc
void setup() {//some inits
-
-
+
+ for (int i=0;i<6;i++) {
+
+ ADSR[i].setAttack(0);
+ ADSR[i].setDecay(200);
+ ADSR[i].setSustain(0.2);
+ ADSR[i].setRelease(2000);
+
+ }
}
void play(double *output) {
-
- mix=0;//we're adding up the samples each update and it makes sense to clear them each time first.
-
- //so this first bit is just a basic metronome so we can hear what we're doing.
-
- 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
-
- if (voice==6) {
- voice=0;
- }
-
- ADSR[voice].trigger(0, adsrEnv[0]);//trigger the envelope from the start
- pitch[voice]=voice+1;
- voice++;
-
- lastCount=0;
-
- }
-
- //and this is where we build the synth
-
- for (int i=0; i<6; i++) {
-
-
- ADSRout[i]=ADSR[i].line(8,adsrEnv);//our ADSR env has 8 value/time pairs.
-
- LFO1out[i]=LFO1[i].sinebuf(0.2);//this lfo is a sinewave at 0.2 hz
-
- VCO1out[i]=VCO1[i].pulse(55*pitch[i],0.6);//here's VCO1. it's a pulse wave at 55 hz, with a pulse width of 0.6
- VCO2out[i]=VCO2[i].pulse((110*pitch[i])+LFO1out[i],0.2);//here's VCO2. it's a pulse wave at 110hz with LFO modulation on the frequency, and width of 0.2
-
-
- VCFout[i]=VCF[i].lores((VCO1out[i]+VCO2out[i])*0.5, 250+((pitch[i]+LFO1out[i])*1000), 10);//now we stick the VCO's into the VCF, using the ADSR as the filter cutoff
-
- mix+=VCFout[i]*ADSRout[i]/6;//finally we add the ADSR as an amplitude modulator
-
-
- }
-
- output[0]=mix*0.5;//left channel
- output[1]=mix*0.5;//right channel
-
+
+ mix=0;//we're adding up the samples each update and it makes sense to clear them each time first.
+
+ //so this first bit is just a basic metronome so we can hear what we're doing.
+
+ 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
+
+ if (voice==6) {
+ voice=0;
+ }
+
+ ADSR[voice].trigger=1;//trigger the envelope from the start
+ pitch[voice]=voice+1;
+ voice++;
+
+ }
+
+ //and this is where we build the synth
+
+ for (int i=0; i<6; i++) {
+
+
+ ADSRout[i]=ADSR[i].adsr(1.,ADSR[i].trigger);//our ADSR env is passed a constant signal of 1 to generate the transient.
+
+ LFO1out[i]=LFO1[i].sinebuf(0.2);//this lfo is a sinewave at 0.2 hz
+
+ VCO1out[i]=VCO1[i].pulse(55*pitch[i],0.6);//here's VCO1. it's a pulse wave at 55 hz, with a pulse width of 0.6
+ VCO2out[i]=VCO2[i].pulse((110*pitch[i])+LFO1out[i],0.2);//here's VCO2. it's a pulse wave at 110hz with LFO modulation on the frequency, and width of 0.2
+
+
+ VCFout[i]=VCF[i].lores((VCO1out[i]+VCO2out[i])*0.5, 250+((pitch[i]+LFO1out[i])*1000), 10);//now we stick the VCO's into the VCF, using the ADSR as the filter cutoff
+
+ mix+=VCFout[i]*ADSRout[i]/6;//finally we add the ADSR as an amplitude modulator
+
+
+ }
+
+ output[0]=mix*0.5;//left channel
+ output[1]=mix*0.5;//right channel
+
+
+ // This just sends note-off messages.
+ for (int i=0; i<6; i++) {
+ ADSR[i].trigger=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/17.Compressor.cpp b/maximilian_examples/17.Compressor.cpp
index c6b7897..c9bf221 100644
--- a/maximilian_examples/17.Compressor.cpp
+++ b/maximilian_examples/17.Compressor.cpp
@@ -5,25 +5,28 @@ maxiDyn compressor; //this is a compressor
double out;
void setup() {//some inits
-
- beats.load("/Users/yourusername/somewhere/schub.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.
-
+
+ beats.load("/Users/michaelgrierson/Documents/workspace/Maximilian/ofxMaxim/examples/OSX/ofMaximExample007OSX_Granular/bin/data/beat2.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.
+
+ compressor.setAttack(100);
+ compressor.setRelease(300);
+ compressor.setThreshold(0.25);
+ compressor.setRatio(5);
+
+ //you can set these any time you like.
+
}
void play(double *output) {//this is where the magic happens. Very slow magic.
-
-
- //here, we're just compressing the file in real-time
- //arguments are input,ratio,threshold,attack,release
- out=compressor.compressor(beats.play(),5,0.25,0.0001,0.9999);
-
- output[0]=out;
- output[1]=out;
-
- // *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.
-
+
+
+ //here, we're just compressing the file in real-time
+ //arguments are input,ratio,threshold,attack,release
+ out=compressor.compress(beats.play());
+
+ output[0]=out;
+ output[1]=out;
+
}
diff --git a/maximilian_examples/2.TwoTones.cpp b/maximilian_examples/2.TwoTones.cpp
index 4e22994..2c94711 100755
--- a/maximilian_examples/2.TwoTones.cpp
+++ b/maximilian_examples/2.TwoTones.cpp
@@ -1,14 +1,18 @@
+//This examples shows another fundamental building block of digital audio - adding two sine waves together. When you add waves together they create a new wave whose amplitude at any time is computed by adding the current amplitudes of each wave together. So, if one wave has an amplitude of 1, and the other has an amplitude of 1, the new wave will be equal to 2 at that point in time. Whereas, later, if one wave has an amplitude of -1, and the other has an amplitude of 1, the new wave - the one you hear - will equal 0. This can create some interesting effects, including 'beating', when the waves interact to create a single wave that fades up and down based on the frequencies of the two interacting waves. The frequency of the 'beating' i.e. the fading in and out, is equal to the difference in frequency between the two waves.
+
#include "maximilian.h"
maxiOsc mySine,myOtherSine;//Two oscillators with names.
void setup() {//some inits
- //nothing to go here this time
+ //nothing to go here this time
}
void play(double *output) {//this is where the magic happens. Very slow magic.
-
- *output=mySine.sinewave(440)+myOtherSine.sinewave(441);//these two sines will beat together. They're now a bit too loud though..
-
+
+ //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/20.additive.cpp b/maximilian_examples/20.additive.cpp
deleted file mode 100644
index 753434d..0000000
--- a/maximilian_examples/20.additive.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "maximilian.h"
-
-maxiOsc sineBank[10];//let's create an oscillator and give it a name.
-
-void setup() {//some inits
- //nothing to go here this time
-}
-
-
-
-void play(double *output) {//this is where the magic happens. Very slow magic.
-
- double wave=0;
- double f0 = 100;
- for(int i=0; i < 10; i++) {
- double thisSine = wave + sineBank[i].sinewave(f0 + (i * f0));
- double multiplier = 1.0 / (i+1.0);
- thisSine = thisSine * multiplier;
- wave = wave + thisSine;
- }
- wave *= 0.1;
- *output = wave;//simple as that!
-
-
-}
-
diff --git a/maximilian_examples/3.AM1.cpp b/maximilian_examples/3.AM1.cpp
index ec96c7f..5d75942 100755
--- a/maximilian_examples/3.AM1.cpp
+++ b/maximilian_examples/3.AM1.cpp
@@ -1,15 +1,22 @@
#include "maximilian.h"
-//This shows how to use maximilian to do basic amplitude modulation
+//This shows how to use maximilian to do basic amplitude modulation. Amplitude modulation is when you multiply waves together. In maximilian you just use the * inbetween the two waveforms.
maxiOsc mySine,myOtherSine;//Two oscillators. They can be called anything. They can be any of the available waveforms. These ones will be sinewaves
void setup() {//some inits
- //nothing to go here this time
+ //nothing to go here this time
}
void play(double *output) {
-
- *output=mySine.sinewave(440)*myOtherSine.sinewave(10);
-
+
+ // This form of amplitude modulation is straightforward multiplication of two waveforms.
+ // Notice that the maths is different to when you add waves.
+ // The waves aren't 'beating'. Instead, the amplitude of one is modulating the amplitude of the other
+ // Remember that the sine wave has positive and negative sections as it oscillates.
+ // 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 4e783d3..2827a28 100755
--- a/maximilian_examples/4.AM2.cpp
+++ b/maximilian_examples/4.AM2.cpp
@@ -1,16 +1,25 @@
#include "maximilian.h"
-//This shows how to use maximilian to do basic amplitude modulation
+//This shows how to use maximilian to do basic amplitude modulation.
+//It also shows what happens when you modulate waves with waves that have frequencies over 20 hz.
+//You start to get interesting effects.
maxiOsc mySine,myOtherSine,myPhasor;//Three oscillators. They can be called anything. They can be any of the available waveforms.
void setup() {//some inits
- //nothing to go here this time
+ //nothing to go here this time
}
void play(double *output) {
-
- *output=mySine.sinewave(440)*myOtherSine.sinewave(myPhasor.phasor(0.1,0,440));
-
+
+ //Using the phasor we can create a ramp, and use this ramp to set the frequency of one of the waves.
+ //When the frequency of the lower waveform passes over the threshold of 20hz, we start to hear two new waveforms.
+ //The frequency of the first new wave is the sum of the two original waves.
+ //The frequency of the second new wave is the difference of the two original waves.
+ //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 c734dcf..266e11f 100755
--- a/maximilian_examples/5.FM1.cpp
+++ b/maximilian_examples/5.FM1.cpp
@@ -1,14 +1,35 @@
+// One way of thinking about FM synthesis is to see it as vibrato.
+// You make a pitch, then vary it up and down at some rate.
+// You can change the speed of the pitch variation (modulation frequency), and also the amount of variation (modulation index).
+// In FM, usually only one of the waveforms - the carrier that provides the initial pitch - is sent to the output.
+// The frequency of the the carrier wave is continually adjusted at a rate equal to the frequency of the second wave (the modulator).
+// So at any given point in time, the frequency of the carrier can increase by an amount equal to the current amp of the modulator.
+// This has some interesting effects.
+
#include "maximilian.h"
maxiOsc mySine,myOtherSine;//Two oscillators
void setup() {//some inits
- //nothing to go here this time
+ //nothing to go here this time
}
void play(double *output) {
-
- *output=mySine.sinewave(myOtherSine.sinewave(1)*440);
-
+
+ // In this example, the 'myOtherSine.sinewave' is at an amplitude of 1, it's original amplitude.
+ // This is pretty simple and not too useful.
+ //output[0]=mySine.sinewave(440*myOtherSine.sinewave(1));
+
+ // Perhaps you should comment out the above line and uncomment the below one instead
+ // It shows how the frequency of the carrier is altered by ADDING a second waveform to its frequency value.
+ // The carrier frequency is 440, and the modulation frequency is 1.
+ // It also shows how the modulation index works. In this case the modulation index is 100
+ // Try adjusting the modolation index. Also, try altering the modulation frequency.
+ output[0]=mySine.sinewave(440+(myOtherSine.sinewave(1)*100));
+ output[1]=output[0];
+
}
+
+// 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.
diff --git a/maximilian_examples/6.FM2.cpp b/maximilian_examples/6.FM2.cpp
index d9acd72..4c6ec8a 100755
--- a/maximilian_examples/6.FM2.cpp
+++ b/maximilian_examples/6.FM2.cpp
@@ -1,14 +1,17 @@
+// Nothing much to say about this other than I like it.
+
#include "maximilian.h"
maxiOsc mySine,myOtherSine,myLastSine,myPhasor;//Three oscillators
void setup() {//some inits
- //nothing to go here this time
+ //nothing to go here this time
}
void play(double *output) {
-
- *output=mySine.sinewave(myOtherSine.sinewave(myLastSine.sinewave(0.1)*30)*440);//awesome bassline
-
+
+ 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 7de2f0e..0000000
--- a/maximilian_examples/7.Counting.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#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) {
-
- CurrentCount=myCounter.phasor(1, 1, 9);//phasor can take three arguments; frequency, start value and end value.
- *output=mySquare.square(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 806e14f..138fb0d 100755
--- a/maximilian_examples/9.Envelopes.cpp
+++ b/maximilian_examples/9.Envelopes.cpp
@@ -1,33 +1,52 @@
+//Envelopes allow you to shape the sound. The basic idea is that a sound has the following shape
+// Attack: This is how long it takes to fade up to maximum volume
+// Decay: This is how long it takes to reach the sustain level.
+// Sustain: This is the sustain level
+// Release: This is how long it takes to fade out.
+
#include "maximilian.h"
maxiOsc myCounter,mySwitchableOsc;//
int CurrentCount;//
double myOscOutput,myCurrentVolume;//
-double myEnvelopeData[4] = {1,0,0,500};//this data will be used to make an envelope. Value and time to value in ms.
-maxiEnvelope myEnvelope;
+maxiEnv myEnvelope;
void setup() {//some inits
- myEnvelope.amplitude=myEnvelopeData[0]; //initialise the envelope
+
+ //Timing is in ms
+
+ myEnvelope.setAttack(0);
+ myEnvelope.setDecay(1); // Needs to be at least 1
+ myEnvelope.setSustain(1);
+ myEnvelope.setRelease(1000);
+
}
void play(double *output) {
-
- myCurrentVolume=myEnvelope.line(4,myEnvelopeData);
-
- 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.
-
- if (CurrentCount==1)
-
- myEnvelope.trigger(0,myEnvelopeData[0]); //trigger the envelope
-
- *output=myOscOutput*myCurrentVolume;//point me at your speakers and fire.
+
+ //notice that we feed in a value of 1. to create an envelope shape we can apply later.
+ myCurrentVolume=myEnvelope.adsr(1.,myEnvelope.trigger);
+
+ CurrentCount=myCounter.phasor(1, 1, 9);//phasor can take three arguments; frequency, start value and end value.
+
+ // You'll notice that these 'if' statements don't require curly braces "{}".
+ // This is because there is only one outcome if the statement is true.
+
+ if (CurrentCount==1) myEnvelope.trigger=1; //trigger the envelope
+
+ else myEnvelope.trigger=0;//release the envelope to make it fade out only if it's been triggered
+
+ if (CurrentCount<5)
+
+ myOscOutput=mySwitchableOsc.sawn(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*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