Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //todo:
- //poti hook-up
- //!1V/Octave-tracking!
- //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 <MozziGuts.h> //for mtof
- //#include <mozzi_midi.h> // for mtof
- #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
- //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
- int noteArray[8] = {0, 1, 2, 3, 4, 5, 6, 7}; //Notenarray for "NoteN"-array selection
- //int mtof = 1;
- void setup() {
- //setting up the audio components
- //===========================================================================
- //analogReadResolution(12);
- AudioMemory(200);
- waveform1.begin(WAVEFORM_SAWTOOTH);
- waveform1.amplitude(0.75);
- waveform1.frequency(65.41);
- waveform1.pulseWidth(0.15);
- waveform2.begin(WAVEFORM_SAWTOOTH);
- waveform2.amplitude(0.75);
- waveform2.frequency(65.41);
- waveform2.pulseWidth(0.15);
- waveform3.begin(WAVEFORM_SAWTOOTH);
- waveform3.amplitude(0.75);
- waveform3.frequency(65.41);
- waveform3.pulseWidth(0.15);
- waveform4.begin(WAVEFORM_SAWTOOTH);
- waveform4.amplitude(0.75);
- 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.3);
- mixer1.gain(1, 0.3);
- mixer1.gain(2, 0.3);
- mixer1.gain(3, 0.3);
- /*
- 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
- }
- void updateControl() {} // thats a mozzi thing
- void loop() {
- // const char startCV = 0; //mozzi´s pin for analogread startCV
- tasterState = digitalRead(tasterPin); //read tasterPin and set tasterState
- // triggerState = digitalRead(triggerPin); //read triggerPin and set triggerState
- /*
- //mozzi´s attempt to change the incoming voltage to a midi number, with mtof this note to a frequency
- //DID NOT WORK IN THIS STATE
- //===========================================================================================================
- // read CV frequency
- int CV_value = mozziAnalogRead(A0);
- // Convert CV to a midi note between 21 and 117 which is Moog 1V/Oct as per midimuso documentation
- int low_to_high = (117 - 21);
- float midival = (CV_value / 1023.f) * low_to_high;
- midival = midival + 21;
- float midifreq = mtof(midival);
- waveform1.frequency(midifreq * 1); //read Analog8 und setze auf startCV
- //mozzi´s attempt end
- //============================================================================================================
- */
- 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
- /*
- // my attempt to get the envelope starting, Problem it needs an input signal (like audio or dc); dc to control filtercutoff must be multiplied with upper targetfrequency
- //================================================================================================================
- if (triggerState == HIGH)
- {
- envelope1.noteOn();
- }
- else if (triggerState == LOW)
- {
- envelope1.noteOff();
- }
- //my attempt end
- //===============================================================================================
- */
- //the only pitch tracking that works most, but its not any known Volt to "Frequency" scale
- //PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
- float PitchCV = map(startCV, 0, 1023, 65.41, 2093);
- waveform1.frequency((float)(PitchCV) * 1); //WF1 plays rootnote (from startCV) in 1Hz/V Scale THAT DOESN´T WORK!!!
- waveform2.frequency((float)(PitchCV) * Note2[0]); //WF2 plays rootnote * Frequencyproportionn from "Note2"-array
- waveform3.frequency((float)(PitchCV) * Note3[0]); //WF3 plays rootnote * Frequencyproportionn from "Note3"-array
- waveform4.frequency((float)(PitchCV) * Note4[0]); //WF4 plays rootnote * Frequencyproportionn from "Note4"-array
- //PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
- /*
- //VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
- //next attempt to get a 1V/Oct tracking by using the well known formula "freq = lowest freq * 2^(0-5 Signal)"
- //this just end in spitting out frequencys multiplied by the lowest (i.e. 55, 110, 220, 440, etc)
- float voltOctave = map(startCV, 0, 1023, 0, 3.3);
- waveform1.frequency(65.4064 * (pow(2, map(startCV, 0, 1023, 0, 1)) * 1)); //WF1 plays rootnote (from startCV) in 1V /Oct Scale THAT ALSO DOESN´T WORK!!!
- waveform2.frequency(((pow(2, (voltOctave)) * 55)) * Note2[0]); //WF2 plays rootnote * Frequencyproportionn from "Note2"-array
- waveform3.frequency(((pow(2, (voltOctave)) * 55)) * Note3[0]); //WF3 plays rootnote * Frequencyproportionn from "Note3"-array
- waveform4.frequency(((pow(2, (voltOctave)) * 55)) * Note4[0]); //WF4 plays rootnote * Frequencyproportionn from "Note4"-array
- //VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
- */
- int cutoff = map(stationCV, 0, 1023, 65.41, 8184); //map stationCV to cutoff
- filter1.frequency(cutoff); //Filter1 filters cutoff
- if (tasterState == HIGH) //when tasterState is High
- {
- mode++; //count case mode + 1
- delay(200); //delay zur Entprellung
- }
- //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
- filter2.frequency((float)map(stationKnob, 0, 1023, 65.41, 8184)); //Filter1 filters cutoff
- filter2.resonance((float)map(startKnob, 0, 1023, 0, 5)); //controls Resonance
- break;
- case 1: //Volume1 + 2,3,4
- digitalWrite(L1Pin, HIGH); //Led 1 an
- digitalWrite(L2Pin, LOW); //Led 2 aus
- digitalWrite(L3Pin, LOW); //Led 3 aus
- digitalWrite(L4Pin, LOW); //Led 4 aus
- 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(L1Pin, LOW); //Led 1 aus
- digitalWrite(L2Pin, HIGH); //Led 2 an
- digitalWrite(L3Pin, LOW); //Led 3 aus
- digitalWrite(L4Pin, LOW); //Led 4 aus
- //int noteArray[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(L1Pin, LOW); //Led 1 aus
- digitalWrite(L2Pin, LOW); //Led 2 aus
- digitalWrite(L3Pin, HIGH); //Led 3 an
- digitalWrite(L4Pin, LOW); //Led 4 aus
- 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(L1Pin, LOW); //Led 1 aus
- digitalWrite(L2Pin, LOW); //Led 2 aus
- digitalWrite(L3Pin, LOW); //Led 3 aus
- 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
- //==================================================================================================
- /*
- //yet an other attempt to get 1V/Oct AND Chord changing working
- //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- waveform2.frequency((float)(65.4064 * pow(2, (startCV)) * Note2[noteArray])); //WF2 spielt Grundton * Frequenzverhältnis aus "Note2"-array
- waveform3.frequency((float)(65.4064 * pow(2, (startCV)) * Note3[noteArray])); // WF3 spielt Grundton * Frequenzverhältnis aus "Note3"-array
- waveform4.frequency((float)(65.4064 * pow(2, (startCV)) * Note4[noteArray])); // WF4 spielt Grundton * Frequenzverhältnis aus "Note4"-array
- //errormessage: invalid types 'float [8][int [8]]' for array subscript
- //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement