Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: lfo cutoff

  1. #1
    Junior Member
    Join Date
    Sep 2017
    Posts
    3

    lfo cutoff

    hey,
    i'm new in this all teensy, and im trying to build synth.
    i'm try to undrestend how can i control filter cutoff by lfo that affected from the cutoff knob position.
    tnx!

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,153
    First, decide if you want to control the cutoff by a knob or by an lfo or by a combination of both.
    Second, decide if the knob will be a pot or a rotary encoder.
    Write code to read the knob, if combination then write a function to add or multiply the knob reading with the lfo output. Inject the result into the filter control function.

  3. #3
    Junior Member
    Join Date
    Sep 2017
    Posts
    3
    first off all thank you!
    can you give me an exmple for code that combines knob with (1023-0 values) with lfo base on Waveform oscillator?

  4. #4
    Junior Member
    Join Date
    Sep 2017
    Posts
    3
    here is my code
    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <Bounce.h>
    
    
    AudioSynthWaveform       vcowf;          //xy=1845,1892.5
    AudioSynthWaveform       vcosaw;         //xy=1847,1855.5
    AudioMixer4              vcomixer;       //xy=1993,1873.5
    AudioSynthWaveform       lfo;            //xy=2002.6667022705078,1935.1666240692139
    AudioFilterStateVariable filter;         //xy=2385,1879.5
    AudioMixer4              vcfmixer;       //xy=2538,1876.5
    AudioEffectEnvelope      env;            //xy=2701,1880.5
    AudioOutputI2S           i2s1;           //xy=2862,1884.5
    AudioConnection          patchCord1(vcowf, 0, vcomixer, 1);
    AudioConnection          patchCord2(vcosaw, 0, vcomixer, 0);
    AudioConnection          patchCord3(vcomixer, 0, filter, 0);
    AudioConnection          patchCord4(lfo, 0, filter, 1);
    AudioConnection          patchCord5(filter, 0, vcfmixer, 0);
    AudioConnection          patchCord6(filter, 1, vcfmixer, 1);
    AudioConnection          patchCord7(filter, 2, vcfmixer, 2);
    AudioConnection          patchCord8(vcfmixer, env);
    AudioConnection          patchCord9(env, 0, i2s1, 0);
    AudioConnection          patchCord10(env, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=2868,1841.5
    
    
    
    //synth 
    float mainVolume;
    int tempLineOutLevel;
    int lfowaveShape;
    int waveShape;//WaveShapes
    float amount;
    float lfofrq;
    float filterres;
    float filtertype;
    float filtercutoff;
    
    
    
    //ADSR
    int attacktime;
    int decaytime;
    float sustainlevel;
    int releasetime;
    
    
    
    void setup() {
      
      AudioMemory(160);
      Serial.begin(115200);
      sgtl5000_1.enable();
      sgtl5000_1.volume(.7);
    
    
    //mixer stratup
     vcomixer.gain(0, .5);
     vcomixer.gain(1, .5);
     vcomixer.gain(2, 0);
     vcomixer.gain(3, 0);
    
     vcfmixer.gain(0, 1);
     vcfmixer.gain(1, 0);
     vcfmixer.gain(2, 0);
     vcfmixer.gain(3, 0);
    
    //osc stratup
    vcosaw.begin(WAVEFORM_SAWTOOTH);
    vcosaw.amplitude(1);
    vcosaw.frequency(440);
    
    vcowf.begin(WAVEFORM_SINE);
    vcosaw.amplitude(1);
    vcosaw.frequency(220);
    
    
    
    
    //lfo strtup
    lfo.begin(1,3,WAVEFORM_SINE);
    
    
       
      }
    
    
    
    
    void loop() {
    
      //Volume
      mainVolume = analogRead(A1);
      mainVolume = mainVolume/1023;
      sgtl5000_1.volume(mainVolume);
      tempLineOutLevel = analogRead(A1);
      tempLineOutLevel = map(tempLineOutLevel, 0, 1023, 31, 13);
      sgtl5000_1.lineOutLevel(tempLineOutLevel);
    
    
    
    
    
        //shape
        waveShape = analogRead(A0);
        waveShape = waveShape/255;
            if(waveShape <= 4 && waveShape >= 3){
              vcowf.begin(WAVEFORM_PULSE);
              }
     if(waveShape <= 3 && waveShape >= 2){
              vcowf.begin(WAVEFORM_SQUARE);
              }
     if(waveShape <= 2 && waveShape >= 1){
              vcowf.begin(WAVEFORM_SAWTOOTH);
              }
     if(waveShape <= 1 && waveShape >= 0){
              vcowf.begin(WAVEFORM_SINE);
              }
    
    
    //vcomixer
    
    float  mix = analogRead(A3);
    mix = mix/1023;
    float mix2 = 1 - mix;
    vcomixer.gain(0, mix);
    vcomixer.gain(1, mix2);
    
    
    //lfo amount-vol
    amount = analogRead(A7);
      amount = amount/1023;
      lfo.amplitude(amount);
    
    
    //lfo frq
    lfofrq = analogRead(A6);
    lfofrq = lfofrq/50;
    lfo.frequency(lfofrq);
    
    
    
    
    
    //lfo waveform
      lfowaveShape = analogRead(A0);
        lfowaveShape = lfowaveShape/255;
        
     if(lfowaveShape <= 4 && lfowaveShape >= 3){
              vcowf.begin(WAVEFORM_PULSE);
              }
     if(lfowaveShape <= 3 && lfowaveShape >= 2){
              vcowf.begin(WAVEFORM_SQUARE);
              }
     if(lfowaveShape <= 2 && lfowaveShape >= 1){
              vcowf.begin(WAVEFORM_SAWTOOTH);
              }
     if(lfowaveShape <= 1 && lfowaveShape >= 0){
              vcowf.begin(WAVEFORM_SINE);
              }
    
    
    
    
    //filter cutoff
     filtercutoff = analogRead(A11);
     filtercutoff = map(filtercutoff, 0, 1023, 0, 10000);
     filter.frequency(filtercutoff);
    
    
    
    //filter resonans
    
    filterres = analogRead(A12);
    filterres = filterres/250;
    filterres = filterres+0.9;
    filter.resonance(filterres);
    
    //vcfmixer -filtertype
    
    
      filtertype = analogRead(A13);
        filtertype = filtertype/330;
        
     if(filtertype <= 3 && filtertype >= 2){
               vcfmixer.gain(0, 1);
               vcfmixer.gain(1, 0);
               vcfmixer.gain(2, 0);
              }
     if(filtertype <= 2 && filtertype >= 1){
               vcfmixer.gain(0, 0);
               vcfmixer.gain(1, 1);
               vcfmixer.gain(2, 0);
              }
     if(filtertype <= 1 && filtertype >= 0){
               vcfmixer.gain(0, 0);
               vcfmixer.gain(1, 0);
               vcfmixer.gain(2, 1);
              }
    
    
    //adsr
    
    attacktime = analogRead(A14);
    attacktime = attacktime*2;
    env.attack(attacktime);
    
    
    decaytime = analogRead(A16);
    decaytime = decaytime*2;
    env.decay(decaytime);
    
    
    
    sustainlevel = analogRead(A15);
    sustainlevel = sustainlevel/1023;
    env.sustain(decaytime);
    
    
    releasetime = analogRead(A17);
    releasetime = releasetime*2;
    env.release(releasetime);
    
    
    
    
    
    
    
    
    
    
    
    }

Posting Permissions

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