diff options
| author | mick grierson <mickgrierson@gmail.com> | 2015-10-02 09:12:44 +0100 |
|---|---|---|
| committer | mick grierson <mickgrierson@gmail.com> | 2015-10-02 09:12:44 +0100 |
| commit | 61dfa1e6f2dbc680df96ee9afdd3bb6b898560a7 (patch) | |
| tree | 80fed4ff1d616ff7cb1d3c8c2c6213e977b4928f /main.cpp | |
| parent | e4eb667af04304cbe9c0be5997ebea2049178590 (diff) | |
removing binaries
Diffstat (limited to 'main.cpp')
| -rwxr-xr-x | main.cpp | 82 |
1 files changed, 17 insertions, 65 deletions
@@ -1,81 +1,33 @@ -#include "maximilian.h" - -//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]; -maxiFilter VCF[6]; -maxiEnv ADSR[6]; - -//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]; +#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() {//some inits +void setup() { - for (int i=0;i<6;i++) { - - ADSR[i].setAttack(0); - ADSR[i].setDecay(200); - ADSR[i].setSustain(0.2); - ADSR[i].setRelease(2000); - - } + 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) { - 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++; - - } + myClock.ticker(); // This makes the clock object count at the current samplerate - //and this is where we build the synth + //This is a 'conditional'. It does a test and then does something if the test is true - 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 + if (myClock.tick) { // If there is an actual tick at this time, this will be true. - 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 + freq+=100; // DO SOMETHING - - 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 + } // The curly braces close the conditional + //output[0] is the left output. output[1] is the right output - // This just sends note-off messages. - for (int i=0; i<6; i++) { - ADSR[i].trigger=0; - } + output[0]=mySine.sinewave(freq);//simple as that! + output[1]=output[0]; } + |
