aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmain.cpp53
-rw-r--r--maximilian.cpp20
-rwxr-xr-xmaximilian.h6
-rw-r--r--maximilian_examples/16.Replicant.cpp62
4 files changed, 125 insertions, 16 deletions
diff --git a/main.cpp b/main.cpp
index cd50505..c03c909 100755
--- a/main.cpp
+++ b/main.cpp
@@ -1,13 +1,22 @@
#include "maximilian.h"
-maxiOsc sound,bass,timer,mod;
-maxiEnv envelope;
-double bassout,leadout;
-int trigger;
-int currentCount,lastCount,playHead=0;
-int rhythm[8]={1,0,1,0,1,0,1,0};
-float pitch[8]={220,220,246.9,261.6};
-float currentPitch;
+//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
+maxiFilter filter, filter2;//some filters
+maxiDelayline delay;//a delay
+convert mtof;//a method for converting midi notes to frequency
+double bassout,leadout, delayout;//some variables to hold the data and pass it around
+int trigger, trigger2, newnote;//some control variables
+int currentCount,lastCount,playHead=0, 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};
@@ -16,22 +25,38 @@ void setup() {//some inits
}
void play(double *output) {//this is where the magic happens. Very slow magic.
- currentCount=(int)timer.phasor(20);//this sets up a metronome that ticks every so often
+
+ 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=rhythm[playHead%8];//read through the array
- currentPitch=pitch[(playHead%8)/2];
+ 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=envelope.adsr(bass.saw(currentPitch*0.5)+sound.pulse(currentPitch*0.5,mod.phasor(1)),1,0.9995, 0.25, 0.9995, 1, trigger);//new, simple ADSR.
+ 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
- *output=bassout;
+ 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;
+
}
diff --git a/maximilian.cpp b/maximilian.cpp
index 476a0f9..4e64cbd 100644
--- a/maximilian.cpp
+++ b/maximilian.cpp
@@ -47,6 +47,8 @@ int maxiSettings::bufferSize = 1024;
double sineBuffer[514]={0,0.012268,0.024536,0.036804,0.049042,0.06131,0.073547,0.085785,0.097992,0.1102,0.12241,0.13455,0.1467,0.15884,0.17093,0.18301,0.19507,0.20709,0.21909,0.23105,0.24295,0.25485,0.26669,0.2785,0.29025,0.30197,0.31366,0.32529,0.33685,0.34839,0.35986,0.37128,0.38266,0.39395,0.40521,0.41641,0.42752,0.4386,0.44958,0.46051,0.47137,0.48215,0.49286,0.50351,0.51407,0.52457,0.53497,0.54529,0.55554,0.5657,0.57578,0.58575,0.59567,0.60547,0.6152,0.62482,0.63437,0.6438,0.65314,0.66238,0.67151,0.68057,0.68951,0.69833,0.70706,0.7157,0.72421,0.7326,0.74091,0.74908,0.75717,0.76514,0.77298,0.7807,0.7883,0.79581,0.80316,0.81042,0.81754,0.82455,0.83142,0.8382,0.84482,0.85132,0.8577,0.86392,0.87006,0.87604,0.88187,0.8876,0.89319,0.89862,0.90396,0.90912,0.91415,0.91907,0.92383,0.92847,0.93295,0.93729,0.9415,0.94556,0.94949,0.95325,0.95691,0.96039,0.96375,0.96692,0.97,0.9729,0.97565,0.97827,0.98074,0.98306,0.98523,0.98724,0.98914,0.99084,0.99243,0.99387,0.99515,0.99628,0.99725,0.99808,0.99875,0.99927,0.99966,0.99988,0.99997,0.99988,0.99966,0.99927,0.99875,0.99808,0.99725,0.99628,0.99515,0.99387,0.99243,0.99084,0.98914,0.98724,0.98523,0.98306,0.98074,0.97827,0.97565,0.9729,0.97,0.96692,0.96375,0.96039,0.95691,0.95325,0.94949,0.94556,0.9415,0.93729,0.93295,0.92847,0.92383,0.91907,0.91415,0.90912,0.90396,0.89862,0.89319,0.8876,0.88187,0.87604,0.87006,0.86392,0.8577,0.85132,0.84482,0.8382,0.83142,0.82455,0.81754,0.81042,0.80316,0.79581,0.7883,0.7807,0.77298,0.76514,0.75717,0.74908,0.74091,0.7326,0.72421,0.7157,0.70706,0.69833,0.68951,0.68057,0.67151,0.66238,0.65314,0.6438,0.63437,0.62482,0.6152,0.60547,0.59567,0.58575,0.57578,0.5657,0.55554,0.54529,0.53497,0.52457,0.51407,0.50351,0.49286,0.48215,0.47137,0.46051,0.44958,0.4386,0.42752,0.41641,0.40521,0.39395,0.38266,0.37128,0.35986,0.34839,0.33685,0.32529,0.31366,0.30197,0.29025,0.2785,0.26669,0.25485,0.24295,0.23105,0.21909,0.20709,0.19507,0.18301,0.17093,0.15884,0.1467,0.13455,0.12241,0.1102,0.097992,0.085785,0.073547,0.06131,0.049042,0.036804,0.024536,0.012268,0,-0.012268,-0.024536,-0.036804,-0.049042,-0.06131,-0.073547,-0.085785,-0.097992,-0.1102,-0.12241,-0.13455,-0.1467,-0.15884,-0.17093,-0.18301,-0.19507,-0.20709,-0.21909,-0.23105,-0.24295,-0.25485,-0.26669,-0.2785,-0.29025,-0.30197,-0.31366,-0.32529,-0.33685,-0.34839,-0.35986,-0.37128,-0.38266,-0.39395,-0.40521,-0.41641,-0.42752,-0.4386,-0.44958,-0.46051,-0.47137,-0.48215,-0.49286,-0.50351,-0.51407,-0.52457,-0.53497,-0.54529,-0.55554,-0.5657,-0.57578,-0.58575,-0.59567,-0.60547,-0.6152,-0.62482,-0.63437,-0.6438,-0.65314,-0.66238,-0.67151,-0.68057,-0.68951,-0.69833,-0.70706,-0.7157,-0.72421,-0.7326,-0.74091,-0.74908,-0.75717,-0.76514,-0.77298,-0.7807,-0.7883,-0.79581,-0.80316,-0.81042,-0.81754,-0.82455,-0.83142,-0.8382,-0.84482,-0.85132,-0.8577,-0.86392,-0.87006,-0.87604,-0.88187,-0.8876,-0.89319,-0.89862,-0.90396,-0.90912,-0.91415,-0.91907,-0.92383,-0.92847,-0.93295,-0.93729,-0.9415,-0.94556,-0.94949,-0.95325,-0.95691,-0.96039,-0.96375,-0.96692,-0.97,-0.9729,-0.97565,-0.97827,-0.98074,-0.98306,-0.98523,-0.98724,-0.98914,-0.99084,-0.99243,-0.99387,-0.99515,-0.99628,-0.99725,-0.99808,-0.99875,-0.99927,-0.99966,-0.99988,-0.99997,-0.99988,-0.99966,-0.99927,-0.99875,-0.99808,-0.99725,-0.99628,-0.99515,-0.99387,-0.99243,-0.99084,-0.98914,-0.98724,-0.98523,-0.98306,-0.98074,-0.97827,-0.97565,-0.9729,-0.97,-0.96692,-0.96375,-0.96039,-0.95691,-0.95325,-0.94949,-0.94556,-0.9415,-0.93729,-0.93295,-0.92847,-0.92383,-0.91907,-0.91415,-0.90912,-0.90396,-0.89862,-0.89319,-0.8876,-0.88187,-0.87604,-0.87006,-0.86392,-0.8577,-0.85132,-0.84482,-0.8382,-0.83142,-0.82455,-0.81754,-0.81042,-0.80316,-0.79581,-0.7883,-0.7807,-0.77298,-0.76514,-0.75717,-0.74908,-0.74091,-0.7326,-0.72421,-0.7157,-0.70706,-0.69833,-0.68951,-0.68057,-0.67151,-0.66238,-0.65314,-0.6438,-0.63437,-0.62482,-0.6152,-0.60547,-0.59567,-0.58575,-0.57578,-0.5657,-0.55554,-0.54529,-0.53497,-0.52457,-0.51407,-0.50351,-0.49286,-0.48215,-0.47137,-0.46051,-0.44958,-0.4386,-0.42752,-0.41641,-0.40521,-0.39395,-0.38266,-0.37128,-0.35986,-0.34839,-0.33685,-0.32529,-0.31366,-0.30197,-0.29025,-0.2785,-0.26669,-0.25485,-0.24295,-0.23105,-0.21909,-0.20709,-0.19507,-0.18301,-0.17093,-0.15884,-0.1467,-0.13455,-0.12241,-0.1102,-0.097992,-0.085785,-0.073547,-0.06131,-0.049042,-0.036804,-0.024536,-0.012268,0,0.012268
};
+int mtofarray[129]={0, 8.661957, 9.177024, 9.722718, 10.3, 10.913383, 11.562325, 12.25, 12.978271, 13.75, 14.567617, 15.433853, 16.351599, 17.323914, 18.354048, 19.445436, 20.601723, 21.826765, 23.124651, 24.5, 25.956543, 27.5, 29.135235, 30.867706, 32.703197, 34.647827, 36.708096, 38.890873, 41.203445, 43.65353, 46.249302, 49., 51.913086, 55., 58.27047, 61.735413, 65.406395, 69.295654, 73.416191, 77.781746, 82.406891, 87.30706, 92.498604, 97.998856, 103.826172, 110., 116.540939, 123.470825, 130.81279, 138.591309, 146.832382, 155.563492, 164.813782, 174.61412, 184.997208, 195.997711, 207.652344, 220., 233.081879, 246.94165, 261.62558, 277.182617,293.664764, 311.126984, 329.627563, 349.228241, 369.994415, 391.995422, 415.304688, 440., 466.163757, 493.883301, 523.25116, 554.365234, 587.329529, 622.253967, 659.255127, 698.456482, 739.988831, 783.990845, 830.609375, 880., 932.327515, 987.766602, 1046.502319, 1108.730469, 1174.659058, 1244.507935, 1318.510254, 1396.912964, 1479.977661, 1567.981689, 1661.21875, 1760., 1864.655029, 1975.533203, 2093.004639, 2217.460938, 2349.318115, 2489.015869, 2637.020508, 2793.825928, 2959.955322, 3135.963379, 3322.4375, 3520., 3729.31, 3951.066406, 4186.009277, 4434.921875, 4698.63623, 4978.031738, 5274.041016, 5587.651855, 5919.910645, 6271.926758, 6644.875, 7040., 7458.620117, 7902.132812, 8372.018555, 8869.84375, 9397.272461, 9956.063477, 10548.082031, 11175.303711, 11839.821289, 12543.853516, 13289.75};
+
void setup();//use this to do any initialisation if you want.
void play(double *channels);//run dac!
@@ -211,11 +213,20 @@ void maxiEnvelope::trigger(int index, double amp) {
}
//and this
+
+maxiDelayline::maxiDelayline() {
+ memory[88200]=NULL;
+
+}
+
+
double maxiDelayline::dl(double input, int size, double feedback) {
- if ( phase >=size ) phase = 0;
+ if ( phase >=size ) {
+ phase = 0;
+ }
memory[phase]=(memory[phase]*feedback)+(input*feedback)*0.5;
phase+=1;
- output=memory[phase+1];
+ output=memory[phase];
return(output);
}
@@ -970,4 +981,9 @@ double maxiEnv::adsr(double input, double attack, double decay, double sustain,
}
return output;
+}
+
+double convert::mtof(int midinote) {
+
+ return mtofarray[midinote];
} \ No newline at end of file
diff --git a/maximilian.h b/maximilian.h
index b7c4e9b..cb1bebb 100755
--- a/maximilian.h
+++ b/maximilian.h
@@ -116,6 +116,7 @@ class maxiDelayline {
double memory[88200];
public:
+ maxiDelayline();
double dl(double input, int size, double feedback);
double dl(double input, int size, double feedback, int position);
@@ -351,4 +352,9 @@ public:
int attackphase,decayphase,sustainphase,holdphase,releasephase;
};
+class convert {
+ public:
+ double mtof(int midinote);
+};
+
#endif
diff --git a/maximilian_examples/16.Replicant.cpp b/maximilian_examples/16.Replicant.cpp
new file mode 100644
index 0000000..c03c909
--- /dev/null
+++ b/maximilian_examples/16.Replicant.cpp
@@ -0,0 +1,62 @@
+#include "maximilian.h"
+
+//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
+maxiFilter filter, filter2;//some filters
+maxiDelayline delay;//a delay
+convert mtof;//a method for converting midi notes to frequency
+double bassout,leadout, delayout;//some variables to hold the data and pass it around
+int trigger, trigger2, newnote;//some control variables
+int currentCount,lastCount,playHead=0, 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;
+
+}
+