From 2ba7a5056011da98c04fe33b5ee4b74d3a35da8c Mon Sep 17 00:00:00 2001 From: Mick Grierson Date: Mon, 10 Oct 2011 00:19:19 +0100 Subject: fixed channel problem in player.cpp. Also started work on a polysynth example --- main.cpp | 57 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 20 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index cd9cd46..7348246 100755 --- a/main.cpp +++ b/main.cpp @@ -1,24 +1,24 @@ #include "maximilian.h" -//This shows how to use maximilian to build a monophonic synth +//This shows how to use maximilian to build a polyphonic synth. Works but something weirds going on with the ticks. Hmm.. //These are the synthesiser bits -maxiOsc VCO1,VCO2,LFO1,LFO2; -maxiFilter VCF; -maxiEnvelope ADSR; +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,250,0.125,125,0,500}; +double adsrEnv[8]={1,5,0.125,50,0.125,125,0,100}; //This is a bunch of control signals so that we can hear something maxiOsc timer;//this is the metronome -int currentCount,lastCount;//these values are used to check if we have a new beat this sample +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,VCO2out,LFO1out,LFO2out,VCFout,ADSRout; +double VCO1out[6],VCO2out[6],LFO1out[6],LFO2out[6],VCFout[6],ADSRout[6],mix,pitch[6]; void setup() {//some inits @@ -30,30 +30,47 @@ 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 + 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 - - ADSR.trigger(0, adsrEnv[0]);//trigger the envelope from the start + + if (voice==6) { + voice=0; + } + + ADSR[voice].trigger(0, adsrEnv[0]);//trigger the envelope from the start + pitch[voice]=voice; + 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 + + } //and this is where we build the synth - - ADSRout=ADSR.line(8,adsrEnv);//our ADSR env has 8 value/time pairs. + for (int i=0; i<6; i++) { + - LFO1out=LFO1.sinebuf(0.2);//this lfo is a sinewave at 0.2 hz + 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 - 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 + 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; } -- cgit v1.3