/ DSP-G1_Synth_Parameters_Demo / DSP-G1_Synth_Parameters_Demo.ino
DSP-G1_Synth_Parameters_Demo.ino
  1  // SPDX-FileCopyrightText: 2018 John Park for Adafruit Industries
  2  //
  3  // SPDX-License-Identifier: MIT
  4  
  5  //DSP-G1_Synth_Parameters_Demo
  6  //Feather M0 Express connected to DSP-G1 voice chip over TX pin
  7  
  8  #include <MIDI.h>
  9  MIDI_CREATE_DEFAULT_INSTANCE();
 10  static const unsigned LED = 13;      // LED pin on the Feather
 11  
 12  void setup() {
 13    Serial.begin(115200);
 14    pinMode(LED, OUTPUT);
 15    MIDI.begin(1);
 16  
 17  /////////////DSP-G1 CC Parameter Settings
 18  //arguments are CC number, followed by value, and MIDI out channel
 19    MIDI.sendControlChange( 7, 120, 1);   //volume
 20    MIDI.sendControlChange( 1,   0, 1);   //LFO mod
 21    MIDI.sendControlChange(16,   6, 1);   //LFO rate
 22    MIDI.sendControlChange(20,   0, 1);   //LFO waveform 0-63 sine, 64-127 S/H
 23    MIDI.sendControlChange(74,  80, 1);   //DC Filter cutoff - higher number lets more harmonics through
 24    MIDI.sendControlChange(71,   0, 1);   //DC Filter resonance
 25    MIDI.sendControlChange(82,  32, 1);   //DC Filter envelope Attack
 26    MIDI.sendControlChange(83,  38, 1);   //DC Filter envelope Decay
 27    MIDI.sendControlChange(28,  64, 1);   //DC Filter envelope Sustain
 28    MIDI.sendControlChange(29,  32, 1);   //DC Filter envelope Release
 29    MIDI.sendControlChange(81,  57, 1);   //DC Filter envelope modulation
 30    MIDI.sendControlChange(76, 100, 1);   //DC Oscillator waveform* 100
 31    MIDI.sendControlChange( 4,   0, 1);   //DC Oscillator wrap
 32    MIDI.sendControlChange(21,   0, 1);   //DC Oscillator range
 33    MIDI.sendControlChange(93,   4, 1);   //DC Oscillator detune
 34    MIDI.sendControlChange(73,   5, 1);   //DC Oscillator envelope Attack
 35    MIDI.sendControlChange(75,  12, 1);   //DC Oscillator envelope Decay
 36    MIDI.sendControlChange(31,  60, 1);   //DC Oscillator envelope Sustain
 37    MIDI.sendControlChange(72,  80, 1);   //DC Oscillator envelope Release
 38  // Wavforms: 0 tri, 25 squarish, 50 pulse, 75 other squarish, 100 saw
 39  }
 40  
 41  void loop() {
 42    digitalWrite(LED, HIGH);
 43    Serial.println("Playing notes");
 44    //Play a C
 45    MIDI.sendNoteOn(24,127,1); //note 24 is C1, velocity 127, channel 1)
 46    //Velocity isn't implemented, but it's a good habit to specify it
 47    delay(1000);
 48  
 49    //Play an E
 50    MIDI.sendNoteOff(24,0,1); // note 24, velocity 0, channel 1
 51    delay(250);
 52    MIDI.sendNoteOn(28,127,1); //note E1
 53    delay(1000);
 54  
 55    //Play a G
 56    MIDI.sendNoteOff(28,0,1);
 57    delay(250);
 58    MIDI.sendNoteOn(31,127,1); //note G1
 59    delay(1000);
 60  
 61    //Play an A#
 62    MIDI.sendNoteOff(31,0,1);
 63    delay(250);
 64    MIDI.sendNoteOn(34,127,1); //note G1
 65    delay(1000);
 66    MIDI.sendNoteOff(34,0,1);
 67  
 68    //rest
 69    delay(500);
 70    //chord
 71    MIDI.sendNoteOn(12,127,1); //C0
 72    MIDI.sendNoteOn(28,127,1); //E2
 73    MIDI.sendNoteOn(31,127,1); //G2
 74    MIDI.sendNoteOn(34,127,1); //A#2
 75    MIDI.sendNoteOn(48,127,1); //C3
 76    //hold
 77    delay(4000);
 78  
 79    //filter cutoff frequency sweep
 80    sweepFilterCutoff(1,15); //turn the filter cutoff knob to the right
 81    sweepFilterCutoff(0,15); //turn the filter cutoff knob to the left
 82  
 83    //filter cutoff and resonance sweeps
 84    sweepFilterCutoff(1,15); //turn the filter cutoff knob to the right
 85    sweepFilterResonance(1,15); //turn the filter resonance peak knob to the right
 86    sweepFilterCutoff(0,15); //turn down the cutoff
 87    sweepFilterResonance(0,15); //and turn down the resonance
 88    //hold here
 89    delay(2000);
 90  
 91    //oscillator detune
 92    sweepDetune(1,15); //turn up the detune
 93    //hold to listen to that detune
 94    delay(3000);
 95    sweepDetune(0, 15); //turn it back down
 96    delay(2000);
 97  
 98    digitalWrite(LED, LOW);
 99    Serial.println("Notes off");
100    MIDI.sendNoteOff(12,0,1);
101    MIDI.sendNoteOff(28,0,1);
102    MIDI.sendNoteOff(31,0,1);
103    MIDI.sendNoteOff(34,0,1);
104    MIDI.sendNoteOff(48,0,1);
105    delay(200);
106  }
107  
108  void sweepFilterCutoff(int dir,int rate){ //dir 0 down, dir 1 up. rate in ms, e.g. 30
109    if(dir==1){ //sweep up
110      for(int i = 0; i < 128; i++){
111        MIDI.sendControlChange(74,i,1);
112        delay(rate);
113        Serial.print("Filter cutoff: "); Serial.println(i);
114      }
115    }
116    else{ //sweep down
117      for(int i = 127; i >=0 ; i--){
118        MIDI.sendControlChange(74,i,1);
119        delay(rate);
120        Serial.print("Filter cutoff: "); Serial.println(i);
121      }
122    }
123  }
124  
125  void sweepDetune(int dir,int rate){ //dir 0 down, dir 1 up. rate in ms, e.g. 30
126    if(dir==1){ //sweep up
127      for(int i = 0; i < 128; i++){
128        MIDI.sendControlChange(93,i,1);
129        delay(rate);
130        Serial.print("Detune: "); Serial.println(i);
131      }
132    }
133    else{ //sweep down
134      for(int i = 127; i >=0 ; i--){
135        MIDI.sendControlChange(93,i,1);
136        delay(rate);
137        Serial.print("Detune: "); Serial.println(i);
138      }
139    }
140  }
141  
142  void sweepFilterResonance(int dir,int rate){ //dir 0 down, dir 1 up. rate in ms, e.g. 30
143    if(dir==1){ //sweep up
144      for(int i = 0; i < 100; i++){ //127 has loads of feedback
145        MIDI.sendControlChange(71,i,1);
146        delay(rate);
147        Serial.print("Filter resonance: "); Serial.println(i);
148      }
149    }
150    else{ //sweep down
151      for(int i = 127; i >=0 ; i--){
152        MIDI.sendControlChange(71,i,1);
153        delay(rate);
154        Serial.print("Filter resonance: "); Serial.println(i);
155      }
156    }
157  }