From 7b2f0c750d820c67121507f658831f8c7914601e Mon Sep 17 00:00:00 2001 From: Jakob Bak Date: Sun, 10 Feb 2013 10:34:10 +0100 Subject: [PATCH] Added Music examples to Apps folder --- software/apps/Music/_1_minimal/_1_minimal.ino | 25 +++++++ .../apps/Music/_2_waveform/_2_waveform.ino | 56 +++++++++++++++ .../apps/Music/_3_frequency/_3_frequency.ino | 42 +++++++++++ software/apps/Music/_4_gain/_4_gain.ino | 47 +++++++++++++ .../Music/_5_semi_detune/_5_semi_detune.ino | 31 ++++++++ .../_6_noteOn_noteOff/_6_noteOn_noteOff.ino | 70 +++++++++++++++++++ .../_7_spaghetti_tones/_7_spaghetti_tones.ino | 60 ++++++++++++++++ software/apps/Music/_8_midi/_8_midi.ino | 30 ++++++++ 8 files changed, 361 insertions(+) create mode 100644 software/apps/Music/_1_minimal/_1_minimal.ino create mode 100644 software/apps/Music/_2_waveform/_2_waveform.ino create mode 100644 software/apps/Music/_3_frequency/_3_frequency.ino create mode 100644 software/apps/Music/_4_gain/_4_gain.ino create mode 100644 software/apps/Music/_5_semi_detune/_5_semi_detune.ino create mode 100644 software/apps/Music/_6_noteOn_noteOff/_6_noteOn_noteOff.ino create mode 100644 software/apps/Music/_7_spaghetti_tones/_7_spaghetti_tones.ino create mode 100644 software/apps/Music/_8_midi/_8_midi.ino diff --git a/software/apps/Music/_1_minimal/_1_minimal.ino b/software/apps/Music/_1_minimal/_1_minimal.ino new file mode 100644 index 0000000..bbe5b73 --- /dev/null +++ b/software/apps/Music/_1_minimal/_1_minimal.ino @@ -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 + + +void setup() { + + // We initialise the sound engine by calling Music.init() which outputs a tone + Music.init(); + +} + +void loop() { + +} + diff --git a/software/apps/Music/_2_waveform/_2_waveform.ino b/software/apps/Music/_2_waveform/_2_waveform.ino new file mode 100644 index 0000000..764cd06 --- /dev/null +++ b/software/apps/Music/_2_waveform/_2_waveform.ino @@ -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 + +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; + } +} + diff --git a/software/apps/Music/_3_frequency/_3_frequency.ino b/software/apps/Music/_3_frequency/_3_frequency.ino new file mode 100644 index 0000000..a1c5393 --- /dev/null +++ b/software/apps/Music/_3_frequency/_3_frequency.ino @@ -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 + +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; + } +} + diff --git a/software/apps/Music/_4_gain/_4_gain.ino b/software/apps/Music/_4_gain/_4_gain.ino new file mode 100644 index 0000000..d93eb4c --- /dev/null +++ b/software/apps/Music/_4_gain/_4_gain.ino @@ -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 + +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; + } +} + diff --git a/software/apps/Music/_5_semi_detune/_5_semi_detune.ino b/software/apps/Music/_5_semi_detune/_5_semi_detune.ino new file mode 100644 index 0000000..1c5c1f0 --- /dev/null +++ b/software/apps/Music/_5_semi_detune/_5_semi_detune.ino @@ -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 + +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() { + +} + diff --git a/software/apps/Music/_6_noteOn_noteOff/_6_noteOn_noteOff.ino b/software/apps/Music/_6_noteOn_noteOff/_6_noteOn_noteOff.ino new file mode 100644 index 0000000..8d67a7f --- /dev/null +++ b/software/apps/Music/_6_noteOn_noteOff/_6_noteOn_noteOff.ino @@ -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 + +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; + } + +} + diff --git a/software/apps/Music/_7_spaghetti_tones/_7_spaghetti_tones.ino b/software/apps/Music/_7_spaghetti_tones/_7_spaghetti_tones.ino new file mode 100644 index 0000000..7f0aad8 --- /dev/null +++ b/software/apps/Music/_7_spaghetti_tones/_7_spaghetti_tones.ino @@ -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 + +// 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; + } + + +} + diff --git a/software/apps/Music/_8_midi/_8_midi.ino b/software/apps/Music/_8_midi/_8_midi.ino new file mode 100644 index 0000000..c738708 --- /dev/null +++ b/software/apps/Music/_8_midi/_8_midi.ino @@ -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 + +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(); + +} +