// HSS Effects // Gijs Gieskes 2009 // http://gieskes.nl //buffer mems #define mem 500 //168 is 500, 328 is 1000. byte buffer[mem]; //lowpass filter int lowV = 131; unsigned long lowMill = 0; //SH float SHrv = 0; unsigned long SHmil = 0; byte keys[5] = {0,0,0,0,0}; byte keysp[5] = {0,0,0,0,0}; //analog int analogInput = 0; byte anaCount = 0; int anaVs[4]; //modulator unsigned long Mmill = 0; boolean mhl = true; //digital delay int arCounD = 0; //audio out variable long S1out; //synth volume int length = 0; void setup() { analogReference(INTERNAL); //speed up PWM on pin 9 and 10: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235060559 TCCR1B = TCCR1B & 0b11111000 | 0x01; //audio output pinMode(9, OUTPUT); //buttons pins pinMode(1, INPUT); pinMode(3, INPUT); pinMode(4, INPUT); pinMode(5, INPUT); pinMode(6, INPUT); pinMode(7, INPUT); pinMode(8, INPUT); digitalWrite(1, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, HIGH); digitalWrite(6, HIGH); digitalWrite(7, HIGH); digitalWrite(8, HIGH); Serial.begin(9600); } void loop(){ //digital Reads readButs(); //analogReads S1out = analogRead(4) >> 2; //volume change analogR(); //Effacts digitalDelay(); looper(); modulator(); distortion(); SHgate(); lowpass(); //write to output aWrite(S1out); delayMicroseconds(map(anaVs[1], 0, 1023, 2000, 1)); } void readButs(){ boolean b8 = digitalRead(8); for(byte i=0; i<5; i++){ if(digitalRead(i+3) == LOW){ keys[i] = 1; }else{ keys[i] = 0; } if(b8 == LOW && keys[i] == 1){ keysp[i] = 1; }else if(b8 == LOW){ keysp[i] = 0; } } } void modulator(){ if(keys[3] == 1 || keysp[3] == 1){ unsigned long l = map(anaVs[2], 0, 1023, 50000, 0); if(micros() - Mmill > l){ Mmill = micros(); mhl = !mhl; } if(mhl){ S1out = 131; } } } void lowpass(){ if(keys[1] == 1 || keysp[1] == 1){ byte s = 2; if(S1out < lowV && S1out < lowV-s){ lowV -= s; }else if(S1out > lowV && S1out > lowV+s){ lowV += s; } S1out = ((lowV-131) * 4.5) + 131; } } void digitalDelay(){ if(keys[0] == 1 || keysp[0] == 1){ length = map(anaVs[2], 0, 1023, 1, (mem - 2)); arCounD++; if(arCounD > (mem-1)){ arCounD = 0; } int countm = (arCounD+length) % (mem - 1); buffer[arCounD] = (S1out+buffer[countm]) >> 1; S1out = buffer[arCounD]; } } void looper(){ if(digitalRead(1) == LOW){ int l = map(anaVs[3], 0, 1023, (mem-1), 4); arCounD++; if(arCounD > l){ arCounD = 0; } S1out = buffer[arCounD]; } } void distortion(){ if(keys[2] == 1 || keysp[2] == 1){ S1out -= 131; S1out *= map(anaVs[3], 0, 1023, 1, 3); S1out += 131; S1out = constrain(S1out, 90, 170); } } void SHgate(){ int l = map(anaVs[2], 0, 1023, 700, 0); if(millis() - SHmil > l){ SHmil = millis(); SHrv = random(1,100)*0.00999; } if(keys[4] == 1 || keysp[4] == 1){ S1out -= 131; S1out *= SHrv; S1out += 131; S1out = constrain(S1out, 90, 165); } } //output to audio void aWrite(byte i){ i = constrain(i, 0, 255); analogWrite(9,i); } //analog Reads void analogR(){ anaCount++; if(anaCount > 3){ anaCount = 1; } anaVs[anaCount] = analogRead(anaCount); }