Advertisement
degu234

ChordOrgan Synthvoice v5.5

Aug 28th, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 17.37 KB | None | 0 0
  1. //todo:
  2. //poti hook-up
  3. //!1V/Octave-tracking!
  4. //EnvelopeGenerator with trigger in that actually sends a control value (dc2) to the filter (dc2 * 8184)
  5. //Envelopegenerator Release control on page 2 controlled by stationKnob
  6. //!Chord selection!
  7. //
  8. //
  9. //stationKnob = A9
  10. //stationCV = A8
  11. //startKnob = A7
  12. //startCV = A6
  13. //tasterButton = Pin 8
  14. //triggerCV = Pin 9
  15. //Output = dac1
  16.  
  17. //#include <MozziGuts.h> //for mtof
  18. //#include <mozzi_midi.h> // for mtof
  19. #include <synth_waveform.h>
  20.  
  21. #include <Audio.h>
  22. #include <Wire.h>
  23. #include <SPI.h>
  24. #include <SD.h>
  25. #include <SerialFlash.h>
  26.  
  27. // GUItool: begin automatically generated code
  28. AudioSynthWaveform       waveform3;      //xy=83.75000762939453,347.0000081062317
  29. AudioSynthWaveform       waveform1;      //xy=86.7500114440918,251.0000057220459
  30. AudioSynthWaveform       waveform2;      //xy=87.75000762939453,300.0000066757202
  31. AudioSynthWaveform       waveform4;      //xy=96.75000762939453,397.00000190734863
  32. AudioMixer4              mixer1;         //xy=246.75002670288086,288.00000381469727
  33. AudioFilterStateVariable filter1;        //xy=406.75000381469727,250.00000381469727
  34. AudioSynthWaveformDc     dc1;            //xy=475,536.25
  35. AudioFilterStateVariable filter2;        //xy=547,195
  36. AudioMixer4              mixer2;         //xy=574.5000152587891,319.00000953674316
  37. AudioEffectWaveFolder    wavefolder1;    //xy=741.25,382.5
  38. AudioEffectBitcrusher    bitcrusher1;    //xy=772.2500190734863,272.2500333786011
  39. AudioEffectDelay         delay1;         //xy=942.0001220703125,523.5000152587891
  40. AudioMixer4              mixer3;         //xy=946.0000267028809,340.0000333786011
  41. AudioFilterStateVariable filter3;        //xy=946.6000061035156,415
  42. AudioMixer4              mixer5;         //xy=1223.7500343322754,251.25000953674316
  43. AudioOutputAnalog        dac1;           //xy=1386.7500381469727,316.00000858306885
  44. AudioConnection          patchCord1(waveform3, 0, mixer1, 2);
  45. AudioConnection          patchCord2(waveform1, 0, mixer1, 0);
  46. AudioConnection          patchCord3(waveform2, 0, mixer1, 1);
  47. AudioConnection          patchCord4(waveform4, 0, mixer1, 3);
  48. AudioConnection          patchCord5(mixer1, 0, filter1, 0);
  49. AudioConnection          patchCord6(filter1, 0, filter2, 0);
  50. AudioConnection          patchCord7(dc1, 0, wavefolder1, 1);
  51. AudioConnection          patchCord8(filter2, 0, mixer2, 0);
  52. AudioConnection          patchCord9(mixer2, 0, wavefolder1, 0);
  53. AudioConnection          patchCord10(wavefolder1, bitcrusher1);
  54. AudioConnection          patchCord11(bitcrusher1, 0, mixer3, 0);
  55. AudioConnection          patchCord12(delay1, 0, filter3, 0);
  56. AudioConnection          patchCord13(mixer3, delay1);
  57. AudioConnection          patchCord14(mixer3, 0, mixer5, 0);
  58. AudioConnection          patchCord15(filter3, 2, mixer3, 1);
  59. AudioConnection          patchCord16(mixer5, dac1);
  60. AudioControlSGTL5000     sgtl5000_1;     //xy=822,662
  61. // GUItool: end automatically generated code
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. //Constants
  69. const int tasterPin = 8;     //taster at Pin 8
  70. //const int triggerPin = 9;    //Jack for Gate at Pin 9
  71.  
  72. const int L1Pin = 3;       // LED1 at Pin 3
  73. const int L2Pin = 4;      // LED2 at Pin 4
  74. const int L3Pin = 5;      // LED3 at Pin 5
  75. const int L4Pin = 6;      // LED4 at Pin 6
  76.  
  77. //Variables
  78. int mode = 0;                // Variable for case switching
  79. int tasterState = 0;         // Variable to save tasterstate
  80. //int triggerState = 0;     // Variable to save triggerstate
  81. float Note2[8] = {1.25992, 1.18920, 1.25992, 1.33484};  //Frequency proportion to 2nd note
  82. float Note3[8] = {1.49830, 1.49830, 1.49830, 1.49830};  //Frequency proportion to 3rd note
  83. float Note4[8] = {1.88774, 1.88774, 1.88775, 1.88775};  //Frequency proportion to 4th note
  84. int noteArray[8] = {0, 1, 2, 3, 4, 5, 6, 7}; //Notenarray for "NoteN"-array selection
  85. //int mtof = 1;
  86.  
  87.  
  88. void setup() {
  89.   //setting up the audio components
  90.   //===========================================================================
  91.   //analogReadResolution(12);
  92.   AudioMemory(200);
  93.  
  94.   waveform1.begin(WAVEFORM_SAWTOOTH);
  95.   waveform1.amplitude(0.75);
  96.   waveform1.frequency(65.41);
  97.   waveform1.pulseWidth(0.15);
  98.  
  99.   waveform2.begin(WAVEFORM_SAWTOOTH);
  100.   waveform2.amplitude(0.75);
  101.   waveform2.frequency(65.41);
  102.   waveform2.pulseWidth(0.15);
  103.  
  104.   waveform3.begin(WAVEFORM_SAWTOOTH);
  105.   waveform3.amplitude(0.75);
  106.   waveform3.frequency(65.41);
  107.   waveform3.pulseWidth(0.15);
  108.  
  109.   waveform4.begin(WAVEFORM_SAWTOOTH);
  110.   waveform4.amplitude(0.75);
  111.   waveform4.frequency(65.41);
  112.   waveform4.pulseWidth(0.15);
  113.  
  114.   //mixer1 to controll Waveform1 with stationKnob; Waveform2-4 with startKnob on page 1
  115.   mixer1.gain(0, 0.3);
  116.   mixer1.gain(1, 0.3);
  117.   mixer1.gain(2, 0.3);
  118.   mixer1.gain(3, 0.3);
  119.   /*
  120.     envelope1.delay(0);
  121.     envelope1.attack(20);
  122.     envelope1.hold(0);
  123.     envelope1.decay(5000);
  124.     envelope1.sustain(0.7);
  125.     envelope1.release(500);
  126.   */
  127.   //dc2.amplitude(0);
  128.  
  129.   //filter1 is controlled by the stationCV input
  130.   filter1.frequency(16000);                                                  //set initial Filter1 freq to 16000Hz
  131.   filter1.resonance(0);                                                      //set Resonance to 0
  132.  
  133.   //filter2 is controlled by the stationKnob on page 0
  134.   filter2.frequency(16000);                                                  //set initial Filter2 freq to 16000Hz
  135.   filter2.resonance(0);                                                      //set Resonance to 0
  136.  
  137.   //mixer2 is just there, no need for it actually
  138.   mixer2.gain(0, 1);                                                         //set Mixer2(Channel, Gain) (0-3, 0-1)
  139.   mixer2.gain(1, 1);
  140.  
  141.   //dc1 for wavefolder input controlled by stationKnob on page 3
  142.   dc1.amplitude(0.05);                                                       //set dc1 for Wavefolder Input
  143.  
  144.   //bitcrusher1 controlled by startKnob on page 3
  145.   bitcrusher1.bits(16);
  146.   bitcrusher1.sampleRate(44100);
  147.  
  148.   //delay1 time controlled by stationKnob; feedback controlled by startKnob on page 4
  149.   delay1.delay(0, 3);                                                        //set Delay(OutChannel, saved Samples) (0-7, 3-449*) *maximum
  150.  
  151.   //filter3 HighPassfilter to get rid of the muddy sound in feedbackloop
  152.   filter3.frequency(200);                                                   //set initial Filter3 freq to 16000Hz
  153.   filter3.resonance(0);                                                      //set Resonance to 0
  154.  
  155.   //mixer3 for feedback controlled by startKnob on page 4
  156.   mixer3.gain(0, 1);                                                         //setze Mixer2(Kanal, Gain) (0-3, 0-1)
  157.   mixer3.gain(1, 0);
  158.  
  159.   //mixer4.gain(1, 0);
  160.   //mixer4.gain(0, 0);
  161.  
  162.   //mixer5 again just a mixer to pass audio thru
  163.   mixer5.gain(0, 0.5);
  164.   //mixer5.gain(1, 0.5);
  165.  
  166.  
  167.   //setting up the audio components DONE!!
  168.   //===========================================================================
  169.  
  170.   //setting up the Pins as In´s n Out´s
  171.   //============================================================================
  172.   pinMode(tasterPin, INPUT);                                                 //taster is input
  173.   //pinMode(triggerPin, INPUT);                                             //trigger is input
  174.   pinMode(L1Pin, OUTPUT);                                                    // Set LEDPin as output
  175.   pinMode(L2Pin, OUTPUT);                                                    // Set LEDPin as output
  176.   pinMode(L3Pin, OUTPUT);                                                    // Set LEDPin as output
  177.   pinMode(L4Pin, OUTPUT);                                                    // Set LEDPin as output
  178.  
  179.  
  180. }
  181.  
  182. void updateControl() {}                                                      // thats a mozzi thing
  183.  
  184.  
  185. void loop() {
  186.   // const char startCV = 0;                                                     //mozzi´s pin for analogread startCV
  187.   tasterState = digitalRead(tasterPin);                                       //read tasterPin and set tasterState
  188.   //  triggerState = digitalRead(triggerPin);                                  //read triggerPin and set triggerState
  189.  
  190.   /*
  191.     //mozzi´s attempt to change the incoming voltage to a midi number, with mtof this note to a frequency
  192.     //DID NOT WORK IN THIS STATE
  193.     //===========================================================================================================
  194.  
  195.     // read CV frequency
  196.     int CV_value = mozziAnalogRead(A0);
  197.     // Convert CV to a midi note between 21 and 117 which is Moog 1V/Oct as per midimuso documentation
  198.     int low_to_high = (117 - 21);
  199.     float midival = (CV_value / 1023.f) * low_to_high;
  200.     midival = midival + 21;
  201.     float midifreq = mtof(midival);
  202.  
  203.     waveform1.frequency(midifreq * 1);  //read Analog8 und setze auf startCV
  204.     //mozzi´s attempt end
  205.     //============================================================================================================
  206.   */
  207.  
  208.   int startCV = analogRead(A8);
  209.   int startKnob = analogRead(A7);                                             //lies Analog7 und setze auf startKnob
  210.   int stationKnob = analogRead(A9);                                           //lies Analog9 und setze auf stationKnob
  211.   int stationCV = analogRead(A6);                                             //lies Analog6 und setze auf stationCV
  212.  
  213.   /*
  214.     // 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
  215.     //================================================================================================================
  216.     if (triggerState == HIGH)
  217.     {
  218.       envelope1.noteOn();
  219.     }
  220.     else  if (triggerState == LOW)
  221.     {
  222.       envelope1.noteOff();
  223.     }
  224.     //my attempt end
  225.     //===============================================================================================
  226.   */
  227.  
  228.  
  229.     //the only pitch tracking that works most, but its not any known Volt to "Frequency" scale
  230.     //PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
  231.     float PitchCV = map(startCV, 0, 1023, 65.41, 2093);
  232.     waveform1.frequency((float)(PitchCV) * 1);                                  //WF1 plays rootnote (from startCV) in 1Hz/V Scale THAT DOESN´T WORK!!!
  233.     waveform2.frequency((float)(PitchCV) * Note2[0]);                           //WF2 plays rootnote * Frequencyproportionn from "Note2"-array
  234.     waveform3.frequency((float)(PitchCV) * Note3[0]);                           //WF3 plays rootnote * Frequencyproportionn from "Note3"-array
  235.     waveform4.frequency((float)(PitchCV) * Note4[0]);                           //WF4 plays rootnote * Frequencyproportionn from "Note4"-array
  236.     //PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
  237.  
  238.   /*
  239.     //VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
  240.     //next attempt to get a 1V/Oct tracking by using the well known formula "freq = lowest freq * 2^(0-5 Signal)"
  241.     //this just end in spitting out frequencys multiplied by the lowest (i.e. 55, 110, 220, 440, etc)
  242.       float voltOctave = map(startCV, 0, 1023, 0, 3.3);
  243.       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!!!
  244.       waveform2.frequency(((pow(2, (voltOctave)) * 55)) * Note2[0]);            //WF2 plays rootnote * Frequencyproportionn from "Note2"-array
  245.       waveform3.frequency(((pow(2, (voltOctave)) * 55)) * Note3[0]);            //WF3 plays rootnote * Frequencyproportionn from "Note3"-array
  246.       waveform4.frequency(((pow(2, (voltOctave)) * 55)) * Note4[0]);            //WF4 plays rootnote * Frequencyproportionn from "Note4"-array
  247.       //VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
  248.   */
  249.  
  250.   int cutoff = map(stationCV, 0, 1023, 65.41, 8184);                          //map stationCV to cutoff
  251.   filter1.frequency(cutoff);                                                  //Filter1 filters cutoff
  252.  
  253.   if (tasterState == HIGH)                                                    //when tasterState is High
  254.   {
  255.     mode++;                                                                   //count case mode + 1
  256.     delay(200);                                                               //delay zur Entprellung
  257.   }
  258.    //begin of page switching and what happens in each page
  259.   //==========================================================================
  260.  
  261.   switch (mode) {
  262.     case 0: //Filter5 + Resonance
  263.       digitalWrite(L1Pin, LOW);                                               //Led 1 aus
  264.       digitalWrite(L2Pin, LOW);                                               //Led 2 aus
  265.       digitalWrite(L3Pin, LOW);                                               //Led 3 aus
  266.       digitalWrite(L4Pin, LOW);                                               //Led 4 aus
  267.       filter2.frequency((float)map(stationKnob, 0, 1023, 65.41, 8184));       //Filter1 filters cutoff
  268.       filter2.resonance((float)map(startKnob, 0, 1023, 0, 5));                //controls Resonance
  269.       break;
  270.  
  271.     case 1: //Volume1 + 2,3,4
  272.       digitalWrite(L1Pin, HIGH);                                              //Led 1 an
  273.       digitalWrite(L2Pin, LOW);                                               //Led 2 aus
  274.       digitalWrite(L3Pin, LOW);                                               //Led 3 aus
  275.       digitalWrite(L4Pin, LOW);                                               //Led 4 aus
  276.       mixer1.gain(0, ((float)stationKnob / 3069));                            //Gain Mixer1 Eingang 0
  277.       mixer1.gain(1, ((float)startKnob / 3069));                              //Gain Mixer1 Eingang 1
  278.       mixer1.gain(2, ((float)startKnob / 3069));                              //Gain Mixer1 Eingang 2
  279.       mixer1.gain(3, ((float)startKnob / 3069));                              //Gain Mixer1 Eingang 3
  280.       break;
  281.  
  282.     case 2: //Chord
  283.       digitalWrite(L1Pin, LOW);                                               //Led 1 aus
  284.       digitalWrite(L2Pin, HIGH);                                              //Led 2 an
  285.       digitalWrite(L3Pin, LOW);                                               //Led 3 aus
  286.       digitalWrite(L4Pin, LOW);                                               //Led 4 aus
  287.       //int noteArray[map(stationKnob, 0, 1023, 0, 7)];                       //stationKnob stores value 0-7 into noteArray
  288.       waveform1.begin(map(startKnob, 0, 1023, 0, 12));                        //waveform selection with startKnob
  289.       waveform2.begin(map(startKnob, 0, 1023, 0, 12));                        //waveform selection with startKnob
  290.       waveform3.begin(map(startKnob, 0, 1023, 0, 12));                        //waveform selection with startKnob
  291.       waveform4.begin(map(startKnob, 0, 1023, 0, 12));                        //waveform selection with startKnob
  292.       break;
  293.  
  294.     case 3: //wavefolder + bitcrusher
  295.       digitalWrite(L1Pin, LOW);                                               //Led 1 aus
  296.       digitalWrite(L2Pin, LOW);                                               //Led 2 aus
  297.       digitalWrite(L3Pin, HIGH);                                              //Led 3 an
  298.       digitalWrite(L4Pin, LOW);                                               //Led 4 aus
  299.       dc1.amplitude((float) stationKnob / 1023);                              //dc-value 0-1 for Wavefolder controlled by stationKnob
  300.       bitcrusher1.sampleRate(map(startKnob, 0, 1023, 1, 44100));              //samplerate 1-44100Hz controlled by startKnob
  301.       break;
  302.  
  303.     case 4: //delaytime + feedback
  304.       digitalWrite(L1Pin, LOW);                                               //Led 1 aus
  305.       digitalWrite(L2Pin, LOW);                                               //Led 2 aus
  306.       digitalWrite(L3Pin, LOW);                                               //Led 3 aus
  307.       digitalWrite(L4Pin, HIGH);                                              //Led 4 aus
  308.       delay1.delay(0, map(stationKnob, 0, 1023, 3, 200));                     //delaytime 3-200ms controlled by stationknob
  309.       mixer3.gain(1, ((float)startKnob / 1023));                              //delayfeedback 0-1 controlled by startknob
  310.       break;
  311.  
  312.     default:                                                                  //next taster push brings us back to page 0
  313.       mode = 0;
  314.   }
  315.   //end of page switching
  316.   //==================================================================================================
  317.  
  318.  
  319.   /*
  320.    //yet an other attempt to get 1V/Oct AND Chord changing working
  321.     //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  322.     waveform2.frequency((float)(65.4064 * pow(2, (startCV)) * Note2[noteArray]));                     //WF2 spielt Grundton * Frequenzverhältnis aus "Note2"-array
  323.     waveform3.frequency((float)(65.4064 * pow(2, (startCV)) * Note3[noteArray]));                    //  WF3 spielt Grundton * Frequenzverhältnis aus "Note3"-array
  324.     waveform4.frequency((float)(65.4064 * pow(2, (startCV)) * Note4[noteArray]));                    //  WF4 spielt Grundton * Frequenzverhältnis aus "Note4"-array
  325.  
  326.     //errormessage: invalid types 'float [8][int [8]]' for array subscript
  327.     //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  328.   */
  329. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement