Oscillator selects and examples

Made it possible to select type and number of oscillators to compile
(via preprocessor). Made Examples folder to library where  tutorials
will go in.
This commit is contained in:
Jakob Bak
2013-01-23 19:29:10 +01:00
parent e1a7320aa6
commit 642b4973ca
14 changed files with 717 additions and 47 deletions
@@ -0,0 +1,68 @@
// This needs to be in all sketches at the moment
#include <stdint.h>
// The Music and Midi objects are automatically instantiated when the header file is included.
// Make calls to the Music and Midi objects with "Music.function(args)" and "Midi.function(args)"
// You still need to call Music.init() and Midi.init() in the setup() function below.
#include <Music.h>
// variables for this sketch
boolean noteIsOn = false;
int n = 0;
int dir = 1;
int rootNote = 26;
int note[] = {0,2,3,5,7,9,10,12,14};
long time = 0;
long lastTime = 0;
long beatTime = 80;
void setup() {
// We initialise the sound engine by calling Music.init() which outputs a tone
Music.init();
// Choosing the square wave oscillator.
Music.setWaveform(1);
// Detuning the three oscillators slightly to create movement in the sound.
Music.setDetune(0.008);
// enabling the envelope lets us define an gain envelope for the synth
// without having to specify it in our loop() or physics code.
Music.enableEnvelope();
Music.setAttack(8);
Music.setDecay(90);
Music.setSustain(48);
Music.setRelease(64);
}
void loop() {
// This short routine loops note over and over again
time = millis();
if(time - lastTime > beatTime) {
if(!noteIsOn) {
Music.noteOn(rootNote+note[n]);
noteIsOn = true;
n = n + dir;
if(n > 7)
{
dir = -1;
}
else if(n < 1)
{
dir = 1;
}
} else {
Music.noteOff();
noteIsOn = false;
}
lastTime = time;
}
}