Added Music examples to Apps folder
This commit is contained in:
parent
4fddbf3190
commit
7b2f0c750d
25
software/apps/Music/_1_minimal/_1_minimal.ino
Normal file
25
software/apps/Music/_1_minimal/_1_minimal.ino
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// You can set the number of oscillators (1 to 3) and the bit depth of the
|
||||||
|
// oscillators (8 or 12 bit). These settings must be defined before the
|
||||||
|
// inclusion of the MMM library files. They default to 1 osciallator
|
||||||
|
// and 8bit respectively.
|
||||||
|
|
||||||
|
#define NUM_OSCILLATORS 1
|
||||||
|
#define BIT_DEPTH 12
|
||||||
|
|
||||||
|
// The Music object is automatically instantiated when the header file is
|
||||||
|
// included. Make calls to the Music objects wit "Music.function(args)".
|
||||||
|
// You still need to call Music.init() in the setup() function below.
|
||||||
|
#include <Music.h>
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
// We initialise the sound engine by calling Music.init() which outputs a tone
|
||||||
|
Music.init();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
56
software/apps/Music/_2_waveform/_2_waveform.ino
Normal file
56
software/apps/Music/_2_waveform/_2_waveform.ino
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// You can set the number of oscillators (1 to 3) and the bit depth of the
|
||||||
|
// oscillators (8 or 12 bit). These settings must be defined before the
|
||||||
|
// inclusion of the MMM library files. They default to 1 osciallator
|
||||||
|
// and 8bit respectively.
|
||||||
|
|
||||||
|
#define NUM_OSCILLATORS 1
|
||||||
|
#define BIT_DEPTH 8
|
||||||
|
|
||||||
|
// The Music object is automatically instantiated when the header file is
|
||||||
|
// included. Make calls to the Music objects with "Music.function(args)".
|
||||||
|
// You still need to call Music.init() in the setup() function below.
|
||||||
|
#include <Music.h>
|
||||||
|
|
||||||
|
int delayTime = 1000;
|
||||||
|
int cnt = 0;
|
||||||
|
long timeNow;
|
||||||
|
long lastTime = 0;
|
||||||
|
|
||||||
|
byte waveFormArray[] = { SINE,
|
||||||
|
SQUARE,
|
||||||
|
PULSE,
|
||||||
|
TRIANGLE,
|
||||||
|
SAW,
|
||||||
|
FUZZ,
|
||||||
|
DIGI1,
|
||||||
|
DIGI2,
|
||||||
|
DIGI3,
|
||||||
|
DIGI4,
|
||||||
|
NOISE,
|
||||||
|
DIGI6,
|
||||||
|
TAN1,
|
||||||
|
TAN2,
|
||||||
|
TAN3,
|
||||||
|
TAN4
|
||||||
|
};
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
// We initialise the sound engine by calling Music.init() which outputs a tone
|
||||||
|
Music.init();
|
||||||
|
Music.setFrequency(220);
|
||||||
|
Music.setWaveform(SINE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
timeNow = millis();
|
||||||
|
if((timeNow-lastTime) > delayTime) {
|
||||||
|
cnt = cnt + 1;
|
||||||
|
if(cnt>15) cnt = 0;
|
||||||
|
Music.setWaveform(waveFormArray[cnt]);
|
||||||
|
lastTime = timeNow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
42
software/apps/Music/_3_frequency/_3_frequency.ino
Normal file
42
software/apps/Music/_3_frequency/_3_frequency.ino
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// You can set the number of oscillators (1 to 3) and the bit depth of the
|
||||||
|
// oscillators (8 or 12 bit). These settings must be defined before the
|
||||||
|
// inclusion of the MMM library files. They default to 1 osciallator
|
||||||
|
// and 8bit respectively.
|
||||||
|
|
||||||
|
#define NUM_OSCILLATORS 3
|
||||||
|
#define BIT_DEPTH 8
|
||||||
|
|
||||||
|
// The Music object is automatically instantiated when the header file is
|
||||||
|
// included. Make calls to the Music objects with "Music.function(args)".
|
||||||
|
// You still need to call Music.init() in the setup() function below.
|
||||||
|
#include <Music.h>
|
||||||
|
|
||||||
|
int delayTime = 400;
|
||||||
|
int cnt = 0;
|
||||||
|
float baseFrequency = 110;
|
||||||
|
long timeNow;
|
||||||
|
long lastTime = 0;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
// We initialise the sound engine by calling Music.init() which outputs a tone
|
||||||
|
Music.init();
|
||||||
|
Music.setFrequency(220);
|
||||||
|
Music.setDetune(0.001); // ranges from 0.00 - 0.02 are usually good
|
||||||
|
Music.setWaveform(SAW);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
timeNow = millis();
|
||||||
|
if((timeNow-lastTime) > delayTime) {
|
||||||
|
cnt = cnt + 1;
|
||||||
|
if(cnt>3) cnt = 0;
|
||||||
|
Music.setFrequency1(baseFrequency*1*cnt);
|
||||||
|
Music.setFrequency2(baseFrequency*1.3333*cnt);
|
||||||
|
Music.setFrequency3(baseFrequency*1.5*cnt);
|
||||||
|
lastTime = timeNow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
47
software/apps/Music/_4_gain/_4_gain.ino
Normal file
47
software/apps/Music/_4_gain/_4_gain.ino
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// You can set the number of oscillators (1 to 3) and the bit depth of the
|
||||||
|
// oscillators (8 or 12 bit). These settings must be defined before the
|
||||||
|
// inclusion of the MMM library files. They default to 1 osciallator
|
||||||
|
// and 8bit respectively.
|
||||||
|
|
||||||
|
#define NUM_OSCILLATORS 3
|
||||||
|
#define BIT_DEPTH 8
|
||||||
|
|
||||||
|
// The Music object is automatically instantiated when the header file is
|
||||||
|
// included. Make calls to the Music objects with "Music.function(args)".
|
||||||
|
// You still need to call Music.init() in the setup() function below.
|
||||||
|
#include <Music.h>
|
||||||
|
|
||||||
|
int delayTime = 100;
|
||||||
|
int cnt = 0;
|
||||||
|
float baseFrequency = 110;
|
||||||
|
long timeNow;
|
||||||
|
long lastTime = 0;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
// We initialise the sound engine by calling Music.init() which outputs a tone
|
||||||
|
Music.init();
|
||||||
|
Music.setFrequency(220);
|
||||||
|
Music.setDetune(0.005); // ranges from 0.00 - 0.02 are usually good
|
||||||
|
Music.setWaveform(PULSE);
|
||||||
|
Music.setFrequency1(baseFrequency*1);
|
||||||
|
Music.setFrequency2(baseFrequency*1.3333);
|
||||||
|
Music.setFrequency3(baseFrequency*1.5);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
timeNow = millis();
|
||||||
|
if((timeNow-lastTime) > delayTime) {
|
||||||
|
cnt = cnt + 1;
|
||||||
|
if(cnt>16) cnt = 0;
|
||||||
|
float counter = float(cnt);
|
||||||
|
Music.setGain1(1.0/cnt);
|
||||||
|
Music.setGain2(1.0/cnt);
|
||||||
|
Music.setGain3(1.0/cnt);
|
||||||
|
lastTime = timeNow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
31
software/apps/Music/_5_semi_detune/_5_semi_detune.ino
Normal file
31
software/apps/Music/_5_semi_detune/_5_semi_detune.ino
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// You can set the number of oscillators (1 to 3) and the bit depth of the
|
||||||
|
// oscillators (8 or 12 bit). These settings must be defined before the
|
||||||
|
// inclusion of the MMM library files. They default to 1 osciallator
|
||||||
|
// and 8bit respectively.
|
||||||
|
|
||||||
|
#define NUM_OSCILLATORS 3
|
||||||
|
#define BIT_DEPTH 8
|
||||||
|
|
||||||
|
// The Music object is automatically instantiated when the header file is
|
||||||
|
// included. Make calls to the Music objects with "Music.function(args)".
|
||||||
|
// You still need to call Music.init() in the setup() function below.
|
||||||
|
#include <Music.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
// We initialise the sound engine by calling Music.init() which outputs a tone
|
||||||
|
Music.init();
|
||||||
|
Music.setFrequency(110);
|
||||||
|
Music.setDetune(0.005); // ranges from 0.00 - 0.02 are usually good
|
||||||
|
Music.setWaveform(DIGI2);
|
||||||
|
Music.setSemitone1(0);
|
||||||
|
Music.setSemitone2(7);
|
||||||
|
Music.setSemitone3(-12);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
70
software/apps/Music/_6_noteOn_noteOff/_6_noteOn_noteOff.ino
Normal file
70
software/apps/Music/_6_noteOn_noteOff/_6_noteOn_noteOff.ino
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
// You can set the number of oscillators (1 to 3) and the bit depth of the
|
||||||
|
// oscillators (8 or 12 bit). These settings must be defined before the
|
||||||
|
// inclusion of the MMM library files. They default to 1 osciallator
|
||||||
|
// and 8bit respectively.
|
||||||
|
|
||||||
|
#define NUM_OSCILLATORS 3
|
||||||
|
#define BIT_DEPTH 8
|
||||||
|
|
||||||
|
// The Music object is automatically instantiated when the header file is
|
||||||
|
// included. Make calls to the Music objects with "Music.function(args)".
|
||||||
|
// You still need to call Music.init() in the setup() function below.
|
||||||
|
#include <Music.h>
|
||||||
|
|
||||||
|
boolean noteIsOn = false;
|
||||||
|
int n = 0;
|
||||||
|
int dir = 1;
|
||||||
|
int rootNote = 36;
|
||||||
|
int note[] = {0,2,3,5,7,9,10,12,14};
|
||||||
|
|
||||||
|
long time = 0;
|
||||||
|
long lastTime = 0;
|
||||||
|
long timeDelay = 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(DIGI3);
|
||||||
|
|
||||||
|
// 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 > timeDelay) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
// 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
|
||||||
|
float gain = 1.0;
|
||||||
|
float c = 220; // center frequency
|
||||||
|
float f1 = 1;
|
||||||
|
float f2 = 1;
|
||||||
|
float f3 = 1;
|
||||||
|
float m1 = 1.0011;
|
||||||
|
float m2 = 1.0012;
|
||||||
|
float m3 = 1.0013;
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
// We initialise the sound engine by calling Music.init() which outputs a tone
|
||||||
|
Music.init();
|
||||||
|
|
||||||
|
// Choosing the sine wave oscillator (optional since this is already the default).
|
||||||
|
Music.setWaveform(0);
|
||||||
|
|
||||||
|
// Setting the initial frequency for all three oscillators.
|
||||||
|
Music.setFrequency(c);
|
||||||
|
|
||||||
|
// Detuning the three oscillators slightly to create movement in the sound.
|
||||||
|
Music.setDetune(0.002);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
// This short routine creates a
|
||||||
|
|
||||||
|
Music.setFrequency1(c*f1);
|
||||||
|
Music.setFrequency2(c*f2);
|
||||||
|
Music.setFrequency3(c*f3);
|
||||||
|
|
||||||
|
f1 *= m1;
|
||||||
|
f2 *= m2;
|
||||||
|
f3 *= m3;
|
||||||
|
|
||||||
|
if(f1 > 4.0) m1 = 0.9745;
|
||||||
|
if(f2 > 4.0) m2 = 0.9852;
|
||||||
|
if(f3 > 4.0) m3 = 0.9975;
|
||||||
|
|
||||||
|
if(f1 < 0.25) m1 = 1.0754;
|
||||||
|
if(f2 < 0.25) m2 = 1.0573;
|
||||||
|
if(f3 < 0.25) m3 = 1.0386;
|
||||||
|
|
||||||
|
if(millis() > 10000) {
|
||||||
|
Music.setGain(gain);
|
||||||
|
gain *= 0.999;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
30
software/apps/Music/_8_midi/_8_midi.ino
Normal file
30
software/apps/Music/_8_midi/_8_midi.ino
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// You can set the number of oscillators (1 to 3) and the bit depth of the
|
||||||
|
// oscillators (8 or 12 bit). These settings must be defined before the
|
||||||
|
// inclusion of the MMM library files. They default to 1 osciallator
|
||||||
|
// and 8bit respectively.
|
||||||
|
|
||||||
|
#define NUM_OSCILLATORS 3
|
||||||
|
#define BIT_DEPTH 8
|
||||||
|
#define MIDI
|
||||||
|
|
||||||
|
// The Music object is automatically instantiated when the header file is
|
||||||
|
// included. Make calls to the Music objects with "Music.function(args)".
|
||||||
|
// You still need to call Music.init() in the setup() function below.
|
||||||
|
#include <Music.h>
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
// We initialise the sound engine by calling Music.init() which outputs a tone
|
||||||
|
Music.init();
|
||||||
|
Midi.init();
|
||||||
|
Music.enableEnvelope();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
// In order to send MIDI to the sketch, use the Music_Controls.pde Processing sketch
|
||||||
|
Midi.checkMidi();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user