This example demonstrates the Smooth class.
#include <MozziGuts.h>
#include <Oscil.h>
#include <tables/sin2048_int8.h>
#include <EventDelay.h>
#include <Smooth.h>
#include <mozzi_rand.h>
#define CONTROL_RATE 128
const unsigned int gainChangeMsec = 200;
const unsigned int smoothOnOffMsec = 2000;
float smoothness = 0.9975f;
boolean smoothIsOn=true;
long target_gain = 0;
void setup(){
aSin.setFreq(330);
kGainChangeDelay.
set(gainChangeMsec);
kSmoothOnOff.
set(smoothOnOffMsec);
}
if(kSmoothOnOff.
ready()){
if (smoothIsOn) {
aSmoothGain.setSmoothness(0.f);
smoothIsOn = false;
}
else{
aSmoothGain.setSmoothness(smoothness);
smoothIsOn = true;
}
}
if(kGainChangeDelay.
ready()){
target_gain =
rand((byte) 255);
kGainChangeDelay.
start();
}
}
return (aSmoothGain.next(target_gain) * aSin.next()) >> 8;
}
void loop(){
}