Advertisement
degu234

ChordOrgan Synthvoice Poti-Pickup

Aug 30th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 15.23 KB | None | 0 0
  1. //todo:
  2. //!poti hook-up!
  3. //EnvelopeGenerator with trigger in that actually sends a control value (dc2) to the filter (dc2 * 8184)
  4. //Envelopegenerator Release control on page 2 controlled by stationKnob
  5. //!Chord selection!
  6. //
  7. //
  8. //stationKnob = A9
  9. //stationCV = A8
  10. //startKnob = A7
  11. //startCV = A6
  12. //tasterButton = Pin 8
  13. //triggerCV = Pin 9
  14. //Output = dac1
  15.  
  16. #include <synth_waveform.h>
  17.  
  18. #include <Audio.h>
  19. #include <Wire.h>
  20. #include <SPI.h>
  21. #include <SD.h>
  22. #include <SerialFlash.h>
  23.  
  24. // GUItool: begin automatically generated code
  25. AudioSynthWaveform       waveform3;      //xy=83.75000762939453,347.0000081062317
  26. AudioSynthWaveform       waveform1;      //xy=86.7500114440918,251.0000057220459
  27. AudioSynthWaveform       waveform2;      //xy=87.75000762939453,300.0000066757202
  28. AudioSynthWaveform       waveform4;      //xy=96.75000762939453,397.00000190734863
  29. AudioMixer4              mixer1;         //xy=246.75002670288086,288.00000381469727
  30. AudioFilterStateVariable filter1;        //xy=406.75000381469727,250.00000381469727
  31. AudioSynthWaveformDc     dc1;            //xy=475,536.25
  32. AudioFilterStateVariable filter2;        //xy=547,195
  33. AudioMixer4              mixer2;         //xy=574.5000152587891,319.00000953674316
  34. AudioEffectWaveFolder    wavefolder1;    //xy=741.25,382.5
  35. AudioEffectBitcrusher    bitcrusher1;    //xy=772.2500190734863,272.2500333786011
  36. AudioEffectDelay         delay1;         //xy=942.0001220703125,523.5000152587891
  37. AudioMixer4              mixer3;         //xy=946.0000267028809,340.0000333786011
  38. AudioFilterStateVariable filter3;        //xy=946.6000061035156,415
  39. AudioMixer4              mixer5;         //xy=1223.7500343322754,251.25000953674316
  40. AudioOutputAnalog        dac1;           //xy=1386.7500381469727,316.00000858306885
  41. AudioConnection          patchCord1(waveform3, 0, mixer1, 2);
  42. AudioConnection          patchCord2(waveform1, 0, mixer1, 0);
  43. AudioConnection          patchCord3(waveform2, 0, mixer1, 1);
  44. AudioConnection          patchCord4(waveform4, 0, mixer1, 3);
  45. AudioConnection          patchCord5(mixer1, 0, filter1, 0);
  46. AudioConnection          patchCord6(filter1, 0, filter2, 0);
  47. AudioConnection          patchCord7(dc1, 0, wavefolder1, 1);
  48. AudioConnection          patchCord8(filter2, 0, mixer2, 0);
  49. AudioConnection          patchCord9(mixer2, 0, wavefolder1, 0);
  50. AudioConnection          patchCord10(wavefolder1, bitcrusher1);
  51. AudioConnection          patchCord11(bitcrusher1, 0, mixer3, 0);
  52. AudioConnection          patchCord12(delay1, 0, filter3, 0);
  53. AudioConnection          patchCord13(mixer3, delay1);
  54. AudioConnection          patchCord14(mixer3, 0, mixer5, 0);
  55. AudioConnection          patchCord15(filter3, 2, mixer3, 1);
  56. AudioConnection          patchCord16(mixer5, dac1);
  57. AudioControlSGTL5000     sgtl5000_1;     //xy=822,662
  58. // GUItool: end automatically generated code
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. //Constants
  66. const int tasterPin = 8;     //taster at Pin 8
  67. const int triggerPin = 9;    //Jack for Gate at Pin 9
  68.  
  69. const int L1Pin = 3;       // LED1 at Pin 3
  70. const int L2Pin = 4;      // LED2 at Pin 4
  71. const int L3Pin = 5;      // LED3 at Pin 5
  72. const int L4Pin = 6;      // LED4 at Pin 6
  73. const int L5Pin = 11;     // LED5 at Pin 11
  74.  
  75. //Variables
  76. int mode = 0;                // Variable for case switching
  77. int tasterState = 0;         // Variable to save tasterstate
  78. int triggerState = 0;     // Variable to save triggerstate
  79. float Note2[8] = {1.25992, 1.18920, 1.25992, 1.33484};  //Frequency proportion to 2nd note
  80. float Note3[8] = {1.49830, 1.49830, 1.49830, 1.49830};  //Frequency proportion to 3rd note
  81. float Note4[8] = {1.88774, 1.88774, 1.88775, 1.88775};  //Frequency proportion to 4th note
  82. float noteArray[8] = {0, 1, 2, 3, 4, 5, 6, 7}; //Notenarray for "NoteN"-array selection
  83. 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,
  84.                    130.8128, 138.5913, 146.8324, 155.5635, 164.8138, 174.6141, 184.9972, 195.9977, 207.6523, 220.0000, 233.0819, 246.9417,
  85.                    261.6256, 277.1826, 293.6648, 311.1270, 329.6276, 349.2282, 369.9944, 391.9954, 415.3047, 440.0000, 466.1638, 493.8833,
  86.                    523.2511, 554.3653, 587.3295, 622.2540, 659.2551, 698.4565, 739.9888, 783.9909, 830.6094, 880.0000, 932.3275, 987.7666,
  87.                    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
  88.                   };
  89.  
  90.  
  91.  
  92. void setup() {
  93.   Serial.begin(19200); // USB is always 12 or 480 Mbit/se
  94.   //setting up the audio components
  95.   //===========================================================================
  96.   //analogReadResolution(12);
  97.   AudioMemory(200);
  98.  
  99.   waveform1.begin(WAVEFORM_SAWTOOTH);
  100.   waveform1.amplitude(1);
  101.   waveform1.frequency(65.41);
  102.   waveform1.pulseWidth(0.15);
  103.  
  104.   waveform2.begin(WAVEFORM_SAWTOOTH);
  105.   waveform2.amplitude(1);
  106.   waveform2.frequency(65.41);
  107.   waveform2.pulseWidth(0.15);
  108.  
  109.   waveform3.begin(WAVEFORM_SAWTOOTH);
  110.   waveform3.amplitude(1);
  111.   waveform3.frequency(65.41);
  112.   waveform3.pulseWidth(0.15);
  113.  
  114.   waveform4.begin(WAVEFORM_SAWTOOTH);
  115.   waveform4.amplitude(1);
  116.   waveform4.frequency(65.41);
  117.   waveform4.pulseWidth(0.15);
  118.  
  119.   //mixer1 to controll Waveform1 with stationKnob; Waveform2-4 with startKnob on page 1
  120.   mixer1.gain(0, 0.25);
  121.   mixer1.gain(1, 0.25);
  122.   mixer1.gain(2, 0.25);
  123.   mixer1.gain(3, 0.25);
  124.   /*
  125.     envelope1.delay(0);
  126.     envelope1.attack(20);
  127.     envelope1.hold(0);
  128.     envelope1.decay(5000);
  129.     envelope1.sustain(0.7);
  130.     envelope1.release(500);
  131.   */
  132.   //dc2.amplitude(0);
  133.  
  134.   //filter1 is controlled by the stationCV input
  135.   filter1.frequency(16000);                                                  //set initial Filter1 freq to 16000Hz
  136.   filter1.resonance(0);                                                      //set Resonance to 0
  137.  
  138.   //filter2 is controlled by the stationKnob on page 0
  139.   filter2.frequency(16000);                                                  //set initial Filter2 freq to 16000Hz
  140.   filter2.resonance(0);                                                      //set Resonance to 0
  141.  
  142.   //mixer2 is just there, no need for it actually
  143.   mixer2.gain(0, 1);                                                         //set Mixer2(Channel, Gain) (0-3, 0-1)
  144.   mixer2.gain(1, 1);
  145.  
  146.   //dc1 for wavefolder input controlled by stationKnob on page 3
  147.   dc1.amplitude(0.05);                                                       //set dc1 for Wavefolder Input
  148.  
  149.   //bitcrusher1 controlled by startKnob on page 3
  150.   bitcrusher1.bits(16);
  151.   bitcrusher1.sampleRate(44100);
  152.  
  153.   //delay1 time controlled by stationKnob; feedback controlled by startKnob on page 4
  154.   delay1.delay(0, 3);                                                        //set Delay(OutChannel, saved Samples) (0-7, 3-449*) *maximum
  155.  
  156.   //filter3 HighPassfilter to get rid of the muddy sound in feedbackloop
  157.   filter3.frequency(200);                                                   //set initial Filter3 freq to 16000Hz
  158.   filter3.resonance(0);                                                      //set Resonance to 0
  159.  
  160.   //mixer3 for feedback controlled by startKnob on page 4
  161.   mixer3.gain(0, 1);                                                         //setze Mixer2(Kanal, Gain) (0-3, 0-1)
  162.   mixer3.gain(1, 0);
  163.  
  164.   //mixer4.gain(1, 0);
  165.   //mixer4.gain(0, 0);
  166.  
  167.   //mixer5 again just a mixer to pass audio thru
  168.   mixer5.gain(0, 0.5);
  169.   //mixer5.gain(1, 0.5);
  170.  
  171.  
  172.   //setting up the audio components DONE!!
  173.   //===========================================================================
  174.  
  175.   //setting up the Pins as In´s n Out´s
  176.   //============================================================================
  177.   pinMode(tasterPin, INPUT);                                                 //taster is input
  178.   pinMode(triggerPin, INPUT);                                             //trigger is input
  179.   pinMode(L1Pin, OUTPUT);                                                    // Set LEDPin as output
  180.   pinMode(L2Pin, OUTPUT);                                                    // Set LEDPin as output
  181.   pinMode(L3Pin, OUTPUT);                                                    // Set LEDPin as output
  182.   pinMode(L4Pin, OUTPUT);                                                    // Set LEDPin as output
  183.   pinMode(L5Pin, OUTPUT);                                                    // Set LEDPin as output
  184.  
  185.  
  186. }
  187.  
  188.  
  189.  
  190.  
  191. void loop() {
  192.   tasterState = digitalRead(tasterPin);                                       //read tasterPin and set tasterState
  193.   triggerState = digitalRead(triggerPin);                                  //read triggerPin and set triggerState
  194.  
  195.  
  196.   int startCV = analogRead(A8);
  197.   int startKnob = analogRead(A7);                                             //lies Analog7 und setze auf startKnob
  198.   int stationKnob = analogRead(A9);                                           //lies Analog9 und setze auf stationKnob
  199.   int stationCV = analogRead(A6);                                             //lies Analog6 und setze auf stationCV
  200.  /*variables to handle each´s page last knob position
  201.   int filterCutoff;
  202.   int filterCutoffOld = 512;
  203.   int resoNance = 0;
  204.   int resoNanceOld = 0;
  205.   int volume1 = 1023;
  206.   int volume1Old = 1023;
  207.   int volume234 = 1023;
  208.   int volume234Old = 1023;
  209.   //int chordSelect = 0;
  210.   //int chordSelectOld = 0;
  211.   int wfSelect = 439;
  212.   int wfSelectOld = 439;
  213.   int waveFolder = 307;
  214.   int waveFolderOld = 307;
  215.   int bitCrusher = 1023;
  216.   int bitCrusherOld = 1023;
  217.   int delayTime = 0;
  218.   int delayTimeOld = 0;
  219.   int feedBack = 0;
  220.   int feedBackOld = 0;
  221. */
  222.   //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 :)
  223.   //PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
  224.   int hertzseriell = map(startCV, 0, 1023, 0, 40);
  225.   waveform1.frequency(Hertz[hertzseriell]); //WF1 plays rootnote
  226.   waveform2.frequency(Hertz[hertzseriell] * Note2[0]); //WF2 plays rootnote * Frequencyproportionn from "Note2"-array
  227.   waveform3.frequency(Hertz[hertzseriell] * Note3[0]); //WF3 plays rootnote * Frequencyproportionn from "Note3"-array
  228.   waveform4.frequency(Hertz[hertzseriell] * Note4[0]); //WF4 plays rootnote * Frequencyproportionn from "Note4"-array
  229.   //PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
  230.  
  231.  
  232.   //int cutoff = map(stationCV, 0, 1023, 65.41, 8184);                          //map stationCV to cutoff
  233.   //filter1.frequency(cutoff);                                                  //Filter1 filters cutoff
  234.   filter1.frequency(map(stationCV, 0, 1023, 0, 8184));
  235.  
  236.  
  237.   if (tasterState == HIGH)                                                    //when tasterState is High
  238.   {
  239.     mode++;                                                                   //count case mode + 1
  240.     delay(200);                                                               //delay zur Entprellung
  241.   }
  242.   digitalWrite(L5Pin, triggerState );
  243.  
  244.   digitalWrite(L1Pin, LOW);                                               //Led 1 aus
  245.   digitalWrite(L2Pin, LOW);                                               //Led 2 aus
  246.   digitalWrite(L3Pin, LOW);                                               //Led 3 aus
  247.   digitalWrite(L4Pin, LOW);                                               //Led 4 aus
  248.  
  249.   //begin of page switching and what happens in each page
  250.   //==========================================================================
  251.  
  252.   switch (mode) {
  253.     case 0: //Filter5 + Resonance
  254.       digitalWrite(L1Pin, LOW);                                               //Led 1 aus
  255.       digitalWrite(L2Pin, LOW);                                               //Led 2 aus
  256.       digitalWrite(L3Pin, LOW);                                               //Led 3 aus
  257.       digitalWrite(L4Pin, LOW);                                               //Led 4 aus
  258.       //nachdem ich nach dem Durchschalten der cases 0-4 wieder bei 0 gelandet bin
  259.       //soll die nachstehende funktion erst dann "aktiv" werden, wenn das Poti (aktueller Wert)
  260.       //filterCutoffOld über/unterschritten wurde (größer/kleiner Vergleich?)
  261.       filter2.frequency((float)map(stationKnob, 0, 1023, 65.41, 8184));       //Filter1 filters cutoff
  262.       //nach einem erneuten Tastendruck in das nächste Case soll der aktuelle Wert als filterCutoffOld
  263.       //übernommen und gespeichert werden.
  264.  
  265.       //diese  abfrage soll in jedem case für beide Potentiometer angewendet werden.
  266.       filter2.resonance((float)map(startKnob, 0, 1023, 0, 5));                //controls Resonance
  267.       break;
  268.  
  269.     case 1: //Volume1 + 2,3,4
  270.     //das eigentliche Abspeichern der vorigen Werte wird wohl hier passieren
  271.       digitalWrite(L1Pin, HIGH);                                              //Led 1 an
  272.       mixer1.gain(0, ((float)stationKnob / 3069));                            //Gain Mixer1 Eingang 0
  273.       mixer1.gain(1, ((float)startKnob / 3069));                              //Gain Mixer1 Eingang 1
  274.       mixer1.gain(2, ((float)startKnob / 3069));                              //Gain Mixer1 Eingang 2
  275.       mixer1.gain(3, ((float)startKnob / 3069));                              //Gain Mixer1 Eingang 3
  276.       break;
  277.  
  278.     case 2: //Chord
  279.       digitalWrite(L2Pin, HIGH);                                              //Led 2 an
  280.       noteArray[map(stationKnob, 0, 1023, 0, 7)];                       //stationKnob stores value 0-7 into noteArray
  281.     //  Serial.print(noteArray);
  282.       //note3[map(stationKnob, 0, 1023, 0, 7)];                       //stationKnob stores value 0-7 into noteArray
  283.       //note4[map(stationKnob, 0, 1023, 0, 7)];                       //stationKnob stores value 0-7 into noteArray
  284.       waveform1.begin(map(startKnob, 0, 1023, 0, 12));                        //waveform selection with startKnob
  285.       waveform2.begin(map(startKnob, 0, 1023, 0, 12));                        //waveform selection with startKnob
  286.       waveform3.begin(map(startKnob, 0, 1023, 0, 12));                        //waveform selection with startKnob
  287.       waveform4.begin(map(startKnob, 0, 1023, 0, 12));                        //waveform selection with startKnob
  288.  
  289.       break;
  290.  
  291.     case 3: //wavefolder + bitcrusher
  292.       digitalWrite(L3Pin, HIGH);                                              //Led 3 an
  293.       dc1.amplitude((float) stationKnob / 1023);                              //dc-value 0-1 for Wavefolder controlled by stationKnob
  294.       bitcrusher1.sampleRate(map(startKnob, 0, 1023, 1, 44100));              //samplerate 1-44100Hz controlled by startKnob
  295.       break;
  296.  
  297.     case 4: //delaytime + feedback
  298.       digitalWrite(L4Pin, HIGH);                                              //Led 4 aus
  299.       delay1.delay(0, map(stationKnob, 0, 1023, 3, 200));                     //delaytime 3-200ms controlled by stationknob
  300.       mixer3.gain(1, ((float)startKnob / 1023));                              //delayfeedback 0-1 controlled by startknob
  301.       break;
  302.  
  303.     default:                                                                  //next taster push brings us back to page 0
  304.       mode = 0;
  305.   }
  306.   //end of page switching
  307.   //==================================================================================================
  308.  
  309.  
  310.  
  311. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement