Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //todo:
- //!poti hook-up!
- //EnvelopeGenerator with trigger in that actually sends a control value (dc2) to the filter (dc2 * 8184)
- //Envelopegenerator Release control on page 2 controlled by stationKnob
- //!Chord selection!
- //
- //
- //stationKnob = A9
- //stationCV = A8
- //startKnob = A7
- //startCV = A6
- //tasterButton = Pin 8
- //triggerCV = Pin 9
- //Output = dac1
- #include <synth_waveform.h>
- #include <Audio.h>
- #include <Wire.h>
- #include <SPI.h>
- #include <SD.h>
- #include <SerialFlash.h>
- // GUItool: begin automatically generated code
- AudioSynthWaveform waveform3; //xy=83.75000762939453,347.0000081062317
- AudioSynthWaveform waveform1; //xy=86.7500114440918,251.0000057220459
- AudioSynthWaveform waveform2; //xy=87.75000762939453,300.0000066757202
- AudioSynthWaveform waveform4; //xy=96.75000762939453,397.00000190734863
- AudioMixer4 mixer1; //xy=246.75002670288086,288.00000381469727
- AudioFilterStateVariable filter1; //xy=406.75000381469727,250.00000381469727
- AudioSynthWaveformDc dc1; //xy=475,536.25
- AudioFilterStateVariable filter2; //xy=547,195
- AudioMixer4 mixer2; //xy=574.5000152587891,319.00000953674316
- AudioEffectWaveFolder wavefolder1; //xy=741.25,382.5
- AudioEffectBitcrusher bitcrusher1; //xy=772.2500190734863,272.2500333786011
- AudioEffectDelay delay1; //xy=942.0001220703125,523.5000152587891
- AudioMixer4 mixer3; //xy=946.0000267028809,340.0000333786011
- AudioFilterStateVariable filter3; //xy=946.6000061035156,415
- AudioMixer4 mixer5; //xy=1223.7500343322754,251.25000953674316
- AudioOutputAnalog dac1; //xy=1386.7500381469727,316.00000858306885
- AudioConnection patchCord1(waveform3, 0, mixer1, 2);
- AudioConnection patchCord2(waveform1, 0, mixer1, 0);
- AudioConnection patchCord3(waveform2, 0, mixer1, 1);
- AudioConnection patchCord4(waveform4, 0, mixer1, 3);
- AudioConnection patchCord5(mixer1, 0, filter1, 0);
- AudioConnection patchCord6(filter1, 0, filter2, 0);
- AudioConnection patchCord7(dc1, 0, wavefolder1, 1);
- AudioConnection patchCord8(filter2, 0, mixer2, 0);
- AudioConnection patchCord9(mixer2, 0, wavefolder1, 0);
- AudioConnection patchCord10(wavefolder1, bitcrusher1);
- AudioConnection patchCord11(bitcrusher1, 0, mixer3, 0);
- AudioConnection patchCord12(delay1, 0, filter3, 0);
- AudioConnection patchCord13(mixer3, delay1);
- AudioConnection patchCord14(mixer3, 0, mixer5, 0);
- AudioConnection patchCord15(filter3, 2, mixer3, 1);
- AudioConnection patchCord16(mixer5, dac1);
- AudioControlSGTL5000 sgtl5000_1; //xy=822,662
- // GUItool: end automatically generated code
- //Constants
- const int tasterPin = 8; //taster at Pin 8
- const int triggerPin = 9; //Jack for Gate at Pin 9
- const int L1Pin = 3; // LED1 at Pin 3
- const int L2Pin = 4; // LED2 at Pin 4
- const int L3Pin = 5; // LED3 at Pin 5
- const int L4Pin = 6; // LED4 at Pin 6
- const int L5Pin = 11; // LED5 at Pin 11
- //Variables
- int mode = 0; // Variable for case switching
- int tasterState = 0; // Variable to save tasterstate
- int triggerState = 0; // Variable to save triggerstate
- float Note2[8] = {1.25992, 1.18920, 1.25992, 1.33484}; //Frequency proportion to 2nd note
- float Note3[8] = {1.49830, 1.49830, 1.49830, 1.49830}; //Frequency proportion to 3rd note
- float Note4[8] = {1.88774, 1.88774, 1.88775, 1.88775}; //Frequency proportion to 4th note
- float noteArray[8] = {0, 1, 2, 3, 4, 5, 6, 7}; //Notenarray for "NoteN"-array selection
- float Hertz[61] = {65.4064, 69.957, 73.41619, 77.78175, 82.40689, 87.30706, 92.49861, 97.99886, 103.8262, 110.0000, 116.5409, 123.4708,
- 130.8128, 138.5913, 146.8324, 155.5635, 164.8138, 174.6141, 184.9972, 195.9977, 207.6523, 220.0000, 233.0819, 246.9417,
- 261.6256, 277.1826, 293.6648, 311.1270, 329.6276, 349.2282, 369.9944, 391.9954, 415.3047, 440.0000, 466.1638, 493.8833,
- 523.2511, 554.3653, 587.3295, 622.2540, 659.2551, 698.4565, 739.9888, 783.9909, 830.6094, 880.0000, 932.3275, 987.7666,
- 1046.502, 1108.731, 1174.659, 1244.508, 1318.510, 1396.913, 1479.978, 1567.982, 1661.219, 1760.000, 1864.655, 1975.533, 2093.005
- };
- void setup() {
- Serial.begin(19200); // USB is always 12 or 480 Mbit/se
- //setting up the audio components
- //===========================================================================
- //analogReadResolution(12);
- AudioMemory(200);
- waveform1.begin(WAVEFORM_SAWTOOTH);
- waveform1.amplitude(1);
- waveform1.frequency(65.41);
- waveform1.pulseWidth(0.15);
- waveform2.begin(WAVEFORM_SAWTOOTH);
- waveform2.amplitude(1);
- waveform2.frequency(65.41);
- waveform2.pulseWidth(0.15);
- waveform3.begin(WAVEFORM_SAWTOOTH);
- waveform3.amplitude(1);
- waveform3.frequency(65.41);
- waveform3.pulseWidth(0.15);
- waveform4.begin(WAVEFORM_SAWTOOTH);
- waveform4.amplitude(1);
- waveform4.frequency(65.41);
- waveform4.pulseWidth(0.15);
- //mixer1 to controll Waveform1 with stationKnob; Waveform2-4 with startKnob on page 1
- mixer1.gain(0, 0.25);
- mixer1.gain(1, 0.25);
- mixer1.gain(2, 0.25);
- mixer1.gain(3, 0.25);
- /*
- envelope1.delay(0);
- envelope1.attack(20);
- envelope1.hold(0);
- envelope1.decay(5000);
- envelope1.sustain(0.7);
- envelope1.release(500);
- */
- //dc2.amplitude(0);
- //filter1 is controlled by the stationCV input
- filter1.frequency(16000); //set initial Filter1 freq to 16000Hz
- filter1.resonance(0); //set Resonance to 0
- //filter2 is controlled by the stationKnob on page 0
- filter2.frequency(16000); //set initial Filter2 freq to 16000Hz
- filter2.resonance(0); //set Resonance to 0
- //mixer2 is just there, no need for it actually
- mixer2.gain(0, 1); //set Mixer2(Channel, Gain) (0-3, 0-1)
- mixer2.gain(1, 1);
- //dc1 for wavefolder input controlled by stationKnob on page 3
- dc1.amplitude(0.05); //set dc1 for Wavefolder Input
- //bitcrusher1 controlled by startKnob on page 3
- bitcrusher1.bits(16);
- bitcrusher1.sampleRate(44100);
- //delay1 time controlled by stationKnob; feedback controlled by startKnob on page 4
- delay1.delay(0, 3); //set Delay(OutChannel, saved Samples) (0-7, 3-449*) *maximum
- //filter3 HighPassfilter to get rid of the muddy sound in feedbackloop
- filter3.frequency(200); //set initial Filter3 freq to 16000Hz
- filter3.resonance(0); //set Resonance to 0
- //mixer3 for feedback controlled by startKnob on page 4
- mixer3.gain(0, 1); //setze Mixer2(Kanal, Gain) (0-3, 0-1)
- mixer3.gain(1, 0);
- //mixer4.gain(1, 0);
- //mixer4.gain(0, 0);
- //mixer5 again just a mixer to pass audio thru
- mixer5.gain(0, 0.5);
- //mixer5.gain(1, 0.5);
- //setting up the audio components DONE!!
- //===========================================================================
- //setting up the Pins as In´s n Out´s
- //============================================================================
- pinMode(tasterPin, INPUT); //taster is input
- pinMode(triggerPin, INPUT); //trigger is input
- pinMode(L1Pin, OUTPUT); // Set LEDPin as output
- pinMode(L2Pin, OUTPUT); // Set LEDPin as output
- pinMode(L3Pin, OUTPUT); // Set LEDPin as output
- pinMode(L4Pin, OUTPUT); // Set LEDPin as output
- pinMode(L5Pin, OUTPUT); // Set LEDPin as output
- }
- void loop() {
- tasterState = digitalRead(tasterPin); //read tasterPin and set tasterState
- triggerState = digitalRead(triggerPin); //read triggerPin and set triggerState
- int startCV = analogRead(A8);
- int startKnob = analogRead(A7); //lies Analog7 und setze auf startKnob
- int stationKnob = analogRead(A9); //lies Analog9 und setze auf stationKnob
- int stationCV = analogRead(A6); //lies Analog6 und setze auf stationCV
- /*variables to handle each´s page last knob position
- int filterCutoff;
- int filterCutoffOld = 512;
- int resoNance = 0;
- int resoNanceOld = 0;
- int volume1 = 1023;
- int volume1Old = 1023;
- int volume234 = 1023;
- int volume234Old = 1023;
- //int chordSelect = 0;
- //int chordSelectOld = 0;
- int wfSelect = 439;
- int wfSelectOld = 439;
- int waveFolder = 307;
- int waveFolderOld = 307;
- int bitCrusher = 1023;
- int bitCrusherOld = 1023;
- int delayTime = 0;
- int delayTimeOld = 0;
- int feedBack = 0;
- int feedBackOld = 0;
- */
- //1V/Octave works, though only till 3.3V so its a 40 Note Range beginning from C1 65.4064Hz Hertzarray goes to 60, so you could transpose those 40 Notes :)
- //PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
- int hertzseriell = map(startCV, 0, 1023, 0, 40);
- waveform1.frequency(Hertz[hertzseriell]); //WF1 plays rootnote
- waveform2.frequency(Hertz[hertzseriell] * Note2[0]); //WF2 plays rootnote * Frequencyproportionn from "Note2"-array
- waveform3.frequency(Hertz[hertzseriell] * Note3[0]); //WF3 plays rootnote * Frequencyproportionn from "Note3"-array
- waveform4.frequency(Hertz[hertzseriell] * Note4[0]); //WF4 plays rootnote * Frequencyproportionn from "Note4"-array
- //PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
- //int cutoff = map(stationCV, 0, 1023, 65.41, 8184); //map stationCV to cutoff
- //filter1.frequency(cutoff); //Filter1 filters cutoff
- filter1.frequency(map(stationCV, 0, 1023, 0, 8184));
- if (tasterState == HIGH) //when tasterState is High
- {
- mode++; //count case mode + 1
- delay(200); //delay zur Entprellung
- }
- digitalWrite(L5Pin, triggerState );
- digitalWrite(L1Pin, LOW); //Led 1 aus
- digitalWrite(L2Pin, LOW); //Led 2 aus
- digitalWrite(L3Pin, LOW); //Led 3 aus
- digitalWrite(L4Pin, LOW); //Led 4 aus
- //begin of page switching and what happens in each page
- //==========================================================================
- switch (mode) {
- case 0: //Filter5 + Resonance
- digitalWrite(L1Pin, LOW); //Led 1 aus
- digitalWrite(L2Pin, LOW); //Led 2 aus
- digitalWrite(L3Pin, LOW); //Led 3 aus
- digitalWrite(L4Pin, LOW); //Led 4 aus
- //nachdem ich nach dem Durchschalten der cases 0-4 wieder bei 0 gelandet bin
- //soll die nachstehende funktion erst dann "aktiv" werden, wenn das Poti (aktueller Wert)
- //filterCutoffOld über/unterschritten wurde (größer/kleiner Vergleich?)
- filter2.frequency((float)map(stationKnob, 0, 1023, 65.41, 8184)); //Filter1 filters cutoff
- //nach einem erneuten Tastendruck in das nächste Case soll der aktuelle Wert als filterCutoffOld
- //übernommen und gespeichert werden.
- //diese abfrage soll in jedem case für beide Potentiometer angewendet werden.
- filter2.resonance((float)map(startKnob, 0, 1023, 0, 5)); //controls Resonance
- break;
- case 1: //Volume1 + 2,3,4
- //das eigentliche Abspeichern der vorigen Werte wird wohl hier passieren
- digitalWrite(L1Pin, HIGH); //Led 1 an
- mixer1.gain(0, ((float)stationKnob / 3069)); //Gain Mixer1 Eingang 0
- mixer1.gain(1, ((float)startKnob / 3069)); //Gain Mixer1 Eingang 1
- mixer1.gain(2, ((float)startKnob / 3069)); //Gain Mixer1 Eingang 2
- mixer1.gain(3, ((float)startKnob / 3069)); //Gain Mixer1 Eingang 3
- break;
- case 2: //Chord
- digitalWrite(L2Pin, HIGH); //Led 2 an
- noteArray[map(stationKnob, 0, 1023, 0, 7)]; //stationKnob stores value 0-7 into noteArray
- // Serial.print(noteArray);
- //note3[map(stationKnob, 0, 1023, 0, 7)]; //stationKnob stores value 0-7 into noteArray
- //note4[map(stationKnob, 0, 1023, 0, 7)]; //stationKnob stores value 0-7 into noteArray
- waveform1.begin(map(startKnob, 0, 1023, 0, 12)); //waveform selection with startKnob
- waveform2.begin(map(startKnob, 0, 1023, 0, 12)); //waveform selection with startKnob
- waveform3.begin(map(startKnob, 0, 1023, 0, 12)); //waveform selection with startKnob
- waveform4.begin(map(startKnob, 0, 1023, 0, 12)); //waveform selection with startKnob
- break;
- case 3: //wavefolder + bitcrusher
- digitalWrite(L3Pin, HIGH); //Led 3 an
- dc1.amplitude((float) stationKnob / 1023); //dc-value 0-1 for Wavefolder controlled by stationKnob
- bitcrusher1.sampleRate(map(startKnob, 0, 1023, 1, 44100)); //samplerate 1-44100Hz controlled by startKnob
- break;
- case 4: //delaytime + feedback
- digitalWrite(L4Pin, HIGH); //Led 4 aus
- delay1.delay(0, map(stationKnob, 0, 1023, 3, 200)); //delaytime 3-200ms controlled by stationknob
- mixer3.gain(1, ((float)startKnob / 1023)); //delayfeedback 0-1 controlled by startknob
- break;
- default: //next taster push brings us back to page 0
- mode = 0;
- }
- //end of page switching
- //==================================================================================================
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement