Advertisement
degu234

ChordOrgan Synthvoice 5.5a

Aug 29th, 2021
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.81 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. int 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(9600); // 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(0.75);
  101. waveform1.frequency(65.41);
  102. waveform1.pulseWidth(0.15);
  103.  
  104. waveform2.begin(WAVEFORM_SAWTOOTH);
  105. waveform2.amplitude(0.75);
  106. waveform2.frequency(65.41);
  107. waveform2.pulseWidth(0.15);
  108.  
  109. waveform3.begin(WAVEFORM_SAWTOOTH);
  110. waveform3.amplitude(0.75);
  111. waveform3.frequency(65.41);
  112. waveform3.pulseWidth(0.15);
  113.  
  114. waveform4.begin(WAVEFORM_SAWTOOTH);
  115. waveform4.amplitude(0.75);
  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.3);
  121. mixer1.gain(1, 0.3);
  122. mixer1.gain(2, 0.3);
  123. mixer1.gain(3, 0.3);
  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.  
  201.  
  202. //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 :)
  203. //PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
  204. int hertzseriell = map(startCV, 0, 1023, 0, 40);
  205. waveform1.frequency(Hertz[map(startCV, 0, 1023, 0, 40)] * 1); //WF1 plays rootnote
  206. waveform2.frequency(Hertz[map(startCV, 0, 1023, 0, 40)] * Note2[0]); //WF2 plays rootnote * Frequencyproportionn from "Note2"-array
  207. waveform3.frequency(Hertz[map(startCV, 0, 1023, 0, 40)] * Note3[0]); //WF3 plays rootnote * Frequencyproportionn from "Note3"-array
  208. waveform4.frequency(Hertz[map(startCV, 0, 1023, 0, 40)] * Note4[0]); //WF4 plays rootnote * Frequencyproportionn from "Note4"-array
  209. //PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
  210. Serial.println(triggerState);
  211.  
  212. int cutoff = map(stationCV, 0, 1023, 65.41, 8184); //map stationCV to cutoff
  213. filter1.frequency(cutoff); //Filter1 filters cutoff
  214.  
  215. if (tasterState == HIGH) //when tasterState is High
  216. {
  217. mode++; //count case mode + 1
  218. delay(200); //delay zur Entprellung
  219. }
  220. if (triggerState == HIGH)
  221. {
  222. digitalWrite(L5Pin, HIGH);
  223. }
  224. else
  225. {
  226. digitalWrite(L5Pin, LOW);
  227. }
  228. //begin of page switching and what happens in each page
  229. //==========================================================================
  230.  
  231. switch (mode) {
  232. case 0: //Filter5 + Resonance
  233. digitalWrite(L1Pin, LOW); //Led 1 aus
  234. digitalWrite(L2Pin, LOW); //Led 2 aus
  235. digitalWrite(L3Pin, LOW); //Led 3 aus
  236. digitalWrite(L4Pin, LOW); //Led 4 aus
  237. filter2.frequency((float)map(stationKnob, 0, 1023, 65.41, 8184)); //Filter1 filters cutoff
  238. filter2.resonance((float)map(startKnob, 0, 1023, 0, 5)); //controls Resonance
  239. break;
  240.  
  241. case 1: //Volume1 + 2,3,4
  242. digitalWrite(L1Pin, HIGH); //Led 1 an
  243. digitalWrite(L2Pin, LOW); //Led 2 aus
  244. digitalWrite(L3Pin, LOW); //Led 3 aus
  245. digitalWrite(L4Pin, LOW); //Led 4 aus
  246. mixer1.gain(0, ((float)stationKnob / 3069)); //Gain Mixer1 Eingang 0
  247. mixer1.gain(1, ((float)startKnob / 3069)); //Gain Mixer1 Eingang 1
  248. mixer1.gain(2, ((float)startKnob / 3069)); //Gain Mixer1 Eingang 2
  249. mixer1.gain(3, ((float)startKnob / 3069)); //Gain Mixer1 Eingang 3
  250. break;
  251.  
  252. case 2: //Chord
  253. digitalWrite(L1Pin, LOW); //Led 1 aus
  254. digitalWrite(L2Pin, HIGH); //Led 2 an
  255. digitalWrite(L3Pin, LOW); //Led 3 aus
  256. digitalWrite(L4Pin, LOW); //Led 4 aus
  257. //int noteArray[map(stationKnob, 0, 1023, 0, 7)]; //stationKnob stores value 0-7 into noteArray
  258. waveform1.begin(map(startKnob, 0, 1023, 0, 12)); //waveform selection with startKnob
  259. waveform2.begin(map(startKnob, 0, 1023, 0, 12)); //waveform selection with startKnob
  260. waveform3.begin(map(startKnob, 0, 1023, 0, 12)); //waveform selection with startKnob
  261. waveform4.begin(map(startKnob, 0, 1023, 0, 12)); //waveform selection with startKnob
  262. break;
  263.  
  264. case 3: //wavefolder + bitcrusher
  265. digitalWrite(L1Pin, LOW); //Led 1 aus
  266. digitalWrite(L2Pin, LOW); //Led 2 aus
  267. digitalWrite(L3Pin, HIGH); //Led 3 an
  268. digitalWrite(L4Pin, LOW); //Led 4 aus
  269. dc1.amplitude((float) stationKnob / 1023); //dc-value 0-1 for Wavefolder controlled by stationKnob
  270. bitcrusher1.sampleRate(map(startKnob, 0, 1023, 1, 44100)); //samplerate 1-44100Hz controlled by startKnob
  271. break;
  272.  
  273. case 4: //delaytime + feedback
  274. digitalWrite(L1Pin, LOW); //Led 1 aus
  275. digitalWrite(L2Pin, LOW); //Led 2 aus
  276. digitalWrite(L3Pin, LOW); //Led 3 aus
  277. digitalWrite(L4Pin, HIGH); //Led 4 aus
  278. delay1.delay(0, map(stationKnob, 0, 1023, 3, 200)); //delaytime 3-200ms controlled by stationknob
  279. mixer3.gain(1, ((float)startKnob / 1023)); //delayfeedback 0-1 controlled by startknob
  280. break;
  281.  
  282. default: //next taster push brings us back to page 0
  283. mode = 0;
  284. }
  285. //end of page switching
  286. //==================================================================================================
  287.  
  288.  
  289.  
  290. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement