aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmain.cpp16
-rwxr-xr-xmaximilian_examples/14.monosynth.cpp4
-rw-r--r--maximilian_examples/15.polysynth.cpp72
3 files changed, 79 insertions, 13 deletions
diff --git a/main.cpp b/main.cpp
index 7348246..00763cd 100755
--- a/main.cpp
+++ b/main.cpp
@@ -1,6 +1,6 @@
#include "maximilian.h"
-//This shows how to use maximilian to build a polyphonic synth. Works but something weirds going on with the ticks. Hmm..
+//This shows how to use maximilian to build a polyphonic synth.
//These are the synthesiser bits
maxiOsc VCO1[6],VCO2[6],LFO1[6],LFO2[6];
@@ -9,7 +9,7 @@ maxiEnvelope ADSR[6];
//These are the control values for the envelope
-double adsrEnv[8]={1,5,0.125,50,0.125,125,0,100};
+double adsrEnv[8]={1,5,0.125,100,0.125,200,0,1000};
//This is a bunch of control signals so that we can hear something
@@ -39,19 +39,13 @@ void play(double *output) {
}
ADSR[voice].trigger(0, adsrEnv[0]);//trigger the envelope from the start
- pitch[voice]=voice;
+ pitch[voice]=voice+1;
voice++;
-
- cout << "tick\n";//ticking twice for some reason
- cout << voice;//ticking twice for some reason
- cout << "\n";//ticking twice for some reason
-
-
- lastCount=currentCount;//set the last count to the current count
+ lastCount=0;
}
-
+
//and this is where we build the synth
for (int i=0; i<6; i++) {
diff --git a/maximilian_examples/14.monosynth.cpp b/maximilian_examples/14.monosynth.cpp
index cd9cd46..5dd4e7e 100755
--- a/maximilian_examples/14.monosynth.cpp
+++ b/maximilian_examples/14.monosynth.cpp
@@ -36,9 +36,9 @@ void play(double *output) {
ADSR.trigger(0, adsrEnv[0]);//trigger the envelope from the start
- cout << "tick\n";//ticking twice for some reason
+ cout << "tick\n";//the clock ticks
- lastCount=currentCount;//set the last count to the current count
+ lastCount=0;//set lastCount to 0
}
//and this is where we build the synth
diff --git a/maximilian_examples/15.polysynth.cpp b/maximilian_examples/15.polysynth.cpp
new file mode 100644
index 0000000..6c949ea
--- /dev/null
+++ b/maximilian_examples/15.polysynth.cpp
@@ -0,0 +1,72 @@
+#include "maximilian.h"
+
+//This shows how to use maximilian to build a polyphonic synth.
+//Basically it's the same as the monsynth example only with arrays of objects
+//and a voice allocation system
+
+//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};
+
+//This is a bunch of control signals so that we can hear something
+
+maxiOsc timer;//this is the metronome
+int currentCount,lastCount,voice=0;//these values are used to check if we have a new beat this sample
+
+//and these are some variables we can use to pass stuff around
+
+double VCO1out[6],VCO2out[6],LFO1out[6],LFO2out[6],VCFout[6],ADSRout[6],mix,pitch[6];
+
+
+void setup() {//some inits
+
+
+}
+
+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(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;//set lastCount to 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+(ADSRout[i]*15000), 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=mix;
+}