Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 33

Thread: problem of noob with potentiometer

  1. #1

    problem of noob with potentiometer

    hi, I try to ad potentiometer to an existing code of a midi synth, I start to ad a potentiometer to the cutoff but when I turn the knob the filter is closed at the middle of the potentiometer, any one can help me or show me the good way to ad potentiometer please?
    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <MIDI.h>  
    #include <SerialFlash.h>
    #include <Bounce.h>
    // GUItool: begin automatically generated code
    AudioSynthWaveformDc     dc1;            //xy=55,229.9999976158142
    AudioSynthWaveformModulated waveformMod9;   //xy=228.57149451119562,475.7143028804235
    AudioSynthWaveformModulated waveformMod3;   //xy=231.42856979370117,176.85713577270508
    AudioSynthWaveformModulated waveformMod4;   //xy=231.42856979370117,211.85713577270508
    AudioSynthWaveformModulated waveformMod5;   //xy=231.42858123779297,255.42856407165527
    AudioSynthWaveformModulated waveformMod6;   //xy=231.42858123779297,290.4285640716553
    AudioSynthWaveformModulated waveformMod7;   //xy=231.42858123779297,325.4285640716553
    AudioSynthWaveformModulated waveformMod8;   //xy=231.42858123779297,362.4285640716553
    AudioSynthWaveformModulated waveformMod2;   //xy=232.42856979370117,139.85713577270508
    AudioSynthWaveformModulated waveformMod1;   //xy=233.42856979370117,102.85713577270508
    AudioSynthNoiseWhite     noise1;         //xy=235.71430587768555,527.1428508758545
    AudioSynthNoisePink      pink1;          //xy=244.28573608398438,571.4285678863525
    AudioEffectEnvelope      envelope7;      //xy=410.4285697937012,325.8571357727051
    AudioEffectEnvelope      envelope6;      //xy=414.4285697937012,289.8571357727051
    AudioEffectEnvelope      envelope1;      //xy=415.4285697937012,102.85713577270508
    AudioEffectEnvelope      envelope5;      //xy=415.4285697937012,254.85713577270508
    AudioEffectEnvelope      envelope8;      //xy=415.4285697937012,362.8571357727051
    AudioEffectEnvelope      envelope2;      //xy=416.4285697937012,139.85713577270508
    AudioEffectEnvelope      envelope4;      //xy=416.4285697937012,216.85713577270508
    AudioEffectEnvelope      envelope3;      //xy=417.4285697937012,178.85713577270508
    AudioMixer4              mixer4;         //xy=438.5714530944824,517.1428680419922
    AudioEffectEnvelope      envelope9;      //xy=601.4286117553711,477.1428565979004
    AudioMixer4              mixer1;         //xy=619.4285697937012,171.85713577270508
    AudioMixer4              mixer2;         //xy=625.4285697937012,282.8571357727051
    AudioSynthWaveformDc     dc2;            //xy=625.1072998046875,421.3571472167969
    AudioSynthWaveformDc     dc3;            //xy=647,79.25
    AudioEffectEnvelope      envelope10;     //xy=786.46435546875,411.857177734375
    AudioSynthWaveformModulated waveformMod11;  //xy=794,329
    AudioMixer4              mixer3;         //xy=806.7858390808105,194.64279556274414
    AudioSynthWaveformModulated waveformMod10;  //xy=827.75,98.74999904632568
    AudioMixer4              mixer8;         //xy=958,343
    AudioEffectMultiply      multiply1;      //xy=1055.0000038146973,74.24999976158142
    AudioFilterStateVariable filter1;        //xy=1091.5714111328125,283.00006103515625
    AudioMixer4              mixer7;         //xy=1283.7500190734863,245.00000190734863
    AudioEffectDelay         delay1;         //xy=1491.1905250549316,414.9405460357666
    AudioEffectFreeverbStereo freeverbs1;     //xy=1511.190486907959,253.51194190979004
    AudioMixer4              mixer5;         //xy=1671.1904525756836,140.65477180480957
    AudioMixer4              mixer6;         //xy=1672.6188468933105,363.5119228363037
    AudioOutputAnalogStereo  dacs1;          //xy=1821.4761123657227,290.65477991104126
    AudioOutputUSB           usb1;
    AudioConnection          patchCord1(dc1, 0, waveformMod1, 1);
    AudioConnection          patchCord2(dc1, 0, waveformMod2, 1);
    AudioConnection          patchCord3(dc1, 0, waveformMod3, 1);
    AudioConnection          patchCord4(dc1, 0, waveformMod4, 1);
    AudioConnection          patchCord5(dc1, 0, waveformMod5, 1);
    AudioConnection          patchCord6(dc1, 0, waveformMod6, 1);
    AudioConnection          patchCord7(dc1, 0, waveformMod7, 1);
    AudioConnection          patchCord8(dc1, 0, waveformMod8, 1);
    AudioConnection          patchCord9(dc1, 0, waveformMod9, 1);
    AudioConnection          patchCord10(waveformMod9, 0, mixer4, 0);
    AudioConnection          patchCord11(waveformMod3, envelope3);
    AudioConnection          patchCord12(waveformMod4, envelope4);
    AudioConnection          patchCord13(waveformMod5, envelope5);
    AudioConnection          patchCord14(waveformMod6, envelope6);
    AudioConnection          patchCord15(waveformMod7, envelope7);
    AudioConnection          patchCord16(waveformMod8, envelope8);
    AudioConnection          patchCord17(waveformMod2, envelope2);
    AudioConnection          patchCord18(waveformMod1, envelope1);
    AudioConnection          patchCord19(noise1, 0, mixer4, 1);
    AudioConnection          patchCord20(pink1, 0, mixer4, 2);
    AudioConnection          patchCord21(envelope7, 0, mixer2, 2);
    AudioConnection          patchCord22(envelope6, 0, mixer2, 1);
    AudioConnection          patchCord23(envelope1, 0, mixer1, 0);
    AudioConnection          patchCord24(envelope5, 0, mixer2, 0);
    AudioConnection          patchCord25(envelope8, 0, mixer2, 3);
    AudioConnection          patchCord26(envelope2, 0, mixer1, 1);
    AudioConnection          patchCord27(envelope4, 0, mixer1, 3);
    AudioConnection          patchCord28(envelope3, 0, mixer1, 2);
    AudioConnection          patchCord29(mixer4, envelope9);
    AudioConnection          patchCord30(envelope9, 0, mixer3, 2);
    AudioConnection          patchCord31(mixer1, 0, mixer3, 0);
    AudioConnection          patchCord32(mixer2, 0, mixer3, 1);
    AudioConnection          patchCord33(dc2, envelope10);
    AudioConnection          patchCord34(dc3, 0, waveformMod10, 1);
    AudioConnection          patchCord35(dc3, 0, waveformMod11, 1);
    AudioConnection          patchCord36(envelope10, 0, mixer8, 1);
    AudioConnection          patchCord37(waveformMod11, 0, mixer8, 0);
    AudioConnection          patchCord38(mixer3, 0, filter1, 0);
    AudioConnection          patchCord39(waveformMod10, 0, multiply1, 1);
    AudioConnection          patchCord40(mixer8, 0, filter1, 1);
    AudioConnection          patchCord41(multiply1, 0, mixer7, 0);
    AudioConnection          patchCord42(filter1, 0, multiply1, 0);
    AudioConnection          patchCord43(filter1, 0, mixer7, 1);
    AudioConnection          patchCord44(mixer7, freeverbs1);
    AudioConnection          patchCord45(mixer7, delay1);
    AudioConnection          patchCord46(mixer7, 0, mixer5, 1);
    AudioConnection          patchCord47(delay1, 0, mixer6, 1);
    AudioConnection          patchCord48(freeverbs1, 0, mixer5, 0);
    AudioConnection          patchCord49(freeverbs1, 1, mixer6, 0);
    //AudioConnection          patchCord50(mixer5, 0, dacs1, 0);
    //AudioConnection          patchCord51(mixer6, 0, dacs1, 1);
    AudioConnection          patchCord52(mixer5, 0, usb1, 0);
    AudioConnection          patchCord53(mixer6, 0, usb1, 1);
    AudioControlSGTL5000  sgtl5000_1;
    // GUItool: end automatically generated code
    
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
    
    /**
     * End generated code block
     */
    
    float hz2;
    
    float cutoff = 19000;
    float reso = 1.11;
    
    float revol = 0;
    float rsize = 0.1;
    
    float atk = 10.5;
    float dcy = 35;
    float sus = 0.5;
    float rls = 300;
    float atkf = 10.5;
    float dcyf = 35;
    float susf = 0.5;
    float rlsf = 300;
    float md = 0.0;
    
    float phs = 0;
    
    int swc = 0;
    int swc2 = 0;
    
    int wavfrm;
    int wavfrm2;
    
    int srlswc = 0;
    
    float nse1 = 0.0;
    float pnk1 = 0.0;
    
    float amp2 = 0.00;
    float vely = 0.00;
    
    float shpwm = 0.00;
    float shpwm2 = 0.00;
    
    float lfofreq = 0.00;
    float lfoamp = 0.00;
    float lfoampf = 0.00;
    
    int valueconvert;
    
    #include <Bounce.h>
    //teensy 3.6 mux pins
    
    #define MUX_S0 28
    #define MUX_S1 27
    #define MUX_S2 26
    #define MUX_S3 25
    
    #define MUX1 38
    #define MUX2 A22
    
    #define MUX1_nse1 0//
    #define MUX1_lfofreq 1//
    #define MUX1_shpwm2 2//
    #define MUX1_lfoamp 3//
    #define MUX1_swc 4//
    #define MUX1_amp2 5//
    #define MUX1_atkf 6//
    #define MUX1_dcyf 7//
    #define MUX1_md  8//
    #define MUX1_shpwm 9//
    #define MUX1_phs 10
    //#define MUX1_ 11
    //#define MUX1_swc 12
    //#define MUX1_13
    //#define MUX1_ 14
    #define MUX1_reso 15
    //mux2 pins
    #define MUX2_rls 0//
    #define MUX2_sus 1//
    #define MUX2_dcy 2//
    #define MUX2_atk 3//
    #define MUX2_lfoamp 4//
    #define MUX2_revol 5 //
    #define MUX2_rsize 6
    //#define MUX2_swc 7
    
    #define MUX2_shpwm2 5
    #define MUX2_vol 8
    #define MUX2_rlsf 9//HIGH//
    #define MUX2_susf 10//
    #define MUX2_reso 12//
    #define MUX2_cutoff 13//
    
    #define MUXCHANNELS 16
    #define QUANTISE_FACTOR 7
    #define DEBOUNCE 30
    #define VOLUME_POT A14
    
    //midi cc
    
    
    //MIDI CC control numbers
    
    #define CCcutoff 1
    #define CCreso 2
    #define CCrevol 19
    #define CCrsize 20
    #define CCatk 13
    #define CCdcy 14
    #define CCsus 15
    #define CCrls 16
    #define CCatkf 9
    #define CCdcyf 10
    #define CCsusf 11
    #define CCrlsf 12
    #define CCmd 3
    #define CCphs 4
    #define CCswc 5//switch lfo
    #define CCswc2 22//noise
    #define CCnse1 6
    #define CCpnk1 7
    #define CCamp2 8//vol osc
    #define CCshpwm 24//shape waveform
    #define CCshpwm2 23//lfo waveform
    #define CClfoamp 17//lfo amnt
    #define CClfofreq 18
    #define CCvol 25
    /*
    static byte muxInput = 0;
    static int mux1ValuesPrev[MUXCHANNELS] = {};
    static int mux2ValuesPrev[MUXCHANNELS] = {};
    
    static int mux1Read = 0;
    static int mux2Read = 0;
    //static int volumeRead = 0;
    //static int volumePrevious = 0;
    
    void setupHardware()
    {
      //Mux address pins
      
      pinMode(MUX1, INPUT);
      pinMode(MUX2, INPUT);
      
      pinMode(MUX_S0, OUTPUT);
      pinMode(MUX_S1, OUTPUT);
      pinMode(MUX_S2, OUTPUT);
      pinMode(MUX_S3, OUTPUT);
      }      */                           
    extern const int16_t myWaveform[256];  // defined in myWaveform.ino
    
    #define POLYPHONY 8  // Max # simultaneous notes
    #define WAVEFORM WAVEFORM_SAWTOOTH
    
    byte notesSounding[POLYPHONY] = {0};
    
    void myControlChange(byte channel, byte control, byte value){//LPD 8 CONTROL SURFACE// SERIAL BUTTON SWITCH
     /* if (control == CCcutoff) {        //CUTOFF    
        cutoff = 1000* (value/127);  
      }*/
      if (control == CCreso) {        //RESO
        reso = (value / 29.53)+1.11;
          
      }
      if (control == CCrevol) {             //REVERB VOL
        revol = (value / 381.00);         
      }
      if (control == CCrsize) {            //REVERB SIZE
        rsize = (value / 254.00);         
      } 
                            //ADSR                            
      if (control == CCatk) {           //A
        atk = pow(value, 1.70);          
      }
      if (control == CCdcy) {           //D
        dcy = pow(value, 1.70);           
      }
      if (control == CCsus) {           //S
        sus = (value / 127.00);        
      }
      if (control == CCrls) {           //R
        rls = pow(value, 1.91);             
      }
                           //ADSR VCF
      if (control == CCatkf) {            //A  
        atkf = pow(value, 1.70);             
      }
      if (control == CCdcyf) {           //D
        dcyf = pow(value, 1.70);        
      }
      if (control == CCsusf) {           //S
        susf = (value / 127.00);        
      }
      if (control == CCrlsf) {           //R
        rlsf = pow(value, 1.91);        
      }                              
      if (control == CCmd) {            // MOD DEPTH
        md = (value / 127.00);          
      }  
      if (control == CCphs) {            //PHASE 
         phs = (value / 254.00);
      }
      if (control == CCswc) {             // SWITCH
        swc = value;}
      if (control == CCswc2) {             // SWITCH LFO
        swc2 = value;}  
      if (control == CCnse1) {             // NOISE 
        nse1 = (value/254.00);}
      if (control == CCpnk1) {             // PINK 
        pnk1 = (value/254.00);}    
      if (control == CCamp2) {             //3 and 4 OSC VOL's
        amp2 = (value / 254.00);}   
      if (control == CCshpwm) {            //SHAPE WAVEFORM
        shpwm = (value / 127.000);}  
      if (control == CCshpwm2) {            //LFO SHAPE WAVEFORM
        shpwm2 = (value / 127.000);} 
      if (control == CClfoamp) {            //LFO AMOUNT
        lfoamp = (value / 127.00);} 
      if (control == CClfoamp) {            //LFO FILTER AMOUNT
        lfoampf = (value / 127.00);} 
      if (control == CClfofreq) {            //LFO FREQ
        lfofreq = pow(value, 2.04);}
           if (srlswc == HIGH){                                   //TASTO SWITCH SERIALE
      
      Serial.print("CC, ch=");
      Serial.print(channel);
      Serial.print(", ctrl= ");
      Serial.print(control);
      Serial.print(", value=");
      Serial.print(value);
    
      Serial.print("   A=");
      Serial.print(atk);
      Serial.print("   D=");
      Serial.print(dcy);
      Serial.print("   S=");
      Serial.print(sus);
      Serial.print("   R=");
      Serial.print(rls);
      
      Serial.print("   Af=");
      Serial.print(atkf);
      Serial.print("   Df=");
      Serial.print(dcyf);
      Serial.print("   Sf=");
      Serial.print(susf);
      Serial.print("   Rf=");
      Serial.print(rlsf);
      Serial.print("  SWC=");
      Serial.print(swc);
      Serial.print("  SWC2=");
      Serial.print(swc2);
      Serial.println();
           }
           if (srlswc == LOW){
          if(swc <= 14){
          Serial.print ("WAVEFORM = SINE ");
          Serial.println ();}
          if(swc > 14 && swc <= 28){
          Serial.print ("WAVEFORM = TRIANGLE ");
          Serial.println ();}
          if(swc > 28 && swc <= 42){
          Serial.print ("WAVEFORM = TRIANGLE VAR ");
          Serial.println ();}
          if(swc > 42 && swc <= 56){
          Serial.print ("WAVEFORM = SAWTOOTH ");
          Serial.println ();}
          if(swc > 56 && swc <= 70){
          Serial.print ("WAVEFORM = SAWTOOTH REV ");
          Serial.println ();}
          if(swc > 70 && swc <= 84){
          Serial.print ("WAVEFORM = SQUARE ");
          Serial.println ();}
          if(swc > 84 && swc <= 98){
          Serial.print ("WAVEFORM = PULSE ");
          Serial.println ();}
          if(swc > 98 && swc <= 113){
          Serial.print ("WAVEFORM = ARBITRARY ");
          Serial.println ();}
          if(swc > 113 && swc <= 127){
          Serial.print ("WAVEFORM = SAMPLE&HOLD ");
          Serial.println ();}
          
             if(swc2 <= 14){
          Serial.print ("LFO = SINE ");
          Serial.println ();}
          if(swc2 > 14 && swc2 <= 28){
          Serial.print ("LFO = TRIANGLE ");
          Serial.println ();}
          if(swc2 > 28 && swc2 <= 42){
          Serial.print ("LFO = TRIANGLE VAR ");
          Serial.println ();}
          if(swc2 > 42 && swc2 <= 56){
          Serial.print ("LFO = SAWTOOTH ");
          Serial.println ();}
          if(swc2 > 56 && swc2 <= 70){
          Serial.print ("LFO = SAWTOOTH REV ");
          Serial.println ();}
          if(swc2 > 70 && swc2 <= 84){
          Serial.print ("LFO = SQUARE ");
          Serial.println ();}
          if(swc2 > 84 && swc2 <= 98){
          Serial.print ("LFO = PULSE ");
          Serial.println ();}
          if(swc2 > 98 && swc2 <= 113){
          Serial.print ("LFO = ARBITRARY ");
          Serial.println ();}
          if(swc2 > 113 && swc2 <= 127){
          Serial.print ("LFO = SAMPLE&HOLD ");
          Serial.println ();}
          
               Serial.print("CUTOFF=");
               Serial.print(cutoff);
               Serial.print("   Q=");
               Serial.print(reso);
               Serial.print("  MOD DEPTH=");
               Serial.print(md);
               Serial.print("   REV VOL=");
               Serial.print(revol);
               Serial.print("   REV SIZE=");
               Serial.print(rsize);
               Serial.print("   NOISE=");
               Serial.print(nse1);
               Serial.print("   PINK=");
               Serial.print(pnk1);
               Serial.print("  =");
               Serial.print(phs);
               Serial.print("  V's=");
               Serial.print(amp2);
               Serial.print("  pwm=");
               Serial.print(shpwm);
               Serial.print("  LFO pwm=");
               Serial.print(shpwm2);
               Serial.print("  LFO FREQ=");
               Serial.print(lfofreq);
               Serial.print("  LFO AMOUNT=");
               Serial.print(lfoamp);
               Serial.println();
        }
      }
    AudioSynthWaveformModulated *waveforms[POLYPHONY] = {
      &waveformMod1,
      &waveformMod2,
      &waveformMod3,
      &waveformMod4,
      &waveformMod5,
      &waveformMod6,
      &waveformMod7,
      &waveformMod8
    };
    AudioEffectEnvelope *envelopes[POLYPHONY] = {
      &envelope1,
      &envelope2,
      &envelope3,
      &envelope4,
      &envelope5,
      &envelope6,
      &envelope7,
      &envelope8
    };
    byte currentNote = 0;
    double noteToFrequency(byte note) {
      return 440.0 * pow(2, ((note - 69.0) / 12.0));
    }
    byte getFreeWaveform() {
      for (byte i = 0; i < POLYPHONY; i++) {
        if (notesSounding[i] == 0) {
          return i;
        }
      }
        
      return 0;
    }
    
    void onNoteOn(byte channel, byte note, byte velocity) {       // VELOCITY
        vely = (velocity / 181.42)+0.07;                      
     
       
      envelope9.noteOn();
      envelope10.noteOn();
      
      byte index = getFreeWaveform();
      
      
      AudioSynthWaveformModulated *waveform = waveforms[index];
      waveform->frequency(noteToFrequency(note));
      
      AudioEffectEnvelope *envelope = envelopes[index];
      envelope->noteOn();
        
      notesSounding[index] = note;
    
      hz2  = 440 * pow (2.0, ((note +  7) - 69.0) / 12.0); 
    
      if (srlswc == HIGH){
      Serial.print("ON,       ch=");
      Serial.print(channel);
      Serial.print(", note=");
      Serial.print(note);
      Serial.print(", velocity=");
      Serial.print(velocity);
      Serial.print(", vely=");
      Serial.print(vely);
      Serial.println();
      }
    }
    void onNoteOff(byte channel, byte note, byte velocity) {
    
      envelope9.noteOff();
      envelope10.noteOff();
      
      for (byte i = 0; i < POLYPHONY; i++) {
        if (notesSounding[i] == note) {
          AudioEffectEnvelope *envelope = envelopes[i];
          envelope->noteOff();
          notesSounding[i] = 0;
        }
      }
                                               //SERIAL
      if (srlswc == HIGH){
      Serial.print("OFF,     ch=");
      Serial.print(channel);
      Serial.print(", note=");
      Serial.print(note);
      Serial.print(", velocity=");
      Serial.print(velocity);
      Serial.println();
      
    }
    }
    void setup() {                 //                     S  E  T  U  P
    
    
      //dacs1.analogReference(EXTERNAL);
      
      //pinMode(24, INPUT_PULLUP);
      Serial.begin(38400);
      AudioMemory(20);
     //set initial volume
      mixer5.gain(1, 0.3);
      mixer6.gain(1, 0.3);
    
      
      //setupHardware();
      
      mixer8.gain(2, 0.0);
      mixer8.gain(3, 0.0);
    
      waveformMod1.arbitraryWaveform(myWaveform, 172.0);
      waveformMod2.arbitraryWaveform(myWaveform, 172.0);
      waveformMod3.arbitraryWaveform(myWaveform, 172.0);
      waveformMod4.arbitraryWaveform(myWaveform, 172.0);
      waveformMod5.arbitraryWaveform(myWaveform, 172.0);
      waveformMod6.arbitraryWaveform(myWaveform, 172.0);
      waveformMod7.arbitraryWaveform(myWaveform, 172.0);
      waveformMod8.arbitraryWaveform(myWaveform, 172.0);
      waveformMod9.arbitraryWaveform(myWaveform, 172.0);
      
      for (byte i = 0; i < POLYPHONY; i++) {
        waveforms[i]->amplitude(0.5);
        waveforms[i]->begin(WAVEFORM);
        envelopes[i]->delay(0.0);
        envelopes[i]->hold(0.0);
      }
    
      envelope9.delay(0);
      envelope9.hold(0);
      envelope10.delay(0);
      envelope10.hold(0);
      usbMIDI.begin();
      usbMIDI.setHandleControlChange(myControlChange);
      usbMIDI.setHandleNoteOn(onNoteOn);
      usbMIDI.setHandleNoteOff(onNoteOff);
     MIDI.begin();
     MIDI.setHandleNoteOn(onNoteOn);
     MIDI.setHandleNoteOff(onNoteOff);
     MIDI.setHandleControlChange(myControlChange);
    
      delay1.disable(1);
      delay1.disable(2);
      delay1.disable(3);
      delay1.disable(4);
      delay1.disable(5);
      delay1.disable(6);
      delay1.disable(7);
    
      freeverbs1.damping(1.0);
      filter1.octaveControl(24);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.32);
    }
    
    
    void loop() {                        //                L   O   O   P
    
    
      float cutoffknob = analogRead(A3);
       float cutoff = cutoffknob;
       /*int resoknob = analogRead (A2);
       float reso = (float)resoknob;*/
       srlswc = digitalRead(24);
     
      
       if(swc <= 14){                    // SINE
        wavfrm = WAVEFORM_SINE;}
        if(swc > 14 && swc <= 28){        //TRIANGLE
        wavfrm = WAVEFORM_TRIANGLE;}
        if(swc > 28 && swc <= 42){        //TRIANGLE VAR
        wavfrm = WAVEFORM_TRIANGLE_VARIABLE;}
        if(swc > 42 && swc <= 56){        //SAWTOOTH
        wavfrm = WAVEFORM_SAWTOOTH;}
        if(swc > 56 && swc <= 70){        //SAWTOOTH REV
        wavfrm = WAVEFORM_SAWTOOTH_REVERSE;}
        if(swc > 70 && swc <= 84){        //SQUARE
        wavfrm = WAVEFORM_SQUARE;}
        if(swc > 84 && swc <= 98){        //PULSE
        wavfrm = WAVEFORM_PULSE;}
        if(swc > 98 && swc <= 113){       //ARBITRARY
        wavfrm = WAVEFORM_ARBITRARY;}
        if(swc > 113 && swc <= 127){      //SAMPLE&HOLD
        wavfrm = WAVEFORM_SAMPLE_HOLD;}
                                                                     //LFO SHAPE
        if(swc2 <= 14){                    // SINE
        wavfrm2 = WAVEFORM_SINE;}
        if(swc2 > 14 && swc2 <= 28){        //TRIANGLE
        wavfrm2 = WAVEFORM_TRIANGLE;}
        if(swc2 > 28 && swc2 <= 42){        //TRIANGLE VAR
        wavfrm2 = WAVEFORM_TRIANGLE_VARIABLE;}
        if(swc2 > 42 && swc2 <= 56){        //SAWTOOTH
        wavfrm2 = WAVEFORM_SAWTOOTH;}
        if(swc2 > 56 && swc2 <= 70){        //SAWTOOTH REV
        wavfrm2 = WAVEFORM_SAWTOOTH_REVERSE;}
        if(swc2 > 70 && swc2 <= 84){        //SQUARE
        wavfrm2 = WAVEFORM_SQUARE;}
        if(swc2 > 84 && swc2 <= 98){        //PULSE
        wavfrm2 = WAVEFORM_PULSE;}
        if(swc2 > 98 && swc2 <= 113){       //ARBITRARY
        wavfrm2 = WAVEFORM_ARBITRARY;}
        if(swc2 > 113 && swc2 <= 127){      //SAMPLE&HOLD
        wavfrm2 = WAVEFORM_SAMPLE_HOLD;}
    
      waveformMod9.begin(0.3, 440, wavfrm);  //loader waveform
      waveformMod9.frequency(hz2);
      waveformMod9.amplitude(amp2);
    
      waveformMod10.begin(0.3, 440, wavfrm2);
      waveformMod10.frequency(lfofreq);
      waveformMod10.amplitude(lfoamp);
      
      waveformMod11.begin(0.3, 440, wavfrm2);
      waveformMod11.frequency(lfofreq);
      waveformMod11.amplitude(lfoampf);
      mixer8.gain(0, lfoampf);
      
      envelope1.attack(atk);
      envelope1.decay(dcy);
      envelope1.sustain(sus);
      envelope1.release(rls);
      
      envelope2.attack(atk);
      envelope2.decay(dcy);
      envelope2.sustain(sus);
      envelope2.release(rls);
    
      envelope3.attack(atk);
      envelope3.decay(dcy);
      envelope3.sustain(sus);
      envelope3.release(rls);
    
      envelope4.attack(atk);
      envelope4.decay(dcy);
      envelope4.sustain(sus);
      envelope4.release(rls);
    
      envelope5.attack(atk);
      envelope5.decay(dcy);
      envelope5.sustain(sus);
      envelope5.release(rls);
    
      envelope6.attack(atk);
      envelope6.decay(dcy);
      envelope6.sustain(sus);
      envelope6.release(rls);  
    
      envelope7.attack(atk);
      envelope7.decay(dcy);
      envelope7.sustain(sus);
      envelope7.release(rls);  
    
      envelope8.attack(atk);
      envelope8.decay(dcy);
      envelope8.sustain(sus);
      envelope8.release(rls);
    
      envelope9.attack(atk);
      envelope9.decay(dcy);
      envelope9.sustain(sus);
      envelope9.release(rls);  
    
      envelope10.attack(atkf);
      envelope10.decay(dcyf);
      envelope10.sustain(susf);
      envelope10.release(rlsf);  
    
      filter1.frequency(cutoff);
      filter1.resonance(reso);
             
    
      delay1.delay(0,phs);      //stereoize
      
      dc1.amplitude(shpwm);     //pwm
      dc3.amplitude(shpwm2);    //Lfo waveform pwm
      dc2.amplitude(md);        //mod depth env 
    
      pink1.amplitude(pnk1);
      noise1.amplitude(nse1);
      freeverbs1.roomsize(rsize);
      mixer5.gain(0, revol);
      mixer6.gain(0, revol);
    
      
        
        for (byte i = 0; i < POLYPHONY; i++) {
         waveforms[i]->begin(wavfrm);
         waveforms[i]->amplitude(vely); 
        }
       
      usbMIDI.read();
    }

  2. #2
    hi benwadub,
    looks like basically what you're doing is this:
    Code:
      float cutoffknob = analogRead(A3);
      filter1.frequency(cutoffknob);
    analogRead(A3) will return the raw ADC value, and that probably won't match perfectly to a frequency range you're looking for. If you're reading it at 10 bit resolution, analogRead(A3) will return 0-1023, which means the filter will only open until 1khz.
    you can multiply it by 10, for example, to get a linear response to 10khz, or you can try for an exponential response.
    hope this helps!

  3. #3
    Thanks for you answer so if I want to have a response from 20khz to 0 when fully closed how could it be written please? I learn code since few month but I learn alone and it s not very easy!

  4. #4
    Explore map() and for float values have a look around for float versions of map() that various folks have posted. You typically use in the form
    Code:
    dest = map(reading, lowest_reading, highest_reading, lowest_output, highest_output)
    So perhaps:
    Code:
    reading = 731 // in 0 .. 1023 range
    dest = map(reading, 0, 1023, 0, 20000);
    which would map a reading between 0 and 1023 to an output range of 0..20000. (in this case the destination would be set to 14,291 in fact).

    (of course a function like map() is linear - you might actually want to have a logarithmic mapping - that would be more tricky to achieve).

  5. #5
    Wow thank you very much for your help!!

  6. #6
    hi, so I just tried with map
    Code:
    filter1.frequency(cutoff);
    cutoff = map(analogRead(A3),0, 1023, 0, 20000);
    but I still don t have the total range of frequency with my knob, it cut sound at around the half of the pot
    sorry for my approximative English :-)

  7. #7
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    228
    in your latest post you have code in wrong order should be:
    Code:
    cutoff = map(analogRead(A3),0, 1023, 0, 20000);
    filter1.frequency(cutoff);

    I think its very unnecessary to use the map function in this situation
    better just to do
    which gives you a range of 0-20460 Hz with 20Hz increments
    Code:
    int cutoff = analogRead(A3) * 20; 
    filter1.frequency((float)cutoff);
    the map function gives you increments of 20000/1023 = ~19.5503421309873

    also the map function could be used when you want to do "complicated" things
    like
    cutoff = map(analogRead(A3),0, 1023, 16, 20000);


    also you did analog read to a float without casting, this is never a good idea.

    it should be in that case:
    Code:
    float cutoffknob = (float)analogRead(A3);
    float cutoff = cutoffknob; // don't know why you are using cutoffknob it's never used somewhere else

    also if you still want to use the map function
    here is the float function of that
    Code:
    float mapf(float x, float in_min, float in_max, float out_min, float out_max)
    {
        return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
    }

  8. #8
    I still have the same problem, maybe there is something else wrong in the code?
    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <MIDI.h>  
    #include <SerialFlash.h>
    #include <Bounce.h>
    // GUItool: begin automatically generated code
    AudioSynthWaveformDc     dc1;            //xy=55,229.9999976158142
    AudioSynthWaveformModulated waveformMod9;   //xy=228.57149451119562,475.7143028804235
    AudioSynthWaveformModulated waveformMod3;   //xy=231.42856979370117,176.85713577270508
    AudioSynthWaveformModulated waveformMod4;   //xy=231.42856979370117,211.85713577270508
    AudioSynthWaveformModulated waveformMod5;   //xy=231.42858123779297,255.42856407165527
    AudioSynthWaveformModulated waveformMod6;   //xy=231.42858123779297,290.4285640716553
    AudioSynthWaveformModulated waveformMod7;   //xy=231.42858123779297,325.4285640716553
    AudioSynthWaveformModulated waveformMod8;   //xy=231.42858123779297,362.4285640716553
    AudioSynthWaveformModulated waveformMod2;   //xy=232.42856979370117,139.85713577270508
    AudioSynthWaveformModulated waveformMod1;   //xy=233.42856979370117,102.85713577270508
    AudioSynthNoiseWhite     noise1;         //xy=235.71430587768555,527.1428508758545
    AudioSynthNoisePink      pink1;          //xy=244.28573608398438,571.4285678863525
    AudioEffectEnvelope      envelope7;      //xy=410.4285697937012,325.8571357727051
    AudioEffectEnvelope      envelope6;      //xy=414.4285697937012,289.8571357727051
    AudioEffectEnvelope      envelope1;      //xy=415.4285697937012,102.85713577270508
    AudioEffectEnvelope      envelope5;      //xy=415.4285697937012,254.85713577270508
    AudioEffectEnvelope      envelope8;      //xy=415.4285697937012,362.8571357727051
    AudioEffectEnvelope      envelope2;      //xy=416.4285697937012,139.85713577270508
    AudioEffectEnvelope      envelope4;      //xy=416.4285697937012,216.85713577270508
    AudioEffectEnvelope      envelope3;      //xy=417.4285697937012,178.85713577270508
    AudioMixer4              mixer4;         //xy=438.5714530944824,517.1428680419922
    AudioEffectEnvelope      envelope9;      //xy=601.4286117553711,477.1428565979004
    AudioMixer4              mixer1;         //xy=619.4285697937012,171.85713577270508
    AudioMixer4              mixer2;         //xy=625.4285697937012,282.8571357727051
    AudioSynthWaveformDc     dc2;            //xy=625.1072998046875,421.3571472167969
    AudioSynthWaveformDc     dc3;            //xy=647,79.25
    AudioEffectEnvelope      envelope10;     //xy=786.46435546875,411.857177734375
    AudioSynthWaveformModulated waveformMod11;  //xy=794,329
    AudioMixer4              mixer3;         //xy=806.7858390808105,194.64279556274414
    AudioSynthWaveformModulated waveformMod10;  //xy=827.75,98.74999904632568
    AudioMixer4              mixer8;         //xy=958,343
    AudioEffectMultiply      multiply1;      //xy=1055.0000038146973,74.24999976158142
    AudioFilterStateVariable filter1;        //xy=1091.5714111328125,283.00006103515625
    AudioMixer4              mixer7;         //xy=1283.7500190734863,245.00000190734863
    AudioEffectDelay         delay1;         //xy=1491.1905250549316,414.9405460357666
    AudioEffectFreeverbStereo freeverbs1;     //xy=1511.190486907959,253.51194190979004
    AudioMixer4              mixer5;         //xy=1671.1904525756836,140.65477180480957
    AudioMixer4              mixer6;         //xy=1672.6188468933105,363.5119228363037
    AudioOutputAnalogStereo  dacs1;          //xy=1821.4761123657227,290.65477991104126
    AudioOutputUSB           usb1;
    AudioConnection          patchCord1(dc1, 0, waveformMod1, 1);
    AudioConnection          patchCord2(dc1, 0, waveformMod2, 1);
    AudioConnection          patchCord3(dc1, 0, waveformMod3, 1);
    AudioConnection          patchCord4(dc1, 0, waveformMod4, 1);
    AudioConnection          patchCord5(dc1, 0, waveformMod5, 1);
    AudioConnection          patchCord6(dc1, 0, waveformMod6, 1);
    AudioConnection          patchCord7(dc1, 0, waveformMod7, 1);
    AudioConnection          patchCord8(dc1, 0, waveformMod8, 1);
    AudioConnection          patchCord9(dc1, 0, waveformMod9, 1);
    AudioConnection          patchCord10(waveformMod9, 0, mixer4, 0);
    AudioConnection          patchCord11(waveformMod3, envelope3);
    AudioConnection          patchCord12(waveformMod4, envelope4);
    AudioConnection          patchCord13(waveformMod5, envelope5);
    AudioConnection          patchCord14(waveformMod6, envelope6);
    AudioConnection          patchCord15(waveformMod7, envelope7);
    AudioConnection          patchCord16(waveformMod8, envelope8);
    AudioConnection          patchCord17(waveformMod2, envelope2);
    AudioConnection          patchCord18(waveformMod1, envelope1);
    AudioConnection          patchCord19(noise1, 0, mixer4, 1);
    AudioConnection          patchCord20(pink1, 0, mixer4, 2);
    AudioConnection          patchCord21(envelope7, 0, mixer2, 2);
    AudioConnection          patchCord22(envelope6, 0, mixer2, 1);
    AudioConnection          patchCord23(envelope1, 0, mixer1, 0);
    AudioConnection          patchCord24(envelope5, 0, mixer2, 0);
    AudioConnection          patchCord25(envelope8, 0, mixer2, 3);
    AudioConnection          patchCord26(envelope2, 0, mixer1, 1);
    AudioConnection          patchCord27(envelope4, 0, mixer1, 3);
    AudioConnection          patchCord28(envelope3, 0, mixer1, 2);
    AudioConnection          patchCord29(mixer4, envelope9);
    AudioConnection          patchCord30(envelope9, 0, mixer3, 2);
    AudioConnection          patchCord31(mixer1, 0, mixer3, 0);
    AudioConnection          patchCord32(mixer2, 0, mixer3, 1);
    AudioConnection          patchCord33(dc2, envelope10);
    AudioConnection          patchCord34(dc3, 0, waveformMod10, 1);
    AudioConnection          patchCord35(dc3, 0, waveformMod11, 1);
    AudioConnection          patchCord36(envelope10, 0, mixer8, 1);
    AudioConnection          patchCord37(waveformMod11, 0, mixer8, 0);
    AudioConnection          patchCord38(mixer3, 0, filter1, 0);
    AudioConnection          patchCord39(waveformMod10, 0, multiply1, 1);
    AudioConnection          patchCord40(mixer8, 0, filter1, 1);
    AudioConnection          patchCord41(multiply1, 0, mixer7, 0);
    AudioConnection          patchCord42(filter1, 0, multiply1, 0);
    AudioConnection          patchCord43(filter1, 0, mixer7, 1);
    AudioConnection          patchCord44(mixer7, freeverbs1);
    AudioConnection          patchCord45(mixer7, delay1);
    AudioConnection          patchCord46(mixer7, 0, mixer5, 1);
    AudioConnection          patchCord47(delay1, 0, mixer6, 1);
    AudioConnection          patchCord48(freeverbs1, 0, mixer5, 0);
    AudioConnection          patchCord49(freeverbs1, 1, mixer6, 0);
    //AudioConnection          patchCord50(mixer5, 0, dacs1, 0);
    //AudioConnection          patchCord51(mixer6, 0, dacs1, 1);
    AudioConnection          patchCord52(mixer5, 0, usb1, 0);
    AudioConnection          patchCord53(mixer6, 0, usb1, 1);
    AudioControlSGTL5000  sgtl5000_1;
    // GUItool: end automatically generated code
    
    MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
    
    /**
     * End generated code block
     */
    
    float hz2;
    float cutoff;
    float reso = 1.11;
    float revol = 0;
    float rsize = 0.1;
    float atk = 10.5;
    float dcy = 35;
    float sus = 0.5;
    float rls = 300;
    float atkf = 10.5;
    float dcyf = 35;
    float susf = 0.5;
    float rlsf = 300;
    float md = 0.0;
    float phs = 0;
    int swc = 0;
    int swc2 = 0;
    int wavfrm;
    int wavfrm2;
    int srlswc = 0;
    float nse1 = 0.0;
    float pnk1 = 0.0;
    float amp2 = 0.00;
    float vely = 0.00;
    float shpwm = 0.00;
    float shpwm2 = 0.00;
    float lfofreq = 0.00;
    float lfoamp = 0.00;
    float lfoampf = 0.00;
    int valueconvert;
    
    #include <Bounce.h>
    //teensy 3.6 mux pins
    
    //MIDI CC control numbers
    #define CCcutoff 1
    #define CCreso 2
    #define CCrevol 19
    #define CCrsize 20
    #define CCatk 13
    #define CCdcy 14
    #define CCsus 15
    #define CCrls 16
    #define CCatkf 9
    #define CCdcyf 10
    #define CCsusf 11
    #define CCrlsf 12
    #define CCmd 3
    #define CCphs 4
    #define CCswc 5//switch lfo
    #define CCswc2 22//noise
    #define CCnse1 6
    #define CCpnk1 7
    #define CCamp2 8//vol osc
    #define CCshpwm 24//shape waveform
    #define CCshpwm2 23//lfo waveform
    #define CClfoamp 17//lfo amnt
    #define CClfofreq 18
    #define CCvol 25
    
                              
    extern const int16_t myWaveform[256];  // defined in myWaveform.ino
    
    #define POLYPHONY 8  // Max # simultaneous notes
    #define WAVEFORM WAVEFORM_SAWTOOTH
    
    byte notesSounding[POLYPHONY] = {0};
    
    void myControlChange(byte channel, byte control, byte value){//LPD 8 CONTROL SURFACE// SERIAL BUTTON SWITCH
      if (control == CCcutoff) {        //CUTOFF    
        cutoff = (pow(value, 2.04))+20;  
      }
      if (control == CCreso) {        //RESO
        reso = (value / 29.53)+1.11;
      }
      if (control == CCrevol) {             //REVERB VOL
        revol = (value / 381.00);         
      }
      if (control == CCrsize) {            //REVERB SIZE
        rsize = (value / 254.00);         
      } 
                            //ADSR                            
      if (control == CCatk) {           //A
        atk = pow(value, 1.70);          
      }
      if (control == CCdcy) {           //D
        dcy = pow(value, 1.70);           
      }
      if (control == CCsus) {           //S
        sus = (value / 127.00);        
      }
      if (control == CCrls) {           //R
        rls = pow(value, 1.91);             
      }
                           //ADSR VCF
      if (control == CCatkf) {            //A  
        atkf = pow(value, 1.70);             
      }
      if (control == CCdcyf) {           //D
        dcyf = pow(value, 1.70);        
      }
      if (control == CCsusf) {           //S
        susf = (value / 127.00);        
      }
      if (control == CCrlsf) {           //R
        rlsf = pow(value, 1.91);        
      }                              
      if (control == CCmd) {            // MOD DEPTH
        md = (value / 127.00);          
      }  
      if (control == CCphs) {            //PHASE 
         phs = (value / 254.00);
      }
      if (control == CCswc) {             // SWITCH
        swc = value;}
      if (control == CCswc2) {             // SWITCH LFO
        swc2 = value;}  
      if (control == CCnse1) {             // NOISE 
        nse1 = (value/254.00);}
      if (control == CCpnk1) {             // PINK 
        pnk1 = (value/254.00);}    
      if (control == CCamp2) {             //3 and 4 OSC VOL's
        amp2 = (value / 254.00);}   
      if (control == CCshpwm) {            //SHAPE WAVEFORM
        shpwm = (value / 127.000);}  
      if (control == CCshpwm2) {            //LFO SHAPE WAVEFORM
        shpwm2 = (value / 127.000);} 
      if (control == CClfoamp) {            //LFO AMOUNT
        lfoamp = (value / 127.00);} 
      if (control == CClfoamp) {            //LFO FILTER AMOUNT
        lfoampf = (value / 127.00);} 
      if (control == CClfofreq) {            //LFO FREQ
        lfofreq = pow(value, 2.04);}
           if (srlswc == HIGH){                                   //TASTO SWITCH SERIALE
      
      Serial.print("CC, ch=");
      Serial.print(channel);
      Serial.print(", ctrl= ");
      Serial.print(control);
      Serial.print(", value=");
      Serial.print(value);
    
      Serial.print("   A=");
      Serial.print(atk);
      Serial.print("   D=");
      Serial.print(dcy);
      Serial.print("   S=");
      Serial.print(sus);
      Serial.print("   R=");
      Serial.print(rls);
      
      Serial.print("   Af=");
      Serial.print(atkf);
      Serial.print("   Df=");
      Serial.print(dcyf);
      Serial.print("   Sf=");
      Serial.print(susf);
      Serial.print("   Rf=");
      Serial.print(rlsf);
      Serial.print("  SWC=");
      Serial.print(swc);
      Serial.print("  SWC2=");
      Serial.print(swc2);
      Serial.println();
           }
           if (srlswc == LOW){
          if(swc <= 14){
          Serial.print ("WAVEFORM = SINE ");
          Serial.println ();}
          if(swc > 14 && swc <= 28){
          Serial.print ("WAVEFORM = TRIANGLE ");
          Serial.println ();}
          if(swc > 28 && swc <= 42){
          Serial.print ("WAVEFORM = TRIANGLE VAR ");
          Serial.println ();}
          if(swc > 42 && swc <= 56){
          Serial.print ("WAVEFORM = SAWTOOTH ");
          Serial.println ();}
          if(swc > 56 && swc <= 70){
          Serial.print ("WAVEFORM = SAWTOOTH REV ");
          Serial.println ();}
          if(swc > 70 && swc <= 84){
          Serial.print ("WAVEFORM = SQUARE ");
          Serial.println ();}
          if(swc > 84 && swc <= 98){
          Serial.print ("WAVEFORM = PULSE ");
          Serial.println ();}
          if(swc > 98 && swc <= 113){
          Serial.print ("WAVEFORM = ARBITRARY ");
          Serial.println ();}
          if(swc > 113 && swc <= 127){
          Serial.print ("WAVEFORM = SAMPLE&HOLD ");
          Serial.println ();}
          
             if(swc2 <= 14){
          Serial.print ("LFO = SINE ");
          Serial.println ();}
          if(swc2 > 14 && swc2 <= 28){
          Serial.print ("LFO = TRIANGLE ");
          Serial.println ();}
          if(swc2 > 28 && swc2 <= 42){
          Serial.print ("LFO = TRIANGLE VAR ");
          Serial.println ();}
          if(swc2 > 42 && swc2 <= 56){
          Serial.print ("LFO = SAWTOOTH ");
          Serial.println ();}
          if(swc2 > 56 && swc2 <= 70){
          Serial.print ("LFO = SAWTOOTH REV ");
          Serial.println ();}
          if(swc2 > 70 && swc2 <= 84){
          Serial.print ("LFO = SQUARE ");
          Serial.println ();}
          if(swc2 > 84 && swc2 <= 98){
          Serial.print ("LFO = PULSE ");
          Serial.println ();}
          if(swc2 > 98 && swc2 <= 113){
          Serial.print ("LFO = ARBITRARY ");
          Serial.println ();}
          if(swc2 > 113 && swc2 <= 127){
          Serial.print ("LFO = SAMPLE&HOLD ");
          Serial.println ();}
          
               Serial.print("CUTOFF=");
               Serial.print(cutoff);
               Serial.print("   Q=");
               Serial.print(reso);
               Serial.print("  MOD DEPTH=");
               Serial.print(md);
               Serial.print("   REV VOL=");
               Serial.print(revol);
               Serial.print("   REV SIZE=");
               Serial.print(rsize);
               Serial.print("   NOISE=");
               Serial.print(nse1);
               Serial.print("   PINK=");
               Serial.print(pnk1);
               Serial.print("  =");
               Serial.print(phs);
               Serial.print("  V's=");
               Serial.print(amp2);
               Serial.print("  pwm=");
               Serial.print(shpwm);
               Serial.print("  LFO pwm=");
               Serial.print(shpwm2);
               Serial.print("  LFO FREQ=");
               Serial.print(lfofreq);
               Serial.print("  LFO AMOUNT=");
               Serial.print(lfoamp);
               Serial.println();
        }
      }
    AudioSynthWaveformModulated *waveforms[POLYPHONY] = {
      &waveformMod1,
      &waveformMod2,
      &waveformMod3,
      &waveformMod4,
      &waveformMod5,
      &waveformMod6,
      &waveformMod7,
      &waveformMod8
    };
    AudioEffectEnvelope *envelopes[POLYPHONY] = {
      &envelope1,
      &envelope2,
      &envelope3,
      &envelope4,
      &envelope5,
      &envelope6,
      &envelope7,
      &envelope8
    };
    byte currentNote = 0;
    double noteToFrequency(byte note) {
      return 440.0 * pow(2, ((note - 69.0) / 12.0));
    }
    byte getFreeWaveform() {
      for (byte i = 0; i < POLYPHONY; i++) {
        if (notesSounding[i] == 0) {
          return i;
        }
      }
        
      return 0;
    }
    
    void onNoteOn(byte channel, byte note, byte velocity) {       // VELOCITY
        vely = (velocity / 181.42)+0.07;                      
     
       
      envelope9.noteOn();
      envelope10.noteOn();
      
      byte index = getFreeWaveform();
      
      
      AudioSynthWaveformModulated *waveform = waveforms[index];
      waveform->frequency(noteToFrequency(note));
      
      AudioEffectEnvelope *envelope = envelopes[index];
      envelope->noteOn();
        
      notesSounding[index] = note;
    
      hz2  = 440 * pow (2.0, ((note +  7) - 69.0) / 12.0); 
    
      if (srlswc == HIGH){
      Serial.print("ON,       ch=");
      Serial.print(channel);
      Serial.print(", note=");
      Serial.print(note);
      Serial.print(", velocity=");
      Serial.print(velocity);
      Serial.print(", vely=");
      Serial.print(vely);
      Serial.println();
      }
    }
    void onNoteOff(byte channel, byte note, byte velocity) {
    
      envelope9.noteOff();
      envelope10.noteOff();
      
      for (byte i = 0; i < POLYPHONY; i++) {
        if (notesSounding[i] == note) {
          AudioEffectEnvelope *envelope = envelopes[i];
          envelope->noteOff();
          notesSounding[i] = 0;
        }
      }
                                               //SERIAL
      if (srlswc == HIGH){
      Serial.print("OFF,     ch=");
      Serial.print(channel);
      Serial.print(", note=");
      Serial.print(note);
      Serial.print(", velocity=");
      Serial.print(velocity);
      Serial.println();
      
    }
    }
    void setup() {                 //                     S  E  T  U  P
    
    
      //dacs1.analogReference(EXTERNAL);
      
      //pinMode(24, INPUT_PULLUP);
      Serial.begin(38400);
      AudioMemory(20);
     //set initial volume
      mixer5.gain(1, 0.3);
      mixer6.gain(1, 0.3);
    
       //setupHardware();
      
      mixer8.gain(2, 0.0);
      mixer8.gain(3, 0.0);
    
      waveformMod1.arbitraryWaveform(myWaveform, 172.0);
      waveformMod2.arbitraryWaveform(myWaveform, 172.0);
      waveformMod3.arbitraryWaveform(myWaveform, 172.0);
      waveformMod4.arbitraryWaveform(myWaveform, 172.0);
      waveformMod5.arbitraryWaveform(myWaveform, 172.0);
      waveformMod6.arbitraryWaveform(myWaveform, 172.0);
      waveformMod7.arbitraryWaveform(myWaveform, 172.0);
      waveformMod8.arbitraryWaveform(myWaveform, 172.0);
      waveformMod9.arbitraryWaveform(myWaveform, 172.0);
      
      for (byte i = 0; i < POLYPHONY; i++) {
        waveforms[i]->amplitude(0.5);
        waveforms[i]->begin(WAVEFORM);
        envelopes[i]->delay(0.0);
        envelopes[i]->hold(0.0);
      }
    
      envelope9.delay(0);
      envelope9.hold(0);
      envelope10.delay(0);
      envelope10.hold(0);
      usbMIDI.begin();
      usbMIDI.setHandleControlChange(myControlChange);
      usbMIDI.setHandleNoteOn(onNoteOn);
      usbMIDI.setHandleNoteOff(onNoteOff);
     MIDI.begin();
     MIDI.setHandleNoteOn(onNoteOn);
     MIDI.setHandleNoteOff(onNoteOff);
     MIDI.setHandleControlChange(myControlChange);
    
      delay1.disable(1);
      delay1.disable(2);
      delay1.disable(3);
      delay1.disable(4);
      delay1.disable(5);
      delay1.disable(6);
      delay1.disable(7);
    
      freeverbs1.damping(1.0);
      filter1.octaveControl(24);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.32);
    }
    
    
    void loop() {                        //                L   O   O   P
    
     
      int cutoff = analogRead(A3) *20;
       //float cutoff = cutoffknob;
       /*int resoknob = analogRead (A2);
       float reso = (float)resoknob;*/
       srlswc = digitalRead(24);
     
         if(swc <= 14){                    // SINE
        wavfrm = WAVEFORM_SINE;}
        if(swc > 14 && swc <= 28){        //TRIANGLE
        wavfrm = WAVEFORM_TRIANGLE;}
        if(swc > 28 && swc <= 42){        //TRIANGLE VAR
        wavfrm = WAVEFORM_TRIANGLE_VARIABLE;}
        if(swc > 42 && swc <= 56){        //SAWTOOTH
        wavfrm = WAVEFORM_SAWTOOTH;}
        if(swc > 56 && swc <= 70){        //SAWTOOTH REV
        wavfrm = WAVEFORM_SAWTOOTH_REVERSE;}
        if(swc > 70 && swc <= 84){        //SQUARE
        wavfrm = WAVEFORM_SQUARE;}
        if(swc > 84 && swc <= 98){        //PULSE
        wavfrm = WAVEFORM_PULSE;}
        if(swc > 98 && swc <= 113){       //ARBITRARY
        wavfrm = WAVEFORM_ARBITRARY;}
        if(swc > 113 && swc <= 127){      //SAMPLE&HOLD
        wavfrm = WAVEFORM_SAMPLE_HOLD;}
                                                                     //LFO SHAPE
        if(swc2 <= 14){                    // SINE
        wavfrm2 = WAVEFORM_SINE;}
        if(swc2 > 14 && swc2 <= 28){        //TRIANGLE
        wavfrm2 = WAVEFORM_TRIANGLE;}
        if(swc2 > 28 && swc2 <= 42){        //TRIANGLE VAR
        wavfrm2 = WAVEFORM_TRIANGLE_VARIABLE;}
        if(swc2 > 42 && swc2 <= 56){        //SAWTOOTH
        wavfrm2 = WAVEFORM_SAWTOOTH;}
        if(swc2 > 56 && swc2 <= 70){        //SAWTOOTH REV
        wavfrm2 = WAVEFORM_SAWTOOTH_REVERSE;}
        if(swc2 > 70 && swc2 <= 84){        //SQUARE
        wavfrm2 = WAVEFORM_SQUARE;}
        if(swc2 > 84 && swc2 <= 98){        //PULSE
        wavfrm2 = WAVEFORM_PULSE;}
        if(swc2 > 98 && swc2 <= 113){       //ARBITRARY
        wavfrm2 = WAVEFORM_ARBITRARY;}
        if(swc2 > 113 && swc2 <= 127){      //SAMPLE&HOLD
        wavfrm2 = WAVEFORM_SAMPLE_HOLD;}
    
      waveformMod9.begin(0.3, 440, wavfrm);  //loader waveform
      waveformMod9.frequency(hz2);
      waveformMod9.amplitude(amp2);
    
      waveformMod10.begin(0.3, 440, wavfrm2);
      waveformMod10.frequency(lfofreq);
      waveformMod10.amplitude(lfoamp);
      
      waveformMod11.begin(0.3, 440, wavfrm2);
      waveformMod11.frequency(lfofreq);
      waveformMod11.amplitude(lfoampf);
      mixer8.gain(0, lfoampf);
      
      envelope1.attack(atk);
      envelope1.decay(dcy);
      envelope1.sustain(sus);
      envelope1.release(rls);
      
      envelope2.attack(atk);
      envelope2.decay(dcy);
      envelope2.sustain(sus);
      envelope2.release(rls);
    
      envelope3.attack(atk);
      envelope3.decay(dcy);
      envelope3.sustain(sus);
      envelope3.release(rls);
    
      envelope4.attack(atk);
      envelope4.decay(dcy);
      envelope4.sustain(sus);
      envelope4.release(rls);
    
      envelope5.attack(atk);
      envelope5.decay(dcy);
      envelope5.sustain(sus);
      envelope5.release(rls);
    
      envelope6.attack(atk);
      envelope6.decay(dcy);
      envelope6.sustain(sus);
      envelope6.release(rls);  
    
      envelope7.attack(atk);
      envelope7.decay(dcy);
      envelope7.sustain(sus);
      envelope7.release(rls);  
    
      envelope8.attack(atk);
      envelope8.decay(dcy);
      envelope8.sustain(sus);
      envelope8.release(rls);
    
      envelope9.attack(atk);
      envelope9.decay(dcy);
      envelope9.sustain(sus);
      envelope9.release(rls);  
    
      envelope10.attack(atkf);
      envelope10.decay(dcyf);
      envelope10.sustain(susf);
      envelope10.release(rlsf);  
    
      filter1.frequency((float)cutoff);
      filter1.resonance(reso);
             
      delay1.delay(0,phs);      //stereoize
      
      dc1.amplitude(shpwm);     //pwm
      dc3.amplitude(shpwm2);    //Lfo waveform pwm
      dc2.amplitude(md);        //mod depth env 
    
      pink1.amplitude(pnk1);
      noise1.amplitude(nse1);
      freeverbs1.roomsize(rsize);
      mixer5.gain(0, revol);
      mixer6.gain(0, revol);
    
      
        
        for (byte i = 0; i < POLYPHONY; i++) {
         waveforms[i]->begin(wavfrm);
         waveforms[i]->amplitude(vely); 
        }
       
      usbMIDI.read();
    }

  9. #9
    Are you sure the AnalogRead is returning a full sweep 0 to 1023 for complete rotation of the pot. Just Serial.println() the raw value and wind the pot to either end. Is it 0 at one end and 1023 at the other?

    EDIT if you find it is just 213 at the lower end and 724 at the upper (say) then put those as the lower and upper values in the map() function in place of 0, 1023

  10. #10
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    228
    Also how is your pot connected?

  11. #11
    Quote Originally Posted by wrightflyer View Post
    Are you sure the AnalogRead is returning a full sweep 0 to 1023 for complete rotation of the pot. Just Serial.println() the raw value and wind the pot to either end. Is it 0 at one end and 1023 at the other?

    EDIT if you find it is just 213 at the lower end and 724 at the upper (say) then put those as the lower and upper values in the map() function in place of 0, 1023
    hi so when I turn the knob it print on serial monitor 0 or 20460, nothing else between these 2 values
    my pot is wired one pin to gnd one other to vcc and the middle pin of the pot to my A3 pin on teensy
    and it s a 10k pot

  12. #12
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,499
    What voltage is VCC? It should be 3.3V for a 3.3V Teensy - and if 5V on T_3.6 or 4.0, 4.1 or LC that is not a proper value to present.

    If it is 5V then anything over 3.3V will read full scale. But seeing only 0 or mapped full scale suggests something is wrong.

  13. #13
    i wired vcc to the 3.3v pin on the teensy 3.6

  14. #14
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,499
    Quote Originally Posted by benwadub View Post
    i wired vcc to the 3.3v pin on the teensy 3.6
    That seems right. What does a meter on GND and the center pole going to Teensy pin read in rotation?

  15. #15
    I got 3.28 fully open and 0V fully closed

  16. #16
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,499
    Quote Originally Posted by benwadub View Post
    I got 3.28 fully open and 0V fully closed
    And in between does it change from 0V linearly across 0V ... 1V ... 2V ... 3V ... 3.28V ?

  17. #17
    yes it s linearly I can reach each voltage when turning slowly the knob.
    but when I come under 2.89v serial print show 0 as value

  18. #18
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,499
    Quote Originally Posted by benwadub View Post
    yes it s linearly I can reach each voltage when turning slowly the knob.
    but when I come under 2.89v serial print show 0 as value
    That is good for the meter, the Teensy should see the same thing and respond the same way then given proper code. If the Pin or Teensy has not been damaged.

    But that is acting like a DIGITAL pin is in use? Not sure what Teensy is in use - but hopefully there is a card at hand for it?
    Digital pins are the numbers on the cards 0-14 ...
    Analog pins are those A0-A9...
    To use an Analog pins enter the A# OR the digital pin number beside it
    Not sure if this is current and correct code :: int cutoff = analogRead(A3) *20;
    > but A3 seems to be Teensy pin 17 and that should work.

    Maybe starting with this simple sample : {arduino}\examples\03.Analog\AnalogInOutSerial\Ana logInOutSerial.ino

    adjust the pin number : analogInPin

    perhaps remove the line : analogWrite(analogOutPin, outputValue);

    And even adjust this line - after testing it as written : outputValue = map(sensorValue, 0, 1023, 0, 255);

  19. #19
    i m using the pin 17, with analoginoutserial I get the same result :-(
    i have the audio shield wired on the 3.6 maybe that can be a problem? I didn't thought about it!

  20. #20
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,499
    Quote Originally Posted by benwadub View Post
    i m using the pin 17, with analoginoutserial I get the same result :-(
    i have the audio shield wired on the 3.6 maybe that can be a problem? I didn't thought about it!
    Could be that pin is shared with Audio adapter - look it up on PJRC.com ...

  21. #21
    Sadly it does not look like a pin clash. In this picture I simply put the Teensy 4 and Audio shield pin outs side by side:

    https://github.com/wrightflyer/Synth...ter/layout.png

    Pin 17 (A3) is not a clash with a signal on the Audio shield.

    Like Defragster I would suggest you reduce this to a minimum - simply create a sketch with an AnalogRead(A3) and a Serial.println() and try it in a complete isolation from any other software. Also simply try unplugging the audio shield when you do this to see if it is making a difference.

    As Teensy 3/4 are 3V3 you should have Gnd at one end of your pot, 3V3 at the other and then the slider pin into the analog input.

  22. #22
    ok so I tried with a minimum of code and same result!!
    Code:
    void setup() {
      // put your setup code here, to run once:
    
    }
    
    void loop() {
      int cutoff = analogRead(A3) *20;
       //analogReadAveraging(10);
       Serial.println(cutoff);
       delay(100);
      // put your main code here, to run repeatedly:
    
    }
    serial print give this

    20460
    20460
    20460
    20460
    20460
    20460
    20460
    0
    0
    0
    0
    0
    0
    0
    i ll try with another teensy 3.6, on this one audioboard is soldered on, ill tell. you what it do on the second one! again thanks for helping me! guys!

  23. #23
    it seems that my teensy as a problem, the other one used for the synth doesn't react the same way!

  24. #24
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    228
    you could also try the other analog inputs A12-A22 (pin31-"41") there could be a short between A3 (pin17) and some other pin under the bga.
    assuming that you use a teensy 3.6

  25. #25
    I tried with each analog pins and they all have the problem, toi made lots of experiment with this teensy and audio shield and already desoldered and resolve red the shield on it I think I broke it!
    I l Gina order a 4.1 and the rev d audio shield to restart this project!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •