ADSR

94 views
Skip to first unread message

psyCohoLix

unread,
Jan 3, 2019, 7:16:33 AM1/3/19
to Mozzi-users
Hello,

I am a very beginnger of programming with mozzi library. I want to code a sketch that plays a note every second with ADSR to see how ADSR works. My Code:

#include <MozziGuts.h>
#include <Oscil.h>
#include <tables/square_analogue512_int8.h>
#include <ADSR.h>
#include <EventDelay.h>

#define CONTROL_RATE 128

Oscil <512, AUDIO_RATE> aSaw(SQUARE_ANALOGUE512_DATA);

ADSR <CONTROL_RATE, AUDIO_RATE> env;



EventDelay Delay;

int counter=0;
int On_Off;

void setup(){
 
  startMozzi(CONTROL_RATE);
  aSaw.setFreq(55);

}

void updateControl(){
 
  env.setADLevels(200,32);
  env.setTimes(20,20,20,20);


  Delay.set(1000);
 
 
  if(Delay.ready()){

    counter=counter+1;
    
     if(counter==2){
      counter=0;
      Delay.start(true);
    }

    Delay.start();
   }

    if(counter==1){
      env.noteOn();
    }
    else{
      env.noteOff();
    }
   

  env.update();
}

int updateAudio(){

  return (int) (env.next() * aSaw.next())>>8;
 
}

void loop(){
  audioHook();
}



My problem is that the note plays the whole second even though the decay, sustain and release is 20ms. Have you got some solution ?

greetings
Reply all
Reply to author
Forward
0 new messages