#include <MozziGuts.h>
#include <Oscil.h> // oscillator template
#include <tables/sin2048_int8.h> // sine table for oscillator
// use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included above
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin1(SIN2048_DATA);
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin2(SIN2048_DATA);
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin3(SIN2048_DATA);
void setup(){
startMozzi(CONTROL_RATE); // set a control rate of 64 (powers of 2 please)
aSin1.setFreq(493.88f); // set the frequency
aSin2.setFreq(622.25f);
aSin3.setFreq(880.00f);
}
void updateControl(){
// put changing controls in here
}
int updateAudio(){
return ((int)aSin1.next() + aSin2.next() + aSin3.next())>>1;
}
void loop(){
audioHook(); // required here
}#include <MozziGuts.h>
#include <Oscil.h> // oscillator template
#include <tables/smoothsquare8192_int8.h> // squarewave table for oscillator
#include <ADSR.h>
const int buttonPin = 4; // the number of the pushbutton pin
Oscil <SMOOTHSQUARE8192_NUM_CELLS, AUDIO_RATE> aSig1(SMOOTHSQUARE8192_DATA);
Oscil <SMOOTHSQUARE8192_NUM_CELLS, AUDIO_RATE> aSig2(SMOOTHSQUARE8192_DATA);
Oscil <SMOOTHSQUARE8192_NUM_CELLS, AUDIO_RATE> aSig3(SMOOTHSQUARE8192_DATA);
ADSR <CONTROL_RATE, AUDIO_RATE> envelope;
void setup() {
startMozzi();
envelope.setADLevels(255,255);
envelope.setTimes(250,500,1000,500); // will release after 1750 ms or earlier if button is released sooner
aSig1.setFreq(600); // set the frequency
aSig2.setFreq(880);
aSig3.setFreq(1200);
}
boolean triggered = false;
void updateControl() {
if (digitalRead(buttonPin) == HIGH) {
if (!triggered){ // only happens once at start of each button press
envelope.noteOn();
triggered = true;
}
}
else { // button off
envelope.noteOff();
triggered = false;
}
envelope.update();
}
int updateAudio(){
int whistle = ((int)aSig1.next() + aSig2.next() + aSig3.next())>>1;
return ((long)envelope.next() * whistle)>>8;