//HSS3S02V10 for use with HSS3f hardware. //gijs gieskes 2009/2011, http://gieskes.nl //credits: http://gieskes.nl/instruments/files/hard-soft-synth-3/hss3-credits.html //upload using arduino version 21 only //pots mounted on top == true, bottom == false; boolean reverse = true; byte volume = 0; byte prevstatePWM1 = 255; byte prevstatePWM2 = 255; byte ADCByte = 0; //pot array int pot[8] = { 0,0,0,0,0,0,0,0}; int potp[8] = { 0,0,0,0,0,0,0,0}; //int potm[8] = {0,0,0,0,0,0,0,0}; byte mcounter = 0; byte seqCount = 0; boolean typeSwitch = 0; unsigned long mlong[4] = { 0,0,0,0}; byte vibA = 0; float fout = 0; boolean Acounter = 0; boolean Bcounter = 0; //midi library: //http://timothytwillman.com/itp_blog/?page_id=240 #include "Midi.h" boolean midibool = false; boolean sendMIDI = false; //boolean midiactive = false; boolean changeMode = false; class MyMidi : public Midi { public: // Need this to compile; it just hands things off to the Midi class. MyMidi(HardwareSerial &s) : Midi(s) { } void handleControlChange(unsigned int channel, unsigned int controller, unsigned int value) { if(controller == 20 || 21 || 22 || 23 || 24 || 25 || 26){ midibool = true; } //midiactive = true; switch(controller){ case 20: pot[0] = 1023-(value<<3); break; case 21: pot[1] = 1023-(value<<3); break; case 22: pot[2] = 1023-(value<<3); break; case 23: pot[3] = 1023-(value<<3); break; case 24: pot[4] = 1023-(value<<3); break; case 25: pot[5] = 1023-(value<<3); break; case 26: pot[6] = 1023-(value<<3); break; //pot[(controller-1)%7] = 1023-(value<<3); } } void handleNoteOn(unsigned int channel, unsigned int note, unsigned int velocity) { switch(note){ case 0: changeMode = true; break; case 1: triggerNormal(); break; } } void handleStart(){ seqCount = 0; changeMode = true; } }; MyMidi midi(Serial); byte midichannel = 1; //wave generator values byte decayA = 0; int octaver = 0; int octaver2 = 0; byte butSel = 0; byte prevSynth = 100; byte triggerDecay = 0; int sinAc = 0; byte sinAc2 = 0; int avLed = 0; char cvol = 0; float tvol = 0.5; float tvol2 = 0; float kick = 0; int BA = 0; int BB = 0; int tp = 0; //oscs unsigned int oscA = 0; unsigned int oscB = 0; unsigned int oscC = 0; unsigned int oscD = 0; unsigned int oscE = 0; unsigned int oscF = 0; unsigned int oscG = 0; unsigned int oscA2 = 0; unsigned int oscB2 = 0; unsigned int oscC2 = 0; unsigned int oscD2 = 0; unsigned int oscE2 = 0; unsigned int oscF2 = 0; byte offset = 0; boolean ta = LOW; boolean tb = LOW; boolean tc = LOW; boolean td = LOW; int oscL[8] = { 264,264,264,264,264,264,264,264}; //noise synth waveform holder byte oscN[8] = { 1,1,1,1,1,1,1,1}; float sinA[32] = { 0.6, 0.679, 0.755, 0.825, 0.886, 0.936, 0.972, 0.994, 1, 0.99, 0.965, 0.926, 0.874, 0.811, 0.739, 0.662, 0.583, 0.504, 0.429, 0.361, 0.303, 0.256, 0.222, 0.204, 0.201, 0.214, 0.242, 0.284, 0.339, 0.404, 0.477, 0.554}; //byte waveTable[512]; byte waveTable[1025]; float sinC[41]; byte ti = 0; int out = 0; //trigger vars volatile boolean externalTrigger = false; volatile boolean triggerActive = false; volatile boolean inLoop = false; void setup(){ pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, INPUT); digitalWrite(8, HIGH); delay(100); sendMIDI = !digitalRead(8); //TIMER SETUP TCCR0B = TCCR0B & 0b11111000 | 0x01; TCCR1B = TCCR1B & 0b11111000 | 0x01; TCCR2B = TCCR2B & 0b11111000 | 0x01; //set speed of ADC: //http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1208715493/11 //http://vimeo.com/1460684 //ADCSRA &= ~B111; //ADCSRA |= B111; for(float f=0.5; f<1; f+=0.05){ sinC[ti] = f; ti++; } for(float f=1; f>0.5; f-=0.05){ sinC[ti] = f; ti++; } waveTable[0] = 32; waveTable[1] = 32; for(byte i=6; i<255; i++){ waveGenartor(pot[3], 0); } pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(13, OUTPUT); //read all pots before startup readAnalogs(); readAnalogs(); readAnalogs(); readAnalogs(); readAnalogs(); readAnalogs(); pinMode(2, INPUT); digitalWrite(2, HIGH); pinMode(3, INPUT); digitalWrite(3, HIGH); //set to CHANGE to patch signal direct thrue.. attachInterrupt(0, triggerOut, CHANGE); attachInterrupt(1, triggerOut, CHANGE); midi.begin(1); startupSound(); //Serial.begin(9600); } void loop(){ //check if we are in the loop.. (for interupt, pullup resistors). inLoop = true; midi.poll(); modeChange(); //read potmeters readAnalogs(); if(typeSwitch){ butSel = pot[5] >> 7; switch (butSel){ case 0: V1P01(); break; case 1: V1P04(); break; case 2: V1P02(); break; case 3: V1P05(); break; case 4: V1P06(); break; case 5: V1P03(); break; case 6: V1P07(); break; case 7: V1P08(); break; } } else{ butSel = pot[5]/70;// >> 6; switch (butSel){ case 0: S1P00(); break; case 1: S1P01(); break; case 2: S1P03(); break; case 3: S1P02(); break; case 4: S1P04(); break; case 5: S1P05(); break; case 6: S1P06(); break; case 7: S1P07(); break; case 8: S1P08(); break; case 9: S1P09(); break; case 10: S1P11(); break; case 11: S1P14(); break; case 12: S1P10(); break; case 13: S1P15(); break; case 14: S1P12(); break; case 15: S1P13(); break; } } } inline void V1P01(){ if(prevSynth != butSel){ digitalWrite(5, 0); digitalWrite(6, 0); digitalWrite(7, 0); digitalWrite(10, 0); resetVisSetup(); prevSynth = butSel; } if((pot[4]>>8)+2 != ADCByte){ ADCByte = (pot[4]>>8)+2; ADCSRA &= ~B111; ADCSRA |= ADCByte; } oscA = cup(oscA, pot[0]>>4); //was 5 if(!oscA){ ta = !ta; } if(triggerState() || !bitRead(PINB, 0)){ tc = tb; } else{ if(tc == tb){ tb = !tb; } } if(tb){ if(ta){ analogWrite(5, min(((1023-pot[1])>>2)+1, 255)); analogWrite(6, min(((1023-pot[2])>>2)+1, 255)); } else{ analogWrite(5, min(((1023-pot[3])>>2)+1, 255)); analogWrite(6, min((pot[3]>>2)+1, 255)); } } else{ if(ta){ analogWrite(5, min((pot[1]>>2)+1, 254)); analogWrite(6, min((pot[2]>>2)+1, 254)); } else{ analogWrite(5, min((pot[3]>>2)+1, 254)); analogWrite(6, min(((1023-pot[3])>>2)+1, 254)); } } } inline void V1P04(){ if(prevSynth != butSel){ prevSynth = butSel; resetVisSetup(); } analogWrite(10, min((pot[3]>>2), 255)); if((pot[4]>>8)+4 != ADCByte){ ADCByte = (pot[4]>>8)+4; ADCSRA &= ~B111; ADCSRA |= ADCByte; } oscC = cup(oscC, 8); oscL[oscC] = (byte) ((pot[1]>>2)*(oscC+1)); oscN[oscC] = (byte) ((pot[2]>>2)*(oscC+1)); oscA = cup(oscA, pot[0]>>5); if(!oscA){ oscB = cup(oscB, 8); } else{ //dummy oscB2 = cup(oscB2, 8); } if(triggerState() || !bitRead(PINB, 0)){ tc = tb; } else{ if(tc == tb){ tb = !tb; } } if(tb){ analogWrite(5, min(oscL[oscB]+1, 255)); analogWrite(6, min(oscN[oscB]+1, 255)); } else{ analogWrite(5, min(255-oscL[oscB]+1, 255)); analogWrite(6, min(255-oscN[oscB]+1, 255)); } } inline void V1P02(){ if(prevSynth != butSel){ resetVisSetup(); prevSynth = butSel; } if(triggerState() || !bitRead(PINB, 0)){ oscD= 0; } oscC = cup(oscC, 100); if(!oscC){ oscD++; oscD = min(oscD, 64); } oscA = cup(oscA, min(pot[4]>>5, oscD)); //was 5 if(!oscA){ oscB = cup(oscB, 4); } analogWrite(5, min(((1023-pot[oscB])>>2)+1, 255)); analogWrite(6, min(((pot[oscB])>>2)+1, 255)); } inline void V1P05(){ if(prevSynth != butSel){ resetVisSetup(); prevSynth = butSel; } if(triggerState() || !bitRead(PINB, 0)){ oscD= 0; } oscC = cup(oscC, 200); if(!oscC){ oscD++; oscD = min(oscD, pot[3]>>4); } else{ //dummy calcs oscD2++; oscD2 = min(oscD2, 150); } oscA = cup(oscA, pot[4]>>4); //was 5 if(!oscA){ oscA2 = cup(oscA2, 3); } else{ //dummy calcs oscB2 = cup(oscB2, 3); } if(oscL[oscA2] >= 255){ oscN[oscA2] = 0; } if(oscL[oscA2] <= 1 || oscL[oscA2] <= (pot[oscA2]>>2)){ oscN[oscA2] = 1; } oscB = cup(oscB, oscD); if(!oscB){ if(oscN[oscA2] == 1){ oscL[oscA2]++; } else{ oscL[oscA2]--; } } analogWrite(5, 1023-oscL[oscA2]); analogWrite(6, oscL[oscA2]); delayMicroseconds(9); } inline void V1P06(){ if(prevSynth != butSel){ resetVisSetup(); prevSynth = butSel; } if(triggerState() || !bitRead(PINB, 0)){ oscD = 0; oscE = 0; } oscC = cup(oscC, 200); if(!oscC){ oscD++; oscD = min(oscD, pot[2]>>6); oscE++; oscE = min(oscE, pot[3]>>6); } if(oscC2 == 0){ oscA = cup(oscA, ((1023 - (oscL[0] << 2)) >> 6)+1); //was 5 } else if(oscC2 == 1){ oscA = cup(oscA, ((oscL[0] << 2) >> 6)+1); //was 5 } else if(oscC2 == 2){ oscA = cup(oscA, ((1023 - (oscL[1] << 2)) >> 6)+1); } else{ oscA = cup(oscA, ((oscL[1] << 2) >> 6)+1); } if(!oscA){ ta = !ta; oscA2 = cup(oscA2, 2); oscC2 = cup(oscC2, 4); } if(oscL[0] >= 255){ oscN[0] = 0; } if(oscL[0] <= 1){ oscN[0] = 1; } if(oscL[1] >= 255){ oscN[1] = 0; } if(oscL[1] <= 1){ oscN[1] = 1; } oscB = cup(oscB, oscD); if(!oscB){ if(oscN[0] == 1){ oscL[0]++; } else{ oscL[0]--; } } oscB2 = cup(oscB2, oscE); if(!oscB2){ if(oscN[1] == 1){ oscL[1]++; } else{ oscL[1]--; } } oscD2 = cup(oscD2, pot[0]>>2); if(!oscD2){ oscF = cup(oscF, 255); } oscE2 = cup(oscE2, pot[1]>>2); if(!oscE2){ oscG = cup(oscG, 255); } analogWrite(5, (byte) ((oscF)*(oscA2+1))); analogWrite(6, (byte) ((oscG)*(oscA2+1))); delayMicroseconds((pot[4]>>2)+9); } inline void V1P03(){ if(prevSynth != butSel){ prevSynth = butSel; resetVisSetup(); } if((pot[4]>>8)+4 != ADCByte){ ADCByte = (pot[4]>>8)+4; ADCSRA &= ~B111; ADCSRA |= ADCByte; } oscA = cup(oscA, pot[0]>>4); //was 5 if(!oscA){ ta = !ta; } else{ //dummy ta = ta; } oscA2 = cup(oscA2, pot[2]>>3); if(!oscA2){ if(oscB2 >= pot[3]>>2){ td = false; } if(oscB2 < 1){ td = true; } if(td){ oscB2++; } else{ oscB2--; } } else{ //dummy oscC2++; oscC2++; } if(triggerState() || !bitRead(PINB, 0)){ tc = tb; } else{ if(tc == tb){ oscC = 0; if(td){ oscB2 = 0; } else{ oscB2 = 255; } tb = !tb; } } //trigger fade? oscB = cup(oscB, 20); if(!oscB){ oscC++; oscC = min(oscC, 255); } if(ta){ analogWrite(5, min((pot[1]>>2)+1, oscC)); analogWrite(6, min(((1023-pot[1])>>2)+1, oscC)); } else{ analogWrite(5, 0); analogWrite(6, 0); } analogWrite(10, oscB2); } inline void V1P07(){ if(prevSynth != butSel){ prevSynth = butSel; resetVisSetup(); } if((pot[4]>>8)+4 != ADCByte){ ADCByte = (pot[4]>>8)+4; ADCSRA &= ~B111; ADCSRA |= ADCByte; } if(triggerState() || !bitRead(PINB, 0)){ Acounter = !Acounter; } oscA2 = cup(oscA2, pot[2]>>3); if(!oscA2){ if(Acounter){ if(oscB2 > 255){ td = false; } if(oscB2 <= pot[3]>>2){ td = true; } } else{ if(oscB2 > pot[3]>>2){ td = false; } if(oscB2 <= 0){ td = true; } } if(td){ oscB2++; } else{ oscB2--; } } analogWrite(10, oscB2); oscA = cup(oscA, pot[1]>>4); if(!oscA){ for(int i=0; i<(1 << (pot[0]>>7)); i++){ ta = !ta; if(ta){// && pot[2] > 300){ tb = !tb; if(tb){// && pot[2] > 700){ tc = !tc; } } bitWrite(PORTD, 7, ta); bitWrite(PORTD, 6, tb); bitWrite(PORTD, 5, tc); } } } inline void V1P08(){ if(prevSynth != butSel){ prevSynth = butSel; resetVisSetup(); ta = 0; tb = 0; tc = 0; td = 0; } if(triggerState() || !bitRead(PINB, 0)){ oscC2 = 1; } oscB2 = cup(oscB2, pot[4]>>6); if(!oscB2){ oscC2 += (pot[0]>>2)+1; oscC2 = min(oscC2, pot[0]<<2); } oscA = cup(oscA, pot[1]>>5); if(!oscA){ if((pot[2] >> 8) == 0){ for(unsigned int i=0; i<(oscC2); i++){ oscA2 = cup(oscA2, 3); bitWrite(PORTB, 2, oscA2); if(ta){ tb = !tb; bitWrite(PORTD, 6, oscA2); if(tb){ tc = !tc; bitWrite(PORTD, 5, oscA2); if(tc){ td = !td; // bitWrite(PORTD, 7, oscA2); } } } } } else if((pot[2] >> 8) == 1){ for(unsigned int i=0; i<(oscC2); i++){ ta = !ta; bitWrite(PORTD, 7, 1); if(ta){ tb = !tb; bitWrite(PORTD, 6, tb); bitWrite(PORTD, 5, tb); if(tb){ bitWrite(PORTB, 2, 1); } } //bitWrite(PORTD, 7, 0); bitWrite(PORTD, 6, 0); bitWrite(PORTD, 5, 0); bitWrite(PORTB, 2, 0); } } else if((pot[2] >> 8) == 2){ for(unsigned int i=0; i<(oscC2); i++){ ta = !ta; if(ta){ tb = !tb; if(tb){ tc = !tc; if(tc){ td = !td; } } } bitWrite(PORTD, 7, ta); //bitWrite(PORTD, 6, tb); bitWrite(PORTD, 5, tc); bitWrite(PORTB, 2, td); } } else{ for(unsigned int i=0; i<(oscC2); i++){ ta = !ta; if(ta){ tb = !tb; } //bitWrite(PORTD, 7, ta); //bitWrite(PORTD, 6, tb); bitWrite(PORTD, 5, ta); bitWrite(PORTB, 2, ta); } } } for(int i=0; i<(pot[3]>>2); i++){ ta = !ta; } } ///////// ///////// ///////// ///////// inline void S1P00(){ //reset vars if(prevSynth != butSel){ prevSynth = butSel; digitalWrite(11, HIGH); } setupPWM(1); waveGenartor(pot[3], 0); oscA2 = max(pot[0] >> 2, 1); oscA = cup(oscA, max(oscA2+1, 1)); oscB = cup(oscB, max(oscA2+2, 2)); oscC = cup(oscC, max(oscA2+3, 3)); //mix oscillators out = ((waveTable[oscA])+(waveTable[oscB])+(waveTable[oscC]))>>2; //add vibrato if(millis() - mlong[0] > ((pot[2]<<2)+512)){ mlong[0] = millis(); analogWrite(11, (255 - (pot[4] >> 2))); vibA = cup(vibA, ti); fout = sinC[vibA]*((pot[1]*0.001)+0.9); trigger((ti*2)); } out *= fout; out = constrain(out, 0, 127); if(!oscA){ Acounter = !Acounter; } if(!oscA2){ Bcounter = !Bcounter; } analogWrite(5, 20); analogWrite(6, 10); if(oscD > out){ oscD++; } else{ oscD--; } audioOut(out); analogWrite(10, out); delayMicroseconds(oscA2); } inline void S1P01(){ //reset vars if(prevSynth != butSel){ prevSynth = butSel; } setupPWM(1); waveGenartor(pot[3], 0); //detunes oscillators oscA++; oscA %= (pot[0] >> 4)+1; oscB++; oscB %= (pot[1] >> 4)+1; oscC++; oscC %= (pot[2] >> 4)+1; //mix oscillators out = ((waveTable[oscA]*2)+(waveTable[oscB]*2)+(waveTable[oscC]*2))/7; analogWrite(11, (255 - (pot[4] >> 2))); audioOut(out); analogWrite(10, out); delayMicroseconds(1); } inline void S1P02(){ //kick //reset vars if(prevSynth != butSel){ setupPWM(0); prevSynth = butSel; } static unsigned int pitchDecay = 0; waveGenartor(pot[3], 0); oscA = cup(oscA, max((pot[2] >> 4)+1, 1)); oscB = cup(oscB, max((pot[0] >> 4)+1, 1)); oscC = cup(oscC, max((pot[0] >> 4)+2, 1)); pitchDecay = cup(pitchDecay, (pot[4])); //mix oscillators out = ((waveTable[oscA]*2)+(waveTable[oscB]*2)+(waveTable[oscC]*2))/6; byte tr0 = (pot[1]/6)+83; out = constrain(out, 0, tr0); if(!oscA){ Acounter = !Acounter; } if(!oscB){ Bcounter = !Bcounter; } static byte go = 0; go = cup(go, 256); if(!go){ Acounter = !Acounter; } if(Acounter){ //analogWrite(6, out); } else{ analogWrite(10, min(255, (out << 1))); //digitalWrite(6, LOW); } audioOut(out); analogWrite(11, out); if(256 % (pitchDecay + 20) == 0){ trigger(2); } if(!pitchDecay){ tvol = 255; } tvol*=0.992; max(tvol, 0.1); //analogWrite(11, (byte(tvol))); delayMicroseconds(pitchDecay+20); } inline void S1P03(){ //reset vars if(prevSynth != butSel){ setupPWM(0); prevSynth = butSel; digitalWrite(11, HIGH); } //detunes oscillators oscA = cup(oscA, (pot[0] >> 4)+1); oscB = cup(oscB, (pot[0] >> 4)+2); oscC = cup(oscC, (pot[0] >> 4)+3); oscD = cup(oscD, (pot[0] >> 4)+4); //detunes oscillators oscA2 = cup(oscA2, (pot[1] >> 4)+1); oscB2 = cup(oscB2, (pot[1] >> 4)+2); oscC2 = cup(oscC2, (pot[1] >> 4)+3); oscD2 = cup(oscD2, (pot[1] >> 4)+4); //mix oscillators unsigned int outA = ((waveTable[oscA]*2)+(waveTable[oscB]*2)+(waveTable[oscC]*2)+(waveTable[oscD]*2)); unsigned int outB = ((waveTable[oscA2]*2)+(waveTable[oscB2]*2)+(waveTable[oscC2]*2)+(waveTable[oscD2]*2)); outA = (outA)*(((pot[2]+1)*0.0005)); outB = (outB)*(((pot[3]+1)*0.0005)); if(outA > 255){ outA -= (outA - 255); trigger(32); } if(outB > 255){ outB -= (outB - 255); trigger(32); } byte out = (outA+outB) >> 1; //oscilloscope(Mout); digitalWrite(5, out); digitalWrite(6, out); audioOut(out); analogWrite(10, out); analogWrite(11, (pot[4] >> 2)); delayMicroseconds(1); } inline void S1P04(){ //techno //reset vars if(prevSynth != butSel){ //setup timers setupPWM(0); prevSynth = butSel; oscA = 0; seqCount = 0; tvol = 0; //resetWavetable(); } //legato if(tp < pot[seqCount]){ tp++; } else if(tp > pot[seqCount]){ tp--; } //oscillators timer oscA++; oscA %= (tp >> 3)+20; //display wave.. analogWrite(10, (tp >> 2)); analogWrite(11, (tp >> 2)); //interval if(triggerME((pot[4] >> 1)+ 4, 0)){ //selectpotmeter for next pitch seqCount++; seqCount %= 4; //render waveform waveGenartor(1023, ta); //pwm sound, changes settings inside the waveGenerator if(!(sinAc % 32)){ sinAc = 0; ta = !ta; } //reset volume tvol = 0.5; tc = random(2); //no display lines digitalWrite(5, 0); digitalWrite(6, 0); //send trigger digitalWrite(13, HIGH); digitalWrite(4, HIGH); oscA2 = 30; } oscA2--; oscA2 = max(oscA2, 0); if(!oscA2){ digitalWrite(13, LOW); digitalWrite(4, LOW); } //fade out tvol -= 0.0002; tvol = max(tvol, 0.0001); out = (waveTable[oscA])*tvol; audioOut(out); delayMicroseconds(20); } inline void S1P05(){ //reset vars if(prevSynth != butSel){ digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); prevSynth = butSel; oscD = 0; oscA2 = 2; oscB2 = 2; oscC2 = 2; oscD2 = 0; oscL[0] = 0; oscL[1] = 0; oscL[2] = 0; } //setup timers setupPWM(0); oscA++; oscA %= oscA2; oscB++; oscB %= oscB2; oscC++; oscC %= oscC2; //pitch change if(triggerME((pot[4] >> 3)+10, 0)){ waveGenartor(1023, 0); byte selMode = pot[3] >> 8; if(selMode == 0){ oscA2 = max(pot[0] >> 4, 1); oscB2 = max(pot[1] >> 4, 1); oscC2 = max(pot[2] >> 4, 1); } else if(selMode == 1){ oscA2 = max(pot[1] >> 4, 1); oscB2 = max(pot[2] >> 4, 1); oscC2 = max(pot[0] >> 4, 1); } else if(selMode == 2){ oscA2 = max(pot[2] >> 4, 1); oscB2 = max(pot[0] >> 4, 1); oscC2 = max(pot[1] >> 4, 1); } oscL[0]++; oscL[0] %= max((pot[0] >> 3)+1, 1); oscL[1]++; oscL[1] %= max((pot[1] >> 3)+1, 1); oscL[2]++; oscL[2] %= max((pot[2] >> 3)+1, 1); //fade reset oscD2 = 240; } //fade oscD2 -= 0.01; oscD2 = max(oscD2, 0.0001); //reset out out = 0; //mix if(!oscL[0]){ out += (sinA[oscA]*oscD2); trigger(2); } if(!oscL[1]){ out += (sinA[oscB]*oscD2); trigger(2); } if(!oscL[2]){ out += (sinA[oscC]*oscD2); trigger(2); //reset Effect LED oscD = 255; } //fade Efect LED oscD--; oscD = max(oscD, 1); analogWrite(11, oscD); out = max(min((out/3), 255), 1); audioOut(max(min(out, 100), 1)); analogWrite(10, min(256, (out << 2))); delayMicroseconds(1); } inline void S1P06(){ //noise //reset vars if(prevSynth != butSel){ prevSynth = butSel; digitalWrite(10, LOW); } setupPWM(0); //switch between up or down fade if(triggerME(pot[2]+50, 0)){ for(byte i=0; i<255; i++){ waveTable[i] = random(32); } analogWrite(11, min((waveTable[0]*(pot[4] >> 5)), 255)); ta = !ta; //visuals if(waveTable[0] > 4){ analogWrite(5, min(255, (waveTable[0] << 2))); } else{ digitalWrite(5, (waveTable[0] >> 3)); } if(waveTable[1] > 4){ analogWrite(6, min(255, (waveTable[1] << 2))); } else{ digitalWrite(6, (waveTable[1] >> 3)); } digitalWrite(7, (waveTable[2] >> 2)); //start trigger digitalWrite(13, HIGH); digitalWrite(4, HIGH); triggerDecay = 30; } //countdwon trigger and set low.. triggerDecay--; triggerDecay = max(triggerDecay, 0); if(!triggerDecay){ digitalWrite(13, LOW); digitalWrite(4, LOW); } //fade if(ta == 0){ kick -= 0.0003; if(kick < 0.001){ kick = 0.95; } } else if(ta == 1){ kick += 0.0003; if(kick > 0.95){ kick = 0.0001; } } //play wave form.. oscA++; oscA %= ((pot[1] >> 3)+2); out = min(waveTable[oscA]*kick, 253)+1; audioOut(out); delayMicroseconds((pot[0] << 1)+1); } inline void S1P07(){ //noise //reset vars if(prevSynth != butSel){ prevSynth = butSel; } setupPWM(0); //add up and add new rand vars to array with delay.. oscA++; oscA %= (pot[4] >> 4)+1; if(!oscA){ oscB++; oscB %= 8; oscN[oscB] = random(90)*kick; tc = !tc; digitalWrite(7, tc); } //select active sounds oscA2 = pot[1] >> 5; //fade in if(bitRead(oscA2, 0)){ kick += 0.01; if(kick > 0.99){ kick = 0; } } //fade out if(bitRead(oscA2, 1)){ kick -= 0.01; if(kick < 0.1){ kick = 1; } } //oscilate if(bitRead(oscA2, 2)){ for(int i = 100; i>1; i--){ ta = !ta; if(ta){ audioOut(limiter(pot[1] >> 6)); } else{ audioOut(5); } delayMicroseconds((pot[0] >> 1)+1); } } //add empty time.. if(bitRead(oscA2, 3)){ //read voor break.. readAnalogs(); readAnalogs(); readAnalogs(); readAnalogs(); readAnalogs(); readAnalogs(); delay(pot[3] >> 2); } for(int i=0; i<((pot[2] >> 4)+1); i++){ byte t = i % 8; out = min((oscN[t]*kick), 128); analogWrite(11, min((out*3), 255)); audioOut(limiter(out)); tb = !tb; digitalWrite(6, tb); trigger(pot[2]+4); delayMicroseconds((pot[0] >> 1)+1); } ta = !ta; digitalWrite(5, ta); digitalWrite(4, LOW); digitalWrite(10, LOW); } inline void S1P08(){ //hypnotoad //reset vars if(prevSynth != butSel){ prevSynth = butSel; oscA2 = 0; oscB2 = 0; oscC2 = 0; oscA = 0; oscB = 0; ta = false; tb = false; tc = false; analogWrite(10, 0); analogWrite(5, 0); analogWrite(6, 0); analogWrite(7, 0); } //setup timers setupPWM(1); if(millis() - mlong[1] > ((pot[2] >> 1)+2)){ mlong[1] = millis(); sinAc++; sinAc %= max(pot[0] >> 2, 1); waveTable[sinAc] = random(100); tb = !tb; } if(millis() - mlong[0] > (pot[3]+128)){ mlong[0] = millis(); trigger(2); oscC2++; oscC2 %= ti; } ta = !ta; //oscillators oscA++; oscA %= max(pot[0] >> 2, 2); oscB++; oscB %= max(pot[0] >> 2, 3); out = (((waveTable[oscA])+(waveTable[oscB]))/3); //Serial.println(oscC2, DEC); analogWrite(11, (pot[4] >> 2)); analogWrite(10, oscC2*12); analogWrite(5, sinAc); analogWrite(6, (255 - sinAc)); digitalWrite(7, tc); audioOut(out); delayMicroseconds((((pot[1])+1)*sinC[oscC2])+1); } inline void S1P09(){ //melody bin seq //reset vars if(prevSynth != butSel){ prevSynth = butSel; BA = 0; BB = 0; tvol = 0; tb = true; } //setup timers setupPWM(0); if(triggerME(pot[4]+20, 1)){ BA = pot[2] >> 2; BB = pot[3] >> 2; waveGenartor(1023, ta); oscA2++; oscA2 %= 8; oscB2++; oscB2 %= 8; if(!(sinAc % 32)){ sinAc = 0; ta = !ta; } //no extra visuals digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); //tvol = 0.5; tb = true; //start trigger digitalWrite(13, HIGH); digitalWrite(4, HIGH); oscC2 = 30; } //countdwon trigger and set low.. oscC2--; oscC2 = max(oscC2, 0); if(!oscC2){ digitalWrite(13, LOW); digitalWrite(4, LOW); } //pitch oscA++; oscA %= (pot[0] >> 3)+2; oscB++; oscB %= (pot[1] >> 3)+2; if(bitRead(BA, oscA2) && bitRead(BB, oscB2)){ out = ((waveTable[oscA]*2)+(waveTable[oscB]*2))*(tvol/3); oscD--; } else if(bitRead(BA, oscA2)){ out = waveTable[oscA]*tvol; oscD++; } else if(bitRead(BB, oscB2)){ out = waveTable[oscB]*tvol; oscD++; } //oscD %= 255; oscD = max(min(oscD, 254), 1); analogWrite(11, oscD); //short attack.. if(tb){ if(tvol > 0.8){ tb = false; } tvol += (pot[4]+1)*0.00001;//0.005; } else{ tvol -= (pot[4]+1)*0.00001;//0.005; tvol = max(tvol, 0.0001); } audioOut(out); analogWrite(10, out); } inline void S1P10(){ //4/4 chipy attempt.. //reset vars if(prevSynth != butSel){ prevSynth = butSel; //no extra visuals digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); digitalWrite(11, HIGH); } //setup timers setupPWM(0); if(triggerME(pot[4]+20, 1)){ BA = pot[2] >> 2; BB = pot[3] >> 2; //waveGenartor(1023, ta, ta); waveGenartor(1023, 0); //reset volume decay tvol = 0.5; //bit read counters (probably only need one of these..). oscA2++; if(oscA2 > 7){ oscA2 = 0; } oscB2++; if(oscB2 > 7){ oscB2 = 0; } //change volume with length of long pitch change.. tvol2 = ((byte) (pot[1]))*0.0035; //add some delay (4/4 type) because the analog reads are to unstable.. oscD2++; if(oscD2 > (8 << (pot[1] >> 8))){ oscD2 = 0; } if(!oscD2){ for(byte i=0; i<8; i++){ //multiply and make into byte... melody generation.. oscL[i] = (byte) (pot[0]*(i+1)); oscL[i] += 1; } //melody change oscC2++; oscC2 %= 8; } //start trigger digitalWrite(13, HIGH); digitalWrite(4, HIGH); triggerDecay = 30; //attack time change.. kick = (oscL[oscA2] >> 2)+1; } //countdwon trigger and set low.. triggerDecay--; triggerDecay = max(triggerDecay, 0); if(!triggerDecay){ digitalWrite(13, LOW); digitalWrite(4, LOW); } //kick pitch down speed kick += 0.05; kick = min(kick, 255); //pitch //oscA++; oscA = cup(oscA, (byte) (kick)); //convert from float to byte //oscB++; oscB = cup(oscB, max((oscL[oscA2] >> 1), 2)); if(bitRead(BA, oscA2) && bitRead(BB, oscB2)){ fout = ((waveTable[oscA]*1.3)+(waveTable[oscB]*2))*(tvol/2); } else if(bitRead(BA, oscA2)){ fout = waveTable[oscA]*tvol; } else if(bitRead(BB, oscB2)){ fout = waveTable[oscB]*tvol; } tvol -= 0.0003; tvol = max(tvol, 0.0001); //oscD++; oscD = cup(oscD, 128); if(!oscD){ tb = !tb; } //oscC++; oscC = cup(oscC, oscL[oscC2]); //mix in with limiter out = (byte) min(((fout*2)+(waveTable[oscC]*tvol2))*0.5, 255); audioOut(out); analogWrite(10, out); } inline void S1P11(){ //clicks //reset vars if(prevSynth != butSel){ prevSynth = butSel; } //setup timers setupPWM(0); if(triggerME(pot[4]+20, 1)){ //add some delay (4/4 type) because the analog reads are to unstable.. oscA2++; oscA2 %= 16; if(!oscA2){ for(byte i=0; i<8; i++){ //multiply and make into byte... melody generation.. oscL[i] = max(((oscL[i]+((byte) (pot[2]*(i+1))))/2), 1); oscN[i] = max(((oscN[i]+((byte) (pot[3]*(i+1))))/2), 1); } } //select pitch oscB2++; oscB2 %= pot[0] >> 7; oscC2++; oscC2 %= pot[1] >> 7; //no extra visuals digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); tvol = 2; //start trigger digitalWrite(13, HIGH); digitalWrite(4, HIGH); triggerDecay = 30; } //countdwon trigger and set low.. triggerDecay--; triggerDecay = max(triggerDecay, 0); if(!triggerDecay){ digitalWrite(13, LOW); digitalWrite(4, LOW); } //pitch oscA++; oscA %= (oscL[oscB2] >> 2)+1; oscB++; oscB %= (oscN[oscC2] >> 2)+1; //fade out tvol *= 0.9; tvol = max(tvol, 0.0001); tvol = min(tvol, 2); if(!oscA || !oscB){ tc = !tc; if(tc){ out = 100*tvol; analogWrite(11, (out % 255)); } else{ out = 0; } } audioOut(out); analogWrite(10, out); } inline void S1P12(){ //2 voice arpegiator with fade //reset vars if(prevSynth != butSel){ prevSynth = butSel; digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); digitalWrite(11, HIGH); } //setup timers setupPWM(0); if(triggerME(pot[4]+20, 1)){ waveGenartor(pot[1], 0); //add some delay (4/4 type) because the analog reads are to unstable.. oscA2++; oscA2 = cup(oscA2, 8); if(!oscA2){ for(byte i=0; i<8; i++){ //multiply and make into byte... melody generation.. oscL[i] = max(((oscL[i]+((byte) (pot[2]*(i+1))))/2), 1); oscN[i] = max(((oscN[i]+((byte) (pot[3]*(i+1))))/2), 1); } } //select pitch oscB2++; oscB2 = cup(oscB2, pot[0] >> 7); oscC2++; oscC2 = cup(oscC2, pot[1] >> 7); //tvol = 2; tb = true; //start trigger digitalWrite(13, HIGH); digitalWrite(4, HIGH); triggerDecay = 30; } //countdwon trigger and set low.. triggerDecay--; triggerDecay = max(triggerDecay, 0); if(!triggerDecay){ digitalWrite(13, LOW); digitalWrite(4, LOW); } //short attack.. if(tb){ if(tvol >= 2){ tb = false; } tvol += 0.03; } else{ tvol -= 0.0009; tvol = max(tvol, 0.0001); } //pitch oscA++; oscA = cup(oscA, max((oscL[oscB2]>>1), 2)); oscB++; oscB = cup(oscB, max((oscN[oscC2]>>1), 2)); //mix out = min(((waveTable[oscA]*tvol)+(waveTable[oscB]*tvol))/4, 255); audioOut(out); //visuals analogWrite(10, min((out*2), 255)); if(out > 50){ digitalWrite(5, HIGH); } else{ digitalWrite(5, LOW); } } inline void S1P13(){ //setup timers //reset vars if(prevSynth != butSel){ prevSynth = butSel; triggerDecay = 1; } setupPWM(0); //extra reads //pot[5] = analogRead(5); oscA++; oscA = cup(oscA, 8); oscL[oscA] = max(((oscL[oscA]+((byte) (pot[0]*(oscA+1))))>>1), 1); //select sounds byte tpot = pot[1] >> 8; byte tpot2 = pot[2] >> 8; //set random or not if((pot[3] >> 8) == 0){ } else if((pot[3] >> 8) == 1){ tpot = random(4); } else if((pot[3] >> 8) == 2){ tpot2 = random(4); } else{ tpot = random(4); tpot2 = random(4); } //effect led //analogWrite(11, (255 - (pot[4] >> 2))); oscC2 = cup(oscC2, 4); analogWrite(11, (min(oscL[oscC2] >> 1, 255))); oscD2 = (pot[4]>>2)+1; //send trigger triggerDecay = !triggerDecay; digitalWrite(13, triggerDecay); digitalWrite(4, triggerDecay); if(tpot == 0){ //1st one empty } else if(tpot == 1){ //no fade, 8 pitches for(byte j=0; j<2; j++){ for(byte i=0; i<255; i++){ ta = !ta; delayMicroseconds((oscL[j]+1)+oscD2); if(ta){ audioOut(25); bitWrite(PORTB, 2, 1); } else{ audioOut(0); bitWrite(PORTB, 2, 0); } } } } else if(tpot == 2){ //no fade, 8 pitches for(byte j=0; j<4; j++){ for(byte i=0; i<255; i++){ ta = !ta; oscB++; oscB = cup(oscB, 35); delayMicroseconds((oscL[j]+1)+oscD2); if(ta){ audioOut(oscB); digitalWrite(5, HIGH); } else{ audioOut(35-oscB); digitalWrite(5, LOW); } } //if((analogRead(5) >> 6) != 13){break;} } } else if(tpot == 3){ //fade in and out, 8 pitches for(byte j=0; j<4; j++){ tvol = 0; for(byte i=0; i<255; i++){ ta = !ta; tvol += 0.0025; delayMicroseconds((oscL[j+4]+1)+oscD2); if(ta){ audioOut(40*tvol); digitalWrite(6, HIGH); } else{ audioOut(0); digitalWrite(6, LOW); } } for(byte i=0; i<255; i++){ ta = !ta; tvol -= 0.0025; tvol = max(tvol, 0.001); delayMicroseconds((oscL[j]+1)+oscD2); if(ta){ audioOut(40*tvol); bitWrite(PORTB, 2, 1); } else{ audioOut(0); bitWrite(PORTB, 2, 0); } } //if((analogRead(5) >> 6) != 13){break;} } } //send trigger triggerDecay = !triggerDecay; digitalWrite(13, triggerDecay); digitalWrite(4, triggerDecay); if(tpot2 == 0){ //1st one empty } else if(tpot2 == 1){ //just a pitch for(byte j=0; j<2; j++){ for(byte i=0; i<((byte)(oscL[oscA]>>2)); i++){ ta = !ta; delayMicroseconds((oscL[oscA]+1)+oscD2); if(ta){ audioOut(16); bitWrite(PORTB, 2, 1); } else{ audioOut(0); bitWrite(PORTB, 2, 0); } } //if((analogRead(5) >> 6) != 13){break;} } } else if(tpot2 == 2){ // for(byte j=0; j<2; j++){ tvol = 0; for(byte i=0; i<255; i++){ tvol += 0.0025; ta = !ta; oscC++; oscC = cup(oscC, 3); oscB++; oscB = cup(oscB, 35); delayMicroseconds((oscL[oscA]+1)+oscD2); if(ta){ bitWrite(PORTB, 2, 1); audioOut((oscB*tvol)*oscC); } else{ bitWrite(PORTB, 2, 0); audioOut(0); } } //if((analogRead(5) >> 6) != 13){break;} } } else if(tpot2 == 3){ for(byte j=0; j<3; j++){ for(byte i=0; i<255; i++){ ta = !ta; delayMicroseconds((oscL[oscA]+1)+oscD2); audioOut(random(40)); bitWrite(PORTB, 2, ta); } } } } inline void S1P14(){ //bas kick and hh noise.. //reset vars if(prevSynth != butSel){ prevSynth = butSel; digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); digitalWrite(11, HIGH); } //setup timers setupPWM(0); if(triggerME(pot[4]+20, 1)){ BA = pot[2] >> 2; BB = pot[3] >> 2; waveGenartor(1023, ta); //crosfade volume.. tvol = min(pot[1]*0.001, 0.6); tvol2 = min((1023-pot[1])*0.001, 0.6); //bit read counters seqCount++; seqCount %= 8; //phasing.. if(!(sinAc % 32)){ sinAc = 0; ta = !ta; } //start trigger digitalWrite(13, HIGH); digitalWrite(4, HIGH); triggerDecay = 30; //attack time change.. kick = (pot[0] >> 2)+1; } //countdwon trigger and set low.. triggerDecay--; triggerDecay = max(triggerDecay, 0); if(!triggerDecay){ digitalWrite(13, LOW); digitalWrite(4, LOW); } //kick pitch down speed kick += 0.05; kick = min(kick, 255); //volume tvol -= 0.001; tvol = max(tvol, 0.0001); tvol2 -= 0.003; tvol2 = max(tvol2, 0.0001); //pitch oscA++; oscA %= (byte) (kick); //convert from float to byte oscB++; oscB %= (byte) (tvol2); //convert from float to byte //reset volume if no beat A if(!bitRead(BA, seqCount)){ tvol = 0.001; //analogWrite(11, random(255)); oscD += (random(10) - 5); oscD %= 256; analogWrite(11, oscD); } //reset volume if no beat B if(!bitRead(BB, seqCount)){ tvol2 = 0.001; digitalWrite(11, LOW); } //mix out = (waveTable[oscA]*tvol)+(random(240)*tvol2)/2; audioOut(out); analogWrite(10, min((out*8), 255)); } inline void S1P15(){ //square wave synth.. //reset vars if(prevSynth != butSel){ prevSynth = butSel; oscA2 = 10; oscB2 = 10; oscC2 = 10; analogWrite(10, 0); } setupPWM(0); //oscillators oscA++; oscA %= (pot[0]>>4)+8; oscB++; oscB %= (pot[0]>>4)+9; oscC++; oscC %= (pot[0]>>4)+10; //inverse cycle if(!oscA){ ta = !ta; } if(!oscB){ tb = !tb; } if(!oscC){ tc = !tc; } //reset output volume out = 0; //make wave form, lower volume on low pitch if(ta){ out += 28; } if(tb){ out += 28; } if(tc){ out += 28; } if(triggerME(pot[4]+10, 1)){ oscA2++; oscA2 %= (pot[2]>>7)+1; for(byte i=0; i<8; i++){ //multiply and make into byte... melody generation.. reverse for low pitch on no arp.. oscL[i] = 255 - ((byte) ((pot[1]>>2)*((i+1)))); } //start trigger digitalWrite(13, HIGH); digitalWrite(4, HIGH); triggerDecay = 30; } //countdwon trigger and set low.. triggerDecay--; triggerDecay = max(triggerDecay, 0); if(!triggerDecay){ digitalWrite(13, LOW); digitalWrite(4, LOW); } out += pot[3]>>4; out = constrain(out, 1, 100); audioOut(out); //visuals digitalWrite(7, ta); digitalWrite(6, tb); digitalWrite(5, tc); analogWrite(11, oscL[oscA2]); //overall pitch delayMicroseconds(max(oscL[oscA2], 1)); } ///////// //other// ///////// /* void waveGenartor(int inpA, byte inpB){ static byte decayA = 0; sinAc = cup(sinAc, 256); sinAc2 = cup(sinAc2, 32); decayA = cup(decayA, (inpA >> 5)+1); waveTable[sinAc] = (255*sinA[decayA])*sinA[sinAc2]; } */ void waveGenartor(int inpA, byte inpB){ static byte decayA = 0; sinAc++; sinAc %= 256; sinAc2++; sinAc2 %= 32; decayA++; decayA %= (inpA >> 5)+1; waveTable[sinAc] = (255*sinA[decayA])*sinA[sinAc2]; } inline void waveGenartor1(int inpA){ octaver = cup(octaver, inpA); if(!octaver){ sinAc2 = cup(sinAc2, 31); } sinAc = cup(sinAc, 255); octaver = cup(octaver, (128-inpA)); if(!octaver){ decayA = cup(decayA, 31); } waveTable[sinAc] = (220*sinA[decayA])*sinA[sinAc2]; } //nice smooth sound!! with droneL0 void waveGenartor4(int inpA, int inpD){ octaver = cup(octaver, inpD); if(!octaver){ sinAc2 = cup(sinAc2, 32); } sinAc = cup(sinAc, inpD>>4); //stange but it sounds nice.. decayA = cup(decayA, (inpA >> 5)+1); waveTable[sinAc] = (255*sinA[decayA])*sinA[sinAc2]; } void waveGenartor2(int inpA){ sinAc = cup(sinAc, 512); decayA = cup(decayA, 32); waveTable[sinAc] = constrain((inpA*sinA[decayA]), 2, 128); } /* //read pots, 1 at a time inline void readAnalogs(){ static byte potc = 0; static unsigned int potsmooth[7]; potc = cupb(potc, 6); //walk throu all pots if(!midibool){ if(sendMIDI){ potsmooth[potc] += 1023 - analogRead(potc); if(!potc){ mcounter = cupb(mcounter, 8); } if(!mcounter){ pot[potc] = potsmooth[potc]>>3; potsmooth[potc] = 0; if(potp[potc]>>3 != pot[potc]>>3){ potp[potc] = pot[potc]; midi.sendControlChange(1, potc+20, 127-(potp[potc]>>3)); } } } else{ pot[potc] = 1023 - analogRead(potc); } } else{ //potm[potc] = 1023 - analogRead(potc); 1023 - analogRead(potc); } } */ //read pots, 1 at a time inline void readAnalogs(){ static byte potc = 0; if(!midibool){ potc = cup(potc, 6); //pot[potc] = analogRead(potc); pot[potc] = 1023 - analogRead(potc); } } byte audioOut(byte signal){ //Serial.println(signal>>(pot[6]>>7), DEC); //delay(50); //analogWrite(9, constrain(signal>>(pot[6]>>7), 4, s172)); analogWrite(9, min(signal>>(pot[6]>>7), 180)); } //send trigger void trigger(byte inp){ volatile static int tCount = 0; if(!externalTrigger){ tCount = cup(tCount, inp); digitalWrite(13, tCount); digitalWrite(4, tCount); } } void triggerNormal(){ if(inLoop){ //set external trigger to true if there is a trigger signal.. externalTrigger = true; //set trigger to active, see above triggerActive = true; } } void triggerOut(){ volatile static boolean triggerSignal = 1; if(triggerSignal){ triggerNormal(); } triggerSignal = !triggerSignal; digitalWrite(13, triggerSignal); digitalWrite(4, triggerSignal); } //if trigger use trigger, otherwise use millis.. boolean triggerME(int mil, byte arr){ boolean retVal = false; if(!externalTrigger){ if(millis() - mlong[arr] > mil){ mlong[arr] = millis(); retVal = true; } else{ retVal = false; } } else if(triggerActive){ //reset trigger status, for trigger below triggerActive = false; retVal = true; } return retVal; } boolean triggerState(){ if(triggerActive){ triggerActive = false; return true; } else{ return false; } } void resetWavetable(){ for(int i=0; i<512; i++){ waveTable[i] = 0; } } void sendMidi(byte noteIn, byte volume, byte channel){ static byte noteHolder[3]; if(noteIn != noteHolder[channel]){ midi.sendNoteOff(channel, noteHolder[channel], 0); noteHolder[channel] = noteIn; midi.sendNoteOn(channel, noteIn, volume); } } void sendMidiNoOne(byte noteIn, byte volume){ static int noteHolder; midi.sendNoteOff(midichannel, noteHolder, 0); noteHolder = noteIn; midi.sendNoteOn(midichannel, noteIn, volume); } inline static int cup(int a, int b){ a++; if(a >= b){ a = 0; } return a; } inline static byte cupb(byte a, byte b){ a++; if(a >= b){ a = 0; } return a; } //setup PWMs: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235060559 void setupPWM(byte inp){ if(inp != prevstatePWM1){ prevstatePWM1 = inp; if(inp == 0){ cli(); TCCR0B = TCCR0B & 0b11111000 | 0x03; sei(); } else if(inp == 1){ cli(); TCCR0B = TCCR0B & 0b11111000 | 0x01; sei(); } } } /* void setupPWMS(byte inp, byte inpB){ if(inpB != prevstatePWM2){ prevstatePWM2 = inpB; if(inp == 0){ cli(); TCCR0B = TCCR0B & 0b11111000 | inpB; sei(); }else if(inp == 1){ cli(); TCCR1B = TCCR1B & 0b11111000 | inpB; sei(); }else if(inp == 2){ cli(); TCCR2B = TCCR2B & 0b11111000 | inpB; } } } */ inline byte limiter(byte inp){ return constrain(inp, 0, 60); } void startupSound(){ //wait tone for(int i=10000; i>0; i--){ oscA++; oscA %= 32; out = sinA[oscA]*16; audioOut(out); delayMicroseconds(68); } //dial for(int j=8; j>0; j--){ byte rpitch = random(1, 50); int rpitcC = (50 - rpitch)*50; for(unsigned int i=rpitcC; i>0; i--){ oscA++; oscA %= 32; out = sinA[oscA]*35; audioOut(out); delayMicroseconds(rpitch); } delay(100); } delay(1000); //part 2.. oscA = 0; for(int i=20000; i>0; i--){ oscA++; oscA %= 32; out = sinA[oscA]*2; audioOut(out); delayMicroseconds(1); } for(int i=2000; i>0; i--){ oscA++; oscA %= 32; out = sinA[oscA]*2; audioOut(out); delayMicroseconds(70); } oscA = 0; for(int j=7; j>0; j--){ for(int i=96; i>0; i--){ oscA++; oscA %= 32; out = sinA[oscA]*12; audioOut(out); delayMicroseconds(1); } delay(6); } for(int i=200; i>0; i--){ oscA++; oscA %= 32; out = sinA[oscA]*20; audioOut(out); delayMicroseconds(1); } for(int j=10; j>0; j--){ byte tv = random(4, 20); for(int k=20; k>0; k--){ for(int i=96; i>0; i--){ oscA++; oscA %= 32; out = sinA[oscA]*tv; audioOut(out); delayMicroseconds(1); } } } //noise for(unsigned int i=3000; i>0; i--){ analogWrite(9, random(14)); delayMicroseconds(1); } tvol = 20; for(unsigned int i=3000; i>0; i--){ tvol += 0.005; oscA++; oscA %= 8; out = (sinA[oscA]*30)+random(tvol)/2; audioOut(out); delayMicroseconds(1); } tvol /= 2; for(unsigned int i=600; i>0; i--){ oscA++; oscA %= 8; out = (sinA[oscA]*30)+random(tvol)/2; audioOut(out); delayMicroseconds(1); } tvol = 0; for(unsigned int i=1000; i>0; i--){ tvol += 0.002; analogWrite(9, (random(20)*tvol)); delayMicroseconds(1); } } void resetVisSetup(){ digitalWrite(5, 0); digitalWrite(6, 0); digitalWrite(7, 0); //analogWrite(9, 32); digitalWrite(10, 0); ADCSRA &= ~B111; ADCSRA |= B00000111; setupPWM(1); } inline void modeChange(){ if(!bitRead(PINB, 0) || changeMode){ changeMode = false; prevSynth = 255; prevstatePWM1 = 255; prevstatePWM2 = 255; typeSwitch = !typeSwitch; while(!digitalRead(8)){ } if(typeSwitch){ cli(); TCCR0B = TCCR0B & 0b11111000 | 0x03; TCCR1B = TCCR1B & 0b11111000 | 0x01; TCCR2B = TCCR2B & 0b11111000 | 0x01; sei(); } else{ cli(); TCCR0B = TCCR0B & 0b11111000 | 0x01; TCCR1B = TCCR1B & 0b11111000 | 0x01; TCCR2B = TCCR2B & 0b11111000 | 0x01; sei(); } ADCSRA &= ~B111; ADCSRA |= B00000111; externalTrigger = false; midi.sendStart(); seqCount = 0; delay(100); } }